You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

591 lines
18 KiB

Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Redo coordinator structure, connect API to node - API: - Modify the constructor so that hardcoded rollup constants don't need to be passed (introduce a `Config` and use `configAPI` internally) - Common: - Update rollup constants with proper *big.Int when required - Add BidCoordinator and Slot structs used by the HistoryDB and Synchronizer. - Add helper methods to AuctionConstants - AuctionVariables: Add column `DefaultSlotSetBidSlotNum` (in the SQL table: `default_slot_set_bid_slot_num`), which indicates at which slotNum does the `DefaultSlotSetBid` specified starts applying. - Config: - Move coordinator exclusive configuration from the node config to the coordinator config - Coordinator: - Reorganize the code towards having the goroutines started and stopped from the coordinator itself instead of the node. - Remove all stop and stopped channels, and use context.Context and sync.WaitGroup instead. - Remove BatchInfo setters and assing variables directly - In ServerProof and ServerProofPool use context instead stop channel. - Use message passing to notify the coordinator about sync updates and reorgs - Introduce the Pipeline, which can be started and stopped by the Coordinator - Introduce the TxManager, which manages ethereum transactions (the TxManager is also in charge of making the forge call to the rollup smart contract). The TxManager keeps ethereum transactions and: 1. Waits for the transaction to be accepted 2. Waits for the transaction to be confirmed for N blocks - In forge logic, first prepare a batch and then wait for an available server proof to have all work ready once the proof server is ready. - Remove the `isForgeSequence` method which was querying the smart contract, and instead use notifications sent by the Synchronizer to figure out if it's forging time. - Update test (which is a minimal test to manually see if the coordinator starts) - HistoryDB: - Add method to get the number of batches in a slot (used to detect when a slot has passed the bid winner forging deadline) - Add method to get the best bid and associated coordinator of a slot (used to detect the forgerAddress that can forge the slot) - General: - Rename some instances of `currentBlock` to `lastBlock` to be more clear. - Node: - Connect the API to the node and call the methods to update cached state when the sync advances blocks. - Call methods to update Coordinator state when the sync advances blocks and finds reorgs. - Synchronizer: - Add Auction field in the Stats, which contain the current slot with info about highest bidder and other related info required to know who can forge in the current block. - Better organization of cached state: - On Sync, update the internal cached state - On Init or Reorg, load the state from HistoryDB into the internal cached state.
3 years ago
  1. package synchronizer
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "math/big"
  8. "os"
  9. "sort"
  10. "testing"
  11. ethCommon "github.com/ethereum/go-ethereum/common"
  12. "github.com/hermeznetwork/hermez-node/common"
  13. dbUtils "github.com/hermeznetwork/hermez-node/db"
  14. "github.com/hermeznetwork/hermez-node/db/historydb"
  15. "github.com/hermeznetwork/hermez-node/db/statedb"
  16. "github.com/hermeznetwork/hermez-node/eth"
  17. "github.com/hermeznetwork/hermez-node/test"
  18. "github.com/hermeznetwork/hermez-node/test/til"
  19. "github.com/jinzhu/copier"
  20. "github.com/stretchr/testify/assert"
  21. "github.com/stretchr/testify/require"
  22. )
  23. var tokenConsts = map[common.TokenID]eth.ERC20Consts{}
  24. type timer struct {
  25. time int64
  26. }
  27. func (t *timer) Time() int64 {
  28. currentTime := t.time
  29. t.time++
  30. return currentTime
  31. }
  32. func accountsCmp(accounts []common.Account) func(i, j int) bool {
  33. return func(i, j int) bool { return accounts[i].Idx < accounts[j].Idx }
  34. }
  35. // Check Sync output and HistoryDB state against expected values generated by
  36. // til
  37. func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, syncBlock *common.BlockData) {
  38. // Check Blocks
  39. dbBlocks, err := s.historyDB.GetAllBlocks()
  40. require.Nil(t, err)
  41. dbBlocks = dbBlocks[1:] // ignore block 0, added by default in the DB
  42. assert.Equal(t, blockNum, len(dbBlocks))
  43. assert.Equal(t, int64(blockNum), dbBlocks[blockNum-1].EthBlockNum)
  44. assert.NotEqual(t, dbBlocks[blockNum-1].Hash, dbBlocks[blockNum-2].Hash)
  45. assert.Greater(t, dbBlocks[blockNum-1].Timestamp.Unix(), dbBlocks[blockNum-2].Timestamp.Unix())
  46. // Check Tokens
  47. assert.Equal(t, len(block.Rollup.AddedTokens), len(syncBlock.Rollup.AddedTokens))
  48. dbTokens, err := s.historyDB.GetAllTokens()
  49. require.Nil(t, err)
  50. dbTokens = dbTokens[1:] // ignore token 0, added by default in the DB
  51. for i, token := range block.Rollup.AddedTokens {
  52. dbToken := dbTokens[i]
  53. syncToken := syncBlock.Rollup.AddedTokens[i]
  54. assert.Equal(t, block.Block.EthBlockNum, syncToken.EthBlockNum)
  55. assert.Equal(t, token.TokenID, syncToken.TokenID)
  56. assert.Equal(t, token.EthAddr, syncToken.EthAddr)
  57. tokenConst := tokenConsts[token.TokenID]
  58. assert.Equal(t, tokenConst.Name, syncToken.Name)
  59. assert.Equal(t, tokenConst.Symbol, syncToken.Symbol)
  60. assert.Equal(t, tokenConst.Decimals, syncToken.Decimals)
  61. var tokenCpy historydb.TokenWithUSD
  62. //nolint:gosec
  63. require.Nil(t, copier.Copy(&tokenCpy, &token)) // copy common.Token to historydb.TokenWithUSD
  64. require.Nil(t, copier.Copy(&tokenCpy, &tokenConst)) // copy common.Token to historydb.TokenWithUSD
  65. tokenCpy.ItemID = dbToken.ItemID // we don't care about ItemID
  66. assert.Equal(t, tokenCpy, dbToken)
  67. }
  68. // Check L1UserTxs
  69. assert.Equal(t, len(block.Rollup.L1UserTxs), len(syncBlock.Rollup.L1UserTxs))
  70. dbL1UserTxs, err := s.historyDB.GetAllL1UserTxs()
  71. require.Nil(t, err)
  72. // Ignore BatchNum in syncBlock.L1UserTxs because this value is set by the HistoryDB
  73. for i := range syncBlock.Rollup.L1UserTxs {
  74. syncBlock.Rollup.L1UserTxs[i].BatchNum = block.Rollup.L1UserTxs[i].BatchNum
  75. }
  76. assert.Equal(t, block.Rollup.L1UserTxs, syncBlock.Rollup.L1UserTxs)
  77. for _, tx := range block.Rollup.L1UserTxs {
  78. var dbTx *common.L1Tx
  79. // Find tx in DB output
  80. for _, _dbTx := range dbL1UserTxs {
  81. if *tx.ToForgeL1TxsNum == *_dbTx.ToForgeL1TxsNum &&
  82. tx.Position == _dbTx.Position {
  83. dbTx = new(common.L1Tx)
  84. *dbTx = _dbTx
  85. break
  86. }
  87. }
  88. assert.Equal(t, &tx, dbTx) //nolint:gosec
  89. }
  90. // Check Batches
  91. assert.Equal(t, len(block.Rollup.Batches), len(syncBlock.Rollup.Batches))
  92. dbBatches, err := s.historyDB.GetAllBatches()
  93. require.Nil(t, err)
  94. dbL1CoordinatorTxs, err := s.historyDB.GetAllL1CoordinatorTxs()
  95. require.Nil(t, err)
  96. dbL2Txs, err := s.historyDB.GetAllL2Txs()
  97. require.Nil(t, err)
  98. dbExits, err := s.historyDB.GetAllExits()
  99. require.Nil(t, err)
  100. // dbL1CoordinatorTxs := []common.L1Tx{}
  101. for i, batch := range block.Rollup.Batches {
  102. var dbBatch *common.Batch
  103. // Find batch in DB output
  104. for _, _dbBatch := range dbBatches {
  105. if batch.Batch.BatchNum == _dbBatch.BatchNum {
  106. dbBatch = new(common.Batch)
  107. *dbBatch = _dbBatch
  108. break
  109. }
  110. }
  111. syncBatch := syncBlock.Rollup.Batches[i]
  112. // We don't care about TotalFeesUSD. Use the syncBatch that
  113. // has a TotalFeesUSD inserted by the HistoryDB
  114. batch.Batch.TotalFeesUSD = syncBatch.Batch.TotalFeesUSD
  115. assert.Equal(t, batch.CreatedAccounts, syncBatch.CreatedAccounts)
  116. batch.Batch.NumAccounts = len(batch.CreatedAccounts)
  117. // Test field by field to facilitate debugging of errors
  118. assert.Equal(t, batch.L1CoordinatorTxs, syncBatch.L1CoordinatorTxs)
  119. assert.Equal(t, batch.L2Txs, syncBatch.L2Txs)
  120. // In exit tree, we only check AccountIdx and Balance, because
  121. // it's what we have precomputed before.
  122. for j := range batch.ExitTree {
  123. exit := &batch.ExitTree[j]
  124. assert.Equal(t, exit.AccountIdx, syncBatch.ExitTree[j].AccountIdx)
  125. assert.Equal(t, exit.Balance, syncBatch.ExitTree[j].Balance)
  126. *exit = syncBatch.ExitTree[j]
  127. }
  128. assert.Equal(t, batch.Batch, syncBatch.Batch)
  129. assert.Equal(t, batch, syncBatch)
  130. assert.Equal(t, &batch.Batch, dbBatch) //nolint:gosec
  131. // Check L1CoordinatorTxs from DB
  132. for _, tx := range batch.L1CoordinatorTxs {
  133. var dbTx *common.L1Tx
  134. // Find tx in DB output
  135. for _, _dbTx := range dbL1CoordinatorTxs {
  136. if *tx.BatchNum == *_dbTx.BatchNum &&
  137. tx.Position == _dbTx.Position {
  138. dbTx = new(common.L1Tx)
  139. *dbTx = _dbTx
  140. break
  141. }
  142. }
  143. assert.Equal(t, &tx, dbTx) //nolint:gosec
  144. }
  145. // Check L2Txs from DB
  146. for _, tx := range batch.L2Txs {
  147. var dbTx *common.L2Tx
  148. // Find tx in DB output
  149. for _, _dbTx := range dbL2Txs {
  150. if tx.BatchNum == _dbTx.BatchNum &&
  151. tx.Position == _dbTx.Position {
  152. dbTx = new(common.L2Tx)
  153. *dbTx = _dbTx
  154. break
  155. }
  156. }
  157. assert.Equal(t, &tx, dbTx) //nolint:gosec
  158. }
  159. // Check Exits from DB
  160. for _, exit := range batch.ExitTree {
  161. var dbExit *common.ExitInfo
  162. // Find exit in DB output
  163. for _, _dbExit := range dbExits {
  164. if exit.BatchNum == _dbExit.BatchNum &&
  165. exit.AccountIdx == _dbExit.AccountIdx {
  166. dbExit = new(common.ExitInfo)
  167. *dbExit = _dbExit
  168. break
  169. }
  170. }
  171. // Compare MerkleProof in JSON because unmarshaled 0
  172. // big.Int leaves the internal big.Int array at nil,
  173. // and gives trouble when comparing big.Int with
  174. // internal big.Int array != nil but empty.
  175. mtp, err := json.Marshal(exit.MerkleProof)
  176. require.Nil(t, err)
  177. dbMtp, err := json.Marshal(dbExit.MerkleProof)
  178. require.Nil(t, err)
  179. assert.Equal(t, mtp, dbMtp)
  180. dbExit.MerkleProof = exit.MerkleProof
  181. assert.Equal(t, &exit, dbExit) //nolint:gosec
  182. }
  183. }
  184. // Compare accounts from HistoryDB with StateDB (they should match)
  185. dbAccounts, err := s.historyDB.GetAllAccounts()
  186. require.Nil(t, err)
  187. sdbAccounts, err := s.stateDB.GetAccounts()
  188. require.Nil(t, err)
  189. assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)
  190. }
  191. func assertEqualAccountsHistoryDBStateDB(t *testing.T, hdbAccs, sdbAccs []common.Account) {
  192. assert.Equal(t, len(hdbAccs), len(sdbAccs))
  193. sort.SliceStable(hdbAccs, accountsCmp(hdbAccs))
  194. sort.SliceStable(sdbAccs, accountsCmp(sdbAccs))
  195. for i := range hdbAccs {
  196. hdbAcc := hdbAccs[i]
  197. sdbAcc := sdbAccs[i]
  198. assert.Equal(t, hdbAcc.Idx, sdbAcc.Idx)
  199. assert.Equal(t, hdbAcc.TokenID, sdbAcc.TokenID)
  200. assert.Equal(t, hdbAcc.EthAddr, sdbAcc.EthAddr)
  201. assert.Equal(t, hdbAcc.PublicKey, sdbAcc.PublicKey)
  202. }
  203. }
  204. // ethAddTokens adds the tokens from the blocks to the blockchain
  205. func ethAddTokens(blocks []common.BlockData, client *test.Client) {
  206. for _, block := range blocks {
  207. for _, token := range block.Rollup.AddedTokens {
  208. consts := eth.ERC20Consts{
  209. Name: fmt.Sprintf("Token %d", token.TokenID),
  210. Symbol: fmt.Sprintf("TK%d", token.TokenID),
  211. Decimals: 18,
  212. }
  213. tokenConsts[token.TokenID] = consts
  214. client.CtlAddERC20(token.EthAddr, consts)
  215. }
  216. }
  217. }
  218. // ethAddBlocks adds block data to the smart contracts
  219. func ethAddBlocks(t *testing.T, blocks []common.BlockData,
  220. client *test.Client, clientSetup *test.ClientSetup) {
  221. for _, block := range blocks {
  222. for _, token := range block.Rollup.AddedTokens {
  223. _, err := client.RollupAddTokenSimple(token.EthAddr, clientSetup.RollupVariables.FeeAddToken)
  224. require.Nil(t, err)
  225. }
  226. for _, tx := range block.Rollup.L1UserTxs {
  227. client.CtlSetAddr(tx.FromEthAddr)
  228. _, err := client.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.LoadAmount, tx.Amount,
  229. uint32(tx.TokenID), int64(tx.ToIdx))
  230. require.Nil(t, err)
  231. }
  232. client.CtlSetAddr(clientSetup.AuctionVariables.BootCoordinator)
  233. for _, batch := range block.Rollup.Batches {
  234. _, err := client.RollupForgeBatch(&eth.RollupForgeBatchArgs{
  235. NewLastIdx: batch.Batch.LastIdx,
  236. NewStRoot: batch.Batch.StateRoot,
  237. NewExitRoot: batch.Batch.ExitRoot,
  238. L1CoordinatorTxs: batch.L1CoordinatorTxs,
  239. L1CoordinatorTxsAuths: [][]byte{}, // Intentionally empty
  240. L2TxsData: batch.L2Txs,
  241. FeeIdxCoordinator: batch.Batch.FeeIdxsCoordinator,
  242. // Circuit selector
  243. VerifierIdx: 0, // Intentionally empty
  244. L1Batch: batch.L1Batch,
  245. ProofA: [2]*big.Int{}, // Intentionally empty
  246. ProofB: [2][2]*big.Int{}, // Intentionally empty
  247. ProofC: [2]*big.Int{}, // Intentionally empty
  248. })
  249. require.Nil(t, err)
  250. }
  251. // Mine block and sync
  252. client.CtlMineBlock()
  253. }
  254. }
  255. func TestSync(t *testing.T) {
  256. //
  257. // Setup
  258. //
  259. ctx := context.Background()
  260. // Int State DB
  261. dir, err := ioutil.TempDir("", "tmpdb")
  262. require.Nil(t, err)
  263. defer assert.Nil(t, os.RemoveAll(dir))
  264. stateDB, err := statedb.NewStateDB(dir, statedb.TypeSynchronizer, 32)
  265. assert.Nil(t, err)
  266. // Init History DB
  267. pass := os.Getenv("POSTGRES_PASS")
  268. db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
  269. require.Nil(t, err)
  270. historyDB := historydb.NewHistoryDB(db)
  271. // Clear DB
  272. test.WipeDB(historyDB.DB())
  273. // Init eth client
  274. var timer timer
  275. clientSetup := test.NewClientSetupExample()
  276. bootCoordAddr := clientSetup.AuctionVariables.BootCoordinator
  277. client := test.NewClient(true, &timer, &ethCommon.Address{}, clientSetup)
  278. // Create Synchronizer
  279. s, err := NewSynchronizer(client, historyDB, stateDB, Config{
  280. StartBlockNum: ConfigStartBlockNum{
  281. Rollup: 1,
  282. Auction: 1,
  283. WDelayer: 1,
  284. },
  285. InitialVariables: SCVariables{
  286. Rollup: *clientSetup.RollupVariables,
  287. Auction: *clientSetup.AuctionVariables,
  288. WDelayer: *clientSetup.WDelayerVariables,
  289. },
  290. })
  291. require.Nil(t, err)
  292. //
  293. // First Sync from an initial state
  294. //
  295. // Test Sync for rollup genesis block
  296. syncBlock, discards, err := s.Sync2(ctx, nil)
  297. require.Nil(t, err)
  298. require.Nil(t, discards)
  299. require.NotNil(t, syncBlock)
  300. assert.Equal(t, int64(1), syncBlock.Block.EthBlockNum)
  301. dbBlocks, err := s.historyDB.GetAllBlocks()
  302. require.Nil(t, err)
  303. assert.Equal(t, 2, len(dbBlocks))
  304. assert.Equal(t, int64(1), dbBlocks[1].EthBlockNum)
  305. // Sync again and expect no new blocks
  306. syncBlock, discards, err = s.Sync2(ctx, nil)
  307. require.Nil(t, err)
  308. require.Nil(t, discards)
  309. require.Nil(t, syncBlock)
  310. //
  311. // Generate blockchain and smart contract data, and fill the test smart contracts
  312. //
  313. // Generate blockchain data with til
  314. set1 := `
  315. Type: Blockchain
  316. AddToken(1)
  317. AddToken(2)
  318. AddToken(3)
  319. CreateAccountDeposit(1) C: 2000 // Idx=256+2=258
  320. CreateAccountDeposit(2) A: 2000 // Idx=256+3=259
  321. CreateAccountDeposit(1) D: 500 // Idx=256+4=260
  322. CreateAccountDeposit(2) B: 500 // Idx=256+5=261
  323. CreateAccountDeposit(2) C: 500 // Idx=256+6=262
  324. CreateAccountCoordinator(1) A // Idx=256+0=256
  325. CreateAccountCoordinator(1) B // Idx=256+1=257
  326. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{5}
  327. > batchL1 // forge defined L1UserTxs{5}, freeze L1UserTxs{nil}
  328. > block // blockNum=2
  329. CreateAccountDepositTransfer(1) E-A: 1000, 200 // Idx=256+7=263
  330. ForceExit(1) A: 100
  331. ForceExit(1) B: 80
  332. ForceTransfer(1) A-D: 100
  333. Transfer(1) C-A: 100 (200)
  334. Exit(1) C: 50 (200)
  335. Exit(1) D: 30 (200)
  336. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{3}
  337. > batchL1 // forge L1UserTxs{3}, freeze defined L1UserTxs{nil}
  338. > block // blockNum=3
  339. `
  340. tc := til.NewContext(common.RollupConstMaxL1UserTx)
  341. tilCfgExtra := til.ConfigExtra{
  342. BootCoordAddr: bootCoordAddr,
  343. CoordUser: "A",
  344. }
  345. blocks, err := tc.GenerateBlocks(set1)
  346. require.Nil(t, err)
  347. // Sanity check
  348. require.Equal(t, 2, len(blocks))
  349. // blocks 0 (blockNum=2)
  350. i := 0
  351. require.Equal(t, 2, int(blocks[i].Block.EthBlockNum))
  352. require.Equal(t, 3, len(blocks[i].Rollup.AddedTokens))
  353. require.Equal(t, 5, len(blocks[i].Rollup.L1UserTxs))
  354. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  355. require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L1CoordinatorTxs))
  356. // blocks 1 (blockNum=3)
  357. i = 1
  358. require.Equal(t, 3, int(blocks[i].Block.EthBlockNum))
  359. require.Equal(t, 4, len(blocks[i].Rollup.L1UserTxs))
  360. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  361. require.Equal(t, 3, len(blocks[i].Rollup.Batches[0].L2Txs))
  362. // Generate extra required data
  363. ethAddTokens(blocks, client)
  364. err = tc.FillBlocksExtra(blocks, &tilCfgExtra)
  365. assert.Nil(t, err)
  366. tc.FillBlocksL1UserTxsBatchNum(blocks)
  367. // Add block data to the smart contracts
  368. ethAddBlocks(t, blocks, client, clientSetup)
  369. //
  370. // Sync to synchronize the current state from the test smart contracts,
  371. // and check the outcome
  372. //
  373. // Block 2
  374. syncBlock, discards, err = s.Sync2(ctx, nil)
  375. require.Nil(t, err)
  376. require.Nil(t, discards)
  377. require.NotNil(t, syncBlock)
  378. assert.Equal(t, int64(2), syncBlock.Block.EthBlockNum)
  379. checkSyncBlock(t, s, 2, &blocks[0], syncBlock)
  380. // Block 3
  381. syncBlock, discards, err = s.Sync2(ctx, nil)
  382. require.Nil(t, err)
  383. require.Nil(t, discards)
  384. require.NotNil(t, syncBlock)
  385. assert.Equal(t, int64(3), syncBlock.Block.EthBlockNum)
  386. checkSyncBlock(t, s, 3, &blocks[1], syncBlock)
  387. // Block 4
  388. // Generate 2 withdraws manually
  389. _, err = client.RollupWithdrawMerkleProof(tc.Users["A"].BJJ.Public(), 1, 4, 256, big.NewInt(100), []*big.Int{}, true)
  390. require.Nil(t, err)
  391. _, err = client.RollupWithdrawMerkleProof(tc.Users["C"].BJJ.Public(), 1, 3, 258, big.NewInt(50), []*big.Int{}, false)
  392. require.Nil(t, err)
  393. client.CtlMineBlock()
  394. syncBlock, discards, err = s.Sync2(ctx, nil)
  395. require.Nil(t, err)
  396. require.Nil(t, discards)
  397. require.NotNil(t, syncBlock)
  398. assert.Equal(t, int64(4), syncBlock.Block.EthBlockNum)
  399. dbExits, err := s.historyDB.GetAllExits()
  400. require.Nil(t, err)
  401. foundA1, foundC1 := false, false
  402. for _, exit := range dbExits {
  403. if exit.AccountIdx == 256 && exit.BatchNum == 4 {
  404. foundA1 = true
  405. assert.Equal(t, int64(4), *exit.InstantWithdrawn)
  406. }
  407. if exit.AccountIdx == 258 && exit.BatchNum == 3 {
  408. foundC1 = true
  409. assert.Equal(t, int64(4), *exit.DelayedWithdrawRequest)
  410. }
  411. }
  412. assert.True(t, foundA1)
  413. assert.True(t, foundC1)
  414. // Block 5
  415. // Update variables manually
  416. rollupVars, auctionVars, wDelayerVars, err := s.historyDB.GetSCVars()
  417. require.Nil(t, err)
  418. rollupVars.ForgeL1L2BatchTimeout = 42
  419. _, err = client.RollupUpdateForgeL1L2BatchTimeout(rollupVars.ForgeL1L2BatchTimeout)
  420. require.Nil(t, err)
  421. auctionVars.OpenAuctionSlots = 17
  422. _, err = client.AuctionSetOpenAuctionSlots(auctionVars.OpenAuctionSlots)
  423. require.Nil(t, err)
  424. wDelayerVars.WithdrawalDelay = 99
  425. _, err = client.WDelayerChangeWithdrawalDelay(wDelayerVars.WithdrawalDelay)
  426. require.Nil(t, err)
  427. client.CtlMineBlock()
  428. syncBlock, discards, err = s.Sync2(ctx, nil)
  429. require.Nil(t, err)
  430. require.Nil(t, discards)
  431. require.NotNil(t, syncBlock)
  432. assert.Equal(t, int64(5), syncBlock.Block.EthBlockNum)
  433. dbRollupVars, dbAuctionVars, dbWDelayerVars, err := s.historyDB.GetSCVars()
  434. require.Nil(t, err)
  435. // Set EthBlockNum for Vars to the blockNum in which they were updated (should be 5)
  436. rollupVars.EthBlockNum = syncBlock.Block.EthBlockNum
  437. auctionVars.EthBlockNum = syncBlock.Block.EthBlockNum
  438. wDelayerVars.EthBlockNum = syncBlock.Block.EthBlockNum
  439. assert.Equal(t, rollupVars, dbRollupVars)
  440. assert.Equal(t, auctionVars, dbAuctionVars)
  441. assert.Equal(t, wDelayerVars, dbWDelayerVars)
  442. //
  443. // Reorg test
  444. //
  445. // Redo blocks 2-5 (as a reorg) only leaving:
  446. // - 2 create account transactions
  447. // - 2 add tokens
  448. // We add a 6th block so that the synchronizer can detect the reorg
  449. set2 := `
  450. Type: Blockchain
  451. AddToken(1)
  452. AddToken(2)
  453. CreateAccountDeposit(1) C: 2000 // Idx=256+1=257
  454. CreateAccountCoordinator(1) A // Idx=256+0=256
  455. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{1}
  456. > batchL1 // forge defined L1UserTxs{1}, freeze L1UserTxs{nil}
  457. > block // blockNum=2
  458. > block // blockNum=3
  459. > block // blockNum=4
  460. > block // blockNum=5
  461. > block // blockNum=6
  462. `
  463. tc = til.NewContext(common.RollupConstMaxL1UserTx)
  464. tilCfgExtra = til.ConfigExtra{
  465. BootCoordAddr: bootCoordAddr,
  466. CoordUser: "A",
  467. }
  468. blocks, err = tc.GenerateBlocks(set2)
  469. require.Nil(t, err)
  470. for i := 0; i < 4; i++ {
  471. client.CtlRollback()
  472. }
  473. blockNum := client.CtlLastBlock()
  474. require.Equal(t, int64(1), blockNum)
  475. // Generate extra required data
  476. ethAddTokens(blocks, client)
  477. err = tc.FillBlocksExtra(blocks, &tilCfgExtra)
  478. assert.Nil(t, err)
  479. tc.FillBlocksL1UserTxsBatchNum(blocks)
  480. // Add block data to the smart contracts
  481. ethAddBlocks(t, blocks, client, clientSetup)
  482. // First sync detects the reorg and discards 4 blocks
  483. syncBlock, discards, err = s.Sync2(ctx, nil)
  484. require.Nil(t, err)
  485. expetedDiscards := int64(4)
  486. require.Equal(t, &expetedDiscards, discards)
  487. require.Nil(t, syncBlock)
  488. // At this point, the DB only has data up to block 1
  489. dbBlock, err := s.historyDB.GetLastBlock()
  490. require.Nil(t, err)
  491. assert.Equal(t, int64(1), dbBlock.EthBlockNum)
  492. // Accounts in HistoryDB and StateDB must be empty
  493. dbAccounts, err := s.historyDB.GetAllAccounts()
  494. require.Nil(t, err)
  495. sdbAccounts, err := s.stateDB.GetAccounts()
  496. require.Nil(t, err)
  497. assert.Equal(t, 0, len(dbAccounts))
  498. assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)
  499. // Sync blocks 2-6
  500. for i := 0; i < 5; i++ {
  501. syncBlock, discards, err = s.Sync2(ctx, nil)
  502. require.Nil(t, err)
  503. require.Nil(t, discards)
  504. require.NotNil(t, syncBlock)
  505. assert.Equal(t, int64(2+i), syncBlock.Block.EthBlockNum)
  506. }
  507. dbBlock, err = s.historyDB.GetLastBlock()
  508. require.Nil(t, err)
  509. assert.Equal(t, int64(6), dbBlock.EthBlockNum)
  510. // Accounts in HistoryDB and StateDB is only 2 entries
  511. dbAccounts, err = s.historyDB.GetAllAccounts()
  512. require.Nil(t, err)
  513. sdbAccounts, err = s.stateDB.GetAccounts()
  514. require.Nil(t, err)
  515. assert.Equal(t, 2, len(dbAccounts))
  516. assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)
  517. }