Skip to content

Commit

Permalink
add l1 block number to SyncHelper *Confirmed methods
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz committed May 15, 2024
1 parent 690ef23 commit de611b4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
10 changes: 5 additions & 5 deletions arbitrum/handler_p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down
6 changes: 3 additions & 3 deletions arbitrum/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions eth/protocols/arb/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions eth/protocols/arb/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ const (
)

type LastConfirmedMsgPacket struct {
Header *types.Header
Node uint64
Header *types.Header
L1BlockNumber uint64
Node uint64
}

type CheckpointMsgPacket struct {
Expand All @@ -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
Expand Down

0 comments on commit de611b4

Please sign in to comment.