Skip to content

Commit

Permalink
Merge pull request #938 from iotaledger/feat/fixed-snapshot-export
Browse files Browse the repository at this point in the history
Do not export a newer finalized slot than the target slot of a snapshot
  • Loading branch information
alexsporn authored Apr 25, 2024
2 parents 80baf80 + c88d908 commit e0c5e67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
21 changes: 10 additions & 11 deletions pkg/storage/permanent/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit e0c5e67

Please sign in to comment.