From 42ab4fd8b8c083b895c6bb09677ae94d5d577c00 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:39:15 +0100 Subject: [PATCH] Orphan non-accepted blocks before force-committing a slot. --- pkg/protocol/block_dispatcher.go | 1 + .../engine/notarization/slotnotarization/manager.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/protocol/block_dispatcher.go b/pkg/protocol/block_dispatcher.go index 4e70c1f9a..cb9684439 100644 --- a/pkg/protocol/block_dispatcher.go +++ b/pkg/protocol/block_dispatcher.go @@ -323,6 +323,7 @@ func (b *BlockDispatcher) processWarpSyncResponse(commitmentID iotago.Commitment if len(blockIDs) == 0 { forceCommitmentFunc() + return nil } diff --git a/pkg/protocol/engine/notarization/slotnotarization/manager.go b/pkg/protocol/engine/notarization/slotnotarization/manager.go index 0b033661b..3b3c3c3a9 100644 --- a/pkg/protocol/engine/notarization/slotnotarization/manager.go +++ b/pkg/protocol/engine/notarization/slotnotarization/manager.go @@ -15,6 +15,7 @@ import ( "github.com/iotaledger/iota-core/pkg/protocol/engine/blocks" "github.com/iotaledger/iota-core/pkg/protocol/engine/ledger" "github.com/iotaledger/iota-core/pkg/protocol/engine/notarization" + "github.com/iotaledger/iota-core/pkg/protocol/engine/tipselection" "github.com/iotaledger/iota-core/pkg/protocol/engine/upgrade" "github.com/iotaledger/iota-core/pkg/protocol/sybilprotection" "github.com/iotaledger/iota-core/pkg/storage" @@ -34,6 +35,7 @@ type Manager struct { ledger ledger.Ledger sybilProtection sybilprotection.SybilProtection upgradeOrchestrator upgrade.Orchestrator + tipSelection tipselection.TipSelection storage *storage.Storage @@ -57,6 +59,7 @@ func NewProvider() module.Provider[*engine.Engine, notarization.Notarization] { m.ledger = e.Ledger m.sybilProtection = e.SybilProtection + m.tipSelection = e.TipSelection m.attestation = e.Attestations m.upgradeOrchestrator = e.UpgradeOrchestrator @@ -111,6 +114,15 @@ func (m *Manager) ForceCommit(slot iotago.SlotIndex) (*model.Commitment, error) return nil, ierrors.New("notarization manager was stopped") } + // When force committing set acceptance time in TipSelection to the end of the epoch + // that is LivenessThresholdUpperBound in the future from the committed slot, + // so that all the unaccepted blocks in force committed slot are orphaned. + // The value must be at least LivenessThresholdUpperBound in the future. + // This is to avoid the situation in which future cone of those blocks becomes accepted after force-committing the slot. + // This would cause issues with consistency as it's impossible to add blocks to a committed slot. + artificialAcceptanceTime := m.apiProvider.APIForSlot(slot).TimeProvider().SlotEndTime(slot).Add(m.apiProvider.APIForSlot(slot).ProtocolParameters().LivenessThresholdUpperBound()) + m.tipSelection.SetAcceptanceTime(artificialAcceptanceTime) + commitment, err := m.createCommitment(slot) if err != nil { return nil, ierrors.Wrapf(err, "failed to create commitment for slot %d", slot)