Skip to content

Commit

Permalink
Refactor: removed unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Apr 1, 2022
1 parent 187fd88 commit 730a5ae
Show file tree
Hide file tree
Showing 36 changed files with 467 additions and 748 deletions.
2 changes: 1 addition & 1 deletion packages/refactored/branchdag/branch_dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/iotaledger/goshimmer/packages/database"
"github.com/iotaledger/goshimmer/packages/refactored/utxo"
"github.com/iotaledger/goshimmer/packages/refactored/types/utxo"
)

func TestBranchDAG_RetrieveBranch(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions packages/refactored/branchdag/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package branchdag

import (
"github.com/iotaledger/goshimmer/packages/refactored/utxo"
"github.com/iotaledger/goshimmer/packages/refactored/types"
"github.com/iotaledger/goshimmer/packages/refactored/types/utxo"
)

type ConflictID = utxo.OutputID
Expand All @@ -16,8 +17,8 @@ var NewConflictIDs = utxo.NewOutputIDs

var NewBranchIDs = utxo.NewTransactionIDs

var MasterBranchID = utxo.EmptyTransactionID
var MasterBranchID BranchID

var BranchIDLength = utxo.TransactionIDLength
var BranchIDLength = types.IdentifierLength

var ConflictIDLength = utxo.OutputIDLength
var ConflictIDLength = types.IdentifierLength
30 changes: 15 additions & 15 deletions packages/refactored/ledger/booker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/iotaledger/goshimmer/packages/refactored/branchdag"
"github.com/iotaledger/goshimmer/packages/refactored/generics"
"github.com/iotaledger/goshimmer/packages/refactored/utxo"
utxo2 "github.com/iotaledger/goshimmer/packages/refactored/types/utxo"
)

type Booker struct {
Expand Down Expand Up @@ -64,15 +64,15 @@ func (b *Booker) bookTransaction(txMetadata *TransactionMetadata, inputsMetadata
})
}

func (b *Booker) inheritBranchIDs(txID utxo.TransactionID, inputsMetadata OutputsMetadata) (inheritedBranchIDs branchdag.BranchIDs) {
func (b *Booker) inheritBranchIDs(txID utxo2.TransactionID, inputsMetadata OutputsMetadata) (inheritedBranchIDs branchdag.BranchIDs) {
conflictingInputIDs, consumersToFork := b.determineConflictDetails(txID, inputsMetadata)
if conflictingInputIDs.Size() == 0 {
return b.RemoveConfirmedBranches(inputsMetadata.BranchIDs())
}

b.CreateBranch(txID, b.RemoveConfirmedBranches(inputsMetadata.BranchIDs()), conflictingInputIDs)

_ = consumersToFork.ForEach(func(transactionID utxo.TransactionID) (err error) {
_ = consumersToFork.ForEach(func(transactionID utxo2.TransactionID) (err error) {
b.WithTransactionAndMetadata(transactionID, func(tx *Transaction, txMetadata *TransactionMetadata) {
b.forkTransaction(tx, txMetadata, conflictingInputIDs)
})
Expand All @@ -95,17 +95,17 @@ func (b *Booker) storeOutputs(outputs Outputs, branchIDs branchdag.BranchIDs) {
})
}

func (b *Booker) determineConflictDetails(txID utxo.TransactionID, inputsMetadata OutputsMetadata) (conflictingInputIDs utxo.OutputIDs, consumersToFork utxo.TransactionIDs) {
conflictingInputIDs = utxo.NewOutputIDs()
consumersToFork = utxo.NewTransactionIDs()
func (b *Booker) determineConflictDetails(txID utxo2.TransactionID, inputsMetadata OutputsMetadata) (conflictingInputIDs utxo2.OutputIDs, consumersToFork utxo2.TransactionIDs) {
conflictingInputIDs = utxo2.NewOutputIDs()
consumersToFork = utxo2.NewTransactionIDs()

_ = inputsMetadata.ForEach(func(outputMetadata *OutputMetadata) error {
isConflicting, consumerToFork := outputMetadata.RegisterProcessedConsumer(txID)
if isConflicting {
conflictingInputIDs.Add(outputMetadata.ID())
}

if consumerToFork != utxo.EmptyTransactionID {
if consumerToFork != utxo2.EmptyTransactionID {
consumersToFork.Add(consumerToFork)
}

Expand All @@ -115,14 +115,14 @@ func (b *Booker) determineConflictDetails(txID utxo.TransactionID, inputsMetadat
return conflictingInputIDs, consumersToFork
}

func (b *Booker) forkTransaction(tx *Transaction, txMetadata *TransactionMetadata, outputsSpentByConflictingTx utxo.OutputIDs) {
b.Lock(txMetadata.ID())
func (b *Booker) forkTransaction(tx *Transaction, txMetadata *TransactionMetadata, outputsSpentByConflictingTx utxo2.OutputIDs) {
b.Lock(txMetadata.ID().Identifier)

conflictingInputs := b.resolveInputs(tx.Inputs()).Intersect(outputsSpentByConflictingTx)
previousParentBranches := txMetadata.BranchIDs()

if !b.CreateBranch(txMetadata.ID(), previousParentBranches, conflictingInputs) {
b.Unlock(txMetadata.ID())
b.Unlock(txMetadata.ID().Identifier)
return
}

Expand All @@ -132,20 +132,20 @@ func (b *Booker) forkTransaction(tx *Transaction, txMetadata *TransactionMetadat
})

if !b.updateBranchesAfterFork(txMetadata, txMetadata.ID(), previousParentBranches) {
b.Unlock(txMetadata.ID())
b.Unlock(txMetadata.ID().Identifier)
return
}
b.Unlock(txMetadata.ID())
b.Unlock(txMetadata.ID().Identifier)

b.propagateForkedBranchToFutureCone(txMetadata, previousParentBranches)

return
}

func (b *Booker) propagateForkedBranchToFutureCone(forkedTxMetadata *TransactionMetadata, previousParentBranches branchdag.BranchIDs) {
b.WalkConsumingTransactionMetadata(forkedTxMetadata.OutputIDs(), func(consumingTxMetadata *TransactionMetadata, walker *walker.Walker[utxo.OutputID]) {
b.Lock(consumingTxMetadata.ID())
defer b.Unlock(consumingTxMetadata.ID())
b.WalkConsumingTransactionMetadata(forkedTxMetadata.OutputIDs(), func(consumingTxMetadata *TransactionMetadata, walker *walker.Walker[utxo2.OutputID]) {
b.Lock(consumingTxMetadata.ID().Identifier)
defer b.Unlock(consumingTxMetadata.ID().Identifier)

if !b.updateBranchesAfterFork(consumingTxMetadata, forkedTxMetadata.ID(), previousParentBranches) {
return
Expand Down
2 changes: 1 addition & 1 deletion packages/refactored/ledger/dataflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ledger
import (
"github.com/iotaledger/hive.go/generics/dataflow"

"github.com/iotaledger/goshimmer/packages/refactored/utxo"
"github.com/iotaledger/goshimmer/packages/refactored/types/utxo"
)

type DataFlow struct {
Expand Down
16 changes: 8 additions & 8 deletions packages/refactored/ledger/events.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package ledger

import (
"github.com/iotaledger/goshimmer/packages/refactored/utxo"
utxo2 "github.com/iotaledger/goshimmer/packages/refactored/types/utxo"
)

type TransactionStoredEvent struct {
TransactionID utxo.TransactionID
TransactionID utxo2.TransactionID
}

type TransactionBookedEvent struct {
TransactionID utxo.TransactionID
TransactionID utxo2.TransactionID
Outputs Outputs
}

type TransactionForkedEvent struct {
TransactionID utxo.TransactionID
ParentBranches utxo.TransactionIDs
TransactionID utxo2.TransactionID
ParentBranches utxo2.TransactionIDs
}

type TransactionBranchIDUpdatedEvent struct {
TransactionID utxo.TransactionID
AddedBranchID utxo.TransactionID
RemovedBranchIDs utxo.TransactionIDs
TransactionID utxo2.TransactionID
AddedBranchID utxo2.TransactionID
RemovedBranchIDs utxo2.TransactionIDs
}
18 changes: 9 additions & 9 deletions packages/refactored/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/iotaledger/goshimmer/packages/database"
"github.com/iotaledger/goshimmer/packages/refactored/branchdag"
"github.com/iotaledger/goshimmer/packages/refactored/syncutils"
"github.com/iotaledger/goshimmer/packages/refactored/utxo"
utxo2 "github.com/iotaledger/goshimmer/packages/refactored/types/utxo"
)

// region Ledger ///////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -31,7 +31,7 @@ type Ledger struct {
*syncutils.DAGMutex[[32]byte]
}

func New(store kvstore.KVStore, vm utxo.VM, options ...Option) (ledger *Ledger) {
func New(store kvstore.KVStore, vm utxo2.VM, options ...Option) (ledger *Ledger) {
ledger = &Ledger{
TransactionStoredEvent: event.New[*TransactionStoredEvent](),
TransactionBookedEvent: event.New[*TransactionBookedEvent](),
Expand Down Expand Up @@ -68,14 +68,14 @@ func (l *Ledger) Configure(options ...Option) {
}
}

func (l *Ledger) StoreAndProcessTransaction(tx utxo.Transaction) (err error) {
l.Lock(tx.ID())
defer l.Unlock(tx.ID())
func (l *Ledger) StoreAndProcessTransaction(tx utxo2.Transaction) (err error) {
l.Lock(tx.ID().Identifier)
defer l.Unlock(tx.ID().Identifier)

return l.DataFlow.storeAndProcessTransaction().Run(&dataFlowParams{Transaction: NewTransaction(tx)})
}

func (l *Ledger) CheckTransaction(tx utxo.Transaction) (err error) {
func (l *Ledger) CheckTransaction(tx utxo2.Transaction) (err error) {
return l.DataFlow.checkTransaction().Run(&dataFlowParams{Transaction: NewTransaction(tx)})
}

Expand All @@ -86,13 +86,13 @@ func (l *Ledger) setup() {
}

func (l *Ledger) processTransaction(tx *Transaction) (err error) {
l.Lock(tx.ID())
defer l.Unlock(tx.ID())
l.Lock(tx.ID().Identifier)
defer l.Unlock(tx.ID().Identifier)

return l.DataFlow.processTransaction().Run(&dataFlowParams{Transaction: tx})
}

func (l *Ledger) processConsumingTransactions(outputIDs utxo.OutputIDs) {
func (l *Ledger) processConsumingTransactions(outputIDs utxo2.OutputIDs) {
for it := l.UnprocessedConsumingTransactions(outputIDs).Iterator(); it.HasNext(); {
go l.CachedTransaction(it.Next()).Consume(func(tx *Transaction) {
_ = l.processTransaction(tx)
Expand Down
Loading

0 comments on commit 730a5ae

Please sign in to comment.