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.

703 lines
22 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 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.Nil(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.Nil(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.Nil(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.Nil(t, err)
  105. dbL1CoordinatorTxs, err := s.historyDB.GetAllL1CoordinatorTxs()
  106. require.Nil(t, err)
  107. dbL2Txs, err := s.historyDB.GetAllL2Txs()
  108. require.Nil(t, err)
  109. dbExits, err := s.historyDB.GetAllExits()
  110. require.Nil(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.Nil(t, err)
  208. dbMtp, err := json.Marshal(dbExit.MerkleProof)
  209. require.Nil(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.Nil(t, err)
  218. sdbAccounts, err := s.stateDB.GetAccounts()
  219. require.Nil(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. // ethAddBlocks adds block data to the smart contracts
  250. func ethAddBlocks(t *testing.T, blocks []common.BlockData,
  251. client *test.Client, clientSetup *test.ClientSetup) {
  252. for _, block := range blocks {
  253. for _, token := range block.Rollup.AddedTokens {
  254. _, err := client.RollupAddTokenSimple(token.EthAddr, clientSetup.RollupVariables.FeeAddToken)
  255. require.Nil(t, err)
  256. }
  257. for _, tx := range block.Rollup.L1UserTxs {
  258. client.CtlSetAddr(tx.FromEthAddr)
  259. _, err := client.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.DepositAmount, tx.Amount,
  260. uint32(tx.TokenID), int64(tx.ToIdx))
  261. require.Nil(t, err)
  262. }
  263. client.CtlSetAddr(clientSetup.AuctionVariables.BootCoordinator)
  264. for _, batch := range block.Rollup.Batches {
  265. _, err := client.RollupForgeBatch(&eth.RollupForgeBatchArgs{
  266. NewLastIdx: batch.Batch.LastIdx,
  267. NewStRoot: batch.Batch.StateRoot,
  268. NewExitRoot: batch.Batch.ExitRoot,
  269. L1CoordinatorTxs: batch.L1CoordinatorTxs,
  270. L1CoordinatorTxsAuths: [][]byte{}, // Intentionally empty
  271. L2TxsData: batch.L2Txs,
  272. FeeIdxCoordinator: batch.Batch.FeeIdxsCoordinator,
  273. // Circuit selector
  274. VerifierIdx: 0, // Intentionally empty
  275. L1Batch: batch.L1Batch,
  276. ProofA: [2]*big.Int{}, // Intentionally empty
  277. ProofB: [2][2]*big.Int{}, // Intentionally empty
  278. ProofC: [2]*big.Int{}, // Intentionally empty
  279. })
  280. require.Nil(t, err)
  281. }
  282. // Mine block and sync
  283. client.CtlMineBlock()
  284. }
  285. }
  286. func TestSync(t *testing.T) {
  287. //
  288. // Setup
  289. //
  290. ctx := context.Background()
  291. // Int State DB
  292. dir, err := ioutil.TempDir("", "tmpdb")
  293. require.Nil(t, err)
  294. defer assert.Nil(t, os.RemoveAll(dir))
  295. stateDB, err := statedb.NewStateDB(dir, statedb.TypeSynchronizer, 32)
  296. assert.NoError(t, err)
  297. // Init History DB
  298. pass := os.Getenv("POSTGRES_PASS")
  299. db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
  300. require.Nil(t, err)
  301. historyDB := historydb.NewHistoryDB(db)
  302. // Clear DB
  303. test.WipeDB(historyDB.DB())
  304. // Init eth client
  305. var timer timer
  306. clientSetup := test.NewClientSetupExample()
  307. bootCoordAddr := clientSetup.AuctionVariables.BootCoordinator
  308. client := test.NewClient(true, &timer, &ethCommon.Address{}, clientSetup)
  309. // Create Synchronizer
  310. s, err := NewSynchronizer(client, historyDB, stateDB, Config{
  311. StartBlockNum: ConfigStartBlockNum{
  312. Rollup: 1,
  313. Auction: 1,
  314. WDelayer: 1,
  315. },
  316. InitialVariables: SCVariables{
  317. Rollup: *clientSetup.RollupVariables,
  318. Auction: *clientSetup.AuctionVariables,
  319. WDelayer: *clientSetup.WDelayerVariables,
  320. },
  321. })
  322. require.Nil(t, err)
  323. //
  324. // First Sync from an initial state
  325. //
  326. stats := s.Stats()
  327. assert.Equal(t, false, stats.Synced())
  328. // Test Sync for rollup genesis block
  329. syncBlock, discards, err := s.Sync2(ctx, nil)
  330. require.Nil(t, err)
  331. require.Nil(t, discards)
  332. require.NotNil(t, syncBlock)
  333. require.Nil(t, syncBlock.Rollup.Vars)
  334. require.Nil(t, syncBlock.Auction.Vars)
  335. require.Nil(t, syncBlock.WDelayer.Vars)
  336. assert.Equal(t, int64(1), syncBlock.Block.Num)
  337. stats = s.Stats()
  338. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  339. assert.Equal(t, int64(1), stats.Eth.LastBlock.Num)
  340. assert.Equal(t, int64(1), stats.Sync.LastBlock.Num)
  341. vars := s.SCVars()
  342. assert.Equal(t, clientSetup.RollupVariables, vars.Rollup)
  343. assert.Equal(t, clientSetup.AuctionVariables, vars.Auction)
  344. assert.Equal(t, clientSetup.WDelayerVariables, vars.WDelayer)
  345. dbBlocks, err := s.historyDB.GetAllBlocks()
  346. require.Nil(t, err)
  347. assert.Equal(t, 2, len(dbBlocks))
  348. assert.Equal(t, int64(1), dbBlocks[1].Num)
  349. // Sync again and expect no new blocks
  350. syncBlock, discards, err = s.Sync2(ctx, nil)
  351. require.Nil(t, err)
  352. require.Nil(t, discards)
  353. require.Nil(t, syncBlock)
  354. //
  355. // Generate blockchain and smart contract data, and fill the test smart contracts
  356. //
  357. // Generate blockchain data with til
  358. set1 := `
  359. Type: Blockchain
  360. AddToken(1)
  361. AddToken(2)
  362. AddToken(3)
  363. CreateAccountDeposit(1) C: 2000 // Idx=256+2=258
  364. CreateAccountDeposit(2) A: 2000 // Idx=256+3=259
  365. CreateAccountDeposit(1) D: 500 // Idx=256+4=260
  366. CreateAccountDeposit(2) B: 500 // Idx=256+5=261
  367. CreateAccountDeposit(2) C: 500 // Idx=256+6=262
  368. CreateAccountCoordinator(1) A // Idx=256+0=256
  369. CreateAccountCoordinator(1) B // Idx=256+1=257
  370. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{5}
  371. > batchL1 // forge defined L1UserTxs{5}, freeze L1UserTxs{nil}
  372. > block // blockNum=2
  373. CreateAccountDepositTransfer(1) E-A: 1000, 200 // Idx=256+7=263
  374. ForceTransfer(1) C-B: 80
  375. ForceExit(1) A: 100
  376. ForceExit(1) B: 80
  377. ForceTransfer(1) A-D: 100
  378. Transfer(1) C-A: 100 (200)
  379. Exit(1) C: 50 (200)
  380. Exit(1) D: 30 (200)
  381. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{3}
  382. > batchL1 // forge L1UserTxs{3}, freeze defined L1UserTxs{nil}
  383. > block // blockNum=3
  384. `
  385. tc := til.NewContext(common.RollupConstMaxL1UserTx)
  386. tilCfgExtra := til.ConfigExtra{
  387. BootCoordAddr: bootCoordAddr,
  388. CoordUser: "A",
  389. }
  390. blocks, err := tc.GenerateBlocks(set1)
  391. require.Nil(t, err)
  392. // Sanity check
  393. require.Equal(t, 2, len(blocks))
  394. // blocks 0 (blockNum=2)
  395. i := 0
  396. require.Equal(t, 2, int(blocks[i].Block.Num))
  397. require.Equal(t, 3, len(blocks[i].Rollup.AddedTokens))
  398. require.Equal(t, 5, len(blocks[i].Rollup.L1UserTxs))
  399. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  400. require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L1CoordinatorTxs))
  401. // blocks 1 (blockNum=3)
  402. i = 1
  403. require.Equal(t, 3, int(blocks[i].Block.Num))
  404. require.Equal(t, 5, len(blocks[i].Rollup.L1UserTxs))
  405. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  406. require.Equal(t, 3, len(blocks[i].Rollup.Batches[0].L2Txs))
  407. // Generate extra required data
  408. ethAddTokens(blocks, client)
  409. err = tc.FillBlocksExtra(blocks, &tilCfgExtra)
  410. assert.NoError(t, err)
  411. tc.FillBlocksL1UserTxsBatchNum(blocks)
  412. err = tc.FillBlocksForgedL1UserTxs(blocks)
  413. assert.NoError(t, err)
  414. // Add block data to the smart contracts
  415. ethAddBlocks(t, blocks, client, clientSetup)
  416. //
  417. // Sync to synchronize the current state from the test smart contracts,
  418. // and check the outcome
  419. //
  420. // Block 2
  421. syncBlock, discards, err = s.Sync2(ctx, nil)
  422. require.Nil(t, err)
  423. require.Nil(t, discards)
  424. require.NotNil(t, syncBlock)
  425. assert.Nil(t, syncBlock.Rollup.Vars)
  426. assert.Nil(t, syncBlock.Auction.Vars)
  427. assert.Nil(t, syncBlock.WDelayer.Vars)
  428. assert.Equal(t, int64(2), syncBlock.Block.Num)
  429. stats = s.Stats()
  430. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  431. assert.Equal(t, int64(3), stats.Eth.LastBlock.Num)
  432. assert.Equal(t, int64(2), stats.Sync.LastBlock.Num)
  433. checkSyncBlock(t, s, 2, &blocks[0], syncBlock)
  434. // Block 3
  435. syncBlock, discards, err = s.Sync2(ctx, nil)
  436. require.Nil(t, err)
  437. require.Nil(t, discards)
  438. require.NotNil(t, syncBlock)
  439. assert.Nil(t, syncBlock.Rollup.Vars)
  440. assert.Nil(t, syncBlock.Auction.Vars)
  441. assert.Nil(t, syncBlock.WDelayer.Vars)
  442. assert.Equal(t, int64(3), syncBlock.Block.Num)
  443. stats = s.Stats()
  444. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  445. assert.Equal(t, int64(3), stats.Eth.LastBlock.Num)
  446. assert.Equal(t, int64(3), stats.Sync.LastBlock.Num)
  447. checkSyncBlock(t, s, 3, &blocks[1], syncBlock)
  448. // Block 4
  449. // Generate 2 withdraws manually
  450. _, err = client.RollupWithdrawMerkleProof(tc.Users["A"].BJJ.Public(), 1, 4, 256, big.NewInt(100), []*big.Int{}, true)
  451. require.Nil(t, err)
  452. _, err = client.RollupWithdrawMerkleProof(tc.Users["C"].BJJ.Public(), 1, 3, 258, big.NewInt(50), []*big.Int{}, false)
  453. require.Nil(t, err)
  454. client.CtlMineBlock()
  455. syncBlock, discards, err = s.Sync2(ctx, nil)
  456. require.Nil(t, err)
  457. require.Nil(t, discards)
  458. require.NotNil(t, syncBlock)
  459. assert.Nil(t, syncBlock.Rollup.Vars)
  460. assert.Nil(t, syncBlock.Auction.Vars)
  461. assert.Nil(t, syncBlock.WDelayer.Vars)
  462. assert.Equal(t, int64(4), syncBlock.Block.Num)
  463. stats = s.Stats()
  464. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  465. assert.Equal(t, int64(4), stats.Eth.LastBlock.Num)
  466. assert.Equal(t, int64(4), stats.Sync.LastBlock.Num)
  467. vars = s.SCVars()
  468. assert.Equal(t, clientSetup.RollupVariables, vars.Rollup)
  469. assert.Equal(t, clientSetup.AuctionVariables, vars.Auction)
  470. assert.Equal(t, clientSetup.WDelayerVariables, vars.WDelayer)
  471. dbExits, err := s.historyDB.GetAllExits()
  472. require.Nil(t, err)
  473. foundA1, foundC1 := false, false
  474. for _, exit := range dbExits {
  475. if exit.AccountIdx == 256 && exit.BatchNum == 4 {
  476. foundA1 = true
  477. assert.Equal(t, int64(4), *exit.InstantWithdrawn)
  478. }
  479. if exit.AccountIdx == 258 && exit.BatchNum == 3 {
  480. foundC1 = true
  481. assert.Equal(t, int64(4), *exit.DelayedWithdrawRequest)
  482. }
  483. }
  484. assert.True(t, foundA1)
  485. assert.True(t, foundC1)
  486. // Block 5
  487. // Update variables manually
  488. rollupVars, auctionVars, wDelayerVars, err := s.historyDB.GetSCVars()
  489. require.Nil(t, err)
  490. rollupVars.ForgeL1L2BatchTimeout = 42
  491. _, err = client.RollupUpdateForgeL1L2BatchTimeout(rollupVars.ForgeL1L2BatchTimeout)
  492. require.Nil(t, err)
  493. auctionVars.OpenAuctionSlots = 17
  494. _, err = client.AuctionSetOpenAuctionSlots(auctionVars.OpenAuctionSlots)
  495. require.Nil(t, err)
  496. wDelayerVars.WithdrawalDelay = 99
  497. _, err = client.WDelayerChangeWithdrawalDelay(wDelayerVars.WithdrawalDelay)
  498. require.Nil(t, err)
  499. client.CtlMineBlock()
  500. syncBlock, discards, err = s.Sync2(ctx, nil)
  501. require.Nil(t, err)
  502. require.Nil(t, discards)
  503. require.NotNil(t, syncBlock)
  504. assert.NotNil(t, syncBlock.Rollup.Vars)
  505. assert.NotNil(t, syncBlock.Auction.Vars)
  506. assert.NotNil(t, syncBlock.WDelayer.Vars)
  507. assert.Equal(t, int64(5), syncBlock.Block.Num)
  508. stats = s.Stats()
  509. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  510. assert.Equal(t, int64(5), stats.Eth.LastBlock.Num)
  511. assert.Equal(t, int64(5), stats.Sync.LastBlock.Num)
  512. vars = s.SCVars()
  513. assert.NotEqual(t, clientSetup.RollupVariables, vars.Rollup)
  514. assert.NotEqual(t, clientSetup.AuctionVariables, vars.Auction)
  515. assert.NotEqual(t, clientSetup.WDelayerVariables, vars.WDelayer)
  516. dbRollupVars, dbAuctionVars, dbWDelayerVars, err := s.historyDB.GetSCVars()
  517. require.Nil(t, err)
  518. // Set EthBlockNum for Vars to the blockNum in which they were updated (should be 5)
  519. rollupVars.EthBlockNum = syncBlock.Block.Num
  520. auctionVars.EthBlockNum = syncBlock.Block.Num
  521. wDelayerVars.EthBlockNum = syncBlock.Block.Num
  522. assert.Equal(t, rollupVars, dbRollupVars)
  523. assert.Equal(t, auctionVars, dbAuctionVars)
  524. assert.Equal(t, wDelayerVars, dbWDelayerVars)
  525. //
  526. // Reorg test
  527. //
  528. // Redo blocks 2-5 (as a reorg) only leaving:
  529. // - 2 create account transactions
  530. // - 2 add tokens
  531. // We add a 6th block so that the synchronizer can detect the reorg
  532. set2 := `
  533. Type: Blockchain
  534. AddToken(1)
  535. AddToken(2)
  536. CreateAccountDeposit(1) C: 2000 // Idx=256+1=257
  537. CreateAccountCoordinator(1) A // Idx=256+0=256
  538. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{1}
  539. > batchL1 // forge defined L1UserTxs{1}, freeze L1UserTxs{nil}
  540. > block // blockNum=2
  541. > block // blockNum=3
  542. > block // blockNum=4
  543. > block // blockNum=5
  544. > block // blockNum=6
  545. `
  546. tc = til.NewContext(common.RollupConstMaxL1UserTx)
  547. tilCfgExtra = til.ConfigExtra{
  548. BootCoordAddr: bootCoordAddr,
  549. CoordUser: "A",
  550. }
  551. blocks, err = tc.GenerateBlocks(set2)
  552. require.Nil(t, err)
  553. for i := 0; i < 4; i++ {
  554. client.CtlRollback()
  555. }
  556. block := client.CtlLastBlock()
  557. require.Equal(t, int64(1), block.Num)
  558. // Generate extra required data
  559. ethAddTokens(blocks, client)
  560. err = tc.FillBlocksExtra(blocks, &tilCfgExtra)
  561. assert.NoError(t, err)
  562. tc.FillBlocksL1UserTxsBatchNum(blocks)
  563. // Add block data to the smart contracts
  564. ethAddBlocks(t, blocks, client, clientSetup)
  565. // First sync detects the reorg and discards 4 blocks
  566. syncBlock, discards, err = s.Sync2(ctx, nil)
  567. require.Nil(t, err)
  568. expetedDiscards := int64(4)
  569. require.Equal(t, &expetedDiscards, discards)
  570. require.Nil(t, syncBlock)
  571. stats = s.Stats()
  572. assert.Equal(t, false, stats.Synced())
  573. assert.Equal(t, int64(6), stats.Eth.LastBlock.Num)
  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. // At this point, the DB only has data up to block 1
  579. dbBlock, err := s.historyDB.GetLastBlock()
  580. require.Nil(t, err)
  581. assert.Equal(t, int64(1), dbBlock.Num)
  582. // Accounts in HistoryDB and StateDB must be empty
  583. dbAccounts, err := s.historyDB.GetAllAccounts()
  584. require.Nil(t, err)
  585. sdbAccounts, err := s.stateDB.GetAccounts()
  586. require.Nil(t, err)
  587. assert.Equal(t, 0, len(dbAccounts))
  588. assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)
  589. // Sync blocks 2-6
  590. for i := 0; i < 5; i++ {
  591. syncBlock, discards, err = s.Sync2(ctx, nil)
  592. require.Nil(t, err)
  593. require.Nil(t, discards)
  594. require.NotNil(t, syncBlock)
  595. assert.Nil(t, syncBlock.Rollup.Vars)
  596. assert.Nil(t, syncBlock.Auction.Vars)
  597. assert.Nil(t, syncBlock.WDelayer.Vars)
  598. assert.Equal(t, int64(2+i), syncBlock.Block.Num)
  599. stats = s.Stats()
  600. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  601. assert.Equal(t, int64(6), stats.Eth.LastBlock.Num)
  602. assert.Equal(t, int64(2+i), stats.Sync.LastBlock.Num)
  603. if i == 4 {
  604. assert.Equal(t, true, stats.Synced())
  605. } else {
  606. assert.Equal(t, false, stats.Synced())
  607. }
  608. vars = s.SCVars()
  609. assert.Equal(t, clientSetup.RollupVariables, vars.Rollup)
  610. assert.Equal(t, clientSetup.AuctionVariables, vars.Auction)
  611. assert.Equal(t, clientSetup.WDelayerVariables, vars.WDelayer)
  612. }
  613. dbBlock, err = s.historyDB.GetLastBlock()
  614. require.Nil(t, err)
  615. assert.Equal(t, int64(6), dbBlock.Num)
  616. // Accounts in HistoryDB and StateDB is only 2 entries
  617. dbAccounts, err = s.historyDB.GetAllAccounts()
  618. require.Nil(t, err)
  619. sdbAccounts, err = s.stateDB.GetAccounts()
  620. require.Nil(t, err)
  621. assert.Equal(t, 2, len(dbAccounts))
  622. assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)
  623. }