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.

425 lines
13 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 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 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 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
  1. package synchronizer
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "math/big"
  8. "os"
  9. "testing"
  10. ethCommon "github.com/ethereum/go-ethereum/common"
  11. "github.com/hermeznetwork/hermez-node/common"
  12. dbUtils "github.com/hermeznetwork/hermez-node/db"
  13. "github.com/hermeznetwork/hermez-node/db/historydb"
  14. "github.com/hermeznetwork/hermez-node/db/statedb"
  15. "github.com/hermeznetwork/hermez-node/eth"
  16. "github.com/hermeznetwork/hermez-node/test"
  17. "github.com/hermeznetwork/hermez-node/test/til"
  18. "github.com/jinzhu/copier"
  19. "github.com/stretchr/testify/assert"
  20. "github.com/stretchr/testify/require"
  21. )
  22. var tokenConsts = map[common.TokenID]eth.ERC20Consts{}
  23. type timer struct {
  24. time int64
  25. }
  26. func (t *timer) Time() int64 {
  27. currentTime := t.time
  28. t.time++
  29. return currentTime
  30. }
  31. // Check Sync output and HistoryDB state against expected values generated by
  32. // til
  33. func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, syncBlock *common.BlockData) {
  34. // Check Blocks
  35. dbBlocks, err := s.historyDB.GetAllBlocks()
  36. require.Nil(t, err)
  37. dbBlocks = dbBlocks[1:] // ignore block 0, added by default in the DB
  38. assert.Equal(t, blockNum, len(dbBlocks))
  39. assert.Equal(t, int64(blockNum), dbBlocks[blockNum-1].EthBlockNum)
  40. assert.NotEqual(t, dbBlocks[blockNum-1].Hash, dbBlocks[blockNum-2].Hash)
  41. assert.Greater(t, dbBlocks[blockNum-1].Timestamp.Unix(), dbBlocks[blockNum-2].Timestamp.Unix())
  42. // Check Tokens
  43. assert.Equal(t, len(block.Rollup.AddedTokens), len(syncBlock.Rollup.AddedTokens))
  44. dbTokens, err := s.historyDB.GetAllTokens()
  45. require.Nil(t, err)
  46. dbTokens = dbTokens[1:] // ignore token 0, added by default in the DB
  47. for i, token := range block.Rollup.AddedTokens {
  48. dbToken := dbTokens[i]
  49. syncToken := syncBlock.Rollup.AddedTokens[i]
  50. assert.Equal(t, block.Block.EthBlockNum, syncToken.EthBlockNum)
  51. assert.Equal(t, token.TokenID, syncToken.TokenID)
  52. assert.Equal(t, token.EthAddr, syncToken.EthAddr)
  53. tokenConst := tokenConsts[token.TokenID]
  54. assert.Equal(t, tokenConst.Name, syncToken.Name)
  55. assert.Equal(t, tokenConst.Symbol, syncToken.Symbol)
  56. assert.Equal(t, tokenConst.Decimals, syncToken.Decimals)
  57. var tokenCpy historydb.TokenWithUSD
  58. //nolint:gosec
  59. require.Nil(t, copier.Copy(&tokenCpy, &token)) // copy common.Token to historydb.TokenWithUSD
  60. require.Nil(t, copier.Copy(&tokenCpy, &tokenConst)) // copy common.Token to historydb.TokenWithUSD
  61. tokenCpy.ItemID = dbToken.ItemID // we don't care about ItemID
  62. assert.Equal(t, tokenCpy, dbToken)
  63. }
  64. // Check L1UserTxs
  65. assert.Equal(t, len(block.Rollup.L1UserTxs), len(syncBlock.Rollup.L1UserTxs))
  66. dbL1UserTxs, err := s.historyDB.GetAllL1UserTxs()
  67. require.Nil(t, err)
  68. // Ignore BatchNum in syncBlock.L1UserTxs because this value is set by the HistoryDB
  69. for i := range syncBlock.Rollup.L1UserTxs {
  70. syncBlock.Rollup.L1UserTxs[i].BatchNum = block.Rollup.L1UserTxs[i].BatchNum
  71. }
  72. assert.Equal(t, block.Rollup.L1UserTxs, syncBlock.Rollup.L1UserTxs)
  73. for _, tx := range block.Rollup.L1UserTxs {
  74. var dbTx *common.L1Tx
  75. // Find tx in DB output
  76. for _, _dbTx := range dbL1UserTxs {
  77. if *tx.ToForgeL1TxsNum == *_dbTx.ToForgeL1TxsNum &&
  78. tx.Position == _dbTx.Position {
  79. dbTx = new(common.L1Tx)
  80. *dbTx = _dbTx
  81. break
  82. }
  83. }
  84. assert.Equal(t, &tx, dbTx) //nolint:gosec
  85. }
  86. // Check Batches
  87. assert.Equal(t, len(block.Rollup.Batches), len(syncBlock.Rollup.Batches))
  88. dbBatches, err := s.historyDB.GetAllBatches()
  89. require.Nil(t, err)
  90. dbL1CoordinatorTxs, err := s.historyDB.GetAllL1CoordinatorTxs()
  91. require.Nil(t, err)
  92. dbL2Txs, err := s.historyDB.GetAllL2Txs()
  93. require.Nil(t, err)
  94. dbExits, err := s.historyDB.GetAllExits()
  95. require.Nil(t, err)
  96. // dbL1CoordinatorTxs := []common.L1Tx{}
  97. for i, batch := range block.Rollup.Batches {
  98. var dbBatch *common.Batch
  99. // Find batch in DB output
  100. for _, _dbBatch := range dbBatches {
  101. if batch.Batch.BatchNum == _dbBatch.BatchNum {
  102. dbBatch = new(common.Batch)
  103. *dbBatch = _dbBatch
  104. break
  105. }
  106. }
  107. syncBatch := syncBlock.Rollup.Batches[i]
  108. // We don't care about TotalFeesUSD. Use the syncBatch that
  109. // has a TotalFeesUSD inserted by the HistoryDB
  110. batch.Batch.TotalFeesUSD = syncBatch.Batch.TotalFeesUSD
  111. assert.Equal(t, batch.CreatedAccounts, syncBatch.CreatedAccounts)
  112. batch.Batch.NumAccounts = len(batch.CreatedAccounts)
  113. // Test field by field to facilitate debugging of errors
  114. assert.Equal(t, batch.L1CoordinatorTxs, syncBatch.L1CoordinatorTxs)
  115. assert.Equal(t, batch.L2Txs, syncBatch.L2Txs)
  116. // In exit tree, we only check AccountIdx and Balance, because
  117. // it's what we have precomputed before.
  118. for j := range batch.ExitTree {
  119. exit := &batch.ExitTree[j]
  120. assert.Equal(t, exit.AccountIdx, syncBatch.ExitTree[j].AccountIdx)
  121. assert.Equal(t, exit.Balance, syncBatch.ExitTree[j].Balance)
  122. *exit = syncBatch.ExitTree[j]
  123. }
  124. assert.Equal(t, batch.Batch, syncBatch.Batch)
  125. assert.Equal(t, batch, syncBatch)
  126. assert.Equal(t, &batch.Batch, dbBatch) //nolint:gosec
  127. // Check L1CoordinatorTxs from DB
  128. for _, tx := range batch.L1CoordinatorTxs {
  129. var dbTx *common.L1Tx
  130. // Find tx in DB output
  131. for _, _dbTx := range dbL1CoordinatorTxs {
  132. if *tx.BatchNum == *_dbTx.BatchNum &&
  133. tx.Position == _dbTx.Position {
  134. dbTx = new(common.L1Tx)
  135. *dbTx = _dbTx
  136. break
  137. }
  138. }
  139. assert.Equal(t, &tx, dbTx) //nolint:gosec
  140. }
  141. // Check L2Txs from DB
  142. for _, tx := range batch.L2Txs {
  143. var dbTx *common.L2Tx
  144. // Find tx in DB output
  145. for _, _dbTx := range dbL2Txs {
  146. if tx.BatchNum == _dbTx.BatchNum &&
  147. tx.Position == _dbTx.Position {
  148. dbTx = new(common.L2Tx)
  149. *dbTx = _dbTx
  150. break
  151. }
  152. }
  153. assert.Equal(t, &tx, dbTx) //nolint:gosec
  154. }
  155. // Check Exits from DB
  156. for _, exit := range batch.ExitTree {
  157. var dbExit *common.ExitInfo
  158. // Find exit in DB output
  159. for _, _dbExit := range dbExits {
  160. if exit.BatchNum == _dbExit.BatchNum &&
  161. exit.AccountIdx == _dbExit.AccountIdx {
  162. dbExit = new(common.ExitInfo)
  163. *dbExit = _dbExit
  164. break
  165. }
  166. }
  167. // Compare MerkleProof in JSON because unmarshaled 0
  168. // big.Int leaves the internal big.Int array at nil,
  169. // and gives trouble when comparing big.Int with
  170. // internal big.Int array != nil but empty.
  171. mtp, err := json.Marshal(exit.MerkleProof)
  172. require.Nil(t, err)
  173. dbMtp, err := json.Marshal(dbExit.MerkleProof)
  174. require.Nil(t, err)
  175. assert.Equal(t, mtp, dbMtp)
  176. dbExit.MerkleProof = exit.MerkleProof
  177. assert.Equal(t, &exit, dbExit) //nolint:gosec
  178. }
  179. }
  180. }
  181. func TestSync(t *testing.T) {
  182. //
  183. // Setup
  184. //
  185. ctx := context.Background()
  186. // Int State DB
  187. dir, err := ioutil.TempDir("", "tmpdb")
  188. require.Nil(t, err)
  189. defer assert.Nil(t, os.RemoveAll(dir))
  190. stateDB, err := statedb.NewStateDB(dir, statedb.TypeSynchronizer, 32)
  191. assert.Nil(t, err)
  192. // Init History DB
  193. pass := os.Getenv("POSTGRES_PASS")
  194. db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez")
  195. require.Nil(t, err)
  196. historyDB := historydb.NewHistoryDB(db)
  197. // Clear DB
  198. test.WipeDB(historyDB.DB())
  199. // Init eth client
  200. var timer timer
  201. clientSetup := test.NewClientSetupExample()
  202. bootCoordAddr := clientSetup.AuctionVariables.BootCoordinator
  203. client := test.NewClient(true, &timer, &ethCommon.Address{}, clientSetup)
  204. // Create Synchronizer
  205. s, err := NewSynchronizer(client, historyDB, stateDB, Config{
  206. StartBlockNum: ConfigStartBlockNum{
  207. Rollup: 1,
  208. Auction: 1,
  209. WDelayer: 1,
  210. },
  211. InitialVariables: SCVariables{
  212. Rollup: *clientSetup.RollupVariables,
  213. Auction: *clientSetup.AuctionVariables,
  214. WDelayer: *clientSetup.WDelayerVariables,
  215. },
  216. })
  217. require.Nil(t, err)
  218. //
  219. // First Sync from an initial state
  220. //
  221. // Test Sync for rollup genesis block
  222. syncBlock, discards, err := s.Sync2(ctx, nil)
  223. require.Nil(t, err)
  224. require.Nil(t, discards)
  225. require.NotNil(t, syncBlock)
  226. assert.Equal(t, int64(1), syncBlock.Block.EthBlockNum)
  227. dbBlocks, err := s.historyDB.GetAllBlocks()
  228. require.Nil(t, err)
  229. assert.Equal(t, 2, len(dbBlocks))
  230. assert.Equal(t, int64(1), dbBlocks[1].EthBlockNum)
  231. // Sync again and expect no new blocks
  232. syncBlock, discards, err = s.Sync2(ctx, nil)
  233. require.Nil(t, err)
  234. require.Nil(t, discards)
  235. require.Nil(t, syncBlock)
  236. //
  237. // Generate blockchain and smart contract data, and fill the test smart contracts
  238. //
  239. // Generate blockchain data with til
  240. set1 := `
  241. Type: Blockchain
  242. AddToken(1)
  243. AddToken(2)
  244. AddToken(3)
  245. CreateAccountDeposit(1) C: 2000 // Idx=256+2=258
  246. CreateAccountDeposit(2) A: 2000 // Idx=256+3=259
  247. CreateAccountDeposit(1) D: 500 // Idx=256+4=260
  248. CreateAccountDeposit(2) B: 500 // Idx=256+5=261
  249. CreateAccountDeposit(2) C: 500 // Idx=256+6=262
  250. CreateAccountCoordinator(1) A // Idx=256+0=256
  251. CreateAccountCoordinator(1) B // Idx=256+1=257
  252. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{5}
  253. > batchL1 // forge defined L1UserTxs{5}, freeze L1UserTxs{nil}
  254. > block // blockNum=2
  255. CreateAccountDepositTransfer(1) E-A: 1000, 200 // Idx=256+7=263
  256. ForceExit(1) A: 100
  257. ForceTransfer(1) A-D: 100
  258. Transfer(1) C-A: 100 (200)
  259. Exit(1) D: 30 (200)
  260. > batchL1 // forge L1UserTxs{nil}, freeze defined L1UserTxs{2}
  261. > batchL1 // forge L1UserTxs{2}, freeze defined L1UserTxs{nil}
  262. > block // blockNum=3
  263. `
  264. tc := til.NewContext(common.RollupConstMaxL1UserTx)
  265. tilCfgExtra := til.ConfigExtra{
  266. BootCoordAddr: bootCoordAddr,
  267. CoordUser: "A",
  268. }
  269. blocks, err := tc.GenerateBlocks(set1)
  270. require.Nil(t, err)
  271. // Sanity check
  272. require.Equal(t, 2, len(blocks))
  273. // blocks 0 (blockNum=2)
  274. i := 0
  275. require.Equal(t, 2, int(blocks[i].Block.EthBlockNum))
  276. require.Equal(t, 3, len(blocks[i].Rollup.AddedTokens))
  277. require.Equal(t, 5, len(blocks[i].Rollup.L1UserTxs))
  278. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  279. require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L1CoordinatorTxs))
  280. // blocks 1 (blockNum=3)
  281. i = 1
  282. require.Equal(t, 3, int(blocks[i].Block.EthBlockNum))
  283. require.Equal(t, 3, len(blocks[i].Rollup.L1UserTxs))
  284. require.Equal(t, 2, len(blocks[i].Rollup.Batches))
  285. require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L2Txs))
  286. // Generate extra required data
  287. for _, block := range blocks {
  288. for _, token := range block.Rollup.AddedTokens {
  289. consts := eth.ERC20Consts{
  290. Name: fmt.Sprintf("Token %d", token.TokenID),
  291. Symbol: fmt.Sprintf("TK%d", token.TokenID),
  292. Decimals: 18,
  293. }
  294. tokenConsts[token.TokenID] = consts
  295. client.CtlAddERC20(token.EthAddr, consts)
  296. }
  297. }
  298. err = tc.FillBlocksExtra(blocks, &tilCfgExtra)
  299. assert.Nil(t, err)
  300. // Add block data to the smart contracts
  301. for _, block := range blocks {
  302. for _, token := range block.Rollup.AddedTokens {
  303. _, err := client.RollupAddTokenSimple(token.EthAddr, clientSetup.RollupVariables.FeeAddToken)
  304. require.Nil(t, err)
  305. }
  306. for _, tx := range block.Rollup.L1UserTxs {
  307. client.CtlSetAddr(tx.FromEthAddr)
  308. _, err := client.RollupL1UserTxERC20ETH(tx.FromBJJ, int64(tx.FromIdx), tx.LoadAmount, tx.Amount,
  309. uint32(tx.TokenID), int64(tx.ToIdx))
  310. require.Nil(t, err)
  311. }
  312. client.CtlSetAddr(bootCoordAddr)
  313. // feeIdxCoordinator := []common.Idx{}
  314. // if block.Block.EthBlockNum > 2 {
  315. // // After blockNum=2 we have some accounts, use them as
  316. // // coordinator owned to receive fees.
  317. // feeIdxCoordinator = []common.Idx{common.Idx(256), common.Idx(259)}
  318. // }
  319. for _, batch := range block.Rollup.Batches {
  320. _, err := client.RollupForgeBatch(&eth.RollupForgeBatchArgs{
  321. NewLastIdx: batch.Batch.LastIdx,
  322. NewStRoot: batch.Batch.StateRoot,
  323. NewExitRoot: batch.Batch.ExitRoot,
  324. L1CoordinatorTxs: batch.L1CoordinatorTxs,
  325. L1CoordinatorTxsAuths: [][]byte{}, // Intentionally empty
  326. L2TxsData: batch.L2Txs,
  327. FeeIdxCoordinator: batch.Batch.FeeIdxsCoordinator,
  328. // Circuit selector
  329. VerifierIdx: 0, // Intentionally empty
  330. L1Batch: batch.L1Batch,
  331. ProofA: [2]*big.Int{}, // Intentionally empty
  332. ProofB: [2][2]*big.Int{}, // Intentionally empty
  333. ProofC: [2]*big.Int{}, // Intentionally empty
  334. })
  335. require.Nil(t, err)
  336. }
  337. // Mine block and sync
  338. client.CtlMineBlock()
  339. }
  340. //
  341. // Sync to synchronize the current state from the test smart contracts,
  342. // and check the outcome
  343. //
  344. // Block 2
  345. syncBlock, discards, err = s.Sync2(ctx, nil)
  346. require.Nil(t, err)
  347. require.Nil(t, discards)
  348. require.NotNil(t, syncBlock)
  349. assert.Equal(t, int64(2), syncBlock.Block.EthBlockNum)
  350. checkSyncBlock(t, s, 2, &blocks[0], syncBlock)
  351. // Block 3
  352. syncBlock, discards, err = s.Sync2(ctx, nil)
  353. require.Nil(t, err)
  354. require.Nil(t, discards)
  355. require.NotNil(t, syncBlock)
  356. assert.Equal(t, int64(3), syncBlock.Block.EthBlockNum)
  357. checkSyncBlock(t, s, 3, &blocks[1], syncBlock)
  358. // TODO: Reorg will be properly tested once we have the mock ethClient implemented
  359. /*
  360. // Force a Reorg
  361. lastSavedBlock, err := historyDB.GetLastBlock()
  362. require.Nil(t, err)
  363. lastSavedBlock.EthBlockNum++
  364. err = historyDB.AddBlock(lastSavedBlock)
  365. require.Nil(t, err)
  366. lastSavedBlock.EthBlockNum++
  367. err = historyDB.AddBlock(lastSavedBlock)
  368. require.Nil(t, err)
  369. log.Debugf("Wait for the blockchain to generate some blocks...")
  370. time.Sleep(40 * time.Second)
  371. err = s.Sync()
  372. require.Nil(t, err)
  373. */
  374. }