Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
karimodm committed Dec 12, 2023
1 parent 50a535b commit 7bac679
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 23 deletions.
10 changes: 3 additions & 7 deletions pkg/protocol/engine/eviction/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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()))
}
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/protocol/engine/tipselection/v1/test_framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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,
)
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/protocol/engine/tipselection/v1/tip_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 0 additions & 6 deletions pkg/storage/permanent/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/tests/booker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions pkg/testsuite/blocks.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package testsuite

import (
"fmt"

"github.com/stretchr/testify/assert"

"github.com/iotaledger/hive.go/ds"
Expand All @@ -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())
}

Expand Down

0 comments on commit 7bac679

Please sign in to comment.