Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(driver): introduce StateVariablesUpdated event (#666)
Browse files Browse the repository at this point in the history
Co-authored-by: maskpp <[email protected]>
  • Loading branch information
davidtaikocha and mask-pp authored Mar 27, 2024
1 parent 45ef240 commit 8ecd440
Show file tree
Hide file tree
Showing 5 changed files with 427 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fcc2800cc95a6b92e4a8d11c9d5e15d0ed0abeca
dd4136ae250a8696953a331c13de0a04a67df096
136 changes: 135 additions & 1 deletion bindings/gen_lib_verifying.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

270 changes: 269 additions & 1 deletion bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,11 @@ func (s *Syncer) fillForkchoiceState(
}

// Fetch the latest verified block's header from protocol.
variables, err := s.rpc.GetProtocolStateVariables(
&bind.CallOpts{Context: ctx, BlockNumber: new(big.Int).SetUint64(event.Raw.BlockNumber)},
)
variables, err := s.rpc.GetTaikoDataSlotBByNumber(ctx, event.Raw.BlockNumber)
if err != nil {
return err
}
finalizeHeader, err := s.rpc.L2.HeaderByNumber(ctx, new(big.Int).SetUint64(variables.B.LastVerifiedBlockId))
finalizeHeader, err := s.rpc.L2.HeaderByNumber(ctx, new(big.Int).SetUint64(variables.LastVerifiedBlockId))
if err != nil {
return err
}
Expand Down Expand Up @@ -597,9 +595,11 @@ func (s *Syncer) retrievePastBlock(
l1Origin, err := s.rpc.L2.L1OriginByID(ctx, new(big.Int).SetUint64(currentBlockID))
if err != nil {
if err.Error() == ethereum.NotFound.Error() {
log.Info("L1Origin not found in retrievePastBlock because the L2 EE is just synced through P2P",
log.Info(
"L1Origin not found in retrievePastBlock because the L2 EE is just synced through P2P",
"blockID",
currentBlockID)
currentBlockID,
)
// Can't find l1Origin in L2 EE, so we call the contract to get block info
blockInfo, err := s.rpc.TaikoL1.GetBlock(&bind.CallOpts{Context: ctx}, currentBlockID)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,3 +685,19 @@ func (c *Client) GetTiers(ctx context.Context) ([]*TierProviderTierWithID, error

return tiers, nil
}

// GetTaikoDataSlotBByNumber fetches the state variables by block number.
func (c *Client) GetTaikoDataSlotBByNumber(ctx context.Context, number uint64) (*bindings.TaikoDataSlotB, error) {
iter, err := c.TaikoL1.FilterStateVariablesUpdated(
&bind.FilterOpts{Context: ctx, Start: number, End: &number},
)
if err != nil {
return nil, err
}

for iter.Next() {
return &iter.Event.SlotB, nil
}

return nil, fmt.Errorf("failed to get state variables by block number %d", number)
}

0 comments on commit 8ecd440

Please sign in to comment.