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.

704 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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.
3 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. assert.NoError(t, err)
  437. require.Nil(t, err)
  438. require.Nil(t, discards)
  439. require.NotNil(t, syncBlock)
  440. assert.Nil(t, syncBlock.Rollup.Vars)
  441. assert.Nil(t, syncBlock.Auction.Vars)
  442. assert.Nil(t, syncBlock.WDelayer.Vars)
  443. assert.Equal(t, int64(3), syncBlock.Block.Num)
  444. stats = s.Stats()
  445. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  446. assert.Equal(t, int64(3), stats.Eth.LastBlock.Num)
  447. assert.Equal(t, int64(3), stats.Sync.LastBlock.Num)
  448. checkSyncBlock(t, s, 3, &blocks[1], syncBlock)
  449. // Block 4
  450. // Generate 2 withdraws manually
  451. _, err = client.RollupWithdrawMerkleProof(tc.Users["A"].BJJ.Public(), 1, 4, 256, big.NewInt(100), []*big.Int{}, true)
  452. require.Nil(t, err)
  453. _, err = client.RollupWithdrawMerkleProof(tc.Users["C"].BJJ.Public(), 1, 3, 258, big.NewInt(50), []*big.Int{}, false)
  454. require.Nil(t, err)
  455. client.CtlMineBlock()
  456. syncBlock, discards, err = s.Sync2(ctx, nil)
  457. require.Nil(t, err)
  458. require.Nil(t, discards)
  459. require.NotNil(t, syncBlock)
  460. assert.Nil(t, syncBlock.Rollup.Vars)
  461. assert.Nil(t, syncBlock.Auction.Vars)
  462. assert.Nil(t, syncBlock.WDelayer.Vars)
  463. assert.Equal(t, int64(4), syncBlock.Block.Num)
  464. stats = s.Stats()
  465. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  466. assert.Equal(t, int64(4), stats.Eth.LastBlock.Num)
  467. assert.Equal(t, int64(4), stats.Sync.LastBlock.Num)
  468. vars = s.SCVars()
  469. assert.Equal(t, clientSetup.RollupVariables, vars.Rollup)
  470. assert.Equal(t, clientSetup.AuctionVariables, vars.Auction)
  471. assert.Equal(t, clientSetup.WDelayerVariables, vars.WDelayer)
  472. dbExits, err := s.historyDB.GetAllExits()
  473. require.Nil(t, err)
  474. foundA1, foundC1 := false, false
  475. for _, exit := range dbExits {
  476. if exit.AccountIdx == 256 && exit.BatchNum == 4 {
  477. foundA1 = true
  478. assert.Equal(t, int64(4), *exit.InstantWithdrawn)
  479. }
  480. if exit.AccountIdx == 258 && exit.BatchNum == 3 {
  481. foundC1 = true
  482. assert.Equal(t, int64(4), *exit.DelayedWithdrawRequest)
  483. }
  484. }
  485. assert.True(t, foundA1)
  486. assert.True(t, foundC1)
  487. // Block 5
  488. // Update variables manually
  489. rollupVars, auctionVars, wDelayerVars, err := s.historyDB.GetSCVars()
  490. require.Nil(t, err)
  491. rollupVars.ForgeL1L2BatchTimeout = 42
  492. _, err = client.RollupUpdateForgeL1L2BatchTimeout(rollupVars.ForgeL1L2BatchTimeout)
  493. require.Nil(t, err)
  494. auctionVars.OpenAuctionSlots = 17
  495. _, err = client.AuctionSetOpenAuctionSlots(auctionVars.OpenAuctionSlots)
  496. require.Nil(t, err)
  497. wDelayerVars.WithdrawalDelay = 99
  498. _, err = client.WDelayerChangeWithdrawalDelay(wDelayerVars.WithdrawalDelay)
  499. require.Nil(t, err)
  500. client.CtlMineBlock()
  501. syncBlock, discards, err = s.Sync2(ctx, nil)
  502. require.Nil(t, err)
  503. require.Nil(t, discards)
  504. require.NotNil(t, syncBlock)
  505. assert.NotNil(t, syncBlock.Rollup.Vars)
  506. assert.NotNil(t, syncBlock.Auction.Vars)
  507. assert.NotNil(t, syncBlock.WDelayer.Vars)
  508. assert.Equal(t, int64(5), syncBlock.Block.Num)
  509. stats = s.Stats()
  510. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  511. assert.Equal(t, int64(5), stats.Eth.LastBlock.Num)
  512. assert.Equal(t, int64(5), stats.Sync.LastBlock.Num)
  513. vars = s.SCVars()
  514. assert.NotEqual(t, clientSetup.RollupVariables, vars.Rollup)
  515. assert.NotEqual(t, clientSetup.AuctionVariables, vars.Auction)
  516. assert.NotEqual(t, clientSetup.WDelayerVariables, vars.WDelayer)
  517. dbRollupVars, dbAuctionVars, dbWDelayerVars, err := s.historyDB.GetSCVars()
  518. require.Nil(t, err)
  519. // Set EthBlockNum for Vars to the blockNum in which they were updated (should be 5)
  520. rollupVars.EthBlockNum = syncBlock.Block.Num
  521. auctionVars.EthBlockNum = syncBlock.Block.Num
  522. wDelayerVars.EthBlockNum = syncBlock.Block.Num
  523. assert.Equal(t, rollupVars, dbRollupVars)
  524. assert.Equal(t, auctionVars, dbAuctionVars)
  525. assert.Equal(t, wDelayerVars, dbWDelayerVars)
  526. //
  527. // Reorg test
  528. //
  529. // Redo blocks 2-5 (as a reorg) only leaving:
  530. // - 2 create account transactions
  531. // - 2 add tokens
  532. // We add a 6th block so that the synchronizer can detect the reorg
  533. set2 := `
  534. Type: Blockchain
  535. AddToken(1)
  536. AddToken(2)
  537. CreateAccountDeposit(1) C: 2000 // Idx=256+1=257
  538. CreateAccountCoordinator(1) A // Idx=256+0=256
  539. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{1}
  540. > batchL1 // forge defined L1UserTxs{1}, freeze L1UserTxs{nil}
  541. > block // blockNum=2
  542. > block // blockNum=3
  543. > block // blockNum=4
  544. > block // blockNum=5
  545. > block // blockNum=6
  546. `
  547. tc = til.NewContext(common.RollupConstMaxL1UserTx)
  548. tilCfgExtra = til.ConfigExtra{
  549. BootCoordAddr: bootCoordAddr,
  550. CoordUser: "A",
  551. }
  552. blocks, err = tc.GenerateBlocks(set2)
  553. require.Nil(t, err)
  554. for i := 0; i < 4; i++ {
  555. client.CtlRollback()
  556. }
  557. block := client.CtlLastBlock()
  558. require.Equal(t, int64(1), block.Num)
  559. // Generate extra required data
  560. ethAddTokens(blocks, client)
  561. err = tc.FillBlocksExtra(blocks, &tilCfgExtra)
  562. assert.NoError(t, err)
  563. tc.FillBlocksL1UserTxsBatchNum(blocks)
  564. // Add block data to the smart contracts
  565. ethAddBlocks(t, blocks, client, clientSetup)
  566. // First sync detects the reorg and discards 4 blocks
  567. syncBlock, discards, err = s.Sync2(ctx, nil)
  568. require.Nil(t, err)
  569. expetedDiscards := int64(4)
  570. require.Equal(t, &expetedDiscards, discards)
  571. require.Nil(t, syncBlock)
  572. stats = s.Stats()
  573. assert.Equal(t, false, stats.Synced())
  574. assert.Equal(t, int64(6), stats.Eth.LastBlock.Num)
  575. vars = s.SCVars()
  576. assert.Equal(t, clientSetup.RollupVariables, vars.Rollup)
  577. assert.Equal(t, clientSetup.AuctionVariables, vars.Auction)
  578. assert.Equal(t, clientSetup.WDelayerVariables, vars.WDelayer)
  579. // At this point, the DB only has data up to block 1
  580. dbBlock, err := s.historyDB.GetLastBlock()
  581. require.Nil(t, err)
  582. assert.Equal(t, int64(1), dbBlock.Num)
  583. // Accounts in HistoryDB and StateDB must be empty
  584. dbAccounts, err := s.historyDB.GetAllAccounts()
  585. require.Nil(t, err)
  586. sdbAccounts, err := s.stateDB.GetAccounts()
  587. require.Nil(t, err)
  588. assert.Equal(t, 0, len(dbAccounts))
  589. assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)
  590. // Sync blocks 2-6
  591. for i := 0; i < 5; i++ {
  592. syncBlock, discards, err = s.Sync2(ctx, nil)
  593. require.Nil(t, err)
  594. require.Nil(t, discards)
  595. require.NotNil(t, syncBlock)
  596. assert.Nil(t, syncBlock.Rollup.Vars)
  597. assert.Nil(t, syncBlock.Auction.Vars)
  598. assert.Nil(t, syncBlock.WDelayer.Vars)
  599. assert.Equal(t, int64(2+i), syncBlock.Block.Num)
  600. stats = s.Stats()
  601. assert.Equal(t, int64(1), stats.Eth.FirstBlockNum)
  602. assert.Equal(t, int64(6), stats.Eth.LastBlock.Num)
  603. assert.Equal(t, int64(2+i), stats.Sync.LastBlock.Num)
  604. if i == 4 {
  605. assert.Equal(t, true, stats.Synced())
  606. } else {
  607. assert.Equal(t, false, stats.Synced())
  608. }
  609. vars = s.SCVars()
  610. assert.Equal(t, clientSetup.RollupVariables, vars.Rollup)
  611. assert.Equal(t, clientSetup.AuctionVariables, vars.Auction)
  612. assert.Equal(t, clientSetup.WDelayerVariables, vars.WDelayer)
  613. }
  614. dbBlock, err = s.historyDB.GetLastBlock()
  615. require.Nil(t, err)
  616. assert.Equal(t, int64(6), dbBlock.Num)
  617. // Accounts in HistoryDB and StateDB is only 2 entries
  618. dbAccounts, err = s.historyDB.GetAllAccounts()
  619. require.Nil(t, err)
  620. sdbAccounts, err = s.stateDB.GetAccounts()
  621. require.Nil(t, err)
  622. assert.Equal(t, 2, len(dbAccounts))
  623. assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)
  624. }