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:
@@ -412,7 +412,7 @@ func TestMain(m *testing.M) {
|
||||
bids: testBids,
|
||||
slots: api.genTestSlots(
|
||||
20,
|
||||
commonBlocks[len(commonBlocks)-1].EthBlockNum,
|
||||
commonBlocks[len(commonBlocks)-1].Num,
|
||||
testBids,
|
||||
auctionVars,
|
||||
),
|
||||
@@ -611,7 +611,7 @@ func doBadReq(method, path string, reqBody io.Reader, expectedResponseCode int)
|
||||
|
||||
func getTimestamp(blockNum int64, blocks []common.Block) time.Time {
|
||||
for i := 0; i < len(blocks); i++ {
|
||||
if blocks[i].EthBlockNum == blockNum {
|
||||
if blocks[i].Num == blockNum {
|
||||
return blocks[i].Timestamp
|
||||
}
|
||||
}
|
||||
@@ -647,7 +647,7 @@ func getAccountByIdx(idx common.Idx, accs []common.Account) *common.Account {
|
||||
|
||||
func getBlockByNum(ethBlockNum int64, blocks []common.Block) common.Block {
|
||||
for _, b := range blocks {
|
||||
if b.EthBlockNum == ethBlockNum {
|
||||
if b.Num == ethBlockNum {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
func AddAditionalInformation(blocks []common.BlockData) {
|
||||
for i := range blocks {
|
||||
blocks[i].Block.Timestamp = time.Now().Add(time.Second * 13).UTC()
|
||||
blocks[i].Block.Hash = ethCommon.BigToHash(big.NewInt(blocks[i].Block.EthBlockNum))
|
||||
blocks[i].Block.Hash = ethCommon.BigToHash(big.NewInt(blocks[i].Block.Num))
|
||||
for j := range blocks[i].Rollup.AddedTokens {
|
||||
blocks[i].Rollup.AddedTokens[j].Name = "NAME" + strconv.Itoa(int(blocks[i].Rollup.AddedTokens[j].TokenID))
|
||||
blocks[i].Rollup.AddedTokens[j].Symbol = strconv.Itoa(int(blocks[i].Rollup.AddedTokens[j].TokenID))
|
||||
|
||||
@@ -60,7 +60,7 @@ func genTestBatches(
|
||||
block := common.Block{}
|
||||
found := false
|
||||
for _, b := range blocks {
|
||||
if b.EthBlockNum == cBatches[i].EthBlockNum {
|
||||
if b.Num == cBatches[i].EthBlockNum {
|
||||
block = b
|
||||
found = true
|
||||
break
|
||||
|
||||
10
api/slots.go
10
api/slots.go
@@ -116,9 +116,9 @@ func (a *API) getSlot(c *gin.Context) {
|
||||
|
||||
var slot SlotAPI
|
||||
if err == sql.ErrNoRows {
|
||||
slot = a.newSlotAPI(slotNum, currentBlock.EthBlockNum, nil, auctionVars)
|
||||
slot = a.newSlotAPI(slotNum, currentBlock.Num, nil, auctionVars)
|
||||
} else {
|
||||
slot = a.newSlotAPI(bid.SlotNum, currentBlock.EthBlockNum, &bid, auctionVars)
|
||||
slot = a.newSlotAPI(bid.SlotNum, currentBlock.Num, &bid, auctionVars)
|
||||
}
|
||||
|
||||
// JSON response
|
||||
@@ -221,7 +221,7 @@ func (a *API) getSlots(c *gin.Context) {
|
||||
retBadReq(err, c)
|
||||
return
|
||||
}
|
||||
currentSlot := a.getCurrentSlot(currentBlock.EthBlockNum)
|
||||
currentSlot := a.getCurrentSlot(currentBlock.Num)
|
||||
auctionVars, err := a.h.GetAuctionVars()
|
||||
if err != nil {
|
||||
retBadReq(err, c)
|
||||
@@ -268,7 +268,7 @@ func (a *API) getSlots(c *gin.Context) {
|
||||
// Build the slot information with previous bids
|
||||
var slotsBids []SlotAPI
|
||||
if len(bids) > 0 {
|
||||
slotsBids = a.newSlotsAPIFromWinnerBids(fromItem, order, bids, currentBlock.EthBlockNum, auctionVars)
|
||||
slotsBids = a.newSlotsAPIFromWinnerBids(fromItem, order, bids, currentBlock.Num, auctionVars)
|
||||
if err != nil {
|
||||
retBadReq(err, c)
|
||||
return
|
||||
@@ -296,7 +296,7 @@ func (a *API) getSlots(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
slots, err = a.addEmptySlot(slots, i, currentBlock.EthBlockNum, auctionVars, fromItem, order)
|
||||
slots, err = a.addEmptySlot(slots, i, currentBlock.Num, auctionVars, fromItem, order)
|
||||
if err != nil {
|
||||
retBadReq(err, c)
|
||||
return
|
||||
|
||||
@@ -181,7 +181,7 @@ func TestGetSlots(t *testing.T) {
|
||||
err = doGoodReqPaginated(path, historydb.OrderAsc, &testSlotsResponse{}, appendIter)
|
||||
assert.NoError(t, err)
|
||||
|
||||
currentSlot := api.getCurrentSlot(tc.blocks[len(tc.blocks)-1].EthBlockNum)
|
||||
currentSlot := api.getCurrentSlot(tc.blocks[len(tc.blocks)-1].Num)
|
||||
finishedAuctionSlots := []testSlot{}
|
||||
for i := 0; i < len(tc.slots); i++ {
|
||||
finishAuction := currentSlot + int64(tc.auctionVars.ClosedAuctionSlots)
|
||||
|
||||
16
api/state.go
16
api/state.go
@@ -65,13 +65,21 @@ func (a *API) SetAuctionVariables(auctionVariables common.AuctionVariables) {
|
||||
|
||||
// Network
|
||||
|
||||
// UpdateNetworkInfoBlock update Status.Network block related information
|
||||
func (a *API) UpdateNetworkInfoBlock(
|
||||
lastEthBlock, lastSyncBlock common.Block,
|
||||
) {
|
||||
a.status.Network.LastSyncBlock = lastSyncBlock.Num
|
||||
a.status.Network.LastEthBlock = lastEthBlock.Num
|
||||
}
|
||||
|
||||
// UpdateNetworkInfo update Status.Network information
|
||||
func (a *API) UpdateNetworkInfo(
|
||||
lastEthBlock, lastSyncBlock common.Block,
|
||||
lastBatchNum common.BatchNum, currentSlot int64,
|
||||
) error {
|
||||
a.status.Network.LastSyncBlock = lastSyncBlock.EthBlockNum
|
||||
a.status.Network.LastEthBlock = lastEthBlock.EthBlockNum
|
||||
a.status.Network.LastSyncBlock = lastSyncBlock.Num
|
||||
a.status.Network.LastEthBlock = lastEthBlock.Num
|
||||
lastBatch, err := a.h.GetBatchAPI(lastBatchNum)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -106,8 +114,8 @@ func (a *API) GetNextForgers(lastBlock common.Block, currentSlot, lastClosedSlot
|
||||
SlotNum: i,
|
||||
FromBlock: fromBlock,
|
||||
ToBlock: toBlock,
|
||||
FromTimestamp: lastBlock.Timestamp.Add(time.Second * time.Duration(secondsPerBlock*(fromBlock-lastBlock.EthBlockNum))),
|
||||
ToTimestamp: lastBlock.Timestamp.Add(time.Second * time.Duration(secondsPerBlock*(toBlock-lastBlock.EthBlockNum))),
|
||||
FromTimestamp: lastBlock.Timestamp.Add(time.Second * time.Duration(secondsPerBlock*(fromBlock-lastBlock.Num))),
|
||||
ToTimestamp: lastBlock.Timestamp.Add(time.Second * time.Duration(secondsPerBlock*(toBlock-lastBlock.Num))),
|
||||
},
|
||||
}
|
||||
foundBid := false
|
||||
|
||||
@@ -69,8 +69,8 @@ func TestNextForgers(t *testing.T) {
|
||||
assert.Equal(t, bootCoordinator.Bidder, nextForgers[q].Coordinator.Bidder)
|
||||
}
|
||||
firstBlockSlot, lastBlockSlot := api.getFirstLastBlock(j)
|
||||
fromTimestamp := lastBlock.Timestamp.Add(time.Second * time.Duration(secondsPerBlock*(firstBlockSlot-lastBlock.EthBlockNum)))
|
||||
toTimestamp := lastBlock.Timestamp.Add(time.Second * time.Duration(secondsPerBlock*(lastBlockSlot-lastBlock.EthBlockNum)))
|
||||
fromTimestamp := lastBlock.Timestamp.Add(time.Second * time.Duration(secondsPerBlock*(firstBlockSlot-lastBlock.Num)))
|
||||
toTimestamp := lastBlock.Timestamp.Add(time.Second * time.Duration(secondsPerBlock*(lastBlockSlot-lastBlock.Num)))
|
||||
assert.Equal(t, fromTimestamp.Unix(), nextForgers[q].Period.FromTimestamp.Unix())
|
||||
assert.Equal(t, toTimestamp.Unix(), nextForgers[q].Period.ToTimestamp.Unix())
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func TestUpdateNetworkInfo(t *testing.T) {
|
||||
currentSlotNum := int64(1)
|
||||
err := api.UpdateNetworkInfo(lastBlock, lastBlock, lastBatchNum, currentSlotNum)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, lastBlock.EthBlockNum, api.status.Network.LastSyncBlock)
|
||||
assert.Equal(t, lastBlock.Num, api.status.Network.LastSyncBlock)
|
||||
assert.Equal(t, lastBatchNum, api.status.Network.LastBatch.BatchNum)
|
||||
assert.Equal(t, currentSlotNum, api.status.Network.CurrentSlot)
|
||||
assert.Equal(t, int(api.status.Auction.ClosedAuctionSlots)+1, len(api.status.Network.NextForgers))
|
||||
@@ -146,8 +146,8 @@ func TestGetState(t *testing.T) {
|
||||
assert.Equal(t, tc.rollupVars, status.Rollup)
|
||||
assert.Equal(t, tc.auctionVars, status.Auction)
|
||||
assert.Equal(t, tc.wdelayerVars, status.WithdrawalDelayer)
|
||||
assert.Equal(t, lastBlock.EthBlockNum, status.Network.LastEthBlock)
|
||||
assert.Equal(t, lastBlock.EthBlockNum, status.Network.LastSyncBlock)
|
||||
assert.Equal(t, lastBlock.Num, status.Network.LastEthBlock)
|
||||
assert.Equal(t, lastBlock.Num, status.Network.LastSyncBlock)
|
||||
assert.Equal(t, lastBatchNum, status.Network.LastBatch.BatchNum)
|
||||
assert.Equal(t, currentSlotNum, status.Network.CurrentSlot)
|
||||
assert.Equal(t, int(api.status.Auction.ClosedAuctionSlots)+1, len(status.Network.NextForgers))
|
||||
|
||||
Reference in New Issue
Block a user