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.

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