From 76c89e684e419787c78c96296e75dc196f4a6aad Mon Sep 17 00:00:00 2001 From: kaiden Date: Mon, 6 Jan 2025 21:07:40 +1100 Subject: [PATCH] fix/revert rollup --- sequencer/common/ethrollup.go | 8 +-- sequencer/coordinator/txmanager.go | 2 +- .../database/historydb/historydb_test.go | 2 +- sequencer/database/historydb/views.go | 2 +- sequencer/eth/rollup.go | 68 +++++++++---------- sequencer/synchronizer/synchronizer.go | 4 +- sequencer/synchronizer/synchronizer_test.go | 4 +- sequencer/test/ethClient.go | 14 ++-- 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/sequencer/common/ethrollup.go b/sequencer/common/ethrollup.go index df335bc..91da9ca 100644 --- a/sequencer/common/ethrollup.go +++ b/sequencer/common/ethrollup.go @@ -75,10 +75,10 @@ type BucketUpdate struct { // RollupVariables are the variables of the Rollup Smart Contract type RollupVariables struct { - EthBlockNum int64 `meddler:"eth_block_num"` - ForgeL1BatchTimeout int64 `meddler:"forge_l1_timeout" validate:"required"` - Buckets []BucketParams `meddler:"buckets,json"` - SafeMode bool `meddler:"safe_mode"` + EthBlockNum int64 `meddler:"eth_block_num"` + ForgeL1L2BatchTimeout int64 `meddler:"forge_l1_timeout" validate:"required"` + Buckets []BucketParams `meddler:"buckets,json"` + SafeMode bool `meddler:"safe_mode"` } // RollupVerifierStruct is the information about verifiers of the Rollup Smart Contract diff --git a/sequencer/coordinator/txmanager.go b/sequencer/coordinator/txmanager.go index 9c536e3..c9e325e 100644 --- a/sequencer/coordinator/txmanager.go +++ b/sequencer/coordinator/txmanager.go @@ -303,7 +303,7 @@ func (t *TxManager) mustL1Batch(blockNum int64) bool { if t.stats.Sync.LastL1BatchBlock > lastL1BatchBlockNum { lastL1BatchBlockNum = t.stats.Sync.LastL1BatchBlock } - return blockNum-lastL1BatchBlockNum >= t.vars.Rollup.ForgeL1BatchTimeout-1 + return blockNum-lastL1BatchBlockNum >= t.vars.Rollup.ForgeL1L2BatchTimeout-1 } func (t *TxManager) shouldSendRollupForgeBatch(batchInfo *BatchInfo) error { diff --git a/sequencer/database/historydb/historydb_test.go b/sequencer/database/historydb/historydb_test.go index 838a62b..ecefd38 100644 --- a/sequencer/database/historydb/historydb_test.go +++ b/sequencer/database/historydb/historydb_test.go @@ -581,7 +581,7 @@ func exampleInitSCVars() *common.RollupVariables { // *common.AuctionVariables, rollup := &common.RollupVariables{ EthBlockNum: 0, // FeeAddToken: big.NewInt(10), - ForgeL1BatchTimeout: 12, + ForgeL1L2BatchTimeout: 12, // WithdrawalDelay: 13, Buckets: []common.BucketParams{}, SafeMode: false, diff --git a/sequencer/database/historydb/views.go b/sequencer/database/historydb/views.go index 389e64d..e1609f6 100644 --- a/sequencer/database/historydb/views.go +++ b/sequencer/database/historydb/views.go @@ -141,7 +141,7 @@ func NewRollupVariablesAPI(rollupVariables *common.RollupVariables) *RollupVaria rollupVars := RollupVariablesAPI{ EthBlockNum: rollupVariables.EthBlockNum, // FeeAddToken: apitypes.NewBigIntStr(rollupVariables.FeeAddToken), - ForgeL1BatchTimeout: rollupVariables.ForgeL1BatchTimeout, + ForgeL1BatchTimeout: rollupVariables.ForgeL1L2BatchTimeout, // WithdrawalDelay: rollupVariables.WithdrawalDelay, SafeMode: rollupVariables.SafeMode, Buckets: buckets, diff --git a/sequencer/eth/rollup.go b/sequencer/eth/rollup.go index cff05d3..664d38f 100644 --- a/sequencer/eth/rollup.go +++ b/sequencer/eth/rollup.go @@ -41,7 +41,7 @@ type RollupState struct { // ExitNullifierMap map[[256 / 8]byte]bool ExitNullifierMap map[int64]map[int64]bool // batchNum -> idx -> bool MapL1TxQueue map[int64]*QueueStruct - LastL1Batch int64 + LastL1L2Batch int64 CurrentToForgeL1TxsNum int64 LastToForgeL1TxsNum int64 CurrentIdx int64 @@ -50,9 +50,9 @@ type RollupState struct { // RollupEventInitialize is the InitializeHermezEvent event of the // Smart Contract type RollupEventInitialize struct { - ForgeL1BatchTimeout uint8 - FeeAddToken *big.Int - WithdrawalDelay uint64 + ForgeL1L2BatchTimeout uint8 + FeeAddToken *big.Int + WithdrawalDelay uint64 } // RollupEventL1UserTx is an event of the Rollup Smart Contract @@ -79,9 +79,9 @@ type RollupEventForgeBatch struct { GasPrice *big.Int } -// RollupEventUpdateForgeL1BatchTimeout is an event of the Rollup Smart Contract -type RollupEventUpdateForgeL1BatchTimeout struct { - NewForgeL1BatchTimeout int64 +// RollupEventUpdateForgeL1L2BatchTimeout is an event of the Rollup Smart Contract +type RollupEventUpdateForgeL1L2BatchTimeout struct { + NewForgeL1L2BatchTimeout int64 } // RollupEventUpdateFeeAddToken is an event of the Rollup Smart Contract @@ -146,26 +146,26 @@ type RollupEventSafeMode struct{} // RollupEvents is the list of events in a block of the Rollup Smart Contract type RollupEvents struct { - L1UserTx []RollupEventL1UserTx - ForgeBatch []RollupEventForgeBatch - UpdateForgeL1BatchTimeout []RollupEventUpdateForgeL1BatchTimeout - UpdateFeeAddToken []RollupEventUpdateFeeAddToken - Withdraw []RollupEventWithdraw - UpdateWithdrawalDelay []RollupEventUpdateWithdrawalDelay - UpdateBucketWithdraw []RollupEventUpdateBucketWithdraw - UpdateBucketsParameters []RollupEventUpdateBucketsParameters - UpdateTokenExchange []RollupEventUpdateTokenExchange - SafeMode []RollupEventSafeMode + L1UserTx []RollupEventL1UserTx + ForgeBatch []RollupEventForgeBatch + UpdateForgeL1L2BatchTimeout []RollupEventUpdateForgeL1L2BatchTimeout + UpdateFeeAddToken []RollupEventUpdateFeeAddToken + Withdraw []RollupEventWithdraw + UpdateWithdrawalDelay []RollupEventUpdateWithdrawalDelay + UpdateBucketWithdraw []RollupEventUpdateBucketWithdraw + UpdateBucketsParameters []RollupEventUpdateBucketsParameters + UpdateTokenExchange []RollupEventUpdateTokenExchange + SafeMode []RollupEventSafeMode } // NewRollupEvents creates an empty RollupEvents with the slices initialized. func NewRollupEvents() RollupEvents { return RollupEvents{ - L1UserTx: make([]RollupEventL1UserTx, 0), - ForgeBatch: make([]RollupEventForgeBatch, 0), - UpdateForgeL1BatchTimeout: make([]RollupEventUpdateForgeL1BatchTimeout, 0), - UpdateFeeAddToken: make([]RollupEventUpdateFeeAddToken, 0), - Withdraw: make([]RollupEventWithdraw, 0), + L1UserTx: make([]RollupEventL1UserTx, 0), + ForgeBatch: make([]RollupEventForgeBatch, 0), + UpdateForgeL1L2BatchTimeout: make([]RollupEventUpdateForgeL1L2BatchTimeout, 0), + UpdateFeeAddToken: make([]RollupEventUpdateFeeAddToken, 0), + Withdraw: make([]RollupEventWithdraw, 0), } } @@ -195,7 +195,7 @@ type rollupForgeBatchArgsAux struct { NewScoreRoot *big.Int NewExitRoot *big.Int EncodedL1CoordinatorTx []byte - L1TxsData []byte + L1L2TxsData []byte FeeIdxCoordinator []byte // Circuit selector VerifierIdx uint8 @@ -246,10 +246,10 @@ type RollupClient struct { // RollupVariables returns the RollupVariables from the initialize event func (ei *RollupEventInitialize) RollupVariables() *common.RollupVariables { return &common.RollupVariables{ - EthBlockNum: 0, - ForgeL1BatchTimeout: int64(ei.ForgeL1BatchTimeout), - Buckets: []common.BucketParams{}, - SafeMode: false, + EthBlockNum: 0, + ForgeL1L2BatchTimeout: int64(ei.ForgeL1L2BatchTimeout), + Buckets: []common.BucketParams{}, + SafeMode: false, } } @@ -320,8 +320,8 @@ var ( "L1UserTxEvent(uint32,uint8,bytes)")) logSYBForgeBatch = crypto.Keccak256Hash([]byte( "ForgeBatch(uint32,uint16)")) - logSYBUpdateForgeL1BatchTimeout = crypto.Keccak256Hash([]byte( - "UpdateForgeL1BatchTimeout(uint8)")) + logSYBUpdateForgeL1L2BatchTimeout = crypto.Keccak256Hash([]byte( + "UpdateForgeL1L2BatchTimeout(uint8)")) logSYBWithdrawEvent = crypto.Keccak256Hash([]byte( "WithdrawEvent(uint48,uint32,bool)")) logSYBUpdateBucketWithdraw = crypto.Keccak256Hash([]byte( @@ -414,7 +414,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64, } forgeBatch.GasUsed = txReceipt.GasUsed rollupEvents.ForgeBatch = append(rollupEvents.ForgeBatch, forgeBatch) - case logSYBUpdateForgeL1BatchTimeout: + case logSYBUpdateForgeL1L2BatchTimeout: var updateForgeL1BatchTimeout struct { NewForgeL1BatchTimeout uint8 } @@ -423,9 +423,9 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64, if err != nil { return nil, common.Wrap(err) } - rollupEvents.UpdateForgeL1BatchTimeout = append(rollupEvents.UpdateForgeL1BatchTimeout, - RollupEventUpdateForgeL1BatchTimeout{ - NewForgeL1BatchTimeout: int64(updateForgeL1BatchTimeout.NewForgeL1BatchTimeout), + rollupEvents.UpdateForgeL1L2BatchTimeout = append(rollupEvents.UpdateForgeL1L2BatchTimeout, + RollupEventUpdateForgeL1L2BatchTimeout{ + NewForgeL1L2BatchTimeout: int64(updateForgeL1BatchTimeout.NewForgeL1BatchTimeout), }) case logSYBWithdrawEvent: var withdraw RollupEventWithdraw @@ -588,7 +588,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, numTxsL1Coord := len(aux.EncodedL1CoordinatorTx) / common.RollupConstL1CoordinatorTotalBytes l1UserTxsData := []byte{} if l1UserTxsLen > 0 { - l1UserTxsData = aux.L1TxsData[:numBytesL1TxUser] + l1UserTxsData = aux.L1L2TxsData[:numBytesL1TxUser] } for i := 0; i < int(l1UserTxsLen); i++ { l1Tx, err := diff --git a/sequencer/synchronizer/synchronizer.go b/sequencer/synchronizer/synchronizer.go index 068267e..b371674 100644 --- a/sequencer/synchronizer/synchronizer.go +++ b/sequencer/synchronizer/synchronizer.go @@ -820,8 +820,8 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e varsUpdate := false - for _, evt := range rollupEvents.UpdateForgeL1BatchTimeout { - s.vars.Rollup.ForgeL1BatchTimeout = evt.NewForgeL1BatchTimeout + for _, evt := range rollupEvents.UpdateForgeL1L2BatchTimeout { + s.vars.Rollup.ForgeL1L2BatchTimeout = evt.NewForgeL1L2BatchTimeout varsUpdate = true } diff --git a/sequencer/synchronizer/synchronizer_test.go b/sequencer/synchronizer/synchronizer_test.go index 88f5d96..accb037 100644 --- a/sequencer/synchronizer/synchronizer_test.go +++ b/sequencer/synchronizer/synchronizer_test.go @@ -485,8 +485,8 @@ func TestSyncGeneral(t *testing.T) { // Update variables manually rollupVars, err := s.historyDB.GetSCVars() require.NoError(t, err) - rollupVars.ForgeL1BatchTimeout = 42 - _, err = client.RollupUpdateForgeL1BatchTimeout(rollupVars.ForgeL1BatchTimeout) + rollupVars.ForgeL1L2BatchTimeout = 42 + _, err = client.RollupUpdateForgeL1BatchTimeout(rollupVars.ForgeL1L2BatchTimeout) require.NoError(t, err) client.CtlMineBlock() diff --git a/sequencer/test/ethClient.go b/sequencer/test/ethClient.go index ae862ee..45c7517 100644 --- a/sequencer/test/ethClient.go +++ b/sequencer/test/ethClient.go @@ -122,8 +122,8 @@ func NewClientSetupExample() *ClientSetup { TokamakGovernanceAddress: governanceAddress, } rollupVariables := &common.RollupVariables{ - ForgeL1BatchTimeout: 10, - Buckets: []common.BucketParams{}, + ForgeL1L2BatchTimeout: 10, + Buckets: []common.BucketParams{}, } return &ClientSetup{ RollupConstants: rollupConstants, @@ -191,7 +191,7 @@ func NewClient(l bool, timer Timer, addr *ethCommon.Address, setup *ClientSetup) ExitRoots: make([]*big.Int, 1), ExitNullifierMap: make(map[int64]map[int64]bool), MapL1TxQueue: mapL1TxQueue, - LastL1Batch: 0, + LastL1L2Batch: 0, CurrentToForgeL1TxsNum: 0, LastToForgeL1TxsNum: 1, CurrentIdx: 0, @@ -764,9 +764,9 @@ func (c *Client) RollupUpdateForgeL1BatchTimeout(newForgeL1Timeout int64) (tx *t nextBlock := c.nextBlock() r := nextBlock.Rollup - r.Vars.ForgeL1BatchTimeout = newForgeL1Timeout - r.Events.UpdateForgeL1BatchTimeout = append(r.Events.UpdateForgeL1BatchTimeout, - eth.RollupEventUpdateForgeL1BatchTimeout{NewForgeL1BatchTimeout: newForgeL1Timeout}) + r.Vars.ForgeL1L2BatchTimeout = newForgeL1Timeout + r.Events.UpdateForgeL1L2BatchTimeout = append(r.Events.UpdateForgeL1L2BatchTimeout, + eth.RollupEventUpdateForgeL1L2BatchTimeout{NewForgeL1L2BatchTimeout: newForgeL1Timeout}) return r.addTransaction(c.newTransaction("updateForgeL1L2BatchTimeout", newForgeL1Timeout)), nil } @@ -815,7 +815,7 @@ func (c *Client) RollupEventsByBlock(blockNum int64, func (c *Client) RollupEventInit(genesisBlockNum int64) (*eth.RollupEventInitialize, int64, error) { vars := c.blocks[0].Rollup.Vars return ð.RollupEventInitialize{ - ForgeL1BatchTimeout: uint8(vars.ForgeL1BatchTimeout), + ForgeL1L2BatchTimeout: uint8(vars.ForgeL1L2BatchTimeout), }, 1, nil }