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.

536 lines
16 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
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
  1. package synchronizer
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "math/big"
  8. "os"
  9. "testing"
  10. ethCommon "github.com/ethereum/go-ethereum/common"
  11. "github.com/hermeznetwork/hermez-node/common"
  12. dbUtils "github.com/hermeznetwork/hermez-node/db"
  13. "github.com/hermeznetwork/hermez-node/db/historydb"
  14. "github.com/hermeznetwork/hermez-node/db/statedb"
  15. "github.com/hermeznetwork/hermez-node/eth"
  16. "github.com/hermeznetwork/hermez-node/test"
  17. "github.com/hermeznetwork/hermez-node/test/til"
  18. "github.com/jinzhu/copier"
  19. "github.com/stretchr/testify/assert"
  20. "github.com/stretchr/testify/require"
  21. )
  22. var tokenConsts = map[common.TokenID]eth.ERC20Consts{}
  23. var forceExits = map[int64][]common.ExitInfo{} // ForgeL1TxsNum -> []exit
  24. var nonces = map[common.Idx]common.Nonce{}
  25. type timer struct {
  26. time int64
  27. }
  28. func (t *timer) Time() int64 {
  29. currentTime := t.time
  30. t.time++
  31. return currentTime
  32. }
  33. // Check Sync output and HistoryDB state against expected values generated by
  34. // til
  35. func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, syncBlock *common.BlockData) {
  36. // Check Blocks
  37. dbBlocks, err := s.historyDB.GetAllBlocks()
  38. require.Nil(t, err)
  39. dbBlocks = dbBlocks[1:] // ignore block 0, added by default in the DB
  40. assert.Equal(t, blockNum, len(dbBlocks))
  41. assert.Equal(t, int64(blockNum), dbBlocks[blockNum-1].EthBlockNum)
  42. assert.NotEqual(t, dbBlocks[blockNum-1].Hash, dbBlocks[blockNum-2].Hash)
  43. assert.Greater(t, dbBlocks[blockNum-1].Timestamp.Unix(), dbBlocks[blockNum-2].Timestamp.Unix())
  44. // Check Tokens
  45. assert.Equal(t, len(block.Rollup.AddedTokens), len(syncBlock.Rollup.AddedTokens))
  46. dbTokens, err := s.historyDB.GetAllTokens()
  47. require.Nil(t, err)
  48. dbTokens = dbTokens[1:] // ignore token 0, added by default in the DB
  49. for i, token := range block.Rollup.AddedTokens {
  50. dbToken := dbTokens[i]
  51. syncToken := syncBlock.Rollup.AddedTokens[i]
  52. assert.Equal(t, block.Block.EthBlockNum, syncToken.EthBlockNum)
  53. assert.Equal(t, token.TokenID, syncToken.TokenID)
  54. assert.Equal(t, token.EthAddr, syncToken.EthAddr)
  55. tokenConst := tokenConsts[token.TokenID]
  56. assert.Equal(t, tokenConst.Name, syncToken.Name)
  57. assert.Equal(t, tokenConst.Symbol, syncToken.Symbol)
  58. assert.Equal(t, tokenConst.Decimals, syncToken.Decimals)
  59. var tokenCpy historydb.TokenWithUSD
  60. //nolint:gosec
  61. require.Nil(t, copier.Copy(&tokenCpy, &token)) // copy common.Token to historydb.TokenWithUSD
  62. require.Nil(t, copier.Copy(&tokenCpy, &tokenConst)) // copy common.Token to historydb.TokenWithUSD
  63. tokenCpy.ItemID = dbToken.ItemID // we don't care about ItemID
  64. assert.Equal(t, tokenCpy, dbToken)
  65. }
  66. // Check L1UserTxs
  67. assert.Equal(t, len(block.Rollup.L1UserTxs), len(syncBlock.Rollup.L1UserTxs))
  68. dbL1UserTxs, err := s.historyDB.GetAllL1UserTxs()
  69. require.Nil(t, err)
  70. // Ignore BatchNum in syncBlock.L1UserTxs because this value is set by the HistoryDB
  71. for i := range syncBlock.Rollup.L1UserTxs {
  72. syncBlock.Rollup.L1UserTxs[i].BatchNum = block.Rollup.L1UserTxs[i].BatchNum
  73. }
  74. assert.Equal(t, block.Rollup.L1UserTxs, syncBlock.Rollup.L1UserTxs)
  75. for _, tx := range block.Rollup.L1UserTxs {
  76. var dbTx *common.L1Tx
  77. // Find tx in DB output
  78. for _, _dbTx := range dbL1UserTxs {
  79. if *tx.ToForgeL1TxsNum == *_dbTx.ToForgeL1TxsNum &&
  80. tx.Position == _dbTx.Position {
  81. dbTx = new(common.L1Tx)
  82. *dbTx = _dbTx
  83. break
  84. }
  85. }
  86. assert.Equal(t, &tx, dbTx) //nolint:gosec
  87. }
  88. // Check Batches
  89. assert.Equal(t, len(block.Rollup.Batches), len(syncBlock.Rollup.Batches))
  90. dbBatches, err := s.historyDB.GetAllBatches()
  91. require.Nil(t, err)
  92. dbL1CoordinatorTxs, err := s.historyDB.GetAllL1CoordinatorTxs()
  93. require.Nil(t, err)
  94. // fmt.Printf("DBG dbL1CoordinatorTxs: %+v\n", dbL1CoordinatorTxs)
  95. dbL2Txs, err := s.historyDB.GetAllL2Txs()
  96. require.Nil(t, err)
  97. // fmt.Printf("DBG dbL2Txs: %+v\n", dbL2Txs)
  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. batch.CreatedAccounts = syncBatch.CreatedAccounts // til doesn't output 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. // We are collecting fees after blockNum=2 in 2 idxs
  129. if block.Block.EthBlockNum > 2 {
  130. // fmt.Printf("DBG collectedFees: %+v\n", syncBatch.Batch.CollectedFees)
  131. assert.Equal(t, 2, len(syncBatch.Batch.CollectedFees))
  132. }
  133. batch.Batch.CollectedFees = syncBatch.Batch.CollectedFees
  134. assert.Equal(t, batch.Batch, syncBatch.Batch)
  135. assert.Equal(t, batch, syncBatch)
  136. assert.Equal(t, &batch.Batch, dbBatch) //nolint:gosec
  137. // Check L1CoordinatorTxs from DB
  138. for _, tx := range batch.L1CoordinatorTxs {
  139. var dbTx *common.L1Tx
  140. // Find tx in DB output
  141. for _, _dbTx := range dbL1CoordinatorTxs {
  142. if *tx.BatchNum == *_dbTx.BatchNum &&
  143. tx.Position == _dbTx.Position {
  144. dbTx = new(common.L1Tx)
  145. *dbTx = _dbTx
  146. break
  147. }
  148. }
  149. assert.Equal(t, &tx, dbTx) //nolint:gosec
  150. }
  151. // Check L2Txs from DB
  152. for _, tx := range batch.L2Txs {
  153. var dbTx *common.L2Tx
  154. // Find tx in DB output
  155. for _, _dbTx := range dbL2Txs {
  156. if tx.BatchNum == _dbTx.BatchNum &&
  157. tx.Position == _dbTx.Position {
  158. dbTx = new(common.L2Tx)
  159. *dbTx = _dbTx
  160. break
  161. }
  162. }
  163. assert.Equal(t, &tx, dbTx) //nolint:gosec
  164. }
  165. // Check Exits from DB
  166. for _, exit := range batch.ExitTree {
  167. var dbExit *common.ExitInfo
  168. // Find exit in DB output
  169. for _, _dbExit := range dbExits {
  170. if exit.BatchNum == _dbExit.BatchNum &&
  171. exit.AccountIdx == _dbExit.AccountIdx {
  172. dbExit = new(common.ExitInfo)
  173. *dbExit = _dbExit
  174. break
  175. }
  176. }
  177. // Compare MerkleProof in JSON because unmarshaled 0
  178. // big.Int leaves the internal big.Int array at nil,
  179. // and gives trouble when comparing big.Int with
  180. // internal big.Int array != nil but empty.
  181. mtp, err := json.Marshal(exit.MerkleProof)
  182. require.Nil(t, err)
  183. dbMtp, err := json.Marshal(dbExit.MerkleProof)
  184. require.Nil(t, err)
  185. assert.Equal(t, mtp, dbMtp)
  186. dbExit.MerkleProof = exit.MerkleProof
  187. assert.Equal(t, &exit, dbExit) //nolint:gosec
  188. }
  189. }
  190. }
  191. func TestSync(t *testing.T) {
  192. //
  193. // Setup
  194. //
  195. ctx := context.Background()
  196. // Int State DB
  197. dir, err := ioutil.TempDir("", "tmpdb")
  198. require.Nil(t, err)
  199. defer assert.Nil(t, os.RemoveAll(dir))
  200. stateDB, err := statedb.NewStateDB(dir, statedb.TypeSynchronizer, 32)
  201. assert.Nil(t, err)
  202. // Init History DB
  203. pass := os.Getenv("POSTGRES_PASS")
  204. db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
  205. require.Nil(t, err)
  206. historyDB := historydb.NewHistoryDB(db)
  207. // Clear DB
  208. test.WipeDB(historyDB.DB())
  209. // Init eth client
  210. var timer timer
  211. clientSetup := test.NewClientSetupExample()
  212. bootCoordAddr := clientSetup.AuctionVariables.BootCoordinator
  213. client := test.NewClient(true, &timer, &ethCommon.Address{}, clientSetup)
  214. // Create Synchronizer
  215. s, err := NewSynchronizer(client, historyDB, stateDB, Config{
  216. StartBlockNum: ConfigStartBlockNum{
  217. Rollup: 1,
  218. Auction: 1,
  219. WDelayer: 1,
  220. },
  221. InitialVariables: SCVariables{
  222. Rollup: *clientSetup.RollupVariables,
  223. Auction: *clientSetup.AuctionVariables,
  224. WDelayer: *clientSetup.WDelayerVariables,
  225. },
  226. })
  227. require.Nil(t, err)
  228. //
  229. // First Sync from an initial state
  230. //
  231. // Test Sync for rollup genesis block
  232. syncBlock, discards, err := s.Sync2(ctx, nil)
  233. require.Nil(t, err)
  234. require.Nil(t, discards)
  235. require.NotNil(t, syncBlock)
  236. assert.Equal(t, int64(1), syncBlock.Block.EthBlockNum)
  237. dbBlocks, err := s.historyDB.GetAllBlocks()
  238. require.Nil(t, err)
  239. assert.Equal(t, 2, len(dbBlocks))
  240. assert.Equal(t, int64(1), dbBlocks[1].EthBlockNum)
  241. // Sync again and expect no new blocks
  242. syncBlock, discards, err = s.Sync2(ctx, nil)
  243. require.Nil(t, err)
  244. require.Nil(t, discards)
  245. require.Nil(t, syncBlock)
  246. //
  247. // Generate blockchain and smart contract data, and fill the test smart contracts
  248. //
  249. // Generate blockchain data with til
  250. set1 := `
  251. Type: Blockchain
  252. AddToken(1)
  253. AddToken(2)
  254. AddToken(3)
  255. CreateAccountDeposit(1) C: 2000 // Idx=256+2=258
  256. CreateAccountDeposit(2) A: 2000 // Idx=256+3=259
  257. CreateAccountDeposit(1) D: 500 // Idx=256+4=260
  258. CreateAccountDeposit(2) B: 500 // Idx=256+5=261
  259. CreateAccountDeposit(2) C: 500 // Idx=256+6=262
  260. CreateAccountCoordinator(1) A // Idx=256+0=256
  261. CreateAccountCoordinator(1) B // Idx=256+1=257
  262. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{5}
  263. > batchL1 // forge defined L1UserTxs{5}, freeze L1UserTxs{nil}
  264. > block // blockNum=2
  265. CreateAccountDepositTransfer(1) E-A: 1000, 200 // Idx=256+7=263
  266. ForceExit(1) A: 100
  267. ForceTransfer(1) A-D: 100
  268. Transfer(1) C-A: 100 (200)
  269. Exit(1) D: 30 (200)
  270. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{2}
  271. > batchL1 // forge L1UserTxs{2}, freeze defined L1UserTxs{nil}
  272. > block // blockNum=3
  273. `
  274. tc := til.NewContext(common.RollupConstMaxL1UserTx)
  275. blocks, err := tc.GenerateBlocks(set1)
  276. require.Nil(t, err)
  277. // Sanity check
  278. require.Equal(t, 2, len(blocks))
  279. // blocks 0 (blockNum=2)
  280. i := 0
  281. require.Equal(t, 2, int(blocks[i].Block.EthBlockNum))
  282. require.Equal(t, 3, len(blocks[i].Rollup.AddedTokens))
  283. require.Equal(t, 5, len(blocks[i].Rollup.L1UserTxs))
  284. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  285. require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L1CoordinatorTxs))
  286. // blocks 1 (blockNum=3)
  287. i = 1
  288. require.Equal(t, 3, int(blocks[i].Block.EthBlockNum))
  289. require.Equal(t, 3, len(blocks[i].Rollup.L1UserTxs))
  290. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  291. require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L2Txs))
  292. // Generate extra required data
  293. for _, block := range blocks {
  294. for _, token := range block.Rollup.AddedTokens {
  295. consts := eth.ERC20Consts{
  296. Name: fmt.Sprintf("Token %d", token.TokenID),
  297. Symbol: fmt.Sprintf("TK%d", token.TokenID),
  298. Decimals: 18,
  299. }
  300. tokenConsts[token.TokenID] = consts
  301. client.CtlAddERC20(token.EthAddr, consts)
  302. }
  303. }
  304. // Add block data to the smart contracts
  305. for _, block := range blocks {
  306. for _, token := range block.Rollup.AddedTokens {
  307. _, err := client.RollupAddTokenSimple(token.EthAddr, clientSetup.RollupVariables.FeeAddToken)
  308. require.Nil(t, err)
  309. }
  310. for _, tx := range block.Rollup.L1UserTxs {
  311. client.CtlSetAddr(tx.FromEthAddr)
  312. _, err := client.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.LoadAmount, tx.Amount,
  313. uint32(tx.TokenID), int64(tx.ToIdx))
  314. require.Nil(t, err)
  315. }
  316. client.CtlSetAddr(bootCoordAddr)
  317. feeIdxCoordinator := []common.Idx{}
  318. if block.Block.EthBlockNum > 2 {
  319. // After blockNum=2 we have some accounts, use them as
  320. // coordinator owned to receive fees.
  321. feeIdxCoordinator = []common.Idx{common.Idx(256), common.Idx(259)}
  322. }
  323. for _, batch := range block.Rollup.Batches {
  324. _, err := client.RollupForgeBatch(&eth.RollupForgeBatchArgs{
  325. NewLastIdx: batch.Batch.LastIdx,
  326. NewStRoot: batch.Batch.StateRoot,
  327. NewExitRoot: batch.Batch.ExitRoot,
  328. L1CoordinatorTxs: batch.L1CoordinatorTxs,
  329. L1CoordinatorTxsAuths: [][]byte{}, // Intentionally empty
  330. L2TxsData: batch.L2Txs,
  331. FeeIdxCoordinator: feeIdxCoordinator,
  332. // Circuit selector
  333. VerifierIdx: 0, // Intentionally empty
  334. L1Batch: batch.L1Batch,
  335. ProofA: [2]*big.Int{}, // Intentionally empty
  336. ProofB: [2][2]*big.Int{}, // Intentionally empty
  337. ProofC: [2]*big.Int{}, // Intentionally empty
  338. })
  339. require.Nil(t, err)
  340. }
  341. // Mine block and sync
  342. client.CtlMineBlock()
  343. }
  344. // Fill extra fields not generated by til in til block
  345. openToForge := int64(0)
  346. toForgeL1TxsNum := int64(0)
  347. l1UserTxsLen := map[int64]int{} // ForgeL1TxsNum -> len(L1UserTxs)
  348. for i := range blocks {
  349. block := &blocks[i]
  350. // Count number of L1UserTxs in each queue, to figure out later
  351. // position of L1CoordinatorTxs and L2Txs
  352. for j := range block.Rollup.L1UserTxs {
  353. tx := &block.Rollup.L1UserTxs[j]
  354. l1UserTxsLen[*tx.ToForgeL1TxsNum]++
  355. if tx.Type == common.TxTypeForceExit {
  356. forceExits[*tx.ToForgeL1TxsNum] = append(forceExits[*tx.ToForgeL1TxsNum],
  357. common.ExitInfo{
  358. AccountIdx: tx.FromIdx,
  359. Balance: tx.Amount,
  360. })
  361. }
  362. }
  363. for j := range block.Rollup.Batches {
  364. batch := &block.Rollup.Batches[j]
  365. if batch.L1Batch {
  366. // Set BatchNum for forged L1UserTxs to til blocks
  367. bn := batch.Batch.BatchNum
  368. for k := range blocks {
  369. block := &blocks[k]
  370. for l := range block.Rollup.L1UserTxs {
  371. tx := &block.Rollup.L1UserTxs[l]
  372. if *tx.ToForgeL1TxsNum == openToForge {
  373. tx.BatchNum = &bn
  374. }
  375. }
  376. }
  377. openToForge++
  378. }
  379. batch.Batch.EthBlockNum = block.Block.EthBlockNum
  380. batch.Batch.ForgerAddr = bootCoordAddr // til doesn't fill the batch forger addr
  381. if batch.L1Batch {
  382. toForgeL1TxsNumCpy := toForgeL1TxsNum
  383. batch.Batch.ForgeL1TxsNum = &toForgeL1TxsNumCpy // til doesn't fill the ForgeL1TxsNum
  384. toForgeL1TxsNum++
  385. }
  386. batchNum := batch.Batch.BatchNum
  387. for k := range batch.L1CoordinatorTxs {
  388. tx := &batch.L1CoordinatorTxs[k]
  389. tx.BatchNum = &batchNum
  390. tx.EthBlockNum = batch.Batch.EthBlockNum
  391. }
  392. }
  393. }
  394. // Fill expected positions in L1CoordinatorTxs and L2Txs
  395. for i := range blocks {
  396. block := &blocks[i]
  397. for j := range block.Rollup.Batches {
  398. batch := &block.Rollup.Batches[j]
  399. position := 0
  400. if batch.L1Batch {
  401. position = l1UserTxsLen[*batch.Batch.ForgeL1TxsNum]
  402. }
  403. for k := range batch.L1CoordinatorTxs {
  404. tx := &batch.L1CoordinatorTxs[k]
  405. tx.Position = position
  406. position++
  407. nTx, err := common.NewL1Tx(tx)
  408. require.Nil(t, err)
  409. *tx = *nTx
  410. }
  411. for k := range batch.L2Txs {
  412. tx := &batch.L2Txs[k]
  413. tx.Position = position
  414. position++
  415. nonces[tx.FromIdx]++
  416. tx.Nonce = nonces[tx.FromIdx]
  417. nTx, err := common.NewL2Tx(tx)
  418. require.Nil(t, err)
  419. *tx = *nTx
  420. }
  421. }
  422. }
  423. // Fill ExitTree (only AccountIdx and Balance)
  424. for i := range blocks {
  425. block := &blocks[i]
  426. for j := range block.Rollup.Batches {
  427. batch := &block.Rollup.Batches[j]
  428. if batch.L1Batch {
  429. for forgeL1TxsNum, exits := range forceExits {
  430. if forgeL1TxsNum == *batch.Batch.ForgeL1TxsNum {
  431. batch.ExitTree = append(batch.ExitTree, exits...)
  432. }
  433. }
  434. }
  435. for k := range batch.L2Txs {
  436. tx := &batch.L2Txs[k]
  437. if tx.Type == common.TxTypeExit {
  438. batch.ExitTree = append(batch.ExitTree, common.ExitInfo{
  439. AccountIdx: tx.FromIdx,
  440. Balance: tx.Amount,
  441. })
  442. }
  443. }
  444. }
  445. }
  446. //
  447. // Sync to synchronize the current state from the test smart contracts,
  448. // and check the outcome
  449. //
  450. // Block 2
  451. syncBlock, discards, err = s.Sync2(ctx, nil)
  452. require.Nil(t, err)
  453. require.Nil(t, discards)
  454. require.NotNil(t, syncBlock)
  455. assert.Equal(t, int64(2), syncBlock.Block.EthBlockNum)
  456. checkSyncBlock(t, s, 2, &blocks[0], syncBlock)
  457. // Block 3
  458. syncBlock, discards, err = s.Sync2(ctx, nil)
  459. require.Nil(t, err)
  460. require.Nil(t, discards)
  461. require.NotNil(t, syncBlock)
  462. assert.Equal(t, int64(3), syncBlock.Block.EthBlockNum)
  463. checkSyncBlock(t, s, 3, &blocks[1], syncBlock)
  464. // TODO: Reorg will be properly tested once we have the mock ethClient implemented
  465. /*
  466. // Force a Reorg
  467. lastSavedBlock, err := historyDB.GetLastBlock()
  468. require.Nil(t, err)
  469. lastSavedBlock.EthBlockNum++
  470. err = historyDB.AddBlock(lastSavedBlock)
  471. require.Nil(t, err)
  472. lastSavedBlock.EthBlockNum++
  473. err = historyDB.AddBlock(lastSavedBlock)
  474. require.Nil(t, err)
  475. log.Debugf("Wait for the blockchain to generate some blocks...")
  476. time.Sleep(40 * time.Second)
  477. err = s.Sync()
  478. require.Nil(t, err)
  479. */
  480. }