Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(taiko-client): check the blockID of the last verified block before using it as FinalizedBlockHash #18739

Merged
merged 5 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/taiko-client/driver/chain_syncer/blob/soft_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (s *Syncer) InsertSoftBlockFromTransactionsBatch(
return nil, fmt.Errorf("unexpected NewPayload response status: %s", execStatus.Status)
}

lastVerifiedBlockHash, err := s.rpc.GetLastVerifiedBlockHash(ctx)
lastVerifiedBlockInfo, err := s.rpc.GetLastVerifiedBlock(ctx)
if err != nil {
return nil, fmt.Errorf("failed to fetch last verified block hash: %w", err)
}
Expand All @@ -245,7 +245,7 @@ func (s *Syncer) InsertSoftBlockFromTransactionsBatch(
fc = &engine.ForkchoiceStateV1{
HeadBlockHash: payload.BlockHash,
SafeBlockHash: canonicalHead.L2BlockHash,
FinalizedBlockHash: lastVerifiedBlockHash,
FinalizedBlockHash: lastVerifiedBlockInfo.BlockHash,
}
fcRes, err = s.rpc.L2Engine.ForkchoiceUpdate(ctx, fc, nil)
if err != nil {
Expand Down
23 changes: 6 additions & 17 deletions packages/taiko-client/driver/chain_syncer/blob/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,23 +409,12 @@ func (s *Syncer) insertNewHead(
}

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()
lastVerifiedBlockInfo, err := s.rpc.GetLastVerifiedBlock(ctx)
if err != nil {
return nil, fmt.Errorf("failed to fetch last verified block: %w", err)
}
if payload.Number > lastVerifiedBlockInfo.BlockId {
lastVerifiedBlockHash = lastVerifiedBlockInfo.BlockHash
YoGhurt111 marked this conversation as resolved.
Show resolved Hide resolved
}

fc := &engine.ForkchoiceStateV1{
Expand Down
16 changes: 8 additions & 8 deletions packages/taiko-client/pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,17 +500,17 @@ func (c *Client) GetProtocolStateVariables(opts *bind.CallOpts) (*struct {
return GetProtocolStateVariables(c.TaikoL1, opts)
}

// GetLastVerifiedBlockHash gets the last verified block hash from TaikoL1 contract.
func (c *Client) GetLastVerifiedBlockHash(ctx context.Context) (common.Hash, error) {
// GetLastVerifiedBlock gets the last verified block from TaikoL1 contract.
func (c *Client) GetLastVerifiedBlock(ctx context.Context) (struct {
BlockId uint64 //nolint:stylecheck
BlockHash [32]byte
StateRoot [32]byte
VerifiedAt uint64
}, error) {
ctxWithTimeout, cancel := context.WithTimeout(ctx, defaultTimeout)
defer cancel()

b, err := c.TaikoL1.GetLastVerifiedBlock(&bind.CallOpts{Context: ctxWithTimeout})
if err != nil {
return common.Hash{}, err
}

return b.BlockHash, nil
return c.TaikoL1.GetLastVerifiedBlock(&bind.CallOpts{Context: ctxWithTimeout})
}

// GetL2BlockInfo fetches the L2 block information from the protocol.
Expand Down
Loading