Skip to content

Commit d8df97d

Browse files
committed
attempt (preferably not needed)
1 parent 974aa15 commit d8df97d

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

block/retriever_da.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ func (m *Manager) tryDecodeHeader(bz []byte, daHeight uint64) *types.SignedHeade
176176
return nil
177177
}
178178

179-
// set custom verifier to do correct header verification
180-
header.SetCustomVerifierForSyncNode(m.syncNodeSignaturePayloadProvider)
181-
182179
// validate basic header structure only (without data)
183180
if err := header.Header.ValidateBasic(); err != nil {
184181
m.logger.Debug().Uint64("daHeight", daHeight).Err(err).Msg("blob does not look like a valid header")
@@ -252,11 +249,32 @@ func (m *Manager) createEmptyData(header *types.SignedHeader) *types.Data {
252249
}
253250
}
254251

252+
func (m *Manager) waitForHeight(ctx context.Context, height uint64) error {
253+
for {
254+
currentHeight, err := m.GetStoreHeight(ctx)
255+
if err != nil {
256+
m.logger.Error().Err(err).Msg("failed to get store height")
257+
return err
258+
}
259+
if currentHeight >= height {
260+
return nil
261+
}
262+
263+
time.Sleep(time.Second)
264+
}
265+
}
266+
255267
// sendHeightEventIfValid sends a height event if both header and data are valid and not seen before
256268
func (m *Manager) sendHeightEventIfValid(ctx context.Context, header *types.SignedHeader, data *types.Data, daHeight uint64) {
257269
headerHash := header.Hash().String()
258270
dataHashStr := data.DACommitment().String()
259271

272+
// we need to wait until the previous height has been executed in order to continue syncing
273+
if err := m.waitForHeight(ctx, header.Height()-1); err != nil {
274+
m.logger.Error().Err(err).Msg("failed to wait for previous height")
275+
return
276+
}
277+
260278
// Validate header with its data before proceeding
261279
if err := header.ValidateBasicWithData(data); err != nil {
262280
m.logger.Debug().Uint64("height", header.Height()).Err(err).Msg("header validation with data failed")

block/retriever_store.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,18 @@ func (m *Manager) processHeaderStoreRange(ctx context.Context, startHeight, endH
9494
data = retrievedData
9595
}
9696

97+
// we need to wait until the previous height has been executed in order to continue syncing
98+
if err := m.waitForHeight(ctx, header.Height()-1); err != nil {
99+
m.logger.Error().Err(err).Msg("failed to wait for previous height")
100+
return
101+
}
102+
97103
// validate header and its signature validity with data
98104
if err := header.ValidateBasicWithData(data); err != nil {
99105
m.logger.Debug().Uint64("height", header.Height()).Err(err).Msg("header validation with data failed")
100106
continue
101107
}
108+
102109
m.sendCompleteHeightEvent(ctx, header, data, daHeight, "p2p header sync")
103110
}
104111
}
@@ -133,6 +140,12 @@ func (m *Manager) processDataStoreRange(ctx context.Context, startHeight, endHei
133140
// set custom verifier to do correct header verification
134141
header.SetCustomVerifierForSyncNode(m.syncNodeSignaturePayloadProvider)
135142

143+
// we need to wait until the previous height has been executed in order to continue syncing
144+
if err := m.waitForHeight(ctx, header.Height()-1); err != nil {
145+
m.logger.Error().Err(err).Msg("failed to wait for previous height")
146+
return
147+
}
148+
136149
// validate header and its signature validity with data
137150
if err := header.ValidateBasicWithData(d); err != nil {
138151
m.logger.Debug().Uint64("height", d.Metadata.Height).Err(err).Msg("header validation with data failed")

0 commit comments

Comments
 (0)