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.

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