mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
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.
This commit is contained in:
@@ -553,10 +553,17 @@ func (c *Client) CtlRollback() {
|
||||
//
|
||||
|
||||
// CtlLastBlock returns the last blockNum without checks
|
||||
func (c *Client) CtlLastBlock() int64 {
|
||||
func (c *Client) CtlLastBlock() *common.Block {
|
||||
c.rw.RLock()
|
||||
defer c.rw.RUnlock()
|
||||
return c.blockNum
|
||||
|
||||
block := c.blocks[c.blockNum]
|
||||
return &common.Block{
|
||||
Num: c.blockNum,
|
||||
Timestamp: time.Unix(block.Eth.Time, 0),
|
||||
Hash: block.Eth.Hash,
|
||||
ParentHash: block.Eth.ParentHash,
|
||||
}
|
||||
}
|
||||
|
||||
// EthLastBlock returns the last blockNum
|
||||
@@ -626,7 +633,7 @@ func (c *Client) EthERC20Consts(tokenAddr ethCommon.Address) (*eth.ERC20Consts,
|
||||
// }
|
||||
|
||||
// EthBlockByNumber returns the *common.Block for the given block number in a
|
||||
// deterministic way.
|
||||
// deterministic way. If number == -1, the latests known block is returned.
|
||||
func (c *Client) EthBlockByNumber(ctx context.Context, blockNum int64) (*common.Block, error) {
|
||||
c.rw.RLock()
|
||||
defer c.rw.RUnlock()
|
||||
@@ -634,12 +641,15 @@ func (c *Client) EthBlockByNumber(ctx context.Context, blockNum int64) (*common.
|
||||
if blockNum > c.blockNum {
|
||||
return nil, ethereum.NotFound
|
||||
}
|
||||
if blockNum == -1 {
|
||||
blockNum = c.blockNum
|
||||
}
|
||||
block := c.blocks[blockNum]
|
||||
return &common.Block{
|
||||
EthBlockNum: blockNum,
|
||||
Timestamp: time.Unix(block.Eth.Time, 0),
|
||||
Hash: block.Eth.Hash,
|
||||
ParentHash: block.Eth.ParentHash,
|
||||
Num: blockNum,
|
||||
Timestamp: time.Unix(block.Eth.Time, 0),
|
||||
Hash: block.Eth.Hash,
|
||||
ParentHash: block.Eth.ParentHash,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ func TestClientEth(t *testing.T) {
|
||||
|
||||
block, err := c.EthBlockByNumber(context.TODO(), 0)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(0), block.EthBlockNum)
|
||||
assert.Equal(t, int64(0), block.Num)
|
||||
assert.Equal(t, time.Unix(0, 0), block.Timestamp)
|
||||
assert.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000000", block.Hash.Hex())
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestClientEth(t *testing.T) {
|
||||
|
||||
block, err = c.EthBlockByNumber(context.TODO(), 2)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(2), block.EthBlockNum)
|
||||
assert.Equal(t, int64(2), block.Num)
|
||||
assert.Equal(t, time.Unix(2, 0), block.Timestamp)
|
||||
|
||||
// Add a token
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// Block0 represents Ethereum's genesis block,
|
||||
// which is stored by default at HistoryDB
|
||||
var Block0 common.Block = common.Block{
|
||||
EthBlockNum: 0,
|
||||
Num: 0,
|
||||
Hash: ethCommon.Hash([32]byte{
|
||||
212, 229, 103, 64, 248, 118, 174, 248,
|
||||
192, 16, 184, 106, 64, 213, 245, 103,
|
||||
@@ -44,7 +44,7 @@ func GenBlocks(from, to int64) []common.Block {
|
||||
var blocks []common.Block
|
||||
for i := from; i < to; i++ {
|
||||
blocks = append(blocks, common.Block{
|
||||
EthBlockNum: i,
|
||||
Num: i,
|
||||
//nolint:gomnd
|
||||
Timestamp: time.Now().Add(time.Second * 13).UTC(),
|
||||
Hash: ethCommon.BigToHash(big.NewInt(int64(i))),
|
||||
@@ -62,7 +62,7 @@ func GenTokens(nTokens int, blocks []common.Block) (tokensToAddInDB []common.Tok
|
||||
Name: "NAME" + fmt.Sprint(i),
|
||||
Symbol: fmt.Sprint(i),
|
||||
Decimals: uint64(i + 1),
|
||||
EthBlockNum: blocks[i%len(blocks)].EthBlockNum,
|
||||
EthBlockNum: blocks[i%len(blocks)].Num,
|
||||
EthAddr: ethCommon.BigToAddress(big.NewInt(int64(i))),
|
||||
}
|
||||
tokensToAddInDB = append(tokensToAddInDB, token)
|
||||
@@ -87,7 +87,7 @@ func GenBatches(nBatches int, blocks []common.Block) []common.Batch {
|
||||
for i := 0; i < nBatches; i++ {
|
||||
batch := common.Batch{
|
||||
BatchNum: common.BatchNum(i + 1),
|
||||
EthBlockNum: blocks[i%len(blocks)].EthBlockNum,
|
||||
EthBlockNum: blocks[i%len(blocks)].Num,
|
||||
//nolint:gomnd
|
||||
ForgerAddr: ethCommon.BigToAddress(big.NewInt(6886723)),
|
||||
CollectedFees: collectedFees,
|
||||
@@ -161,7 +161,7 @@ func GenL1Txs(
|
||||
TokenID: token.TokenID,
|
||||
Amount: amount,
|
||||
LoadAmount: amount,
|
||||
EthBlockNum: blocks[i%len(blocks)].EthBlockNum,
|
||||
EthBlockNum: blocks[i%len(blocks)].Num,
|
||||
}
|
||||
if tx.UserOrigin {
|
||||
n := nextTxsNum
|
||||
@@ -287,7 +287,7 @@ func GenL2Txs(
|
||||
Amount: amount,
|
||||
Fee: fee,
|
||||
Nonce: common.Nonce(i + 1),
|
||||
EthBlockNum: blocks[i%len(blocks)].EthBlockNum,
|
||||
EthBlockNum: blocks[i%len(blocks)].Num,
|
||||
Type: randomTxType(i),
|
||||
}
|
||||
if i < nUserTxs {
|
||||
@@ -341,7 +341,7 @@ func GenCoordinators(nCoords int, blocks []common.Block) []common.Coordinator {
|
||||
coords := []common.Coordinator{}
|
||||
for i := 0; i < nCoords; i++ {
|
||||
coords = append(coords, common.Coordinator{
|
||||
EthBlockNum: blocks[i%len(blocks)].EthBlockNum,
|
||||
EthBlockNum: blocks[i%len(blocks)].Num,
|
||||
Forger: ethCommon.BigToAddress(big.NewInt(int64(i))),
|
||||
Bidder: ethCommon.BigToAddress(big.NewInt(int64(i))),
|
||||
URL: "https://foo.bar",
|
||||
@@ -363,7 +363,7 @@ func GenBids(nBids int, blocks []common.Block, coords []common.Coordinator) []co
|
||||
bids = append(bids, common.Bid{
|
||||
SlotNum: slotNum,
|
||||
BidValue: big.NewInt(int64(i)),
|
||||
EthBlockNum: blocks[i%len(blocks)].EthBlockNum,
|
||||
EthBlockNum: blocks[i%len(blocks)].Num,
|
||||
Bidder: coords[i%len(blocks)].Bidder,
|
||||
})
|
||||
}
|
||||
@@ -397,13 +397,13 @@ func GenExitTree(n int, batches []common.Batch, accounts []common.Account, block
|
||||
Balance: big.NewInt(int64(i) * 1000),
|
||||
}
|
||||
if i%2 == 0 {
|
||||
instant := int64(blocks[i%len(blocks)].EthBlockNum)
|
||||
instant := int64(blocks[i%len(blocks)].Num)
|
||||
exitTree[i].InstantWithdrawn = &instant
|
||||
} else if i%3 == 0 {
|
||||
delayedReq := int64(blocks[i%len(blocks)].EthBlockNum)
|
||||
delayedReq := int64(blocks[i%len(blocks)].Num)
|
||||
exitTree[i].DelayedWithdrawRequest = &delayedReq
|
||||
if i%9 == 0 {
|
||||
delayed := int64(blocks[i%len(blocks)].EthBlockNum)
|
||||
delayed := int64(blocks[i%len(blocks)].Num)
|
||||
exitTree[i].DelayedWithdrawn = &delayed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func newBatchData(batchNum int) common.BatchData {
|
||||
func newBlock(blockNum int64) common.BlockData {
|
||||
return common.BlockData{
|
||||
Block: common.Block{
|
||||
EthBlockNum: blockNum,
|
||||
Num: blockNum,
|
||||
},
|
||||
Rollup: common.RollupData{
|
||||
L1UserTxs: []common.L1Tx{},
|
||||
@@ -711,7 +711,7 @@ func (tc *Context) FillBlocksExtra(blocks []common.BlockData, cfg *ConfigExtra)
|
||||
block := &blocks[i]
|
||||
for j := range block.Rollup.Batches {
|
||||
batch := &block.Rollup.Batches[j]
|
||||
batch.Batch.EthBlockNum = block.Block.EthBlockNum
|
||||
batch.Batch.EthBlockNum = block.Block.Num
|
||||
// til doesn't fill the batch forger addr
|
||||
batch.Batch.ForgerAddr = cfg.BootCoordAddr
|
||||
if batch.L1Batch {
|
||||
|
||||
Reference in New Issue
Block a user