Skip to content

Commit

Permalink
Refactor: reverted more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Dec 1, 2023
1 parent 9c845ec commit 1e8e9dd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
10 changes: 10 additions & 0 deletions pkg/protocol/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ func (c *Chain) DispatchBlock(block *model.Block, src peer.ID) (dispatched bool)
func (c *Chain) Commitment(slot iotago.SlotIndex) (commitment *Commitment, exists bool) {
for currentChain := c; currentChain != nil; {
switch forkingPoint := currentChain.ForkingPoint.Get(); {
case forkingPoint == nil:
return nil, false
case forkingPoint.Slot() == slot:
return forkingPoint, true
case slot > forkingPoint.Slot():
Expand Down Expand Up @@ -335,6 +337,14 @@ func (c *Chain) deriveWarpSyncThreshold(latestSeenSlot reactive.ReadableVariable
}, latestSeenSlot))
}

func warpSyncThreshold(latestSeenSlot iotago.SlotIndex, minCommittableAge iotago.SlotIndex) iotago.SlotIndex {

Check failure on line 340 in pkg/protocol/chain.go

View workflow job for this annotation

GitHub Actions / GolangCI-Lint

func `warpSyncThreshold` is unused (unused)
if minCommittableAge < latestSeenSlot {
return latestSeenSlot - minCommittableAge + 1
}

return 0
}

// addCommitment adds the given commitment to this chain.
func (c *Chain) addCommitment(newCommitment *Commitment) (shutdown func()) {
c.commitments.Set(newCommitment.Slot(), newCommitment)
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (c *Commitment) initDerivedProperties() (shutdown func()) {
return lo.Batch(
// mark commitments that are marked as root as verified
c.IsCommitted.InheritFrom(c.IsRoot),
c.IsAboveLatestVerifiedCommitment.InheritFrom(c.IsRoot),
c.ReplayDroppedBlocks.InheritFrom(c.IsRoot),

// mark commitments that are marked as verified as attested, fully booked and committable
c.IsAttested.InheritFrom(c.IsCommitted),
Expand Down
16 changes: 8 additions & 8 deletions pkg/testsuite/mock/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,19 +392,19 @@ func (n *Node) attachEngineLogsWithName(failOnBlockFiltered bool, instance *engi
})

events.SpendDAG.SpenderCreated.Hook(func(conflictID iotago.TransactionID) {
instance.LogTrace("ConflictDAG.SpendCreated", "conflictID", conflictID)
instance.LogTrace("SpendDAG.SpenderCreated", "conflictID", conflictID)
})

events.SpendDAG.SpenderEvicted.Hook(func(conflictID iotago.TransactionID) {
instance.LogTrace("ConflictDAG.SpendEvicted", "conflictID", conflictID)
instance.LogTrace("SpendDAG.SpenderEvicted", "conflictID", conflictID)
})

events.SpendDAG.SpenderRejected.Hook(func(conflictID iotago.TransactionID) {
instance.LogTrace("ConflictDAG.SpendRejected", "conflictID", conflictID)
instance.LogTrace("SpendDAG.SpenderRejected", "conflictID", conflictID)
})

events.SpendDAG.SpenderAccepted.Hook(func(conflictID iotago.TransactionID) {
instance.LogTrace("ConflictDAG.SpendAccepted", "conflictID", conflictID)
instance.LogTrace("SpendDAG.SpenderAccepted", "conflictID", conflictID)
})

instance.Ledger.MemPool().OnSignedTransactionAttached(
Expand Down Expand Up @@ -525,10 +525,6 @@ func (n *Node) FilteredBlocks() []*postsolidfilter.BlockFilteredEvent {
return n.filteredBlockEvents
}

func (n *Node) MainEngineSwitchedCount() int {
return int(n.mainEngineSwitchedCount.Load())
}

func (n *Node) TransactionFailure(txID iotago.SignedTransactionID) (InvalidSignedTransactionEvent, bool) {
n.mutex.RLock()
defer n.mutex.RUnlock()
Expand All @@ -537,6 +533,10 @@ func (n *Node) TransactionFailure(txID iotago.SignedTransactionID) (InvalidSigne
return event, exists
}

func (n *Node) MainEngineSwitchedCount() int {
return int(n.mainEngineSwitchedCount.Load())
}

func (n *Node) AttachedBlocks() []*blocks.Block {
n.mutex.RLock()
defer n.mutex.RUnlock()
Expand Down
15 changes: 13 additions & 2 deletions pkg/testsuite/storage_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ func (t *TestSuite) AssertCommitmentSlotIndexExists(slot iotago.SlotIndex, nodes
return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: commitment at index %v not found", node.Name, slot)
}

// Make sure the main chain exists
mainChain := node.Protocol.Chains.Main.Get()
if mainChain == nil {
return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: main chain not found when checking for commitment at index %v", node.Name, slot)
}

// Make sure the commitment is also available in the ChainManager.
if node.Protocol.Chains.Main.Get().LatestCommitment.Get().ID().Slot() < slot {
latestCommitment := mainChain.LatestCommitment.Get()
if latestCommitment == nil || latestCommitment.ID().Slot() < slot {
return ierrors.Errorf("AssertCommitmentSlotIndexExists: %s: commitment at index %v not found in ChainManager", node.Name, slot)
}

Expand Down Expand Up @@ -126,8 +133,12 @@ func (t *TestSuite) AssertChainID(expectedChainID iotago.CommitmentID, nodes ...

for _, node := range nodes {
t.Eventually(func() error {
actualChainID := node.Protocol.Chains.Main.Get().ForkingPoint.Get().ID()
mainChain := node.Protocol.Chains.Main.Get()
if mainChain == nil {
return ierrors.Errorf("AssertChainID: %s: main chain not found", node.Name)
}

actualChainID := mainChain.ForkingPoint.Get().ID()
if expectedChainID != actualChainID {
fmt.Println(expectedChainID, actualChainID)

Expand Down

0 comments on commit 1e8e9dd

Please sign in to comment.