@@ -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 }
0 commit comments