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.

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