Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
fix(BUX-255): kahn sorting: ignore inputs we do not use for the trans…
Browse files Browse the repository at this point in the history
…action
  • Loading branch information
arkadiuszos4chain committed Oct 3, 2023
1 parent 8abe1aa commit 9edbf2c
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions beef_tx.go
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ type beefTx struct {
}

func newBeefTx(version uint32, tx *Transaction) (*beefTx, error) {
if version > 65_535 {
return nil, errors.New("version above 65.535")
if version > 0xFFFF {
return nil, errors.New("version above 0xFFFF")
}

// get inputs parent transactions
11 changes: 7 additions & 4 deletions beef_tx_sorting.go
Original file line number Diff line number Diff line change
@@ -28,16 +28,19 @@ func prepareSortStructures(dag []*Transaction) (txByID map[string]*Transaction,
incomingEdgesMap[tx.ID] = 0
}

calculateIncomingEdges(incomingEdgesMap, dag)
calculateIncomingEdges(incomingEdgesMap, txByID)
zeroIncomingEdgeQueue = getTxWithZeroIncomingEdges(incomingEdgesMap)

return
}

func calculateIncomingEdges(inDegree map[string]int, transactions []*Transaction) {
for _, tx := range transactions {
func calculateIncomingEdges(inDegree map[string]int, txByID map[string]*Transaction) {
for _, tx := range txByID {
for _, input := range tx.draftTransaction.Configuration.Inputs {
inDegree[input.UtxoPointer.TransactionID]++
inputUtxoTxID := input.UtxoPointer.TransactionID
if _, ok := txByID[inputUtxoTxID]; ok { // transaction can contains inputs we are not interested in
inDegree[inputUtxoTxID]++
}
}
}
}
4 changes: 2 additions & 2 deletions beef_tx_sorting_test.go
Original file line number Diff line number Diff line change
@@ -12,10 +12,10 @@ func Test_kahnTopologicalSortTransaction(t *testing.T) {
txsFromOldestToNewest := []*Transaction{
createTx("0"),
createTx("1", "0"),
createTx("2", "1"),
createTx("2", "1", "101"),
createTx("3", "2", "1"),
createTx("4", "3", "1"),
createTx("5", "3", "2"),
createTx("5", "3", "2", "100"),
createTx("6", "4", "2", "0"),
createTx("7", "6", "5", "3", "1"),
createTx("8", "7"),

0 comments on commit 9edbf2c

Please sign in to comment.