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.

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