@@ -7,10 +7,11 @@ import (
77 "encoding/binary"
88 "errors"
99 "fmt"
10- "github.com/ethereum/go-ethereum/crypto"
1110 "sync"
1211 "time"
1312
13+ "github.com/ethereum/go-ethereum/crypto"
14+
1415 "github.com/golang/snappy"
1516 lru "github.com/hashicorp/golang-lru/v2"
1617 pubsub "github.com/libp2p/go-libp2p-pubsub"
@@ -21,6 +22,7 @@ import (
2122 "github.com/ethereum/go-ethereum/common"
2223 "github.com/ethereum/go-ethereum/log"
2324
25+ "github.com/ethereum-optimism/optimism/op-node/params"
2426 "github.com/ethereum-optimism/optimism/op-node/rollup"
2527 "github.com/ethereum-optimism/optimism/op-service/eth"
2628 opsigner "github.com/ethereum-optimism/optimism/op-service/signer"
@@ -49,8 +51,10 @@ const (
4951// Message domains, the msg id function uncompresses to keep data monomorphic,
5052// but invalid compressed data will need a unique different id.
5153
52- var MessageDomainInvalidSnappy = [4 ]byte {0 , 0 , 0 , 0 }
53- var MessageDomainValidSnappy = [4 ]byte {1 , 0 , 0 , 0 }
54+ var (
55+ MessageDomainInvalidSnappy = [4 ]byte {0 , 0 , 0 , 0 }
56+ MessageDomainValidSnappy = [4 ]byte {1 , 0 , 0 , 0 }
57+ )
5458
5559type GossipSetupConfigurables interface {
5660 PeerScoringParams () * ScoringParams
@@ -404,7 +408,6 @@ func verifyGatewaySignature(log log.Logger, signatureBytes []byte, messageBytes
404408}
405409
406410func BuildBlocksValidator (log log.Logger , cfg * rollup.Config , runCfg GossipRuntimeConfig , blockVersion eth.BlockVersion ) pubsub.ValidatorEx {
407-
408411 // Seen block hashes per block height
409412 // uint64 -> *seenBlocks
410413 blockHeightLRU , err := lru.New [uint64 , * seenBlocks ](1000 )
@@ -472,10 +475,13 @@ func BuildBlocksValidator(log log.Logger, cfg *rollup.Config, runCfg GossipRunti
472475 // rounding down to seconds is fine here.
473476 now := uint64 (time .Now ().Unix ())
474477
475- // [REJECT] if the `payload.timestamp` is older than 60 seconds in the past
476- if uint64 (payload .Timestamp ) < now - 60 {
477- log .Warn ("payload is too old" , "timestamp" , uint64 (payload .Timestamp ))
478- return pubsub .ValidationReject
478+ // CHANGE(thedevbirb): for chain replication, allow old blocks.
479+ if ! params .BopReplay {
480+ // [REJECT] if the `payload.timestamp` is older than 60 seconds in the past
481+ if uint64 (payload .Timestamp ) < now - 60 {
482+ log .Warn ("payload is too old" , "timestamp" , uint64 (payload .Timestamp ))
483+ return pubsub .ValidationReject
484+ }
479485 }
480486
481487 // [REJECT] if the `payload.timestamp` is more than 5 seconds into the future
@@ -703,7 +709,7 @@ type publisher struct {
703709var _ GossipOut = (* publisher )(nil )
704710
705711func combinePeers (allPeers ... []peer.ID ) []peer.ID {
706- var seen = make (map [peer.ID ]bool )
712+ seen : = make (map [peer.ID ]bool )
707713 var res []peer.ID
708714 for _ , peers := range allPeers {
709715 for _ , p := range peers {
@@ -933,7 +939,6 @@ func newNewFragTopic(ctx context.Context, topicId string, ps *pubsub.PubSub, log
933939 validator ,
934940 pubsub .WithValidatorTimeout (3 * time .Second ),
935941 pubsub .WithValidatorConcurrency (4 ))
936-
937942 if err != nil {
938943 return nil , fmt .Errorf ("failed to register gossip topic: %w" , err )
939944 }
@@ -971,7 +976,6 @@ func sealFragFragTopic(ctx context.Context, topicId string, ps *pubsub.PubSub, l
971976 validator ,
972977 pubsub .WithValidatorTimeout (3 * time .Second ),
973978 pubsub .WithValidatorConcurrency (4 ))
974-
975979 if err != nil {
976980 return nil , fmt .Errorf ("failed to register gossip topic: %w" , err )
977981 }
@@ -1009,7 +1013,6 @@ func newEnvTopic(ctx context.Context, topicId string, ps *pubsub.PubSub, log log
10091013 validator ,
10101014 pubsub .WithValidatorTimeout (3 * time .Second ),
10111015 pubsub .WithValidatorConcurrency (4 ))
1012-
10131016 if err != nil {
10141017 return nil , fmt .Errorf ("failed to register gossip topic: %w" , err )
10151018 }
@@ -1047,7 +1050,6 @@ func newBlockTopic(ctx context.Context, topicId string, ps *pubsub.PubSub, log l
10471050 validator ,
10481051 pubsub .WithValidatorTimeout (3 * time .Second ),
10491052 pubsub .WithValidatorConcurrency (4 ))
1050-
10511053 if err != nil {
10521054 return nil , fmt .Errorf ("failed to register gossip topic: %w" , err )
10531055 }
@@ -1080,8 +1082,10 @@ func newBlockTopic(ctx context.Context, topicId string, ps *pubsub.PubSub, log l
10801082 }, nil
10811083}
10821084
1083- type TopicSubscriber func (ctx context.Context , sub * pubsub.Subscription )
1084- type MessageHandler func (ctx context.Context , from peer.ID , msg any ) error
1085+ type (
1086+ TopicSubscriber func (ctx context.Context , sub * pubsub.Subscription )
1087+ MessageHandler func (ctx context.Context , from peer.ID , msg any ) error
1088+ )
10851089
10861090func NewFragHandler (onNewFrag func (ctx context.Context , from peer.ID , msg * eth.SignedNewFrag ) error ) MessageHandler {
10871091 return func (ctx context.Context , from peer.ID , msg any ) error {
0 commit comments