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.

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