From afcca2ef4713d7212ad1e1a2cb9dcbf519b17c9f Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Thu, 25 Apr 2024 17:18:40 +0200 Subject: [PATCH 1/2] Do not export a newer finalized slot than the target slot of a snapshot --- pkg/storage/permanent/settings.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pkg/storage/permanent/settings.go b/pkg/storage/permanent/settings.go index 092bd5098..462a6f13b 100644 --- a/pkg/storage/permanent/settings.go +++ b/pkg/storage/permanent/settings.go @@ -362,23 +362,22 @@ func (s *Settings) SetLatestIssuedValidationBlock(block *model.Block) (err error } func (s *Settings) Export(writer io.WriteSeeker, targetCommitment *iotago.Commitment) error { - var commitmentBytes []byte - var err error - if targetCommitment != nil { - // We always know the version of the target commitment, so there can be no error. - commitmentBytes, err = lo.PanicOnErr(s.apiProvider.APIForVersion(targetCommitment.ProtocolVersion)).Encode(targetCommitment) - if err != nil { - return ierrors.Wrap(err, "failed to encode target commitment") - } - } else { - commitmentBytes = s.LatestCommitment().Data() + // We always know the version of the target commitment, so there can be no error. + commitmentBytes, err := lo.PanicOnErr(s.apiProvider.APIForVersion(targetCommitment.ProtocolVersion)).Encode(targetCommitment) + if err != nil { + return ierrors.Wrap(err, "failed to encode target commitment") } if err := stream.WriteBytesWithSize(writer, commitmentBytes, serializer.SeriLengthPrefixTypeAsUint16); err != nil { return ierrors.Wrap(err, "failed to write commitment") } - if err := stream.Write(writer, s.LatestFinalizedSlot()); err != nil { + latestFinalizedSlot := s.LatestFinalizedSlot() + if latestFinalizedSlot > targetCommitment.Slot { + latestFinalizedSlot = targetCommitment.Slot + } + + if err := stream.Write(writer, latestFinalizedSlot); err != nil { return ierrors.Wrap(err, "failed to write latest finalized slot") } From c88d908e55e9b62d71e9f6ac299aded535ad8878 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Thu, 25 Apr 2024 17:20:01 +0200 Subject: [PATCH 2/2] Added extended info to error message --- pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go b/pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go index 1217093ec..0067c0a97 100644 --- a/pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go +++ b/pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go @@ -213,7 +213,7 @@ func (b *BlockDAG) shouldAppend(modelBlock *model.Block) (shouldAppend bool, err func (b *BlockDAG) canAppendToParents(modelBlock *model.Block) (parentsValid bool, err error) { for _, parent := range modelBlock.ProtocolBlock().ParentsWithType() { if isBelowRange, isInRange := b.evictionState.BelowOrInActiveRootBlockRange(parent.ID); isBelowRange || isInRange && !b.evictionState.IsActiveRootBlock(parent.ID) { - return false, ierrors.Errorf("parent %s with type %s of block %s is too old", parent.ID, parent.Type, modelBlock.ID()) + return false, ierrors.Errorf("parent %s with type %s of block %s is too old (isBelowRange: %t, isInRange: %t, isActiveRootBlock: %t)", parent.ID, parent.Type, modelBlock.ID(), isBelowRange, isInRange, b.evictionState.IsActiveRootBlock(parent.ID)) } }