Skip to content

Commit

Permalink
Do not export a newer finalized slot than the target slot of a snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsporn committed Apr 25, 2024
1 parent 52cc42b commit afcca2e
Showing 1 changed file with 10 additions and 11 deletions.
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 afcca2e

Please sign in to comment.