From 04ae0744c21086def1422278ba508873707ee515 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:34:29 +0200 Subject: [PATCH] Fix force commitment condition --- components/inx/server_commitments.go | 6 ++---- pkg/testsuite/mock/blockissuer_acceptance_loss.go | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/components/inx/server_commitments.go b/components/inx/server_commitments.go index 298c15b9f..b4cbfa165 100644 --- a/components/inx/server_commitments.go +++ b/components/inx/server_commitments.go @@ -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()) } diff --git a/pkg/testsuite/mock/blockissuer_acceptance_loss.go b/pkg/testsuite/mock/blockissuer_acceptance_loss.go index cf7afb7d9..634f61ead 100644 --- a/pkg/testsuite/mock/blockissuer_acceptance_loss.go +++ b/pkg/testsuite/mock/blockissuer_acceptance_loss.go @@ -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