Skip to content

Commit

Permalink
Add forking related comments
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Mar 18, 2024
1 parent 40a74e0 commit 5d7779e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/protocol/engines.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ func (e *Engines) ForkAtSlot(slot iotago.SlotIndex) (*engine.Engine, error) {
if err = newStorage.Commitments().Rollback(slot, latestCommitment.Slot()); err != nil {
return nil, ierrors.Wrap(err, "failed to rollback commitments")
}
// create temporary components and rollback their permanent state, which will be reflected on disk.

// some components are automatically rolled back by deleting their data on disk (e.g. slot based storage).
// some other components need to be rolled back manually, like the UTXO ledger for example.
// we need to create temporary components to rollback their permanent state, which will be reflected on disk.
evictionState := eviction.NewState(newStorage.Settings(), newStorage.RootBlocks)
evictionState.Initialize(latestCommitment.Slot())

Expand Down
6 changes: 6 additions & 0 deletions pkg/retainer/txretainer/tx_retainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ func NewProvider(opts ...options.Option[TransactionRetainer]) module.Provider[*e

// Reset resets the component to a clean state as if it was created at the last commitment.
func (r *TransactionRetainer) Reset(targetSlot iotago.SlotIndex) {
// In the TransactionRetainer, we rely on the fact that "Reset" is always called
// when a new engine is initialized (even during chain switching).
// This is the cleanest way to rollback the state on disc to the
// last committed slot without the need to initialize temporary
// components in the "ForkAtSlot" method.
//
// we need to rollback the transaction retainer to the target slot
// to delete all transactions that were committed after the target slot.
if err := r.txRetainerDatabase.Rollback(targetSlot); err != nil {
Expand Down

0 comments on commit 5d7779e

Please sign in to comment.