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.

531 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. })
  222. require.Nil(t, err)
  223. //
  224. // First Sync from an initial state
  225. //
  226. // Test Sync for rollup genesis block
  227. syncBlock, discards, err := s.Sync2(ctx, nil)
  228. require.Nil(t, err)
  229. require.Nil(t, discards)
  230. require.NotNil(t, syncBlock)
  231. assert.Equal(t, int64(1), syncBlock.Block.EthBlockNum)
  232. dbBlocks, err := s.historyDB.GetAllBlocks()
  233. require.Nil(t, err)
  234. assert.Equal(t, 2, len(dbBlocks))
  235. assert.Equal(t, int64(1), dbBlocks[1].EthBlockNum)
  236. // Sync again and expect no new blocks
  237. syncBlock, discards, err = s.Sync2(ctx, nil)
  238. require.Nil(t, err)
  239. require.Nil(t, discards)
  240. require.Nil(t, syncBlock)
  241. //
  242. // Generate blockchain and smart contract data, and fill the test smart contracts
  243. //
  244. // Generate blockchain data with til
  245. set1 := `
  246. Type: Blockchain
  247. AddToken(1)
  248. AddToken(2)
  249. AddToken(3)
  250. CreateAccountDeposit(1) C: 2000 // Idx=256+2=258
  251. CreateAccountDeposit(2) A: 2000 // Idx=256+3=259
  252. CreateAccountDeposit(1) D: 500 // Idx=256+4=260
  253. CreateAccountDeposit(2) B: 500 // Idx=256+5=261
  254. CreateAccountDeposit(2) C: 500 // Idx=256+6=262
  255. CreateAccountCoordinator(1) A // Idx=256+0=256
  256. CreateAccountCoordinator(1) B // Idx=256+1=257
  257. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{5}
  258. > batchL1 // forge defined L1UserTxs{5}, freeze L1UserTxs{nil}
  259. > block // blockNum=2
  260. CreateAccountDepositTransfer(1) E-A: 1000, 200 // Idx=256+7=263
  261. ForceExit(1) A: 100
  262. ForceTransfer(1) A-D: 100
  263. Transfer(1) C-A: 100 (200)
  264. Exit(1) D: 30 (200)
  265. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{2}
  266. > batchL1 // forge L1UserTxs{2}, freeze defined L1UserTxs{nil}
  267. > block // blockNum=3
  268. `
  269. tc := til.NewContext(common.RollupConstMaxL1UserTx)
  270. blocks, err := tc.GenerateBlocks(set1)
  271. require.Nil(t, err)
  272. // Sanity check
  273. require.Equal(t, 2, len(blocks))
  274. // blocks 0 (blockNum=2)
  275. i := 0
  276. require.Equal(t, 2, int(blocks[i].Block.EthBlockNum))
  277. require.Equal(t, 3, len(blocks[i].Rollup.AddedTokens))
  278. require.Equal(t, 5, len(blocks[i].Rollup.L1UserTxs))
  279. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  280. require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L1CoordinatorTxs))
  281. // blocks 1 (blockNum=3)
  282. i = 1
  283. require.Equal(t, 3, int(blocks[i].Block.EthBlockNum))
  284. require.Equal(t, 3, len(blocks[i].Rollup.L1UserTxs))
  285. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  286. require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L2Txs))
  287. // Generate extra required data
  288. for _, block := range blocks {
  289. for _, token := range block.Rollup.AddedTokens {
  290. consts := eth.ERC20Consts{
  291. Name: fmt.Sprintf("Token %d", token.TokenID),
  292. Symbol: fmt.Sprintf("TK%d", token.TokenID),
  293. Decimals: 18,
  294. }
  295. tokenConsts[token.TokenID] = consts
  296. client.CtlAddERC20(token.EthAddr, consts)
  297. }
  298. }
  299. // Add block data to the smart contracts
  300. for _, block := range blocks {
  301. for _, token := range block.Rollup.AddedTokens {
  302. _, err := client.RollupAddTokenSimple(token.EthAddr, clientSetup.RollupVariables.FeeAddToken)
  303. require.Nil(t, err)
  304. }
  305. for _, tx := range block.Rollup.L1UserTxs {
  306. client.CtlSetAddr(tx.FromEthAddr)
  307. _, err := client.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.LoadAmount, tx.Amount,
  308. uint32(tx.TokenID), int64(tx.ToIdx))
  309. require.Nil(t, err)
  310. }
  311. client.CtlSetAddr(bootCoordAddr)
  312. feeIdxCoordinator := []common.Idx{}
  313. if block.Block.EthBlockNum > 2 {
  314. // After blockNum=2 we have some accounts, use them as
  315. // coordinator owned to receive fees.
  316. feeIdxCoordinator = []common.Idx{common.Idx(256), common.Idx(259)}
  317. }
  318. for _, batch := range block.Rollup.Batches {
  319. _, err := client.RollupForgeBatch(&eth.RollupForgeBatchArgs{
  320. NewLastIdx: batch.Batch.LastIdx,
  321. NewStRoot: batch.Batch.StateRoot,
  322. NewExitRoot: batch.Batch.ExitRoot,
  323. L1CoordinatorTxs: batch.L1CoordinatorTxs,
  324. L1CoordinatorTxsAuths: [][]byte{}, // Intentionally empty
  325. L2TxsData: batch.L2Txs,
  326. FeeIdxCoordinator: feeIdxCoordinator,
  327. // Circuit selector
  328. VerifierIdx: 0, // Intentionally empty
  329. L1Batch: batch.L1Batch,
  330. ProofA: [2]*big.Int{}, // Intentionally empty
  331. ProofB: [2][2]*big.Int{}, // Intentionally empty
  332. ProofC: [2]*big.Int{}, // Intentionally empty
  333. })
  334. require.Nil(t, err)
  335. }
  336. // Mine block and sync
  337. client.CtlMineBlock()
  338. }
  339. // Fill extra fields not generated by til in til block
  340. openToForge := int64(0)
  341. toForgeL1TxsNum := int64(0)
  342. l1UserTxsLen := map[int64]int{} // ForgeL1TxsNum -> len(L1UserTxs)
  343. for i := range blocks {
  344. block := &blocks[i]
  345. // Count number of L1UserTxs in each queue, to figure out later
  346. // position of L1CoordinatorTxs and L2Txs
  347. for j := range block.Rollup.L1UserTxs {
  348. tx := &block.Rollup.L1UserTxs[j]
  349. l1UserTxsLen[*tx.ToForgeL1TxsNum]++
  350. if tx.Type == common.TxTypeForceExit {
  351. forceExits[*tx.ToForgeL1TxsNum] = append(forceExits[*tx.ToForgeL1TxsNum],
  352. common.ExitInfo{
  353. AccountIdx: tx.FromIdx,
  354. Balance: tx.Amount,
  355. })
  356. }
  357. }
  358. for j := range block.Rollup.Batches {
  359. batch := &block.Rollup.Batches[j]
  360. if batch.L1Batch {
  361. // Set BatchNum for forged L1UserTxs to til blocks
  362. bn := batch.Batch.BatchNum
  363. for k := range blocks {
  364. block := &blocks[k]
  365. for l := range block.Rollup.L1UserTxs {
  366. tx := &block.Rollup.L1UserTxs[l]
  367. if *tx.ToForgeL1TxsNum == openToForge {
  368. tx.BatchNum = &bn
  369. }
  370. }
  371. }
  372. openToForge++
  373. }
  374. batch.Batch.EthBlockNum = block.Block.EthBlockNum
  375. batch.Batch.ForgerAddr = bootCoordAddr // til doesn't fill the batch forger addr
  376. if batch.L1Batch {
  377. toForgeL1TxsNumCpy := toForgeL1TxsNum
  378. batch.Batch.ForgeL1TxsNum = &toForgeL1TxsNumCpy // til doesn't fill the ForgeL1TxsNum
  379. toForgeL1TxsNum++
  380. }
  381. batchNum := batch.Batch.BatchNum
  382. for k := range batch.L1CoordinatorTxs {
  383. tx := &batch.L1CoordinatorTxs[k]
  384. tx.BatchNum = &batchNum
  385. tx.EthBlockNum = batch.Batch.EthBlockNum
  386. }
  387. }
  388. }
  389. // Fill expected positions in L1CoordinatorTxs and L2Txs
  390. for i := range blocks {
  391. block := &blocks[i]
  392. for j := range block.Rollup.Batches {
  393. batch := &block.Rollup.Batches[j]
  394. position := 0
  395. if batch.L1Batch {
  396. position = l1UserTxsLen[*batch.Batch.ForgeL1TxsNum]
  397. }
  398. for k := range batch.L1CoordinatorTxs {
  399. tx := &batch.L1CoordinatorTxs[k]
  400. tx.Position = position
  401. position++
  402. nTx, err := common.NewL1Tx(tx)
  403. require.Nil(t, err)
  404. *tx = *nTx
  405. }
  406. for k := range batch.L2Txs {
  407. tx := &batch.L2Txs[k]
  408. tx.Position = position
  409. position++
  410. nonces[tx.FromIdx]++
  411. tx.Nonce = nonces[tx.FromIdx]
  412. nTx, err := common.NewL2Tx(tx)
  413. require.Nil(t, err)
  414. *tx = *nTx
  415. }
  416. }
  417. }
  418. // Fill ExitTree (only AccountIdx and Balance)
  419. for i := range blocks {
  420. block := &blocks[i]
  421. for j := range block.Rollup.Batches {
  422. batch := &block.Rollup.Batches[j]
  423. if batch.L1Batch {
  424. for forgeL1TxsNum, exits := range forceExits {
  425. if forgeL1TxsNum == *batch.Batch.ForgeL1TxsNum {
  426. batch.ExitTree = append(batch.ExitTree, exits...)
  427. }
  428. }
  429. }
  430. for k := range batch.L2Txs {
  431. tx := &batch.L2Txs[k]
  432. if tx.Type == common.TxTypeExit {
  433. batch.ExitTree = append(batch.ExitTree, common.ExitInfo{
  434. AccountIdx: tx.FromIdx,
  435. Balance: tx.Amount,
  436. })
  437. }
  438. }
  439. }
  440. }
  441. //
  442. // Sync to synchronize the current state from the test smart contracts,
  443. // and check the outcome
  444. //
  445. // Block 2
  446. syncBlock, discards, err = s.Sync2(ctx, nil)
  447. require.Nil(t, err)
  448. require.Nil(t, discards)
  449. require.NotNil(t, syncBlock)
  450. assert.Equal(t, int64(2), syncBlock.Block.EthBlockNum)
  451. checkSyncBlock(t, s, 2, &blocks[0], syncBlock)
  452. // Block 3
  453. syncBlock, discards, err = s.Sync2(ctx, nil)
  454. require.Nil(t, err)
  455. require.Nil(t, discards)
  456. require.NotNil(t, syncBlock)
  457. assert.Equal(t, int64(3), syncBlock.Block.EthBlockNum)
  458. checkSyncBlock(t, s, 3, &blocks[1], syncBlock)
  459. // TODO: Reorg will be properly tested once we have the mock ethClient implemented
  460. /*
  461. // Force a Reorg
  462. lastSavedBlock, err := historyDB.GetLastBlock()
  463. require.Nil(t, err)
  464. lastSavedBlock.EthBlockNum++
  465. err = historyDB.AddBlock(lastSavedBlock)
  466. require.Nil(t, err)
  467. lastSavedBlock.EthBlockNum++
  468. err = historyDB.AddBlock(lastSavedBlock)
  469. require.Nil(t, err)
  470. log.Debugf("Wait for the blockchain to generate some blocks...")
  471. time.Sleep(40 * time.Second)
  472. err = s.Sync()
  473. require.Nil(t, err)
  474. */
  475. }