From de611b4f7590c544d7a6c5b7991a439060f2bdae Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 15 May 2024 21:08:06 +0200 Subject: [PATCH] add l1 block number to SyncHelper *Confirmed methods --- arbitrum/handler_p2p.go | 10 +++++----- arbitrum/sync_test.go | 6 +++--- eth/protocols/arb/handler.go | 9 +++++---- eth/protocols/arb/protocol.go | 9 +++++---- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/arbitrum/handler_p2p.go b/arbitrum/handler_p2p.go index cca9296b06..fbdffca0aa 100644 --- a/arbitrum/handler_p2p.go +++ b/arbitrum/handler_p2p.go @@ -40,10 +40,10 @@ import ( ) type SyncHelper interface { - LastConfirmed() (*types.Header, uint64, error) + LastConfirmed() (*types.Header, uint64, uint64, error) LastCheckpoint() (*types.Header, error) CheckpointSupported(*types.Header) (bool, error) - ValidateConfirmed(*types.Header, uint64) (bool, error) + ValidateConfirmed(*types.Header, uint64, uint64) (bool, error) } type Peer struct { @@ -272,7 +272,7 @@ func (h *arbHandler) PeerInfo(id enode.ID) interface{} { return nil } -func (h *arbHandler) HandleLastConfirmed(peer *arb.Peer, confirmed *types.Header, node uint64) { +func (h *arbHandler) HandleLastConfirmed(peer *arb.Peer, confirmed *types.Header, l1BlockNumber uint64, node uint64) { protoHandler := (*protocolHandler)(h) validated := false valid := false @@ -285,7 +285,7 @@ func (h *arbHandler) HandleLastConfirmed(peer *arb.Peer, confirmed *types.Header } if !validated { var err error - valid, err = h.helper.ValidateConfirmed(confirmed, node) + valid, err = h.helper.ValidateConfirmed(confirmed, l1BlockNumber, node) if err != nil { log.Error("error in validate confirmed", "id", peer.ID(), "err", err) return @@ -344,7 +344,7 @@ func (h *arbHandler) HandleCheckpoint(peer *arb.Peer, checkpoint *types.Header, protoHandler.advanceCheckpoint(checkpoint) } -func (h *arbHandler) LastConfirmed() (*types.Header, uint64, error) { +func (h *arbHandler) LastConfirmed() (*types.Header, uint64, uint64, error) { return h.helper.LastConfirmed() } diff --git a/arbitrum/sync_test.go b/arbitrum/sync_test.go index 2908526d50..8e01ed8c03 100644 --- a/arbitrum/sync_test.go +++ b/arbitrum/sync_test.go @@ -61,8 +61,8 @@ type dummySyncHelper struct { checkpoint *types.Header } -func (d *dummySyncHelper) LastConfirmed() (*types.Header, uint64, error) { - return d.confirmed, 0, nil +func (d *dummySyncHelper) LastConfirmed() (*types.Header, uint64, uint64, error) { + return d.confirmed, 0, 0, nil } func (d *dummySyncHelper) LastCheckpoint() (*types.Header, error) { @@ -76,7 +76,7 @@ func (d *dummySyncHelper) CheckpointSupported(*types.Header) (bool, error) { return true, nil } -func (d *dummySyncHelper) ValidateConfirmed(header *types.Header, node uint64) (bool, error) { +func (d *dummySyncHelper) ValidateConfirmed(header *types.Header, l1BlockNumber uint64, node uint64) (bool, error) { if d.confirmed == nil { return true, nil } diff --git a/eth/protocols/arb/handler.go b/eth/protocols/arb/handler.go index 8a2f99b8e4..b48822b3c0 100644 --- a/eth/protocols/arb/handler.go +++ b/eth/protocols/arb/handler.go @@ -81,13 +81,14 @@ func HandleMessage(backend Backend, peer *Peer) error { } switch { case msg.Code == GetLastConfirmedMsg: - confirmed, node, err := backend.LastConfirmed() + confirmed, l1BlockNumber, node, err := backend.LastConfirmed() if err != nil || confirmed == nil { return err } response := LastConfirmedMsgPacket{ - Header: confirmed, - Node: node, + Header: confirmed, + L1BlockNumber: l1BlockNumber, + Node: node, } return p2p.Send(peer.rw, LastConfirmedMsg, &response) case msg.Code == LastConfirmedMsg: @@ -99,7 +100,7 @@ func HandleMessage(backend Backend, peer *Peer) error { if incoming.Header == nil { return nil } - backend.HandleLastConfirmed(peer, incoming.Header, incoming.Node) + backend.HandleLastConfirmed(peer, incoming.Header, incoming.L1BlockNumber, incoming.Node) return nil case msg.Code == GetLastCheckpointMsg: checkpoint, err := backend.LastCheckpoint() diff --git a/eth/protocols/arb/protocol.go b/eth/protocols/arb/protocol.go index 62a377f104..57eed84670 100644 --- a/eth/protocols/arb/protocol.go +++ b/eth/protocols/arb/protocol.go @@ -34,8 +34,9 @@ const ( ) type LastConfirmedMsgPacket struct { - Header *types.Header - Node uint64 + Header *types.Header + L1BlockNumber uint64 + Node uint64 } type CheckpointMsgPacket struct { @@ -62,9 +63,9 @@ type Handler func(peer *Peer) error // callback methods to invoke on remote deliveries. type Backend interface { PeerInfo(id enode.ID) interface{} - HandleLastConfirmed(peer *Peer, confirmed *types.Header, node uint64) + HandleLastConfirmed(peer *Peer, confirmed *types.Header, l1BlockNumber uint64, node uint64) HandleCheckpoint(peer *Peer, header *types.Header, supported bool) - LastConfirmed() (*types.Header, uint64, error) + LastConfirmed() (*types.Header, uint64, uint64, error) LastCheckpoint() (*types.Header, error) CheckpointSupported(*types.Header) (bool, error) // RunPeer is invoked when a peer joins on the `eth` protocol. The handler