Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store txConflicting reason correctly and rename ConflictDAG to SpendDAG #508

Merged
merged 27 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3c631d2
Remove optForkAllTransactions
jkrvivian Nov 7, 2023
4063dc2
Store conflictTx failure reason on rejected txs
jkrvivian Nov 7, 2023
f5a30c4
Rename ConflictDAG to SpendDAG
jkrvivian Nov 8, 2023
9280eb4
Merge branch 'develop' into fix/conflicting-tx-reason
jkrvivian Nov 8, 2023
e01553a
Merge branch 'develop' into fix/conflicting-tx-reason
jkrvivian Nov 8, 2023
02fb2f7
Hook to TransactionMetadata OnRejected to capture conflicting reason …
jkrvivian Nov 8, 2023
8561076
Merge branch 'develop' into fix/conflicting-tx-reason
jkrvivian Nov 9, 2023
e6dd308
Remove TestAllWithoutForkingEverything
jkrvivian Nov 9, 2023
2500e79
Remove TestAllWithoutForkingEverything
jkrvivian Nov 9, 2023
0c78f57
Rename variable spenddag to spendDAG
jkrvivian Nov 9, 2023
2857d11
Rename conflict to spend
jkrvivian Nov 9, 2023
2e2f241
Fix resource cleanup unit test to work with forking all transactions.
piotrm50 Nov 10, 2023
e6f7360
Resolve comments
jkrvivian Nov 15, 2023
5f64dfb
Merge branch 'develop' into fix/conflicting-tx-reason
jkrvivian Nov 15, 2023
c81bc25
Fix unit test
jkrvivian Nov 15, 2023
f63865c
Rename ConflictSet to SpendSet
jkrvivian Nov 20, 2023
9e667b2
Merge branch 'develop' into fix/conflicting-tx-reason
jkrvivian Nov 21, 2023
aa045a2
Rename conflict to spend in dashboard frontend
jkrvivian Nov 21, 2023
311b2ef
spend -> spender
cyberphysic4l Nov 21, 2023
62e675e
fix merge errors
cyberphysic4l Nov 21, 2023
316a51e
rename files
cyberphysic4l Nov 21, 2023
357a1cd
remove broken line from spendDag test and clean up
cyberphysic4l Nov 22, 2023
71709d1
Merge branch 'develop' into fix/conflicting-tx-reason
jkrvivian Nov 22, 2023
bf7c619
Remove unused Spend related frontend
jkrvivian Nov 23, 2023
07d4330
Merge branch 'develop' into fix/conflicting-tx-reason
jkrvivian Nov 27, 2023
bd8b14c
Merge branch 'develop' into fix/conflicting-tx-reason
jkrvivian Nov 27, 2023
34d7e00
Merge branch 'develop' into fix/conflicting-tx-reason
jkrvivian Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions components/dashboard/explorer_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func setupExplorerRoutes(routeGroup *echo.Group) {
routeGroup.GET("/output/:"+restapipkg.ParameterOutputID, getOutput)
// routeGroup.GET("/output/:outputID/metadata", ledgerstateAPI.GetOutputMetadata)
// routeGroup.GET("/output/:outputID/consumers", ledgerstateAPI.GetOutputConsumers)
// routeGroup.GET("/conflict/:conflictID", ledgerstateAPI.GetConflict)
// routeGroup.GET("/conflict/:conflictID/children", ledgerstateAPI.GetConflictChildren)
// routeGroup.GET("/conflict/:conflictID/conflicts", ledgerstateAPI.GetConflictConflicts)
// routeGroup.GET("/conflict/:conflictID/voters", ledgerstateAPI.GetConflictVoters)
// routeGroup.GET("/conflict/:spendID", ledgerstateAPI.GetConflict)
// routeGroup.GET("/conflict/:spendID/children", ledgerstateAPI.GetConflictChildren)
// routeGroup.GET("/conflict/:spendID/conflicts", ledgerstateAPI.GetConflictConflicts)
// routeGroup.GET("/conflict/:spendID/voters", ledgerstateAPI.GetConflictVoters)
routeGroup.GET("/slot/commitment/:"+restapipkg.ParameterCommitmentID, getSlotDetailsByID)

routeGroup.GET("/search/:search", func(c echo.Context) error {
Expand Down Expand Up @@ -172,8 +172,8 @@ func createExplorerBlock(block *model.Block, cachedBlock *blocks.Block, metadata
t.LikedInsteadChildren = lo.Map(cachedBlock.ShallowLikeChildren(), func(childBlock *blocks.Block) string {
return childBlock.ID().ToHex()
})
t.ConflictIDs = lo.Map(cachedBlock.ConflictIDs().ToSlice(), func(conflictID iotago.TransactionID) string {
return conflictID.ToHex()
t.SpendIDs = lo.Map(cachedBlock.SpendIDs().ToSlice(), func(spendID iotago.TransactionID) string {
return spendID.ToHex()
})
} else {
switch metadata.BlockState {
Expand Down Expand Up @@ -233,7 +233,7 @@ func getTransactionMetadata(c echo.Context) error {
return ierrors.Errorf("tx metadata not found: %s", txID.ToHex())
}

conflicts, _ := deps.Protocol.MainEngineInstance().Ledger.ConflictDAG().ConflictingConflicts(txID)
conflicts, _ := deps.Protocol.MainEngineInstance().Ledger.SpendDAG().ConflictingSpends(txID)

return httpserver.JSONResponse(c, http.StatusOK, NewTransactionMetadata(txMetadata, conflicts))
}
Expand Down
8 changes: 4 additions & 4 deletions components/dashboard/jsonresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewOutputID(outputID iotago.OutputID) *OutputID {
// OutputMetadata represents the JSON model of the mempool.OutputMetadata.
// type OutputMetadata struct {
// OutputID *OutputID `json:"outputID"`
// ConflictIDs []string `json:"conflictIDs"`
// SpendIDs []string `json:"spendIDs"`
// FirstConsumer string `json:"firstCount"`
// ConfirmedConsumer string `json:"confirmedConsumer,omitempty"`
// ConfirmationState confirmation.State `json:"confirmationState"`
Expand All @@ -102,7 +102,7 @@ func NewOutputID(outputID iotago.OutputID) *OutputID {
// func NewOutputMetadata(outputMetadata *mempool.OutputMetadata, confirmedConsumerID utxo.TransactionID) *OutputMetadata {
// return &OutputMetadata{
// OutputID: NewOutputID(outputMetadata.ID()),
// ConflictIDs: lo.Map(lo.Map(outputMetadata.ConflictIDs().Slice(), func(t utxo.TransactionID) []byte {
// SpendIDs: lo.Map(lo.Map(outputMetadata.SpendIDs().Slice(), func(t utxo.TransactionID) []byte {
// return lo.PanicOnErr(t.Bytes())
// }), base58.Encode),
// FirstConsumer: outputMetadata.FirstConsumer().Base58(),
Expand Down Expand Up @@ -234,7 +234,7 @@ func NewUnlockBlock(unlockBlock iotago.Unlock) *UnlockBlock {
// TransactionMetadata represents the JSON model of the mempool.TransactionMetadata.
type TransactionMetadata struct {
TransactionID string `json:"transactionID"`
ConflictIDs []string `json:"conflictIDs"`
SpendIDs []string `json:"spendIDs"`
Booked bool `json:"booked"`
BookedTime int64 `json:"bookedTime"`
ConfirmationState string `json:"confirmationState"`
Expand All @@ -254,7 +254,7 @@ func NewTransactionMetadata(transactionMetadata mempool.TransactionMetadata, con

return &TransactionMetadata{
TransactionID: transactionMetadata.ID().ToHex(),
ConflictIDs: func() []string {
SpendIDs: func() []string {
var strIDs []string
for _, txID := range conflicts.ToSlice() {
strIDs = append(strIDs, txID.ToHex())
Expand Down
6 changes: 3 additions & 3 deletions components/dashboard/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ type ExplorerBlock struct {
LikedInsteadChildren []string `json:"shallowLikeChildren"`
// Solid defines the solid status of the block.
Solid bool `json:"solid"`
ConflictIDs []string `json:"conflictIDs"`
AddedConflictIDs []string `json:"addedConflictIDs"`
SubtractedConflictIDs []string `json:"subtractedConflictIDs"`
SpendIDs []string `json:"spendIDs"`
AddedSpendIDs []string `json:"addedSpendIDs"`
jkrvivian marked this conversation as resolved.
Show resolved Hide resolved
SubtractedSpendIDs []string `json:"subtractedSpendIDs"`
Scheduled bool `json:"scheduled"`
Booked bool `json:"booked"`
Orphaned bool `json:"orphaned"`
Expand Down
14 changes: 7 additions & 7 deletions components/debugapi/debug_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ type (
Confirmed bool `json:"confirmed"`

Witnesses []string `json:"witnesses"`
// conflictIDs are the all conflictIDs of the block inherited from the parents + payloadConflictIDs.
ConflictIDs []iotago.TransactionID `json:"conflictIDs"`
// payloadConflictIDs are the conflictIDs of the block's payload (in case it is a transaction, otherwise empty).
PayloadConflictIDs []iotago.TransactionID `json:"payloadConflictIDs"`
String string `json:"string"`
// spendIDs are the all spendIDs of the block inherited from the parents + payloadSpendIDs.
SpendIDs []iotago.TransactionID `json:"spendIDs"`
// payloadSpendIDs are the spendIDs of the block's payload (in case it is a transaction, otherwise empty).
PayloadSpendIDs []iotago.TransactionID `json:"payloadSpendIDs"`
String string `json:"string"`
}

Validator struct {
Expand Down Expand Up @@ -82,8 +82,8 @@ func BlockMetadataResponseFromBlock(block *blocks.Block) *BlockMetadataResponse
PreConfirmed: block.IsPreConfirmed(),
Confirmed: block.IsConfirmed(),
Witnesses: lo.Map(block.Witnesses(), func(seatIndex account.SeatIndex) string { return fmt.Sprintf("%d", seatIndex) }),
ConflictIDs: block.ConflictIDs().ToSlice(),
PayloadConflictIDs: block.PayloadConflictIDs().ToSlice(),
SpendIDs: block.SpendIDs().ToSlice(),
PayloadSpendIDs: block.PayloadSpendIDs().ToSlice(),
String: block.String(),
}
}
8 changes: 4 additions & 4 deletions components/metrics/metrics_conflicts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var ConflictMetrics = collector.NewCollection(conflictNamespace,
collector.WithType(collector.Counter),
collector.WithHelp("Time since transaction issuance to the conflict acceptance"),
collector.WithInitFunc(func() {
deps.Protocol.Events.Engine.ConflictDAG.ConflictAccepted.Hook(func(conflictID iotago.TransactionID) {
if txMetadata, exists := deps.Protocol.MainEngineInstance().Ledger.MemPool().TransactionMetadata(conflictID); exists {
deps.Protocol.Events.Engine.SpendDAG.SpendAccepted.Hook(func(spendID iotago.TransactionID) {
if txMetadata, exists := deps.Protocol.MainEngineInstance().Ledger.MemPool().TransactionMetadata(spendID); exists {
firstAttachmentID := txMetadata.EarliestIncludedAttachment()
if block, blockExists := deps.Protocol.MainEngineInstance().BlockFromCache(firstAttachmentID); blockExists {
timeSinceIssuance := time.Since(block.IssuingTime()).Milliseconds()
Expand All @@ -37,7 +37,7 @@ var ConflictMetrics = collector.NewCollection(conflictNamespace,
collector.WithType(collector.Counter),
collector.WithHelp("Number of resolved (accepted) conflicts"),
collector.WithInitFunc(func() {
deps.Protocol.Events.Engine.ConflictDAG.ConflictAccepted.Hook(func(conflictID iotago.TransactionID) {
deps.Protocol.Events.Engine.SpendDAG.SpendAccepted.Hook(func(spendID iotago.TransactionID) {
deps.Collector.Increment(conflictNamespace, resolvedConflictCount)
}, event.WithWorkerPool(Component.WorkerPool))
}),
Expand All @@ -46,7 +46,7 @@ var ConflictMetrics = collector.NewCollection(conflictNamespace,
collector.WithType(collector.Counter),
collector.WithHelp("Number of created conflicts"),
collector.WithInitFunc(func() {
deps.Protocol.Events.Engine.ConflictDAG.ConflictCreated.Hook(func(conflictID iotago.TransactionID) {
deps.Protocol.Events.Engine.SpendDAG.SpendCreated.Hook(func(spendID iotago.TransactionID) {
deps.Collector.Increment(conflictNamespace, allConflictCounts)
}, event.WithWorkerPool(Component.WorkerPool))
}),
Expand Down
12 changes: 6 additions & 6 deletions components/metrics/metrics_slots.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ var SlotMetrics = collector.NewCollection(slotNamespace,
deps.Collector.Update(slotNamespace, createdConflicts, 0, strconv.Itoa(eventSlot))
}, event.WithWorkerPool(Component.WorkerPool))

deps.Protocol.Events.Engine.ConflictDAG.ConflictCreated.Hook(func(conflictID iotago.TransactionID) {
if txMetadata, exists := deps.Protocol.MainEngineInstance().Ledger.TransactionMetadata(conflictID); exists {
deps.Protocol.Events.Engine.SpendDAG.SpendCreated.Hook(func(spendID iotago.TransactionID) {
if txMetadata, exists := deps.Protocol.MainEngineInstance().Ledger.TransactionMetadata(spendID); exists {
for _, attachment := range txMetadata.ValidAttachments() {
deps.Collector.Increment(slotNamespace, createdConflicts, strconv.Itoa(int(attachment.Slot())))
}
Expand All @@ -115,8 +115,8 @@ var SlotMetrics = collector.NewCollection(slotNamespace,
deps.Collector.Update(slotNamespace, acceptedConflicts, 0, strconv.Itoa(eventSlot))
}, event.WithWorkerPool(Component.WorkerPool))

deps.Protocol.Events.Engine.ConflictDAG.ConflictAccepted.Hook(func(conflictID iotago.TransactionID) {
if txMetadata, exists := deps.Protocol.MainEngineInstance().Ledger.TransactionMetadata(conflictID); exists {
deps.Protocol.Events.Engine.SpendDAG.SpendAccepted.Hook(func(spendID iotago.TransactionID) {
if txMetadata, exists := deps.Protocol.MainEngineInstance().Ledger.TransactionMetadata(spendID); exists {
for _, attachmentBlockID := range txMetadata.ValidAttachments() {
if attachment, exists := deps.Protocol.MainEngineInstance().BlockCache.Block(attachmentBlockID); exists && attachment.IsAccepted() {
deps.Collector.Increment(slotNamespace, acceptedConflicts, strconv.Itoa(int(attachment.ID().Slot())))
Expand All @@ -139,8 +139,8 @@ var SlotMetrics = collector.NewCollection(slotNamespace,
deps.Collector.Update(slotNamespace, rejectedConflicts, 0, strconv.Itoa(eventSlot))
}, event.WithWorkerPool(Component.WorkerPool))

deps.Protocol.Events.Engine.ConflictDAG.ConflictRejected.Hook(func(conflictID iotago.TransactionID) {
if txMetadata, exists := deps.Protocol.MainEngineInstance().Ledger.TransactionMetadata(conflictID); exists {
deps.Protocol.Events.Engine.SpendDAG.SpendRejected.Hook(func(spendID iotago.TransactionID) {
if txMetadata, exists := deps.Protocol.MainEngineInstance().Ledger.TransactionMetadata(spendID); exists {
for _, attachmentBlockID := range txMetadata.ValidAttachments() {
if attachment, exists := deps.Protocol.MainEngineInstance().BlockCache.Block(attachmentBlockID); exists && attachment.IsAccepted() {
deps.Collector.Increment(slotNamespace, rejectedConflicts, strconv.Itoa(int(attachment.ID().Slot())))
Expand Down
6 changes: 3 additions & 3 deletions pkg/core/acceptance/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
)

const (
// Pending is the state of pending conflicts.
// Pending is the state of pending spends.
Pending State = iota

// Accepted is the state of accepted conflicts.
// Accepted is the state of accepted spends.
Accepted

// Rejected is the state of rejected conflicts.
// Rejected is the state of rejected spends.
Rejected
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/block_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (b *BlockDispatcher) processWarpSyncResponse(commitmentID iotago.Commitment

// 1. Mark all transactions as accepted
for _, transactionID := range transactionIDs {
targetEngine.Ledger.ConflictDAG().SetAccepted(transactionID)
targetEngine.Ledger.SpendDAG().SetAccepted(transactionID)
}

// 2. Mark all blocks as accepted
Expand Down
36 changes: 18 additions & 18 deletions pkg/protocol/engine/blocks/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type Block struct {
// Booker block
booked reactive.Variable[bool]
witnesses ds.Set[account.SeatIndex]
// conflictIDs are the all conflictIDs of the block inherited from the parents + payloadConflictIDs.
conflictIDs ds.Set[iotago.TransactionID]
// payloadConflictIDs are the conflictIDs of the block's payload (in case it is a transaction, otherwise empty).
payloadConflictIDs ds.Set[iotago.TransactionID]
// spendIDs are the all spendIDs of the block inherited from the parents + payloadSpendIDs.
spendIDs ds.Set[iotago.TransactionID]
// payloadSpendIDs are the spendIDs of the block's payload (in case it is a transaction, otherwise empty).
payloadSpendIDs ds.Set[iotago.TransactionID]

// BlockGadget block
preAccepted bool
Expand Down Expand Up @@ -77,8 +77,8 @@ func (r *rootBlock) String() string {
func NewBlock(data *model.Block) *Block {
return &Block{
witnesses: ds.NewSet[account.SeatIndex](),
conflictIDs: ds.NewSet[iotago.TransactionID](),
payloadConflictIDs: ds.NewSet[iotago.TransactionID](),
spendIDs: ds.NewSet[iotago.TransactionID](),
payloadSpendIDs: ds.NewSet[iotago.TransactionID](),
acceptanceRatifiers: ds.NewSet[account.SeatIndex](),
confirmationRatifiers: ds.NewSet[account.SeatIndex](),
modelBlock: data,
Expand All @@ -94,8 +94,8 @@ func NewBlock(data *model.Block) *Block {
func NewRootBlock(blockID iotago.BlockID, commitmentID iotago.CommitmentID, issuingTime time.Time) *Block {
b := &Block{
witnesses: ds.NewSet[account.SeatIndex](),
conflictIDs: ds.NewSet[iotago.TransactionID](),
payloadConflictIDs: ds.NewSet[iotago.TransactionID](),
spendIDs: ds.NewSet[iotago.TransactionID](),
payloadSpendIDs: ds.NewSet[iotago.TransactionID](),
acceptanceRatifiers: ds.NewSet[account.SeatIndex](),
confirmationRatifiers: ds.NewSet[account.SeatIndex](),

Expand Down Expand Up @@ -127,8 +127,8 @@ func NewMissingBlock(blockID iotago.BlockID) *Block {
missing: true,
missingBlockID: blockID,
witnesses: ds.NewSet[account.SeatIndex](),
conflictIDs: ds.NewSet[iotago.TransactionID](),
payloadConflictIDs: ds.NewSet[iotago.TransactionID](),
spendIDs: ds.NewSet[iotago.TransactionID](),
payloadSpendIDs: ds.NewSet[iotago.TransactionID](),
acceptanceRatifiers: ds.NewSet[account.SeatIndex](),
confirmationRatifiers: ds.NewSet[account.SeatIndex](),
solid: reactive.NewVariable[bool](),
Expand Down Expand Up @@ -395,32 +395,32 @@ func (b *Block) Witnesses() []account.SeatIndex {
return b.witnesses.ToSlice()
}

func (b *Block) ConflictIDs() ds.Set[iotago.TransactionID] {
func (b *Block) SpendIDs() ds.Set[iotago.TransactionID] {
b.mutex.RLock()
defer b.mutex.RUnlock()

return b.conflictIDs
return b.spendIDs
}

func (b *Block) SetConflictIDs(conflictIDs ds.Set[iotago.TransactionID]) {
func (b *Block) SetSpendIDs(spendIDs ds.Set[iotago.TransactionID]) {
b.mutex.Lock()
defer b.mutex.Unlock()

b.conflictIDs = conflictIDs
b.spendIDs = spendIDs
}

func (b *Block) PayloadConflictIDs() ds.Set[iotago.TransactionID] {
func (b *Block) PayloadSpendIDs() ds.Set[iotago.TransactionID] {
b.mutex.RLock()
defer b.mutex.RUnlock()

return b.payloadConflictIDs
return b.payloadSpendIDs
}

func (b *Block) SetPayloadConflictIDs(payloadConflictIDs ds.Set[iotago.TransactionID]) {
func (b *Block) SetPayloadSpendIDs(payloadSpendIDs ds.Set[iotago.TransactionID]) {
b.mutex.Lock()
defer b.mutex.Unlock()

b.payloadConflictIDs = payloadConflictIDs
b.payloadSpendIDs = payloadSpendIDs
}

// IsPreAccepted returns true if the Block was preAccepted.
Expand Down
Loading
Loading