Skip to content

Commit

Permalink
Merge pull request #539 from iotaledger/fix/revive-chain-force-commit…
Browse files Browse the repository at this point in the history
…ment

Fix bugs when force committing slots.
  • Loading branch information
alexsporn authored Nov 21, 2023
2 parents 909a664 + bd8a3e1 commit 7f23ac6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/protocol/block_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func (b *BlockDispatcher) processWarpSyncResponse(commitmentID iotago.Commitment

if len(blockIDs) == 0 {
forceCommitmentFunc()

return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/protocol/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ func (e *Engine) acceptanceHandler() {
e.Ledger.TrackBlock(block)
e.SybilProtection.TrackBlock(block)
e.UpgradeOrchestrator.TrackValidationBlock(block)
e.TipSelection.SetAcceptanceTime(block.IssuingTime())

e.Events.AcceptedBlockProcessed.Trigger(block)
}, event.WithWorkerPool(wp))
Expand Down
12 changes: 12 additions & 0 deletions pkg/protocol/engine/notarization/slotnotarization/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,6 +35,7 @@ type Manager struct {
ledger ledger.Ledger
sybilProtection sybilprotection.SybilProtection
upgradeOrchestrator upgrade.Orchestrator
tipSelection tipselection.TipSelection

storage *storage.Storage

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions pkg/protocol/engine/tipselection/v1/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/iotaledger/hive.go/runtime/module"
"github.com/iotaledger/hive.go/runtime/options"
"github.com/iotaledger/iota-core/pkg/protocol/engine"
"github.com/iotaledger/iota-core/pkg/protocol/engine/blocks"
"github.com/iotaledger/iota-core/pkg/protocol/engine/tipmanager"
"github.com/iotaledger/iota-core/pkg/protocol/engine/tipselection"
iotago "github.com/iotaledger/iota.go/v4"
Expand All @@ -23,10 +22,6 @@ func NewProvider(opts ...options.Option[TipSelection]) module.Provider[*engine.E
// wait for submodules to be constructed (so all of their properties are available)
module.OnAllConstructed(func() {
t.Construct(e.TipManager, e.Ledger.ConflictDAG(), e.Ledger.MemPool().TransactionMetadata, func() iotago.BlockIDs { return lo.Keys(e.EvictionState.ActiveRootBlocks()) }, DynamicLivenessThreshold(e.SybilProtection.SeatManager().OnlineCommittee().Size))

e.Events.AcceptedBlockProcessed.Hook(func(block *blocks.Block) {
t.SetAcceptanceTime(block.IssuingTime())
})
}, e.TipManager, e.Ledger, e.SybilProtection)
})

Expand Down

0 comments on commit 7f23ac6

Please sign in to comment.