From 5d7779e496b8ee4629c0c2ad6c562ba65e6725a7 Mon Sep 17 00:00:00 2001 From: muXxer Date: Mon, 18 Mar 2024 13:53:19 +0100 Subject: [PATCH] Add forking related comments --- pkg/protocol/engines.go | 5 ++++- pkg/retainer/txretainer/tx_retainer.go | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/protocol/engines.go b/pkg/protocol/engines.go index 8dd3a0456..153652611 100644 --- a/pkg/protocol/engines.go +++ b/pkg/protocol/engines.go @@ -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()) diff --git a/pkg/retainer/txretainer/tx_retainer.go b/pkg/retainer/txretainer/tx_retainer.go index d35ade549..0be555a88 100644 --- a/pkg/retainer/txretainer/tx_retainer.go +++ b/pkg/retainer/txretainer/tx_retainer.go @@ -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 {