From e1c87fdcd6722c24209161491c8ab99ca2f458cd Mon Sep 17 00:00:00 2001 From: muXxer Date: Mon, 29 Apr 2024 12:49:00 +0200 Subject: [PATCH] Code cleanup --- components/prometheus/metrics_accounts.go | 2 +- components/prometheus/metrics_scheduler.go | 44 ++++++------ .../engine/accounts/accountsledger/manager.go | 10 +-- .../attestation/slotattestation/manager.go | 6 +- pkg/protocol/engine/blocks/block.go | 12 ++++ .../drr/{drrbuffer.go => basicbuffer.go} | 70 +++++++++---------- .../scheduler/drr/issuerqueue.go | 2 +- .../scheduler/drr/scheduler.go | 27 +++---- .../scheduler/drr/validatorqueue.go | 4 +- .../thresholdblockgadget/gadget.go | 4 +- .../totalweightslotgadget/gadget.go | 2 +- .../post_solid_block_filter.go | 14 ++-- pkg/protocol/engine/ledger/ledger/ledger.go | 4 +- .../engine/tipmanager/v1/tip_manager.go | 4 +- .../orchestrator.go | 2 +- .../sybilprotection/seatmanager/poa/poa.go | 4 +- .../seatmanager/topstakers/topstakers.go | 4 +- .../performance/performance.go | 18 ++--- .../sybilprotectionv1/sybilprotection.go | 6 +- pkg/tests/protocol_engine_switching_test.go | 2 +- pkg/tests/protocol_eviction_test.go | 2 +- 21 files changed, 126 insertions(+), 117 deletions(-) rename pkg/protocol/engine/congestioncontrol/scheduler/drr/{drrbuffer.go => basicbuffer.go} (79%) diff --git a/components/prometheus/metrics_accounts.go b/components/prometheus/metrics_accounts.go index 222def9cf..381d38bdb 100644 --- a/components/prometheus/metrics_accounts.go +++ b/components/prometheus/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.Engines.Main.Get().Ledger.Account(block.ProtocolBlock().Header.IssuerID, deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot()) + accountData, exists, _ := deps.Protocol.Engines.Main.Get().Ledger.Account(block.IssuerID(), deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot()) if exists { deps.Collector.Update(accountNamespace, credits, float64(accountData.Credits.Value), accountData.ID.String()) } diff --git a/components/prometheus/metrics_scheduler.go b/components/prometheus/metrics_scheduler.go index f86414c71..f79656b27 100644 --- a/components/prometheus/metrics_scheduler.go +++ b/components/prometheus/metrics_scheduler.go @@ -35,20 +35,20 @@ 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.Engines.Main.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.IssuerID())), block.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.Engines.Main.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.IssuerID())), block.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.Engines.Main.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.IssuerID())), block.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.Engines.Main.Get().Scheduler.IssuerQueueWork(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + deps.Collector.Update(schedulerNamespace, queueSizePerNodeWork, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueWork(block.IssuerID())), block.IssuerID().String()) }, event.WithWorkerPool(Component.WorkerPool)) }), )), @@ -59,26 +59,26 @@ var SchedulerMetrics = collector.NewCollection(schedulerNamespace, collector.WithHelp("Current size of each node's queue (as block count)."), 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.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + if block.IsBasicBlock() { + deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.IssuerID())), block.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.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + if block.IsBasicBlock() { + deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.IssuerID())), block.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.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + if block.IsBasicBlock() { + deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.IssuerID())), block.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.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + if block.IsBasicBlock() { + deps.Collector.Update(schedulerNamespace, queueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.IssuerQueueBlockCount(block.IssuerID())), block.IssuerID().String()) } }, event.WithWorkerPool(Component.WorkerPool)) }), @@ -90,26 +90,26 @@ var SchedulerMetrics = collector.NewCollection(schedulerNamespace, collector.WithHelp("Current number of validation blocks in each validator's queue."), 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.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + if block.IsValidationBlock() { + deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.IssuerID())), block.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.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + if block.IsValidationBlock() { + deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.IssuerID())), block.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.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + if block.IsValidationBlock() { + deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.IssuerID())), block.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.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.ProtocolBlock().Header.IssuerID)), block.ProtocolBlock().Header.IssuerID.String()) + if block.IsValidationBlock() { + deps.Collector.Update(schedulerNamespace, validatorQueueSizePerNodeCount, float64(deps.Protocol.Engines.Main.Get().Scheduler.ValidatorQueueBlockCount(block.IssuerID())), block.IssuerID().String()) } }, event.WithWorkerPool(Component.WorkerPool)) }), @@ -121,22 +121,18 @@ var SchedulerMetrics = collector.NewCollection(schedulerNamespace, collector.WithInitFunc(func() { deps.Protocol.Events.Engine.Scheduler.BlockEnqueued.Hook(func(_ *blocks.Block) { deps.Collector.Increment(schedulerNamespace, schedulerProcessedBlocks, enqueuedBlockLabel) - }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockDropped.Hook(func(_ *blocks.Block, _ error) { deps.Collector.Increment(schedulerNamespace, schedulerProcessedBlocks, droppedBlockLabel) - }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockSkipped.Hook(func(_ *blocks.Block) { deps.Collector.Increment(schedulerNamespace, schedulerProcessedBlocks, skippedBlockLabel) - }, event.WithWorkerPool(Component.WorkerPool)) deps.Protocol.Events.Engine.Scheduler.BlockScheduled.Hook(func(_ *blocks.Block) { deps.Collector.Increment(schedulerNamespace, schedulerProcessedBlocks, scheduledBlockLabel) - }, event.WithWorkerPool(Component.WorkerPool)) }), )), diff --git a/pkg/protocol/engine/accounts/accountsledger/manager.go b/pkg/protocol/engine/accounts/accountsledger/manager.go index 59f5e8c7e..4ab701d33 100644 --- a/pkg/protocol/engine/accounts/accountsledger/manager.go +++ b/pkg/protocol/engine/accounts/accountsledger/manager.go @@ -94,7 +94,7 @@ func (m *Manager) TrackBlock(block *blocks.Block) { if validationBlock, isValidationBlock := block.ValidationBlock(); isValidationBlock { newSignaledBlock := model.NewSignaledBlock(block.ID(), block.ProtocolBlock(), validationBlock) - m.latestSupportedVersionSignals.Get(block.ID().Slot(), true).Compute(block.ProtocolBlock().Header.IssuerID, func(currentValue *model.SignaledBlock, exists bool) *model.SignaledBlock { + m.latestSupportedVersionSignals.Get(block.ID().Slot(), true).Compute(block.IssuerID(), func(currentValue *model.SignaledBlock, exists bool) *model.SignaledBlock { if !exists { return newSignaledBlock } @@ -481,10 +481,10 @@ func (m *Manager) computeBlockBurnsForSlot(slot iotago.SlotIndex, rmc iotago.Man if !blockLoaded { return nil, ierrors.Errorf("cannot apply the new diff, block %s not found in the block cache", blockID) } - if _, isBasicBlock := block.BasicBlock(); isBasicBlock { - burns[block.ProtocolBlock().Header.IssuerID] += iotago.Mana(block.WorkScore()) * rmc - } else if _, isValidationBlock := block.ValidationBlock(); isValidationBlock { - validationBlockCount[block.ProtocolBlock().Header.IssuerID]++ + if block.IsBasicBlock() { + burns[block.IssuerID()] += iotago.Mana(block.WorkScore()) * rmc + } else if block.IsValidationBlock() { + validationBlockCount[block.IssuerID()]++ } } validationBlocksPerSlot := int(apiForSlot.ProtocolParameters().ValidationBlocksPerSlot()) diff --git a/pkg/protocol/engine/attestation/slotattestation/manager.go b/pkg/protocol/engine/attestation/slotattestation/manager.go index 83c4e5600..8289f98d8 100644 --- a/pkg/protocol/engine/attestation/slotattestation/manager.go +++ b/pkg/protocol/engine/attestation/slotattestation/manager.go @@ -141,7 +141,7 @@ func (m *Manager) GetMap(slot iotago.SlotIndex) (ads.Map[iotago.Identifier, iota // AddAttestationFromValidationBlock adds an attestation from a block to the future attestations (beyond the attestation window). func (m *Manager) AddAttestationFromValidationBlock(block *blocks.Block) error { // Only track validation blocks. - if _, isValidationBlock := block.ValidationBlock(); !isValidationBlock { + if !block.IsValidationBlock() { return nil } @@ -150,7 +150,7 @@ func (m *Manager) AddAttestationFromValidationBlock(block *blocks.Block) error { return ierrors.Errorf("committee for slot %d does not exist", block.ID().Slot()) } // Only track attestations of active committee members. - if _, exists := committee.GetSeat(block.ProtocolBlock().Header.IssuerID); !exists { + if _, exists := committee.GetSeat(block.IssuerID()); !exists { return nil } @@ -165,7 +165,7 @@ func (m *Manager) AddAttestationFromValidationBlock(block *blocks.Block) error { newAttestation := iotago.NewAttestation(m.apiProvider.APIForSlot(block.ID().Slot()), block.ProtocolBlock()) // We keep only the latest attestation for each committee member. - m.futureAttestations.Get(block.ID().Slot(), true).Compute(block.ProtocolBlock().Header.IssuerID, func(currentValue *iotago.Attestation, exists bool) *iotago.Attestation { + m.futureAttestations.Get(block.ID().Slot(), true).Compute(block.IssuerID(), func(currentValue *iotago.Attestation, exists bool) *iotago.Attestation { if !exists { return newAttestation } diff --git a/pkg/protocol/engine/blocks/block.go b/pkg/protocol/engine/blocks/block.go index acbd6bf7d..50891b024 100644 --- a/pkg/protocol/engine/blocks/block.go +++ b/pkg/protocol/engine/blocks/block.go @@ -169,6 +169,10 @@ func (b *Block) ForEachParent(consumer func(parent iotago.Parent)) { b.modelBlock.ProtocolBlock().ForEachParent(consumer) } +func (b *Block) IssuerID() iotago.AccountID { + return b.modelBlock.ProtocolBlock().Header.IssuerID +} + func (b *Block) IsRootBlock() bool { return b.rootBlock != nil } @@ -189,6 +193,10 @@ func (b *Block) SignedTransaction() (tx *iotago.SignedTransaction, hasTransactio return b.modelBlock.SignedTransaction() } +func (b *Block) IsBasicBlock() bool { + return lo.Return2(b.BasicBlock()) +} + func (b *Block) BasicBlock() (basicBlock *iotago.BasicBlockBody, isBasicBlock bool) { if b.modelBlock == nil { return nil, false @@ -197,6 +205,10 @@ func (b *Block) BasicBlock() (basicBlock *iotago.BasicBlockBody, isBasicBlock bo return b.modelBlock.BasicBlock() } +func (b *Block) IsValidationBlock() bool { + return lo.Return2(b.ValidationBlock()) +} + func (b *Block) ValidationBlock() (validationBlock *iotago.ValidationBlockBody, isValidationBlock bool) { if b.modelBlock == nil { return nil, false diff --git a/pkg/protocol/engine/congestioncontrol/scheduler/drr/drrbuffer.go b/pkg/protocol/engine/congestioncontrol/scheduler/drr/basicbuffer.go similarity index 79% rename from pkg/protocol/engine/congestioncontrol/scheduler/drr/drrbuffer.go rename to pkg/protocol/engine/congestioncontrol/scheduler/drr/basicbuffer.go index 7aa2631d7..c284fff4e 100644 --- a/pkg/protocol/engine/congestioncontrol/scheduler/drr/drrbuffer.go +++ b/pkg/protocol/engine/congestioncontrol/scheduler/drr/basicbuffer.go @@ -14,10 +14,10 @@ import ( iotago "github.com/iotaledger/iota.go/v4" ) -// region BufferQueue ///////////////////////////////////////////////////////////////////////////////////////////// +// region BasicBuffer ///////////////////////////////////////////////////////////////////////////////////////////// -// BufferQueue represents a buffer of IssuerQueue. -type BufferQueue struct { +// BasicBuffer represents a buffer of IssuerQueue. +type BasicBuffer struct { activeIssuers *shrinkingmap.ShrinkingMap[iotago.AccountID, *ring.Ring] ring *ring.Ring // size is the number of blocks in the buffer. @@ -29,9 +29,9 @@ type BufferQueue struct { blockChan chan *blocks.Block } -// NewBufferQueue returns a new BufferQueue. -func NewBufferQueue() *BufferQueue { - return &BufferQueue{ +// NewBasicBuffer returns a new BasicBuffer. +func NewBasicBuffer() *BasicBuffer { + return &BasicBuffer{ activeIssuers: shrinkingmap.New[iotago.AccountID, *ring.Ring](), ring: nil, lastScheduleTime: time.Now(), @@ -40,11 +40,11 @@ func NewBufferQueue() *BufferQueue { } // NumActiveIssuers returns the number of active issuers in b. -func (b *BufferQueue) NumActiveIssuers() int { +func (b *BasicBuffer) NumActiveIssuers() int { return b.activeIssuers.Size() } -func (b *BufferQueue) Clear() { +func (b *BasicBuffer) Clear() { select { case <-b.blockChan: default: @@ -57,13 +57,13 @@ func (b *BufferQueue) Clear() { }) } -// Size returns the total number of blocks in BufferQueue. -func (b *BufferQueue) Size() int { +// Size returns the total number of blocks in BasicBuffer. +func (b *BasicBuffer) Size() int { return int(b.size.Load()) } // IssuerQueue returns the queue for the corresponding issuer. -func (b *BufferQueue) IssuerQueue(issuerID iotago.AccountID) *IssuerQueue { +func (b *BasicBuffer) IssuerQueue(issuerID iotago.AccountID) *IssuerQueue { element, ok := b.activeIssuers.Get(issuerID) if !ok { return nil @@ -77,7 +77,7 @@ func (b *BufferQueue) IssuerQueue(issuerID iotago.AccountID) *IssuerQueue { } // IssuerQueueWork returns the total WorkScore of block in the queue for the corresponding issuer. -func (b *BufferQueue) IssuerQueueWork(issuerID iotago.AccountID) iotago.WorkScore { +func (b *BasicBuffer) IssuerQueueWork(issuerID iotago.AccountID) iotago.WorkScore { issuerQueue := b.IssuerQueue(issuerID) if issuerQueue == nil { return 0 @@ -87,7 +87,7 @@ func (b *BufferQueue) IssuerQueueWork(issuerID iotago.AccountID) iotago.WorkScor } // IssuerQueueSize returns the number of blocks in the queue for the corresponding issuer. -func (b *BufferQueue) IssuerQueueBlockCount(issuerID iotago.AccountID) int { +func (b *BasicBuffer) IssuerQueueBlockCount(issuerID iotago.AccountID) int { issuerQueue := b.IssuerQueue(issuerID) if issuerQueue == nil { return 0 @@ -96,14 +96,14 @@ func (b *BufferQueue) IssuerQueueBlockCount(issuerID iotago.AccountID) int { return issuerQueue.Size() } -func (b *BufferQueue) CreateIssuerQueue(issuerID iotago.AccountID) *IssuerQueue { +func (b *BasicBuffer) CreateIssuerQueue(issuerID iotago.AccountID) *IssuerQueue { issuerQueue := NewIssuerQueue(issuerID) b.activeIssuers.Set(issuerID, b.ringInsert(issuerQueue)) return issuerQueue } -func (b *BufferQueue) GetOrCreateIssuerQueue(issuerID iotago.AccountID) *IssuerQueue { +func (b *BasicBuffer) GetOrCreateIssuerQueue(issuerID iotago.AccountID) *IssuerQueue { element, issuerActive := b.activeIssuers.Get(issuerID) if !issuerActive { // create new issuer queue @@ -118,7 +118,7 @@ func (b *BufferQueue) GetOrCreateIssuerQueue(issuerID iotago.AccountID) *IssuerQ } // RemoveIssuerQueue removes all blocks (submitted and ready) for the given issuer and deletes the issuer queue. -func (b *BufferQueue) RemoveIssuerQueue(issuerID iotago.AccountID) { +func (b *BasicBuffer) RemoveIssuerQueue(issuerID iotago.AccountID) { element, ok := b.activeIssuers.Get(issuerID) if !ok { return @@ -134,7 +134,7 @@ func (b *BufferQueue) RemoveIssuerQueue(issuerID iotago.AccountID) { } // RemoveIssuerQueueIfEmpty removes all blocks (submitted and ready) for the given issuer and deletes the issuer queue if it is empty. -func (b *BufferQueue) RemoveIssuerQueueIfEmpty(issuerID iotago.AccountID) { +func (b *BasicBuffer) RemoveIssuerQueueIfEmpty(issuerID iotago.AccountID) { element, ok := b.activeIssuers.Get(issuerID) if !ok { return @@ -152,7 +152,7 @@ func (b *BufferQueue) RemoveIssuerQueueIfEmpty(issuerID iotago.AccountID) { // Submit submits a block. Return blocks dropped from the scheduler to make room for the submitted block. // The submitted block can also be returned as dropped if the issuer does not have enough mana. -func (b *BufferQueue) Submit(blk *blocks.Block, issuerQueue *IssuerQueue, quantumFunc func(iotago.AccountID) Deficit, maxBuffer int) ([]*blocks.Block, bool) { +func (b *BasicBuffer) Submit(blk *blocks.Block, issuerQueue *IssuerQueue, quantumFunc func(iotago.AccountID) Deficit, maxBuffer int) ([]*blocks.Block, bool) { // first we submit the block, and if it turns out that the issuer doesn't have enough bandwidth to submit, it will be removed by dropTail if !issuerQueue.Submit(blk) { return nil, false @@ -170,8 +170,8 @@ func (b *BufferQueue) Submit(blk *blocks.Block, issuerQueue *IssuerQueue, quantu // Unsubmit removes a block from the submitted blocks. // If that block is already marked as ready, Unsubmit has no effect. -func (b *BufferQueue) Unsubmit(block *blocks.Block) bool { - issuerID := block.ProtocolBlock().Header.IssuerID +func (b *BasicBuffer) Unsubmit(block *blocks.Block) bool { + issuerID := block.IssuerID() issuerQueue := b.IssuerQueue(issuerID) if issuerQueue == nil { @@ -188,8 +188,8 @@ func (b *BufferQueue) Unsubmit(block *blocks.Block) bool { } // Ready marks a previously submitted block as ready to be scheduled. -func (b *BufferQueue) Ready(block *blocks.Block) bool { - issuerQueue := b.IssuerQueue(block.ProtocolBlock().Header.IssuerID) +func (b *BasicBuffer) Ready(block *blocks.Block) bool { + issuerQueue := b.IssuerQueue(block.IssuerID()) if issuerQueue == nil { return false } @@ -198,7 +198,7 @@ func (b *BufferQueue) Ready(block *blocks.Block) bool { } // ReadyBlocksCount returns the number of ready blocks in the buffer. -func (b *BufferQueue) ReadyBlocksCount() (readyBlocksCount int) { +func (b *BasicBuffer) ReadyBlocksCount() (readyBlocksCount int) { start := b.Current() if start == nil { return @@ -216,7 +216,7 @@ func (b *BufferQueue) ReadyBlocksCount() (readyBlocksCount int) { } // TotalBlocksCount returns the number of blocks in the buffer. -func (b *BufferQueue) TotalBlocksCount() (blocksCount int) { +func (b *BasicBuffer) TotalBlocksCount() (blocksCount int) { start := b.Current() if start == nil { return @@ -234,7 +234,7 @@ func (b *BufferQueue) TotalBlocksCount() (blocksCount int) { } // Next returns the next IssuerQueue in round-robin order. -func (b *BufferQueue) Next() *IssuerQueue { +func (b *BasicBuffer) Next() *IssuerQueue { if b.ring != nil { b.ring = b.ring.Next() if issuerQueue, isIQ := b.ring.Value.(*IssuerQueue); isIQ { @@ -246,7 +246,7 @@ func (b *BufferQueue) Next() *IssuerQueue { } // Current returns the current IssuerQueue in round-robin order. -func (b *BufferQueue) Current() *IssuerQueue { +func (b *BasicBuffer) Current() *IssuerQueue { if b.ring == nil { return nil } @@ -258,7 +258,7 @@ func (b *BufferQueue) Current() *IssuerQueue { } // PopFront removes the first ready block from the queue of the current issuer. -func (b *BufferQueue) PopFront() *blocks.Block { +func (b *BasicBuffer) PopFront() *blocks.Block { q := b.Current() if q == nil { return nil @@ -275,7 +275,7 @@ func (b *BufferQueue) PopFront() *blocks.Block { } // IssuerIDs returns the issuerIDs of all issuers. -func (b *BufferQueue) IssuerIDs() []iotago.AccountID { +func (b *BasicBuffer) IssuerIDs() []iotago.AccountID { var issuerIDs []iotago.AccountID start := b.Current() if start == nil { @@ -292,7 +292,7 @@ func (b *BufferQueue) IssuerIDs() []iotago.AccountID { return issuerIDs } -func (b *BufferQueue) dropTail(quantumFunc func(iotago.AccountID) Deficit, maxBuffer int) (droppedBlocks []*blocks.Block) { +func (b *BasicBuffer) dropTail(quantumFunc func(iotago.AccountID) Deficit, maxBuffer int) (droppedBlocks []*blocks.Block) { // remove as many blocks as necessary to stay within max buffer size for b.Size() > maxBuffer { // find the longest mana-scaled queue @@ -308,7 +308,7 @@ func (b *BufferQueue) dropTail(quantumFunc func(iotago.AccountID) Deficit, maxBu return droppedBlocks } -func (b *BufferQueue) longestQueueIssuerID(quantumFunc func(iotago.AccountID) Deficit) iotago.AccountID { +func (b *BasicBuffer) longestQueueIssuerID(quantumFunc func(iotago.AccountID) Deficit) iotago.AccountID { start := b.Current() ringStart := b.ring maxScale := math.Inf(-1) @@ -335,7 +335,7 @@ func (b *BufferQueue) longestQueueIssuerID(quantumFunc func(iotago.AccountID) De return maxIssuerID } -func (b *BufferQueue) ringRemove(r *ring.Ring) { +func (b *BasicBuffer) ringRemove(r *ring.Ring) { n := b.ring.Next() if r == b.ring { if n == b.ring { @@ -347,7 +347,7 @@ func (b *BufferQueue) ringRemove(r *ring.Ring) { r.Prev().Link(n) } -func (b *BufferQueue) ringInsert(v interface{}) *ring.Ring { +func (b *BasicBuffer) ringInsert(v interface{}) *ring.Ring { p := ring.New(1) p.Value = v if b.ring == nil { @@ -358,13 +358,13 @@ func (b *BufferQueue) ringInsert(v interface{}) *ring.Ring { return p.Link(b.ring) } -func (b *BufferQueue) waitTime(rate float64, block *blocks.Block) time.Duration { +func (b *BasicBuffer) waitTime(rate float64, block *blocks.Block) time.Duration { tokensRequired := float64(block.WorkScore()) - (b.tokenBucket + rate*time.Since(b.lastScheduleTime).Seconds()) return lo.Max(0, time.Duration(tokensRequired/rate)) } -func (b *BufferQueue) updateTokenBucket(rate float64, tokenBucketSize float64) { +func (b *BasicBuffer) updateTokenBucket(rate float64, tokenBucketSize float64) { b.tokenBucket = lo.Min( tokenBucketSize, b.tokenBucket+rate*time.Since(b.lastScheduleTime).Seconds(), @@ -372,7 +372,7 @@ func (b *BufferQueue) updateTokenBucket(rate float64, tokenBucketSize float64) { b.lastScheduleTime = time.Now() } -func (b *BufferQueue) deductTokens(tokens float64) { +func (b *BasicBuffer) deductTokens(tokens float64) { b.tokenBucket -= tokens } diff --git a/pkg/protocol/engine/congestioncontrol/scheduler/drr/issuerqueue.go b/pkg/protocol/engine/congestioncontrol/scheduler/drr/issuerqueue.go index 80fc750b9..1a04772ce 100644 --- a/pkg/protocol/engine/congestioncontrol/scheduler/drr/issuerqueue.go +++ b/pkg/protocol/engine/congestioncontrol/scheduler/drr/issuerqueue.go @@ -61,7 +61,7 @@ func (q *IssuerQueue) IssuerID() iotago.AccountID { // Submit submits a block for the queue. func (q *IssuerQueue) Submit(element *blocks.Block) bool { // this is just a debugging check, it will never happen in practice - if blkIssuerID := element.ProtocolBlock().Header.IssuerID; q.issuerID != blkIssuerID { + if blkIssuerID := element.IssuerID(); q.issuerID != blkIssuerID { panic(fmt.Sprintf("issuerqueue: queue issuer ID(%x) and issuer ID(%x) does not match.", q.issuerID, blkIssuerID)) } diff --git a/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go b/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go index 445a6a7f3..3c20e4eca 100644 --- a/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go +++ b/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go @@ -35,7 +35,7 @@ type Scheduler struct { seatManager seatmanager.SeatManager - basicBuffer *BufferQueue + basicBuffer *BasicBuffer validatorBuffer *ValidatorBuffer bufferMutex syncutils.RWMutex @@ -55,7 +55,7 @@ func NewProvider(opts ...options.Option[Scheduler]) module.Provider[*engine.Engi return module.Provide(func(e *engine.Engine) scheduler.Scheduler { s := New(e.NewSubModule("Scheduler"), e, opts...) s.errorHandler = e.ErrorHandler("scheduler") - s.basicBuffer = NewBufferQueue() + s.basicBuffer = NewBasicBuffer() e.ConstructedEvent().OnTrigger(func() { s.latestCommittedSlot = func() iotago.SlotIndex { @@ -244,9 +244,9 @@ func (s *Scheduler) IsBlockIssuerReady(accountID iotago.AccountID, workScores .. } func (s *Scheduler) AddBlock(block *blocks.Block) { - if _, isValidation := block.ValidationBlock(); isValidation { + if block.IsValidationBlock() { s.enqueueValidationBlock(block) - } else if _, isBasic := block.BasicBlock(); isBasic { + } else if block.IsBasicBlock() { s.enqueueBasicBlock(block) } } @@ -273,7 +273,7 @@ func (s *Scheduler) enqueueBasicBlock(block *blocks.Block) { slot := s.latestCommittedSlot() - issuerID := block.ProtocolBlock().Header.IssuerID + issuerID := block.IssuerID() issuerQueue := s.getOrCreateIssuer(issuerID) droppedBlocks, submitted := s.basicBuffer.Submit( @@ -309,9 +309,9 @@ func (s *Scheduler) enqueueValidationBlock(block *blocks.Block) { s.bufferMutex.Lock() defer s.bufferMutex.Unlock() - _, exists := s.validatorBuffer.Get(block.ProtocolBlock().Header.IssuerID) + _, exists := s.validatorBuffer.Get(block.IssuerID()) if !exists { - s.addValidator(block.ProtocolBlock().Header.IssuerID) + s.addValidator(block.IssuerID()) } droppedBlock, submitted := s.validatorBuffer.Submit(block, int(s.apiProvider.CommittedAPI().ProtocolParameters().CongestionControlParameters().MaxValidationBufferSize)) if !submitted { @@ -492,7 +492,7 @@ func (s *Scheduler) selectBasicBlockWithoutLocking() { // remove the block from the buffer and adjust issuer's deficit block := s.basicBuffer.PopFront() - issuerID := block.ProtocolBlock().Header.IssuerID + issuerID := block.IssuerID() if _, err := s.updateDeficit(issuerID, -s.deficitFromWork(block.WorkScore())); err != nil { // if something goes wrong with deficit update, drop the block instead of scheduling it. block.SetDropped() @@ -526,7 +526,7 @@ func (s *Scheduler) selectIssuer(start *IssuerQueue, slot iotago.SlotIndex) (Def continue } - issuerID := block.ProtocolBlock().Header.IssuerID + issuerID := block.IssuerID() // compute how often the deficit needs to be incremented until the block can be scheduled deficit, exists := s.deficits.Get(issuerID) @@ -696,7 +696,7 @@ func (s *Scheduler) ready(block *blocks.Block) { } func (s *Scheduler) readyValidationBlock(block *blocks.Block) { - if validatorQueue, exists := s.validatorBuffer.Get(block.ProtocolBlock().Header.IssuerID); exists { + if validatorQueue, exists := s.validatorBuffer.Get(block.IssuerID()); exists { validatorQueue.Ready(block) } } @@ -715,11 +715,12 @@ func (s *Scheduler) updateChildrenWithLocking(block *blocks.Block) { func (s *Scheduler) updateChildrenWithoutLocking(block *blocks.Block) { block.Children().Range(func(childBlock *blocks.Block) { if _, childBlockExists := s.blockCache.Block(childBlock.ID()); childBlockExists && childBlock.IsEnqueued() { - if _, isBasic := childBlock.BasicBlock(); isBasic { + switch { + case childBlock.IsBasicBlock(): s.tryReady(childBlock) - } else if _, isValidation := childBlock.ValidationBlock(); isValidation { + case childBlock.IsValidationBlock(): s.tryReadyValidationBlock(childBlock) - } else { + default: panic("invalid block type") } } diff --git a/pkg/protocol/engine/congestioncontrol/scheduler/drr/validatorqueue.go b/pkg/protocol/engine/congestioncontrol/scheduler/drr/validatorqueue.go index f327ae556..15f08a5bc 100644 --- a/pkg/protocol/engine/congestioncontrol/scheduler/drr/validatorqueue.go +++ b/pkg/protocol/engine/congestioncontrol/scheduler/drr/validatorqueue.go @@ -53,7 +53,7 @@ func (q *ValidatorQueue) AccountID() iotago.AccountID { } func (q *ValidatorQueue) Submit(block *blocks.Block, maxBuffer int) (*blocks.Block, bool) { - if blkAccountID := block.ProtocolBlock().Header.IssuerID; q.accountID != blkAccountID { + if blkAccountID := block.IssuerID(); q.accountID != blkAccountID { panic(fmt.Sprintf("issuerqueue: queue issuer ID(%x) and issuer ID(%x) does not match.", q.accountID, blkAccountID)) } @@ -202,7 +202,7 @@ func (b *ValidatorBuffer) Set(accountID iotago.AccountID, validatorQueue *Valida } func (b *ValidatorBuffer) Submit(block *blocks.Block, maxBuffer int) (*blocks.Block, bool) { - validatorQueue, exists := b.buffer.Get(block.ProtocolBlock().Header.IssuerID) + validatorQueue, exists := b.buffer.Get(block.IssuerID()) if !exists { return nil, false } diff --git a/pkg/protocol/engine/consensus/blockgadget/thresholdblockgadget/gadget.go b/pkg/protocol/engine/consensus/blockgadget/thresholdblockgadget/gadget.go index 493ff97b5..7422ba1cc 100644 --- a/pkg/protocol/engine/consensus/blockgadget/thresholdblockgadget/gadget.go +++ b/pkg/protocol/engine/consensus/blockgadget/thresholdblockgadget/gadget.go @@ -99,7 +99,7 @@ func (g *Gadget) propagate(initialBlockIDs iotago.BlockIDs, evaluateFunc func(bl } func (g *Gadget) isCommitteeValidationBlock(block *blocks.Block) (seat account.SeatIndex, isValid bool) { - if _, isValidationBlock := block.ValidationBlock(); !isValidationBlock { + if !block.IsValidationBlock() { return 0, false } @@ -111,7 +111,7 @@ func (g *Gadget) isCommitteeValidationBlock(block *blocks.Block) (seat account.S } // Only accept blocks for issuers that are part of the committee. - return committee.GetSeat(block.ProtocolBlock().Header.IssuerID) + return committee.GetSeat(block.IssuerID()) } func anyChildInSet(block *blocks.Block, set ds.Set[iotago.BlockID]) bool { diff --git a/pkg/protocol/engine/consensus/slotgadget/totalweightslotgadget/gadget.go b/pkg/protocol/engine/consensus/slotgadget/totalweightslotgadget/gadget.go index 84dd24ec8..0404d11a4 100644 --- a/pkg/protocol/engine/consensus/slotgadget/totalweightslotgadget/gadget.go +++ b/pkg/protocol/engine/consensus/slotgadget/totalweightslotgadget/gadget.go @@ -110,7 +110,7 @@ func (g *Gadget) trackVotes(block *blocks.Block) { tracker, _ := g.slotTrackers.GetOrCreate(block.ID().Slot(), slottracker.NewSlotTracker) - prevLatestSlot, latestSlot, updated := tracker.TrackVotes(block.SlotCommitmentID().Slot(), block.ProtocolBlock().Header.IssuerID, g.lastFinalizedSlot) + prevLatestSlot, latestSlot, updated := tracker.TrackVotes(block.SlotCommitmentID().Slot(), block.IssuerID(), g.lastFinalizedSlot) if !updated { return nil } diff --git a/pkg/protocol/engine/filter/postsolidfilter/postsolidblockfilter/post_solid_block_filter.go b/pkg/protocol/engine/filter/postsolidfilter/postsolidblockfilter/post_solid_block_filter.go index dc2a04252..dcfd17d8f 100644 --- a/pkg/protocol/engine/filter/postsolidfilter/postsolidblockfilter/post_solid_block_filter.go +++ b/pkg/protocol/engine/filter/postsolidfilter/postsolidblockfilter/post_solid_block_filter.go @@ -95,11 +95,11 @@ func (c *PostSolidBlockFilter) ProcessSolidBlock(block *blocks.Block) { // Perform account related checks. { // check if the account exists in the specified slot. - accountData, exists, err := c.accountRetrieveFunc(block.ProtocolBlock().Header.IssuerID, block.SlotCommitmentID().Slot()) + accountData, exists, err := c.accountRetrieveFunc(block.IssuerID(), block.SlotCommitmentID().Slot()) if err != nil { c.filterBlock( block, - ierrors.WithMessagef(iotago.ErrIssuerAccountNotFound, "could not retrieve account information for block issuer %s: %w", block.ProtocolBlock().Header.IssuerID, err), + ierrors.WithMessagef(iotago.ErrIssuerAccountNotFound, "could not retrieve account information for block issuer %s: %w", block.IssuerID(), err), ) return @@ -107,7 +107,7 @@ func (c *PostSolidBlockFilter) ProcessSolidBlock(block *blocks.Block) { if !exists { c.filterBlock( block, - ierrors.WithMessagef(iotago.ErrIssuerAccountNotFound, "block issuer account %s does not exist in slot commitment %s", block.ProtocolBlock().Header.IssuerID, block.ProtocolBlock().Header.SlotCommitmentID.Slot()), + ierrors.WithMessagef(iotago.ErrIssuerAccountNotFound, "block issuer account %s does not exist in slot commitment %s", block.IssuerID(), block.ProtocolBlock().Header.SlotCommitmentID.Slot()), ) return @@ -136,7 +136,7 @@ func (c *PostSolidBlockFilter) ProcessSolidBlock(block *blocks.Block) { if basicBlock.MaxBurnedMana < manaCost { c.filterBlock( block, - ierrors.WithMessagef(iotago.ErrBurnedInsufficientMana, "block issuer account %s burned insufficient Mana, required %d, burned %d", block.ProtocolBlock().Header.IssuerID, manaCost, basicBlock.MaxBurnedMana), + ierrors.WithMessagef(iotago.ErrBurnedInsufficientMana, "block issuer account %s burned insufficient Mana, required %d, burned %d", block.IssuerID(), manaCost, basicBlock.MaxBurnedMana), ) return @@ -149,7 +149,7 @@ func (c *PostSolidBlockFilter) ProcessSolidBlock(block *blocks.Block) { if accountData.Credits.Value < 0 { c.filterBlock( block, - ierrors.WithMessagef(iotago.ErrAccountLocked, "block issuer account %s", block.ProtocolBlock().Header.IssuerID), + ierrors.WithMessagef(iotago.ErrAccountLocked, "block issuer account %s", block.IssuerID()), ) return @@ -161,7 +161,7 @@ func (c *PostSolidBlockFilter) ProcessSolidBlock(block *blocks.Block) { if accountData.ExpirySlot < block.ProtocolBlock().Header.SlotCommitmentID.Slot() { c.filterBlock( block, - ierrors.WithMessagef(iotago.ErrAccountExpired, "block issuer account %s is expired, expiry slot %d in commitment %d", block.ProtocolBlock().Header.IssuerID, accountData.ExpirySlot, block.ProtocolBlock().Header.SlotCommitmentID.Slot()), + ierrors.WithMessagef(iotago.ErrAccountExpired, "block issuer account %s is expired, expiry slot %d in commitment %d", block.IssuerID(), accountData.ExpirySlot, block.ProtocolBlock().Header.SlotCommitmentID.Slot()), ) return @@ -177,7 +177,7 @@ func (c *PostSolidBlockFilter) ProcessSolidBlock(block *blocks.Block) { if !accountData.BlockIssuerKeys.Has(expectedBlockIssuerKey) { c.filterBlock( block, - ierrors.WithMessagef(iotago.ErrInvalidSignature, "block issuer account %s does not have block issuer key corresponding to public key %s in slot %d", block.ProtocolBlock().Header.IssuerID, hexutil.EncodeHex(signature.PublicKey[:]), block.ProtocolBlock().Header.SlotCommitmentID.Index()), + ierrors.WithMessagef(iotago.ErrInvalidSignature, "block issuer account %s does not have block issuer key corresponding to public key %s in slot %d", block.IssuerID(), hexutil.EncodeHex(signature.PublicKey[:]), block.ProtocolBlock().Header.SlotCommitmentID.Index()), ) return diff --git a/pkg/protocol/engine/ledger/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger/ledger.go index 7fb5ae31d..bb9b72f4b 100644 --- a/pkg/protocol/engine/ledger/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger/ledger.go @@ -758,7 +758,7 @@ func (l *Ledger) resolveState(stateRef mempool.StateReference) *promise.Promise[ } func (l *Ledger) blockPreAccepted(block *blocks.Block) { - if _, isValidationBlock := block.ValidationBlock(); !isValidationBlock { + if !block.IsValidationBlock() { return } @@ -769,7 +769,7 @@ func (l *Ledger) blockPreAccepted(block *blocks.Block) { panic("committee should exist because we pre-accepted the block") } - seat, exists := committee.GetSeat(block.ProtocolBlock().Header.IssuerID) + seat, exists := committee.GetSeat(block.IssuerID()) if !exists { return } diff --git a/pkg/protocol/engine/tipmanager/v1/tip_manager.go b/pkg/protocol/engine/tipmanager/v1/tip_manager.go index 814d3e788..dc701ed2d 100644 --- a/pkg/protocol/engine/tipmanager/v1/tip_manager.go +++ b/pkg/protocol/engine/tipmanager/v1/tip_manager.go @@ -217,7 +217,7 @@ func (t *TipManager) trackTipMetadata(tipMetadata *TipMetadata) { // trackLatestValidationBlock tracks the latest validator block and takes care of marking the corresponding TipMetadata. func (t *TipManager) trackLatestValidationBlock(tipMetadata *TipMetadata) (teardown func()) { - if _, isValidationBlock := tipMetadata.Block().ValidationBlock(); !isValidationBlock { + if !tipMetadata.Block().IsValidationBlock() { return nil } @@ -226,7 +226,7 @@ func (t *TipManager) trackLatestValidationBlock(tipMetadata *TipMetadata) (teard return nil } - seat, exists := committee.GetSeat(tipMetadata.Block().ProtocolBlock().Header.IssuerID) + seat, exists := committee.GetSeat(tipMetadata.Block().IssuerID()) if !exists { return nil } diff --git a/pkg/protocol/engine/upgrade/signalingupgradeorchestrator/orchestrator.go b/pkg/protocol/engine/upgrade/signalingupgradeorchestrator/orchestrator.go index 300aec42a..d2997e1dd 100644 --- a/pkg/protocol/engine/upgrade/signalingupgradeorchestrator/orchestrator.go +++ b/pkg/protocol/engine/upgrade/signalingupgradeorchestrator/orchestrator.go @@ -163,7 +163,7 @@ func (o *Orchestrator) TrackValidationBlock(block *blocks.Block) { return } - seat, exists := committee.GetSeat(block.ProtocolBlock().Header.IssuerID) + seat, exists := committee.GetSeat(block.IssuerID()) if !exists { return } diff --git a/pkg/protocol/sybilprotection/seatmanager/poa/poa.go b/pkg/protocol/sybilprotection/seatmanager/poa/poa.go index f2d8e976b..73cfd40f3 100644 --- a/pkg/protocol/sybilprotection/seatmanager/poa/poa.go +++ b/pkg/protocol/sybilprotection/seatmanager/poa/poa.go @@ -50,9 +50,9 @@ func NewProvider(opts ...options.Option[SeatManager]) module.Provider[*engine.En panic(ierrors.Errorf("committee not selected for slot %d, but received block in that slot", block.ID().Slot())) } - seat, exists := committee.GetSeat(block.ProtocolBlock().Header.IssuerID) + seat, exists := committee.GetSeat(block.IssuerID()) if exists { - s.activityTracker.MarkSeatActive(seat, block.ProtocolBlock().Header.IssuerID, block.IssuingTime()) + s.activityTracker.MarkSeatActive(seat, block.IssuerID(), block.IssuingTime()) } s.events.BlockProcessed.Trigger(block) diff --git a/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers.go b/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers.go index 27f8304a9..4f7538122 100644 --- a/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers.go +++ b/pkg/protocol/sybilprotection/seatmanager/topstakers/topstakers.go @@ -51,9 +51,9 @@ func NewProvider(opts ...options.Option[SeatManager]) module.Provider[*engine.En panic(ierrors.Errorf("committee not selected for slot %d, but received block in that slot", block.ID().Slot())) } - seat, exists := committee.GetSeat(block.ProtocolBlock().Header.IssuerID) + seat, exists := committee.GetSeat(block.IssuerID()) if exists { - s.activityTracker.MarkSeatActive(seat, block.ProtocolBlock().Header.IssuerID, block.IssuingTime()) + s.activityTracker.MarkSeatActive(seat, block.IssuerID(), block.IssuingTime()) } s.events.BlockProcessed.Trigger(block) diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go index 1f0c5aef0..5e19ec195 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go @@ -88,9 +88,9 @@ func (t *Tracker) TrackValidationBlock(block *blocks.Block) { t.performanceFactorsMutex.Lock() defer t.performanceFactorsMutex.Unlock() - isCommitteeMember, err := t.isCommitteeMember(block.ID().Slot(), block.ProtocolBlock().Header.IssuerID) + isCommitteeMember, err := t.isCommitteeMember(block.ID().Slot(), block.IssuerID()) if err != nil { - t.errHandler(ierrors.Wrapf(err, "error while checking if account %s is a committee member in slot %d", block.ProtocolBlock().Header.IssuerID, block.ID().Slot())) + t.errHandler(ierrors.Wrapf(err, "error while checking if account %s is a committee member in slot %d", block.IssuerID(), block.ID().Slot())) return } @@ -111,7 +111,7 @@ func (t *Tracker) TrackCandidateBlock(block *blocks.Block) { blockEpoch := t.apiProvider.APIForSlot(block.ID().Slot()).TimeProvider().EpochFromSlot(block.ID().Slot()) var rollback bool - t.nextEpochCommitteeCandidates.Compute(block.ProtocolBlock().Header.IssuerID, func(currentValue iotago.SlotIndex, exists bool) iotago.SlotIndex { + t.nextEpochCommitteeCandidates.Compute(block.IssuerID(), func(currentValue iotago.SlotIndex, exists bool) iotago.SlotIndex { if !exists || currentValue > block.ID().Slot() { committeeCandidatesStore, err := t.committeeCandidatesInEpochFunc(blockEpoch) if err != nil { @@ -124,7 +124,7 @@ func (t *Tracker) TrackCandidateBlock(block *blocks.Block) { return currentValue } - err = committeeCandidatesStore.Set(block.ProtocolBlock().Header.IssuerID, block.ID().Slot()) + err = committeeCandidatesStore.Set(block.IssuerID(), block.ID().Slot()) if err != nil { // if there is an error, and we don't register a candidate, then we might eventually create a different commitment t.errHandler(ierrors.Wrapf(err, "error while updating candidate activity for epoch %d", blockEpoch)) @@ -144,7 +144,7 @@ func (t *Tracker) TrackCandidateBlock(block *blocks.Block) { // if there was an error when computing the value, // and it was the first entry for the given issuer, then remove the entry if rollback { - t.nextEpochCommitteeCandidates.Delete(block.ProtocolBlock().Header.IssuerID) + t.nextEpochCommitteeCandidates.Delete(block.IssuerID()) } } @@ -346,9 +346,9 @@ func (t *Tracker) trackCommitteeMemberPerformance(validationBlock *iotago.Valida return } - validatorPerformance, exists, err := validatorPerformances.Load(block.ProtocolBlock().Header.IssuerID) + validatorPerformance, exists, err := validatorPerformances.Load(block.IssuerID()) if err != nil { - t.errHandler(ierrors.Errorf("failed to load performance factor for account %s", block.ProtocolBlock().Header.IssuerID)) + t.errHandler(ierrors.Errorf("failed to load performance factor for account %s", block.IssuerID())) return } @@ -375,8 +375,8 @@ func (t *Tracker) trackCommitteeMemberPerformance(validationBlock *iotago.Valida Hash: validationBlock.ProtocolParametersHash, } - if err = validatorPerformances.Store(block.ProtocolBlock().Header.IssuerID, validatorPerformance); err != nil { - t.errHandler(ierrors.Errorf("failed to store performance factor for account %s", block.ProtocolBlock().Header.IssuerID)) + if err = validatorPerformances.Store(block.IssuerID(), validatorPerformance); err != nil { + t.errHandler(ierrors.Errorf("failed to store performance factor for account %s", block.IssuerID())) } } diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go index 4a4f3f393..25b82dc89 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go @@ -105,7 +105,7 @@ func New(subModule module.Module, engine *engine.Engine, opts ...options.Option[ } func (o *SybilProtection) TrackBlock(block *blocks.Block) { - if _, isValidationBlock := block.ValidationBlock(); isValidationBlock { + if block.IsValidationBlock() { o.performanceTracker.TrackValidationBlock(block) return @@ -115,9 +115,9 @@ func (o *SybilProtection) TrackBlock(block *blocks.Block) { return } - accountData, exists, err := o.ledger.Account(block.ProtocolBlock().Header.IssuerID, block.SlotCommitmentID().Slot()) + accountData, exists, err := o.ledger.Account(block.IssuerID(), block.SlotCommitmentID().Slot()) if err != nil { - o.errHandler(ierrors.Wrapf(err, "error while retrieving data for account %s in slot %d from accounts ledger", block.ProtocolBlock().Header.IssuerID, block.SlotCommitmentID().Slot())) + o.errHandler(ierrors.Wrapf(err, "error while retrieving data for account %s in slot %d from accounts ledger", block.IssuerID(), block.SlotCommitmentID().Slot())) return } diff --git a/pkg/tests/protocol_engine_switching_test.go b/pkg/tests/protocol_engine_switching_test.go index 7a6a3d01d..f7b93ffe3 100644 --- a/pkg/tests/protocol_engine_switching_test.go +++ b/pkg/tests/protocol_engine_switching_test.go @@ -1037,7 +1037,7 @@ func TestProtocol_EngineSwitching_Tie(t *testing.T) { e.ConstructedEvent().OnTrigger(func() { e.Events.PostSolidFilter.BlockAllowed.Hook(func(block *blocks.Block) { - if node, exists := validatorsByAccountID[block.ModelBlock().ProtocolBlock().Header.IssuerID]; exists && onlineValidators.Add(node.Name) { + if node, exists := validatorsByAccountID[block.IssuerID()]; exists && onlineValidators.Add(node.Name) { e.LogError("node online", "name", node.Name) poa.SetOnline(onlineValidators.ToSlice()...) } diff --git a/pkg/tests/protocol_eviction_test.go b/pkg/tests/protocol_eviction_test.go index ec2d0561f..bd5daa536 100644 --- a/pkg/tests/protocol_eviction_test.go +++ b/pkg/tests/protocol_eviction_test.go @@ -72,7 +72,7 @@ func TestProtocol_Eviction(t *testing.T) { e.ConstructedEvent().OnTrigger(func() { e.Events.BlockDAG.BlockAppended.Hook(func(block *blocks.Block) { - if block.ModelBlock().ProtocolBlock().Header.IssuerID == node.Validator.AccountData.ID && onlineValidators.Add(node.Name) { + if block.IssuerID() == node.Validator.AccountData.ID && onlineValidators.Add(node.Name) { e.LogError("node online", "name", node.Name) poa.SetOnline(onlineValidators.ToSlice()...) }