Skip to content

Commit

Permalink
Fix force commitment condition
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrm50 committed Apr 2, 2024
1 parent 1c97475 commit 04ae074
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions components/inx/server_commitments.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,11 @@ func (s *Server) ForceCommitUntil(_ context.Context, slot *inx.SlotRequest) (*in
// If the chain manager is aware of a commitments on the main chain, then do not force commit.
// The node should wait to warpsync those slots and use those commitments to avoid potentially creating a diverging commitment.
unwrappedSlot := slot.Unwrap()
protocolParams := deps.Protocol.APIForSlot(unwrappedSlot).ProtocolParameters()
if latestChainCommitment := deps.Protocol.Chains.Main.Get().LatestCommitment.Get(); unwrappedSlot > protocolParams.MaxCommittableAge() &&
latestChainCommitment.Slot() < unwrappedSlot-protocolParams.MaxCommittableAge() {
if latestChainCommitment := deps.Protocol.Chains.Main.Get().LatestCommitment.Get(); latestChainCommitment.Slot() >= unwrappedSlot {
return nil, ierrors.Errorf("chain manager is aware of a newer commitment (%s) than target slot %d", latestChainCommitment, unwrappedSlot)
}

err := deps.Protocol.Engines.Main.Get().Notarization.ForceCommitUntil(slot.Unwrap())
err := deps.Protocol.Engines.Main.Get().Notarization.ForceCommitUntil(unwrappedSlot)
if err != nil {
return nil, ierrors.Wrapf(err, "error while performing force commit until %d", slot.GetSlot())
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/testsuite/mock/blockissuer_acceptance_loss.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func (i *BlockIssuer) reviveChain(issuingTime time.Time, node *Node) (*iotago.Co

// If the chain manager is aware of a commitments on the main chain, then do not force commit.
// The node should wait to warpsync those slots and use those commitments to avoid potentially creating a diverging commitment.
if issuingSlot > apiForSlot.ProtocolParameters().MaxCommittableAge() &&
node.Protocol.Chains.Main.Get().LatestCommitment.Get().Slot() < issuingSlot-apiForSlot.ProtocolParameters().MaxCommittableAge() {
return nil, iotago.EmptyBlockID, ierrors.Errorf("chain manager is aware of a newer commitment, slot: %d, minCommittableAge: %d", issuingSlot, apiForSlot.ProtocolParameters().MinCommittableAge())
if issuingSlot > apiForSlot.ProtocolParameters().MinCommittableAge() &&
node.Protocol.Chains.Main.Get().LatestCommitment.Get().Slot() >= issuingSlot-apiForSlot.ProtocolParameters().MinCommittableAge() {
return nil, iotago.EmptyBlockID, ierrors.Errorf("chain manager is aware of a newer commitment, slot: %d, minCommittableAge: %d", issuingSlot-apiForSlot.ProtocolParameters().MinCommittableAge(), apiForSlot.ProtocolParameters().MinCommittableAge())
}

// Force commitments until minCommittableAge relative to the block's issuing time. We basically "pretend" that
Expand Down

0 comments on commit 04ae074

Please sign in to comment.