diff --git a/components/dashboard/component.go b/components/dashboard/component.go index 20617cc4b..6fb614105 100644 --- a/components/dashboard/component.go +++ b/components/dashboard/component.go @@ -150,12 +150,12 @@ func currentNodeStatus() *nodestatus { LastPauseGC: m.PauseNs[(m.NumGC+255)%256], } // get TangleTime - cl := deps.Protocol.MainEngine.Get().Clock - syncStatus := deps.Protocol.MainEngine.Get().SyncManager.SyncStatus() + cl := deps.Protocol.Engines.Main.Get().Clock + syncStatus := deps.Protocol.Engines.Main.Get().SyncManager.SyncStatus() status.TangleTime = tangleTime{ Synced: syncStatus.NodeSynced, - Bootstrapped: deps.Protocol.MainEngine.Get().SyncManager.IsBootstrapped(), + Bootstrapped: deps.Protocol.Engines.Main.Get().SyncManager.IsBootstrapped(), AcceptedBlockSlot: int64(syncStatus.LastAcceptedBlockSlot), ConfirmedBlockSlot: int64(syncStatus.LastConfirmedBlockSlot), CommittedSlot: int64(syncStatus.LatestCommitment.Slot()), diff --git a/components/dashboard/explorer_routes.go b/components/dashboard/explorer_routes.go index 29e76199d..692722f71 100644 --- a/components/dashboard/explorer_routes.go +++ b/components/dashboard/explorer_routes.go @@ -79,14 +79,14 @@ func setupExplorerRoutes(routeGroup *echo.Group) { } func findBlock(blockID iotago.BlockID) (explorerBlk *ExplorerBlock, err error) { - block, exists := deps.Protocol.MainEngine.Get().Block(blockID) + block, exists := deps.Protocol.Engines.Main.Get().Block(blockID) if !exists { return nil, ierrors.Errorf("block not found: %s", blockID.ToHex()) } - cachedBlock, _ := deps.Protocol.MainEngine.Get().BlockCache.Block(blockID) + cachedBlock, _ := deps.Protocol.Engines.Main.Get().BlockCache.Block(blockID) - blockMetadata, err := deps.Protocol.MainEngine.Get().Retainer.BlockMetadata(blockID) + blockMetadata, err := deps.Protocol.Engines.Main.Get().Retainer.BlockMetadata(blockID) if err != nil { return nil, ierrors.Wrapf(err, "block metadata %s", blockID.ToHex()) } @@ -201,12 +201,12 @@ func getTransaction(c echo.Context) error { outputID := iotago.OutputID{} copy(outputID[:], txID[:]) - output, err := deps.Protocol.MainEngine.Get().Ledger.Output(outputID) + output, err := deps.Protocol.Engines.Main.Get().Ledger.Output(outputID) if err != nil { return err } - block, exists := deps.Protocol.MainEngine.Get().Block(output.BlockID()) + block, exists := deps.Protocol.Engines.Main.Get().Block(output.BlockID()) if !exists { return ierrors.Errorf("block not found: %s", output.BlockID().ToHex()) } @@ -228,12 +228,12 @@ func getTransactionMetadata(c echo.Context) error { // Get the first output of that transaction (using index 0) outputID := iotago.OutputID{} copy(outputID[:], txID[:]) - txMetadata, exists := deps.Protocol.MainEngine.Get().Ledger.MemPool().TransactionMetadata(txID) + txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.MemPool().TransactionMetadata(txID) if !exists { return ierrors.Errorf("tx metadata not found: %s", txID.ToHex()) } - conflicts, _ := deps.Protocol.MainEngine.Get().Ledger.ConflictDAG().ConflictingConflicts(txID) + conflicts, _ := deps.Protocol.Engines.Main.Get().Ledger.ConflictDAG().ConflictingConflicts(txID) return httpserver.JSONResponse(c, http.StatusOK, NewTransactionMetadata(txMetadata, conflicts)) } @@ -244,7 +244,7 @@ func getOutput(c echo.Context) error { return err } - output, err := deps.Protocol.MainEngine.Get().Ledger.Output(outputID) + output, err := deps.Protocol.Engines.Main.Get().Ledger.Output(outputID) if err != nil { return err } @@ -258,12 +258,12 @@ func getSlotDetailsByID(c echo.Context) error { return err } - commitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(commitmentID.Slot()) + commitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(commitmentID.Slot()) if err != nil { return err } - diffs, err := deps.Protocol.MainEngine.Get().Ledger.SlotDiffs(commitmentID.Slot()) + diffs, err := deps.Protocol.Engines.Main.Get().Ledger.SlotDiffs(commitmentID.Slot()) if err != nil { return err } diff --git a/components/dashboard/tip.go b/components/dashboard/tip.go index 18073d4c2..78e124553 100644 --- a/components/dashboard/tip.go +++ b/components/dashboard/tip.go @@ -17,7 +17,7 @@ func setupTipsRoutes(routeGroup *echo.Group) { } func tips() *TipsResponse { - allTips := append(deps.Protocol.MainEngine.Get().TipManager.StrongTips(), deps.Protocol.MainEngine.Get().TipManager.WeakTips()...) + allTips := append(deps.Protocol.Engines.Main.Get().TipManager.StrongTips(), deps.Protocol.Engines.Main.Get().TipManager.WeakTips()...) t := make([]string, len(allTips)) for i, tip := range allTips { diff --git a/components/dashboard/visualizer.go b/components/dashboard/visualizer.go index a29b69e94..31eca650d 100644 --- a/components/dashboard/visualizer.go +++ b/components/dashboard/visualizer.go @@ -55,7 +55,7 @@ func sendVertex(blk *blocks.Block, confirmed bool) { IsTx: isTx, IsTxAccepted: func() bool { if isTx { - txMetadata, exists := deps.Protocol.MainEngine.Get().Ledger.MemPool().TransactionMetadata(lo.PanicOnErr(signedTransaction.Transaction.ID())) + txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.MemPool().TransactionMetadata(lo.PanicOnErr(signedTransaction.Transaction.ID())) if exists { return txMetadata.IsAccepted() } diff --git a/components/dashboard/ws.go b/components/dashboard/ws.go index 2d31869e3..e66e4d2d1 100644 --- a/components/dashboard/ws.go +++ b/components/dashboard/ws.go @@ -50,7 +50,7 @@ func runWebSocketStreams(component *app.Component) { broadcastWsBlock(&wsblk{MsgTypeNodeStatus, currentNodeStatus()}) broadcastWsBlock(&wsblk{MsgTypeNeighborMetric, neighborMetrics()}) broadcastWsBlock(&wsblk{MsgTypeTipsMetric, &tipsInfo{ - TotalTips: len(deps.Protocol.MainEngine.Get().TipManager.StrongTips()) + len(deps.Protocol.MainEngine.Get().TipManager.WeakTips()), + TotalTips: len(deps.Protocol.Engines.Main.Get().TipManager.StrongTips()) + len(deps.Protocol.Engines.Main.Get().TipManager.WeakTips()), }}) case *componentsmetric: broadcastWsBlock(&wsblk{MsgTypeComponentCounterMetric, x}) diff --git a/components/dashboard_metrics/node.go b/components/dashboard_metrics/node.go index 7a6d98658..d4d59776a 100644 --- a/components/dashboard_metrics/node.go +++ b/components/dashboard_metrics/node.go @@ -27,9 +27,9 @@ func nodeInfoExtended() *NodeInfoExtended { func databaseSizesMetrics() (*DatabaseSizesMetric, error) { return &DatabaseSizesMetric{ - Prunable: deps.Protocol.MainEngine.Get().Storage.PrunableDatabaseSize(), - Permanent: deps.Protocol.MainEngine.Get().Storage.PermanentDatabaseSize(), - Total: deps.Protocol.MainEngine.Get().Storage.Size(), + Prunable: deps.Protocol.Engines.Main.Get().Storage.PrunableDatabaseSize(), + Permanent: deps.Protocol.Engines.Main.Get().Storage.PermanentDatabaseSize(), + Total: deps.Protocol.Engines.Main.Get().Storage.Size(), Time: time.Now().Unix(), }, nil } diff --git a/components/debugapi/blocks.go b/components/debugapi/blocks.go index 9a91bb3f7..f9a9dfdd2 100644 --- a/components/debugapi/blocks.go +++ b/components/debugapi/blocks.go @@ -10,7 +10,7 @@ import ( ) func getSlotBlockIDs(index iotago.SlotIndex) (*BlockChangesResponse, error) { - blocksForSlot, err := deps.Protocol.MainEngine.Get().Storage.Blocks(index) + blocksForSlot, err := deps.Protocol.Engines.Main.Get().Storage.Blocks(index) if err != nil { return nil, ierrors.Wrapf(err, "failed to get block storage bucket for slot %d", index) } diff --git a/components/debugapi/component.go b/components/debugapi/component.go index 15fb357cc..bff2f7195 100644 --- a/components/debugapi/component.go +++ b/components/debugapi/component.go @@ -153,7 +153,7 @@ func configure() error { return err } - if block, exists := deps.Protocol.MainEngine.Get().BlockCache.Block(blockID); exists && block.ProtocolBlock() != nil { + if block, exists := deps.Protocol.Engines.Main.Get().BlockCache.Block(blockID); exists && block.ProtocolBlock() != nil { response := BlockMetadataResponseFromBlock(block) return httpserver.JSONResponse(c, http.StatusOK, response) diff --git a/components/debugapi/node.go b/components/debugapi/node.go index 36b13b763..313b52e61 100644 --- a/components/debugapi/node.go +++ b/components/debugapi/node.go @@ -8,8 +8,8 @@ import ( //nolint:unparam // we have no error case right now func validatorsSummary() (*ValidatorsSummaryResponse, error) { - seatManager := deps.Protocol.MainEngine.Get().SybilProtection.SeatManager() - latestSlotIndex := deps.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Slot() + seatManager := deps.Protocol.Engines.Main.Get().SybilProtection.SeatManager() + latestSlotIndex := deps.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot() latestCommittee := seatManager.Committee(latestSlotIndex) validatorSeats := []*Validator{} latestCommittee.Accounts().ForEach(func(id iotago.AccountID, pool *account.Pool) bool { diff --git a/components/debugapi/transactions.go b/components/debugapi/transactions.go index 5c4e72e09..6d215aacf 100644 --- a/components/debugapi/transactions.go +++ b/components/debugapi/transactions.go @@ -17,7 +17,7 @@ func init() { func storeTransactionsPerSlot(scd *notarization.SlotCommittedDetails) error { slot := scd.Commitment.Slot() - stateDiff, err := deps.Protocol.MainEngine.Get().Ledger.MemPool().StateDiff(slot) + stateDiff, err := deps.Protocol.Engines.Main.Get().Ledger.MemPool().StateDiff(slot) if err != nil { return ierrors.Wrapf(err, "failed to retrieve state diff for slot %d", slot) } diff --git a/components/inx/server_blocks.go b/components/inx/server_blocks.go index 362319e92..c82f6fe10 100644 --- a/components/inx/server_blocks.go +++ b/components/inx/server_blocks.go @@ -18,7 +18,7 @@ import ( func (s *Server) ReadBlock(_ context.Context, blockID *inx.BlockId) (*inx.RawBlock, error) { blkID := blockID.Unwrap() - block, exists := deps.Protocol.MainEngine.Get().Block(blkID) // block +1 + block, exists := deps.Protocol.Engines.Main.Get().Block(blkID) // block +1 if !exists { return nil, status.Errorf(codes.NotFound, "block %s not found", blkID.ToHex()) } @@ -148,7 +148,7 @@ func (s *Server) attachBlock(ctx context.Context, block *iotago.ProtocolBlock) ( } func getINXBlockMetadata(blockID iotago.BlockID) (*inx.BlockMetadata, error) { - blockMetadata, err := deps.Protocol.MainEngine.Get().Retainer.BlockMetadata(blockID) + blockMetadata, err := deps.Protocol.Engines.Main.Get().Retainer.BlockMetadata(blockID) if err != nil { return nil, ierrors.Errorf("failed to get BlockMetadata: %v", err) } diff --git a/components/inx/server_commitments.go b/components/inx/server_commitments.go index 9b8aa75f7..6c3030142 100644 --- a/components/inx/server_commitments.go +++ b/components/inx/server_commitments.go @@ -29,7 +29,7 @@ func (s *Server) ReadCommitment(_ context.Context, req *inx.CommitmentRequest) ( commitmentSlot = req.GetCommitmentId().Unwrap().Slot() } - commitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(commitmentSlot) + commitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(commitmentSlot) if err != nil { if ierrors.Is(err, kvstore.ErrKeyNotFound) { return nil, status.Errorf(codes.NotFound, "commitment slot %d not found", req.GetCommitmentSlot()) diff --git a/components/inx/server_issuance.go b/components/inx/server_issuance.go index 652c25a16..50d43f2ae 100644 --- a/components/inx/server_issuance.go +++ b/components/inx/server_issuance.go @@ -12,7 +12,7 @@ import ( ) func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.TipsResponse, error) { - references := deps.Protocol.MainEngine.Get().TipSelection.SelectTips(int(req.GetCount())) + references := deps.Protocol.Engines.Main.Get().TipSelection.SelectTips(int(req.GetCount())) return &inx.TipsResponse{ StrongTips: inx.NewBlockIds(references[iotago.StrongParentType]), @@ -30,7 +30,7 @@ func (s *Server) ValidatePayload(_ context.Context, payload *inx.RawPayload) (*i switch typedPayload := blockPayload.(type) { case *iotago.SignedTransaction: - memPool := deps.Protocol.MainEngine.Get().Ledger.MemPool() + memPool := deps.Protocol.Engines.Main.Get().Ledger.MemPool() inputReferences, inputsErr := memPool.VM().Inputs(typedPayload.Transaction) if inputsErr != nil { diff --git a/components/inx/server_node.go b/components/inx/server_node.go index 33a7feb5f..87f3361b7 100644 --- a/components/inx/server_node.go +++ b/components/inx/server_node.go @@ -16,7 +16,7 @@ func inxNodeStatus(status *syncmanager.SyncStatus) *inx.NodeStatus { // HasPruned is false when a node just started from a snapshot and keeps data of the LastPrunedEpoch, thus still need // to send finalized commitment. if !status.HasPruned || status.LatestFinalizedSlot > deps.Protocol.CommittedAPI().TimeProvider().EpochEnd(status.LastPrunedEpoch) { - finalizedCommitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(status.LatestFinalizedSlot) + finalizedCommitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(status.LatestFinalizedSlot) if err != nil { return nil } @@ -34,7 +34,7 @@ func inxNodeStatus(status *syncmanager.SyncStatus) *inx.NodeStatus { } func (s *Server) ReadNodeStatus(context.Context, *inx.NoParams) (*inx.NodeStatus, error) { - return inxNodeStatus(deps.Protocol.MainEngine.Get().SyncManager.SyncStatus()), nil + return inxNodeStatus(deps.Protocol.Engines.Main.Get().SyncManager.SyncStatus()), nil } func (s *Server) ListenToNodeStatus(req *inx.NodeStatusRequest, srv inx.INX_ListenToNodeStatusServer) error { @@ -95,7 +95,7 @@ func (s *Server) ListenToNodeStatus(req *inx.NodeStatusRequest, srv inx.INX_List func (s *Server) ReadNodeConfiguration(context.Context, *inx.NoParams) (*inx.NodeConfiguration, error) { protoParams := make([]*inx.RawProtocolParameters, 0) - provider := deps.Protocol.MainEngine.Get().Storage.Settings().APIProvider() + provider := deps.Protocol.Engines.Main.Get().Storage.Settings().APIProvider() for _, version := range provider.ProtocolEpochVersions() { protocolParams := provider.ProtocolParameters(version.Version) if protocolParams == nil { diff --git a/components/inx/server_utxo.go b/components/inx/server_utxo.go index 595879306..496a8f23e 100644 --- a/components/inx/server_utxo.go +++ b/components/inx/server_utxo.go @@ -17,7 +17,7 @@ import ( ) func NewLedgerOutput(o *utxoledger.Output) (*inx.LedgerOutput, error) { - latestCommitment := deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment() + latestCommitment := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment() l := &inx.LedgerOutput{ OutputId: inx.NewOutputId(o.OutputID()), @@ -30,7 +30,7 @@ func NewLedgerOutput(o *utxoledger.Output) (*inx.LedgerOutput, error) { includedSlot := o.SlotBooked() if includedSlot <= latestCommitment.Slot() { - includedCommitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(includedSlot) + includedCommitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(includedSlot) if err != nil { return nil, ierrors.Wrapf(err, "failed to load commitment with slot: %d", includedSlot) } @@ -52,10 +52,10 @@ func NewLedgerSpent(s *utxoledger.Spent) (*inx.LedgerSpent, error) { SlotSpent: uint32(s.SlotSpent()), } - latestCommitment := deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment() + latestCommitment := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment() spentSlot := s.SlotSpent() if spentSlot <= latestCommitment.Slot() { - spentCommitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(spentSlot) + spentCommitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(spentSlot) if err != nil { return nil, ierrors.Wrapf(err, "failed to load commitment with slot: %d", spentSlot) } @@ -118,7 +118,7 @@ func NewLedgerUpdateBatchOperationConsumed(spent *utxoledger.Spent) (*inx.Ledger } func (s *Server) ReadOutput(_ context.Context, id *inx.OutputId) (*inx.OutputResponse, error) { - engine := deps.Protocol.MainEngine.Get() + engine := deps.Protocol.Engines.Main.Get() latestCommitment := engine.Storage.Settings().LatestCommitment() @@ -157,7 +157,7 @@ func (s *Server) ReadOutput(_ context.Context, id *inx.OutputId) (*inx.OutputRes } func (s *Server) ReadUnspentOutputs(_ *inx.NoParams, srv inx.INX_ReadUnspentOutputsServer) error { - engine := deps.Protocol.MainEngine.Get() + engine := deps.Protocol.Engines.Main.Get() latestCommitment := engine.Storage.Settings().LatestCommitment() var innerErr error @@ -230,7 +230,7 @@ func (s *Server) ListenToLedgerUpdates(req *inx.SlotRangeRequest, srv inx.INX_Li sendStateDiffsRange := func(startSlot iotago.SlotIndex, endSlot iotago.SlotIndex) error { for currentSlot := startSlot; currentSlot <= endSlot; currentSlot++ { - stateDiff, err := deps.Protocol.MainEngine.Get().Ledger.SlotDiffs(currentSlot) + stateDiff, err := deps.Protocol.Engines.Main.Get().Ledger.SlotDiffs(currentSlot) if err != nil { return status.Errorf(codes.NotFound, "ledger update for slot %d not found", currentSlot) } @@ -252,7 +252,7 @@ func (s *Server) ListenToLedgerUpdates(req *inx.SlotRangeRequest, srv inx.INX_Li return 0, nil } - latestCommitment := deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment() + latestCommitment := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment() if startSlot > latestCommitment.Slot() { // no need to send previous state diffs @@ -260,7 +260,7 @@ func (s *Server) ListenToLedgerUpdates(req *inx.SlotRangeRequest, srv inx.INX_Li } // Stream all available milestone diffs first - prunedEpoch, hasPruned := deps.Protocol.MainEngine.Get().SyncManager.LastPrunedEpoch() + prunedEpoch, hasPruned := deps.Protocol.Engines.Main.Get().SyncManager.LastPrunedEpoch() if hasPruned && startSlot <= deps.Protocol.CommittedAPI().TimeProvider().EpochEnd(prunedEpoch) { return 0, status.Errorf(codes.InvalidArgument, "given startSlot %d is older than the current pruningSlot %d", startSlot, deps.Protocol.CommittedAPI().TimeProvider().EpochEnd(prunedEpoch)) } diff --git a/components/metrics/metrics_accounts.go b/components/metrics/metrics_accounts.go index 0f7bf1086..a761ca800 100644 --- a/components/metrics/metrics_accounts.go +++ b/components/metrics/metrics_accounts.go @@ -23,7 +23,7 @@ var AccountMetrics = collector.NewCollection(accountNamespace, collector.WithPruningDelay(10*time.Minute), collector.WithInitFunc(func() { deps.Protocol.Events.Engine.BlockGadget.BlockAccepted.Hook(func(block *blocks.Block) { - accountData, exists, _ := deps.Protocol.MainEngine.Get().Ledger.Account(block.ProtocolBlock().IssuerID, deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment().Slot()) + accountData, exists, _ := deps.Protocol.Engines.Main.Get().Ledger.Account(block.ProtocolBlock().IssuerID, deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot()) if exists { deps.Collector.Update(accountNamespace, credits, float64(accountData.Credits.Value), accountData.ID.String()) } @@ -34,7 +34,7 @@ var AccountMetrics = collector.NewCollection(accountNamespace, collector.WithType(collector.Gauge), collector.WithHelp("Seats seen as active by the node."), collector.WithCollectFunc(func() (metricValue float64, labelValues []string) { - return float64(deps.Protocol.MainEngine.Get().SybilProtection.SeatManager().OnlineCommittee().Size()), nil + return float64(deps.Protocol.Engines.Main.Get().SybilProtection.SeatManager().OnlineCommittee().Size()), nil }), )), ) diff --git a/components/metrics/metrics_conflicts.go b/components/metrics/metrics_conflicts.go index 22baf4cd3..8b8bcda64 100644 --- a/components/metrics/metrics_conflicts.go +++ b/components/metrics/metrics_conflicts.go @@ -22,9 +22,9 @@ var ConflictMetrics = collector.NewCollection(conflictNamespace, collector.WithHelp("Time since transaction issuance to the conflict acceptance"), collector.WithInitFunc(func() { deps.Protocol.Events.Engine.ConflictDAG.ConflictAccepted.Hook(func(conflictID iotago.TransactionID) { - if txMetadata, exists := deps.Protocol.MainEngine.Get().Ledger.MemPool().TransactionMetadata(conflictID); exists { + if txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.MemPool().TransactionMetadata(conflictID); exists { firstAttachmentID := txMetadata.EarliestIncludedAttachment() - if block, blockExists := deps.Protocol.MainEngine.Get().BlockFromCache(firstAttachmentID); blockExists { + if block, blockExists := deps.Protocol.Engines.Main.Get().BlockFromCache(firstAttachmentID); blockExists { timeSinceIssuance := time.Since(block.IssuingTime()).Milliseconds() timeIssuanceSeconds := float64(timeSinceIssuance) / 1000 deps.Collector.Update(conflictNamespace, resolutionTime, timeIssuanceSeconds) diff --git a/components/metrics/metrics_db.go b/components/metrics/metrics_db.go index 65260a2ad..2d2987868 100644 --- a/components/metrics/metrics_db.go +++ b/components/metrics/metrics_db.go @@ -17,14 +17,14 @@ var DBMetrics = collector.NewCollection(dbNamespace, collector.WithType(collector.Gauge), collector.WithHelp("DB size in bytes for permanent storage."), collector.WithCollectFunc(func() (metricValue float64, labelValues []string) { - return float64(deps.Protocol.MainEngine.Get().Storage.PermanentDatabaseSize()), nil + return float64(deps.Protocol.Engines.Main.Get().Storage.PermanentDatabaseSize()), nil }), )), collector.WithMetric(collector.NewMetric(sizeBytesPrunable, collector.WithType(collector.Gauge), collector.WithHelp("DB size in bytes for prunable storage."), collector.WithCollectFunc(func() (metricValue float64, labelValues []string) { - return float64(deps.Protocol.MainEngine.Get().Storage.PrunableDatabaseSize()), nil + return float64(deps.Protocol.Engines.Main.Get().Storage.PrunableDatabaseSize()), nil }), )), ) diff --git a/components/metrics/metrics_info.go b/components/metrics/metrics_info.go index 4d3457798..7bae443d5 100644 --- a/components/metrics/metrics_info.go +++ b/components/metrics/metrics_info.go @@ -36,7 +36,7 @@ var InfoMetrics = collector.NewCollection(infoNamespace, collector.WithType(collector.Gauge), collector.WithHelp("Node sync status based on ATT."), collector.WithCollectFunc(func() (metricValue float64, labelValues []string) { - if deps.Protocol.MainEngine.Get().SyncManager.IsNodeSynced() { + if deps.Protocol.Engines.Main.Get().SyncManager.IsNodeSynced() { return 1, nil } diff --git a/components/metrics/metrics_scheduler.go b/components/metrics/metrics_scheduler.go index 124071d68..5096ef433 100644 --- a/components/metrics/metrics_scheduler.go +++ b/components/metrics/metrics_scheduler.go @@ -38,22 +38,22 @@ var SchedulerMetrics = collector.NewCollection(schedulerNamespace, collector.WithHelp("Current size of each node's queue (in work units)."), collector.WithInitFunc(func() { deps.Protocol.Events.Engine.Scheduler.BlockEnqueued.Hook(func(block *blocks.Block) { - deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.MainEngine.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockSkipped.Hook(func(block *blocks.Block) { - deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.MainEngine.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockDropped.Hook(func(block *blocks.Block, _ error) { - deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.MainEngine.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(block *blocks.Block) { - deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.MainEngine.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) }, event.WithWorkerPool(Component.WorkerPool)) }), @@ -66,25 +66,25 @@ var SchedulerMetrics = collector.NewCollection(schedulerNamespace, collector.WithInitFunc(func() { deps.Protocol.Events.Engine.Scheduler.BlockEnqueued.Hook(func(block *blocks.Block) { if _, isBasic := block.BasicBlock(); isBasic { - deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.MainEngine.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) } }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockSkipped.Hook(func(block *blocks.Block) { if _, isBasic := block.BasicBlock(); isBasic { - deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.MainEngine.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) } }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockDropped.Hook(func(block *blocks.Block, _ error) { if _, isBasic := block.BasicBlock(); isBasic { - deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.MainEngine.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) } }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(block *blocks.Block) { if _, isBasic := block.BasicBlock(); isBasic { - deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.MainEngine.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) } }, event.WithWorkerPool(Component.WorkerPool)) }), @@ -97,25 +97,25 @@ var SchedulerMetrics = collector.NewCollection(schedulerNamespace, collector.WithInitFunc(func() { deps.Protocol.Events.Engine.Scheduler.BlockEnqueued.Hook(func(block *blocks.Block) { if _, isValidation := block.ValidationBlock(); isValidation { - deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.MainEngine.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) } }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockSkipped.Hook(func(block *blocks.Block) { if _, isValidation := block.ValidationBlock(); isValidation { - deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.MainEngine.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) } }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockDropped.Hook(func(block *blocks.Block, _ error) { if _, isValidation := block.ValidationBlock(); isValidation { - deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.MainEngine.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) } }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(block *blocks.Block) { if _, isValidation := block.ValidationBlock(); isValidation { - deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.MainEngine.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) + deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().IssuerID)), block.ProtocolBlock().IssuerID.String()) } }, event.WithWorkerPool(Component.WorkerPool)) }), @@ -127,9 +127,9 @@ var SchedulerMetrics = collector.NewCollection(schedulerNamespace, collector.WithHelp("Current amount of mana of each issuer in the queue."), collector.WithInitFunc(func() { deps.Protocol.Events.Engine.Scheduler.BlockEnqueued.Hook(func(block *blocks.Block) { - mana, err := deps.Protocol.MainEngine.Get().Ledger.ManaManager().GetManaOnAccount(block.ProtocolBlock().IssuerID, block.SlotCommitmentID().Slot()) + mana, err := deps.Protocol.Engines.Main.Get().Ledger.ManaManager().GetManaOnAccount(block.ProtocolBlock().IssuerID, block.SlotCommitmentID().Slot()) if err != nil { - deps.Protocol.MainEngine.Get().ErrorHandler("metrics")(ierrors.Wrapf(err, "failed to retrieve mana on account %s for slot %d", block.ProtocolBlock().IssuerID, block.SlotCommitmentID().Slot())) + deps.Protocol.Engines.Main.Get().ErrorHandler("metrics")(ierrors.Wrapf(err, "failed to retrieve mana on account %s for slot %d", block.ProtocolBlock().IssuerID, block.SlotCommitmentID().Slot())) return } @@ -168,42 +168,42 @@ var SchedulerMetrics = collector.NewCollection(schedulerNamespace, collector.WithType(collector.Gauge), collector.WithHelp("Maximum number of basic blocks that can be stored in the buffer."), collector.WithCollectFunc(func() (float64, []string) { - return float64(deps.Protocol.MainEngine.Get().CommittedAPI().ProtocolParameters().CongestionControlParameters().MaxBufferSize), []string{} + return float64(deps.Protocol.Engines.Main.Get().CommittedAPI().ProtocolParameters().CongestionControlParameters().MaxBufferSize), []string{} }), )), collector.WithMetric(collector.NewMetric(basicBufferReadyBlockCount, collector.WithType(collector.Gauge), collector.WithHelp("Number of ready blocks in the scheduler buffer."), collector.WithCollectFunc(func() (float64, []string) { - return float64(deps.Protocol.MainEngine.Get().Scheduler.ReadyBlocksCount()), []string{} + return float64(deps.Protocol.Engines.Main.Get().Scheduler.ReadyBlocksCount()), []string{} }), )), collector.WithMetric(collector.NewMetric(basicBufferTotalSize, collector.WithType(collector.Gauge), collector.WithHelp("Current number of basic blocks in the scheduler buffer."), collector.WithCollectFunc(func() (float64, []string) { - return float64(deps.Protocol.MainEngine.Get().Scheduler.BasicBufferSize()), []string{} + return float64(deps.Protocol.Engines.Main.Get().Scheduler.BasicBufferSize()), []string{} }), )), collector.WithMetric(collector.NewMetric(rate, collector.WithType(collector.Gauge), collector.WithHelp("Current scheduling rate of basic blocks."), collector.WithCollectFunc(func() (float64, []string) { - return float64(deps.Protocol.MainEngine.Get().CommittedAPI().ProtocolParameters().CongestionControlParameters().SchedulerRate), []string{} + return float64(deps.Protocol.Engines.Main.Get().CommittedAPI().ProtocolParameters().CongestionControlParameters().SchedulerRate), []string{} }), )), collector.WithMetric(collector.NewMetric(validatorBufferTotalSize, collector.WithType(collector.Gauge), collector.WithHelp("Current number of validation blocks in the scheduling buffer."), collector.WithCollectFunc(func() (float64, []string) { - return float64(deps.Protocol.MainEngine.Get().Scheduler.ValidatorBufferSize()), []string{} + return float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorBufferSize()), []string{} }), )), collector.WithMetric(collector.NewMetric(validatorQueueMaxSize, collector.WithType(collector.Gauge), collector.WithHelp("Maximum number of validation blocks that can be stored in each validator queue."), collector.WithCollectFunc(func() (float64, []string) { - return float64(deps.Protocol.MainEngine.Get().CommittedAPI().ProtocolParameters().CongestionControlParameters().MaxValidationBufferSize), []string{} + return float64(deps.Protocol.Engines.Main.Get().CommittedAPI().ProtocolParameters().CongestionControlParameters().MaxValidationBufferSize), []string{} }), )), ) diff --git a/components/metrics/metrics_slots.go b/components/metrics/metrics_slots.go index 03423acfb..021fc010f 100644 --- a/components/metrics/metrics_slots.go +++ b/components/metrics/metrics_slots.go @@ -69,10 +69,10 @@ var SlotMetrics = collector.NewCollection(slotNamespace, collector.WithPruningDelay(10*time.Minute), collector.WithHelp("Number of accepted attachments by the node per slot."), collector.WithInitFunc(func() { - deps.Protocol.MainEngine.Get().Ledger.OnTransactionAttached(func(transactionMetadata mempool.TransactionMetadata) { + deps.Protocol.Engines.Main.Get().Ledger.OnTransactionAttached(func(transactionMetadata mempool.TransactionMetadata) { transactionMetadata.OnAccepted(func() { for _, attachmentBlockID := range transactionMetadata.ValidAttachments() { - if block, exists := deps.Protocol.MainEngine.Get().BlockCache.Block(attachmentBlockID); exists && block.IsAccepted() { + if block, exists := deps.Protocol.Engines.Main.Get().BlockCache.Block(attachmentBlockID); exists && block.IsAccepted() { deps.Collector.Increment(slotNamespace, acceptedAttachments, strconv.Itoa(int(attachmentBlockID.Slot()))) } } @@ -94,7 +94,7 @@ var SlotMetrics = collector.NewCollection(slotNamespace, }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.ConflictDAG.ConflictCreated.Hook(func(conflictID iotago.TransactionID) { - if txMetadata, exists := deps.Protocol.MainEngine.Get().Ledger.TransactionMetadata(conflictID); exists { + if txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.TransactionMetadata(conflictID); exists { for _, attachment := range txMetadata.ValidAttachments() { deps.Collector.Increment(slotNamespace, createdConflicts, strconv.Itoa(int(attachment.Slot()))) } @@ -116,9 +116,9 @@ var SlotMetrics = collector.NewCollection(slotNamespace, }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.ConflictDAG.ConflictAccepted.Hook(func(conflictID iotago.TransactionID) { - if txMetadata, exists := deps.Protocol.MainEngine.Get().Ledger.TransactionMetadata(conflictID); exists { + if txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.TransactionMetadata(conflictID); exists { for _, attachmentBlockID := range txMetadata.ValidAttachments() { - if attachment, exists := deps.Protocol.MainEngine.Get().BlockCache.Block(attachmentBlockID); exists && attachment.IsAccepted() { + if attachment, exists := deps.Protocol.Engines.Main.Get().BlockCache.Block(attachmentBlockID); exists && attachment.IsAccepted() { deps.Collector.Increment(slotNamespace, acceptedConflicts, strconv.Itoa(int(attachment.ID().Slot()))) } } @@ -140,9 +140,9 @@ var SlotMetrics = collector.NewCollection(slotNamespace, }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.ConflictDAG.ConflictRejected.Hook(func(conflictID iotago.TransactionID) { - if txMetadata, exists := deps.Protocol.MainEngine.Get().Ledger.TransactionMetadata(conflictID); exists { + if txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.TransactionMetadata(conflictID); exists { for _, attachmentBlockID := range txMetadata.ValidAttachments() { - if attachment, exists := deps.Protocol.MainEngine.Get().BlockCache.Block(attachmentBlockID); exists && attachment.IsAccepted() { + if attachment, exists := deps.Protocol.Engines.Main.Get().BlockCache.Block(attachmentBlockID); exists && attachment.IsAccepted() { deps.Collector.Increment(slotNamespace, rejectedConflicts, strconv.Itoa(int(attachment.ID().Slot()))) } } diff --git a/components/metrics/metrics_tangle.go b/components/metrics/metrics_tangle.go index a6bb7d3e6..82cca7b85 100644 --- a/components/metrics/metrics_tangle.go +++ b/components/metrics/metrics_tangle.go @@ -21,7 +21,7 @@ var TangleMetrics = collector.NewCollection(tangleNamespace, collector.WithType(collector.Gauge), collector.WithHelp("Number of strong tips in the tangle"), collector.WithCollectFunc(func() (metricValue float64, labelValues []string) { - count := len(deps.Protocol.MainEngine.Get().TipManager.StrongTips()) + count := len(deps.Protocol.Engines.Main.Get().TipManager.StrongTips()) return float64(count), nil }), @@ -30,7 +30,7 @@ var TangleMetrics = collector.NewCollection(tangleNamespace, collector.WithType(collector.Gauge), collector.WithHelp("Number of weak tips in the tangle"), collector.WithCollectFunc(func() (metricValue float64, labelValues []string) { - count := len(deps.Protocol.MainEngine.Get().TipManager.WeakTips()) + count := len(deps.Protocol.Engines.Main.Get().TipManager.WeakTips()) return float64(count), nil }), diff --git a/components/metricstracker/component.go b/components/metricstracker/component.go index dd32ff1a3..9cde574c9 100644 --- a/components/metricstracker/component.go +++ b/components/metricstracker/component.go @@ -46,7 +46,7 @@ func provide(c *dig.Container) error { } if err := c.Provide(func(deps metricsTrackerDeps) *MetricsTracker { - m := New(deps.Protocol.MainEngine.Get().SyncManager.IsBootstrapped) + m := New(deps.Protocol.Engines.Main.Get().SyncManager.IsBootstrapped) return m }); err != nil { diff --git a/components/restapi/core/accounts.go b/components/restapi/core/accounts.go index e57c9a783..207e68f07 100644 --- a/components/restapi/core/accounts.go +++ b/components/restapi/core/accounts.go @@ -22,9 +22,9 @@ func congestionForAccountID(c echo.Context) (*apimodels.CongestionResponse, erro return nil, err } - commitment := deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment() + commitment := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment() - acc, exists, err := deps.Protocol.MainEngine.Get().Ledger.Account(accountID, commitment.Slot()) + acc, exists, err := deps.Protocol.Engines.Main.Get().Ledger.Account(accountID, commitment.Slot()) if err != nil { return nil, ierrors.Wrapf(err, "failed to get account: %s form the Ledger", accountID.ToHex()) } @@ -34,7 +34,7 @@ func congestionForAccountID(c echo.Context) (*apimodels.CongestionResponse, erro return &apimodels.CongestionResponse{ Slot: commitment.Slot(), - Ready: deps.Protocol.MainEngine.Get().Scheduler.IsBlockIssuerReady(accountID), + Ready: deps.Protocol.Engines.Main.Get().Scheduler.IsBlockIssuerReady(accountID), ReferenceManaCost: commitment.ReferenceManaCost(), BlockIssuanceCredits: acc.Credits.Value, }, nil @@ -52,7 +52,7 @@ func validators(c echo.Context) (*apimodels.ValidatorsResponse, error) { pageSize = restapi.ParamsRestAPI.MaxPageSize } } - latestCommittedSlot := deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment().Slot() + latestCommittedSlot := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot() // no cursor provided will be the first request requestedSlot := latestCommittedSlot var cursorIndex uint32 @@ -71,13 +71,13 @@ func validators(c echo.Context) (*apimodels.ValidatorsResponse, error) { nextEpoch := deps.Protocol.APIForSlot(latestCommittedSlot).TimeProvider().EpochFromSlot(latestCommittedSlot) + 1 slotRange := uint32(requestedSlot) / restapi.ParamsRestAPI.RequestsMemoryCacheGranularity - registeredValidators, exists := deps.Protocol.MainEngine.Get().Retainer.RegisteredValidatorsCache(slotRange) + registeredValidators, exists := deps.Protocol.Engines.Main.Get().Retainer.RegisteredValidatorsCache(slotRange) if !exists { - registeredValidators, err = deps.Protocol.MainEngine.Get().SybilProtection.OrderedRegisteredCandidateValidatorsList(nextEpoch) + registeredValidators, err = deps.Protocol.Engines.Main.Get().SybilProtection.OrderedRegisteredCandidateValidatorsList(nextEpoch) if err != nil { return nil, ierrors.Wrapf(err, "failed to get ordered registered validators list for epoch %d", nextEpoch) } - deps.Protocol.MainEngine.Get().Retainer.RetainRegisteredValidatorsCache(slotRange, registeredValidators) + deps.Protocol.Engines.Main.Get().Retainer.RetainRegisteredValidatorsCache(slotRange, registeredValidators) } page := registeredValidators[cursorIndex:lo.Min(cursorIndex+pageSize, uint32(len(registeredValidators)))] @@ -100,9 +100,9 @@ func validatorByAccountID(c echo.Context) (*apimodels.ValidatorResponse, error) if err != nil { return nil, ierrors.Wrapf(err, "failed to parse the %s parameter", restapipkg.ParameterAccountID) } - latestCommittedSlot := deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment().Slot() + latestCommittedSlot := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot() - accountData, exists, err := deps.Protocol.MainEngine.Get().Ledger.Account(accountID, latestCommittedSlot) + accountData, exists, err := deps.Protocol.Engines.Main.Get().Ledger.Account(accountID, latestCommittedSlot) if err != nil { return nil, ierrors.Wrapf(err, "failed to get account: %s form the Ledger", accountID.ToHex()) } @@ -110,7 +110,7 @@ func validatorByAccountID(c echo.Context) (*apimodels.ValidatorResponse, error) return nil, ierrors.Errorf("account not found: %s for latest committedSlot %d", accountID.ToHex(), latestCommittedSlot) } nextEpoch := deps.Protocol.APIForSlot(latestCommittedSlot).TimeProvider().EpochFromSlot(latestCommittedSlot) + 1 - active := deps.Protocol.MainEngine.Get().SybilProtection.IsCandidateActive(accountID, nextEpoch) + active := deps.Protocol.Engines.Main.Get().SybilProtection.IsCandidateActive(accountID, nextEpoch) return &apimodels.ValidatorResponse{ AccountID: accountID, @@ -130,7 +130,7 @@ func rewardsByOutputID(c echo.Context) (*apimodels.ManaRewardsResponse, error) { return nil, ierrors.Wrapf(err, "failed to parse the %s parameter", restapipkg.ParameterOutputID) } - utxoOutput, err := deps.Protocol.MainEngine.Get().Ledger.Output(outputID) + utxoOutput, err := deps.Protocol.Engines.Main.Get().Ledger.Output(outputID) if err != nil { return nil, ierrors.Wrapf(err, "failed to get output %s from ledger", outputID.ToHex()) } @@ -150,7 +150,7 @@ func rewardsByOutputID(c echo.Context) (*apimodels.ManaRewardsResponse, error) { stakingFeature := feature.(*iotago.StakingFeature) // check if the account is a validator - reward, actualStart, actualEnd, err = deps.Protocol.MainEngine.Get().SybilProtection.ValidatorReward( + reward, actualStart, actualEnd, err = deps.Protocol.Engines.Main.Get().SybilProtection.ValidatorReward( accountOutput.AccountID, stakingFeature.StakedAmount, stakingFeature.StartEpoch, @@ -160,13 +160,13 @@ func rewardsByOutputID(c echo.Context) (*apimodels.ManaRewardsResponse, error) { case iotago.OutputDelegation: //nolint:forcetypeassert delegationOutput := utxoOutput.Output().(*iotago.DelegationOutput) - latestCommittedSlot := deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment().Slot() + latestCommittedSlot := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot() stakingEnd := delegationOutput.EndEpoch // the output is in delayed calaiming state if endEpoch is set, otherwise we use latest possible epoch if delegationOutput.EndEpoch == 0 { - stakingEnd = deps.Protocol.APIForSlot(latestCommittedSlot).TimeProvider().EpochFromSlot(deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment().Slot()) + stakingEnd = deps.Protocol.APIForSlot(latestCommittedSlot).TimeProvider().EpochFromSlot(deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot()) } - reward, actualStart, actualEnd, err = deps.Protocol.MainEngine.Get().SybilProtection.DelegatorReward( + reward, actualStart, actualEnd, err = deps.Protocol.Engines.Main.Get().SybilProtection.DelegatorReward( delegationOutput.ValidatorAddress.AccountID(), delegationOutput.DelegatedAmount, delegationOutput.StartEpoch, @@ -198,7 +198,7 @@ func selectedCommittee(c echo.Context) *apimodels.CommitteeResponse { slot = timeProvider.EpochEnd(epoch) } - seatedAccounts := deps.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(slot) + seatedAccounts := deps.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(slot) committee := make([]*apimodels.CommitteeMemberResponse, 0, seatedAccounts.Accounts().Size()) seatedAccounts.Accounts().ForEach(func(accountID iotago.AccountID, seat *account.Pool) bool { committee = append(committee, &apimodels.CommitteeMemberResponse{ diff --git a/components/restapi/core/blocks.go b/components/restapi/core/blocks.go index 0edd00cd1..96ce3d9c4 100644 --- a/components/restapi/core/blocks.go +++ b/components/restapi/core/blocks.go @@ -21,7 +21,7 @@ func blockByID(c echo.Context) (*model.Block, error) { return nil, ierrors.Wrapf(err, "failed to parse block ID: %s", c.Param(restapi.ParameterBlockID)) } - block, exists := deps.Protocol.MainEngine.Get().Block(blockID) + block, exists := deps.Protocol.Engines.Main.Get().Block(blockID) if !exists { return nil, ierrors.Errorf("block not found: %s", blockID.ToHex()) } @@ -30,7 +30,7 @@ func blockByID(c echo.Context) (*model.Block, error) { } func blockMetadataByBlockID(blockID iotago.BlockID) (*apimodels.BlockMetadataResponse, error) { - blockMetadata, err := deps.Protocol.MainEngine.Get().Retainer.BlockMetadata(blockID) + blockMetadata, err := deps.Protocol.Engines.Main.Get().Retainer.BlockMetadata(blockID) if err != nil { return nil, ierrors.Wrapf(err, "failed to get block metadata: %s", blockID.ToHex()) } @@ -48,15 +48,15 @@ func blockMetadataByID(c echo.Context) (*apimodels.BlockMetadataResponse, error) } func blockIssuanceBySlot(slotIndex iotago.SlotIndex) (*apimodels.IssuanceBlockHeaderResponse, error) { - references := deps.Protocol.MainEngine.Get().TipSelection.SelectTips(iotago.BlockMaxParents) + references := deps.Protocol.Engines.Main.Get().TipSelection.SelectTips(iotago.BlockMaxParents) var slotCommitment *model.Commitment var err error // by default we use latest commitment if slotIndex == 0 { - slotCommitment = deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment() + slotCommitment = deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment() } else { - slotCommitment, err = deps.Protocol.MainEngine.Get().Storage.Commitments().Load(slotIndex) + slotCommitment, err = deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(slotIndex) if err != nil { return nil, ierrors.Wrapf(err, "failed to load commitment for requested slot %d", slotIndex) } @@ -70,7 +70,7 @@ func blockIssuanceBySlot(slotIndex iotago.SlotIndex) (*apimodels.IssuanceBlockHe StrongParents: references[iotago.StrongParentType], WeakParents: references[iotago.WeakParentType], ShallowLikeParents: references[iotago.ShallowLikeParentType], - LatestFinalizedSlot: deps.Protocol.MainEngine.Get().SyncManager.LatestFinalizedSlot(), + LatestFinalizedSlot: deps.Protocol.Engines.Main.Get().SyncManager.LatestFinalizedSlot(), Commitment: slotCommitment.Commitment(), } diff --git a/components/restapi/core/commitment.go b/components/restapi/core/commitment.go index 53de1df08..712e0378a 100644 --- a/components/restapi/core/commitment.go +++ b/components/restapi/core/commitment.go @@ -20,7 +20,7 @@ func indexByCommitmentID(c echo.Context) (iotago.SlotIndex, error) { } func getCommitmentDetails(index iotago.SlotIndex) (*iotago.Commitment, error) { - commitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(index) + commitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(index) if err != nil { return nil, ierrors.Wrapf(err, "failed to load commitment: %d", index) } @@ -29,7 +29,7 @@ func getCommitmentDetails(index iotago.SlotIndex) (*iotago.Commitment, error) { } func getUTXOChanges(index iotago.SlotIndex) (*apimodels.UTXOChangesResponse, error) { - diffs, err := deps.Protocol.MainEngine.Get().Ledger.SlotDiffs(index) + diffs, err := deps.Protocol.Engines.Main.Get().Ledger.SlotDiffs(index) if err != nil { return nil, ierrors.Wrapf(err, "failed to get slot diffs: %d", index) } diff --git a/components/restapi/core/component.go b/components/restapi/core/component.go index 0e1d09666..0574bf620 100644 --- a/components/restapi/core/component.go +++ b/components/restapi/core/component.go @@ -373,7 +373,7 @@ func AddFeature(feature string) { func checkNodeSynced() echo.MiddlewareFunc { return func(next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) error { - if !deps.Protocol.MainEngine.Get().SyncManager.IsNodeSynced() { + if !deps.Protocol.Engines.Main.Get().SyncManager.IsNodeSynced() { return ierrors.Wrap(echo.ErrServiceUnavailable, "node is not synced") } diff --git a/components/restapi/core/node.go b/components/restapi/core/node.go index 325aba0c3..955ad9cfc 100644 --- a/components/restapi/core/node.go +++ b/components/restapi/core/node.go @@ -6,7 +6,7 @@ import ( func protocolParameters() []*apimodels.InfoResProtocolParameters { protoParams := make([]*apimodels.InfoResProtocolParameters, 0) - provider := deps.Protocol.MainEngine.Get().Storage.Settings().APIProvider() + provider := deps.Protocol.Engines.Main.Get().Storage.Settings().APIProvider() for _, version := range provider.ProtocolEpochVersions() { protocolParams := provider.ProtocolParameters(version.Version) if protocolParams == nil { @@ -23,8 +23,8 @@ func protocolParameters() []*apimodels.InfoResProtocolParameters { } func info() *apimodels.InfoResponse { - clSnapshot := deps.Protocol.MainEngine.Get().Clock.Snapshot() - syncStatus := deps.Protocol.MainEngine.Get().SyncManager.SyncStatus() + clSnapshot := deps.Protocol.Engines.Main.Get().Clock.Snapshot() + syncStatus := deps.Protocol.Engines.Main.Get().SyncManager.SyncStatus() metrics := deps.MetricsTracker.NodeMetrics() return &apimodels.InfoResponse{ diff --git a/components/restapi/core/transaction.go b/components/restapi/core/transaction.go index 944b7bfec..9dc1ea160 100644 --- a/components/restapi/core/transaction.go +++ b/components/restapi/core/transaction.go @@ -24,7 +24,7 @@ func blockIDFromTransactionID(transactionID iotago.TransactionID) (iotago.BlockI // Get the first output of that transaction (using index 0) outputID := iotago.OutputIDFromTransactionIDAndIndex(transactionID, 0) - output, spent, err := deps.Protocol.MainEngine.Get().Ledger.OutputOrSpent(outputID) + output, spent, err := deps.Protocol.Engines.Main.Get().Ledger.OutputOrSpent(outputID) if err != nil { return iotago.EmptyBlockID, ierrors.Wrapf(err, "failed to get output: %s", outputID.ToHex()) } @@ -42,7 +42,7 @@ func blockByTransactionID(c echo.Context) (*model.Block, error) { return nil, ierrors.Wrapf(err, "failed to get block ID by transaction ID") } - block, exists := deps.Protocol.MainEngine.Get().Block(blockID) + block, exists := deps.Protocol.Engines.Main.Get().Block(blockID) if !exists { return nil, ierrors.Errorf("block not found: %s", blockID.String()) } diff --git a/components/restapi/core/utxo.go b/components/restapi/core/utxo.go index bc8c4d9b9..e5fec1eea 100644 --- a/components/restapi/core/utxo.go +++ b/components/restapi/core/utxo.go @@ -16,7 +16,7 @@ func getOutput(c echo.Context) (*apimodels.OutputResponse, error) { return nil, ierrors.Wrapf(err, "failed to parse output ID param: %s", c.Param(restapipkg.ParameterOutputID)) } - output, err := deps.Protocol.MainEngine.Get().Ledger.Output(outputID) + output, err := deps.Protocol.Engines.Main.Get().Ledger.Output(outputID) if err != nil { return nil, ierrors.Wrapf(err, "failed to get output: %s from the Ledger", outputID.String()) } @@ -33,7 +33,7 @@ func getOutputMetadata(c echo.Context) (*apimodels.OutputMetadata, error) { return nil, ierrors.Wrapf(err, "failed to parse output ID param: %s", c.Param(restapipkg.ParameterOutputID)) } - output, spent, err := deps.Protocol.MainEngine.Get().Ledger.OutputOrSpent(outputID) + output, spent, err := deps.Protocol.Engines.Main.Get().Ledger.OutputOrSpent(outputID) if err != nil { return nil, ierrors.Wrapf(err, "failed to get output: %s from the Ledger", outputID.String()) } @@ -51,7 +51,7 @@ func getOutputWithMetadata(c echo.Context) (*apimodels.OutputWithMetadataRespons return nil, ierrors.Wrapf(err, "failed to parse output ID param: %s", c.Param(restapipkg.ParameterOutputID)) } - output, spent, err := deps.Protocol.MainEngine.Get().Ledger.OutputOrSpent(outputID) + output, spent, err := deps.Protocol.Engines.Main.Get().Ledger.OutputOrSpent(outputID) if err != nil { return nil, ierrors.Wrapf(err, "failed to get output: %s from the Ledger", outputID.String()) } @@ -82,7 +82,7 @@ func getOutputWithMetadata(c echo.Context) (*apimodels.OutputWithMetadataRespons } func newOutputMetadataResponse(output *utxoledger.Output) (*apimodels.OutputMetadata, error) { - latestCommitment := deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment() + latestCommitment := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment() resp := &apimodels.OutputMetadata{ BlockID: output.BlockID(), @@ -94,7 +94,7 @@ func newOutputMetadataResponse(output *utxoledger.Output) (*apimodels.OutputMeta includedSlotIndex := output.SlotBooked() if includedSlotIndex <= latestCommitment.Slot() { - includedCommitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(includedSlotIndex) + includedCommitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(includedSlotIndex) if err != nil { return nil, ierrors.Wrapf(err, "failed to load commitment with index: %d", includedSlotIndex) } @@ -105,7 +105,7 @@ func newOutputMetadataResponse(output *utxoledger.Output) (*apimodels.OutputMeta } func newSpentMetadataResponse(spent *utxoledger.Spent) (*apimodels.OutputMetadata, error) { - latestCommitment := deps.Protocol.MainEngine.Get().SyncManager.LatestCommitment() + latestCommitment := deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment() resp := &apimodels.OutputMetadata{ BlockID: spent.BlockID(), @@ -118,7 +118,7 @@ func newSpentMetadataResponse(spent *utxoledger.Spent) (*apimodels.OutputMetadat includedSlotIndex := spent.Output().SlotBooked() if includedSlotIndex <= latestCommitment.Slot() { - includedCommitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(includedSlotIndex) + includedCommitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(includedSlotIndex) if err != nil { return nil, ierrors.Wrapf(err, "failed to load commitment with index: %d", includedSlotIndex) } @@ -127,7 +127,7 @@ func newSpentMetadataResponse(spent *utxoledger.Spent) (*apimodels.OutputMetadat spentSlotIndex := spent.SlotSpent() if spentSlotIndex <= latestCommitment.Slot() { - spentCommitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(spentSlotIndex) + spentCommitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(spentSlotIndex) if err != nil { return nil, ierrors.Wrapf(err, "failed to load commitment with index: %d", spentSlotIndex) } diff --git a/components/restapi/management/pruning.go b/components/restapi/management/pruning.go index 6ab776de0..6d613ddec 100644 --- a/components/restapi/management/pruning.go +++ b/components/restapi/management/pruning.go @@ -10,7 +10,7 @@ import ( ) func pruneDatabase(c echo.Context) (*apimodels.PruneDatabaseResponse, error) { - if deps.Protocol.MainEngine.Get().Storage.IsPruning() { + if deps.Protocol.Engines.Main.Get().Storage.IsPruning() { return nil, ierrors.Wrapf(echo.ErrServiceUnavailable, "node is already pruning") } @@ -30,14 +30,14 @@ func pruneDatabase(c echo.Context) (*apimodels.PruneDatabaseResponse, error) { var err error if request.Index != 0 { - err = deps.Protocol.MainEngine.Get().Storage.PruneByEpochIndex(request.Index) + err = deps.Protocol.Engines.Main.Get().Storage.PruneByEpochIndex(request.Index) if err != nil { return nil, ierrors.Wrapf(echo.ErrInternalServerError, "pruning database failed: %s", err) } } if request.Depth != 0 { - _, _, err := deps.Protocol.MainEngine.Get().Storage.PruneByDepth(request.Depth) + _, _, err := deps.Protocol.Engines.Main.Get().Storage.PruneByDepth(request.Depth) if err != nil { return nil, ierrors.Wrapf(echo.ErrInternalServerError, "pruning database failed: %s", err) } @@ -49,13 +49,13 @@ func pruneDatabase(c echo.Context) (*apimodels.PruneDatabaseResponse, error) { return nil, ierrors.Wrapf(echo.ErrInternalServerError, "pruning database failed: %s", err) } - err = deps.Protocol.MainEngine.Get().Storage.PruneBySize(pruningTargetDatabaseSizeBytes) + err = deps.Protocol.Engines.Main.Get().Storage.PruneBySize(pruningTargetDatabaseSizeBytes) if err != nil { return nil, ierrors.Wrapf(echo.ErrInternalServerError, "pruning database failed: %s", err) } } - targetIndex, hasPruned := deps.Protocol.MainEngine.Get().Storage.LastPrunedEpoch() + targetIndex, hasPruned := deps.Protocol.Engines.Main.Get().Storage.LastPrunedEpoch() if hasPruned { targetIndex++ } diff --git a/components/restapi/routes.go b/components/restapi/routes.go index d03cb7820..6250ed11b 100644 --- a/components/restapi/routes.go +++ b/components/restapi/routes.go @@ -21,7 +21,7 @@ type RoutesResponse struct { func setupRoutes() { deps.Echo.GET(nodeAPIHealthRoute, func(c echo.Context) error { - if deps.Protocol.MainEngine.Get().SyncManager.IsNodeSynced() { + if deps.Protocol.Engines.Main.Get().SyncManager.IsNodeSynced() { return c.NoContent(http.StatusOK) } diff --git a/components/validator/component.go b/components/validator/component.go index 23200dcd8..bed6442ca 100644 --- a/components/validator/component.go +++ b/components/validator/component.go @@ -68,7 +68,7 @@ func run() error { } func checkValidatorStatus(ctx context.Context) { - account, exists, err := deps.Protocol.MainEngine.Get().Ledger.Account(validatorAccount.ID(), deps.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Slot()) + account, exists, err := deps.Protocol.Engines.Main.Get().Ledger.Account(validatorAccount.ID(), deps.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot()) if err != nil { Component.LogErrorf("error when retrieving BlockIssuer account %s: %w", validatorAccount.ID(), err) diff --git a/components/validator/issuer.go b/components/validator/issuer.go index bb5210492..ff4456e0d 100644 --- a/components/validator/issuer.go +++ b/components/validator/issuer.go @@ -14,7 +14,7 @@ var ErrBlockTooRecent = ierrors.New("block is too recent compared to latest comm func issueValidatorBlock(ctx context.Context) { // Get the main engine instance in case it changes mid-execution. - engineInstance := deps.Protocol.MainEngine.Get() + engineInstance := deps.Protocol.Engines.Main.Get() blockIssuingTime := time.Now() nextBroadcast := blockIssuingTime.Add(ParamsValidator.CommitteeBroadcastInterval) @@ -97,12 +97,12 @@ func issueValidatorBlock(ctx context.Context) { } func reviveChain(issuingTime time.Time) (*iotago.Commitment, iotago.BlockID, error) { - lastCommittedSlot := deps.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Slot() + lastCommittedSlot := deps.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot() apiForSlot := deps.Protocol.APIForSlot(lastCommittedSlot) // Get a rootblock as recent as possible for the parent. parentBlockID := iotago.EmptyBlockID - for rootBlock := range deps.Protocol.MainEngine.Get().EvictionState.ActiveRootBlocks() { + for rootBlock := range deps.Protocol.Engines.Main.Get().EvictionState.ActiveRootBlocks() { if rootBlock.Slot() > parentBlockID.Slot() { parentBlockID = rootBlock } @@ -122,11 +122,11 @@ func reviveChain(issuingTime time.Time) (*iotago.Commitment, iotago.BlockID, err } commitUntilSlot := issuingSlot - apiForSlot.ProtocolParameters().MinCommittableAge() - if err := deps.Protocol.MainEngine.Get().Notarization.ForceCommitUntil(commitUntilSlot); err != nil { + if err := deps.Protocol.Engines.Main.Get().Notarization.ForceCommitUntil(commitUntilSlot); err != nil { return nil, iotago.EmptyBlockID, ierrors.Wrapf(err, "failed to force commit until slot %d", commitUntilSlot) } - commitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(commitUntilSlot) + commitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(commitUntilSlot) if err != nil { return nil, iotago.EmptyBlockID, ierrors.Wrapf(err, "failed to commit until slot %d to revive chain", commitUntilSlot) } @@ -136,7 +136,7 @@ func reviveChain(issuingTime time.Time) (*iotago.Commitment, iotago.BlockID, err func getAddressableCommitment(blockSlot iotago.SlotIndex) (*iotago.Commitment, error) { protoParams := deps.Protocol.CommittedAPI().ProtocolParameters() - commitment := deps.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment() + commitment := deps.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment() if blockSlot > commitment.Slot+protoParams.MaxCommittableAge() { return nil, ierrors.Wrapf(ErrBlockTooRecent, "can't issue block: block slot %d is too far in the future, latest commitment is %d", blockSlot, commitment.Slot) @@ -148,7 +148,7 @@ func getAddressableCommitment(blockSlot iotago.SlotIndex) (*iotago.Commitment, e } commitmentSlot := commitment.Slot - protoParams.MinCommittableAge() - loadedCommitment, err := deps.Protocol.MainEngine.Get().Storage.Commitments().Load(commitmentSlot) + loadedCommitment, err := deps.Protocol.Engines.Main.Get().Storage.Commitments().Load(commitmentSlot) if err != nil { return nil, ierrors.Wrapf(err, "error loading valid commitment of slot %d according to minCommittableAge from storage", commitmentSlot) } diff --git a/pkg/protocol/api_provider.go b/pkg/protocol/api_provider.go index 8b4bf1861..df8b7cb12 100644 --- a/pkg/protocol/api_provider.go +++ b/pkg/protocol/api_provider.go @@ -20,8 +20,8 @@ func NewAPIProvider(protocol *Protocol) *APIProvider { // APIForVersion returns the API for the given version. func (a *APIProvider) APIForVersion(version iotago.Version) (api iotago.API, err error) { - if mainEngineInstance := a.MainEngine.Get(); mainEngineInstance != nil { - return a.MainEngine.Get().APIForVersion(version) + if mainEngineInstance := a.Engines.Main.Get(); mainEngineInstance != nil { + return a.Engines.Main.Get().APIForVersion(version) } return nil, ierrors.New("no engine instance available") @@ -29,25 +29,25 @@ func (a *APIProvider) APIForVersion(version iotago.Version) (api iotago.API, err // APIForSlot returns the API for the given slot. func (a *APIProvider) APIForSlot(slot iotago.SlotIndex) iotago.API { - return a.MainEngine.Get().APIForSlot(slot) + return a.Engines.Main.Get().APIForSlot(slot) } // APIForEpoch returns the API for the given epoch. func (a *APIProvider) APIForEpoch(epoch iotago.EpochIndex) iotago.API { - return a.MainEngine.Get().APIForEpoch(epoch) + return a.Engines.Main.Get().APIForEpoch(epoch) } // APIForTime returns the API for the given time. func (a *APIProvider) APIForTime(t time.Time) iotago.API { - return a.MainEngine.Get().APIForTime(t) + return a.Engines.Main.Get().APIForTime(t) } // CommittedAPI returns the API for the committed state. func (a *APIProvider) CommittedAPI() iotago.API { - return a.MainEngine.Get().CommittedAPI() + return a.Engines.Main.Get().CommittedAPI() } // LatestAPI returns the latest API. func (a *APIProvider) LatestAPI() iotago.API { - return a.MainEngine.Get().LatestAPI() + return a.Engines.Main.Get().LatestAPI() } diff --git a/pkg/protocol/engine_manager.go b/pkg/protocol/engines.go similarity index 81% rename from pkg/protocol/engine_manager.go rename to pkg/protocol/engines.go index 2ca1d8349..bd775dc4c 100644 --- a/pkg/protocol/engine_manager.go +++ b/pkg/protocol/engines.go @@ -21,8 +21,8 @@ import ( iotago "github.com/iotaledger/iota.go/v4" ) -type EngineManager struct { - MainEngine reactive.Variable[*engine.Engine] +type Engines struct { + Main reactive.Variable[*engine.Engine] protocol *Protocol worker *workerpool.WorkerPool @@ -31,9 +31,9 @@ type EngineManager struct { *module.ReactiveModule } -func NewEngineManager(protocol *Protocol) *EngineManager { - e := &EngineManager{ - MainEngine: reactive.NewVariable[*engine.Engine](), +func NewEngines(protocol *Protocol) *Engines { + e := &Engines{ + Main: reactive.NewVariable[*engine.Engine](), ReactiveModule: protocol.NewReactiveSubModule("Engines"), protocol: protocol, worker: protocol.Workers.CreatePool("Engines", workerpool.WithWorkerCount(1)), @@ -63,7 +63,7 @@ func NewEngineManager(protocol *Protocol) *EngineManager { return e } -func (e *EngineManager) LoadMainEngine(snapshotPath string) (*engine.Engine, error) { +func (e *Engines) LoadMainEngine(snapshotPath string) (*engine.Engine, error) { info := &engineInfo{} if err := ioutils.ReadJSONFromFile(e.infoFilePath(), info); err != nil && !ierrors.Is(err, os.ErrNotExist) { return nil, ierrors.Errorf("unable to read engine info file: %w", err) @@ -72,12 +72,12 @@ func (e *EngineManager) LoadMainEngine(snapshotPath string) (*engine.Engine, err // load previous engine as main engine if it exists. if len(info.Name) > 0 { if exists, isDirectory, err := ioutils.PathExists(e.directory.Path(info.Name)); err == nil && exists && isDirectory { - e.MainEngine.Set(e.loadEngineInstanceFromSnapshot(info.Name, snapshotPath)) + e.Main.Set(e.loadEngineInstanceFromSnapshot(info.Name, snapshotPath)) } } // load new engine if no previous engine exists. - e.MainEngine.Compute(func(mainEngine *engine.Engine) *engine.Engine { + e.Main.Compute(func(mainEngine *engine.Engine) *engine.Engine { if mainEngine != nil { return mainEngine } @@ -90,19 +90,19 @@ func (e *EngineManager) LoadMainEngine(snapshotPath string) (*engine.Engine, err return nil, err } - return e.MainEngine.Get(), nil + return e.Main.Get(), nil } -func (e *EngineManager) ForkAtSlot(slot iotago.SlotIndex) (*engine.Engine, error) { +func (e *Engines) ForkAtSlot(slot iotago.SlotIndex) (*engine.Engine, error) { newEngineAlias := lo.PanicOnErr(uuid.NewUUID()).String() errorHandler := func(err error) { e.protocol.LogError("engine error", "err", err, "name", newEngineAlias[0:8]) } // copy raw data on disk. - newStorage, err := storage.Clone(e.MainEngine.Get().Storage, e.directory.Path(newEngineAlias), DatabaseVersion, errorHandler, e.protocol.Options.StorageOptions...) + newStorage, err := storage.Clone(e.Main.Get().Storage, e.directory.Path(newEngineAlias), DatabaseVersion, errorHandler, e.protocol.Options.StorageOptions...) if err != nil { - return nil, ierrors.Wrapf(err, "failed to copy storage from active engine instance (%s) to new engine instance (%s)", e.MainEngine.Get().Storage.Directory(), e.directory.Path(newEngineAlias)) + return nil, ierrors.Wrapf(err, "failed to copy storage from active engine instance (%s) to new engine instance (%s)", e.Main.Get().Storage.Directory(), e.directory.Path(newEngineAlias)) } // remove commitments that after forking point. @@ -152,8 +152,8 @@ func (e *EngineManager) ForkAtSlot(slot iotago.SlotIndex) (*engine.Engine, error return candidateEngine, nil } -func (e *EngineManager) CleanupCandidates() error { - activeDir := filepath.Base(e.MainEngine.Get().Storage.Directory()) +func (e *Engines) CleanupCandidates() error { + activeDir := filepath.Base(e.Main.Get().Storage.Directory()) dirs, err := e.directory.SubDirs() if err != nil { @@ -171,11 +171,11 @@ func (e *EngineManager) CleanupCandidates() error { return nil } -func (e *EngineManager) infoFilePath() string { +func (e *Engines) infoFilePath() string { return e.directory.Path(engineInfoFile) } -func (e *EngineManager) loadEngineInstanceFromSnapshot(engineAlias string, snapshotPath string) *engine.Engine { +func (e *Engines) loadEngineInstanceFromSnapshot(engineAlias string, snapshotPath string) *engine.Engine { errorHandler := func(err error) { e.protocol.LogError("engine error", "err", err, "name", engineAlias[0:8]) } @@ -185,20 +185,20 @@ func (e *EngineManager) loadEngineInstanceFromSnapshot(engineAlias string, snaps return e.loadEngineInstanceWithStorage(engineAlias, storage.Create(e.directory.Path(engineAlias), DatabaseVersion, errorHandler, e.protocol.Options.StorageOptions...)) } -func (e *EngineManager) loadEngineInstanceWithStorage(engineAlias string, storage *storage.Storage) *engine.Engine { +func (e *Engines) loadEngineInstanceWithStorage(engineAlias string, storage *storage.Storage) *engine.Engine { return engine.New(e.protocol.Logger, e.protocol.Workers.CreateGroup(engineAlias), storage, e.protocol.Options.FilterProvider, e.protocol.Options.CommitmentFilterProvider, e.protocol.Options.BlockDAGProvider, e.protocol.Options.BookerProvider, e.protocol.Options.ClockProvider, e.protocol.Options.BlockGadgetProvider, e.protocol.Options.SlotGadgetProvider, e.protocol.Options.SybilProtectionProvider, e.protocol.Options.NotarizationProvider, e.protocol.Options.AttestationProvider, e.protocol.Options.LedgerProvider, e.protocol.Options.SchedulerProvider, e.protocol.Options.TipManagerProvider, e.protocol.Options.TipSelectionProvider, e.protocol.Options.RetainerProvider, e.protocol.Options.UpgradeOrchestratorProvider, e.protocol.Options.SyncManagerProvider, e.protocol.Options.EngineOptions...) } -func (e *EngineManager) syncMainEngineFromMainChain() (unsubscribe func()) { +func (e *Engines) syncMainEngineFromMainChain() (unsubscribe func()) { return e.protocol.MainChain.OnUpdateWithContext(func(_, mainChain *Chain, unsubscribeOnUpdate func(subscriptionFactory func() (unsubscribe func()))) { unsubscribeOnUpdate(func() func() { - return e.MainEngine.InheritFrom(mainChain.SpawnedEngine) + return e.Main.InheritFrom(mainChain.SpawnedEngine) }) }) } -func (e *EngineManager) syncMainEngineInfoFile() (unsubscribe func()) { - return e.MainEngine.OnUpdate(func(_, mainEngine *engine.Engine) { +func (e *Engines) syncMainEngineInfoFile() (unsubscribe func()) { + return e.Main.OnUpdate(func(_, mainEngine *engine.Engine) { if mainEngine != nil { if err := ioutils.WriteJSONToFile(e.infoFilePath(), &engineInfo{Name: filepath.Base(mainEngine.Storage.Directory())}, 0o644); err != nil { e.LogError("unable to write engine info file", "err", err) @@ -207,7 +207,7 @@ func (e *EngineManager) syncMainEngineInfoFile() (unsubscribe func()) { }) } -func (e *EngineManager) injectEngineInstances() (unsubscribe func()) { +func (e *Engines) injectEngineInstances() (unsubscribe func()) { return e.protocol.OnChainCreated(func(chain *Chain) { chain.VerifyState.OnUpdate(func(_, instantiate bool) { e.worker.Submit(func() { @@ -218,7 +218,7 @@ func (e *EngineManager) injectEngineInstances() (unsubscribe func()) { } if newEngine, err := func() (*engine.Engine, error) { - if e.MainEngine.Get() == nil { + if e.Main.Get() == nil { return e.LoadMainEngine(e.protocol.Options.SnapshotPath) } diff --git a/pkg/protocol/protocol.go b/pkg/protocol/protocol.go index e0f1546c8..818d99773 100644 --- a/pkg/protocol/protocol.go +++ b/pkg/protocol/protocol.go @@ -27,10 +27,10 @@ type Protocol struct { CommitmentsProtocol *CommitmentsProtocol AttestationsProtocol *AttestationsProtocol WarpSyncProtocol *WarpSyncProtocol + Engines *Engines Options *Options *ChainManager - *EngineManager *APIProvider *module.ReactiveModule @@ -51,7 +51,7 @@ func New(logger log.Logger, workers *workerpool.Group, networkEndpoint network.E p.AttestationsProtocol = NewAttestationsProtocol(p) p.WarpSyncProtocol = NewWarpSyncProtocol(p) p.ChainManager = newChainManager(p) - p.EngineManager = NewEngineManager(p) + p.Engines = NewEngines(p) p.APIProvider = NewAPIProvider(p) p.Initialized.OnTrigger(func() { @@ -75,7 +75,7 @@ func New(logger log.Logger, workers *workerpool.Group, networkEndpoint network.E p.AttestationsProtocol.Shutdown() p.WarpSyncProtocol.Shutdown() p.Network.Shutdown() - p.EngineManager.Shutdown.Trigger() + p.Engines.Shutdown.Trigger() }) }) @@ -109,7 +109,7 @@ func (p *Protocol) waitEngineInitialized() { var waitInitialized sync.WaitGroup waitInitialized.Add(1) - p.MainEngine.OnUpdateOnce(func(_, engine *engine.Engine) { + p.Engines.Main.OnUpdateOnce(func(_, engine *engine.Engine) { engine.Initialized.OnTrigger(waitInitialized.Done) }) waitInitialized.Wait() diff --git a/pkg/protocol/protocol_blocks.go b/pkg/protocol/protocol_blocks.go index aa737cfcd..c22372363 100644 --- a/pkg/protocol/protocol_blocks.go +++ b/pkg/protocol/protocol_blocks.go @@ -121,7 +121,7 @@ func (b *BlocksProtocol) ProcessResponse(block *model.Block, from peer.ID) { func (b *BlocksProtocol) ProcessRequest(blockID iotago.BlockID, from peer.ID) { b.workerPool.Submit(func() { - block, exists := b.protocol.MainEngine.Get().Block(blockID) + block, exists := b.protocol.Engines.Main.Get().Block(blockID) if !exists { b.LogTrace("requested block not found", "blockID", blockID) diff --git a/pkg/tests/accounts_test.go b/pkg/tests/accounts_test.go index 0e8bff975..5fcc87483 100644 --- a/pkg/tests/accounts_test.go +++ b/pkg/tests/accounts_test.go @@ -78,7 +78,7 @@ func Test_TransitionAccount(t *testing.T) { newGenesisOutputKey := utils.RandBlockIssuerKey() newAccountBlockIssuerKey := utils.RandBlockIssuerKey() - latestCommitmentID := node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment().MustID() + latestCommitmentID := node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment().MustID() accountInput, accountOutputs, accountWallets := ts.TransactionFramework.TransitionAccount( "Genesis:1", @@ -137,7 +137,7 @@ func Test_TransitionAccount(t *testing.T) { // commit until the expiry slot of the transitioned genesis account plus one latestParent = ts.CommitUntilSlot(accountOutputs[0].FeatureSet().BlockIssuer().ExpirySlot+1, latestParent) // set the expiry slof of the transitioned genesis account to the latest committed + MaxCommittableAge - newAccountExpirySlot := node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Slot() + ts.API.ProtocolParameters().MaxCommittableAge() + newAccountExpirySlot := node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot() + ts.API.ProtocolParameters().MaxCommittableAge() inputForNewAccount, newAccountOutputs, newAccountWallets := ts.TransactionFramework.CreateAccountFromInput("TX1:1", testsuite.WithAccountConditions(iotago.AccountOutputUnlockConditions{ &iotago.StateControllerAddressUnlockCondition{Address: ts.TransactionFramework.DefaultAddress()}, @@ -157,7 +157,7 @@ func Test_TransitionAccount(t *testing.T) { AccountID: genesisAccountOutput.AccountID, }, &iotago.CommitmentInput{ - CommitmentID: node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment().MustID(), + CommitmentID: node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment().MustID(), }, }), testsuite.WithInputs(inputForNewAccount), @@ -166,7 +166,7 @@ func Test_TransitionAccount(t *testing.T) { testsuite.WithSlotCreated(block2Slot), )) - block2 := ts.IssueBasicBlockAtSlotWithOptions("block2", block2Slot, node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment(), blockIssuer, node1, tx2, mock.WithStrongParents(latestParent.ID())) + block2 := ts.IssueBasicBlockAtSlotWithOptions("block2", block2Slot, node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment(), blockIssuer, node1, tx2, mock.WithStrongParents(latestParent.ID())) latestParent = ts.CommitUntilSlot(block2Slot, block2) @@ -228,7 +228,7 @@ func Test_TransitionAccount(t *testing.T) { tx3 := lo.PanicOnErr(ts.TransactionFramework.CreateSignedTransactionWithOptions("TX3", newDelegationWallets, testsuite.WithContextInputs(iotago.TxEssenceContextInputs{ &iotago.CommitmentInput{ - CommitmentID: node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment().MustID(), + CommitmentID: node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment().MustID(), }, }), testsuite.WithInputs(inputForNewDelegation), @@ -236,7 +236,7 @@ func Test_TransitionAccount(t *testing.T) { testsuite.WithSlotCreated(block3Slot), )) - block3 := ts.IssueBasicBlockAtSlotWithOptions("block3", block3Slot, node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment(), blockIssuer, node1, tx3, mock.WithStrongParents(latestParent.ID())) + block3 := ts.IssueBasicBlockAtSlotWithOptions("block3", block3Slot, node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment(), blockIssuer, node1, tx3, mock.WithStrongParents(latestParent.ID())) latestParent = ts.CommitUntilSlot(block3Slot, block3) delegatedAmount := inputForNewDelegation[0].BaseTokenAmount() @@ -272,7 +272,7 @@ func Test_TransitionAccount(t *testing.T) { tx4 := lo.PanicOnErr(ts.TransactionFramework.CreateSignedTransactionWithOptions("TX4", delegationTransitionWallets, testsuite.WithContextInputs(iotago.TxEssenceContextInputs{ &iotago.CommitmentInput{ - CommitmentID: node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment().MustID(), + CommitmentID: node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment().MustID(), }, }), testsuite.WithInputs(inputForDelegationTransition), @@ -282,7 +282,7 @@ func Test_TransitionAccount(t *testing.T) { block4Slot := latestParent.ID().Slot() - block4 := ts.IssueBasicBlockAtSlotWithOptions("block4", block4Slot, node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment(), blockIssuer, node1, tx4, mock.WithStrongParents(latestParent.ID())) + block4 := ts.IssueBasicBlockAtSlotWithOptions("block4", block4Slot, node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment(), blockIssuer, node1, tx4, mock.WithStrongParents(latestParent.ID())) latestParent = ts.CommitUntilSlot(block4Slot, block4) @@ -326,7 +326,7 @@ func Test_TransitionAccount(t *testing.T) { slotIndexBlock5 := latestParent.ID().Index() - block5 := ts.IssueBasicBlockAtSlotWithOptions("block5", slotIndexBlock5, node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment(), blockIssuer, node1, tx5, mock.WithStrongParents(latestParent.ID())) + block5 := ts.IssueBasicBlockAtSlotWithOptions("block5", slotIndexBlock5, node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment(), blockIssuer, node1, tx5, mock.WithStrongParents(latestParent.ID())) latestParent = ts.CommitUntilSlot(slotIndexBlock5, block5) @@ -358,7 +358,7 @@ func Test_TransitionAccount(t *testing.T) { AccountID: implicitAccountID, }, &iotago.CommitmentInput{ - CommitmentID: node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment().MustID(), + CommitmentID: node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment().MustID(), }, }), testsuite.WithInputs(inputForImplicitAccountTransition), @@ -368,7 +368,7 @@ func Test_TransitionAccount(t *testing.T) { slotIndexBlock6 := latestParent.ID().Index() - block6 := ts.IssueBasicBlockAtSlotWithOptions("block6", slotIndexBlock6, node1.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment(), blockIssuer, node1, tx6, mock.WithStrongParents(latestParent.ID())) + block6 := ts.IssueBasicBlockAtSlotWithOptions("block6", slotIndexBlock6, node1.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment(), blockIssuer, node1, tx6, mock.WithStrongParents(latestParent.ID())) latestParent = ts.CommitUntilSlot(slotIndexBlock6, block6) diff --git a/pkg/tests/booker_test.go b/pkg/tests/booker_test.go index 4c133139f..62b70f623 100644 --- a/pkg/tests/booker_test.go +++ b/pkg/tests/booker_test.go @@ -257,7 +257,7 @@ func Test_SpendRejectedCommittedRace(t *testing.T) { node2.Validator.AccountID, }, ts.Nodes()...) - genesisCommitment := lo.PanicOnErr(node1.Protocol.MainEngine.Get().Storage.Commitments().Load(0)).Commitment() + genesisCommitment := lo.PanicOnErr(node1.Protocol.Engines.Main.Get().Storage.Commitments().Load(0)).Commitment() // Create and issue double spends { @@ -362,7 +362,7 @@ func Test_SpendRejectedCommittedRace(t *testing.T) { ) } - commitment1 := lo.PanicOnErr(node2.Protocol.MainEngine.Get().Storage.Commitments().Load(1)).Commitment() + commitment1 := lo.PanicOnErr(node2.Protocol.Engines.Main.Get().Storage.Commitments().Load(1)).Commitment() // This should be booked on the rejected tx1 conflict tx4 := lo.PanicOnErr(ts.TransactionFramework.CreateSimpleTransaction("tx4", 1, "tx1:0")) @@ -520,7 +520,7 @@ func Test_SpendPendingCommittedRace(t *testing.T) { node2.Validator.AccountID, }, ts.Nodes()...) - genesisCommitment := lo.PanicOnErr(node1.Protocol.MainEngine.Get().Storage.Commitments().Load(0)).Commitment() + genesisCommitment := lo.PanicOnErr(node1.Protocol.Engines.Main.Get().Storage.Commitments().Load(0)).Commitment() // Create and issue double spends { @@ -601,7 +601,7 @@ func Test_SpendPendingCommittedRace(t *testing.T) { ) } - commitment1 := lo.PanicOnErr(node2.Protocol.MainEngine.Get().Storage.Commitments().Load(1)).Commitment() + commitment1 := lo.PanicOnErr(node2.Protocol.Engines.Main.Get().Storage.Commitments().Load(1)).Commitment() // Issue a block booked on a pending conflict on node2 { diff --git a/pkg/tests/confirmation_state_test.go b/pkg/tests/confirmation_state_test.go index 2099fbfb8..b97c4b549 100644 --- a/pkg/tests/confirmation_state_test.go +++ b/pkg/tests/confirmation_state_test.go @@ -108,7 +108,7 @@ func TestConfirmationFlags(t *testing.T) { testsuite.WithChainID(genesisCommitment.MustID()), testsuite.WithStorageCommitments([]*iotago.Commitment{genesisCommitment}), testsuite.WithSybilProtectionCommittee(0, expectedCommittee), - testsuite.WithSybilProtectionOnlineCommittee(lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID))), + testsuite.WithSybilProtectionOnlineCommittee(lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID))), testsuite.WithEvictedSlot(0), testsuite.WithActiveRootBlocks(ts.Blocks("Genesis")), testsuite.WithStorageRootBlocks(ts.Blocks("Genesis")), @@ -145,7 +145,7 @@ func TestConfirmationFlags(t *testing.T) { // Issue in the next slot so that slot 2 becomes committed. - slot1Commitment := lo.PanicOnErr(nodeA.Protocol.MainEngine.Get().Storage.Commitments().Load(1)).Commitment() + slot1Commitment := lo.PanicOnErr(nodeA.Protocol.Engines.Main.Get().Storage.Commitments().Load(1)).Commitment() slot2CommittableSlot := slot1CommittableSlot + 1 alias2A0 := fmt.Sprintf("A.%d.0", slot2CommittableSlot) alias2A1 := fmt.Sprintf("A.%d.1", slot2CommittableSlot) @@ -165,15 +165,15 @@ func TestConfirmationFlags(t *testing.T) { testsuite.WithEqualStoredCommitmentAtIndex(2), testsuite.WithSybilProtectionCommittee(slot2CommittableSlot, expectedCommittee), testsuite.WithSybilProtectionOnlineCommittee( - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID)), - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeB.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeB.Validator.AccountID)), ), testsuite.WithEvictedSlot(2), ) // Confirm aliasA0 by pre-confirming a block a 3rd validator in the next slot. - slot2Commitment := lo.PanicOnErr(nodeA.Protocol.MainEngine.Get().Storage.Commitments().Load(2)).Commitment() + slot2Commitment := lo.PanicOnErr(nodeA.Protocol.Engines.Main.Get().Storage.Commitments().Load(2)).Commitment() slot3CommittableSlot := slot2CommittableSlot + 1 alias3C0 := fmt.Sprintf("C.%d.0", slot3CommittableSlot) @@ -205,9 +205,9 @@ func TestConfirmationFlags(t *testing.T) { testsuite.WithEqualStoredCommitmentAtIndex(2), testsuite.WithSybilProtectionCommittee(slot3CommittableSlot, expectedCommittee), testsuite.WithSybilProtectionOnlineCommittee( - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID)), - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeB.Validator.AccountID)), - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeC.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeB.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeC.Validator.AccountID)), ), testsuite.WithEvictedSlot(2), ) @@ -260,9 +260,9 @@ func TestConfirmationFlags(t *testing.T) { testsuite.WithEqualStoredCommitmentAtIndex(3), testsuite.WithSybilProtectionCommittee(slot4CommittableSlot, expectedCommittee), testsuite.WithSybilProtectionOnlineCommittee( - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID)), - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeB.Validator.AccountID)), - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeC.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeB.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeC.Validator.AccountID)), ), testsuite.WithEvictedSlot(3), ) diff --git a/pkg/tests/loss_of_acceptance_test.go b/pkg/tests/loss_of_acceptance_test.go index ccc788eed..7a078023e 100644 --- a/pkg/tests/loss_of_acceptance_test.go +++ b/pkg/tests/loss_of_acceptance_test.go @@ -46,7 +46,7 @@ func TestLossOfAcceptanceFromGenesis(t *testing.T) { // Create snapshot to use later. snapshotPath := ts.Directory.Path(fmt.Sprintf("%d_snapshot", time.Now().Unix())) - require.NoError(t, ts.Node("node0").Protocol.MainEngine.Get().WriteSnapshot(snapshotPath)) + require.NoError(t, ts.Node("node0").Protocol.Engines.Main.Get().WriteSnapshot(snapshotPath)) // Revive chain on node0. { @@ -147,7 +147,7 @@ func TestLossOfAcceptanceFromSnapshot(t *testing.T) { var node0restarted *mock.Node { snapshotPath := ts.Directory.Path(fmt.Sprintf("%d_snapshot", time.Now().Unix())) - require.NoError(t, ts.Node("node0").Protocol.MainEngine.Get().WriteSnapshot(snapshotPath)) + require.NoError(t, ts.Node("node0").Protocol.Engines.Main.Get().WriteSnapshot(snapshotPath)) node0restarted = ts.AddNode("node0-restarted") node0restarted.Validator = node0.Validator diff --git a/pkg/tests/protocol_engine_rollback_test.go b/pkg/tests/protocol_engine_rollback_test.go index fc273918b..c7647fde4 100644 --- a/pkg/tests/protocol_engine_rollback_test.go +++ b/pkg/tests/protocol_engine_rollback_test.go @@ -98,14 +98,14 @@ func TestProtocol_EngineRollbackFinalization(t *testing.T) { node3.Validator.AccountID, } expectedOnlineCommitteeFull := []account.SeatIndex{ - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node2.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node3.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node2.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node3.Validator.AccountID)), } for _, node := range ts.Nodes() { - node.Protocol.MainEngine.Get().SybilProtection.SeatManager().(*mock2.ManualPOA).SetOnline("node0", "node1", "node2", "node3") + node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().(*mock2.ManualPOA).SetOnline("node0", "node1", "node2", "node3") } { @@ -171,7 +171,7 @@ func TestProtocol_EngineRollbackFinalization(t *testing.T) { ts.AssertBlocksExist(ts.BlocksWithPrefix("P0"), true, ts.Nodes()...) } - newEngine, err := node3.Protocol.EngineManager.ForkAtSlot(13) + newEngine, err := node3.Protocol.Engines.ForkAtSlot(13) require.NoError(t, err) // Assert state of the forked engine after rollback. @@ -194,7 +194,7 @@ func TestProtocol_EngineRollbackFinalization(t *testing.T) { for slot := 1; slot <= 13; slot++ { copiedCommitment, err := newEngine.Storage.Commitments().Load(iotago.SlotIndex(slot)) require.NoError(t, err) - sourceCommitment, err := node1.Protocol.MainEngine.Get().Storage.Commitments().Load(iotago.SlotIndex(slot)) + sourceCommitment, err := node1.Protocol.Engines.Main.Get().Storage.Commitments().Load(iotago.SlotIndex(slot)) require.NoError(t, err) require.Equal(t, sourceCommitment.ID(), copiedCommitment.ID()) } @@ -279,19 +279,19 @@ func TestProtocol_EngineRollbackNoFinalization(t *testing.T) { node3.Validator.AccountID, } expectedOnlineCommitteeFull := []account.SeatIndex{ - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node2.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node3.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node2.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node3.Validator.AccountID)), } expectedOnlineCommitteeHalf := []account.SeatIndex{ - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), } for _, node := range ts.Nodes() { - node.Protocol.MainEngine.Get().SybilProtection.SeatManager().(*mock2.ManualPOA).SetOnline("node0", "node1", "node2", "node3") + node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().(*mock2.ManualPOA).SetOnline("node0", "node1", "node2", "node3") } { @@ -343,7 +343,7 @@ func TestProtocol_EngineRollbackNoFinalization(t *testing.T) { // Update online committee. for _, node := range ts.Nodes() { - manualPOA := node.Protocol.MainEngine.Get().SybilProtection.SeatManager().(*mock2.ManualPOA) + manualPOA := node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().(*mock2.ManualPOA) manualPOA.SetOnline("node0", "node1") manualPOA.SetOffline("node2", "node3") } @@ -364,7 +364,7 @@ func TestProtocol_EngineRollbackNoFinalization(t *testing.T) { ts.AssertBlocksExist(ts.BlocksWithPrefix("P0"), true, ts.Nodes()...) } - newEngine, err := node3.Protocol.EngineManager.ForkAtSlot(13) + newEngine, err := node3.Protocol.Engines.ForkAtSlot(13) require.NoError(t, err) // Assert state of the forked engine after rollback. @@ -387,7 +387,7 @@ func TestProtocol_EngineRollbackNoFinalization(t *testing.T) { for slot := 1; slot <= 13; slot++ { copiedCommitment, err := newEngine.Storage.Commitments().Load(iotago.SlotIndex(slot)) require.NoError(t, err) - sourceCommitment, err := node1.Protocol.MainEngine.Get().Storage.Commitments().Load(iotago.SlotIndex(slot)) + sourceCommitment, err := node1.Protocol.Engines.Main.Get().Storage.Commitments().Load(iotago.SlotIndex(slot)) require.NoError(t, err) require.Equal(t, sourceCommitment.ID(), copiedCommitment.ID()) } @@ -472,19 +472,19 @@ func TestProtocol_EngineRollbackNoFinalizationLastSlot(t *testing.T) { node3.Validator.AccountID, } expectedOnlineCommitteeFull := []account.SeatIndex{ - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node2.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node3.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node2.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node3.Validator.AccountID)), } expectedOnlineCommitteeHalf := []account.SeatIndex{ - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), } for _, node := range ts.Nodes() { - node.Protocol.MainEngine.Get().SybilProtection.SeatManager().(*mock2.ManualPOA).SetOnline("node0", "node1", "node2", "node3") + node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().(*mock2.ManualPOA).SetOnline("node0", "node1", "node2", "node3") } { @@ -536,7 +536,7 @@ func TestProtocol_EngineRollbackNoFinalizationLastSlot(t *testing.T) { // Update online committee. for _, node := range ts.Nodes() { - manualPOA := node.Protocol.MainEngine.Get().SybilProtection.SeatManager().(*mock2.ManualPOA) + manualPOA := node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().(*mock2.ManualPOA) manualPOA.SetOnline("node0", "node1") manualPOA.SetOffline("node2", "node3") } @@ -557,7 +557,7 @@ func TestProtocol_EngineRollbackNoFinalizationLastSlot(t *testing.T) { ts.AssertBlocksExist(ts.BlocksWithPrefix("P0"), true, ts.Nodes()...) } - newEngine, err := node3.Protocol.EngineManager.ForkAtSlot(15) + newEngine, err := node3.Protocol.Engines.ForkAtSlot(15) require.NoError(t, err) // Assert state of the forked engine after rollback. @@ -580,7 +580,7 @@ func TestProtocol_EngineRollbackNoFinalizationLastSlot(t *testing.T) { for slot := 1; slot <= 15; slot++ { copiedCommitment, err := newEngine.Storage.Commitments().Load(iotago.SlotIndex(slot)) require.NoError(t, err) - sourceCommitment, err := node1.Protocol.MainEngine.Get().Storage.Commitments().Load(iotago.SlotIndex(slot)) + sourceCommitment, err := node1.Protocol.Engines.Main.Get().Storage.Commitments().Load(iotago.SlotIndex(slot)) require.NoError(t, err) require.Equal(t, sourceCommitment.ID(), copiedCommitment.ID()) } @@ -665,19 +665,19 @@ func TestProtocol_EngineRollbackNoFinalizationBeforePointOfNoReturn(t *testing.T node3.Validator.AccountID, } expectedOnlineCommitteeFull := []account.SeatIndex{ - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node2.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node3.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node2.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node3.Validator.AccountID)), } expectedOnlineCommitteeHalf := []account.SeatIndex{ - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), } for _, node := range ts.Nodes() { - node.Protocol.MainEngine.Get().SybilProtection.SeatManager().(*mock2.ManualPOA).SetOnline("node0", "node1", "node2", "node3") + node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().(*mock2.ManualPOA).SetOnline("node0", "node1", "node2", "node3") } { @@ -729,7 +729,7 @@ func TestProtocol_EngineRollbackNoFinalizationBeforePointOfNoReturn(t *testing.T // Update online committee. for _, node := range ts.Nodes() { - manualPOA := node.Protocol.MainEngine.Get().SybilProtection.SeatManager().(*mock2.ManualPOA) + manualPOA := node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().(*mock2.ManualPOA) manualPOA.SetOnline("node0", "node1") manualPOA.SetOffline("node2", "node3") } @@ -750,7 +750,7 @@ func TestProtocol_EngineRollbackNoFinalizationBeforePointOfNoReturn(t *testing.T ts.AssertBlocksExist(ts.BlocksWithPrefix("P0"), true, ts.Nodes()...) } - newEngine, err := node3.Protocol.EngineManager.ForkAtSlot(9) + newEngine, err := node3.Protocol.Engines.ForkAtSlot(9) require.NoError(t, err) // Assert state of the forked engine after rollback. @@ -773,7 +773,7 @@ func TestProtocol_EngineRollbackNoFinalizationBeforePointOfNoReturn(t *testing.T for slot := 1; slot <= 9; slot++ { copiedCommitment, err := newEngine.Storage.Commitments().Load(iotago.SlotIndex(slot)) require.NoError(t, err) - sourceCommitment, err := node1.Protocol.MainEngine.Get().Storage.Commitments().Load(iotago.SlotIndex(slot)) + sourceCommitment, err := node1.Protocol.Engines.Main.Get().Storage.Commitments().Load(iotago.SlotIndex(slot)) require.NoError(t, err) require.Equal(t, sourceCommitment.ID(), copiedCommitment.ID()) } diff --git a/pkg/tests/protocol_engine_switching_test.go b/pkg/tests/protocol_engine_switching_test.go index d9538571a..c811207d2 100644 --- a/pkg/tests/protocol_engine_switching_test.go +++ b/pkg/tests/protocol_engine_switching_test.go @@ -128,20 +128,20 @@ func TestProtocol_EngineSwitching(t *testing.T) { node7.Validator.AccountID, } expectedP1OnlineCommittee := []account.SeatIndex{ - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node2.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node3.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node4.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node0.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node1.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node2.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node3.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node4.Validator.AccountID)), } expectedP2OnlineCommittee := []account.SeatIndex{ - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node6.Validator.AccountID)), - lo.Return1(node0.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node7.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node6.Validator.AccountID)), + lo.Return1(node0.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(node7.Validator.AccountID)), } expectedOnlineCommittee := append(expectedP1OnlineCommittee, expectedP2OnlineCommittee...) for _, node := range ts.Nodes() { - node.Protocol.MainEngine.Get().SybilProtection.SeatManager().(*mock2.ManualPOA).SetOnline("node0", "node1", "node2", "node3", "node4", "node6", "node7") + node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().(*mock2.ManualPOA).SetOnline("node0", "node1", "node2", "node3", "node4", "node6", "node7") } // Verify that nodes have the expected states. @@ -207,7 +207,7 @@ func TestProtocol_EngineSwitching(t *testing.T) { // Set online committee for each partition. for _, node := range ts.Nodes() { - manualPOA := node.Protocol.MainEngine.Get().SybilProtection.SeatManager().(*mock2.ManualPOA) + manualPOA := node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().(*mock2.ManualPOA) if node.Partition == "P1" { manualPOA.SetOnline("node0", "node1", "node2", "node3", "node4") manualPOA.SetOffline("node6", "node7") @@ -329,7 +329,7 @@ func TestProtocol_EngineSwitching(t *testing.T) { } for _, node := range ts.Nodes() { - manualPOA := node.Protocol.MainEngine.Get().SybilProtection.SeatManager().(*mock2.ManualPOA) + manualPOA := node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().(*mock2.ManualPOA) manualPOA.SetOnline("node0", "node1", "node2", "node3", "node4", "node6", "node7") } // Merge the partitions diff --git a/pkg/tests/protocol_startup_test.go b/pkg/tests/protocol_startup_test.go index f54f55fe1..c6a6bbf66 100644 --- a/pkg/tests/protocol_startup_test.go +++ b/pkg/tests/protocol_startup_test.go @@ -58,7 +58,7 @@ func Test_BookInCommittedSlot(t *testing.T) { } expectedOnlineCommittee := []account.SeatIndex{ - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID)), } // Verify that nodes have the expected states. @@ -113,7 +113,7 @@ func Test_BookInCommittedSlot(t *testing.T) { }) ts.AssertAttestationsForSlot(slot, ts.Blocks(aliases...), ts.Nodes()...) } - ts.IssueValidationBlockAtSlot("5*", 5, lo.PanicOnErr(nodeA.Protocol.MainEngine.Get().Storage.Commitments().Load(3)).Commitment(), ts.Node("nodeA"), ts.BlockIDsWithPrefix("4.3-")...) + ts.IssueValidationBlockAtSlot("5*", 5, lo.PanicOnErr(nodeA.Protocol.Engines.Main.Get().Storage.Commitments().Load(3)).Commitment(), ts.Node("nodeA"), ts.BlockIDsWithPrefix("4.3-")...) ts.AssertBlocksExist(ts.Blocks("5*"), false, ts.Nodes("nodeA")...) } @@ -168,8 +168,8 @@ func Test_StartNodeFromSnapshotAndDisk(t *testing.T) { } expectedOnlineCommittee := []account.SeatIndex{ - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID)), - lo.Return1(nodeA.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeB.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeA.Validator.AccountID)), + lo.Return1(nodeA.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(1).GetSeat(nodeB.Validator.AccountID)), } // Verify that nodes have the expected states. @@ -323,7 +323,7 @@ func Test_StartNodeFromSnapshotAndDisk(t *testing.T) { { // Create snapshot. snapshotPath := ts.Directory.Path(fmt.Sprintf("%d_snapshot", time.Now().Unix())) - require.NoError(t, ts.Node("nodeA").Protocol.MainEngine.Get().WriteSnapshot(snapshotPath)) + require.NoError(t, ts.Node("nodeA").Protocol.Engines.Main.Get().WriteSnapshot(snapshotPath)) nodeD := ts.AddNode("nodeD") nodeD.Initialize(true, append(nodeOptions, @@ -344,7 +344,7 @@ func Test_StartNodeFromSnapshotAndDisk(t *testing.T) { ts.AssertStorageRootBlocks(expectedStorageRootBlocksFrom9, ts.Nodes("nodeD")...) } - slot7Commitment := lo.PanicOnErr(nodeA.Protocol.MainEngine.Get().Storage.Commitments().Load(7)) + slot7Commitment := lo.PanicOnErr(nodeA.Protocol.Engines.Main.Get().Storage.Commitments().Load(7)) ts.AssertNodeState(ts.Nodes("nodeC-restarted", "nodeD"), testsuite.WithSnapshotImported(true), @@ -473,7 +473,7 @@ func Test_StartNodeFromSnapshotAndDisk(t *testing.T) { { // Create snapshot. snapshotPath := ts.Directory.Path(fmt.Sprintf("%d_snapshot", time.Now().Unix())) - require.NoError(t, ts.Node("nodeA").Protocol.MainEngine.Get().WriteSnapshot(snapshotPath)) + require.NoError(t, ts.Node("nodeA").Protocol.Engines.Main.Get().WriteSnapshot(snapshotPath)) nodeD := ts.AddNode("nodeE") nodeD.Initialize(true, append(nodeOptions, diff --git a/pkg/tests/upgrade_signaling_test.go b/pkg/tests/upgrade_signaling_test.go index 044f4d8a0..b2e65976c 100644 --- a/pkg/tests/upgrade_signaling_test.go +++ b/pkg/tests/upgrade_signaling_test.go @@ -204,7 +204,7 @@ func Test_Upgrade_Signaling(t *testing.T) { }, ts.Nodes()...) // check that rollback is correct - account, exists, err := ts.Node("nodeA").Protocol.MainEngine.Get().Ledger.Account(ts.Node("nodeA").Validator.AccountID, 7) + account, exists, err := ts.Node("nodeA").Protocol.Engines.Main.Get().Ledger.Account(ts.Node("nodeA").Validator.AccountID, 7) require.NoError(t, err) require.True(t, exists) require.Equal(t, model.VersionAndHash{Version: 4, Hash: hash2}, account.LatestSupportedProtocolVersionAndHash) @@ -252,7 +252,7 @@ func Test_Upgrade_Signaling(t *testing.T) { // Create snapshot. snapshotPath := ts.Directory.Path(fmt.Sprintf("%d_snapshot", time.Now().Unix())) - require.NoError(t, ts.Node("nodeA").Protocol.MainEngine.Get().WriteSnapshot(snapshotPath)) + require.NoError(t, ts.Node("nodeA").Protocol.Engines.Main.Get().WriteSnapshot(snapshotPath)) { nodeG := ts.AddNode("nodeG") @@ -311,7 +311,7 @@ func Test_Upgrade_Signaling(t *testing.T) { // Create snapshot and start new nodeH from it. { snapshotPath := ts.Directory.Path(fmt.Sprintf("%d_snapshot", time.Now().Unix())) - require.NoError(t, ts.Node("nodeE2").Protocol.MainEngine.Get().WriteSnapshot(snapshotPath)) + require.NoError(t, ts.Node("nodeE2").Protocol.Engines.Main.Get().WriteSnapshot(snapshotPath)) nodeG := ts.AddNode("nodeH") nodeG.Initialize(true, diff --git a/pkg/testsuite/accounts.go b/pkg/testsuite/accounts.go index 55407e902..6dfdef91f 100644 --- a/pkg/testsuite/accounts.go +++ b/pkg/testsuite/accounts.go @@ -13,12 +13,12 @@ import ( func (t *TestSuite) AssertAccountData(accountData *accounts.AccountData, nodes ...*mock.Node) { t.Eventually(func() error { for _, node := range nodes { - actualAccountData, exists, err := node.Protocol.MainEngine.Get().Ledger.Account(accountData.ID, node.Protocol.MainEngine.Get().SyncManager.LatestCommitment().Slot()) + actualAccountData, exists, err := node.Protocol.Engines.Main.Get().Ledger.Account(accountData.ID, node.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot()) if err != nil { return ierrors.Wrap(err, "AssertAccountData: failed to load account data") } if !exists { - return ierrors.Errorf("AssertAccountData: %s: account %s does not exist with latest committed slot %d", node.Name, accountData.ID, node.Protocol.MainEngine.Get().SyncManager.LatestCommitment().Slot()) + return ierrors.Errorf("AssertAccountData: %s: account %s does not exist with latest committed slot %d", node.Name, accountData.ID, node.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot()) } if accountData.ID != actualAccountData.ID { @@ -74,7 +74,7 @@ func (t *TestSuite) AssertAccountDiff(accountID iotago.AccountID, index iotago.S t.Eventually(func() error { for _, node := range nodes { - accountsDiffStorage, err := node.Protocol.MainEngine.Get().Storage.AccountDiffs(index) + accountsDiffStorage, err := node.Protocol.Engines.Main.Get().Storage.AccountDiffs(index) if err != nil { return ierrors.Wrapf(err, "AssertAccountDiff: %s: failed to load accounts diff for slot %d", node.Name, index) } diff --git a/pkg/testsuite/attestations.go b/pkg/testsuite/attestations.go index d4b72a9c7..54c87e6f8 100644 --- a/pkg/testsuite/attestations.go +++ b/pkg/testsuite/attestations.go @@ -23,7 +23,7 @@ func (t *TestSuite) AssertAttestationsForSlot(slot iotago.SlotIndex, blocks []*b for _, node := range nodes { t.Eventually(func() error { - attestationTree, err := node.Protocol.MainEngine.Get().Attestations.GetMap(slot) + attestationTree, err := node.Protocol.Engines.Main.Get().Attestations.GetMap(slot) if err != nil { return ierrors.Wrapf(err, "AssertAttestationsForSlot: %s: error loading attestation tree for slot %d", node.Name, slot) } diff --git a/pkg/testsuite/blocks.go b/pkg/testsuite/blocks.go index e00a499d1..3b77f6193 100644 --- a/pkg/testsuite/blocks.go +++ b/pkg/testsuite/blocks.go @@ -16,7 +16,7 @@ func (t *TestSuite) AssertBlock(block *blocks.Block, node *mock.Node) *model.Blo var loadedBlock *model.Block t.Eventually(func() error { var exists bool - loadedBlock, exists = node.Protocol.MainEngine.Get().Block(block.ID()) + loadedBlock, exists = node.Protocol.Engines.Main.Get().Block(block.ID()) if !exists { return ierrors.Errorf("AssertBlock: %s: block %s does not exist", node.Name, block.ID()) } @@ -47,7 +47,7 @@ func (t *TestSuite) AssertBlocksExist(blocks []*blocks.Block, expectedExist bool t.AssertBlock(block, node) } else { t.Eventually(func() error { - if lo.Return2(node.Protocol.MainEngine.Get().Block(block.ID())) { + if lo.Return2(node.Protocol.Engines.Main.Get().Block(block.ID())) { return ierrors.Errorf("AssertBlocksExist: %s: block %s exists but should not", node.Name, block) } @@ -64,7 +64,7 @@ func (t *TestSuite) assertBlocksInCacheWithFunc(expectedBlocks []*blocks.Block, for _, node := range nodes { for _, block := range expectedBlocks { t.Eventually(func() error { - blockFromCache, exists := node.Protocol.MainEngine.Get().BlockFromCache(block.ID()) + blockFromCache, exists := node.Protocol.Engines.Main.Get().BlockFromCache(block.ID()) if !exists { return ierrors.Errorf("assertBlocksInCacheWithFunc[%s]: %s: block %s does not exist", propertyName, node.Name, block.ID()) } @@ -121,7 +121,7 @@ func (t *TestSuite) AssertBlocksInCacheConflicts(blockConflicts map[*blocks.Bloc for _, node := range nodes { for block, conflictAliases := range blockConflicts { t.Eventually(func() error { - blockFromCache, exists := node.Protocol.MainEngine.Get().BlockFromCache(block.ID()) + blockFromCache, exists := node.Protocol.Engines.Main.Get().BlockFromCache(block.ID()) if !exists { return ierrors.Errorf("AssertBlocksInCacheConflicts: %s: block %s does not exist", node.Name, block.ID()) } diff --git a/pkg/testsuite/chainmanager.go b/pkg/testsuite/chainmanager.go index b2e42b3cb..6db00d9ed 100644 --- a/pkg/testsuite/chainmanager.go +++ b/pkg/testsuite/chainmanager.go @@ -16,7 +16,7 @@ func (t *TestSuite) AssertChainManagerIsSolid(nodes ...*mock.Node) { } latestChainCommitment := chain.LatestCommitment.Get() - latestCommitment := node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment() + latestCommitment := node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment() if latestCommitment.ID() != latestChainCommitment.ID() { return ierrors.Errorf("AssertChainManagerIsSolid: %s: latest commitment is not equal, expected %s, got %s", node.Name, latestCommitment.ID(), latestChainCommitment.ID()) diff --git a/pkg/testsuite/conflicts.go b/pkg/testsuite/conflicts.go index f191b0017..5a996cfc0 100644 --- a/pkg/testsuite/conflicts.go +++ b/pkg/testsuite/conflicts.go @@ -13,7 +13,7 @@ func (t *TestSuite) AssertConflictsInCacheAcceptanceState(expectedConflictAliase for _, node := range nodes { for _, conflictAlias := range expectedConflictAliases { t.Eventually(func() error { - acceptanceState := node.Protocol.MainEngine.Get().Ledger.ConflictDAG().AcceptanceState(ds.NewSet(t.TransactionFramework.TransactionID(conflictAlias))) + acceptanceState := node.Protocol.Engines.Main.Get().Ledger.ConflictDAG().AcceptanceState(ds.NewSet(t.TransactionFramework.TransactionID(conflictAlias))) if acceptanceState != expectedState { return ierrors.Errorf("assertTransactionsInCacheWithFunc: %s: conflict %s is %s, but expected %s", node.Name, conflictAlias, acceptanceState, expectedState) diff --git a/pkg/testsuite/eviction.go b/pkg/testsuite/eviction.go index 0893e5c76..8b9500a1b 100644 --- a/pkg/testsuite/eviction.go +++ b/pkg/testsuite/eviction.go @@ -20,7 +20,7 @@ func (t *TestSuite) AssertActiveRootBlocks(expectedBlocks []*blocks.Block, nodes for _, node := range nodes { t.Eventually(func() error { - activeRootBlocks := node.Protocol.MainEngine.Get().EvictionState.ActiveRootBlocks() + activeRootBlocks := node.Protocol.Engines.Main.Get().EvictionState.ActiveRootBlocks() if !assert.Equal(t.fakeTesting, expectedRootBlocks, activeRootBlocks) { return ierrors.Errorf("AssertActiveRootBlocks: %s: expected %v, got %v", node.Name, expectedRootBlocks, activeRootBlocks) @@ -36,8 +36,8 @@ func (t *TestSuite) AssertEvictedSlot(expectedIndex iotago.SlotIndex, nodes ...* for _, node := range nodes { t.Eventually(func() error { - if expectedIndex != lo.Return1(node.Protocol.MainEngine.Get().EvictionState.LastEvictedSlot()) { - return ierrors.Errorf("AssertEvictedSlot: %s: expected %d, got %d", node.Name, expectedIndex, lo.Return1(node.Protocol.MainEngine.Get().EvictionState.LastEvictedSlot())) + if expectedIndex != lo.Return1(node.Protocol.Engines.Main.Get().EvictionState.LastEvictedSlot()) { + return ierrors.Errorf("AssertEvictedSlot: %s: expected %d, got %d", node.Name, expectedIndex, lo.Return1(node.Protocol.Engines.Main.Get().EvictionState.LastEvictedSlot())) } return nil diff --git a/pkg/testsuite/mock/acceptance_loss.go b/pkg/testsuite/mock/acceptance_loss.go index c69ce1a46..e295819b5 100644 --- a/pkg/testsuite/mock/acceptance_loss.go +++ b/pkg/testsuite/mock/acceptance_loss.go @@ -8,12 +8,12 @@ import ( ) func (i *BlockIssuer) reviveChain(issuingTime time.Time, node *Node) (*iotago.Commitment, iotago.BlockID, error) { - lastCommittedSlot := node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Slot() + lastCommittedSlot := node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot() apiForSlot := node.Protocol.APIForSlot(lastCommittedSlot) // Get a rootblock as recent as possible for the parent. parentBlockID := iotago.EmptyBlockID - for rootBlock := range node.Protocol.MainEngine.Get().EvictionState.ActiveRootBlocks() { + for rootBlock := range node.Protocol.Engines.Main.Get().EvictionState.ActiveRootBlocks() { if rootBlock.Slot() > parentBlockID.Slot() { parentBlockID = rootBlock } @@ -33,11 +33,11 @@ func (i *BlockIssuer) reviveChain(issuingTime time.Time, node *Node) (*iotago.Co } commitUntilSlot := issuingSlot - apiForSlot.ProtocolParameters().MinCommittableAge() - if err := node.Protocol.MainEngine.Get().Notarization.ForceCommitUntil(commitUntilSlot); err != nil { + if err := node.Protocol.Engines.Main.Get().Notarization.ForceCommitUntil(commitUntilSlot); err != nil { return nil, iotago.EmptyBlockID, ierrors.Wrapf(err, "failed to force commit until slot %d", commitUntilSlot) } - commitment, err := node.Protocol.MainEngine.Get().Storage.Commitments().Load(commitUntilSlot) + commitment, err := node.Protocol.Engines.Main.Get().Storage.Commitments().Load(commitUntilSlot) if err != nil { return nil, iotago.EmptyBlockID, ierrors.Wrapf(err, "failed to commit until slot %d to revive chain", commitUntilSlot) } diff --git a/pkg/testsuite/mock/blockissuer.go b/pkg/testsuite/mock/blockissuer.go index 554fb6cd4..d2b82d11a 100644 --- a/pkg/testsuite/mock/blockissuer.go +++ b/pkg/testsuite/mock/blockissuer.go @@ -188,7 +188,7 @@ func (i *BlockIssuer) IssueValidationBlock(ctx context.Context, alias string, no validationBlock, _ := block.ValidationBlock() - node.Protocol.MainEngine.Get().LogTrace("issued validation block", "blockID", block.ID(), "slot", block.ID().Slot(), "commitment", block.SlotCommitmentID(), "latestFinalizedSlot", block.ProtocolBlock().LatestFinalizedSlot, "version", block.ProtocolBlock().ProtocolVersion, "highestSupportedVersion", validationBlock.HighestSupportedVersion, "hash", validationBlock.ProtocolParametersHash) + node.Protocol.Engines.Main.Get().LogTrace("issued validation block", "blockID", block.ID(), "slot", block.ID().Slot(), "commitment", block.SlotCommitmentID(), "latestFinalizedSlot", block.ProtocolBlock().LatestFinalizedSlot, "version", block.ProtocolBlock().ProtocolVersion, "highestSupportedVersion", validationBlock.HighestSupportedVersion, "hash", validationBlock.ProtocolParametersHash) return block } @@ -255,7 +255,7 @@ func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, node * if err != nil { rmcSlot = 0 } - rmc, err := node.Protocol.MainEngine.Get().Ledger.RMCManager().RMC(rmcSlot) + rmc, err := node.Protocol.Engines.Main.Get().Ledger.RMCManager().RMC(rmcSlot) require.NoError(i.Testing, err) // only set the burned Mana as the last step before signing, so workscore calculation is correct. @@ -378,8 +378,8 @@ func (i *BlockIssuer) AttachBlock(ctx context.Context, iotaBlock *iotago.Protoco } if iotaBlock.SlotCommitmentID == iotago.EmptyCommitmentID { - iotaBlock.SlotCommitmentID = node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment().MustID() - iotaBlock.LatestFinalizedSlot = node.Protocol.MainEngine.Get().Storage.Settings().LatestFinalizedSlot() + iotaBlock.SlotCommitmentID = node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment().MustID() + iotaBlock.LatestFinalizedSlot = node.Protocol.Engines.Main.Get().Storage.Settings().LatestFinalizedSlot() resign = true } @@ -429,7 +429,7 @@ func (i *BlockIssuer) AttachBlock(ctx context.Context, iotaBlock *iotago.Protoco if err != nil { rmcSlot = 0 } - rmc, err := node.Protocol.MainEngine.Get().Ledger.RMCManager().RMC(rmcSlot) + rmc, err := node.Protocol.Engines.Main.Get().Ledger.RMCManager().RMC(rmcSlot) if err != nil { return iotago.EmptyBlockID, ierrors.Wrapf(err, "error loading commitment of slot %d from storage to get RMC", rmcSlot) } @@ -468,7 +468,7 @@ func (i *BlockIssuer) AttachBlock(ctx context.Context, iotaBlock *iotago.Protoco return iotago.EmptyBlockID, ierrors.Wrap(err, "error serializing block to model block") } - if !i.optsRateSetterEnabled || node.Protocol.MainEngine.Get().Scheduler.IsBlockIssuerReady(modelBlock.ProtocolBlock().IssuerID) { + if !i.optsRateSetterEnabled || node.Protocol.Engines.Main.Get().Scheduler.IsBlockIssuerReady(modelBlock.ProtocolBlock().IssuerID) { i.events.BlockConstructed.Trigger(modelBlock) if err = i.IssueBlockAndAwaitEvent(ctx, modelBlock, node, node.Protocol.Events.Engine.BlockDAG.BlockAttached); err != nil { @@ -495,7 +495,7 @@ func (i *BlockIssuer) setDefaultBlockParams(blockParams *BlockHeaderParams, node } if blockParams.LatestFinalizedSlot == nil { - latestFinalizedSlot := node.Protocol.MainEngine.Get().Storage.Settings().LatestFinalizedSlot() + latestFinalizedSlot := node.Protocol.Engines.Main.Get().Storage.Settings().LatestFinalizedSlot() blockParams.LatestFinalizedSlot = &latestFinalizedSlot } @@ -516,7 +516,7 @@ func (i *BlockIssuer) getAddressableCommitment(currentAPI iotago.API, blockIssui protoParams := currentAPI.ProtocolParameters() blockSlot := currentAPI.TimeProvider().SlotFromTime(blockIssuingTime) - commitment := node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment() + commitment := node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment() if blockSlot > commitment.Slot+protoParams.MaxCommittableAge() { return nil, ierrors.Wrapf(ErrBlockTooRecent, "can't issue block: block slot %d is too far in the future, latest commitment is %d", blockSlot, commitment.Slot) @@ -528,7 +528,7 @@ func (i *BlockIssuer) getAddressableCommitment(currentAPI iotago.API, blockIssui } commitmentSlot := commitment.Slot - protoParams.MinCommittableAge() - loadedCommitment, err := node.Protocol.MainEngine.Get().Storage.Commitments().Load(commitmentSlot) + loadedCommitment, err := node.Protocol.Engines.Main.Get().Storage.Commitments().Load(commitmentSlot) if err != nil { return nil, ierrors.Wrapf(err, "error loading valid commitment of slot %d according to minCommittableAge from storage", commitmentSlot) } @@ -550,7 +550,7 @@ func (i *BlockIssuer) getReferences(ctx context.Context, p iotago.Payload, node func (i *BlockIssuer) validateReferences(issuingTime time.Time, slotCommitmentIndex iotago.SlotIndex, references model.ParentReferences, node *Node) error { for _, parent := range lo.Flatten(lo.Map(lo.Values(references), func(ds iotago.BlockIDs) []iotago.BlockID { return ds })) { - b, exists := node.Protocol.MainEngine.Get().BlockFromCache(parent) + b, exists := node.Protocol.Engines.Main.Get().BlockFromCache(parent) if !exists { return ierrors.Errorf("cannot issue block if the parents are not known: %s", parent) } @@ -572,7 +572,7 @@ func (i *BlockIssuer) IssueBlock(block *model.Block, node *Node) error { } if _, isValidationBlock := block.ValidationBlock(); isValidationBlock { - _ = node.Protocol.MainEngine.Get().Storage.Settings().SetLatestIssuedValidationBlock(block) + _ = node.Protocol.Engines.Main.Get().Storage.Settings().SetLatestIssuedValidationBlock(block) } i.events.BlockIssued.Trigger(block) @@ -596,7 +596,7 @@ func (i *BlockIssuer) getReferencesWithRetry(ctx context.Context, _ iotago.Paylo defer timeutil.CleanupTicker(interval) for { - references = node.Protocol.MainEngine.Get().TipSelection.SelectTips(parentsCount) + references = node.Protocol.Engines.Main.Get().TipSelection.SelectTips(parentsCount) if len(references[iotago.StrongParentType]) > 0 { return references, nil } diff --git a/pkg/testsuite/mock/node.go b/pkg/testsuite/mock/node.go index 3a8cfb416..a4ad97d5e 100644 --- a/pkg/testsuite/mock/node.go +++ b/pkg/testsuite/mock/node.go @@ -395,7 +395,7 @@ func (n *Node) attachEngineLogsWithName(failOnBlockFiltered bool, instance *engi } func (n *Node) attachEngineLogs(failOnBlockFiltered bool, instance *engine.Engine) { - engineName := fmt.Sprintf("%s - %s", lo.Cond(n.Protocol.MainEngine.Get() != instance, "Candidate", "Main"), instance.Name()[:8]) + engineName := fmt.Sprintf("%s - %s", lo.Cond(n.Protocol.Engines.Main.Get() != instance, "Candidate", "Main"), instance.Name()[:8]) n.attachEngineLogsWithName(failOnBlockFiltered, instance, engineName) } diff --git a/pkg/testsuite/storage_accountdiffs.go b/pkg/testsuite/storage_accountdiffs.go index 532d64b08..e3d9ec9b3 100644 --- a/pkg/testsuite/storage_accountdiffs.go +++ b/pkg/testsuite/storage_accountdiffs.go @@ -15,7 +15,7 @@ func (t *TestSuite) AssertStorageAccountDiffs(slot iotago.SlotIndex, accountDiff for _, node := range nodes { for accountID, diffChange := range accountDiffs { t.Eventually(func() error { - store, err := node.Protocol.MainEngine.Get().Storage.AccountDiffs(slot) + store, err := node.Protocol.Engines.Main.Get().Storage.AccountDiffs(slot) if err != nil { return ierrors.Wrapf(err, "AssertStorageAccountDiffs: %s: failed to load accounts diff for slot %d", node.Name, slot) } diff --git a/pkg/testsuite/storage_blocks.go b/pkg/testsuite/storage_blocks.go index 21b9bc9ac..09c1afe30 100644 --- a/pkg/testsuite/storage_blocks.go +++ b/pkg/testsuite/storage_blocks.go @@ -10,7 +10,7 @@ import ( func (t *TestSuite) AssertStorageBlock(block *model.Block, node *mock.Node) { t.Eventually(func() error { - storage, err := node.Protocol.MainEngine.Get().Storage.Blocks(block.ID().Slot()) + storage, err := node.Protocol.Engines.Main.Get().Storage.Blocks(block.ID().Slot()) if err != nil { return ierrors.Errorf("AssertStorageBlock: %s: storage for %s is nil", node.Name, block.ID().Slot()) } @@ -37,7 +37,7 @@ func (t *TestSuite) AssertStorageBlockExist(block *model.Block, expectedExist bo t.AssertStorageBlock(block, node) } else { t.Eventually(func() error { - storage, err := node.Protocol.MainEngine.Get().Storage.Blocks(block.ID().Slot()) + storage, err := node.Protocol.Engines.Main.Get().Storage.Blocks(block.ID().Slot()) if err != nil { //nolint:nilerr // expected behavior return nil diff --git a/pkg/testsuite/storage_commitments.go b/pkg/testsuite/storage_commitments.go index 888d1ebd8..d14f7e9a2 100644 --- a/pkg/testsuite/storage_commitments.go +++ b/pkg/testsuite/storage_commitments.go @@ -15,7 +15,7 @@ func (t *TestSuite) AssertStorageCommitments(commitments []*iotago.Commitment, n for _, node := range nodes { for _, commitment := range commitments { t.Eventually(func() error { - storedCommitment, err := node.Protocol.MainEngine.Get().Storage.Commitments().Load(commitment.Slot) + storedCommitment, err := node.Protocol.Engines.Main.Get().Storage.Commitments().Load(commitment.Slot) if err != nil { return ierrors.Wrapf(err, "AssertStorageCommitments: %s: error loading commitment: %s", node.Name, commitment.MustID()) } @@ -37,7 +37,7 @@ func (t *TestSuite) AssertEqualStoredCommitmentAtIndex(index iotago.SlotIndex, n var commitment *model.Commitment var commitmentNode *mock.Node for _, node := range nodes { - storedCommitment, err := node.Protocol.MainEngine.Get().Storage.Commitments().Load(index) + storedCommitment, err := node.Protocol.Engines.Main.Get().Storage.Commitments().Load(index) if err != nil { return ierrors.Wrapf(err, "AssertEqualStoredCommitmentAtIndex: %s: error loading commitment for slot: %d", node.Name, index) } @@ -63,12 +63,12 @@ func (t *TestSuite) AssertStorageCommitmentBlocks(slot iotago.SlotIndex, expecte t.Eventually(func() error { for _, node := range nodes { - storedCommitment, err := node.Protocol.MainEngine.Get().Storage.Commitments().Load(slot) + storedCommitment, err := node.Protocol.Engines.Main.Get().Storage.Commitments().Load(slot) if err != nil { return ierrors.Wrapf(err, "AssertStorageCommitmentBlocks: %s: error loading commitment for slot: %d", node.Name, slot) } - committedSlot, err := node.Protocol.MainEngine.Get().CommittedSlot(storedCommitment.ID()) + committedSlot, err := node.Protocol.Engines.Main.Get().CommittedSlot(storedCommitment.ID()) if err != nil { return ierrors.Wrapf(err, "AssertStorageCommitmentBlocks: %s: error getting committed slot for commitment: %s", node.Name, storedCommitment.ID()) } diff --git a/pkg/testsuite/storage_prunable.go b/pkg/testsuite/storage_prunable.go index 4fe4db6ca..f5fa36271 100644 --- a/pkg/testsuite/storage_prunable.go +++ b/pkg/testsuite/storage_prunable.go @@ -26,7 +26,7 @@ func (t *TestSuite) AssertPrunedUntil(expectedStorage *types.Tuple[int, bool], for _, node := range nodes { t.Eventually(func() error { - if err := t.assertPrunedUntil(node.Protocol.MainEngine.Get().Storage, expectedStorage, expectedDecidedUpgrades, expectedPoolStats, expectedCommittee, expectedRewards); err != nil { + if err := t.assertPrunedUntil(node.Protocol.Engines.Main.Get().Storage, expectedStorage, expectedDecidedUpgrades, expectedPoolStats, expectedCommittee, expectedRewards); err != nil { return ierrors.Wrapf(err, "AssertPrunedSlot: %s", node.Name) } diff --git a/pkg/testsuite/storage_rootblocks.go b/pkg/testsuite/storage_rootblocks.go index 3deea5499..119c140a6 100644 --- a/pkg/testsuite/storage_rootblocks.go +++ b/pkg/testsuite/storage_rootblocks.go @@ -12,7 +12,7 @@ func (t *TestSuite) AssertStorageRootBlocks(blocks []*blocks.Block, nodes ...*mo for _, node := range nodes { for _, block := range blocks { t.Eventually(func() error { - storage, err := node.Protocol.MainEngine.Get().Storage.RootBlocks(block.ID().Slot()) + storage, err := node.Protocol.Engines.Main.Get().Storage.RootBlocks(block.ID().Slot()) if err != nil { return ierrors.Errorf("AssertStorageRootBlocks: %s: error loading root blocks for %s: %v", node.Name, block.ID().Slot(), err) } diff --git a/pkg/testsuite/storage_settings.go b/pkg/testsuite/storage_settings.go index 5cf1e7afb..f8667ead0 100644 --- a/pkg/testsuite/storage_settings.go +++ b/pkg/testsuite/storage_settings.go @@ -11,8 +11,8 @@ func (t *TestSuite) AssertSnapshotImported(imported bool, nodes ...*mock.Node) { for _, node := range nodes { t.Eventually(func() error { - if imported != node.Protocol.MainEngine.Get().Storage.Settings().IsSnapshotImported() { - return ierrors.Errorf("AssertSnapshotImported: %s: expected %v, got %v", node.Name, imported, node.Protocol.MainEngine.Get().Storage.Settings().IsSnapshotImported()) + if imported != node.Protocol.Engines.Main.Get().Storage.Settings().IsSnapshotImported() { + return ierrors.Errorf("AssertSnapshotImported: %s: expected %v, got %v", node.Name, imported, node.Protocol.Engines.Main.Get().Storage.Settings().IsSnapshotImported()) } return nil @@ -39,8 +39,8 @@ func (t *TestSuite) AssertLatestCommitment(commitment *iotago.Commitment, nodes for _, node := range nodes { t.Eventually(func() error { - if !commitment.Equals(node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment()) { - return ierrors.Errorf("AssertLatestCommitment: %s: expected %s, got %s", node.Name, commitment, node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment()) + if !commitment.Equals(node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment()) { + return ierrors.Errorf("AssertLatestCommitment: %s: expected %s, got %s", node.Name, commitment, node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment()) } return nil @@ -53,11 +53,11 @@ func (t *TestSuite) AssertCommitmentSlotIndexExists(slot iotago.SlotIndex, nodes for _, node := range nodes { t.Eventually(func() error { - if node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().ID().Slot() < slot { + if node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().ID().Slot() < slot { return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: commitment with at least %v not found in settings.LatestCommitment()", node.Name, slot) } - cm, err := node.Protocol.MainEngine.Get().Storage.Commitments().Load(slot) + cm, err := node.Protocol.Engines.Main.Get().Storage.Commitments().Load(slot) if err != nil { return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: expected %v, got error %v", node.Name, slot, err) } @@ -81,8 +81,8 @@ func (t *TestSuite) AssertLatestCommitmentSlotIndex(slot iotago.SlotIndex, nodes for _, node := range nodes { t.Eventually(func() error { - if slot != node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Slot() { - return ierrors.Errorf("AssertLatestCommitmentSlotIndex: %s: expected %v, got %v", node.Name, slot, node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Slot()) + if slot != node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot() { + return ierrors.Errorf("AssertLatestCommitmentSlotIndex: %s: expected %v, got %v", node.Name, slot, node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot()) } return nil @@ -95,8 +95,8 @@ func (t *TestSuite) AssertLatestCommitmentCumulativeWeight(cw uint64, nodes ...* for _, node := range nodes { t.Eventually(func() error { - if cw != node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().CumulativeWeight() { - return ierrors.Errorf("AssertLatestCommitmentCumulativeWeight: %s: expected %v, got %v", node.Name, cw, node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().CumulativeWeight()) + if cw != node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().CumulativeWeight() { + return ierrors.Errorf("AssertLatestCommitmentCumulativeWeight: %s: expected %v, got %v", node.Name, cw, node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().CumulativeWeight()) } return nil @@ -109,8 +109,8 @@ func (t *TestSuite) AssertLatestFinalizedSlot(slot iotago.SlotIndex, nodes ...*m for _, node := range nodes { t.Eventually(func() error { - if slot != node.Protocol.MainEngine.Get().Storage.Settings().LatestFinalizedSlot() { - return ierrors.Errorf("AssertLatestFinalizedSlot: %s: expected %d, got %d from settings", node.Name, slot, node.Protocol.MainEngine.Get().Storage.Settings().LatestFinalizedSlot()) + if slot != node.Protocol.Engines.Main.Get().Storage.Settings().LatestFinalizedSlot() { + return ierrors.Errorf("AssertLatestFinalizedSlot: %s: expected %d, got %d from settings", node.Name, slot, node.Protocol.Engines.Main.Get().Storage.Settings().LatestFinalizedSlot()) } return nil diff --git a/pkg/testsuite/sybilprotection.go b/pkg/testsuite/sybilprotection.go index 123ec2e3d..65a28a7b8 100644 --- a/pkg/testsuite/sybilprotection.go +++ b/pkg/testsuite/sybilprotection.go @@ -14,7 +14,7 @@ func (t *TestSuite) AssertSybilProtectionCommittee(slot iotago.SlotIndex, expect for _, node := range nodes { t.Eventually(func() error { - accounts := node.Protocol.MainEngine.Get().SybilProtection.SeatManager().Committee(slot).Accounts().IDs() + accounts := node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().Committee(slot).Accounts().IDs() if !assert.ElementsMatch(t.fakeTesting, expectedAccounts, accounts) { return ierrors.Errorf("AssertSybilProtectionCommittee: %s: expected %s, got %s", node.Name, expectedAccounts, accounts) } @@ -33,7 +33,7 @@ func (t *TestSuite) AssertSybilProtectionOnlineCommittee(expectedSeats []account for _, node := range nodes { t.Eventually(func() error { - seats := node.Protocol.MainEngine.Get().SybilProtection.SeatManager().OnlineCommittee().ToSlice() + seats := node.Protocol.Engines.Main.Get().SybilProtection.SeatManager().OnlineCommittee().ToSlice() if !assert.ElementsMatch(t.fakeTesting, expectedSeats, seats) { return ierrors.Errorf("AssertSybilProtectionOnlineCommittee: %s: expected %v, got %v", node.Name, expectedSeats, seats) } diff --git a/pkg/testsuite/testsuite_issue_blocks.go b/pkg/testsuite/testsuite_issue_blocks.go index bec70d4bf..73f578ea9 100644 --- a/pkg/testsuite/testsuite_issue_blocks.go +++ b/pkg/testsuite/testsuite_issue_blocks.go @@ -284,7 +284,7 @@ func (t *TestSuite) CommitUntilSlot(slot iotago.SlotIndex, parent *blocks.Block) // then issue one more block to accept the last in the chain which will trigger commitment of the second last in the chain activeValidators := t.Validators() - latestCommittedSlot := activeValidators[0].Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Slot() + latestCommittedSlot := activeValidators[0].Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot() if latestCommittedSlot >= slot { return parent } @@ -296,12 +296,12 @@ func (t *TestSuite) CommitUntilSlot(slot iotago.SlotIndex, parent *blocks.Block) for _, node := range activeValidators { require.True(t.Testing, node.IsValidator(), "node: %s: is not a validator node", node.Name) blockAlias := fmt.Sprintf("chain-%s-%d-%s", parent.ID().Alias(), chainIndex, node.Name) - tip = t.IssueValidationBlockAtSlot(blockAlias, nextBlockSlot, node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment(), node, tip.ID()) + tip = t.IssueValidationBlockAtSlot(blockAlias, nextBlockSlot, node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment(), node, tip.ID()) } // acceptance of nextBlockSlot for _, node := range activeValidators { blockAlias := fmt.Sprintf("chain-%s-%d-%s", parent.ID().Alias(), chainIndex+1, node.Name) - tip = t.IssueValidationBlockAtSlot(blockAlias, nextBlockSlot, node.Protocol.MainEngine.Get().Storage.Settings().LatestCommitment().Commitment(), node, tip.ID()) + tip = t.IssueValidationBlockAtSlot(blockAlias, nextBlockSlot, node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment(), node, tip.ID()) } if nextBlockSlot == slot+t.API.ProtocolParameters().MinCommittableAge() { break diff --git a/pkg/testsuite/tips.go b/pkg/testsuite/tips.go index c9f315d1c..cc5b4f5ff 100644 --- a/pkg/testsuite/tips.go +++ b/pkg/testsuite/tips.go @@ -17,7 +17,7 @@ func (t *TestSuite) AssertStrongTips(expectedBlocks []*blocks.Block, nodes ...*m for _, node := range nodes { t.Eventually(func() error { - storedTipsBlocks := node.Protocol.MainEngine.Get().TipManager.StrongTips() + storedTipsBlocks := node.Protocol.Engines.Main.Get().TipManager.StrongTips() storedTipsBlockIDs := lo.Map(storedTipsBlocks, tipmanager.TipMetadata.ID) if !assert.ElementsMatch(t.fakeTesting, expectedBlockIDs, storedTipsBlockIDs) { diff --git a/pkg/testsuite/transactions.go b/pkg/testsuite/transactions.go index c4b3e0528..6a4502feb 100644 --- a/pkg/testsuite/transactions.go +++ b/pkg/testsuite/transactions.go @@ -19,7 +19,7 @@ func (t *TestSuite) AssertTransaction(transaction *iotago.Transaction, node *moc t.Eventually(func() error { var exists bool - loadedTransactionMetadata, exists = node.Protocol.MainEngine.Get().Ledger.TransactionMetadata(transactionID) + loadedTransactionMetadata, exists = node.Protocol.Engines.Main.Get().Ledger.TransactionMetadata(transactionID) if !exists { return ierrors.Errorf("AssertTransaction: %s: transaction %s does not exist", node.Name, transactionID) } @@ -61,7 +61,7 @@ func (t *TestSuite) AssertTransactionsExist(transactions []*iotago.Transaction, t.AssertTransaction(transaction, node) } else { t.Eventually(func() error { - if lo.Return2(node.Protocol.MainEngine.Get().Ledger.TransactionMetadata(transactionID)) { + if lo.Return2(node.Protocol.Engines.Main.Get().Ledger.TransactionMetadata(transactionID)) { return ierrors.Errorf("AssertTransactionsExist: %s: transaction %s exists but should not", node.Name, transactionID) } @@ -84,7 +84,7 @@ func (t *TestSuite) assertTransactionsInCacheWithFunc(expectedTransactions []*io require.NoError(t.Testing, err) t.Eventually(func() error { - blockFromCache, exists := node.Protocol.MainEngine.Get().Ledger.TransactionMetadata(transactionID) + blockFromCache, exists := node.Protocol.Engines.Main.Get().Ledger.TransactionMetadata(transactionID) if !exists { return ierrors.Errorf("assertTransactionsInCacheWithFunc: %s: transaction %s does not exist", node.Name, transactionID) } @@ -136,7 +136,7 @@ func (t *TestSuite) AssertTransactionInCacheConflicts(transactionConflicts map[* require.NoError(t.Testing, err) t.Eventually(func() error { - transactionFromCache, exists := node.Protocol.MainEngine.Get().Ledger.TransactionMetadata(transactionID) + transactionFromCache, exists := node.Protocol.Engines.Main.Get().Ledger.TransactionMetadata(transactionID) if !exists { return ierrors.Errorf("AssertTransactionInCacheConflicts: %s: block %s does not exist", node.Name, transactionID) } diff --git a/pkg/testsuite/transactions_framework.go b/pkg/testsuite/transactions_framework.go index 108aeb368..82c6c2a68 100644 --- a/pkg/testsuite/transactions_framework.go +++ b/pkg/testsuite/transactions_framework.go @@ -34,7 +34,7 @@ func NewTransactionFramework(protocol *protocol.Protocol, genesisSeed []byte) *T wallet: mock.NewHDWallet("genesis", genesisSeed, 0), } - if err := protocol.MainEngine.Get().Ledger.ForEachUnspentOutput(func(output *utxoledger.Output) bool { + if err := protocol.Engines.Main.Get().Ledger.ForEachUnspentOutput(func(output *utxoledger.Output) bool { tf.states[fmt.Sprintf("Genesis:%d", output.OutputID().Index())] = output return true }); err != nil { diff --git a/pkg/testsuite/upgrades.go b/pkg/testsuite/upgrades.go index c7ddc67ab..5ecfa1a33 100644 --- a/pkg/testsuite/upgrades.go +++ b/pkg/testsuite/upgrades.go @@ -14,7 +14,7 @@ func (t *TestSuite) AssertEpochVersions(epochVersions map[iotago.Version]iotago. t.Eventually(func() error { for version, expectedEpoch := range epochVersions { - epochForVersion, exists := node.Protocol.MainEngine.Get().Storage.Settings().APIProvider().EpochForVersion(version) + epochForVersion, exists := node.Protocol.Engines.Main.Get().Storage.Settings().APIProvider().EpochForVersion(version) if !exists { return ierrors.Errorf("AssertEpochVersions: %s: version %d not found", node.Name, version) } @@ -36,7 +36,7 @@ func (t *TestSuite) AssertVersionAndProtocolParameters(versionsAndProtocolParame t.Eventually(func() error { for version, expectedProtocolParameters := range versionsAndProtocolParameters { - protocolParameters := node.Protocol.MainEngine.Get().Storage.Settings().APIProvider().ProtocolParameters(version) + protocolParameters := node.Protocol.Engines.Main.Get().Storage.Settings().APIProvider().ProtocolParameters(version) if expectedProtocolParameters == nil { if protocolParameters != nil { @@ -71,7 +71,7 @@ func (t *TestSuite) AssertVersionAndProtocolParametersHashes(versionsAndProtocol t.Eventually(func() error { for version, expectedProtocolParametersHash := range versionsAndProtocolParametersHashes { - protocolParametersHash := node.Protocol.MainEngine.Get().Storage.Settings().APIProvider().ProtocolParametersHash(version) + protocolParametersHash := node.Protocol.Engines.Main.Get().Storage.Settings().APIProvider().ProtocolParametersHash(version) if expectedProtocolParametersHash == iotago.EmptyIdentifier { if protocolParametersHash != iotago.EmptyIdentifier {