Skip to content

Commit

Permalink
fix(taiko-client): fix lastVerifiedBlockHash fetch (#18277)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Oct 22, 2024
1 parent be08e8b commit 8512f45
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
22 changes: 19 additions & 3 deletions packages/taiko-client/driver/chain_syncer/beaconsync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/eth/downloader"
Expand Down Expand Up @@ -71,9 +72,24 @@ func (s *Syncer) TriggerBeaconSync(blockID uint64) error {
return fmt.Errorf("unexpected NewPayload response status: %s", status.Status)
}

lastVerifiedBlockHash, err := s.rpc.GetLastVerifiedBlockHash(s.ctx)
if err != nil {
return fmt.Errorf("failed to fetch the last verified block hash: %w", err)
var lastVerifiedBlockHash common.Hash
if lastVerifiedBlockHash, err = s.rpc.GetLastVerifiedBlockHash(s.ctx); err != nil {
log.Debug("Failed to fetch the last verified block hash", "err", err)

stateVars, err := s.rpc.GetProtocolStateVariables(&bind.CallOpts{Context: s.ctx})
if err != nil {
return fmt.Errorf("failed to fetch protocol state variables: %w", err)
}

lastVerifiedBlockHeader, err := s.rpc.L2CheckPoint.HeaderByNumber(
s.ctx,
new(big.Int).SetUint64(stateVars.B.LastVerifiedBlockId),
)
if err != nil {
return fmt.Errorf("failed to fetch the last verified block hash: %w", err)
}

lastVerifiedBlockHash = lastVerifiedBlockHeader.Hash()
}

fcRes, err := s.rpc.L2Engine.ForkchoiceUpdate(s.ctx, &engine.ForkchoiceStateV1{
Expand Down
21 changes: 18 additions & 3 deletions packages/taiko-client/driver/chain_syncer/blob/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,24 @@ func (s *Syncer) insertNewHead(
return nil, fmt.Errorf("failed to create execution payloads: %w", err)
}

lastVerifiedBlockHash, err := s.rpc.GetLastVerifiedBlockHash(ctx)
if err != nil {
return nil, fmt.Errorf("failed to fetch the last verified block hash: %w", err)
var lastVerifiedBlockHash common.Hash
if lastVerifiedBlockHash, err = s.rpc.GetLastVerifiedBlockHash(ctx); err != nil {
log.Debug("Failed to fetch last verified block hash", "error", err)

stateVars, err := s.rpc.GetProtocolStateVariables(&bind.CallOpts{Context: ctx})
if err != nil {
return nil, fmt.Errorf("failed to fetch protocol state variables: %w", err)
}

lastVerifiedBlockHeader, err := s.rpc.L2.HeaderByNumber(
ctx,
new(big.Int).SetUint64(stateVars.B.LastVerifiedBlockId),
)
if err != nil {
return nil, fmt.Errorf("failed to fetch last verified block: %w", err)
}

lastVerifiedBlockHash = lastVerifiedBlockHeader.Hash()
}

fc := &engine.ForkchoiceStateV1{
Expand Down

0 comments on commit 8512f45

Please sign in to comment.