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 |
|
package priceupdater
import ( "context" "math/big" "os" "testing"
ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" dbUtils "github.com/hermeznetwork/hermez-node/db" "github.com/hermeznetwork/hermez-node/db/historydb" "github.com/hermeznetwork/hermez-node/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" )
func TestPriceUpdater(t *testing.T) { // Init DB
pass := os.Getenv("POSTGRES_PASS") db, err := dbUtils.InitSQLDB(5432, "localhost", "hermez", pass, "hermez") assert.NoError(t, err) historyDB := historydb.NewHistoryDB(db, nil) // Clean DB
test.WipeDB(historyDB.DB()) // Populate DB
// Gen blocks and add them to DB
blocks := test.GenBlocks(1, 2) assert.NoError(t, historyDB.AddBlocks(blocks)) // Gen tokens and add them to DB
tokens := []common.Token{} tokens = append(tokens, common.Token{ TokenID: 1, EthBlockNum: blocks[0].Num, EthAddr: ethCommon.BigToAddress(big.NewInt(2)), Name: "DAI", Symbol: "DAI", Decimals: 18, }) assert.NoError(t, historyDB.AddTokens(tokens)) // Init price updater
pu, err := NewPriceUpdater("https://api-pub.bitfinex.com/v2/", APITypeBitFinexV2, historyDB) require.NoError(t, err) // Update token list
assert.NoError(t, pu.UpdateTokenList()) // Update prices
pu.UpdatePrices(context.Background()) // Check that prices have been updated
fetchedTokens, err := historyDB.GetTokensTest() require.NoError(t, err) // TokenID 0 (ETH) is always on the DB
assert.Equal(t, 2, len(fetchedTokens)) for _, token := range fetchedTokens { assert.NotNil(t, token.USD) assert.NotNil(t, token.USDUpdate) } }
|