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.

660 lines
21 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 coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
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 coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
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 coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
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 coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
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 coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
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 coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
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 coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
Update coordinator, call all api update functions - Common: - Rename Block.EthBlockNum to Block.Num to avoid unneeded repetition - API: - Add UpdateNetworkInfoBlock to update just block information, to be used when the node is not yet synchronized - Node: - Call API.UpdateMetrics and UpdateRecommendedFee in a loop, with configurable time intervals - Synchronizer: - When mapping events by TxHash, use an array to support the possibility of multiple calls of the same function happening in the same transaction (for example, a smart contract in a single transaction could call withdraw with delay twice, which would generate 2 withdraw events, and 2 deposit events). - In Stats, keep entire LastBlock instead of just the blockNum - In Stats, add lastL1BatchBlock - Test Stats and SCVars - Coordinator: - Enable writing the BatchInfo in every step of the pipeline to disk (with JSON text files) for debugging purposes. - Move the Pipeline functionality from the Coordinator to its own struct (Pipeline) - Implement shouldL1lL2Batch - In TxManager, implement logic to perform several attempts when doing ethereum node RPC calls before considering the error. (Both for calls to forgeBatch and transaction receipt) - In TxManager, reorganize the flow and note the specific points in which actions are made when err != nil - HistoryDB: - Implement GetLastL1BatchBlockNum: returns the blockNum of the latest forged l1Batch, to help the coordinator decide when to forge an L1Batch. - EthereumClient and test.Client: - Update EthBlockByNumber to return the last block when the passed number is -1.
4 years ago
  1. package synchronizer
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "math/big"
  8. "os"
  9. "sort"
  10. "testing"
  11. "time"
  12. ethCommon "github.com/ethereum/go-ethereum/common"
  13. "github.com/hermeznetwork/hermez-node/common"
  14. dbUtils "github.com/hermeznetwork/hermez-node/db"
  15. "github.com/hermeznetwork/hermez-node/db/historydb"
  16. "github.com/hermeznetwork/hermez-node/db/statedb"
  17. "github.com/hermeznetwork/hermez-node/eth"
  18. "github.com/hermeznetwork/hermez-node/test"
  19. "github.com/hermeznetwork/hermez-node/test/til"
  20. "github.com/jinzhu/copier"
  21. "github.com/stretchr/testify/assert"
  22. "github.com/stretchr/testify/require"
  23. )
  24. var tokenConsts = map[common.TokenID]eth.ERC20Consts{}
  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. func accountsCmp(accounts []common.Account) func(i, j int) bool {
  34. return func(i, j int) bool { return accounts[i].Idx < accounts[j].Idx }
  35. }
  36. // Check Sync output and HistoryDB state against expected values generated by
  37. // til
  38. func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, syncBlock *common.BlockData) {
  39. // Check Blocks
  40. dbBlocks, err := s.historyDB.GetAllBlocks()
  41. require.NoError(t, err)
  42. dbBlocks = dbBlocks[1:] // ignore block 0, added by default in the DB
  43. assert.Equal(t, blockNum, len(dbBlocks))
  44. assert.Equal(t, int64(blockNum), dbBlocks[blockNum-1].Num)
  45. assert.NotEqual(t, dbBlocks[blockNum-1].Hash, dbBlocks[blockNum-2].Hash)
  46. assert.Greater(t, dbBlocks[blockNum-1].Timestamp.Unix(), dbBlocks[blockNum-2].Timestamp.Unix())
  47. // Check Tokens
  48. assert.Equal(t, len(block.Rollup.AddedTokens), len(syncBlock.Rollup.AddedTokens))
  49. dbTokens, err := s.historyDB.GetAllTokens()
  50. require.NoError(t, err)
  51. dbTokens = dbTokens[1:] // ignore token 0, added by default in the DB
  52. for i, token := range block.Rollup.AddedTokens {
  53. dbToken := dbTokens[i]
  54. syncToken := syncBlock.Rollup.AddedTokens[i]
  55. assert.Equal(t, block.Block.Num, syncToken.EthBlockNum)
  56. assert.Equal(t, token.TokenID, syncToken.TokenID)
  57. assert.Equal(t, token.EthAddr, syncToken.EthAddr)
  58. tokenConst := tokenConsts[token.TokenID]
  59. assert.Equal(t, tokenConst.Name, syncToken.Name)
  60. assert.Equal(t, tokenConst.Symbol, syncToken.Symbol)
  61. assert.Equal(t, tokenConst.Decimals, syncToken.Decimals)
  62. var tokenCpy historydb.TokenWithUSD
  63. //nolint:gosec
  64. require.Nil(t, copier.Copy(&tokenCpy, &token)) // copy common.Token to historydb.TokenWithUSD
  65. require.Nil(t, copier.Copy(&tokenCpy, &tokenConst)) // copy common.Token to historydb.TokenWithUSD
  66. tokenCpy.ItemID = dbToken.ItemID // we don't care about ItemID
  67. assert.Equal(t, tokenCpy, dbToken)
  68. }
  69. // Check submitted L1UserTxs
  70. assert.Equal(t, len(block.Rollup.L1UserTxs), len(syncBlock.Rollup.L1UserTxs))
  71. dbL1UserTxs, err := s.historyDB.GetAllL1UserTxs()
  72. require.NoError(t, err)
  73. // Ignore BatchNum in syncBlock.L1UserTxs because this value is set by
  74. // the HistoryDB. Also ignore EffectiveAmount & EffectiveDepositAmount
  75. // because this value is set by StateDB.ProcessTxs.
  76. for i := range syncBlock.Rollup.L1UserTxs {
  77. syncBlock.Rollup.L1UserTxs[i].BatchNum = block.Rollup.L1UserTxs[i].BatchNum
  78. assert.Nil(t, syncBlock.Rollup.L1UserTxs[i].EffectiveDepositAmount)
  79. assert.Nil(t, syncBlock.Rollup.L1UserTxs[i].EffectiveAmount)
  80. }
  81. assert.Equal(t, block.Rollup.L1UserTxs, syncBlock.Rollup.L1UserTxs)
  82. for _, tx := range block.Rollup.L1UserTxs {
  83. var dbTx *common.L1Tx
  84. // Find tx in DB output
  85. for _, _dbTx := range dbL1UserTxs {
  86. if *tx.ToForgeL1TxsNum == *_dbTx.ToForgeL1TxsNum &&
  87. tx.Position == _dbTx.Position {
  88. dbTx = new(common.L1Tx)
  89. *dbTx = _dbTx
  90. break
  91. }
  92. }
  93. // If the tx has been forged in this block, this will be
  94. // reflected in the DB, and so the Effective values will be
  95. // already set
  96. if dbTx.BatchNum != nil {
  97. tx.EffectiveAmount = tx.Amount
  98. tx.EffectiveDepositAmount = tx.DepositAmount
  99. }
  100. assert.Equal(t, &tx, dbTx) //nolint:gosec
  101. }
  102. // Check Batches
  103. assert.Equal(t, len(block.Rollup.Batches), len(syncBlock.Rollup.Batches))
  104. dbBatches, err := s.historyDB.GetAllBatches()
  105. require.NoError(t, err)
  106. dbL1CoordinatorTxs, err := s.historyDB.GetAllL1CoordinatorTxs()
  107. require.NoError(t, err)
  108. dbL2Txs, err := s.historyDB.GetAllL2Txs()
  109. require.NoError(t, err)
  110. dbExits, err := s.historyDB.GetAllExits()
  111. require.NoError(t, err)
  112. // dbL1CoordinatorTxs := []common.L1Tx{}
  113. for i, batch := range block.Rollup.Batches {
  114. var dbBatch *common.Batch
  115. // Find batch in DB output
  116. for _, _dbBatch := range dbBatches {
  117. if batch.Batch.BatchNum == _dbBatch.BatchNum {
  118. dbBatch = new(common.Batch)
  119. *dbBatch = _dbBatch
  120. break
  121. }
  122. }
  123. syncBatch := syncBlock.Rollup.Batches[i]
  124. // We don't care about TotalFeesUSD. Use the syncBatch that
  125. // has a TotalFeesUSD inserted by the HistoryDB
  126. batch.Batch.TotalFeesUSD = syncBatch.Batch.TotalFeesUSD
  127. assert.Equal(t, batch.CreatedAccounts, syncBatch.CreatedAccounts)
  128. batch.Batch.NumAccounts = len(batch.CreatedAccounts)
  129. // Test field by field to facilitate debugging of errors
  130. assert.Equal(t, batch.L1UserTxs, syncBatch.L1UserTxs)
  131. assert.Equal(t, batch.L1CoordinatorTxs, syncBatch.L1CoordinatorTxs)
  132. assert.Equal(t, batch.L2Txs, syncBatch.L2Txs)
  133. // In exit tree, we only check AccountIdx and Balance, because
  134. // it's what we have precomputed before.
  135. require.Equal(t, len(batch.ExitTree), len(syncBatch.ExitTree))
  136. for j := range batch.ExitTree {
  137. exit := &batch.ExitTree[j]
  138. assert.Equal(t, exit.AccountIdx, syncBatch.ExitTree[j].AccountIdx)
  139. assert.Equal(t, exit.Balance, syncBatch.ExitTree[j].Balance)
  140. *exit = syncBatch.ExitTree[j]
  141. }
  142. assert.Equal(t, batch.Batch, syncBatch.Batch)
  143. assert.Equal(t, batch, syncBatch)
  144. assert.Equal(t, &batch.Batch, dbBatch) //nolint:gosec
  145. // Check forged L1UserTxs from DB, and check effective values
  146. // in sync output
  147. for j, tx := range batch.L1UserTxs {
  148. var dbTx *common.L1Tx
  149. // Find tx in DB output
  150. for _, _dbTx := range dbL1UserTxs {
  151. if *tx.BatchNum == *_dbTx.BatchNum &&
  152. tx.Position == _dbTx.Position {
  153. dbTx = new(common.L1Tx)
  154. *dbTx = _dbTx
  155. break
  156. }
  157. }
  158. assert.Equal(t, &tx, dbTx) //nolint:gosec
  159. syncTx := &syncBlock.Rollup.Batches[i].L1UserTxs[j]
  160. assert.Equal(t, syncTx.DepositAmount, syncTx.EffectiveDepositAmount)
  161. assert.Equal(t, syncTx.Amount, syncTx.EffectiveAmount)
  162. }
  163. // Check L1CoordinatorTxs from DB
  164. for _, tx := range batch.L1CoordinatorTxs {
  165. var dbTx *common.L1Tx
  166. // Find tx in DB output
  167. for _, _dbTx := range dbL1CoordinatorTxs {
  168. if *tx.BatchNum == *_dbTx.BatchNum &&
  169. tx.Position == _dbTx.Position {
  170. dbTx = new(common.L1Tx)
  171. *dbTx = _dbTx
  172. break
  173. }
  174. }
  175. assert.Equal(t, &tx, dbTx) //nolint:gosec
  176. }
  177. // Check L2Txs from DB
  178. for _, tx := range batch.L2Txs {
  179. var dbTx *common.L2Tx
  180. // Find tx in DB output
  181. for _, _dbTx := range dbL2Txs {
  182. if tx.BatchNum == _dbTx.BatchNum &&
  183. tx.Position == _dbTx.Position {
  184. dbTx = new(common.L2Tx)
  185. *dbTx = _dbTx
  186. break
  187. }
  188. }
  189. assert.Equal(t, &tx, dbTx) //nolint:gosec
  190. }
  191. // Check Exits from DB
  192. for _, exit := range batch.ExitTree {
  193. var dbExit *common.ExitInfo
  194. // Find exit in DB output
  195. for _, _dbExit := range dbExits {
  196. if exit.BatchNum == _dbExit.BatchNum &&
  197. exit.AccountIdx == _dbExit.AccountIdx {
  198. dbExit = new(common.ExitInfo)
  199. *dbExit = _dbExit
  200. break
  201. }
  202. }
  203. // Compare MerkleProof in JSON because unmarshaled 0
  204. // big.Int leaves the internal big.Int array at nil,
  205. // and gives trouble when comparing big.Int with
  206. // internal big.Int array != nil but empty.
  207. mtp, err := json.Marshal(exit.MerkleProof)
  208. require.NoError(t, err)
  209. dbMtp, err := json.Marshal(dbExit.MerkleProof)
  210. require.NoError(t, err)
  211. assert.Equal(t, mtp, dbMtp)
  212. dbExit.MerkleProof = exit.MerkleProof
  213. assert.Equal(t, &exit, dbExit) //nolint:gosec
  214. }
  215. }
  216. // Compare accounts from HistoryDB with StateDB (they should match)
  217. dbAccounts, err := s.historyDB.GetAllAccounts()
  218. require.NoError(t, err)
  219. sdbAccounts, err := s.stateDB.GetAccounts()
  220. require.NoError(t, err)
  221. assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)
  222. }
  223. func assertEqualAccountsHistoryDBStateDB(t *testing.T, hdbAccs, sdbAccs []common.Account) {
  224. assert.Equal(t, len(hdbAccs), len(sdbAccs))
  225. sort.SliceStable(hdbAccs, accountsCmp(hdbAccs))
  226. sort.SliceStable(sdbAccs, accountsCmp(sdbAccs))
  227. for i := range hdbAccs {
  228. hdbAcc := hdbAccs[i]
  229. sdbAcc := sdbAccs[i]
  230. assert.Equal(t, hdbAcc.Idx, sdbAcc.Idx)
  231. assert.Equal(t, hdbAcc.TokenID, sdbAcc.TokenID)
  232. assert.Equal(t, hdbAcc.EthAddr, sdbAcc.EthAddr)
  233. assert.Equal(t, hdbAcc.PublicKey, sdbAcc.PublicKey)
  234. }
  235. }
  236. // ethAddTokens adds the tokens from the blocks to the blockchain
  237. func ethAddTokens(blocks []common.BlockData, client *test.Client) {
  238. for _, block := range blocks {
  239. for _, token := range block.Rollup.AddedTokens {
  240. consts := eth.ERC20Consts{
  241. Name: fmt.Sprintf("Token %d", token.TokenID),
  242. Symbol: fmt.Sprintf("TK%d", token.TokenID),
  243. Decimals: 18,
  244. }
  245. tokenConsts[token.TokenID] = consts
  246. client.CtlAddERC20(token.EthAddr, consts)
  247. }
  248. }
  249. }
  250. func TestSync(t *testing.T) {
  251. //
  252. // Setup
  253. //
  254. ctx := context.Background()
  255. // Int State DB
  256. dir, err := ioutil.TempDir("", "tmpdb")
  257. require.NoError(t, err)
  258. defer assert.Nil(t, os.RemoveAll(dir))
  259. stateDB, err := statedb.NewStateDB(dir, statedb.TypeSynchronizer, 32)
  260. require.NoError(t, err)
  261. // Init History DB
  262. pass := os.Getenv("POSTGRES_PASS")
  263. db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
  264. require.NoError(t, err)
  265. historyDB := historydb.NewHistoryDB(db)
  266. // Clear DB
  267. test.WipeDB(historyDB.DB())
  268. // Init eth client
  269. var timer timer
  270. clientSetup := test.NewClientSetupExample()
  271. bootCoordAddr := clientSetup.AuctionVariables.BootCoordinator
  272. client := test.NewClient(true, &timer, &ethCommon.Address{}, clientSetup)
  273. // Create Synchronizer
  274. s, err := NewSynchronizer(client, historyDB, stateDB, Config{
  275. StatsRefreshPeriod: 0 * time.Second,
  276. })
  277. require.NoError(t, err)
  278. //
  279. // First Sync from an initial state
  280. //
  281. stats := s.Stats()
  282. assert.Equal(t, false, stats.Synced())
  283. // Test Sync for rollup genesis block
  284. syncBlock, discards, err := s.Sync2(ctx, nil)
  285. require.NoError(t, err)
  286. require.Nil(t, discards)
  287. require.NotNil(t, syncBlock)
  288. require.Nil(t, syncBlock.Rollup.Vars)
  289. require.Nil(t, syncBlock.Auction.Vars)
  290. require.Nil(t, syncBlock.WDelayer.Vars)
  291. assert.Equal(t, int64(1), syncBlock.Block.Num)
  292. stats = s.Stats()
  293. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  294. assert.Equal(t, int64(1), stats.Eth.LastBlock.Num)
  295. assert.Equal(t, int64(1), stats.Sync.LastBlock.Num)
  296. vars := s.SCVars()
  297. assert.Equal(t, clientSetup.RollupVariables, vars.Rollup)
  298. assert.Equal(t, clientSetup.AuctionVariables, vars.Auction)
  299. assert.Equal(t, clientSetup.WDelayerVariables, vars.WDelayer)
  300. dbBlocks, err := s.historyDB.GetAllBlocks()
  301. require.NoError(t, err)
  302. assert.Equal(t, 2, len(dbBlocks))
  303. assert.Equal(t, int64(1), dbBlocks[1].Num)
  304. // Sync again and expect no new blocks
  305. syncBlock, discards, err = s.Sync2(ctx, nil)
  306. require.NoError(t, err)
  307. require.Nil(t, discards)
  308. require.Nil(t, syncBlock)
  309. //
  310. // Generate blockchain and smart contract data, and fill the test smart contracts
  311. //
  312. // Generate blockchain data with til
  313. set1 := `
  314. Type: Blockchain
  315. AddToken(1)
  316. AddToken(2)
  317. AddToken(3)
  318. CreateAccountDeposit(1) C: 2000 // Idx=256+2=258
  319. CreateAccountDeposit(2) A: 2000 // Idx=256+3=259
  320. CreateAccountDeposit(1) D: 500 // Idx=256+4=260
  321. CreateAccountDeposit(2) B: 500 // Idx=256+5=261
  322. CreateAccountDeposit(2) C: 500 // Idx=256+6=262
  323. CreateAccountCoordinator(1) A // Idx=256+0=256
  324. CreateAccountCoordinator(1) B // Idx=256+1=257
  325. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{5}
  326. > batchL1 // forge defined L1UserTxs{5}, freeze L1UserTxs{nil}
  327. > block // blockNum=2
  328. CreateAccountDepositTransfer(1) E-A: 1000, 200 // Idx=256+7=263
  329. ForceTransfer(1) C-B: 80
  330. ForceExit(1) A: 100
  331. ForceExit(1) B: 80
  332. ForceTransfer(1) A-D: 100
  333. Transfer(1) C-A: 100 (200)
  334. Exit(1) C: 50 (200)
  335. Exit(1) D: 30 (200)
  336. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{3}
  337. > batchL1 // forge L1UserTxs{3}, freeze defined L1UserTxs{nil}
  338. > block // blockNum=3
  339. `
  340. tc := til.NewContext(common.RollupConstMaxL1UserTx)
  341. tilCfgExtra := til.ConfigExtra{
  342. BootCoordAddr: bootCoordAddr,
  343. CoordUser: "A",
  344. }
  345. blocks, err := tc.GenerateBlocks(set1)
  346. require.NoError(t, err)
  347. // Sanity check
  348. require.Equal(t, 2, len(blocks))
  349. // blocks 0 (blockNum=2)
  350. i := 0
  351. require.Equal(t, 2, int(blocks[i].Block.Num))
  352. require.Equal(t, 3, len(blocks[i].Rollup.AddedTokens))
  353. require.Equal(t, 5, len(blocks[i].Rollup.L1UserTxs))
  354. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  355. require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L1CoordinatorTxs))
  356. // blocks 1 (blockNum=3)
  357. i = 1
  358. require.Equal(t, 3, int(blocks[i].Block.Num))
  359. require.Equal(t, 5, len(blocks[i].Rollup.L1UserTxs))
  360. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  361. require.Equal(t, 3, len(blocks[i].Rollup.Batches[0].L2Txs))
  362. // Generate extra required data
  363. ethAddTokens(blocks, client)
  364. err = tc.FillBlocksExtra(blocks, &tilCfgExtra)
  365. require.NoError(t, err)
  366. tc.FillBlocksL1UserTxsBatchNum(blocks)
  367. err = tc.FillBlocksForgedL1UserTxs(blocks)
  368. require.NoError(t, err)
  369. // Add block data to the smart contracts
  370. err = client.CtlAddBlocks(blocks)
  371. require.NoError(t, err)
  372. //
  373. // Sync to synchronize the current state from the test smart contracts,
  374. // and check the outcome
  375. //
  376. // Block 2
  377. syncBlock, discards, err = s.Sync2(ctx, nil)
  378. require.NoError(t, err)
  379. require.Nil(t, discards)
  380. require.NotNil(t, syncBlock)
  381. assert.Nil(t, syncBlock.Rollup.Vars)
  382. assert.Nil(t, syncBlock.Auction.Vars)
  383. assert.Nil(t, syncBlock.WDelayer.Vars)
  384. assert.Equal(t, int64(2), syncBlock.Block.Num)
  385. stats = s.Stats()
  386. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  387. assert.Equal(t, int64(3), stats.Eth.LastBlock.Num)
  388. assert.Equal(t, int64(2), stats.Sync.LastBlock.Num)
  389. checkSyncBlock(t, s, 2, &blocks[0], syncBlock)
  390. // Block 3
  391. syncBlock, discards, err = s.Sync2(ctx, nil)
  392. assert.NoError(t, err)
  393. require.NoError(t, err)
  394. require.Nil(t, discards)
  395. require.NotNil(t, syncBlock)
  396. assert.Nil(t, syncBlock.Rollup.Vars)
  397. assert.Nil(t, syncBlock.Auction.Vars)
  398. assert.Nil(t, syncBlock.WDelayer.Vars)
  399. assert.Equal(t, int64(3), syncBlock.Block.Num)
  400. stats = s.Stats()
  401. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  402. assert.Equal(t, int64(3), stats.Eth.LastBlock.Num)
  403. assert.Equal(t, int64(3), stats.Sync.LastBlock.Num)
  404. checkSyncBlock(t, s, 3, &blocks[1], syncBlock)
  405. // Block 4
  406. // Generate 2 withdraws manually
  407. _, err = client.RollupWithdrawMerkleProof(tc.Users["A"].BJJ.Public(), 1, 4, 256, big.NewInt(100), []*big.Int{}, true)
  408. require.NoError(t, err)
  409. _, err = client.RollupWithdrawMerkleProof(tc.Users["C"].BJJ.Public(), 1, 3, 258, big.NewInt(50), []*big.Int{}, false)
  410. require.NoError(t, err)
  411. client.CtlMineBlock()
  412. syncBlock, discards, err = s.Sync2(ctx, nil)
  413. require.NoError(t, err)
  414. require.Nil(t, discards)
  415. require.NotNil(t, syncBlock)
  416. assert.Nil(t, syncBlock.Rollup.Vars)
  417. assert.Nil(t, syncBlock.Auction.Vars)
  418. assert.Nil(t, syncBlock.WDelayer.Vars)
  419. assert.Equal(t, int64(4), syncBlock.Block.Num)
  420. stats = s.Stats()
  421. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  422. assert.Equal(t, int64(4), stats.Eth.LastBlock.Num)
  423. assert.Equal(t, int64(4), stats.Sync.LastBlock.Num)
  424. vars = s.SCVars()
  425. assert.Equal(t, clientSetup.RollupVariables, vars.Rollup)
  426. assert.Equal(t, clientSetup.AuctionVariables, vars.Auction)
  427. assert.Equal(t, clientSetup.WDelayerVariables, vars.WDelayer)
  428. dbExits, err := s.historyDB.GetAllExits()
  429. require.NoError(t, err)
  430. foundA1, foundC1 := false, false
  431. for _, exit := range dbExits {
  432. if exit.AccountIdx == 256 && exit.BatchNum == 4 {
  433. foundA1 = true
  434. assert.Equal(t, int64(4), *exit.InstantWithdrawn)
  435. }
  436. if exit.AccountIdx == 258 && exit.BatchNum == 3 {
  437. foundC1 = true
  438. assert.Equal(t, int64(4), *exit.DelayedWithdrawRequest)
  439. }
  440. }
  441. assert.True(t, foundA1)
  442. assert.True(t, foundC1)
  443. // Block 5
  444. // Update variables manually
  445. rollupVars, auctionVars, wDelayerVars, err := s.historyDB.GetSCVars()
  446. require.NoError(t, err)
  447. rollupVars.ForgeL1L2BatchTimeout = 42
  448. _, err = client.RollupUpdateForgeL1L2BatchTimeout(rollupVars.ForgeL1L2BatchTimeout)
  449. require.NoError(t, err)
  450. auctionVars.OpenAuctionSlots = 17
  451. _, err = client.AuctionSetOpenAuctionSlots(auctionVars.OpenAuctionSlots)
  452. require.NoError(t, err)
  453. wDelayerVars.WithdrawalDelay = 99
  454. _, err = client.WDelayerChangeWithdrawalDelay(wDelayerVars.WithdrawalDelay)
  455. require.NoError(t, err)
  456. client.CtlMineBlock()
  457. syncBlock, discards, err = s.Sync2(ctx, nil)
  458. require.NoError(t, err)
  459. require.Nil(t, discards)
  460. require.NotNil(t, syncBlock)
  461. assert.NotNil(t, syncBlock.Rollup.Vars)
  462. assert.NotNil(t, syncBlock.Auction.Vars)
  463. assert.NotNil(t, syncBlock.WDelayer.Vars)
  464. assert.Equal(t, int64(5), syncBlock.Block.Num)
  465. stats = s.Stats()
  466. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  467. assert.Equal(t, int64(5), stats.Eth.LastBlock.Num)
  468. assert.Equal(t, int64(5), stats.Sync.LastBlock.Num)
  469. vars = s.SCVars()
  470. assert.NotEqual(t, clientSetup.RollupVariables, vars.Rollup)
  471. assert.NotEqual(t, clientSetup.AuctionVariables, vars.Auction)
  472. assert.NotEqual(t, clientSetup.WDelayerVariables, vars.WDelayer)
  473. dbRollupVars, dbAuctionVars, dbWDelayerVars, err := s.historyDB.GetSCVars()
  474. require.NoError(t, err)
  475. // Set EthBlockNum for Vars to the blockNum in which they were updated (should be 5)
  476. rollupVars.EthBlockNum = syncBlock.Block.Num
  477. auctionVars.EthBlockNum = syncBlock.Block.Num
  478. wDelayerVars.EthBlockNum = syncBlock.Block.Num
  479. assert.Equal(t, rollupVars, dbRollupVars)
  480. assert.Equal(t, auctionVars, dbAuctionVars)
  481. assert.Equal(t, wDelayerVars, dbWDelayerVars)
  482. //
  483. // Reorg test
  484. //
  485. // Redo blocks 2-5 (as a reorg) only leaving:
  486. // - 2 create account transactions
  487. // - 2 add tokens
  488. // We add a 6th block so that the synchronizer can detect the reorg
  489. set2 := `
  490. Type: Blockchain
  491. AddToken(1)
  492. AddToken(2)
  493. CreateAccountDeposit(1) C: 2000 // Idx=256+1=257
  494. CreateAccountCoordinator(1) A // Idx=256+0=256
  495. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{1}
  496. > batchL1 // forge defined L1UserTxs{1}, freeze L1UserTxs{nil}
  497. > block // blockNum=2
  498. > block // blockNum=3
  499. > block // blockNum=4
  500. > block // blockNum=5
  501. > block // blockNum=6
  502. `
  503. tc = til.NewContext(common.RollupConstMaxL1UserTx)
  504. tilCfgExtra = til.ConfigExtra{
  505. BootCoordAddr: bootCoordAddr,
  506. CoordUser: "A",
  507. }
  508. blocks, err = tc.GenerateBlocks(set2)
  509. require.NoError(t, err)
  510. for i := 0; i < 4; i++ {
  511. client.CtlRollback()
  512. }
  513. block := client.CtlLastBlock()
  514. require.Equal(t, int64(1), block.Num)
  515. // Generate extra required data
  516. ethAddTokens(blocks, client)
  517. err = tc.FillBlocksExtra(blocks, &tilCfgExtra)
  518. require.NoError(t, err)
  519. tc.FillBlocksL1UserTxsBatchNum(blocks)
  520. // Add block data to the smart contracts
  521. err = client.CtlAddBlocks(blocks)
  522. require.NoError(t, err)
  523. // First sync detects the reorg and discards 4 blocks
  524. syncBlock, discards, err = s.Sync2(ctx, nil)
  525. require.NoError(t, err)
  526. expetedDiscards := int64(4)
  527. require.Equal(t, &expetedDiscards, discards)
  528. require.Nil(t, syncBlock)
  529. stats = s.Stats()
  530. assert.Equal(t, false, stats.Synced())
  531. assert.Equal(t, int64(6), stats.Eth.LastBlock.Num)
  532. vars = s.SCVars()
  533. assert.Equal(t, clientSetup.RollupVariables, vars.Rollup)
  534. assert.Equal(t, clientSetup.AuctionVariables, vars.Auction)
  535. assert.Equal(t, clientSetup.WDelayerVariables, vars.WDelayer)
  536. // At this point, the DB only has data up to block 1
  537. dbBlock, err := s.historyDB.GetLastBlock()
  538. require.NoError(t, err)
  539. assert.Equal(t, int64(1), dbBlock.Num)
  540. // Accounts in HistoryDB and StateDB must be empty
  541. dbAccounts, err := s.historyDB.GetAllAccounts()
  542. require.NoError(t, err)
  543. sdbAccounts, err := s.stateDB.GetAccounts()
  544. require.NoError(t, err)
  545. assert.Equal(t, 0, len(dbAccounts))
  546. assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)
  547. // Sync blocks 2-6
  548. for i := 0; i < 5; i++ {
  549. syncBlock, discards, err = s.Sync2(ctx, nil)
  550. require.NoError(t, err)
  551. require.Nil(t, discards)
  552. require.NotNil(t, syncBlock)
  553. assert.Nil(t, syncBlock.Rollup.Vars)
  554. assert.Nil(t, syncBlock.Auction.Vars)
  555. assert.Nil(t, syncBlock.WDelayer.Vars)
  556. assert.Equal(t, int64(2+i), syncBlock.Block.Num)
  557. stats = s.Stats()
  558. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  559. assert.Equal(t, int64(6), stats.Eth.LastBlock.Num)
  560. assert.Equal(t, int64(2+i), stats.Sync.LastBlock.Num)
  561. if i == 4 {
  562. assert.Equal(t, true, stats.Synced())
  563. } else {
  564. assert.Equal(t, false, stats.Synced())
  565. }
  566. vars = s.SCVars()
  567. assert.Equal(t, clientSetup.RollupVariables, vars.Rollup)
  568. assert.Equal(t, clientSetup.AuctionVariables, vars.Auction)
  569. assert.Equal(t, clientSetup.WDelayerVariables, vars.WDelayer)
  570. }
  571. dbBlock, err = s.historyDB.GetLastBlock()
  572. require.NoError(t, err)
  573. assert.Equal(t, int64(6), dbBlock.Num)
  574. // Accounts in HistoryDB and StateDB is only 2 entries
  575. dbAccounts, err = s.historyDB.GetAllAccounts()
  576. require.NoError(t, err)
  577. sdbAccounts, err = s.stateDB.GetAccounts()
  578. require.NoError(t, err)
  579. assert.Equal(t, 2, len(dbAccounts))
  580. assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)
  581. }