Skip to content

Commit 31e7659

Browse files
committed
Merge branch 'main' into julien/sync-p2p
2 parents 8a4c7d5 + ac00304 commit 31e7659

4 files changed

Lines changed: 35 additions & 53 deletions

File tree

block/internal/syncing/da_retriever.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ func (r *DARetriever) processBlobs(ctx context.Context, blobs [][]byte, daHeight
189189

190190
// Handle empty data case
191191
if data == nil {
192-
if r.isEmptyDataExpected(header) {
193-
data = r.createEmptyDataForHeader(ctx, header)
192+
if isEmptyDataExpected(header) {
193+
data = createEmptyDataForHeader(ctx, header)
194194
delete(r.pendingHeaders, height)
195195
} else {
196196
// keep header in pending headers until data lands
@@ -289,24 +289,6 @@ func (r *DARetriever) tryDecodeData(bz []byte, daHeight uint64) *types.Data {
289289
return &signedData.Data
290290
}
291291

292-
// isEmptyDataExpected checks if empty data is expected for a header
293-
func (r *DARetriever) isEmptyDataExpected(header *types.SignedHeader) bool {
294-
return len(header.DataHash) == 0 || bytes.Equal(header.DataHash, common.DataHashForEmptyTxs)
295-
}
296-
297-
// createEmptyDataForHeader creates empty data for a header
298-
func (r *DARetriever) createEmptyDataForHeader(ctx context.Context, header *types.SignedHeader) *types.Data {
299-
return &types.Data{
300-
Txs: make(types.Txs, 0),
301-
Metadata: &types.Metadata{
302-
ChainID: header.ChainID(),
303-
Height: header.Height(),
304-
Time: header.BaseHeader.Time,
305-
LastDataHash: nil, // LastDataHash must be filled in the syncer, as it is not available here, block n-1 has not been processed yet.
306-
},
307-
}
308-
}
309-
310292
// assertExpectedProposer validates the proposer address
311293
func (r *DARetriever) assertExpectedProposer(proposerAddr []byte) error {
312294
if string(proposerAddr) != string(r.genesis.ProposerAddress) {
@@ -342,3 +324,21 @@ func (r *DARetriever) assertValidSignedData(signedData *types.SignedData) error
342324

343325
return nil
344326
}
327+
328+
// isEmptyDataExpected checks if empty data is expected for a header
329+
func isEmptyDataExpected(header *types.SignedHeader) bool {
330+
return len(header.DataHash) == 0 || bytes.Equal(header.DataHash, common.DataHashForEmptyTxs)
331+
}
332+
333+
// createEmptyDataForHeader creates empty data for a header
334+
func createEmptyDataForHeader(ctx context.Context, header *types.SignedHeader) *types.Data {
335+
return &types.Data{
336+
Txs: make(types.Txs, 0),
337+
Metadata: &types.Metadata{
338+
ChainID: header.ChainID(),
339+
Height: header.Height(),
340+
Time: header.BaseHeader.Time,
341+
LastDataHash: nil, // LastDataHash must be filled in the syncer, as it is not available here, block n-1 has not been processed yet.
342+
},
343+
}
344+
}

block/internal/syncing/da_retriever_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,6 @@ func TestDARetriever_TryDecodeHeaderAndData_Basic(t *testing.T) {
238238
assert.Nil(t, r.tryDecodeData([]byte("junk"), 1))
239239
}
240240

241-
func TestDARetriever_isEmptyDataExpected(t *testing.T) {
242-
r := &DARetriever{}
243-
h := &types.SignedHeader{}
244-
// when DataHash is nil/empty -> expected empty
245-
assert.True(t, r.isEmptyDataExpected(h))
246-
// when equals to predefined emptyTxs hash -> expected empty
247-
h.DataHash = common.DataHashForEmptyTxs
248-
assert.True(t, r.isEmptyDataExpected(h))
249-
}
250-
251241
func TestDARetriever_tryDecodeData_InvalidSignatureOrProposer(t *testing.T) {
252242
ds := dssync.MutexWrap(datastore.NewMapDatastore())
253243
st := store.New(ds)
@@ -422,3 +412,12 @@ func TestDARetriever_ProcessBlobs_MultipleHeadersCrossDAHeightMatching(t *testin
422412
require.Len(t, r.pendingHeaders, 0, "all headers should be processed")
423413
require.Len(t, r.pendingData, 0, "all data should be processed")
424414
}
415+
416+
func Test_isEmptyDataExpected(t *testing.T) {
417+
h := &types.SignedHeader{}
418+
// when DataHash is nil/empty -> expected empty
419+
assert.True(t, isEmptyDataExpected(h))
420+
// when equals to predefined emptyTxs hash -> expected empty
421+
h.DataHash = common.DataHashForEmptyTxs
422+
assert.True(t, isEmptyDataExpected(h))
423+
}

block/internal/syncing/syncer.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -241,33 +241,15 @@ func (s *Syncer) syncLoop() {
241241
nextDARequestAt := &time.Time{}
242242

243243
for {
244-
wg := sync.WaitGroup{}
245-
246244
select {
247245
case <-s.ctx.Done():
248246
return
249247
default:
250248
}
251-
wg.Add(1)
252-
go func() {
253-
defer wg.Done()
254-
s.processPendingEvents()
255-
}()
256-
257-
wg.Add(1)
258-
go func() {
259-
defer wg.Done()
260-
s.tryFetchFromP2P()
261-
}()
262-
263-
wg.Add(1)
264-
go func() {
265-
defer wg.Done()
266-
s.tryFetchFromDA(nextDARequestAt)
267-
}()
268-
269-
// wait for pending events processing, p2p and da fetching
270-
wg.Wait()
249+
250+
s.processPendingEvents()
251+
s.tryFetchFromP2P()
252+
s.tryFetchFromDA(nextDARequestAt)
271253

272254
// Prevent busy-waiting when no events are processed
273255
select {
@@ -310,6 +292,7 @@ func (s *Syncer) tryFetchFromDA(nextDARequestAt *time.Time) {
310292
*nextDARequestAt = now.Add(backoffDelay)
311293

312294
s.logger.Error().Err(err).Dur("delay", backoffDelay).Uint64("da_height", daHeight).Msg("failed to retrieve from DA; backing off DA requests")
295+
313296
return
314297
}
315298

test/e2e/evm_full_node_e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func TestEvmSequencerWithFullNodeE2E(t *testing.T) {
426426
t.Logf("Full node block height before DA inclusion wait: %d", fnBlockHeightBeforeWait)
427427

428428
// Wait a few seconds to allow DA inclusion to process
429-
waitTime := 5 * time.Second
429+
waitTime := 4 * time.Second
430430
t.Logf("Waiting %v for DA inclusion to process...", waitTime)
431431
time.Sleep(waitTime)
432432

0 commit comments

Comments
 (0)