Skip to content

Commit

Permalink
Fix: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Dec 1, 2023
1 parent 66e843a commit 32ebf8b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/core/buffer/unsolid_commitment_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (u *UnsolidCommitmentBuffer[V]) Add(commitmentID iotago.CommitmentID, value
u.mutex.RLock()
defer u.mutex.RUnlock()

if commitmentID.Slot() <= u.lastEvictedSlot {
if u.lastEvictedSlot != 0 && commitmentID.Slot() <= u.lastEvictedSlot {
return false
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/protocol/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func newChain(chains *Chains) *Chain {
ClaimedWeight: reactive.NewVariable[uint64](),
AttestedWeight: reactive.NewVariable[uint64](),
VerifiedWeight: reactive.NewVariable[uint64](),
WarpSyncMode: reactive.NewVariable[bool](),
WarpSyncMode: reactive.NewVariable[bool]().Init(true),
WarpSyncThreshold: reactive.NewVariable[iotago.SlotIndex](),
OutOfSyncThreshold: reactive.NewVariable[iotago.SlotIndex](),
RequestAttestations: reactive.NewVariable[bool](),
Expand Down Expand Up @@ -326,9 +326,9 @@ func (c *Chain) deriveOutOfSyncThreshold(latestSeenSlot reactive.ReadableVariabl
// committable age or 0 if this would cause an overflow to the negative numbers).
func (c *Chain) deriveWarpSyncThreshold(latestSeenSlot reactive.ReadableVariable[iotago.SlotIndex], engineInstance *engine.Engine) func() {
return c.WarpSyncThreshold.DeriveValueFrom(reactive.NewDerivedVariable(func(_ iotago.SlotIndex, latestSeenSlot iotago.SlotIndex) iotago.SlotIndex {
warpSyncOffset := engineInstance.LatestAPI().ProtocolParameters().MaxCommittableAge()
warpSyncOffset := engineInstance.LatestAPI().ProtocolParameters().MinCommittableAge()
if warpSyncOffset < latestSeenSlot {
return latestSeenSlot - warpSyncOffset
return latestSeenSlot - warpSyncOffset + 1
}

return 0
Expand Down
1 change: 1 addition & 0 deletions pkg/protocol/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +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),

// mark commitments that are marked as verified as attested, fully booked and committable
c.IsAttested.InheritFrom(c.IsCommitted),
Expand Down
14 changes: 1 addition & 13 deletions pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package inmemoryblockdag

import (
"fmt"
"sync/atomic"

"github.com/iotaledger/hive.go/ds"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/runtime/event"
"github.com/iotaledger/hive.go/runtime/module"
Expand Down Expand Up @@ -76,8 +74,6 @@ func (b *BlockDAG) setupBlock(block *blocks.Block) {
var unsolidParentsCount atomic.Int32
unsolidParentsCount.Store(int32(len(block.Parents())))

unsolidParents := ds.NewSet[iotago.BlockID]()

block.ForEachParent(func(parent iotago.Parent) {
parentBlock, exists := b.blockCache.Block(parent.ID)
if !exists {
Expand All @@ -86,17 +82,9 @@ func (b *BlockDAG) setupBlock(block *blocks.Block) {
return
}

unsolidParents.Add(parent.ID)
fmt.Println("unsolid Parents of ", block.ID(), unsolidParents)

parentBlock.Solid().OnUpdateOnce(func(_ bool, _ bool) {
unsolidParents.Delete(parent.ID)
fmt.Println("unsolid Parents of ", block.ID(), unsolidParents)

if counter := unsolidParentsCount.Add(-1); counter == 0 {
fmt.Println("unsolid counter", counter)
if unsolidParentsCount.Add(-1) == 0 {
if block.SetSolid() {
fmt.Println("unsolid Trigger", counter)
b.events.BlockSolid.Trigger(block)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/protocol_warp_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (w *WarpSyncProtocol) ProcessResponse(commitmentID iotago.CommitmentID, blo
// Let's assume that MCA is 5: when we want to book 15, we expect to have the commitment of 10 to load
// accounts from it, hence why we make committable the slot at - MCA + 1 with respect of the current slot.
minimumCommittableAge := w.protocol.APIForSlot(commitmentID.Slot()).ProtocolParameters().MinCommittableAge()
if committableCommitment, exists := chain.Commitment(commitmentID.Slot() - minimumCommittableAge); exists {
if committableCommitment, exists := chain.Commitment(commitmentID.Slot() - minimumCommittableAge + 1); exists {
committableCommitment.IsCommittable.Set(true)
}
})
Expand Down
60 changes: 55 additions & 5 deletions pkg/testsuite/mock/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func UnregisterIDAliases() {
idAliases = make(map[peer.ID]string)
}

type InvalidSignedTransactionEvent struct {
Metadata mempool.SignedTransactionMetadata
Error error
}

type Node struct {
Testing *testing.T

Expand Down Expand Up @@ -72,10 +77,11 @@ type Node struct {
logHandler slog.Handler
enableEngineLogging bool

mutex syncutils.RWMutex
attachedBlocks []*blocks.Block
currentSlot iotago.SlotIndex
filteredBlockEvents []*postsolidfilter.BlockFilteredEvent
mutex syncutils.RWMutex
attachedBlocks []*blocks.Block
currentSlot iotago.SlotIndex
filteredBlockEvents []*postsolidfilter.BlockFilteredEvent
invalidTransactionEvents map[iotago.SignedTransactionID]InvalidSignedTransactionEvent
}

func NewNode(t *testing.T, net *Network, partition string, name string, validator bool, logHandler slog.Handler) *Node {
Expand Down Expand Up @@ -113,7 +119,8 @@ func NewNode(t *testing.T, net *Network, partition string, name string, validato
logHandler: logHandler,
enableEngineLogging: true,

attachedBlocks: make([]*blocks.Block, 0),
attachedBlocks: make([]*blocks.Block, 0),
invalidTransactionEvents: make(map[iotago.SignedTransactionID]InvalidSignedTransactionEvent),
}
}

Expand Down Expand Up @@ -179,6 +186,33 @@ func (n *Node) hookEvents() {

n.filteredBlockEvents = append(n.filteredBlockEvents, event)
})

n.Protocol.Engines.Main.Get().Ledger.MemPool().OnSignedTransactionAttached(
func(signedTransactionMetadata mempool.SignedTransactionMetadata) {
signedTxID := signedTransactionMetadata.ID()

signedTransactionMetadata.OnSignaturesInvalid(func(err error) {
n.mutex.Lock()
defer n.mutex.Unlock()

n.invalidTransactionEvents[signedTxID] = InvalidSignedTransactionEvent{
Metadata: signedTransactionMetadata,
Error: err,
}
})

transactionMetadata := signedTransactionMetadata.TransactionMetadata()

transactionMetadata.OnInvalid(func(err error) {
n.mutex.Lock()
defer n.mutex.Unlock()

n.invalidTransactionEvents[signedTxID] = InvalidSignedTransactionEvent{
Metadata: signedTransactionMetadata,
Error: err,
}
})
})
}

func (n *Node) hookLogging(failOnBlockFiltered bool) {
Expand Down Expand Up @@ -373,6 +407,14 @@ func (n *Node) attachEngineLogsWithName(failOnBlockFiltered bool, instance *engi
instance.LogTrace("ConflictDAG.SpendAccepted", "conflictID", conflictID)
})

instance.Ledger.MemPool().OnSignedTransactionAttached(
func(signedTransactionMetadata mempool.SignedTransactionMetadata) {
signedTransactionMetadata.OnSignaturesInvalid(func(err error) {
instance.LogTrace("MemPool.SignedTransactionSignaturesInvalid", "tx", signedTransactionMetadata.ID(), "err", err)
})
},
)

instance.Ledger.OnTransactionAttached(func(transactionMetadata mempool.TransactionMetadata) {
instance.LogTrace("Ledger.TransactionAttached", "tx", transactionMetadata.ID())

Expand Down Expand Up @@ -487,6 +529,14 @@ 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()
event, exists := n.invalidTransactionEvents[txID]

return event, exists
}

func (n *Node) AttachedBlocks() []*blocks.Block {
n.mutex.RLock()
defer n.mutex.RUnlock()
Expand Down

0 comments on commit 32ebf8b

Please sign in to comment.