mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 19:36:44 +01:00
Redo coordinator structure, connect API to node
- API: - Modify the constructor so that hardcoded rollup constants don't need to be passed (introduce a `Config` and use `configAPI` internally) - Common: - Update rollup constants with proper *big.Int when required - Add BidCoordinator and Slot structs used by the HistoryDB and Synchronizer. - Add helper methods to AuctionConstants - AuctionVariables: Add column `DefaultSlotSetBidSlotNum` (in the SQL table: `default_slot_set_bid_slot_num`), which indicates at which slotNum does the `DefaultSlotSetBid` specified starts applying. - Config: - Move coordinator exclusive configuration from the node config to the coordinator config - Coordinator: - Reorganize the code towards having the goroutines started and stopped from the coordinator itself instead of the node. - Remove all stop and stopped channels, and use context.Context and sync.WaitGroup instead. - Remove BatchInfo setters and assing variables directly - In ServerProof and ServerProofPool use context instead stop channel. - Use message passing to notify the coordinator about sync updates and reorgs - Introduce the Pipeline, which can be started and stopped by the Coordinator - Introduce the TxManager, which manages ethereum transactions (the TxManager is also in charge of making the forge call to the rollup smart contract). The TxManager keeps ethereum transactions and: 1. Waits for the transaction to be accepted 2. Waits for the transaction to be confirmed for N blocks - In forge logic, first prepare a batch and then wait for an available server proof to have all work ready once the proof server is ready. - Remove the `isForgeSequence` method which was querying the smart contract, and instead use notifications sent by the Synchronizer to figure out if it's forging time. - Update test (which is a minimal test to manually see if the coordinator starts) - HistoryDB: - Add method to get the number of batches in a slot (used to detect when a slot has passed the bid winner forging deadline) - Add method to get the best bid and associated coordinator of a slot (used to detect the forgerAddress that can forge the slot) - General: - Rename some instances of `currentBlock` to `lastBlock` to be more clear. - Node: - Connect the API to the node and call the methods to update cached state when the sync advances blocks. - Call methods to update Coordinator state when the sync advances blocks and finds reorgs. - Synchronizer: - Add Auction field in the Stats, which contain the current slot with info about highest bidder and other related info required to know who can forge in the current block. - Better organization of cached state: - On Sync, update the internal cached state - On Init or Reorg, load the state from HistoryDB into the internal cached state.
This commit is contained in:
@@ -71,7 +71,7 @@ func TestAuctionSetSlotDeadline(t *testing.T) {
|
||||
slotDeadline, err := auctionClientTest.AuctionGetSlotDeadline()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, newSlotDeadline, slotDeadline)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, newSlotDeadline, auctionEvents.NewSlotDeadline[0].NewSlotDeadline)
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func TestAuctionSetOpenAuctionSlots(t *testing.T) {
|
||||
openAuctionSlots, err := auctionClientTest.AuctionGetOpenAuctionSlots()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, newOpenAuctionSlots, openAuctionSlots)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, newOpenAuctionSlots, auctionEvents.NewOpenAuctionSlots[0].NewOpenAuctionSlots)
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func TestAuctionSetClosedAuctionSlots(t *testing.T) {
|
||||
closedAuctionSlots, err := auctionClientTest.AuctionGetClosedAuctionSlots()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, newClosedAuctionSlots, closedAuctionSlots)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, newClosedAuctionSlots, auctionEvents.NewClosedAuctionSlots[0].NewClosedAuctionSlots)
|
||||
_, err = auctionClientTest.AuctionSetClosedAuctionSlots(closedAuctionSlots)
|
||||
@@ -130,7 +130,7 @@ func TestAuctionSetOutbidding(t *testing.T) {
|
||||
outbidding, err := auctionClientTest.AuctionGetOutbidding()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, newOutbidding, outbidding)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, newOutbidding, auctionEvents.NewOutbidding[0].NewOutbidding)
|
||||
_, err = auctionClientTest.AuctionSetOutbidding(outbiddingConst)
|
||||
@@ -151,7 +151,7 @@ func TestAuctionSetAllocationRatio(t *testing.T) {
|
||||
allocationRatio, err := auctionClientTest.AuctionGetAllocationRatio()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, newAllocationRatio, allocationRatio)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, newAllocationRatio, auctionEvents.NewAllocationRatio[0].NewAllocationRatio)
|
||||
_, err = auctionClientTest.AuctionSetAllocationRatio(allocationRatioConst)
|
||||
@@ -178,7 +178,7 @@ func TestAuctionSetDonationAddress(t *testing.T) {
|
||||
donationAddress, err := auctionClientTest.AuctionGetDonationAddress()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, &newDonationAddress, donationAddress)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, newDonationAddress, auctionEvents.NewDonationAddress[0].NewDonationAddress)
|
||||
_, err = auctionClientTest.AuctionSetDonationAddress(donationAddressConst)
|
||||
@@ -193,7 +193,7 @@ func TestAuctionSetBootCoordinator(t *testing.T) {
|
||||
bootCoordinator, err := auctionClientTest.AuctionGetBootCoordinator()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, &newBootCoordinator, bootCoordinator)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, newBootCoordinator, auctionEvents.NewBootCoordinator[0].NewBootCoordinator)
|
||||
_, err = auctionClientTest.AuctionSetBootCoordinator(bootCoordinatorAddressConst)
|
||||
@@ -227,7 +227,7 @@ func TestAuctionChangeDefaultSlotSetBid(t *testing.T) {
|
||||
minBid, err := auctionClientTest.AuctionGetDefaultSlotSetBid(set)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, minBid, newInitialMinBid)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, slotSet, auctionEvents.NewDefaultSlotSetBid[0].SlotSet)
|
||||
assert.Equal(t, newInitialMinBid, auctionEvents.NewDefaultSlotSetBid[0].NewInitialMinBid)
|
||||
@@ -251,7 +251,7 @@ func TestAuctionRegisterCoordinator(t *testing.T) {
|
||||
|
||||
_, err := auctionClientTest.AuctionSetCoordinator(forgerAddress, URL)
|
||||
require.Nil(t, err)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, forgerAddress, auctionEvents.SetCoordinator[0].ForgerAddress)
|
||||
assert.Equal(t, bidderAddress, auctionEvents.SetCoordinator[0].BidderAddress)
|
||||
@@ -268,7 +268,7 @@ func TestAuctionBid(t *testing.T) {
|
||||
bidderAddress := governanceAddressConst
|
||||
_, err = auctionClientTest.AuctionBid(amount, currentSlot+4, bidAmount, deadline)
|
||||
require.Nil(t, err)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, bidAmount, auctionEvents.NewBid[0].BidAmount)
|
||||
assert.Equal(t, bidderAddress, auctionEvents.NewBid[0].Bidder)
|
||||
@@ -306,7 +306,7 @@ func TestAuctionMultiBid(t *testing.T) {
|
||||
bidderAddress := governanceAddressConst
|
||||
_, err = auctionClientTest.AuctionMultiBid(budget, currentSlot+4, currentSlot+10, slotSet, maxBid, minBid, deadline)
|
||||
require.Nil(t, err)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, bidderAddress, auctionEvents.NewBid[0].Bidder)
|
||||
assert.Equal(t, currentSlot+4, auctionEvents.NewBid[0].Slot)
|
||||
@@ -334,7 +334,7 @@ func TestAuctionClaimHEZ(t *testing.T) {
|
||||
|
||||
_, err := auctionClientTest.AuctionClaimHEZ()
|
||||
require.Nil(t, err)
|
||||
currentBlockNum, _ := auctionClientTest.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTest.client.EthLastBlock()
|
||||
auctionEvents, _, _ := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
|
||||
assert.Equal(t, amount, auctionEvents.HEZClaimed[0].Amount)
|
||||
assert.Equal(t, governanceAddressConst, auctionEvents.HEZClaimed[0].Owner)
|
||||
@@ -345,10 +345,10 @@ func TestAuctionForge(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
slotConst := 4
|
||||
blockNum := int64(int(blocksPerSlot)*slotConst + int(genesisBlock))
|
||||
currentBlockNum, _ := auctionClientTestHermez.client.EthCurrentBlock()
|
||||
currentBlockNum, _ := auctionClientTestHermez.client.EthLastBlock()
|
||||
blocksToAdd := blockNum - currentBlockNum
|
||||
addBlocks(blocksToAdd, ethClientDialURL)
|
||||
currentBlockNum, _ = auctionClientTestHermez.client.EthCurrentBlock()
|
||||
currentBlockNum, _ = auctionClientTestHermez.client.EthLastBlock()
|
||||
assert.Equal(t, currentBlockNum, blockNum)
|
||||
_, err = auctionClientTestHermez.AuctionForge(governanceAddressConst)
|
||||
require.Nil(t, err)
|
||||
|
||||
Reference in New Issue
Block a user