From f3653e0d81f4ac8a9afbe037b8c626a1cb63e02f Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:25:50 +0200 Subject: [PATCH 01/22] Implement unit test for read only flag. --- .../engine/ledger/tests/state_resolver.go | 31 +++- .../engine/mempool/tests/testframework.go | 12 +- pkg/protocol/engine/mempool/tests/tests.go | 135 ++++++++++++------ .../engine/mempool/tests/transaction.go | 22 +-- pkg/protocol/engine/mempool/v1/mempool.go | 3 +- .../engine/mempool/v1/mempool_test.go | 8 +- .../mempool/v1/transaction_metadata_test.go | 2 +- 7 files changed, 147 insertions(+), 66 deletions(-) diff --git a/pkg/protocol/engine/ledger/tests/state_resolver.go b/pkg/protocol/engine/ledger/tests/state_resolver.go index 1d56fa0ea..57e88d6be 100644 --- a/pkg/protocol/engine/ledger/tests/state_resolver.go +++ b/pkg/protocol/engine/ledger/tests/state_resolver.go @@ -1,10 +1,13 @@ package ledgertests import ( + "fmt" + "github.com/iotaledger/hive.go/ds/shrinkingmap" "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/iota-core/pkg/core/promise" "github.com/iotaledger/iota-core/pkg/protocol/engine/mempool" + iotago "github.com/iotaledger/iota.go/v4" ) type MockStateResolver struct { @@ -30,13 +33,31 @@ func (s *MockStateResolver) DestroyOutputState(stateID mempool.StateID) { s.statesByID.Delete(stateID) } -func (s *MockStateResolver) ResolveOutputState(outputID mempool.StateID) *promise.Promise[mempool.State] { - output, exists := s.statesByID.Get(outputID) - if !exists { - return promise.New[mempool.State]().Reject(ierrors.Errorf("output %s not found: %w", outputID.ToHex(), mempool.ErrStateNotFound)) +func (s *MockStateResolver) ResolveOutputState(reference iotago.Input) *promise.Promise[mempool.State] { + if reference.Type() == iotago.InputUTXO { + output, exists := s.statesByID.Get(reference.StateID()) + if !exists { + return promise.New[mempool.State]().Reject(ierrors.Errorf("output %s not found: %w", reference.StateID().ToHex(), mempool.ErrStateNotFound)) + } + + fmt.Println("utxo input", output.StateID()) + + return promise.New[mempool.State]().Resolve(output) + } else if reference.Type() == iotago.InputCommitment { + output := &iotago.Commitment{ + ProtocolVersion: 0, + Slot: 0, + PreviousCommitmentID: reference.(*iotago.CommitmentInput).CommitmentID, + RootsID: iotago.Identifier{}, + CumulativeWeight: 0, + ReferenceManaCost: 0, + } + + fmt.Println("comitment input", output.StateID()) + return promise.New[mempool.State]().Resolve(output) } - return promise.New[mempool.State]().Resolve(output) + return promise.New[mempool.State]().Reject(ierrors.Errorf("state not found")) } func (s *MockStateResolver) Cleanup() { diff --git a/pkg/protocol/engine/mempool/tests/testframework.go b/pkg/protocol/engine/mempool/tests/testframework.go index 57451f283..7883636be 100644 --- a/pkg/protocol/engine/mempool/tests/testframework.go +++ b/pkg/protocol/engine/mempool/tests/testframework.go @@ -54,8 +54,8 @@ func NewTestFramework(test *testing.T, instance mempool.MemPool[vote.MockedRank] return t } -func (t *TestFramework) CreateSignedTransaction(transactionAlias string, referencedStates []string, outputCount uint16, invalid ...bool) { - t.CreateTransaction(transactionAlias, referencedStates, outputCount, invalid...) +func (t *TestFramework) CreateSignedTransaction(transactionAlias string, referencedContextStates, referencedStates []string, outputCount uint16, invalid ...bool) { + t.CreateTransaction(transactionAlias, referencedContextStates, referencedStates, outputCount, invalid...) t.SignedTransactionFromTransaction(transactionAlias+"-signed", transactionAlias) } func (t *TestFramework) SignedTransactionFromTransaction(signedTransactionAlias string, transactionAlias string) { @@ -73,9 +73,9 @@ func (t *TestFramework) SignedTransactionFromTransaction(signedTransactionAlias signedTransactionID.RegisterAlias(signedTransactionAlias) } -func (t *TestFramework) CreateTransaction(alias string, referencedStates []string, outputCount uint16, invalid ...bool) { +func (t *TestFramework) CreateTransaction(alias string, referencedContextStates, referencedStates []string, outputCount uint16, invalid ...bool) { // create transaction - transaction := NewTransaction(outputCount, lo.Map(referencedStates, t.stateReference)...) + transaction := NewTransaction(outputCount, lo.Map(referencedStates, t.stateReference), lo.Map(referencedContextStates, t.stateContextReference)...) transaction.invalidTransaction = len(invalid) > 0 && invalid[0] t.transactionByAlias[alias] = transaction @@ -311,6 +311,10 @@ func (t *TestFramework) setupHookedEvents() { }) } +func (t *TestFramework) stateContextReference(alias string) iotago.Input { + return &iotago.CommitmentInput{CommitmentID: iotago.SlotIdentifierRepresentingData(0, []byte(alias))} +} + func (t *TestFramework) stateReference(alias string) iotago.Input { if alias == "genesis" { return &iotago.UTXOInput{} diff --git a/pkg/protocol/engine/mempool/tests/tests.go b/pkg/protocol/engine/mempool/tests/tests.go index bfd396627..5c603c73a 100644 --- a/pkg/protocol/engine/mempool/tests/tests.go +++ b/pkg/protocol/engine/mempool/tests/tests.go @@ -35,21 +35,22 @@ func TestAllWithoutForkingEverything(t *testing.T, frameworkProvider func(*testi func TestAllWithForkingEverything(t *testing.T, frameworkProvider func(*testing.T) *TestFramework) { for testName, testCase := range map[string]func(*testing.T, *TestFramework){ - "TestConflictPropagationForkAll": TestConflictPropagationForkAll, - "TestSetTxOrphanageMultipleAttachments": TestSetTxOrphanageMultipleAttachments, - "TestProcessTransaction": TestProcessTransaction, - "TestProcessTransactionsOutOfOrder": TestProcessTransactionsOutOfOrder, - "TestSetTransactionOrphanage": TestSetTransactionOrphanage, - "TestInvalidTransaction": TestInvalidTransaction, - "TestStoreAttachmentInEvictedSlot": TestStoreAttachmentInEvictedSlot, + "TestConflictPropagationForkAll": TestConflictPropagationForkAll, + "TestSetTxOrphanageMultipleAttachments": TestSetTxOrphanageMultipleAttachments, + "TestProcessTransactionWithReadOnlyInputs": TestProcessTransactionWithReadOnlyInputs, + "TestProcessTransaction": TestProcessTransaction, + "TestProcessTransactionsOutOfOrder": TestProcessTransactionsOutOfOrder, + "TestSetTransactionOrphanage": TestSetTransactionOrphanage, + "TestInvalidTransaction": TestInvalidTransaction, + "TestStoreAttachmentInEvictedSlot": TestStoreAttachmentInEvictedSlot, } { t.Run(testName, func(t *testing.T) { testCase(t, frameworkProvider(t)) }) } } func TestProcessTransaction(t *testing.T, tf *TestFramework) { - tf.CreateTransaction("tx1", []string{"genesis"}, 1) - tf.CreateTransaction("tx2", []string{"tx1:0"}, 1) + tf.CreateTransaction("tx1", []string{}, []string{"genesis"}, 1) + tf.CreateTransaction("tx2", []string{}, []string{"tx1:0"}, 1) tf.SignedTransactionFromTransaction("tx2", "tx2") tf.SignedTransactionFromTransaction("tx1", "tx1") @@ -79,10 +80,62 @@ func TestProcessTransaction(t *testing.T, tf *TestFramework) { }) } +func TestProcessTransactionWithReadOnlyInputs(t *testing.T, tf *TestFramework) { + tf.CreateTransaction("tx1", []string{"readOnlyInput"}, []string{"genesis"}, 1) + tf.CreateTransaction("tx2", []string{"readOnlyInput"}, []string{"tx1:0"}, 1) + + tf.SignedTransactionFromTransaction("tx2", "tx2") + tf.SignedTransactionFromTransaction("tx1", "tx1") + + require.NoError(t, tf.AttachTransactions("tx1", "tx2")) + + tf.RequireBooked("tx1", "tx2") + + tx1Metadata, exists := tf.TransactionMetadata("tx1") + require.True(t, exists) + _ = tx1Metadata.Outputs().ForEach(func(state mempool.StateMetadata) error { + if state.State().Type() == iotago.InputUTXO { + fmt.Println("utxo", state.StateID()) + require.False(t, state.IsAccepted()) + require.Equal(t, 1, state.PendingSpenderCount()) + } + + return nil + }) + + tx2Metadata, exists := tf.TransactionMetadata("tx2") + require.True(t, exists) + + _ = tx2Metadata.Outputs().ForEach(func(state mempool.StateMetadata) error { + if state.State().Type() == iotago.InputUTXO { + require.False(t, state.IsAccepted()) + require.Equal(t, 0, state.PendingSpenderCount()) + } + + if state.State().Type() == iotago.InputCommitment { + require.False(t, state.IsAccepted()) + require.Equal(t, 2, state.PendingSpenderCount()) + } + + return nil + }) + + conflictSetsTx1, exists := tf.ConflictDAG.ConflictSets(tf.TransactionID("tx1")) + fmt.Println(conflictSetsTx1.ToSlice()[0]) + require.True(t, exists) + require.Equal(t, 1, conflictSetsTx1.Size()) + require.True(t, conflictSetsTx1.Has(tf.StateID("genesis"))) + + conflictSetsTx2, exists := tf.ConflictDAG.ConflictSets(tf.TransactionID("tx2")) + require.True(t, exists) + require.Equal(t, 1, conflictSetsTx2.Size()) + require.True(t, conflictSetsTx2.Has(tf.StateID("tx1:0"))) +} + func TestProcessTransactionsOutOfOrder(t *testing.T, tf *TestFramework) { - tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "tx3", 1)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "tx2", 1)) @@ -124,9 +177,9 @@ func TestProcessTransactionsOutOfOrder(t *testing.T, tf *TestFramework) { func TestSetInclusionSlot(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 3)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 2)) @@ -187,9 +240,9 @@ func TestSetInclusionSlot(t *testing.T, tf *TestFramework) { func TestSetTransactionOrphanage(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 3)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 2)) @@ -225,9 +278,9 @@ func TestSetTransactionOrphanage(t *testing.T, tf *TestFramework) { func TestSetTxOrphanageMultipleAttachments(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 4)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 3)) @@ -279,9 +332,9 @@ func TestSetTxOrphanageMultipleAttachments(t *testing.T, tf *TestFramework) { func TestStateDiff(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 1)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 1)) @@ -310,14 +363,14 @@ func TestStateDiff(t *testing.T, tf *TestFramework) { func TestConflictPropagationForkAll(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx1*", []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx1*", []string{}, []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx2*", []string{"tx1*:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) - tf.CreateSignedTransaction("tx3*", []string{"tx2*:0"}, 1) - tf.CreateSignedTransaction("tx4", []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx2*", []string{}, []string{"tx1*:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx3*", []string{}, []string{"tx2*:0"}, 1) + tf.CreateSignedTransaction("tx4", []string{}, []string{"tx1:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 3)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 2)) @@ -342,14 +395,14 @@ func TestConflictPropagationForkAll(t *testing.T, tf *TestFramework) { func TestConflictPropagationForkOnDoubleSpend(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx1*", []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx1*", []string{}, []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx2*", []string{"tx1*:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) - tf.CreateSignedTransaction("tx3*", []string{"tx2*:0"}, 1) - tf.CreateSignedTransaction("tx4", []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx2*", []string{}, []string{"tx1*:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx3*", []string{}, []string{"tx2*:0"}, 1) + tf.CreateSignedTransaction("tx4", []string{}, []string{"tx1:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 3)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 2)) @@ -375,7 +428,7 @@ func TestInvalidTransaction(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1, true) + tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1, true) require.NoError(t, tf.AttachTransaction("tx1-signed", "tx1", "block2", 1)) tf.RequireInvalid("tx1") @@ -387,7 +440,7 @@ func TestStoreAttachmentInEvictedSlot(t *testing.T, tf *TestFramework) { tf.Instance.Evict(iotago.SlotIndex(5)) - tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1, true) + tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1, true) require.Error(t, tf.AttachTransaction("tx1-signed", "tx1", "block2", 1)) require.False(t, lo.Return2(tf.TransactionMetadata("tx1"))) @@ -400,7 +453,7 @@ func TestMemoryRelease(t *testing.T, tf *TestFramework) { signedTxAlias := fmt.Sprintf("tx%d-signed", index) txAlias := fmt.Sprintf("tx%d", index) blockAlias := fmt.Sprintf("block%d", index) - tf.CreateSignedTransaction(txAlias, []string{prevStateAlias}, 2) + tf.CreateSignedTransaction(txAlias, []string{}, []string{prevStateAlias}, 2) require.NoError(t, tf.AttachTransaction(signedTxAlias, txAlias, blockAlias, iotago.SlotIndex(index))) tf.RequireBooked(txAlias) diff --git a/pkg/protocol/engine/mempool/tests/transaction.go b/pkg/protocol/engine/mempool/tests/transaction.go index a21fb2523..72dea36f4 100644 --- a/pkg/protocol/engine/mempool/tests/transaction.go +++ b/pkg/protocol/engine/mempool/tests/transaction.go @@ -21,7 +21,8 @@ func (s *SignedTransaction) String() string { type Transaction struct { id iotago.TransactionID - inputs []iotago.Input + utxoInputs []iotago.Input + contextInputs []iotago.Input outputCount uint16 invalidTransaction bool } @@ -33,11 +34,12 @@ func NewSignedTransaction(transaction mempool.Transaction) *SignedTransaction { } } -func NewTransaction(outputCount uint16, inputs ...iotago.Input) *Transaction { +func NewTransaction(outputCount uint16, inputs []iotago.Input, contextInputs ...iotago.Input) *Transaction { return &Transaction{ - id: tpkg.RandTransactionID(), - inputs: inputs, - outputCount: outputCount, + id: tpkg.RandTransactionID(), + utxoInputs: inputs, + contextInputs: contextInputs, + outputCount: outputCount, } } @@ -46,15 +48,15 @@ func (t *Transaction) ID() (iotago.TransactionID, error) { } func (t *Transaction) Inputs() ([]iotago.Input, error) { - return t.inputs, nil + return append(t.utxoInputs, t.contextInputs...), nil } -func (t *Transaction) CommitmentInput() *iotago.CommitmentInput { - return nil +func (t *Transaction) UTXOInputs() ([]iotago.Input, error) { + return t.utxoInputs, nil } -func (t *Transaction) ContextInputs() (iotago.TransactionContextInputs, error) { - return nil, nil +func (t *Transaction) ContextInputs() ([]iotago.Input, error) { + return t.contextInputs, nil } func (t *Transaction) String() string { diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index 6e93935dc..6f63e1cbd 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -2,6 +2,7 @@ package mempoolv1 import ( "context" + "fmt" "github.com/iotaledger/hive.go/core/memstorage" "github.com/iotaledger/hive.go/ds" @@ -289,7 +290,7 @@ func (m *MemPool[VoteRank]) bookTransaction(transaction *TransactionMetadata) { func (m *MemPool[VoteRank]) forkTransaction(transactionMetadata *TransactionMetadata, resourceIDs ds.Set[mempool.StateID]) { transactionMetadata.conflicting.Trigger() - + fmt.Println("fork transaction", transactionMetadata.ID(), "resources", resourceIDs.ToSlice()) if err := m.conflictDAG.UpdateConflictingResources(transactionMetadata.ID(), resourceIDs); err != nil { transactionMetadata.orphaned.Trigger() diff --git a/pkg/protocol/engine/mempool/v1/mempool_test.go b/pkg/protocol/engine/mempool/v1/mempool_test.go index bb955f1a3..c41c9793a 100644 --- a/pkg/protocol/engine/mempool/v1/mempool_test.go +++ b/pkg/protocol/engine/mempool/v1/mempool_test.go @@ -39,7 +39,7 @@ func TestMempoolV1_ResourceCleanup(t *testing.T) { mempoolInstance := New[vote.MockedRank](mempooltests.TransactionValidator, mempooltests.TransactionExecutor, func(transaction mempool.Transaction) ([]iotago.Input, error) { return transaction.(*mempooltests.Transaction).Inputs() }, func(reference iotago.Input) *promise.Promise[mempool.State] { - return ledgerState.ResolveOutputState(reference.StateID()) + return ledgerState.ResolveOutputState(reference) }, workers, conflictDAG, api.SingleVersionProvider(tpkg.TestAPI), func(error) {}) tf := mempooltests.NewTestFramework(t, mempoolInstance, conflictDAG, ledgerState, workers) @@ -50,7 +50,7 @@ func TestMempoolV1_ResourceCleanup(t *testing.T) { signedTxAlias := fmt.Sprintf("tx%d-signed", index) txAlias := fmt.Sprintf("tx%d", index) blockAlias := fmt.Sprintf("block%d", index) - tf.CreateSignedTransaction(txAlias, []string{prevStateAlias}, 2) + tf.CreateSignedTransaction(txAlias, []string{}, []string{prevStateAlias}, 2) require.NoError(t, tf.AttachTransaction(signedTxAlias, txAlias, blockAlias, iotago.SlotIndex(index))) tf.RequireBooked(txAlias) @@ -110,7 +110,7 @@ func newTestFramework(t *testing.T) *mempooltests.TestFramework { return mempooltests.NewTestFramework(t, New[vote.MockedRank](mempooltests.TransactionValidator, mempooltests.TransactionExecutor, func(transaction mempool.Transaction) ([]iotago.Input, error) { return transaction.(*mempooltests.Transaction).Inputs() }, func(reference iotago.Input) *promise.Promise[mempool.State] { - return ledgerState.ResolveOutputState(reference.StateID()) + return ledgerState.ResolveOutputState(reference) }, workers, conflictDAG, api.SingleVersionProvider(tpkg.TestAPI), func(error) {}), conflictDAG, ledgerState, workers) } @@ -123,6 +123,6 @@ func newForkingTestFramework(t *testing.T) *mempooltests.TestFramework { return mempooltests.NewTestFramework(t, New[vote.MockedRank](mempooltests.TransactionValidator, mempooltests.TransactionExecutor, func(transaction mempool.Transaction) ([]iotago.Input, error) { return transaction.(*mempooltests.Transaction).Inputs() }, func(reference iotago.Input) *promise.Promise[mempool.State] { - return ledgerState.ResolveOutputState(reference.StateID()) + return ledgerState.ResolveOutputState(reference) }, workers, conflictDAG, api.SingleVersionProvider(tpkg.TestAPI), func(error) {}, WithForkAllTransactions[vote.MockedRank](true)), conflictDAG, ledgerState, workers) } diff --git a/pkg/protocol/engine/mempool/v1/transaction_metadata_test.go b/pkg/protocol/engine/mempool/v1/transaction_metadata_test.go index dae4107c4..53b184cd8 100644 --- a/pkg/protocol/engine/mempool/v1/transaction_metadata_test.go +++ b/pkg/protocol/engine/mempool/v1/transaction_metadata_test.go @@ -15,7 +15,7 @@ func TestAttachments(t *testing.T) { "2": iotago.SlotIdentifierRepresentingData(2, []byte("block2")), } - transactionMetadata, err := NewTransactionMetadata(mempooltests.NewTransaction(2), []iotago.Input{}) + transactionMetadata, err := NewTransactionMetadata(mempooltests.NewTransaction(2, []iotago.Input{}), []iotago.Input{}) require.NoError(t, err) signedTransactionMetadata, err := NewSignedTransactionMetadata(mempooltests.NewSignedTransaction(transactionMetadata.Transaction()), transactionMetadata) From 2986f9f2ec513ed1ff41fdc18d585c150b58a8ff Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:11:38 +0200 Subject: [PATCH 02/22] Post-merge fixes --- pkg/protocol/engine/ledger/ledger/vm.go | 6 +++--- pkg/protocol/engine/ledger/tests/state_resolver.go | 5 ----- pkg/protocol/engine/mempool/tests/tests.go | 2 -- pkg/protocol/engine/mempool/v1/mempool.go | 2 -- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/pkg/protocol/engine/ledger/ledger/vm.go b/pkg/protocol/engine/ledger/ledger/vm.go index 34fd045c1..43a45cf54 100644 --- a/pkg/protocol/engine/ledger/ledger/vm.go +++ b/pkg/protocol/engine/ledger/ledger/vm.go @@ -8,7 +8,7 @@ import ( "github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger" iotago "github.com/iotaledger/iota.go/v4" iotagovm "github.com/iotaledger/iota.go/v4/vm" - "github.com/iotaledger/iota.go/v4/vm/stardust" + "github.com/iotaledger/iota.go/v4/vm/nova" ) type VM struct { @@ -131,7 +131,7 @@ func (v *VM) ValidateSignatures(signedTransaction mempool.SignedTransaction, res RewardsInputSet: rewardInputSet, } - unlockedIdentities, err := stardust.NewVirtualMachine().ValidateUnlocks(signedStardustTransaction, resolvedInputs) + unlockedIdentities, err := nova.NewVirtualMachine().ValidateUnlocks(signedStardustTransaction, resolvedInputs) if err != nil { return nil, err } @@ -164,7 +164,7 @@ func (v *VM) Execute(executionContext context.Context, transaction mempool.Trans return nil, ierrors.Errorf("resolvedInputs not found in execution context") } - createdOutputs, err := stardust.NewVirtualMachine().Execute(stardustTransaction, resolvedInputs, unlockedIdentities) + createdOutputs, err := nova.NewVirtualMachine().Execute(stardustTransaction, resolvedInputs, unlockedIdentities) if err != nil { return nil, err } diff --git a/pkg/protocol/engine/ledger/tests/state_resolver.go b/pkg/protocol/engine/ledger/tests/state_resolver.go index 57e88d6be..fbfb556c6 100644 --- a/pkg/protocol/engine/ledger/tests/state_resolver.go +++ b/pkg/protocol/engine/ledger/tests/state_resolver.go @@ -1,8 +1,6 @@ package ledgertests import ( - "fmt" - "github.com/iotaledger/hive.go/ds/shrinkingmap" "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/iota-core/pkg/core/promise" @@ -40,8 +38,6 @@ func (s *MockStateResolver) ResolveOutputState(reference iotago.Input) *promise. return promise.New[mempool.State]().Reject(ierrors.Errorf("output %s not found: %w", reference.StateID().ToHex(), mempool.ErrStateNotFound)) } - fmt.Println("utxo input", output.StateID()) - return promise.New[mempool.State]().Resolve(output) } else if reference.Type() == iotago.InputCommitment { output := &iotago.Commitment{ @@ -53,7 +49,6 @@ func (s *MockStateResolver) ResolveOutputState(reference iotago.Input) *promise. ReferenceManaCost: 0, } - fmt.Println("comitment input", output.StateID()) return promise.New[mempool.State]().Resolve(output) } diff --git a/pkg/protocol/engine/mempool/tests/tests.go b/pkg/protocol/engine/mempool/tests/tests.go index 5c603c73a..e1c4bb176 100644 --- a/pkg/protocol/engine/mempool/tests/tests.go +++ b/pkg/protocol/engine/mempool/tests/tests.go @@ -95,7 +95,6 @@ func TestProcessTransactionWithReadOnlyInputs(t *testing.T, tf *TestFramework) { require.True(t, exists) _ = tx1Metadata.Outputs().ForEach(func(state mempool.StateMetadata) error { if state.State().Type() == iotago.InputUTXO { - fmt.Println("utxo", state.StateID()) require.False(t, state.IsAccepted()) require.Equal(t, 1, state.PendingSpenderCount()) } @@ -121,7 +120,6 @@ func TestProcessTransactionWithReadOnlyInputs(t *testing.T, tf *TestFramework) { }) conflictSetsTx1, exists := tf.ConflictDAG.ConflictSets(tf.TransactionID("tx1")) - fmt.Println(conflictSetsTx1.ToSlice()[0]) require.True(t, exists) require.Equal(t, 1, conflictSetsTx1.Size()) require.True(t, conflictSetsTx1.Has(tf.StateID("genesis"))) diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index 977aeae18..91e273c3a 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -2,7 +2,6 @@ package mempoolv1 import ( "context" - "fmt" "github.com/iotaledger/hive.go/core/memstorage" "github.com/iotaledger/hive.go/ds" @@ -280,7 +279,6 @@ func (m *MemPool[VoteRank]) bookTransaction(transaction *TransactionMetadata) { func (m *MemPool[VoteRank]) forkTransaction(transactionMetadata *TransactionMetadata, resourceIDs ds.Set[mempool.StateID]) { transactionMetadata.conflicting.Trigger() - fmt.Println("fork transaction", transactionMetadata.ID(), "resources", resourceIDs.ToSlice()) if err := m.conflictDAG.UpdateConflictingResources(transactionMetadata.ID(), resourceIDs); err != nil { transactionMetadata.orphaned.Trigger() From e77d5da2e72e4b66a55d511803daf20d848e953e Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:13:54 +0200 Subject: [PATCH 03/22] Fix linter problem --- pkg/protocol/engine/ledger/tests/state_resolver.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/protocol/engine/ledger/tests/state_resolver.go b/pkg/protocol/engine/ledger/tests/state_resolver.go index fbfb556c6..82561379c 100644 --- a/pkg/protocol/engine/ledger/tests/state_resolver.go +++ b/pkg/protocol/engine/ledger/tests/state_resolver.go @@ -40,6 +40,7 @@ func (s *MockStateResolver) ResolveOutputState(reference iotago.Input) *promise. return promise.New[mempool.State]().Resolve(output) } else if reference.Type() == iotago.InputCommitment { + //nolint:forcetypeassert output := &iotago.Commitment{ ProtocolVersion: 0, Slot: 0, From b191e42589e6d113397c4c63e97184a6fbf310fb Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:45:55 +0200 Subject: [PATCH 04/22] Implement read only flag --- pkg/protocol/engine/ledger/ledger/ledger.go | 9 ++++- pkg/protocol/engine/ledger/tests/state.go | 4 ++ .../engine/ledger/tests/state_resolver.go | 4 +- .../ledger/tests/stored_state_reference.go | 38 ------------------- pkg/protocol/engine/mempool/state.go | 2 + .../engine/mempool/tests/testframework.go | 6 +-- pkg/protocol/engine/mempool/v1/mempool.go | 28 ++++++++++---- pkg/protocol/engine/utxoledger/output.go | 4 ++ 8 files changed, 42 insertions(+), 53 deletions(-) delete mode 100644 pkg/protocol/engine/ledger/tests/stored_state_reference.go diff --git a/pkg/protocol/engine/ledger/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger/ledger.go index 5818a92ba..abe88c9f5 100644 --- a/pkg/protocol/engine/ledger/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger/ledger.go @@ -724,9 +724,14 @@ func (l *Ledger) resolveState(stateRef iotago.Input) *promise.Promise[mempool.St } return p.Resolve(loadedCommitment) - case iotago.InputBlockIssuanceCredit, iotago.InputReward: + case iotago.InputBlockIssuanceCredit: // these are always resolved as they depend on the commitment or UTXO inputs - return p.Resolve(stateRef) + //nolint:forcetypeassert // we can safely assume that this is a BlockIssuanceCreditInput + return p.Resolve(stateRef.(*iotago.BlockIssuanceCreditInput)) + case iotago.InputReward: + // these are always resolved as they depend on the commitment or UTXO inputs + //nolint:forcetypeassert // we can safely assume that this is a RewardInput + return p.Resolve(stateRef.(*iotago.RewardInput)) default: return p.Reject(ierrors.Errorf("unsupported input type %s", stateRef.Type())) } diff --git a/pkg/protocol/engine/ledger/tests/state.go b/pkg/protocol/engine/ledger/tests/state.go index 03513f308..1908a1ce0 100644 --- a/pkg/protocol/engine/ledger/tests/state.go +++ b/pkg/protocol/engine/ledger/tests/state.go @@ -27,6 +27,10 @@ func (m *MockedState) Type() iotago.StateType { return iotago.InputUTXO } +func (m *MockedState) ReadOnly() bool { + return false +} + func (m *MockedState) OutputID() iotago.OutputID { return m.id } diff --git a/pkg/protocol/engine/ledger/tests/state_resolver.go b/pkg/protocol/engine/ledger/tests/state_resolver.go index 82561379c..05a55241f 100644 --- a/pkg/protocol/engine/ledger/tests/state_resolver.go +++ b/pkg/protocol/engine/ledger/tests/state_resolver.go @@ -33,9 +33,9 @@ func (s *MockStateResolver) DestroyOutputState(stateID mempool.StateID) { func (s *MockStateResolver) ResolveOutputState(reference iotago.Input) *promise.Promise[mempool.State] { if reference.Type() == iotago.InputUTXO { - output, exists := s.statesByID.Get(reference.StateID()) + output, exists := s.statesByID.Get(reference.ReferencedStateID()) if !exists { - return promise.New[mempool.State]().Reject(ierrors.Errorf("output %s not found: %w", reference.StateID().ToHex(), mempool.ErrStateNotFound)) + return promise.New[mempool.State]().Reject(ierrors.Errorf("output %s not found: %w", reference.ReferencedStateID().ToHex(), mempool.ErrStateNotFound)) } return promise.New[mempool.State]().Resolve(output) diff --git a/pkg/protocol/engine/ledger/tests/stored_state_reference.go b/pkg/protocol/engine/ledger/tests/stored_state_reference.go deleted file mode 100644 index a4d6f520f..000000000 --- a/pkg/protocol/engine/ledger/tests/stored_state_reference.go +++ /dev/null @@ -1,38 +0,0 @@ -package ledgertests - -import ( - "github.com/iotaledger/hive.go/lo" - iotago "github.com/iotaledger/iota.go/v4" -) - -// StoredStateReference is a reference to a State that is stored in the ledger state. -type StoredStateReference iotago.OutputID - -func (l StoredStateReference) StateID() iotago.Identifier { - return iotago.IdentifierFromData(lo.PanicOnErr(l.OutputID().Bytes())) -} - -// Type returns the type of the StateReference. -func (l StoredStateReference) Type() iotago.StateType { - return 0 -} - -// Size returns the size of the StateReference. -func (l StoredStateReference) Size() int { - return 0 -} - -// WorkScore returns the workscore of the StateReference. -func (l StoredStateReference) WorkScore(_ *iotago.WorkScoreStructure) (iotago.WorkScore, error) { - return 0, nil -} - -// OutputID returns the ID of the referenced State in the ledger state. -func (l StoredStateReference) OutputID() iotago.OutputID { - return iotago.OutputID(l) -} - -// Index returns the Index of the referenced State. -func (l StoredStateReference) Index() uint16 { - return iotago.OutputID(l).Index() -} diff --git a/pkg/protocol/engine/mempool/state.go b/pkg/protocol/engine/mempool/state.go index 0b0c9ed9e..984f38dfd 100644 --- a/pkg/protocol/engine/mempool/state.go +++ b/pkg/protocol/engine/mempool/state.go @@ -6,4 +6,6 @@ type State interface { StateID() StateID Type() iotago.StateType + + ReadOnly() bool } diff --git a/pkg/protocol/engine/mempool/tests/testframework.go b/pkg/protocol/engine/mempool/tests/testframework.go index 8746772a7..7224922a4 100644 --- a/pkg/protocol/engine/mempool/tests/testframework.go +++ b/pkg/protocol/engine/mempool/tests/testframework.go @@ -92,7 +92,7 @@ func (t *TestFramework) CreateTransaction(alias string, referencedContextStates, TransactionOutputIndex: i, } - t.stateIDByAlias[alias+":"+strconv.Itoa(int(i))] = t.referencesByAlias[alias+":"+strconv.Itoa(int(i))].StateID() + t.stateIDByAlias[alias+":"+strconv.Itoa(int(i))] = t.referencesByAlias[alias+":"+strconv.Itoa(int(i))].ReferencedStateID() } } @@ -170,11 +170,11 @@ func (t *TestFramework) OutputStateMetadata(alias string) (mempool.StateMetadata func (t *TestFramework) StateID(alias string) mempool.StateID { if alias == "genesis" { - return (&iotago.UTXOInput{}).StateID() + return (&iotago.UTXOInput{}).ReferencedStateID() } stateID, exists := t.stateIDByAlias[alias] - require.True(t.test, exists, "StateID with alias '%s' does not exist", alias) + require.True(t.test, exists, "ReferencedStateID with alias '%s' does not exist", alias) return stateID } diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index 91e273c3a..c4dc79d3c 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -129,7 +129,7 @@ func (m *MemPool[VoteRank]) TransactionMetadata(id iotago.TransactionID) (transa // StateMetadata returns the metadata of the output state with the given ID. func (m *MemPool[VoteRank]) StateMetadata(stateReference mempool.StateReference) (state mempool.StateMetadata, err error) { - stateRequest, exists := m.cachedStateRequests.Get(stateReference.StateID()) + stateRequest, exists := m.cachedStateRequests.Get(stateReference.ReferencedStateID()) // create a new request that does not wait for missing states if !exists || !stateRequest.WasCompleted() { @@ -225,7 +225,7 @@ func (m *MemPool[VoteRank]) solidifyInputs(transaction *TransactionMetadata) { for i, inputReference := range transaction.inputReferences { stateReference, index := inputReference, i - request, created := m.cachedStateRequests.GetOrCreate(stateReference.StateID(), func() *promise.Promise[*StateMetadata] { + request, created := m.cachedStateRequests.GetOrCreate(stateReference.ReferencedStateID(), func() *promise.Promise[*StateMetadata] { return m.requestState(stateReference, true) }) @@ -261,14 +261,26 @@ func (m *MemPool[VoteRank]) executeTransaction(executionContext context.Context, func (m *MemPool[VoteRank]) bookTransaction(transaction *TransactionMetadata) { if m.optForkAllTransactions { - m.forkTransaction(transaction, ds.NewSet(lo.Map(transaction.inputs, func(stateMetadata *StateMetadata) mempool.StateID { - return stateMetadata.state.StateID() - })...)) + m.forkTransaction( + transaction, + ds.NewSet( + lo.Map( + lo.Filter(transaction.inputs, func(metadata *StateMetadata) bool { + return !metadata.state.ReadOnly() + }), + func(stateMetadata *StateMetadata) mempool.StateID { + return stateMetadata.state.StateID() + }, + )..., + ), + ) } else { lo.ForEach(transaction.inputs, func(input *StateMetadata) { - input.OnDoubleSpent(func() { - m.forkTransaction(transaction, ds.NewSet(input.state.StateID())) - }) + if !input.state.ReadOnly() { + input.OnDoubleSpent(func() { + m.forkTransaction(transaction, ds.NewSet(input.state.StateID())) + }) + } }) } diff --git a/pkg/protocol/engine/utxoledger/output.go b/pkg/protocol/engine/utxoledger/output.go index 86b557651..7d5654ea1 100644 --- a/pkg/protocol/engine/utxoledger/output.go +++ b/pkg/protocol/engine/utxoledger/output.go @@ -47,6 +47,10 @@ func (o *Output) Type() iotago.StateType { return iotago.InputUTXO } +func (o *Output) ReadOnly() bool { + return false +} + func (o *Output) OutputID() iotago.OutputID { return o.outputID } From 60b3033f5a7756f76a89db04c33553841280ca29 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 18:39:23 +0200 Subject: [PATCH 05/22] Refactor: simplified code --- go.mod | 2 +- go.sum | 4 ++-- pkg/protocol/engine/ledger/ledger/ledger.go | 10 ++-------- pkg/protocol/engine/mempool/state.go | 2 +- pkg/protocol/engine/utxoledger/output.go | 2 +- tools/evil-spammer/go.mod | 2 +- tools/evil-spammer/go.sum | 1 + tools/gendoc/go.mod | 2 +- tools/gendoc/go.sum | 1 + tools/genesis-snapshot/go.mod | 2 +- tools/genesis-snapshot/go.sum | 1 + 11 files changed, 13 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 265e877aa..d8379bda5 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd - github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a + github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 github.com/labstack/echo/v4 v4.11.1 github.com/labstack/gommon v0.4.0 github.com/libp2p/go-libp2p v0.30.0 diff --git a/go.sum b/go.sum index 1d30c914e..85b486c9b 100644 --- a/go.sum +++ b/go.sum @@ -305,8 +305,8 @@ github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 h1:lQikt github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182/go.mod h1:q24QEsS887ZWJVX76w2kwSgC84KS7wIKOy1otuqZ2ZM= github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd h1:nFG3Zq/zFA4KhBYFX2IezX1C74zfE0DqCt0LrgTa9Ig= github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a h1:xgh1YQvLN+Y3KwX1G9/znGbCaQsfpDtpSLn8nKvaP8s= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 h1:6G9oUOnhhK5oktcsl0BImbrPlgp6tdGskKsAmaMNw8Q= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= diff --git a/pkg/protocol/engine/ledger/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger/ledger.go index abe88c9f5..de5ba1ad2 100644 --- a/pkg/protocol/engine/ledger/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger/ledger.go @@ -724,14 +724,8 @@ func (l *Ledger) resolveState(stateRef iotago.Input) *promise.Promise[mempool.St } return p.Resolve(loadedCommitment) - case iotago.InputBlockIssuanceCredit: - // these are always resolved as they depend on the commitment or UTXO inputs - //nolint:forcetypeassert // we can safely assume that this is a BlockIssuanceCreditInput - return p.Resolve(stateRef.(*iotago.BlockIssuanceCreditInput)) - case iotago.InputReward: - // these are always resolved as they depend on the commitment or UTXO inputs - //nolint:forcetypeassert // we can safely assume that this is a RewardInput - return p.Resolve(stateRef.(*iotago.RewardInput)) + case iotago.InputBlockIssuanceCredit, iotago.InputReward: + return p.Resolve(stateRef.(mempool.State)) default: return p.Reject(ierrors.Errorf("unsupported input type %s", stateRef.Type())) } diff --git a/pkg/protocol/engine/mempool/state.go b/pkg/protocol/engine/mempool/state.go index 984f38dfd..13c723487 100644 --- a/pkg/protocol/engine/mempool/state.go +++ b/pkg/protocol/engine/mempool/state.go @@ -7,5 +7,5 @@ type State interface { Type() iotago.StateType - ReadOnly() bool + IsReadOnly() bool } diff --git a/pkg/protocol/engine/utxoledger/output.go b/pkg/protocol/engine/utxoledger/output.go index 7d5654ea1..285daf29c 100644 --- a/pkg/protocol/engine/utxoledger/output.go +++ b/pkg/protocol/engine/utxoledger/output.go @@ -47,7 +47,7 @@ func (o *Output) Type() iotago.StateType { return iotago.InputUTXO } -func (o *Output) ReadOnly() bool { +func (o *Output) IsReadOnly() bool { return false } diff --git a/tools/evil-spammer/go.mod b/tools/evil-spammer/go.mod index 0d9e3aa96..3878aded9 100644 --- a/tools/evil-spammer/go.mod +++ b/tools/evil-spammer/go.mod @@ -17,7 +17,7 @@ require ( github.com/iotaledger/hive.go/runtime v0.0.0-20230929122509-67f34bfed40d github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000 github.com/iotaledger/iota-core/tools/genesis-snapshot v0.0.0-00010101000000-000000000000 - github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a + github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 github.com/mr-tron/base58 v1.2.0 go.uber.org/atomic v1.11.0 ) diff --git a/tools/evil-spammer/go.sum b/tools/evil-spammer/go.sum index ddf98cf3b..b89c1fba6 100644 --- a/tools/evil-spammer/go.sum +++ b/tools/evil-spammer/go.sum @@ -197,6 +197,7 @@ github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d h1:ek github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a h1:xgh1YQvLN+Y3KwX1G9/znGbCaQsfpDtpSLn8nKvaP8s= github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= diff --git a/tools/gendoc/go.mod b/tools/gendoc/go.mod index ec2ff3eab..e61313f86 100644 --- a/tools/gendoc/go.mod +++ b/tools/gendoc/go.mod @@ -72,7 +72,7 @@ require ( github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d // indirect github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 // indirect github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd // indirect - github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a // indirect + github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 // indirect github.com/ipfs/boxo v0.10.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect diff --git a/tools/gendoc/go.sum b/tools/gendoc/go.sum index 56151f64a..5c30d7ed4 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -313,6 +313,7 @@ github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd h1:nFG3Zq github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a h1:xgh1YQvLN+Y3KwX1G9/znGbCaQsfpDtpSLn8nKvaP8s= github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= diff --git a/tools/genesis-snapshot/go.mod b/tools/genesis-snapshot/go.mod index 6a237325e..9800e8438 100644 --- a/tools/genesis-snapshot/go.mod +++ b/tools/genesis-snapshot/go.mod @@ -10,7 +10,7 @@ require ( github.com/iotaledger/hive.go/lo v0.0.0-20230929122509-67f34bfed40d github.com/iotaledger/hive.go/runtime v0.0.0-20230929122509-67f34bfed40d github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000 - github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a + github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 github.com/mr-tron/base58 v1.2.0 github.com/spf13/pflag v1.0.5 golang.org/x/crypto v0.13.0 diff --git a/tools/genesis-snapshot/go.sum b/tools/genesis-snapshot/go.sum index afe91a46a..42c734ed0 100644 --- a/tools/genesis-snapshot/go.sum +++ b/tools/genesis-snapshot/go.sum @@ -52,6 +52,7 @@ github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d h1:ek github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a h1:xgh1YQvLN+Y3KwX1G9/znGbCaQsfpDtpSLn8nKvaP8s= github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= From 1200b925da9cce6fdaff2ee281a396c7f74cbefe Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 18:42:05 +0200 Subject: [PATCH 06/22] Refactor: re-added comment --- pkg/protocol/engine/ledger/ledger/ledger.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/protocol/engine/ledger/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger/ledger.go index de5ba1ad2..4722b7cc9 100644 --- a/pkg/protocol/engine/ledger/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger/ledger.go @@ -725,6 +725,7 @@ func (l *Ledger) resolveState(stateRef iotago.Input) *promise.Promise[mempool.St return p.Resolve(loadedCommitment) case iotago.InputBlockIssuanceCredit, iotago.InputReward: + // these are always resolved as they depend on the commitment or UTXO inputs return p.Resolve(stateRef.(mempool.State)) default: return p.Reject(ierrors.Errorf("unsupported input type %s", stateRef.Type())) From 46b234f3e4c204b5e47876339331dc8db4efc8fd Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 18:54:04 +0200 Subject: [PATCH 07/22] Refactor: rverted some changes --- pkg/protocol/engine/mempool/tests/testframework.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/protocol/engine/mempool/tests/testframework.go b/pkg/protocol/engine/mempool/tests/testframework.go index 7224922a4..958c8a9ed 100644 --- a/pkg/protocol/engine/mempool/tests/testframework.go +++ b/pkg/protocol/engine/mempool/tests/testframework.go @@ -54,8 +54,8 @@ func NewTestFramework(test *testing.T, instance mempool.MemPool[vote.MockedRank] return t } -func (t *TestFramework) CreateSignedTransaction(transactionAlias string, referencedContextStates, referencedStates []string, outputCount uint16, invalid ...bool) { - t.CreateTransaction(transactionAlias, referencedContextStates, referencedStates, outputCount, invalid...) +func (t *TestFramework) CreateSignedTransaction(transactionAlias string, referencedStates []string, outputCount uint16, invalid ...bool) { + t.CreateTransaction(transactionAlias, referencedStates, outputCount, invalid...) t.SignedTransactionFromTransaction(transactionAlias+"-signed", transactionAlias) } func (t *TestFramework) SignedTransactionFromTransaction(signedTransactionAlias string, transactionAlias string) { @@ -73,9 +73,9 @@ func (t *TestFramework) SignedTransactionFromTransaction(signedTransactionAlias signedTransactionID.RegisterAlias(signedTransactionAlias) } -func (t *TestFramework) CreateTransaction(alias string, referencedContextStates, referencedStates []string, outputCount uint16, invalid ...bool) { +func (t *TestFramework) CreateTransaction(alias string, referencedStates []string, outputCount uint16, invalid ...bool) { // create transaction - transaction := NewTransaction(outputCount, lo.Map(referencedStates, t.stateReference), lo.Map(referencedContextStates, t.stateContextReference)...) + transaction := NewTransaction(outputCount, lo.Map(referencedStates, t.stateReference)...) transaction.invalidTransaction = len(invalid) > 0 && invalid[0] t.transactionByAlias[alias] = transaction From 3696eec95bf0843d29c7a104ca3ccff34a3efda5 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 18:56:26 +0200 Subject: [PATCH 08/22] Refactor: reverted changes --- .../engine/ledger/tests/state_resolver.go | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/pkg/protocol/engine/ledger/tests/state_resolver.go b/pkg/protocol/engine/ledger/tests/state_resolver.go index 05a55241f..1d56fa0ea 100644 --- a/pkg/protocol/engine/ledger/tests/state_resolver.go +++ b/pkg/protocol/engine/ledger/tests/state_resolver.go @@ -5,7 +5,6 @@ import ( "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/iota-core/pkg/core/promise" "github.com/iotaledger/iota-core/pkg/protocol/engine/mempool" - iotago "github.com/iotaledger/iota.go/v4" ) type MockStateResolver struct { @@ -31,29 +30,13 @@ func (s *MockStateResolver) DestroyOutputState(stateID mempool.StateID) { s.statesByID.Delete(stateID) } -func (s *MockStateResolver) ResolveOutputState(reference iotago.Input) *promise.Promise[mempool.State] { - if reference.Type() == iotago.InputUTXO { - output, exists := s.statesByID.Get(reference.ReferencedStateID()) - if !exists { - return promise.New[mempool.State]().Reject(ierrors.Errorf("output %s not found: %w", reference.ReferencedStateID().ToHex(), mempool.ErrStateNotFound)) - } - - return promise.New[mempool.State]().Resolve(output) - } else if reference.Type() == iotago.InputCommitment { - //nolint:forcetypeassert - output := &iotago.Commitment{ - ProtocolVersion: 0, - Slot: 0, - PreviousCommitmentID: reference.(*iotago.CommitmentInput).CommitmentID, - RootsID: iotago.Identifier{}, - CumulativeWeight: 0, - ReferenceManaCost: 0, - } - - return promise.New[mempool.State]().Resolve(output) +func (s *MockStateResolver) ResolveOutputState(outputID mempool.StateID) *promise.Promise[mempool.State] { + output, exists := s.statesByID.Get(outputID) + if !exists { + return promise.New[mempool.State]().Reject(ierrors.Errorf("output %s not found: %w", outputID.ToHex(), mempool.ErrStateNotFound)) } - return promise.New[mempool.State]().Reject(ierrors.Errorf("state not found")) + return promise.New[mempool.State]().Resolve(output) } func (s *MockStateResolver) Cleanup() { From 8a5369393f98f2af2e4263f71c6fff67179dcfca Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 18:57:53 +0200 Subject: [PATCH 09/22] Refactor: reverted more changes --- pkg/protocol/engine/mempool/tests/testframework.go | 4 ---- pkg/protocol/engine/mempool/tests/transaction.go | 10 ++++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pkg/protocol/engine/mempool/tests/testframework.go b/pkg/protocol/engine/mempool/tests/testframework.go index 958c8a9ed..22445154c 100644 --- a/pkg/protocol/engine/mempool/tests/testframework.go +++ b/pkg/protocol/engine/mempool/tests/testframework.go @@ -311,10 +311,6 @@ func (t *TestFramework) setupHookedEvents() { }) } -func (t *TestFramework) stateContextReference(alias string) mempool.StateReference { - return &iotago.CommitmentInput{CommitmentID: iotago.SlotIdentifierRepresentingData(0, []byte(alias))} -} - func (t *TestFramework) stateReference(alias string) mempool.StateReference { if alias == "genesis" { return &iotago.UTXOInput{} diff --git a/pkg/protocol/engine/mempool/tests/transaction.go b/pkg/protocol/engine/mempool/tests/transaction.go index 5345aebd0..d1fda2aa6 100644 --- a/pkg/protocol/engine/mempool/tests/transaction.go +++ b/pkg/protocol/engine/mempool/tests/transaction.go @@ -22,7 +22,6 @@ func (s *SignedTransaction) String() string { type Transaction struct { id iotago.TransactionID utxoInputs []iotago.Input - contextInputs []mempool.StateReference outputCount uint16 invalidTransaction bool } @@ -34,12 +33,11 @@ func NewSignedTransaction(transaction mempool.Transaction) *SignedTransaction { } } -func NewTransaction(outputCount uint16, inputs []mempool.StateReference, contextInputs ...mempool.StateReference) *Transaction { +func NewTransaction(outputCount uint16, inputs ...mempool.StateReference) *Transaction { return &Transaction{ - id: tpkg.RandTransactionID(), - utxoInputs: inputs, - contextInputs: contextInputs, - outputCount: outputCount, + id: tpkg.RandTransactionID(), + utxoInputs: inputs, + outputCount: outputCount, } } From 43bb5b4c77ff63f77f8ca73cc1301fcb23ba9e20 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:00:14 +0200 Subject: [PATCH 10/22] Refactor: reverted more changes --- pkg/protocol/engine/mempool/tests/tests.go | 72 +++++++++++----------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/pkg/protocol/engine/mempool/tests/tests.go b/pkg/protocol/engine/mempool/tests/tests.go index e1c4bb176..7b7523d7c 100644 --- a/pkg/protocol/engine/mempool/tests/tests.go +++ b/pkg/protocol/engine/mempool/tests/tests.go @@ -49,8 +49,8 @@ func TestAllWithForkingEverything(t *testing.T, frameworkProvider func(*testing. } func TestProcessTransaction(t *testing.T, tf *TestFramework) { - tf.CreateTransaction("tx1", []string{}, []string{"genesis"}, 1) - tf.CreateTransaction("tx2", []string{}, []string{"tx1:0"}, 1) + tf.CreateTransaction("tx1", []string{"genesis"}, 1) + tf.CreateTransaction("tx2", []string{"tx1:0"}, 1) tf.SignedTransactionFromTransaction("tx2", "tx2") tf.SignedTransactionFromTransaction("tx1", "tx1") @@ -81,8 +81,8 @@ func TestProcessTransaction(t *testing.T, tf *TestFramework) { } func TestProcessTransactionWithReadOnlyInputs(t *testing.T, tf *TestFramework) { - tf.CreateTransaction("tx1", []string{"readOnlyInput"}, []string{"genesis"}, 1) - tf.CreateTransaction("tx2", []string{"readOnlyInput"}, []string{"tx1:0"}, 1) + tf.CreateTransaction("tx1", []string{"genesis", "readOnlyInput"}, 1) + tf.CreateTransaction("tx2", []string{"tx1:0", "readOnlyInput"}, 1) tf.SignedTransactionFromTransaction("tx2", "tx2") tf.SignedTransactionFromTransaction("tx1", "tx1") @@ -131,9 +131,9 @@ func TestProcessTransactionWithReadOnlyInputs(t *testing.T, tf *TestFramework) { } func TestProcessTransactionsOutOfOrder(t *testing.T, tf *TestFramework) { - tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "tx3", 1)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "tx2", 1)) @@ -175,9 +175,9 @@ func TestProcessTransactionsOutOfOrder(t *testing.T, tf *TestFramework) { func TestSetInclusionSlot(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 3)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 2)) @@ -238,9 +238,9 @@ func TestSetInclusionSlot(t *testing.T, tf *TestFramework) { func TestSetTransactionOrphanage(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 3)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 2)) @@ -276,9 +276,9 @@ func TestSetTransactionOrphanage(t *testing.T, tf *TestFramework) { func TestSetTxOrphanageMultipleAttachments(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 4)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 3)) @@ -330,9 +330,9 @@ func TestSetTxOrphanageMultipleAttachments(t *testing.T, tf *TestFramework) { func TestStateDiff(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 1)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 1)) @@ -361,14 +361,14 @@ func TestStateDiff(t *testing.T, tf *TestFramework) { func TestConflictPropagationForkAll(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx1*", []string{}, []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx1*", []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx2*", []string{}, []string{"tx1*:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) - tf.CreateSignedTransaction("tx3*", []string{}, []string{"tx2*:0"}, 1) - tf.CreateSignedTransaction("tx4", []string{}, []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx2*", []string{"tx1*:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx3*", []string{"tx2*:0"}, 1) + tf.CreateSignedTransaction("tx4", []string{"tx1:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 3)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 2)) @@ -393,14 +393,14 @@ func TestConflictPropagationForkAll(t *testing.T, tf *TestFramework) { func TestConflictPropagationForkOnDoubleSpend(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx1*", []string{}, []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1) + tf.CreateSignedTransaction("tx1*", []string{"genesis"}, 1) - tf.CreateSignedTransaction("tx2", []string{}, []string{"tx1:0"}, 1) - tf.CreateSignedTransaction("tx2*", []string{}, []string{"tx1*:0"}, 1) - tf.CreateSignedTransaction("tx3", []string{}, []string{"tx2:0"}, 1) - tf.CreateSignedTransaction("tx3*", []string{}, []string{"tx2*:0"}, 1) - tf.CreateSignedTransaction("tx4", []string{}, []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx2", []string{"tx1:0"}, 1) + tf.CreateSignedTransaction("tx2*", []string{"tx1*:0"}, 1) + tf.CreateSignedTransaction("tx3", []string{"tx2:0"}, 1) + tf.CreateSignedTransaction("tx3*", []string{"tx2*:0"}, 1) + tf.CreateSignedTransaction("tx4", []string{"tx1:0"}, 1) require.NoError(t, tf.AttachTransaction("tx3-signed", "tx3", "block3", 3)) require.NoError(t, tf.AttachTransaction("tx2-signed", "tx2", "block2", 2)) @@ -426,7 +426,7 @@ func TestInvalidTransaction(t *testing.T, tf *TestFramework) { debug.SetEnabled(true) defer debug.SetEnabled(false) - tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1, true) + tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1, true) require.NoError(t, tf.AttachTransaction("tx1-signed", "tx1", "block2", 1)) tf.RequireInvalid("tx1") @@ -438,7 +438,7 @@ func TestStoreAttachmentInEvictedSlot(t *testing.T, tf *TestFramework) { tf.Instance.Evict(iotago.SlotIndex(5)) - tf.CreateSignedTransaction("tx1", []string{}, []string{"genesis"}, 1, true) + tf.CreateSignedTransaction("tx1", []string{"genesis"}, 1, true) require.Error(t, tf.AttachTransaction("tx1-signed", "tx1", "block2", 1)) require.False(t, lo.Return2(tf.TransactionMetadata("tx1"))) @@ -451,7 +451,7 @@ func TestMemoryRelease(t *testing.T, tf *TestFramework) { signedTxAlias := fmt.Sprintf("tx%d-signed", index) txAlias := fmt.Sprintf("tx%d", index) blockAlias := fmt.Sprintf("block%d", index) - tf.CreateSignedTransaction(txAlias, []string{}, []string{prevStateAlias}, 2) + tf.CreateSignedTransaction(txAlias, []string{prevStateAlias}, 2) require.NoError(t, tf.AttachTransaction(signedTxAlias, txAlias, blockAlias, iotago.SlotIndex(index))) tf.RequireBooked(txAlias) From 21168a4965c5a0d444c4531e9f9e7a65ce734741 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:02:29 +0200 Subject: [PATCH 11/22] Refactor: reverted more code --- pkg/protocol/engine/mempool/tests/transaction.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/pkg/protocol/engine/mempool/tests/transaction.go b/pkg/protocol/engine/mempool/tests/transaction.go index d1fda2aa6..3e0aae669 100644 --- a/pkg/protocol/engine/mempool/tests/transaction.go +++ b/pkg/protocol/engine/mempool/tests/transaction.go @@ -21,7 +21,7 @@ func (s *SignedTransaction) String() string { type Transaction struct { id iotago.TransactionID - utxoInputs []iotago.Input + inputs []mempool.StateReference outputCount uint16 invalidTransaction bool } @@ -36,7 +36,7 @@ func NewSignedTransaction(transaction mempool.Transaction) *SignedTransaction { func NewTransaction(outputCount uint16, inputs ...mempool.StateReference) *Transaction { return &Transaction{ id: tpkg.RandTransactionID(), - utxoInputs: inputs, + inputs: inputs, outputCount: outputCount, } } @@ -46,15 +46,7 @@ func (t *Transaction) ID() (iotago.TransactionID, error) { } func (t *Transaction) Inputs() ([]mempool.StateReference, error) { - return append(t.utxoInputs, t.contextInputs...), nil -} - -func (t *Transaction) UTXOInputs() ([]iotago.Input, error) { - return t.utxoInputs, nil -} - -func (t *Transaction) ContextInputs() ([]iotago.Input, error) { - return t.contextInputs, nil + return t.inputs, nil } func (t *Transaction) String() string { From e79b0e42c27e81f7d9d0211ca6723b639e117e96 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:07:36 +0200 Subject: [PATCH 12/22] Refactor: cleaned up more code --- pkg/protocol/engine/mempool/v1/mempool.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index a1657aa35..28f71c29a 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -265,22 +265,16 @@ func (m *MemPool[VoteRank]) executeTransaction(executionContext context.Context, func (m *MemPool[VoteRank]) bookTransaction(transaction *TransactionMetadata) { if m.optForkAllTransactions { - m.forkTransaction( - transaction, - ds.NewSet( - lo.Map( - lo.Filter(transaction.inputs, func(metadata *StateMetadata) bool { - return !metadata.state.ReadOnly() - }), - func(stateMetadata *StateMetadata) mempool.StateID { - return stateMetadata.state.StateID() - }, - )..., - ), - ) + inputsToFork := lo.Filter(transaction.inputs, func(metadata *StateMetadata) bool { + return !metadata.state.IsReadOnly() + }) + + m.forkTransaction(transaction, ds.NewSet(lo.Map(inputsToFork, func(stateMetadata *StateMetadata) mempool.StateID { + return stateMetadata.state.StateID() + })...)) } else { lo.ForEach(transaction.inputs, func(input *StateMetadata) { - if !input.state.ReadOnly() { + if !input.state.IsReadOnly() { input.OnDoubleSpent(func() { m.forkTransaction(transaction, ds.NewSet(input.state.StateID())) }) From 5f3de1e1126caf2968c6e88e8f1b219870726985 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:08:42 +0200 Subject: [PATCH 13/22] Refactor: minimized code changes --- pkg/protocol/engine/mempool/v1/mempool.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index 28f71c29a..8e3c80a60 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -289,6 +289,7 @@ func (m *MemPool[VoteRank]) bookTransaction(transaction *TransactionMetadata) { func (m *MemPool[VoteRank]) forkTransaction(transactionMetadata *TransactionMetadata, resourceIDs ds.Set[mempool.StateID]) { transactionMetadata.conflicting.Trigger() + if err := m.conflictDAG.UpdateConflictingResources(transactionMetadata.ID(), resourceIDs); err != nil { transactionMetadata.orphaned.Trigger() From 22b6e3e53684f7314a40ad239f4c72ecf4259804 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:10:45 +0200 Subject: [PATCH 14/22] Refactor: reverted more code --- pkg/protocol/engine/ledger/tests/state.go | 2 +- pkg/protocol/engine/mempool/v1/mempool_test.go | 2 +- pkg/protocol/engine/mempool/v1/transaction_metadata_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/protocol/engine/ledger/tests/state.go b/pkg/protocol/engine/ledger/tests/state.go index 1908a1ce0..c4d4766c0 100644 --- a/pkg/protocol/engine/ledger/tests/state.go +++ b/pkg/protocol/engine/ledger/tests/state.go @@ -27,7 +27,7 @@ func (m *MockedState) Type() iotago.StateType { return iotago.InputUTXO } -func (m *MockedState) ReadOnly() bool { +func (m *MockedState) IsReadOnly() bool { return false } diff --git a/pkg/protocol/engine/mempool/v1/mempool_test.go b/pkg/protocol/engine/mempool/v1/mempool_test.go index b151e6a15..c62e5339a 100644 --- a/pkg/protocol/engine/mempool/v1/mempool_test.go +++ b/pkg/protocol/engine/mempool/v1/mempool_test.go @@ -46,7 +46,7 @@ func TestMempoolV1_ResourceCleanup(t *testing.T) { signedTxAlias := fmt.Sprintf("tx%d-signed", index) txAlias := fmt.Sprintf("tx%d", index) blockAlias := fmt.Sprintf("block%d", index) - tf.CreateSignedTransaction(txAlias, []string{}, []string{prevStateAlias}, 2) + tf.CreateSignedTransaction(txAlias, []string{prevStateAlias}, 2) require.NoError(t, tf.AttachTransaction(signedTxAlias, txAlias, blockAlias, iotago.SlotIndex(index))) tf.RequireBooked(txAlias) diff --git a/pkg/protocol/engine/mempool/v1/transaction_metadata_test.go b/pkg/protocol/engine/mempool/v1/transaction_metadata_test.go index db7bb6462..988bbb42f 100644 --- a/pkg/protocol/engine/mempool/v1/transaction_metadata_test.go +++ b/pkg/protocol/engine/mempool/v1/transaction_metadata_test.go @@ -15,7 +15,7 @@ func TestAttachments(t *testing.T) { "2": iotago.SlotIdentifierRepresentingData(2, []byte("block2")), } - transactionMetadata, err := NewTransactionMetadata(mempooltests.NewTransaction(2, nil), nil) + transactionMetadata, err := NewTransactionMetadata(mempooltests.NewTransaction(2), nil) require.NoError(t, err) signedTransactionMetadata, err := NewSignedTransactionMetadata(mempooltests.NewSignedTransaction(transactionMetadata.Transaction()), transactionMetadata) From 25341cd25c1439b21d13a60169d000c5fa56e6b8 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:33:54 +0200 Subject: [PATCH 15/22] Refactor: added the ability to inject states --- .../engine/ledger/tests/state_resolver.go | 6 ++-- .../engine/mempool/state_reference.go | 7 ++++- .../engine/mempool/tests/testframework.go | 28 +++++++++++++++++++ pkg/protocol/engine/mempool/tests/tests.go | 9 ++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/pkg/protocol/engine/ledger/tests/state_resolver.go b/pkg/protocol/engine/ledger/tests/state_resolver.go index 1d56fa0ea..28f320b2b 100644 --- a/pkg/protocol/engine/ledger/tests/state_resolver.go +++ b/pkg/protocol/engine/ledger/tests/state_resolver.go @@ -30,10 +30,10 @@ func (s *MockStateResolver) DestroyOutputState(stateID mempool.StateID) { s.statesByID.Delete(stateID) } -func (s *MockStateResolver) ResolveOutputState(outputID mempool.StateID) *promise.Promise[mempool.State] { - output, exists := s.statesByID.Get(outputID) +func (s *MockStateResolver) ResolveOutputState(reference mempool.StateReference) *promise.Promise[mempool.State] { + output, exists := s.statesByID.Get(reference.ReferencedStateID()) if !exists { - return promise.New[mempool.State]().Reject(ierrors.Errorf("output %s not found: %w", outputID.ToHex(), mempool.ErrStateNotFound)) + return promise.New[mempool.State]().Reject(ierrors.Errorf("output %s not found: %w", reference.ReferencedStateID().ToHex(), mempool.ErrStateNotFound)) } return promise.New[mempool.State]().Resolve(output) diff --git a/pkg/protocol/engine/mempool/state_reference.go b/pkg/protocol/engine/mempool/state_reference.go index 37e7f596e..8cba0f962 100644 --- a/pkg/protocol/engine/mempool/state_reference.go +++ b/pkg/protocol/engine/mempool/state_reference.go @@ -2,4 +2,9 @@ package mempool import iotago "github.com/iotaledger/iota.go/v4" -type StateReference = iotago.Input +type StateReference interface { + ReferencedStateID() iotago.Identifier + + // Type returns the type of Input. + Type() iotago.StateType +} diff --git a/pkg/protocol/engine/mempool/tests/testframework.go b/pkg/protocol/engine/mempool/tests/testframework.go index 22445154c..71976e432 100644 --- a/pkg/protocol/engine/mempool/tests/testframework.go +++ b/pkg/protocol/engine/mempool/tests/testframework.go @@ -54,10 +54,18 @@ func NewTestFramework(test *testing.T, instance mempool.MemPool[vote.MockedRank] return t } + +func (t *TestFramework) InjectState(alias string, state mempool.State) { + t.referencesByAlias[alias] = NewStateReference(state.StateID(), state.Type()) + + t.ledgerState.AddOutputState(state) +} + func (t *TestFramework) CreateSignedTransaction(transactionAlias string, referencedStates []string, outputCount uint16, invalid ...bool) { t.CreateTransaction(transactionAlias, referencedStates, outputCount, invalid...) t.SignedTransactionFromTransaction(transactionAlias+"-signed", transactionAlias) } + func (t *TestFramework) SignedTransactionFromTransaction(signedTransactionAlias string, transactionAlias string) { transaction, exists := t.transactionByAlias[transactionAlias] require.True(t.test, exists, "transaction with alias %s does not exist", transactionAlias) @@ -399,3 +407,23 @@ func (t *TestFramework) Cleanup() { t.signedTransactionByAlias = make(map[string]mempool.SignedTransaction) t.blockIDsByAlias = make(map[string]iotago.BlockID) } + +type genericReference struct { + referencedStateID iotago.Identifier + stateType iotago.StateType +} + +func NewStateReference(referencedStateID iotago.Identifier, stateType iotago.StateType) mempool.StateReference { + return &genericReference{ + referencedStateID: referencedStateID, + stateType: stateType, + } +} + +func (g *genericReference) ReferencedStateID() iotago.Identifier { + return g.referencedStateID +} + +func (g *genericReference) Type() iotago.StateType { + return g.stateType +} diff --git a/pkg/protocol/engine/mempool/tests/tests.go b/pkg/protocol/engine/mempool/tests/tests.go index 7b7523d7c..33cb00f0b 100644 --- a/pkg/protocol/engine/mempool/tests/tests.go +++ b/pkg/protocol/engine/mempool/tests/tests.go @@ -81,6 +81,15 @@ func TestProcessTransaction(t *testing.T, tf *TestFramework) { } func TestProcessTransactionWithReadOnlyInputs(t *testing.T, tf *TestFramework) { + tf.InjectState("readOnlyInput", &iotago.Commitment{ + ProtocolVersion: 0, + Slot: 0, + PreviousCommitmentID: iotago.CommitmentID{}, + RootsID: iotago.Identifier{}, + CumulativeWeight: 0, + ReferenceManaCost: 0, + }) + tf.CreateTransaction("tx1", []string{"genesis", "readOnlyInput"}, 1) tf.CreateTransaction("tx2", []string{"tx1:0", "readOnlyInput"}, 1) From 9ee607721400363413a310aacdeda3c61d05e997 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:49:27 +0200 Subject: [PATCH 16/22] Refactor: fixed errors --- pkg/protocol/engine/ledger/ledger/ledger.go | 2 +- pkg/protocol/engine/ledger/ledger/vm.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/protocol/engine/ledger/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger/ledger.go index 4722b7cc9..34785aa8a 100644 --- a/pkg/protocol/engine/ledger/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger/ledger.go @@ -689,7 +689,7 @@ func (l *Ledger) resolveAccountOutput(accountID iotago.AccountID, slot iotago.Sl return accountOutput, nil } -func (l *Ledger) resolveState(stateRef iotago.Input) *promise.Promise[mempool.State] { +func (l *Ledger) resolveState(stateRef mempool.StateReference) *promise.Promise[mempool.State] { p := promise.New[mempool.State]() l.utxoLedger.ReadLockLedger() diff --git a/pkg/protocol/engine/ledger/ledger/vm.go b/pkg/protocol/engine/ledger/ledger/vm.go index 43a45cf54..720deaeb6 100644 --- a/pkg/protocol/engine/ledger/ledger/vm.go +++ b/pkg/protocol/engine/ledger/ledger/vm.go @@ -21,7 +21,7 @@ func NewVM(ledger *Ledger) *VM { } } -func (v *VM) Inputs(transaction mempool.Transaction) (inputReferences []iotago.Input, err error) { +func (v *VM) Inputs(transaction mempool.Transaction) (inputReferences []mempool.StateReference, err error) { stardustTransaction, ok := transaction.(*iotago.Transaction) if !ok { return nil, iotago.ErrTxTypeInvalid From dc853484f33f14710c400c8645255f67bfae934e Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:54:06 +0200 Subject: [PATCH 17/22] Refactor: reverted accidental changes --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index d8379bda5..19e887385 100644 --- a/go.mod +++ b/go.mod @@ -24,8 +24,8 @@ require ( github.com/iotaledger/hive.go/runtime v0.0.0-20230929122509-67f34bfed40d github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bfed40d github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d - github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 - github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd + github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231001095511-32be422a567e + github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951 github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 github.com/labstack/echo/v4 v4.11.1 github.com/labstack/gommon v0.4.0 diff --git a/go.sum b/go.sum index 85b486c9b..e8e58e9c5 100644 --- a/go.sum +++ b/go.sum @@ -301,10 +301,10 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bf github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bfed40d/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d h1:ekHWRypoaiCXgrJVUQS7rCewsK3FuG1gTbPxu5jYn9c= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 h1:lQiktl3Q0B+cHbVum7WzJikOEP+buw686oSrw5Unyz8= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182/go.mod h1:q24QEsS887ZWJVX76w2kwSgC84KS7wIKOy1otuqZ2ZM= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd h1:nFG3Zq/zFA4KhBYFX2IezX1C74zfE0DqCt0LrgTa9Ig= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231001095511-32be422a567e h1:Mwoe7M6gI2DAjJIXmIskgnI8KdxCY1LyEEhtJCNYBsU= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231001095511-32be422a567e/go.mod h1:jhzexR5X8m6qcmrwt5OX477O/ZwT7Ak9sPT83ByPkAo= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951 h1:qUf1W0fE1IyZzVy3Exv0Kj+SKECXG3S26c9m2ETb07U= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 h1:6G9oUOnhhK5oktcsl0BImbrPlgp6tdGskKsAmaMNw8Q= github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= From a28e0f5e07fcfc0a51d6896b6e8b39668d6fe50e Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:56:58 +0200 Subject: [PATCH 18/22] Refactor: reverted changes --- tools/gendoc/go.mod | 4 ++-- tools/gendoc/go.sum | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/gendoc/go.mod b/tools/gendoc/go.mod index e61313f86..09276b4f3 100644 --- a/tools/gendoc/go.mod +++ b/tools/gendoc/go.mod @@ -70,8 +70,8 @@ require ( github.com/iotaledger/hive.go/runtime v0.0.0-20230929122509-67f34bfed40d // indirect github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bfed40d // indirect github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d // indirect - github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 // indirect - github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd // indirect + github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231001095511-32be422a567e // indirect + github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951 // indirect github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 // indirect github.com/ipfs/boxo v0.10.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect diff --git a/tools/gendoc/go.sum b/tools/gendoc/go.sum index 5c30d7ed4..c72d672e7 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -307,12 +307,11 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bf github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bfed40d/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d h1:ekHWRypoaiCXgrJVUQS7rCewsK3FuG1gTbPxu5jYn9c= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 h1:lQiktl3Q0B+cHbVum7WzJikOEP+buw686oSrw5Unyz8= -github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182/go.mod h1:q24QEsS887ZWJVX76w2kwSgC84KS7wIKOy1otuqZ2ZM= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd h1:nFG3Zq/zFA4KhBYFX2IezX1C74zfE0DqCt0LrgTa9Ig= -github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a h1:xgh1YQvLN+Y3KwX1G9/znGbCaQsfpDtpSLn8nKvaP8s= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231001095511-32be422a567e h1:Mwoe7M6gI2DAjJIXmIskgnI8KdxCY1LyEEhtJCNYBsU= +github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231001095511-32be422a567e/go.mod h1:jhzexR5X8m6qcmrwt5OX477O/ZwT7Ak9sPT83ByPkAo= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951 h1:qUf1W0fE1IyZzVy3Exv0Kj+SKECXG3S26c9m2ETb07U= +github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 h1:6G9oUOnhhK5oktcsl0BImbrPlgp6tdGskKsAmaMNw8Q= github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM= From b6daf0693ad185dfd252cd0002da502ab9095d97 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:58:57 +0200 Subject: [PATCH 19/22] Refactor: fixed go.mod --- tools/evil-spammer/go.sum | 3 +-- tools/genesis-snapshot/go.sum | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/evil-spammer/go.sum b/tools/evil-spammer/go.sum index b89c1fba6..d5eed3cc4 100644 --- a/tools/evil-spammer/go.sum +++ b/tools/evil-spammer/go.sum @@ -195,8 +195,7 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bf github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bfed40d/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d h1:ekHWRypoaiCXgrJVUQS7rCewsK3FuG1gTbPxu5jYn9c= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a h1:xgh1YQvLN+Y3KwX1G9/znGbCaQsfpDtpSLn8nKvaP8s= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 h1:6G9oUOnhhK5oktcsl0BImbrPlgp6tdGskKsAmaMNw8Q= github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= diff --git a/tools/genesis-snapshot/go.sum b/tools/genesis-snapshot/go.sum index 42c734ed0..b70dd30c3 100644 --- a/tools/genesis-snapshot/go.sum +++ b/tools/genesis-snapshot/go.sum @@ -50,8 +50,7 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bf github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bfed40d/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d h1:ekHWRypoaiCXgrJVUQS7rCewsK3FuG1gTbPxu5jYn9c= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a h1:xgh1YQvLN+Y3KwX1G9/znGbCaQsfpDtpSLn8nKvaP8s= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003101444-5687809cd68a/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 h1:6G9oUOnhhK5oktcsl0BImbrPlgp6tdGskKsAmaMNw8Q= github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= From 761f77c6032ba6027695007a4834c31ffb5f47da Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 20:06:14 +0200 Subject: [PATCH 20/22] Refactor: fixed linter issue --- pkg/protocol/engine/ledger/ledger/ledger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/protocol/engine/ledger/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger/ledger.go index 34785aa8a..b96ca0c1d 100644 --- a/pkg/protocol/engine/ledger/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger/ledger.go @@ -725,7 +725,7 @@ func (l *Ledger) resolveState(stateRef mempool.StateReference) *promise.Promise[ return p.Resolve(loadedCommitment) case iotago.InputBlockIssuanceCredit, iotago.InputReward: - // these are always resolved as they depend on the commitment or UTXO inputs + //nolint:forcetypeassert return p.Resolve(stateRef.(mempool.State)) default: return p.Reject(ierrors.Errorf("unsupported input type %s", stateRef.Type())) From 2b9de43c458d277f3d8b4c023ca8761e8bbd0830 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 20:23:43 +0200 Subject: [PATCH 21/22] Refactor: upgraded to latest hive.go --- go.mod | 2 +- go.sum | 4 ++-- tools/evil-spammer/go.mod | 2 +- tools/evil-spammer/go.sum | 4 ++-- tools/gendoc/go.mod | 2 +- tools/gendoc/go.sum | 1 + tools/genesis-snapshot/go.mod | 2 +- tools/genesis-snapshot/go.sum | 4 ++-- 8 files changed, 11 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 19e887385..e15fa25e3 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231001095511-32be422a567e github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951 - github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 + github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737 github.com/labstack/echo/v4 v4.11.1 github.com/labstack/gommon v0.4.0 github.com/libp2p/go-libp2p v0.30.0 diff --git a/go.sum b/go.sum index e8e58e9c5..a899ff5e2 100644 --- a/go.sum +++ b/go.sum @@ -305,8 +305,8 @@ github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231001095511-32be422a567e h1:Mwoe7 github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231001095511-32be422a567e/go.mod h1:jhzexR5X8m6qcmrwt5OX477O/ZwT7Ak9sPT83ByPkAo= github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951 h1:qUf1W0fE1IyZzVy3Exv0Kj+SKECXG3S26c9m2ETb07U= github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 h1:6G9oUOnhhK5oktcsl0BImbrPlgp6tdGskKsAmaMNw8Q= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737 h1:6fuDHswgN9zTwsMuKRKNClnT+rJCojvWf3Hk8f03cvc= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= diff --git a/tools/evil-spammer/go.mod b/tools/evil-spammer/go.mod index 3878aded9..b4678fb13 100644 --- a/tools/evil-spammer/go.mod +++ b/tools/evil-spammer/go.mod @@ -17,7 +17,7 @@ require ( github.com/iotaledger/hive.go/runtime v0.0.0-20230929122509-67f34bfed40d github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000 github.com/iotaledger/iota-core/tools/genesis-snapshot v0.0.0-00010101000000-000000000000 - github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 + github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737 github.com/mr-tron/base58 v1.2.0 go.uber.org/atomic v1.11.0 ) diff --git a/tools/evil-spammer/go.sum b/tools/evil-spammer/go.sum index d5eed3cc4..97376751f 100644 --- a/tools/evil-spammer/go.sum +++ b/tools/evil-spammer/go.sum @@ -195,8 +195,8 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bf github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bfed40d/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d h1:ekHWRypoaiCXgrJVUQS7rCewsK3FuG1gTbPxu5jYn9c= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 h1:6G9oUOnhhK5oktcsl0BImbrPlgp6tdGskKsAmaMNw8Q= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737 h1:6fuDHswgN9zTwsMuKRKNClnT+rJCojvWf3Hk8f03cvc= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= diff --git a/tools/gendoc/go.mod b/tools/gendoc/go.mod index 09276b4f3..60253b09e 100644 --- a/tools/gendoc/go.mod +++ b/tools/gendoc/go.mod @@ -72,7 +72,7 @@ require ( github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d // indirect github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231001095511-32be422a567e // indirect github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951 // indirect - github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 // indirect + github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737 // indirect github.com/ipfs/boxo v0.10.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect diff --git a/tools/gendoc/go.sum b/tools/gendoc/go.sum index c72d672e7..5e0a9c086 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -313,6 +313,7 @@ github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951 h1:qUf1W0 github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231001095356-923e8f138951/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 h1:6G9oUOnhhK5oktcsl0BImbrPlgp6tdGskKsAmaMNw8Q= github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY= github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= diff --git a/tools/genesis-snapshot/go.mod b/tools/genesis-snapshot/go.mod index 9800e8438..ba29c06b3 100644 --- a/tools/genesis-snapshot/go.mod +++ b/tools/genesis-snapshot/go.mod @@ -10,7 +10,7 @@ require ( github.com/iotaledger/hive.go/lo v0.0.0-20230929122509-67f34bfed40d github.com/iotaledger/hive.go/runtime v0.0.0-20230929122509-67f34bfed40d github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000 - github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 + github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737 github.com/mr-tron/base58 v1.2.0 github.com/spf13/pflag v1.0.5 golang.org/x/crypto v0.13.0 diff --git a/tools/genesis-snapshot/go.sum b/tools/genesis-snapshot/go.sum index b70dd30c3..c69dca49d 100644 --- a/tools/genesis-snapshot/go.sum +++ b/tools/genesis-snapshot/go.sum @@ -50,8 +50,8 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bf github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230929122509-67f34bfed40d/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d h1:ekHWRypoaiCXgrJVUQS7rCewsK3FuG1gTbPxu5jYn9c= github.com/iotaledger/hive.go/stringify v0.0.0-20230929122509-67f34bfed40d/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0 h1:6G9oUOnhhK5oktcsl0BImbrPlgp6tdGskKsAmaMNw8Q= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003162632-bf50df95b5f0/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737 h1:6fuDHswgN9zTwsMuKRKNClnT+rJCojvWf3Hk8f03cvc= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003181920-a3245ad7a737/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s= github.com/ipfs/go-cid v0.4.1/go.mod h1:uQHwDeX4c6CtyrFwdqyhpNcxVewur1M7l7fNU7LKwZk= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= From d98fbddc4216f5a78efa62805a8c1b892edf9869 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 20:40:05 +0200 Subject: [PATCH 22/22] Refactor: changes to isReadOnly test in statediff --- pkg/protocol/engine/mempool/v1/state_diff.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pkg/protocol/engine/mempool/v1/state_diff.go b/pkg/protocol/engine/mempool/v1/state_diff.go index e0dcc847e..8a561cf47 100644 --- a/pkg/protocol/engine/mempool/v1/state_diff.go +++ b/pkg/protocol/engine/mempool/v1/state_diff.go @@ -98,19 +98,17 @@ func (s *StateDiff) RollbackTransaction(transaction *TransactionMetadata) error return nil } -func (s *StateDiff) compactStateChanges(output *StateMetadata, newValue int) { - if output.state.Type() != iotago.InputUTXO { - return - } - +func (s *StateDiff) compactStateChanges(stateMetadata *StateMetadata, usageCounter int) { switch { - case newValue > 0: - s.createdOutputs.Set(output.state.StateID(), output) - case newValue < 0: - s.spentOutputs.Set(output.state.StateID(), output) + case usageCounter > 0: + s.createdOutputs.Set(stateMetadata.state.StateID(), stateMetadata) + case usageCounter < 0: + if !stateMetadata.state.IsReadOnly() { + s.spentOutputs.Set(stateMetadata.state.StateID(), stateMetadata) + } default: - s.createdOutputs.Delete(output.state.StateID()) - s.spentOutputs.Delete(output.state.StateID()) + s.createdOutputs.Delete(stateMetadata.state.StateID()) + s.spentOutputs.Delete(stateMetadata.state.StateID()) } }