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

Commit

Permalink
feat(bindings): update Go contract bindings (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Nov 2, 2023
1 parent 405b9ed commit b155b5a
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 54 deletions.
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0f41cb6d94caf3c0e04f4b63e1cea83024c20869
b6abb0d5e06860fb731b4de0d812c82c6985f1f7
57 changes: 30 additions & 27 deletions bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ func (d *Driver) reportProtocolStatus() {

log.Info(
"📖 Protocol status",
"lastVerifiedBlockId", vars.LastVerifiedBlockId,
"pendingBlocks", vars.NumBlocks-vars.LastVerifiedBlockId-1,
"availableSlots", vars.LastVerifiedBlockId+maxNumBlocks-vars.NumBlocks,
"lastVerifiedBlockId", vars.B.LastVerifiedBlockId,
"pendingBlocks", vars.B.NumBlocks-vars.B.LastVerifiedBlockId-1,
"availableSlots", vars.B.LastVerifiedBlockId+maxNumBlocks-vars.B.NumBlocks,
)
}
}
Expand Down
12 changes: 6 additions & 6 deletions driver/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func (s *State) init(ctx context.Context) error {
return err
}

log.Info("Genesis L1 height", "height", stateVars.GenesisHeight)
s.GenesisL1Height = new(big.Int).SetUint64(stateVars.GenesisHeight)
log.Info("Genesis L1 height", "height", stateVars.A.GenesisHeight)
s.GenesisL1Height = new(big.Int).SetUint64(stateVars.A.GenesisHeight)

// Set the L2 head's latest known L1 origin as current L1 sync cursor.
latestL2KnownL1Header, err := s.rpc.LatestL2KnownL1Header(ctx)
Expand All @@ -123,18 +123,18 @@ func (s *State) init(ctx context.Context) error {

snippet, err := s.rpc.TaikoL1.GetSyncedSnippet(
&bind.CallOpts{Context: ctx},
stateVars.LastVerifiedBlockId,
stateVars.B.LastVerifiedBlockId,
)
if err != nil {
return err
}

s.setLatestVerifiedBlockHash(
new(big.Int).SetUint64(stateVars.LastVerifiedBlockId),
new(big.Int).SetUint64(stateVars.LastVerifiedBlockId),
new(big.Int).SetUint64(stateVars.B.LastVerifiedBlockId),
new(big.Int).SetUint64(stateVars.B.LastVerifiedBlockId),
snippet.BlockHash,
)
s.setHeadBlockID(new(big.Int).SetUint64(stateVars.NumBlocks - 1))
s.setHeadBlockID(new(big.Int).SetUint64(stateVars.B.NumBlocks - 1))

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) {
return nil, err
}

isArchive, err := IsArchiveNode(ctxWithTimeout, l1RPC, stateVars.GenesisHeight)
isArchive, err := IsArchiveNode(ctxWithTimeout, l1RPC, stateVars.A.GenesisHeight)
if err != nil {
return nil, err
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *Client) ensureGenesisMatched(ctx context.Context) error {

// Fetch the genesis `BlockVerified` event.
iter, err := c.TaikoL1.FilterBlockVerified(
&bind.FilterOpts{Start: stateVars.GenesisHeight, End: &stateVars.GenesisHeight, Context: ctxWithTimeout},
&bind.FilterOpts{Start: stateVars.A.GenesisHeight, End: &stateVars.A.GenesisHeight, Context: ctxWithTimeout},
[]*big.Int{common.Big0},
nil,
nil,
Expand Down Expand Up @@ -154,7 +154,7 @@ func (c *Client) GetGenesisL1Header(ctx context.Context) (*types.Header, error)
return nil, err
}

return c.L1.HeaderByNumber(ctxWithTimeout, new(big.Int).SetUint64(stateVars.GenesisHeight))
return c.L1.HeaderByNumber(ctxWithTimeout, new(big.Int).SetUint64(stateVars.A.GenesisHeight))
}

// L2ParentByBlockId fetches the block header from L2 execution engine with the largest block id that
Expand Down Expand Up @@ -308,7 +308,7 @@ func (c *Client) L2ExecutionEngineSyncProgress(ctx context.Context) (*L2SyncProg
if err != nil {
return err
}
progress.HighestBlockID = new(big.Int).SetUint64(stateVars.NumBlocks - 1)
progress.HighestBlockID = new(big.Int).SetUint64(stateVars.B.NumBlocks - 1)
return nil
})
g.Go(func() error {
Expand Down Expand Up @@ -336,7 +336,10 @@ func (c *Client) L2ExecutionEngineSyncProgress(ctx context.Context) (*L2SyncProg
}

// GetProtocolStateVariables gets the protocol states from TaikoL1 contract.
func (c *Client) GetProtocolStateVariables(opts *bind.CallOpts) (*bindings.TaikoDataStateVariables, error) {
func (c *Client) GetProtocolStateVariables(opts *bind.CallOpts) (*struct {
A bindings.TaikoDataSlotA
B bindings.TaikoDataSlotB
}, error) {
var (
ctxWithTimeout context.Context
cancel context.CancelFunc
Expand Down Expand Up @@ -399,7 +402,7 @@ func (c *Client) CheckL1ReorgFromL2EE(ctx context.Context, blockID *big.Int) (bo

if l1CurrentToReset, err = c.L1.HeaderByNumber(
ctxWithTimeout,
new(big.Int).SetUint64(stateVars.GenesisHeight),
new(big.Int).SetUint64(stateVars.A.GenesisHeight),
); err != nil {
return false, nil, nil, err
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/rpc/methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ func TestCheckL1ReorgFromL1Cursor(t *testing.T) {
stateVar, err := client.TaikoL1.GetStateVariables(nil)
require.Nil(t, err)

reorged, _, _, err := client.CheckL1ReorgFromL1Cursor(context.Background(), l1Head, stateVar.GenesisHeight)
reorged, _, _, err := client.CheckL1ReorgFromL1Cursor(context.Background(), l1Head, stateVar.A.GenesisHeight)
require.Nil(t, err)
require.False(t, reorged)

l1Head.BaseFee = new(big.Int).Add(l1Head.BaseFee, common.Big1)

reorged, newL1Current, _, err = client.CheckL1ReorgFromL1Cursor(context.Background(), l1Head, stateVar.GenesisHeight)
reorged, newL1Current, _, err = client.CheckL1ReorgFromL1Cursor(
context.Background(),
l1Head,
stateVar.A.GenesisHeight,
)
require.Nil(t, err)
require.True(t, reorged)
require.Equal(t, l1Head.ParentHash, newL1Current.Hash())
Expand Down
5 changes: 4 additions & 1 deletion pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ var (
func GetProtocolStateVariables(
taikoL1Client *bindings.TaikoL1Client,
opts *bind.CallOpts,
) (*bindings.TaikoDataStateVariables, error) {
) (*struct {
A bindings.TaikoDataSlotA
B bindings.TaikoDataSlotB
}, error) {
stateVars, err := taikoL1Client.GetStateVariables(opts)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion prover/proof_submitter/transaction/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (s *Sender) validateProof(ctx context.Context, proofWithHeader *proofProduc
)
return false, err
}
latestVerifiedId := stateVars.LastVerifiedBlockId
latestVerifiedId := stateVars.B.LastVerifiedBlockId
if new(big.Int).SetUint64(latestVerifiedId).Cmp(proofWithHeader.BlockID) >= 0 {
log.Info(
"Block is already verified, skip current proof submission",
Expand Down
10 changes: 5 additions & 5 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,11 @@ func (p *Prover) initL1Current(startingBlockID *big.Int) error {
if err != nil {
return err
}
p.genesisHeightL1 = stateVars.GenesisHeight
p.genesisHeightL1 = stateVars.A.GenesisHeight

if startingBlockID == nil {
if stateVars.LastVerifiedBlockId == 0 {
genesisL1Header, err := p.rpc.L1.HeaderByNumber(p.ctx, new(big.Int).SetUint64(stateVars.GenesisHeight))
if stateVars.B.LastVerifiedBlockId == 0 {
genesisL1Header, err := p.rpc.L1.HeaderByNumber(p.ctx, new(big.Int).SetUint64(stateVars.A.GenesisHeight))
if err != nil {
return err
}
Expand All @@ -793,7 +793,7 @@ func (p *Prover) initL1Current(startingBlockID *big.Int) error {
return nil
}

startingBlockID = new(big.Int).SetUint64(stateVars.LastVerifiedBlockId)
startingBlockID = new(big.Int).SetUint64(stateVars.B.LastVerifiedBlockId)
}

log.Info("Init L1Current cursor", "startingBlockID", startingBlockID)
Expand Down Expand Up @@ -827,7 +827,7 @@ func (p *Prover) isBlockVerified(id *big.Int) (bool, error) {
return false, err
}

return id.Uint64() <= stateVars.LastVerifiedBlockId, nil
return id.Uint64() <= stateVars.B.LastVerifiedBlockId, nil
}

// initSubscription initializes all subscriptions in current prover instance.
Expand Down
4 changes: 2 additions & 2 deletions prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ func (s *ProverTestSuite) TestIsBlockVerified() {
vars, err := s.p.rpc.TaikoL1.GetStateVariables(nil)
s.Nil(err)

verified, err := s.p.isBlockVerified(new(big.Int).SetUint64(vars.LastVerifiedBlockId))
verified, err := s.p.isBlockVerified(new(big.Int).SetUint64(vars.B.LastVerifiedBlockId))
s.Nil(err)
s.True(verified)

verified, err = s.p.isBlockVerified(new(big.Int).SetUint64(vars.LastVerifiedBlockId + 1))
verified, err = s.p.isBlockVerified(new(big.Int).SetUint64(vars.B.LastVerifiedBlockId + 1))
s.Nil(err)
s.False(verified)
}
Expand Down

0 comments on commit b155b5a

Please sign in to comment.