-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(manager): cleanup proposer, full node and rotation flows (#1183
) Co-authored-by: Sergi Rene <[email protected]>
- Loading branch information
1 parent
efbf726
commit 58b9caf
Showing
13 changed files
with
194 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package block | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/dymensionxyz/dymint/p2p" | ||
"github.com/dymensionxyz/dymint/settlement" | ||
uerrors "github.com/dymensionxyz/dymint/utils/errors" | ||
uevent "github.com/dymensionxyz/dymint/utils/event" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
// setFraudHandler sets the fraud handler for the block manager. | ||
func (m *Manager) runAsFullNode(ctx context.Context, eg *errgroup.Group) error { | ||
// update latest finalized height | ||
err := m.updateLastFinalizedHeightFromSettlement() | ||
if err != nil { | ||
return fmt.Errorf("sync block manager from settlement: %w", err) | ||
} | ||
|
||
// Start the settlement validation loop in the background | ||
uerrors.ErrGroupGoLog(eg, m.logger, func() error { | ||
return m.SettlementValidateLoop(ctx) | ||
}) | ||
|
||
// Subscribe to new (or finalized) state updates events. | ||
go uevent.MustSubscribe(ctx, m.Pubsub, "syncLoop", settlement.EventQueryNewSettlementBatchAccepted, m.onNewStateUpdate, m.logger) | ||
go uevent.MustSubscribe(ctx, m.Pubsub, "validateLoop", settlement.EventQueryNewSettlementBatchFinalized, m.onNewStateUpdateFinalized, m.logger) | ||
|
||
// Subscribe to P2P received blocks events (used for P2P syncing). | ||
go uevent.MustSubscribe(ctx, m.Pubsub, "applyGossipedBlocksLoop", p2p.EventQueryNewGossipedBlock, m.OnReceivedBlock, m.logger) | ||
go uevent.MustSubscribe(ctx, m.Pubsub, "applyBlockSyncBlocksLoop", p2p.EventQueryNewBlockSyncBlock, m.OnReceivedBlock, m.logger) | ||
|
||
return nil | ||
} | ||
|
||
func (m *Manager) runAsProposer(ctx context.Context, eg *errgroup.Group) error { | ||
// Subscribe to batch events, to update last submitted height in case batch confirmation was lost. This could happen if the sequencer crash/restarted just after submitting a batch to the settlement and by the time we query the last batch, this batch wasn't accepted yet. | ||
go uevent.MustSubscribe(ctx, m.Pubsub, "updateSubmittedHeightLoop", settlement.EventQueryNewSettlementBatchAccepted, m.UpdateLastSubmittedHeight, m.logger) | ||
|
||
// Sequencer must wait till the DA light client is synced. Otherwise it will fail when submitting blocks. | ||
// Full-nodes does not need to wait, but if it tries to fetch blocks from DA heights previous to the DA light client height it will fail, and it will retry till it reaches the height. | ||
m.DAClient.WaitForSyncing() | ||
|
||
// Sequencer must wait till node is synced till last submittedHeight, in case it is not | ||
m.waitForSettlementSyncing() | ||
|
||
// check if we should rotate | ||
shouldRotate, err := m.ShouldRotate() | ||
if err != nil { | ||
return fmt.Errorf("checking should rotate: %w", err) | ||
} | ||
if shouldRotate { | ||
m.rotate(ctx) | ||
} | ||
|
||
// populate the bytes produced channel | ||
bytesProducedC := make(chan int) | ||
|
||
uerrors.ErrGroupGoLog(eg, m.logger, func() error { | ||
return m.SubmitLoop(ctx, bytesProducedC) | ||
}) | ||
uerrors.ErrGroupGoLog(eg, m.logger, func() error { | ||
bytesProducedC <- m.GetUnsubmittedBytes() // load unsubmitted bytes from previous run | ||
return m.ProduceBlockLoop(ctx, bytesProducedC) | ||
}) | ||
|
||
// Monitor and handling of the rotation | ||
go m.MonitorProposerRotation(ctx) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.