Skip to content

Commit a679cc4

Browse files
committed
fix(block/internal/syncing): only publish header/data locally if source DA -- do not pollute p2p; this is an attempt
1 parent d64fa9b commit a679cc4

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

block/internal/common/expected_interfaces.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package common
22

33
import (
44
"context"
5+
pubsub "github.com/libp2p/go-libp2p-pubsub"
56

67
"github.com/celestiaorg/go-header"
78
)
89

910
// broadcaster interface for P2P broadcasting
1011
type Broadcaster[H header.Header[H]] interface {
11-
WriteToStoreAndBroadcast(ctx context.Context, payload H) error
12+
WriteToStoreAndBroadcast(ctx context.Context, payload H, opts ...pubsub.PubOpt) error
1213
Store() header.Store[H]
1314
}

block/internal/syncing/syncer.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
pubsub "github.com/libp2p/go-libp2p-pubsub"
89
"sync"
910
"sync/atomic"
1011
"time"
1112

1213
"github.com/rs/zerolog"
1314
"golang.org/x/sync/errgroup"
1415

15-
"github.com/evstack/ev-node/block/internal/cache"
16-
"github.com/evstack/ev-node/block/internal/common"
1716
coreda "github.com/evstack/ev-node/core/da"
1817
coreexecutor "github.com/evstack/ev-node/core/execution"
18+
19+
"github.com/evstack/ev-node/block/internal/cache"
20+
"github.com/evstack/ev-node/block/internal/common"
1921
"github.com/evstack/ev-node/pkg/config"
2022
"github.com/evstack/ev-node/pkg/genesis"
2123
"github.com/evstack/ev-node/pkg/store"
@@ -329,6 +331,8 @@ func (s *Syncer) tryFetchFromP2P() {
329331

330332
// Process data (if not already processed by headers)
331333
newDataHeight := s.dataStore.Store().Height()
334+
// TODO @MARKO: why only if newDataHeight != newHeaderHeight? why not process
335+
// just if newDataHeight > currentHeight ?
332336
if newDataHeight != newHeaderHeight && newDataHeight > currentHeight {
333337
s.p2pHandler.ProcessDataRange(s.ctx, currentHeight+1, newDataHeight, s.heightInCh)
334338
}
@@ -388,8 +392,16 @@ func (s *Syncer) processHeightEvent(event *common.DAHeightEvent) {
388392
// only save to p2p stores if the event came from DA
389393
if event.Source == common.SourceDA {
390394
g, ctx := errgroup.WithContext(s.ctx)
391-
g.Go(func() error { return s.headerStore.WriteToStoreAndBroadcast(ctx, event.Header) })
392-
g.Go(func() error { return s.dataStore.WriteToStoreAndBroadcast(ctx, event.Data) })
395+
g.Go(func() error {
396+
// broadcast header locally only — prevents spamming the p2p network with old height notifications,
397+
// allowing the syncer to update its target and fill missing blocks
398+
return s.headerStore.WriteToStoreAndBroadcast(ctx, event.Header, pubsub.WithLocalPublication(true))
399+
})
400+
g.Go(func() error {
401+
// broadcast data locally only — prevents spamming the p2p network with old height notifications,
402+
// allowing the syncer to update its target and fill missing blocks
403+
return s.dataStore.WriteToStoreAndBroadcast(ctx, event.Data, pubsub.WithLocalPublication(true))
404+
})
393405
if err := g.Wait(); err != nil {
394406
s.logger.Error().Err(err).Msg("failed to append event header and/or data to p2p store")
395407
}

pkg/sync/sync_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (syncService *SyncService[H]) Store() header.Store[H] {
123123

124124
// WriteToStoreAndBroadcast initializes store if needed and broadcasts provided header or block.
125125
// Note: Only returns an error in case store can't be initialized. Logs error if there's one while broadcasting.
126-
func (syncService *SyncService[H]) WriteToStoreAndBroadcast(ctx context.Context, headerOrData H) error {
126+
func (syncService *SyncService[H]) WriteToStoreAndBroadcast(ctx context.Context, headerOrData H, opts ...pubsub.PubOpt) error {
127127
if syncService.genesis.InitialHeight == 0 {
128128
return fmt.Errorf("invalid initial height; cannot be zero")
129129
}
@@ -148,7 +148,7 @@ func (syncService *SyncService[H]) WriteToStoreAndBroadcast(ctx context.Context,
148148
}
149149

150150
// Broadcast for subscribers
151-
if err := syncService.sub.Broadcast(ctx, headerOrData); err != nil {
151+
if err := syncService.sub.Broadcast(ctx, headerOrData, opts...); err != nil {
152152
// for the first block when starting the app, broadcast error is expected
153153
// as we have already initialized the store for starting the syncer.
154154
// Hence, we ignore the error. Exact reason: validation ignored

0 commit comments

Comments
 (0)