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.

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