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.

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