diff --git a/pkg/protocol/engine/eviction/state.go b/pkg/protocol/engine/eviction/state.go index fbe025cb8..51054709b 100644 --- a/pkg/protocol/engine/eviction/state.go +++ b/pkg/protocol/engine/eviction/state.go @@ -4,6 +4,7 @@ import ( "io" "github.com/iotaledger/hive.go/ierrors" + "github.com/iotaledger/hive.go/kvstore" "github.com/iotaledger/hive.go/lo" "github.com/iotaledger/hive.go/runtime/syncutils" "github.com/iotaledger/hive.go/serializer/v2" @@ -92,11 +93,6 @@ func (s *State) AllActiveRootBlocks() map[iotago.BlockID]iotago.CommitmentID { }) } - // We include genesis as a root block if the start of our active window is the genesis slot. - if startSlot == s.settings.APIProvider().APIForSlot(s.lastCommittedSlot).ProtocolParameters().GenesisSlot() { - activeRootBlocks[s.settings.APIProvider().CommittedAPI().ProtocolParameters().GenesisBlockID()] = model.NewEmptyCommitment(s.settings.APIProvider().CommittedAPI()).ID() - } - return activeRootBlocks } @@ -148,7 +144,7 @@ func (s *State) AddRootBlock(id iotago.BlockID, commitmentID iotago.CommitmentID panic(ierrors.Wrapf(err, "failed to store root block %s", id)) } - if err := s.settings.AdvanceLatestNonEmptySlot(id.Slot()); err != nil { + if err := s.settings.AdvanceLatestNonEmptySlot(id.Slot()); err != nil && !ierrors.Is(err, kvstore.ErrTypedValueNotChanged) { panic(ierrors.Wrapf(err, "failed to advance latest non empty slot to %d", id.Slot())) } } @@ -316,7 +312,7 @@ func (s *State) activeIndexRange(targetSlot iotago.SlotIndex) (startSlot iotago. return genesisSlot, targetSlot } - rootBlocksWindowStart := targetSlot - maxCommittableAge + 1 + rootBlocksWindowStart := (targetSlot - maxCommittableAge) + 1 if latestNonEmptySlot := s.settings.LatestNonEmptySlot(); rootBlocksWindowStart > latestNonEmptySlot { rootBlocksWindowStart = latestNonEmptySlot diff --git a/pkg/protocol/engine/tipselection/v1/test_framework_test.go b/pkg/protocol/engine/tipselection/v1/test_framework_test.go index 0ce8b8739..4ccfc6170 100644 --- a/pkg/protocol/engine/tipselection/v1/test_framework_test.go +++ b/pkg/protocol/engine/tipselection/v1/test_framework_test.go @@ -41,7 +41,7 @@ func NewTestFramework(test *testing.T, opts ...options.Option[TestFramework]) *T return nil, false } - rootBlocksRetriever := func() iotago.BlockID { + rootBlockRetriever := func() iotago.BlockID { return iotago.EmptyBlockID } @@ -51,7 +51,7 @@ func NewTestFramework(test *testing.T, opts ...options.Option[TestFramework]) *T t.TipManager.Instance, spenddagv1.New[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank](t.CommitteeSize), transactionMetadataRetriever, - rootBlocksRetriever, + rootBlockRetriever, t.expectedLivenessDuration, ) }) diff --git a/pkg/protocol/engine/tipselection/v1/tip_selection.go b/pkg/protocol/engine/tipselection/v1/tip_selection.go index 452f4a953..e9312d8e4 100644 --- a/pkg/protocol/engine/tipselection/v1/tip_selection.go +++ b/pkg/protocol/engine/tipselection/v1/tip_selection.go @@ -28,7 +28,7 @@ type TipSelection struct { // spendDAG is the SpendDAG that is used to track spenders. spendDAG spenddag.SpendDAG[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank] - // rootBlock is a function that returns the current root blocks. + // rootBlock is a function that returns the latest root block. rootBlock func() iotago.BlockID // livenessThreshold is a function that is used to determine the liveness threshold for a tip. @@ -83,11 +83,11 @@ func New(opts ...options.Option[TipSelection]) *TipSelection { // // This method is separated from the constructor so the TipSelection can be initialized lazily after all dependencies // are available. -func (t *TipSelection) Construct(tipManager tipmanager.TipManager, spendDAG spenddag.SpendDAG[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank], transactionMetadataRetriever func(iotago.TransactionID) (mempool.TransactionMetadata, bool), rootBlocksRetriever func() iotago.BlockID, livenessThresholdFunc func(tipmanager.TipMetadata) time.Duration) *TipSelection { +func (t *TipSelection) Construct(tipManager tipmanager.TipManager, spendDAG spenddag.SpendDAG[iotago.TransactionID, mempool.StateID, ledger.BlockVoteRank], transactionMetadataRetriever func(iotago.TransactionID) (mempool.TransactionMetadata, bool), rootBlockRetriever func() iotago.BlockID, livenessThresholdFunc func(tipmanager.TipMetadata) time.Duration) *TipSelection { t.tipManager = tipManager t.spendDAG = spendDAG t.transactionMetadata = transactionMetadataRetriever - t.rootBlock = rootBlocksRetriever + t.rootBlock = rootBlockRetriever t.livenessThreshold = livenessThresholdFunc t.TriggerConstructed() diff --git a/pkg/storage/permanent/settings.go b/pkg/storage/permanent/settings.go index 876bfad1d..6720617d0 100644 --- a/pkg/storage/permanent/settings.go +++ b/pkg/storage/permanent/settings.go @@ -332,12 +332,6 @@ func (s *Settings) SetLatestNonEmptySlot(slot iotago.SlotIndex) (err error) { } func (s *Settings) AdvanceLatestNonEmptySlot(slot iotago.SlotIndex) (err error) { - // We don't need to advance the latest stored slot if it's already ahead of the given slot. - // We check this before Compute to avoid contention inside the TypedValue. - if s.LatestNonEmptySlot() >= slot { - return nil - } - if _, err = s.storeLatestNonEmptySlot.Compute(func(latestNonEmptySlot iotago.SlotIndex, _ bool) (newValue iotago.SlotIndex, err error) { if latestNonEmptySlot >= slot { return latestNonEmptySlot, kvstore.ErrTypedValueNotChanged diff --git a/pkg/tests/booker_test.go b/pkg/tests/booker_test.go index b5407ba42..9929243be 100644 --- a/pkg/tests/booker_test.go +++ b/pkg/tests/booker_test.go @@ -723,7 +723,7 @@ func Test_SpendPendingCommittedRace(t *testing.T) { ts.AssertBlocksInCacheConflicts(map[*blocks.Block][]string{ ts.Block("block2.1"): {"tx1"}, ts.Block("n2-pending-genesis"): {"tx1"}, - // ts.Block("n2-pending-commit1"): {}, // no conflits inherited as the block merges orphaned conflicts. + ts.Block("n2-pending-commit1"): {}, // no conflits inherited as the block merges orphaned conflicts. }, node2) } @@ -753,7 +753,7 @@ func Test_SpendPendingCommittedRace(t *testing.T) { ts.AssertBlocksInCacheConflicts(map[*blocks.Block][]string{ ts.Block("block2.1"): {"tx1"}, ts.Block("n2-pending-genesis"): {"tx1"}, - // ts.Block("n2-pending-commit1"): {}, // no conflits inherited as the block merges orphaned conflicts. + ts.Block("n2-pending-commit1"): {}, // no conflits inherited as the block merges orphaned conflicts. }, node1, node2) ts.AssertTransactionsInCachePending(wallet.Transactions("tx1", "tx2"), true, node1, node2) diff --git a/pkg/testsuite/blocks.go b/pkg/testsuite/blocks.go index f8a35ea47..40bdd265b 100644 --- a/pkg/testsuite/blocks.go +++ b/pkg/testsuite/blocks.go @@ -1,8 +1,6 @@ package testsuite import ( - "fmt" - "github.com/stretchr/testify/assert" "github.com/iotaledger/hive.go/ds" @@ -20,7 +18,6 @@ func (t *TestSuite) AssertBlock(block *blocks.Block, node *mock.Node) *model.Blo var exists bool loadedBlock, exists = node.Protocol.Engines.Main.Get().Block(block.ID()) if !exists { - fmt.Println("loadedBlock ", block.ID()) return ierrors.Errorf("AssertBlock: %s: block %s does not exist", node.Name, block.ID()) }