Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit e0c5e67

Browse files
authored
Merge pull request #938 from iotaledger/feat/fixed-snapshot-export
Do not export a newer finalized slot than the target slot of a snapshot
2 parents 80baf80 + c88d908 commit e0c5e67

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (b *BlockDAG) shouldAppend(modelBlock *model.Block) (shouldAppend bool, err
213213
func (b *BlockDAG) canAppendToParents(modelBlock *model.Block) (parentsValid bool, err error) {
214214
for _, parent := range modelBlock.ProtocolBlock().ParentsWithType() {
215215
if isBelowRange, isInRange := b.evictionState.BelowOrInActiveRootBlockRange(parent.ID); isBelowRange || isInRange && !b.evictionState.IsActiveRootBlock(parent.ID) {
216-
return false, ierrors.Errorf("parent %s with type %s of block %s is too old", parent.ID, parent.Type, modelBlock.ID())
216+
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))
217217
}
218218
}
219219

pkg/storage/permanent/settings.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,23 +362,22 @@ func (s *Settings) SetLatestIssuedValidationBlock(block *model.Block) (err error
362362
}
363363

364364
func (s *Settings) Export(writer io.WriteSeeker, targetCommitment *iotago.Commitment) error {
365-
var commitmentBytes []byte
366-
var err error
367-
if targetCommitment != nil {
368-
// We always know the version of the target commitment, so there can be no error.
369-
commitmentBytes, err = lo.PanicOnErr(s.apiProvider.APIForVersion(targetCommitment.ProtocolVersion)).Encode(targetCommitment)
370-
if err != nil {
371-
return ierrors.Wrap(err, "failed to encode target commitment")
372-
}
373-
} else {
374-
commitmentBytes = s.LatestCommitment().Data()
365+
// We always know the version of the target commitment, so there can be no error.
366+
commitmentBytes, err := lo.PanicOnErr(s.apiProvider.APIForVersion(targetCommitment.ProtocolVersion)).Encode(targetCommitment)
367+
if err != nil {
368+
return ierrors.Wrap(err, "failed to encode target commitment")
375369
}
376370

377371
if err := stream.WriteBytesWithSize(writer, commitmentBytes, serializer.SeriLengthPrefixTypeAsUint16); err != nil {
378372
return ierrors.Wrap(err, "failed to write commitment")
379373
}
380374

381-
if err := stream.Write(writer, s.LatestFinalizedSlot()); err != nil {
375+
latestFinalizedSlot := s.LatestFinalizedSlot()
376+
if latestFinalizedSlot > targetCommitment.Slot {
377+
latestFinalizedSlot = targetCommitment.Slot
378+
}
379+
380+
if err := stream.Write(writer, latestFinalizedSlot); err != nil {
382381
return ierrors.Wrap(err, "failed to write latest finalized slot")
383382
}
384383

0 commit comments

Comments
 (0)