From f15e3674a18dd8976943939b28362124ba1eccd9 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 2 Oct 2023 20:03:26 +0200 Subject: [PATCH 01/12] add allotted Mana to throughput calculation and add 1 to deficit --- pkg/protocol/engine/accounts/mana.go | 2 + pkg/protocol/engine/accounts/mana/manager.go | 82 ++++++++++++++++--- .../scheduler/drr/scheduler.go | 4 +- pkg/protocol/engine/ledger/ledger/ledger.go | 10 ++- 4 files changed, 83 insertions(+), 15 deletions(-) diff --git a/pkg/protocol/engine/accounts/mana.go b/pkg/protocol/engine/accounts/mana.go index 8131a8fe2..207e19a24 100644 --- a/pkg/protocol/engine/accounts/mana.go +++ b/pkg/protocol/engine/accounts/mana.go @@ -22,6 +22,7 @@ func NewMana(value iotago.Mana, excessBaseTokens iotago.BaseToken, updateTime io } } +// Update is applied when the account output is transitioned, updating the total value and excess base tokens. func (m *Mana) Update(value iotago.Mana, excessBaseTokens iotago.BaseToken, updateTime iotago.SlotIndex) { m.mutex.Lock() defer m.mutex.Unlock() @@ -31,6 +32,7 @@ func (m *Mana) Update(value iotago.Mana, excessBaseTokens iotago.BaseToken, upda m.updateTime = updateTime } +// UpdateValue is applied when the total decayed value is updated but the account output is not changed. func (m *Mana) UpdateValue(value iotago.Mana, updateTime iotago.SlotIndex) { m.mutex.Lock() defer m.mutex.Unlock() diff --git a/pkg/protocol/engine/accounts/mana/manager.go b/pkg/protocol/engine/accounts/mana/manager.go index 7ea1a90e8..726cc6996 100644 --- a/pkg/protocol/engine/accounts/mana/manager.go +++ b/pkg/protocol/engine/accounts/mana/manager.go @@ -9,6 +9,7 @@ import ( "github.com/iotaledger/hive.go/lo" "github.com/iotaledger/hive.go/runtime/module" "github.com/iotaledger/hive.go/runtime/syncutils" + "github.com/iotaledger/iota-core/pkg/model" "github.com/iotaledger/iota-core/pkg/protocol/engine/accounts" "github.com/iotaledger/iota-core/pkg/protocol/engine/utxoledger" iotago "github.com/iotaledger/iota.go/v4" @@ -24,15 +25,18 @@ type Manager struct { accountOutputResolveFunc func(iotago.AccountID, iotago.SlotIndex) (*utxoledger.Output, error) + accountRetrieveFunc func(iotago.AccountID, iotago.SlotIndex) (*accounts.AccountData, bool, error) + mutex syncutils.Mutex module.Module } -func NewManager(apiProvider iotago.APIProvider, accountOutputResolveFunc func(iotago.AccountID, iotago.SlotIndex) (*utxoledger.Output, error)) *Manager { +func NewManager(apiProvider iotago.APIProvider, accountOutputResolveFunc func(iotago.AccountID, iotago.SlotIndex) (*utxoledger.Output, error), accountRetrieveFunc func(iotago.AccountID, iotago.SlotIndex) (*accounts.AccountData, bool, error)) *Manager { return &Manager{ apiProvider: apiProvider, accountOutputResolveFunc: accountOutputResolveFunc, + accountRetrieveFunc: accountRetrieveFunc, manaVectorCache: cache.New[iotago.AccountID, *accounts.Mana](10000), } } @@ -55,7 +59,17 @@ func (m *Manager) GetManaOnAccount(accountID iotago.AccountID, currentSlot iotag if err != nil { excessBaseTokens = 0 } - mana = accounts.NewMana(output.StoredMana(), excessBaseTokens, output.SlotCreated()) + + decayedBIC, err := m.getDecayedBIC(accountID, currentSlot) + if err != nil { + return 0, ierrors.Wrapf(err, "failed to get decayed BIC for %s", accountID) + } + totalMana, err := safemath.SafeAdd(output.StoredMana(), decayedBIC) + if err != nil { + return 0, ierrors.Wrapf(err, "overflow when adding stored mana and decayed BIC for account %s", accountID) + } + + mana = accounts.NewMana(totalMana, excessBaseTokens, output.SlotCreated()) if !exists { m.manaVectorCache.Put(accountID, mana) @@ -67,7 +81,7 @@ func (m *Manager) GetManaOnAccount(accountID iotago.AccountID, currentSlot iotag } manaDecayProvider := m.apiProvider.CurrentAPI().ManaDecayProvider() - // apply decay to stored Mana and potential that was added on last update + // apply decay to stored, allotted and potential that was added on last update manaStored, err := manaDecayProvider.ManaWithDecay(mana.Value(), mana.UpdateTime(), currentSlot) if err != nil { return 0, err @@ -79,14 +93,26 @@ func (m *Manager) GetManaOnAccount(accountID iotago.AccountID, currentSlot iotag if err != nil { return 0, err } - updatedValue += manaPotential + updatedValue, err = safemath.SafeAdd(updatedValue, manaPotential) + if err != nil { + return 0, ierrors.Wrapf(err, "overflow when adding stored and potential mana for account %s", accountID) + } + + decayedBIC, err := m.getDecayedBIC(accountID, currentSlot) + if err != nil { + return 0, ierrors.Wrapf(err, "failed to get decayed BIC for %s", accountID) + } + updatedValue, err = safemath.SafeAdd(updatedValue, decayedBIC) + if err != nil { + return 0, ierrors.Wrapf(err, "overflow when adding stored, potential and decayed BIC for account %s", accountID) + } mana.UpdateValue(updatedValue, currentSlot) return mana.Value(), nil } -func (m *Manager) ApplyDiff(slot iotago.SlotIndex, destroyedAccounts ds.Set[iotago.AccountID], accountOutputs map[iotago.AccountID]*utxoledger.Output) { +func (m *Manager) ApplyDiff(slot iotago.SlotIndex, destroyedAccounts ds.Set[iotago.AccountID], accountOutputs map[iotago.AccountID]*utxoledger.Output, accountDiffs map[iotago.AccountID]*model.AccountDiff) error { m.mutex.Lock() defer m.mutex.Unlock() @@ -94,15 +120,51 @@ func (m *Manager) ApplyDiff(slot iotago.SlotIndex, destroyedAccounts ds.Set[iota m.manaVectorCache.Remove(accountID) }) - for accountID, output := range accountOutputs { + for accountID := range accountDiffs { mana, exists := m.manaVectorCache.Get(accountID) if exists { - minDeposit := lo.PanicOnErr(m.apiProvider.CurrentAPI().RentStructure().MinDeposit(output.Output())) - excessBaseTokens, err := safemath.SafeSub(output.BaseTokenAmount(), minDeposit) + var excessBaseTokens iotago.BaseToken + var storedMana iotago.Mana + var err error + if output, has := accountOutputs[accountID]; has { + minDeposit := lo.PanicOnErr(m.apiProvider.CurrentAPI().RentStructure().MinDeposit(output.Output())) + excessBaseTokens, err = safemath.SafeSub(output.BaseTokenAmount(), minDeposit) + if err != nil { + excessBaseTokens = 0 + } + storedMana = output.StoredMana() + } + decayedBIC, err := m.getDecayedBIC(accountID, slot) + if err != nil { + return err + } + totalMana, err := safemath.SafeAdd(decayedBIC, storedMana) if err != nil { - excessBaseTokens = 0 + return ierrors.Wrapf(err, "overflow when adding stored mana and decayed BIC for account %s", accountID) } - mana.Update(output.StoredMana(), excessBaseTokens, slot) + + mana.Update(totalMana, excessBaseTokens, slot) } } + + return nil +} + +func (m *Manager) getDecayedBIC(accountID iotago.AccountID, slot iotago.SlotIndex) (iotago.Mana, error) { + accountBIC, exists, err := m.accountRetrieveFunc(accountID, slot) + if err != nil { + return 0, ierrors.Wrapf(err, "failed to retrieve account data for %s in slot %s", accountID, slot) + } + if !exists { + return 0, ierrors.Errorf("account data for %s in slot %s does not exist", accountID, slot) + } + if accountBIC.Credits.Value <= 0 { + return 0, nil + } + decayedBIC, err := m.apiProvider.CurrentAPI().ManaDecayProvider().ManaWithDecay(iotago.Mana(accountBIC.Credits.Value), accountBIC.Credits.UpdateTime, slot) + if err != nil { + return 0, ierrors.Wrapf(err, "failed to apply mana decay for account %s", accountID) + } + + return decayedBIC, nil } diff --git a/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go b/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go index 6603b45d8..d881dfed4 100644 --- a/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go +++ b/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go @@ -93,7 +93,9 @@ func NewProvider(opts ...options.Option[Scheduler]) module.Provider[*engine.Engi return 0, ierrors.Errorf("account %s has insufficient Mana for block to be scheduled: account Mana %d, min Mana %d", accountID, mana, minMana) } - return Deficit(mana / minMana), nil + mana = lo.Min(mana, iotago.Mana(s.maxDeficit()-1)) + + return 1 + Deficit(mana/minMana), nil } }) s.TriggerConstructed() diff --git a/pkg/protocol/engine/ledger/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger/ledger.go index f9bf12815..1dba6cd00 100644 --- a/pkg/protocol/engine/ledger/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger/ledger.go @@ -72,7 +72,7 @@ func NewProvider() module.Provider[*engine.Engine, ledger.Ledger] { l.memPool = mempoolv1.New(l.executeStardustVM, l.resolveState, e.Workers.CreateGroup("MemPool"), l.conflictDAG, e, l.errorHandler, mempoolv1.WithForkAllTransactions[ledger.BlockVoteRank](true)) e.EvictionState.Events.SlotEvicted.Hook(l.memPool.Evict) - l.manaManager = mana.NewManager(l.apiProvider, l.resolveAccountOutput) + l.manaManager = mana.NewManager(l.apiProvider, l.resolveAccountOutput, l.accountsLedger.Account) latestCommittedSlot := e.Storage.Settings().LatestCommitment().Slot() l.accountsLedger.SetLatestCommittedSlot(latestCommittedSlot) l.rmcManager.SetLatestCommittedSlot(latestCommittedSlot) @@ -170,9 +170,6 @@ func (l *Ledger) CommitSlot(slot iotago.SlotIndex) (stateRoot iotago.Identifier, l.prepareAccountDiffs(accountDiffs, slot, consumedAccounts, createdAccounts) // Commit the changes - // Update the mana manager's cache - l.manaManager.ApplyDiff(slot, destroyedAccounts, createdAccounts) - // Update the UTXO ledger if err = l.utxoLedger.ApplyDiff(slot, outputs, spends); err != nil { return iotago.Identifier{}, iotago.Identifier{}, iotago.Identifier{}, ierrors.Errorf("failed to apply diff to UTXO ledger for slot %d: %w", slot, err) @@ -190,6 +187,11 @@ func (l *Ledger) CommitSlot(slot iotago.SlotIndex) (stateRoot iotago.Identifier, return iotago.Identifier{}, iotago.Identifier{}, iotago.Identifier{}, ierrors.Errorf("failed to apply diff to Accounts ledger for slot %d: %w", slot, err) } + // Update the mana manager's cache + if err = l.manaManager.ApplyDiff(slot, destroyedAccounts, createdAccounts, accountDiffs); err != nil { + return iotago.Identifier{}, iotago.Identifier{}, iotago.Identifier{}, ierrors.Errorf("failed to apply diff to mana manager for slot %d: %w", slot, err) + } + // Mark each transaction as committed so the mempool can evict it stateDiff.ExecutedTransactions().ForEach(func(_ iotago.TransactionID, tx mempool.TransactionMetadata) bool { tx.Commit() From 14f8d593f9993035c66a31b27905a9689c377219 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 2 Oct 2023 20:33:45 +0200 Subject: [PATCH 02/12] use half of max value for BIC in tests to prevent overflow --- pkg/tests/upgrade_signaling_test.go | 14 +++++++------- pkg/testsuite/testsuite.go | 2 +- tools/genesis-snapshot/presets/presets.go | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/tests/upgrade_signaling_test.go b/pkg/tests/upgrade_signaling_test.go index 0423a590e..d30e6ee85 100644 --- a/pkg/tests/upgrade_signaling_test.go +++ b/pkg/tests/upgrade_signaling_test.go @@ -96,7 +96,7 @@ func Test_Upgrade_Signaling(t *testing.T) { ts.AssertAccountData(&accounts.AccountData{ ID: ts.Node("nodeA").AccountID, - Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits, UpdateTime: 0}, + Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits / 2, UpdateTime: 0}, ExpirySlot: iotago.MaxSlotIndex, OutputID: iotago.OutputIDFromTransactionIDAndIndex(snapshotcreator.GenesisTransactionID, 1), BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeA").PubKey))), @@ -109,7 +109,7 @@ func Test_Upgrade_Signaling(t *testing.T) { ts.AssertAccountData(&accounts.AccountData{ ID: ts.Node("nodeF").AccountID, - Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits, UpdateTime: 0}, + Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits / 2, UpdateTime: 0}, ExpirySlot: iotago.MaxSlotIndex, OutputID: iotago.OutputIDFromTransactionIDAndIndex(snapshotcreator.GenesisTransactionID, 6), BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeF").PubKey))), @@ -133,7 +133,7 @@ func Test_Upgrade_Signaling(t *testing.T) { // check account data before all nodes set the current version ts.AssertAccountData(&accounts.AccountData{ ID: ts.Node("nodeA").AccountID, - Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits, UpdateTime: 0}, + Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits / 2, UpdateTime: 0}, ExpirySlot: iotago.MaxSlotIndex, OutputID: iotago.OutputIDFromTransactionIDAndIndex(snapshotcreator.GenesisTransactionID, 1), BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeA").PubKey))), @@ -146,7 +146,7 @@ func Test_Upgrade_Signaling(t *testing.T) { ts.AssertAccountData(&accounts.AccountData{ ID: ts.Node("nodeD").AccountID, - Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits, UpdateTime: 0}, + Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits / 2, UpdateTime: 0}, ExpirySlot: iotago.MaxSlotIndex, OutputID: iotago.OutputIDFromTransactionIDAndIndex(snapshotcreator.GenesisTransactionID, 4), BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeD").PubKey))), @@ -167,7 +167,7 @@ func Test_Upgrade_Signaling(t *testing.T) { ts.AssertAccountData(&accounts.AccountData{ ID: ts.Node("nodeA").AccountID, - Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits, UpdateTime: 0}, + Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits / 2, UpdateTime: 0}, ExpirySlot: iotago.MaxSlotIndex, OutputID: iotago.OutputIDFromTransactionIDAndIndex(snapshotcreator.GenesisTransactionID, 1), BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeA").PubKey))), @@ -340,7 +340,7 @@ func Test_Upgrade_Signaling(t *testing.T) { // check account data at the end of the test ts.AssertAccountData(&accounts.AccountData{ ID: ts.Node("nodeA").AccountID, - Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits, UpdateTime: 0}, + Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits / 2, UpdateTime: 0}, ExpirySlot: iotago.MaxSlotIndex, OutputID: iotago.OutputIDFromTransactionIDAndIndex(snapshotcreator.GenesisTransactionID, 1), BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeA").PubKey))), @@ -353,7 +353,7 @@ func Test_Upgrade_Signaling(t *testing.T) { ts.AssertAccountData(&accounts.AccountData{ ID: ts.Node("nodeD").AccountID, - Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits, UpdateTime: 0}, + Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits / 2, UpdateTime: 0}, ExpirySlot: iotago.MaxSlotIndex, OutputID: iotago.OutputIDFromTransactionIDAndIndex(snapshotcreator.GenesisTransactionID, 4), BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeD").PubKey))), diff --git a/pkg/testsuite/testsuite.go b/pkg/testsuite/testsuite.go index c9a29042c..b01faafb1 100644 --- a/pkg/testsuite/testsuite.go +++ b/pkg/testsuite/testsuite.go @@ -357,7 +357,7 @@ func (t *TestSuite) addNodeToPartition(name string, partition string, validator Mana: iotago.Mana(amount), IssuerKey: iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(node.PubKey)), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits, + BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 2, } if validator { accountDetails.StakedAmount = accountDetails.Amount diff --git a/tools/genesis-snapshot/presets/presets.go b/tools/genesis-snapshot/presets/presets.go index dbfee7494..c3fab197f 100644 --- a/tools/genesis-snapshot/presets/presets.go +++ b/tools/genesis-snapshot/presets/presets.go @@ -43,7 +43,7 @@ var Docker = []options.Option[snapshotcreator.Options]{ Amount: testsuite.MinValidatorAccountAmount, IssuerKey: iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex("0x293dc170d9a59474e6d81cfba7f7d924c09b25d7166bcfba606e53114d0a758b")))), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits, + BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 2, StakingEpochEnd: iotago.MaxEpochIndex, FixedCost: 1, StakedAmount: testsuite.MinValidatorAccountAmount, @@ -55,7 +55,7 @@ var Docker = []options.Option[snapshotcreator.Options]{ Amount: testsuite.MinValidatorAccountAmount, IssuerKey: iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex("0x05c1de274451db8de8182d64c6ee0dca3ae0c9077e0b4330c976976171d79064")))), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits, + BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 2, StakingEpochEnd: iotago.MaxEpochIndex, FixedCost: 1, StakedAmount: testsuite.MinValidatorAccountAmount, @@ -67,7 +67,7 @@ var Docker = []options.Option[snapshotcreator.Options]{ Amount: testsuite.MinValidatorAccountAmount, IssuerKey: iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex("0x1e4b21eb51dcddf65c20db1065e1f1514658b23a3ddbf48d30c0efc926a9a648")))), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits, + BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 2, StakingEpochEnd: iotago.MaxEpochIndex, FixedCost: 1, StakedAmount: testsuite.MinValidatorAccountAmount, @@ -79,7 +79,7 @@ var Docker = []options.Option[snapshotcreator.Options]{ Amount: testsuite.MinIssuerAccountAmount, IssuerKey: iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex("0xa54fafa44a88e4a6a37796526ea884f613a24d84337871226eb6360f022d8b39")))), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits, + BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 2, Mana: iotago.Mana(testsuite.MinIssuerAccountAmount), }, snapshotcreator.AccountDetails{ // nomana2 @@ -88,7 +88,7 @@ var Docker = []options.Option[snapshotcreator.Options]{ Amount: testsuite.MinIssuerAccountAmount, IssuerKey: iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex("0xcb5ea14175ce649149ee41217c44aa70c3205b9939968449eae408727a71f91b")))), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits, + BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 2, Mana: iotago.Mana(testsuite.MinIssuerAccountAmount), }, ), @@ -115,7 +115,7 @@ var Feature = []options.Option[snapshotcreator.Options]{ Amount: testsuite.MinValidatorAccountAmount, IssuerKey: iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex("0x01fb6b9db5d96240aef00bc950d1c67a6494513f6d7cf784e57b4972b96ab2fe")))), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits, + BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 2, StakingEpochEnd: iotago.MaxEpochIndex, FixedCost: 1, StakedAmount: testsuite.MinValidatorAccountAmount, @@ -127,7 +127,7 @@ var Feature = []options.Option[snapshotcreator.Options]{ Amount: testsuite.MinValidatorAccountAmount, IssuerKey: iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex("0x83e7f71a440afd48981a8b4684ddae24434b7182ce5c47cfb56ac528525fd4b6")))), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits, + BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 2, StakingEpochEnd: iotago.MaxEpochIndex, FixedCost: 1, StakedAmount: testsuite.MinValidatorAccountAmount, @@ -139,7 +139,7 @@ var Feature = []options.Option[snapshotcreator.Options]{ Amount: testsuite.MinValidatorAccountAmount, IssuerKey: iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex("0xac628986b2ef52a1679f2289fcd7b4198476976dea4c30ae34ff04ae52e14805")))), ExpirySlot: iotago.MaxSlotIndex, - BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits, + BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 2, StakingEpochEnd: iotago.MaxEpochIndex, FixedCost: 1, StakedAmount: testsuite.MinValidatorAccountAmount, From 257665d61041b4e199adb46d0ad4ad5f47f997de Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 16:33:12 +0200 Subject: [PATCH 03/12] Feat: Introduce alias for StateReferences in mempool and cleanup types (#395) * Feat: bundled VM API in VM interface * Feat: added alias for StateReference * Fix: fixed more types * Feat: removed unused params * Refactor: refactored more code --- pkg/protocol/engine/ledger/ledger/ledger.go | 2 +- pkg/protocol/engine/ledger/ledger/vm.go | 26 +++++--- pkg/protocol/engine/mempool/mempool.go | 2 +- pkg/protocol/engine/mempool/state_metadata.go | 2 - .../engine/mempool/state_reference.go | 8 +-- pkg/protocol/engine/mempool/state_resolver.go | 8 +++ .../engine/mempool/tests/testframework.go | 8 +-- .../engine/mempool/tests/transaction.go | 6 +- pkg/protocol/engine/mempool/tests/vm.go | 23 +++++-- pkg/protocol/engine/mempool/transaction.go | 2 - pkg/protocol/engine/mempool/v1/mempool.go | 64 ++++++++----------- .../engine/mempool/v1/mempool_test.go | 38 +++++------ pkg/protocol/engine/mempool/v1/state_diff.go | 25 ++++---- .../engine/mempool/v1/state_metadata.go | 8 --- .../engine/mempool/v1/transaction_metadata.go | 4 +- .../mempool/v1/transaction_metadata_test.go | 2 +- pkg/protocol/engine/mempool/vm.go | 12 +++- 17 files changed, 122 insertions(+), 118 deletions(-) create mode 100644 pkg/protocol/engine/mempool/state_resolver.go diff --git a/pkg/protocol/engine/ledger/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger/ledger.go index 6136c26b2..5818a92ba 100644 --- a/pkg/protocol/engine/ledger/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger/ledger.go @@ -68,7 +68,7 @@ func NewProvider() module.Provider[*engine.Engine, ledger.Ledger] { l.setRetainTransactionFailureFunc(e.Retainer.RetainTransactionFailure) - l.memPool = mempoolv1.New(l.validateStardustTransaction, l.executeStardustVM, l.extractInputReferences, l.resolveState, e.Workers.CreateGroup("MemPool"), l.conflictDAG, e, l.errorHandler, mempoolv1.WithForkAllTransactions[ledger.BlockVoteRank](true)) + l.memPool = mempoolv1.New(NewVM(l), l.resolveState, e.Workers.CreateGroup("MemPool"), l.conflictDAG, l.errorHandler, mempoolv1.WithForkAllTransactions[ledger.BlockVoteRank](true)) e.EvictionState.Events.SlotEvicted.Hook(l.memPool.Evict) l.manaManager = mana.NewManager(l.apiProvider, l.resolveAccountOutput) diff --git a/pkg/protocol/engine/ledger/ledger/vm.go b/pkg/protocol/engine/ledger/ledger/vm.go index daf263543..34fd045c1 100644 --- a/pkg/protocol/engine/ledger/ledger/vm.go +++ b/pkg/protocol/engine/ledger/ledger/vm.go @@ -11,7 +11,17 @@ import ( "github.com/iotaledger/iota.go/v4/vm/stardust" ) -func (l *Ledger) extractInputReferences(transaction mempool.Transaction) (inputReferences []iotago.Input, err error) { +type VM struct { + ledger *Ledger +} + +func NewVM(ledger *Ledger) *VM { + return &VM{ + ledger: ledger, + } +} + +func (v *VM) Inputs(transaction mempool.Transaction) (inputReferences []iotago.Input, err error) { stardustTransaction, ok := transaction.(*iotago.Transaction) if !ok { return nil, iotago.ErrTxTypeInvalid @@ -27,7 +37,7 @@ func (l *Ledger) extractInputReferences(transaction mempool.Transaction) (inputR return inputReferences, nil } -func (l *Ledger) validateStardustTransaction(signedTransaction mempool.SignedTransaction, resolvedInputStates []mempool.State) (executionContext context.Context, err error) { +func (v *VM) ValidateSignatures(signedTransaction mempool.SignedTransaction, resolvedInputStates []mempool.State) (executionContext context.Context, err error) { signedStardustTransaction, ok := signedTransaction.(*iotago.SignedTransaction) if !ok { return nil, iotago.ErrTxTypeInvalid @@ -57,7 +67,7 @@ func (l *Ledger) validateStardustTransaction(signedTransaction mempool.SignedTra bicInputSet := make(iotagovm.BlockIssuanceCreditInputSet) for _, inp := range bicInputs { - accountData, exists, accountErr := l.accountsLedger.Account(inp.AccountID, commitmentInput.Slot) + accountData, exists, accountErr := v.ledger.accountsLedger.Account(inp.AccountID, commitmentInput.Slot) if accountErr != nil { return nil, ierrors.Join(iotago.ErrBICInputInvalid, ierrors.Wrapf(accountErr, "could not get BIC input for account %s in slot %d", inp.AccountID, commitmentInput.Slot)) } @@ -87,7 +97,7 @@ func (l *Ledger) validateStardustTransaction(signedTransaction mempool.SignedTra accountID = iotago.AccountIDFromOutputID(outputID) } - reward, _, _, rewardErr := l.sybilProtection.ValidatorReward(accountID, stakingFeature.StakedAmount, stakingFeature.StartEpoch, stakingFeature.EndEpoch) + reward, _, _, rewardErr := v.ledger.sybilProtection.ValidatorReward(accountID, stakingFeature.StakedAmount, stakingFeature.StartEpoch, stakingFeature.EndEpoch) if rewardErr != nil { return nil, ierrors.Wrapf(iotago.ErrFailedToClaimStakingReward, "failed to get Validator reward for AccountOutput %s at index %d (StakedAmount: %d, StartEpoch: %d, EndEpoch: %d", outputID, inp.Index, stakingFeature.StakedAmount, stakingFeature.StartEpoch, stakingFeature.EndEpoch) } @@ -102,10 +112,10 @@ func (l *Ledger) validateStardustTransaction(signedTransaction mempool.SignedTra delegationEnd := castOutput.EndEpoch if delegationEnd == 0 { - delegationEnd = l.apiProvider.APIForSlot(commitmentInput.Slot).TimeProvider().EpochFromSlot(commitmentInput.Slot) - iotago.EpochIndex(1) + delegationEnd = v.ledger.apiProvider.APIForSlot(commitmentInput.Slot).TimeProvider().EpochFromSlot(commitmentInput.Slot) - iotago.EpochIndex(1) } - reward, _, _, rewardErr := l.sybilProtection.DelegatorReward(castOutput.ValidatorAddress.AccountID(), castOutput.DelegatedAmount, castOutput.StartEpoch, delegationEnd) + reward, _, _, rewardErr := v.ledger.sybilProtection.DelegatorReward(castOutput.ValidatorAddress.AccountID(), castOutput.DelegatedAmount, castOutput.StartEpoch, delegationEnd) if rewardErr != nil { return nil, ierrors.Wrapf(iotago.ErrFailedToClaimDelegationReward, "failed to get Delegator reward for DelegationOutput %s at index %d (StakedAmount: %d, StartEpoch: %d, EndEpoch: %d", outputID, inp.Index, castOutput.DelegatedAmount, castOutput.StartEpoch, castOutput.EndEpoch) } @@ -133,7 +143,7 @@ func (l *Ledger) validateStardustTransaction(signedTransaction mempool.SignedTra return executionContext, nil } -func (l *Ledger) executeStardustVM(executionContext context.Context, transaction mempool.Transaction) (outputs []mempool.State, err error) { +func (v *VM) Execute(executionContext context.Context, transaction mempool.Transaction) (outputs []mempool.State, err error) { stardustTransaction, ok := transaction.(*iotago.Transaction) if !ok { return nil, iotago.ErrTxTypeInvalid @@ -161,7 +171,7 @@ func (l *Ledger) executeStardustVM(executionContext context.Context, transaction for index, output := range createdOutputs { outputs = append(outputs, utxoledger.CreateOutput( - l.apiProvider, + v.ledger.apiProvider, iotago.OutputIDFromTransactionIDAndIndex(transactionID, uint16(index)), iotago.EmptyBlockID(), 0, diff --git a/pkg/protocol/engine/mempool/mempool.go b/pkg/protocol/engine/mempool/mempool.go index 4f4bb8e18..d9b611009 100644 --- a/pkg/protocol/engine/mempool/mempool.go +++ b/pkg/protocol/engine/mempool/mempool.go @@ -15,7 +15,7 @@ type MemPool[VoteRank conflictdag.VoteRankType[VoteRank]] interface { MarkAttachmentIncluded(blockID iotago.BlockID) bool - StateMetadata(reference iotago.Input) (state StateMetadata, err error) + StateMetadata(reference StateReference) (state StateMetadata, err error) TransactionMetadata(id iotago.TransactionID) (transaction TransactionMetadata, exists bool) diff --git a/pkg/protocol/engine/mempool/state_metadata.go b/pkg/protocol/engine/mempool/state_metadata.go index 6227fd432..1a8b8cb2e 100644 --- a/pkg/protocol/engine/mempool/state_metadata.go +++ b/pkg/protocol/engine/mempool/state_metadata.go @@ -6,8 +6,6 @@ import ( ) type StateMetadata interface { - StateID() StateID - State() State ConflictIDs() reactive.Set[iotago.TransactionID] diff --git a/pkg/protocol/engine/mempool/state_reference.go b/pkg/protocol/engine/mempool/state_reference.go index 9c9de8d7e..37e7f596e 100644 --- a/pkg/protocol/engine/mempool/state_reference.go +++ b/pkg/protocol/engine/mempool/state_reference.go @@ -1,9 +1,5 @@ package mempool -import ( - "github.com/iotaledger/iota-core/pkg/core/promise" - iotago "github.com/iotaledger/iota.go/v4" -) +import iotago "github.com/iotaledger/iota.go/v4" -// StateReferenceResolver is a function that resolves a StateReference to a State. -type StateReferenceResolver func(reference iotago.Input) *promise.Promise[State] +type StateReference = iotago.Input diff --git a/pkg/protocol/engine/mempool/state_resolver.go b/pkg/protocol/engine/mempool/state_resolver.go new file mode 100644 index 000000000..0102800ff --- /dev/null +++ b/pkg/protocol/engine/mempool/state_resolver.go @@ -0,0 +1,8 @@ +package mempool + +import ( + "github.com/iotaledger/iota-core/pkg/core/promise" +) + +// StateResolver is a function that resolves a StateReference to a Promise with the State. +type StateResolver func(reference StateReference) *promise.Promise[State] diff --git a/pkg/protocol/engine/mempool/tests/testframework.go b/pkg/protocol/engine/mempool/tests/testframework.go index 57451f283..02125a3b3 100644 --- a/pkg/protocol/engine/mempool/tests/testframework.go +++ b/pkg/protocol/engine/mempool/tests/testframework.go @@ -22,7 +22,7 @@ type TestFramework struct { Instance mempool.MemPool[vote.MockedRank] ConflictDAG conflictdag.ConflictDAG[iotago.TransactionID, mempool.StateID, vote.MockedRank] - referencesByAlias map[string]iotago.Input + referencesByAlias map[string]mempool.StateReference stateIDByAlias map[string]mempool.StateID signedTransactionByAlias map[string]mempool.SignedTransaction transactionByAlias map[string]mempool.Transaction @@ -39,7 +39,7 @@ func NewTestFramework(test *testing.T, instance mempool.MemPool[vote.MockedRank] t := &TestFramework{ Instance: instance, ConflictDAG: conflictDAG, - referencesByAlias: make(map[string]iotago.Input), + referencesByAlias: make(map[string]mempool.StateReference), stateIDByAlias: make(map[string]mempool.StateID), signedTransactionByAlias: make(map[string]mempool.SignedTransaction), transactionByAlias: make(map[string]mempool.Transaction), @@ -311,7 +311,7 @@ func (t *TestFramework) setupHookedEvents() { }) } -func (t *TestFramework) stateReference(alias string) iotago.Input { +func (t *TestFramework) stateReference(alias string) mempool.StateReference { if alias == "genesis" { return &iotago.UTXOInput{} } @@ -393,7 +393,7 @@ func (t *TestFramework) Cleanup() { iotago.UnregisterIdentifierAliases() - t.referencesByAlias = make(map[string]iotago.Input) + t.referencesByAlias = make(map[string]mempool.StateReference) t.stateIDByAlias = make(map[string]mempool.StateID) t.transactionByAlias = make(map[string]mempool.Transaction) t.signedTransactionByAlias = make(map[string]mempool.SignedTransaction) diff --git a/pkg/protocol/engine/mempool/tests/transaction.go b/pkg/protocol/engine/mempool/tests/transaction.go index a21fb2523..0726b032b 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 - inputs []iotago.Input + inputs []mempool.StateReference outputCount uint16 invalidTransaction bool } @@ -33,7 +33,7 @@ func NewSignedTransaction(transaction mempool.Transaction) *SignedTransaction { } } -func NewTransaction(outputCount uint16, inputs ...iotago.Input) *Transaction { +func NewTransaction(outputCount uint16, inputs ...mempool.StateReference) *Transaction { return &Transaction{ id: tpkg.RandTransactionID(), inputs: inputs, @@ -45,7 +45,7 @@ func (t *Transaction) ID() (iotago.TransactionID, error) { return t.id, nil } -func (t *Transaction) Inputs() ([]iotago.Input, error) { +func (t *Transaction) Inputs() ([]mempool.StateReference, error) { return t.inputs, nil } diff --git a/pkg/protocol/engine/mempool/tests/vm.go b/pkg/protocol/engine/mempool/tests/vm.go index 4985e835f..e1e558954 100644 --- a/pkg/protocol/engine/mempool/tests/vm.go +++ b/pkg/protocol/engine/mempool/tests/vm.go @@ -8,22 +8,33 @@ import ( "github.com/iotaledger/iota-core/pkg/protocol/engine/mempool" ) -func TransactionValidator(_ mempool.SignedTransaction, _ []mempool.State) (executionContext context.Context, err error) { +type VM struct{} + +func (V *VM) Inputs(transaction mempool.Transaction) ([]mempool.StateReference, error) { + testTransaction, ok := transaction.(*Transaction) + if !ok { + return nil, ierrors.New("invalid transaction type in MockedVM") + } + + return testTransaction.Inputs() +} + +func (V *VM) ValidateSignatures(_ mempool.SignedTransaction, _ []mempool.State) (executionContext context.Context, err error) { return context.Background(), nil } -func TransactionExecutor(_ context.Context, inputTransaction mempool.Transaction) (outputs []mempool.State, err error) { - transaction, ok := inputTransaction.(*Transaction) +func (V *VM) Execute(_ context.Context, transaction mempool.Transaction) (outputs []mempool.State, err error) { + typedTransaction, ok := transaction.(*Transaction) if !ok { return nil, ierrors.New("invalid transaction type in MockedVM") } - if transaction.invalidTransaction { + if typedTransaction.invalidTransaction { return nil, ierrors.New("invalid transaction") } - for i := uint16(0); i < transaction.outputCount; i++ { - id, err := transaction.ID() + for i := uint16(0); i < typedTransaction.outputCount; i++ { + id, err := typedTransaction.ID() if err != nil { return nil, err } diff --git a/pkg/protocol/engine/mempool/transaction.go b/pkg/protocol/engine/mempool/transaction.go index fdad023a8..60b2dbde3 100644 --- a/pkg/protocol/engine/mempool/transaction.go +++ b/pkg/protocol/engine/mempool/transaction.go @@ -13,5 +13,3 @@ type Transaction interface { // ID returns the identifier of the Transaction. ID() (iotago.TransactionID, error) } - -type TransactionInputReferenceRetriever func(transaction Transaction) ([]iotago.Input, error) diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index 6e93935dc..a831184d1 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -21,19 +21,11 @@ import ( // MemPool is a component that manages the state of transactions that are not yet included in the ledger state. type MemPool[VoteRank conflictdag.VoteRankType[VoteRank]] struct { - signedTransactionAttached *event.Event1[mempool.SignedTransactionMetadata] - - transactionAttached *event.Event1[mempool.TransactionMetadata] - - // executeStateTransition is the TransactionExecutor that is used to execute the state transition of transactions. - executeStateTransition mempool.TransactionExecutor + // vm is the virtual machine that is used to validate and execute transactions. + vm mempool.VM // resolveState is the function that is used to request state from the ledger. - resolveState mempool.StateReferenceResolver - - inputsOfTransaction mempool.TransactionInputReferenceRetriever - - validateSignedTransaction mempool.TransactionValidator + resolveState mempool.StateResolver // attachments is the storage that is used to keep track of the attachments of transactions. attachments *memstorage.IndexedStorage[iotago.SlotIndex, iotago.BlockID, *SignedTransactionMetadata] @@ -66,27 +58,22 @@ type MemPool[VoteRank conflictdag.VoteRankType[VoteRank]] struct { optForkAllTransactions bool - apiProvider iotago.APIProvider + signedTransactionAttached *event.Event1[mempool.SignedTransactionMetadata] + + transactionAttached *event.Event1[mempool.TransactionMetadata] } // New is the constructor of the MemPool. func New[VoteRank conflictdag.VoteRankType[VoteRank]]( - transactionValidator mempool.TransactionValidator, - transactionExecutor mempool.TransactionExecutor, - transactionInputReferenceRetriever mempool.TransactionInputReferenceRetriever, - stateResolver mempool.StateReferenceResolver, + vm mempool.VM, + stateResolver mempool.StateResolver, workers *workerpool.Group, conflictDAG conflictdag.ConflictDAG[iotago.TransactionID, mempool.StateID, VoteRank], - apiProvider iotago.APIProvider, errorHandler func(error), opts ...options.Option[MemPool[VoteRank]], ) *MemPool[VoteRank] { return options.Apply(&MemPool[VoteRank]{ - signedTransactionAttached: event.New1[mempool.SignedTransactionMetadata](), - transactionAttached: event.New1[mempool.TransactionMetadata](), - validateSignedTransaction: transactionValidator, - executeStateTransition: transactionExecutor, - inputsOfTransaction: transactionInputReferenceRetriever, + vm: vm, resolveState: stateResolver, attachments: memstorage.NewIndexedStorage[iotago.SlotIndex, iotago.BlockID, *SignedTransactionMetadata](), cachedTransactions: shrinkingmap.New[iotago.TransactionID, *TransactionMetadata](), @@ -95,8 +82,9 @@ func New[VoteRank conflictdag.VoteRankType[VoteRank]]( stateDiffs: shrinkingmap.New[iotago.SlotIndex, *StateDiff](), executionWorkers: workers.CreatePool("executionWorkers", 1), conflictDAG: conflictDAG, - apiProvider: apiProvider, errorHandler: errorHandler, + signedTransactionAttached: event.New1[mempool.SignedTransactionMetadata](), + transactionAttached: event.New1[mempool.TransactionMetadata](), }, opts, (*MemPool[VoteRank]).setup) } @@ -140,7 +128,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 iotago.Input) (state mempool.StateMetadata, err error) { +func (m *MemPool[VoteRank]) StateMetadata(stateReference mempool.StateReference) (state mempool.StateMetadata, err error) { stateRequest, exists := m.cachedStateRequests.Get(stateReference.StateID()) // create a new request that does not wait for missing states @@ -202,7 +190,7 @@ func (m *MemPool[VoteRank]) storeTransaction(signedTransaction mempool.SignedTra return nil, false, false, ierrors.Errorf("blockID %d is older than last evicted slot %d", blockID.Slot(), m.lastEvictedSlot) } - inputReferences, err := m.inputsOfTransaction(transaction) + inputReferences, err := m.vm.Inputs(transaction) if err != nil { return nil, false, false, ierrors.Wrap(err, "failed to get input references of transaction") } @@ -261,7 +249,7 @@ func (m *MemPool[VoteRank]) solidifyInputs(transaction *TransactionMetadata) { func (m *MemPool[VoteRank]) executeTransaction(executionContext context.Context, transaction *TransactionMetadata) { m.executionWorkers.Submit(func() { - if outputStates, err := m.executeStateTransition(executionContext, transaction.Transaction()); err != nil { + if outputStates, err := m.vm.Execute(executionContext, transaction.Transaction()); err != nil { transaction.setInvalid(err) } else { transaction.setExecuted(outputStates) @@ -273,11 +261,13 @@ 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, (*StateMetadata).StateID)...)) + m.forkTransaction(transaction, ds.NewSet(lo.Map(transaction.inputs, 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.StateID())) + m.forkTransaction(transaction, ds.NewSet(input.state.StateID())) }) }) } @@ -299,7 +289,7 @@ func (m *MemPool[VoteRank]) forkTransaction(transactionMetadata *TransactionMeta func (m *MemPool[VoteRank]) publishOutputStates(transaction *TransactionMetadata) { for _, output := range transaction.outputs { - stateRequest, isNew := m.cachedStateRequests.GetOrCreate(output.StateID(), lo.NoVariadic(promise.New[*StateMetadata])) + stateRequest, isNew := m.cachedStateRequests.GetOrCreate(output.State().StateID(), lo.NoVariadic(promise.New[*StateMetadata])) stateRequest.Resolve(output) if isNew { @@ -308,7 +298,7 @@ func (m *MemPool[VoteRank]) publishOutputStates(transaction *TransactionMetadata } } -func (m *MemPool[VoteRank]) requestState(stateRef iotago.Input, waitIfMissing ...bool) *promise.Promise[*StateMetadata] { +func (m *MemPool[VoteRank]) requestState(stateRef mempool.StateReference, waitIfMissing ...bool) *promise.Promise[*StateMetadata] { return promise.New(func(p *promise.Promise[*StateMetadata]) { request := m.resolveState(stateRef) @@ -442,15 +432,15 @@ func (m *MemPool[VoteRank]) setupTransaction(transaction *TransactionMetadata) { }) } -func (m *MemPool[VoteRank]) setupOutputState(state *StateMetadata) { - state.OnCommitted(func() { - if !m.cachedStateRequests.Delete(state.StateID(), state.HasNoSpenders) && m.cachedStateRequests.Has(state.StateID()) { - state.onAllSpendersRemoved(func() { m.cachedStateRequests.Delete(state.StateID(), state.HasNoSpenders) }) +func (m *MemPool[VoteRank]) setupOutputState(stateMetadata *StateMetadata) { + stateMetadata.OnCommitted(func() { + if !m.cachedStateRequests.Delete(stateMetadata.state.StateID(), stateMetadata.HasNoSpenders) && m.cachedStateRequests.Has(stateMetadata.state.StateID()) { + stateMetadata.onAllSpendersRemoved(func() { m.cachedStateRequests.Delete(stateMetadata.state.StateID(), stateMetadata.HasNoSpenders) }) } }) - state.OnOrphaned(func() { - m.cachedStateRequests.Delete(state.StateID()) + stateMetadata.OnOrphaned(func() { + m.cachedStateRequests.Delete(stateMetadata.state.StateID()) }) } @@ -458,7 +448,7 @@ func (m *MemPool[VoteRank]) setupSignedTransaction(signedTransactionMetadata *Si transaction.addSigningTransaction(signedTransactionMetadata) transaction.OnSolid(func() { - executionContext, err := m.validateSignedTransaction(signedTransactionMetadata.SignedTransaction(), lo.Map(signedTransactionMetadata.transactionMetadata.inputs, (*StateMetadata).State)) + executionContext, err := m.vm.ValidateSignatures(signedTransactionMetadata.SignedTransaction(), lo.Map(signedTransactionMetadata.transactionMetadata.inputs, (*StateMetadata).State)) if err != nil { _ = signedTransactionMetadata.signaturesInvalid.Set(err) return diff --git a/pkg/protocol/engine/mempool/v1/mempool_test.go b/pkg/protocol/engine/mempool/v1/mempool_test.go index bb955f1a3..c4f64dee2 100644 --- a/pkg/protocol/engine/mempool/v1/mempool_test.go +++ b/pkg/protocol/engine/mempool/v1/mempool_test.go @@ -19,8 +19,6 @@ import ( "github.com/iotaledger/iota-core/pkg/protocol/engine/mempool/conflictdag/conflictdagv1" mempooltests "github.com/iotaledger/iota-core/pkg/protocol/engine/mempool/tests" iotago "github.com/iotaledger/iota.go/v4" - "github.com/iotaledger/iota.go/v4/api" - "github.com/iotaledger/iota.go/v4/tpkg" ) func TestMemPoolV1_InterfaceWithoutForkingEverything(t *testing.T) { @@ -36,13 +34,11 @@ func TestMempoolV1_ResourceCleanup(t *testing.T) { ledgerState := ledgertests.New(ledgertests.NewMockedState(iotago.TransactionID{}, 0)) conflictDAG := conflictdagv1.New[iotago.TransactionID, mempool.StateID, vote.MockedRank](func() int { return 0 }) - 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] { + memPoolInstance := New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] { return ledgerState.ResolveOutputState(reference.StateID()) - }, workers, conflictDAG, api.SingleVersionProvider(tpkg.TestAPI), func(error) {}) + }, workers, conflictDAG, func(error) {}) - tf := mempooltests.NewTestFramework(t, mempoolInstance, conflictDAG, ledgerState, workers) + tf := mempooltests.NewTestFramework(t, memPoolInstance, conflictDAG, ledgerState, workers) issueTransactions := func(startIndex, transactionCount int, prevStateAlias string) (int, string) { index := startIndex @@ -62,7 +58,7 @@ func TestMempoolV1_ResourceCleanup(t *testing.T) { tf.CommitSlot(iotago.SlotIndex(index)) tf.Instance.Evict(iotago.SlotIndex(index)) - require.Nil(t, mempoolInstance.attachments.Get(iotago.SlotIndex(index), false)) + require.Nil(t, memPoolInstance.attachments.Get(iotago.SlotIndex(index), false)) } return index, prevStateAlias @@ -74,19 +70,19 @@ func TestMempoolV1_ResourceCleanup(t *testing.T) { txIndex, prevStateAlias := issueTransactions(1, 10, "genesis") tf.WaitChildren() - require.Equal(t, 0, mempoolInstance.cachedTransactions.Size()) - require.Equal(t, 0, mempoolInstance.stateDiffs.Size()) - require.Equal(t, 0, mempoolInstance.cachedStateRequests.Size()) + require.Equal(t, 0, memPoolInstance.cachedTransactions.Size()) + require.Equal(t, 0, memPoolInstance.stateDiffs.Size()) + require.Equal(t, 0, memPoolInstance.cachedStateRequests.Size()) txIndex, prevStateAlias = issueTransactions(txIndex, 10, prevStateAlias) tf.WaitChildren() - require.Equal(t, 0, mempoolInstance.cachedTransactions.Size()) - require.Equal(t, 0, mempoolInstance.stateDiffs.Size()) - require.Equal(t, 0, mempoolInstance.cachedStateRequests.Size()) + require.Equal(t, 0, memPoolInstance.cachedTransactions.Size()) + require.Equal(t, 0, memPoolInstance.stateDiffs.Size()) + require.Equal(t, 0, memPoolInstance.cachedStateRequests.Size()) attachmentsSlotCount := 0 - mempoolInstance.attachments.ForEach(func(index iotago.SlotIndex, storage *shrinkingmap.ShrinkingMap[iotago.BlockID, *SignedTransactionMetadata]) { + memPoolInstance.attachments.ForEach(func(index iotago.SlotIndex, storage *shrinkingmap.ShrinkingMap[iotago.BlockID, *SignedTransactionMetadata]) { attachmentsSlotCount++ }) @@ -107,11 +103,9 @@ func newTestFramework(t *testing.T) *mempooltests.TestFramework { ledgerState := ledgertests.New(ledgertests.NewMockedState(iotago.TransactionID{}, 0)) conflictDAG := conflictdagv1.New[iotago.TransactionID, mempool.StateID, vote.MockedRank](account.NewAccounts().SelectCommittee().SeatCount) - 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 mempooltests.NewTestFramework(t, New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] { return ledgerState.ResolveOutputState(reference.StateID()) - }, workers, conflictDAG, api.SingleVersionProvider(tpkg.TestAPI), func(error) {}), conflictDAG, ledgerState, workers) + }, workers, conflictDAG, func(error) {}), conflictDAG, ledgerState, workers) } func newForkingTestFramework(t *testing.T) *mempooltests.TestFramework { @@ -120,9 +114,7 @@ func newForkingTestFramework(t *testing.T) *mempooltests.TestFramework { ledgerState := ledgertests.New(ledgertests.NewMockedState(iotago.TransactionID{}, 0)) conflictDAG := conflictdagv1.New[iotago.TransactionID, mempool.StateID, vote.MockedRank](account.NewAccounts().SelectCommittee().SeatCount) - 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 mempooltests.NewTestFramework(t, New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] { return ledgerState.ResolveOutputState(reference.StateID()) - }, workers, conflictDAG, api.SingleVersionProvider(tpkg.TestAPI), func(error) {}, WithForkAllTransactions[vote.MockedRank](true)), conflictDAG, ledgerState, workers) + }, workers, conflictDAG, func(error) {}, WithForkAllTransactions[vote.MockedRank](true)), conflictDAG, ledgerState, workers) } diff --git a/pkg/protocol/engine/mempool/v1/state_diff.go b/pkg/protocol/engine/mempool/v1/state_diff.go index b152f489d..e0dcc847e 100644 --- a/pkg/protocol/engine/mempool/v1/state_diff.go +++ b/pkg/protocol/engine/mempool/v1/state_diff.go @@ -56,17 +56,17 @@ func (s *StateDiff) Mutations() ads.Set[iotago.TransactionID] { } func (s *StateDiff) updateCompactedStateChanges(transaction *TransactionMetadata, direction int) { - transaction.Inputs().Range(func(input mempool.StateMetadata) { - s.compactStateChanges(input, s.stateUsageCounters.Compute(input.StateID(), func(currentValue int, _ bool) int { + for _, input := range transaction.inputs { + s.compactStateChanges(input, s.stateUsageCounters.Compute(input.state.StateID(), func(currentValue int, _ bool) int { return currentValue - direction })) - }) + } - transaction.Outputs().Range(func(output mempool.StateMetadata) { - s.compactStateChanges(output, s.stateUsageCounters.Compute(output.StateID(), func(currentValue int, _ bool) int { + for _, output := range transaction.outputs { + s.compactStateChanges(output, s.stateUsageCounters.Compute(output.state.StateID(), func(currentValue int, _ bool) int { return currentValue + direction })) - }) + } } func (s *StateDiff) AddTransaction(transaction *TransactionMetadata, errorHandler func(error)) error { @@ -91,25 +91,26 @@ func (s *StateDiff) RollbackTransaction(transaction *TransactionMetadata) error if _, err := s.mutations.Delete(transaction.ID()); err != nil { return ierrors.Wrapf(err, "failed to delete transaction from state diff's mutations, txID: %s", transaction.ID()) } + s.updateCompactedStateChanges(transaction, -1) } return nil } -func (s *StateDiff) compactStateChanges(output mempool.StateMetadata, newValue int) { - if output.State().Type() != iotago.InputUTXO { +func (s *StateDiff) compactStateChanges(output *StateMetadata, newValue int) { + if output.state.Type() != iotago.InputUTXO { return } switch { case newValue > 0: - s.createdOutputs.Set(output.StateID(), output) + s.createdOutputs.Set(output.state.StateID(), output) case newValue < 0: - s.spentOutputs.Set(output.StateID(), output) + s.spentOutputs.Set(output.state.StateID(), output) default: - s.createdOutputs.Delete(output.StateID()) - s.spentOutputs.Delete(output.StateID()) + s.createdOutputs.Delete(output.state.StateID()) + s.spentOutputs.Delete(output.state.StateID()) } } diff --git a/pkg/protocol/engine/mempool/v1/state_metadata.go b/pkg/protocol/engine/mempool/v1/state_metadata.go index 67a3f6aca..f7f1a6593 100644 --- a/pkg/protocol/engine/mempool/v1/state_metadata.go +++ b/pkg/protocol/engine/mempool/v1/state_metadata.go @@ -59,14 +59,6 @@ func (s *StateMetadata) setup(optSource ...*TransactionMetadata) *StateMetadata return s } -func (s *StateMetadata) StateID() mempool.StateID { - return s.state.StateID() -} - -func (s *StateMetadata) Type() iotago.StateType { - return iotago.InputUTXO -} - func (s *StateMetadata) State() mempool.State { return s.state } diff --git a/pkg/protocol/engine/mempool/v1/transaction_metadata.go b/pkg/protocol/engine/mempool/v1/transaction_metadata.go index 98e968577..c14b6fa08 100644 --- a/pkg/protocol/engine/mempool/v1/transaction_metadata.go +++ b/pkg/protocol/engine/mempool/v1/transaction_metadata.go @@ -16,7 +16,7 @@ import ( type TransactionMetadata struct { id iotago.TransactionID - inputReferences []iotago.Input + inputReferences []mempool.StateReference inputs []*StateMetadata outputs []*StateMetadata transaction mempool.Transaction @@ -57,7 +57,7 @@ func (t *TransactionMetadata) ValidAttachments() []iotago.BlockID { return t.validAttachments.Keys() } -func NewTransactionMetadata(transaction mempool.Transaction, referencedInputs []iotago.Input) (*TransactionMetadata, error) { +func NewTransactionMetadata(transaction mempool.Transaction, referencedInputs []mempool.StateReference) (*TransactionMetadata, error) { transactionID, transactionIDErr := transaction.ID() if transactionIDErr != nil { return nil, ierrors.Errorf("failed to retrieve transaction ID: %w", transactionIDErr) diff --git a/pkg/protocol/engine/mempool/v1/transaction_metadata_test.go b/pkg/protocol/engine/mempool/v1/transaction_metadata_test.go index dae4107c4..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), []iotago.Input{}) + transactionMetadata, err := NewTransactionMetadata(mempooltests.NewTransaction(2), nil) require.NoError(t, err) signedTransactionMetadata, err := NewSignedTransactionMetadata(mempooltests.NewSignedTransaction(transactionMetadata.Transaction()), transactionMetadata) diff --git a/pkg/protocol/engine/mempool/vm.go b/pkg/protocol/engine/mempool/vm.go index 0d05fb49c..a294ab057 100644 --- a/pkg/protocol/engine/mempool/vm.go +++ b/pkg/protocol/engine/mempool/vm.go @@ -4,6 +4,14 @@ import ( "context" ) -type TransactionValidator func(signedTransaction SignedTransaction, resolvedInputs []State) (executionContext context.Context, err error) +// VM is the interface that defines the virtual machine that is used to validate and execute transactions. +type VM interface { + // Inputs returns the referenced inputs of the given transaction. + Inputs(transaction Transaction) ([]StateReference, error) -type TransactionExecutor func(executionContext context.Context, transaction Transaction) (outputs []State, err error) + // ValidateSignatures validates the signatures of the given SignedTransaction and returns the execution context. + ValidateSignatures(signedTransaction SignedTransaction, inputs []State) (executionContext context.Context, err error) + + // Execute executes the transaction in the given execution context and returns the resulting states. + Execute(executionContext context.Context, transaction Transaction) (outputs []State, err error) +} From 2d94af33246df54428537149ac4e90ee64a9b392 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:00:55 +0200 Subject: [PATCH 04/12] Added a new inx method to validate if a transaction can be executed by the VM successfully --- components/inx/server_issuance.go | 71 +++++++++++++++++++++++ components/inx/server_tips.go | 18 ------ go.mod | 6 +- go.sum | 12 ++-- pkg/protocol/engine/ledger/ledger/vm.go | 6 +- pkg/protocol/engine/mempool/mempool.go | 2 + pkg/protocol/engine/mempool/v1/mempool.go | 4 ++ tools/evil-spammer/go.mod | 2 +- tools/evil-spammer/go.sum | 4 +- tools/gendoc/go.mod | 6 +- tools/gendoc/go.sum | 12 ++-- tools/genesis-snapshot/go.mod | 2 +- tools/genesis-snapshot/go.sum | 4 +- 13 files changed, 104 insertions(+), 45 deletions(-) create mode 100644 components/inx/server_issuance.go delete mode 100644 components/inx/server_tips.go diff --git a/components/inx/server_issuance.go b/components/inx/server_issuance.go new file mode 100644 index 000000000..ac17fea1b --- /dev/null +++ b/components/inx/server_issuance.go @@ -0,0 +1,71 @@ +package inx + +import ( + "context" + + "github.com/iotaledger/hive.go/serializer/v2/serix" + inx "github.com/iotaledger/inx/go" + "github.com/iotaledger/iota-core/pkg/protocol/engine/mempool" + iotago "github.com/iotaledger/iota.go/v4" +) + +func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.TipsResponse, error) { + references := deps.Protocol.MainEngineInstance().TipSelection.SelectTips(int(req.GetCount())) + + return &inx.TipsResponse{ + StrongTips: inx.NewBlockIds(references[iotago.StrongParentType]), + WeakTips: inx.NewBlockIds(references[iotago.WeakParentType]), + ShallowLikeTips: inx.NewBlockIds(references[iotago.ShallowLikeParentType]), + }, nil +} + +func (s *Server) ValidatePayload(ctx context.Context, payload *inx.RawPayload) (*inx.PayloadValidationResponse, error) { + blockPayload, unwrapErr := payload.Unwrap(deps.Protocol.CurrentAPI(), serix.WithValidation()) + if unwrapErr != nil { + //nolint:nilerr // this is expected behavior + return &inx.PayloadValidationResponse{IsValid: false, Error: unwrapErr.Error()}, nil + } + + switch payload := blockPayload.(type) { + case *iotago.SignedTransaction: + memPool := deps.Protocol.MainEngineInstance().Ledger.MemPool() + inputReferences, inputsErr := memPool.VM().Inputs(payload.Transaction) + if inputsErr != nil { + //nolint:nilerr // this is expected behavior + return &inx.PayloadValidationResponse{IsValid: false, Error: inputsErr.Error()}, nil + } + + loadedInputs := make([]mempool.State, 0) + + for _, inputReference := range inputReferences { + metadata, metadataErr := memPool.StateMetadata(inputReference) + if metadataErr != nil { + //nolint:nilerr // this is expected behavior + return &inx.PayloadValidationResponse{IsValid: false, Error: metadataErr.Error()}, nil + } + + loadedInputs = append(loadedInputs, metadata.State()) + } + + executionContext, validationErr := memPool.VM().ValidateSignatures(payload, loadedInputs) + if validationErr != nil { + //nolint:nilerr // this is expected behavior + return &inx.PayloadValidationResponse{IsValid: false, Error: validationErr.Error()}, nil + } + + _, executionErr := memPool.VM().Execute(executionContext, payload.Transaction) + if executionErr != nil { + //nolint:nilerr // this is expected behavior + return &inx.PayloadValidationResponse{IsValid: false, Error: executionErr.Error()}, nil + } + + return &inx.PayloadValidationResponse{IsValid: true}, nil + + case *iotago.TaggedData: + // TaggedData is always valid if serix decoding was successful + return &inx.PayloadValidationResponse{IsValid: true}, nil + + default: + return &inx.PayloadValidationResponse{IsValid: false, Error: "given payload type unknown"}, nil + } +} diff --git a/components/inx/server_tips.go b/components/inx/server_tips.go deleted file mode 100644 index ee107263f..000000000 --- a/components/inx/server_tips.go +++ /dev/null @@ -1,18 +0,0 @@ -package inx - -import ( - "context" - - inx "github.com/iotaledger/inx/go" - iotago "github.com/iotaledger/iota.go/v4" -) - -func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.TipsResponse, error) { - references := deps.Protocol.MainEngineInstance().TipSelection.SelectTips(int(req.GetCount())) - - return &inx.TipsResponse{ - StrongTips: inx.NewBlockIds(references[iotago.StrongParentType]), - WeakTips: inx.NewBlockIds(references[iotago.WeakParentType]), - ShallowLikeTips: inx.NewBlockIds(references[iotago.ShallowLikeParentType]), - }, nil -} diff --git a/go.mod b/go.mod index 265e877aa..ad29cdd90 100644 --- a/go.mod +++ b/go.mod @@ -24,9 +24,9 @@ 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/iota.go/v4 v4.0.0-20231003101444-5687809cd68a + 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-20231003122130-2871888a9297 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..9052996eb 100644 --- a/go.sum +++ b/go.sum @@ -301,12 +301,12 @@ 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-20231003122130-2871888a9297 h1:kbpsa/gF0x6Cxu5lN9TL8u5EdaGv1P3/OKKPW0w83Og= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003122130-2871888a9297/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/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/mempool/mempool.go b/pkg/protocol/engine/mempool/mempool.go index d9b611009..0b4535afc 100644 --- a/pkg/protocol/engine/mempool/mempool.go +++ b/pkg/protocol/engine/mempool/mempool.go @@ -19,6 +19,8 @@ type MemPool[VoteRank conflictdag.VoteRankType[VoteRank]] interface { TransactionMetadata(id iotago.TransactionID) (transaction TransactionMetadata, exists bool) + VM() VM + InjectRequestedState(state State) TransactionMetadataByAttachment(blockID iotago.BlockID) (transaction TransactionMetadata, exists bool) diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index a831184d1..e82a2ea5a 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -88,6 +88,10 @@ func New[VoteRank conflictdag.VoteRankType[VoteRank]]( }, opts, (*MemPool[VoteRank]).setup) } +func (m *MemPool[VoteRank]) VM() mempool.VM { + return m.vm +} + // AttachSignedTransaction adds a transaction to the MemPool that was attached by the given block. func (m *MemPool[VoteRank]) AttachSignedTransaction(signedTransaction mempool.SignedTransaction, transaction mempool.Transaction, blockID iotago.BlockID) (signedTransactionMetadata mempool.SignedTransactionMetadata, err error) { storedSignedTransaction, isNewSignedTransaction, isNewTransaction, err := m.storeTransaction(signedTransaction, transaction, blockID) diff --git a/tools/evil-spammer/go.mod b/tools/evil-spammer/go.mod index 0d9e3aa96..be4d5ccb5 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-20231003122130-2871888a9297 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..6388ee5b3 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-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-20231003122130-2871888a9297 h1:kbpsa/gF0x6Cxu5lN9TL8u5EdaGv1P3/OKKPW0w83Og= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003122130-2871888a9297/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..06bd92756 100644 --- a/tools/gendoc/go.mod +++ b/tools/gendoc/go.mod @@ -70,9 +70,9 @@ 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/iota.go/v4 v4.0.0-20231003101444-5687809cd68a // 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-20231003122130-2871888a9297 // 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..5e53af302 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -307,12 +307,12 @@ 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-20231003122130-2871888a9297 h1:kbpsa/gF0x6Cxu5lN9TL8u5EdaGv1P3/OKKPW0w83Og= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003122130-2871888a9297/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..8a4a3785d 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-20231003122130-2871888a9297 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..fcf0ce336 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-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-20231003122130-2871888a9297 h1:kbpsa/gF0x6Cxu5lN9TL8u5EdaGv1P3/OKKPW0w83Og= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003122130-2871888a9297/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 ec67cbe6bd970274e4096e2b6e2590b4f9b9802e Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:14:55 +0200 Subject: [PATCH 05/12] Feat: cleaned up error handling --- components/inx/server_issuance.go | 73 +++++++++++++++---------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/components/inx/server_issuance.go b/components/inx/server_issuance.go index ac17fea1b..ee4c42253 100644 --- a/components/inx/server_issuance.go +++ b/components/inx/server_issuance.go @@ -3,6 +3,8 @@ package inx import ( "context" + "github.com/iotaledger/hive.go/ierrors" + "github.com/iotaledger/hive.go/lo" "github.com/iotaledger/hive.go/serializer/v2/serix" inx "github.com/iotaledger/inx/go" "github.com/iotaledger/iota-core/pkg/protocol/engine/mempool" @@ -20,52 +22,47 @@ func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.Tips } func (s *Server) ValidatePayload(ctx context.Context, payload *inx.RawPayload) (*inx.PayloadValidationResponse, error) { - blockPayload, unwrapErr := payload.Unwrap(deps.Protocol.CurrentAPI(), serix.WithValidation()) - if unwrapErr != nil { - //nolint:nilerr // this is expected behavior - return &inx.PayloadValidationResponse{IsValid: false, Error: unwrapErr.Error()}, nil - } - - switch payload := blockPayload.(type) { - case *iotago.SignedTransaction: - memPool := deps.Protocol.MainEngineInstance().Ledger.MemPool() - inputReferences, inputsErr := memPool.VM().Inputs(payload.Transaction) - if inputsErr != nil { - //nolint:nilerr // this is expected behavior - return &inx.PayloadValidationResponse{IsValid: false, Error: inputsErr.Error()}, nil + if err := func() error { + blockPayload, unwrapErr := payload.Unwrap(deps.Protocol.CurrentAPI(), serix.WithValidation()) + if unwrapErr != nil { + return unwrapErr } - loadedInputs := make([]mempool.State, 0) + switch typedPayload := blockPayload.(type) { + case *iotago.SignedTransaction: + memPool := deps.Protocol.MainEngineInstance().Ledger.MemPool() - for _, inputReference := range inputReferences { - metadata, metadataErr := memPool.StateMetadata(inputReference) - if metadataErr != nil { - //nolint:nilerr // this is expected behavior - return &inx.PayloadValidationResponse{IsValid: false, Error: metadataErr.Error()}, nil + inputReferences, inputsErr := memPool.VM().Inputs(typedPayload.Transaction) + if inputsErr != nil { + return inputsErr } - loadedInputs = append(loadedInputs, metadata.State()) - } - - executionContext, validationErr := memPool.VM().ValidateSignatures(payload, loadedInputs) - if validationErr != nil { - //nolint:nilerr // this is expected behavior - return &inx.PayloadValidationResponse{IsValid: false, Error: validationErr.Error()}, nil - } + loadedInputs := make([]mempool.State, 0) + for _, inputReference := range inputReferences { + if metadata, metadataErr := memPool.StateMetadata(inputReference); metadataErr != nil { + return metadataErr + } else { + loadedInputs = append(loadedInputs, metadata.State()) + } + } - _, executionErr := memPool.VM().Execute(executionContext, payload.Transaction) - if executionErr != nil { - //nolint:nilerr // this is expected behavior - return &inx.PayloadValidationResponse{IsValid: false, Error: executionErr.Error()}, nil - } + executionContext, validationErr := memPool.VM().ValidateSignatures(typedPayload, loadedInputs) + if validationErr != nil { + return validationErr + } - return &inx.PayloadValidationResponse{IsValid: true}, nil + return lo.Return2(memPool.VM().Execute(executionContext, typedPayload.Transaction)) - case *iotago.TaggedData: - // TaggedData is always valid if serix decoding was successful - return &inx.PayloadValidationResponse{IsValid: true}, nil + case *iotago.TaggedData: + return nil - default: - return &inx.PayloadValidationResponse{IsValid: false, Error: "given payload type unknown"}, nil + default: + return ierrors.Errorf("unsupported payload type: %T", typedPayload) + } + }(); err != nil { + //nolint:nilerr // this is expected behavior + return &inx.PayloadValidationResponse{IsValid: false, Error: err.Error()}, nil } + + return &inx.PayloadValidationResponse{IsValid: true}, nil } From bb4d6a0e8d571cd9589e7a05304e72b936568301 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:18:48 +0200 Subject: [PATCH 06/12] Feat: cleaned more --- components/inx/server_issuance.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/components/inx/server_issuance.go b/components/inx/server_issuance.go index ee4c42253..1cb2eecb6 100644 --- a/components/inx/server_issuance.go +++ b/components/inx/server_issuance.go @@ -46,13 +46,12 @@ func (s *Server) ValidatePayload(ctx context.Context, payload *inx.RawPayload) ( } } - executionContext, validationErr := memPool.VM().ValidateSignatures(typedPayload, loadedInputs) - if validationErr != nil { + if executionContext, validationErr := memPool.VM().ValidateSignatures(typedPayload, loadedInputs); validationErr != nil { return validationErr + } else { + return lo.Return2(memPool.VM().Execute(executionContext, typedPayload.Transaction)) } - return lo.Return2(memPool.VM().Execute(executionContext, typedPayload.Transaction)) - case *iotago.TaggedData: return nil From bc4c49234b40807cd707325635a6cf88b4462b76 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:21:13 +0200 Subject: [PATCH 07/12] Feat: re-added comment --- components/inx/server_issuance.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/inx/server_issuance.go b/components/inx/server_issuance.go index 1cb2eecb6..967366335 100644 --- a/components/inx/server_issuance.go +++ b/components/inx/server_issuance.go @@ -21,7 +21,7 @@ func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.Tips }, nil } -func (s *Server) ValidatePayload(ctx context.Context, payload *inx.RawPayload) (*inx.PayloadValidationResponse, error) { +func (s *Server) ValidatePayload(payload *inx.RawPayload) (*inx.PayloadValidationResponse, error) { if err := func() error { blockPayload, unwrapErr := payload.Unwrap(deps.Protocol.CurrentAPI(), serix.WithValidation()) if unwrapErr != nil { @@ -53,6 +53,7 @@ func (s *Server) ValidatePayload(ctx context.Context, payload *inx.RawPayload) ( } case *iotago.TaggedData: + // TaggedData is always valid if serix decoding was successful return nil default: From f0c45ae651afa6aeb8aa55fc1aded3e86e3fbd5d Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:23:29 +0200 Subject: [PATCH 08/12] Refactor: added unused context again --- components/inx/server_issuance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/inx/server_issuance.go b/components/inx/server_issuance.go index 967366335..376f8e0c5 100644 --- a/components/inx/server_issuance.go +++ b/components/inx/server_issuance.go @@ -21,7 +21,7 @@ func (s *Server) RequestTips(_ context.Context, req *inx.TipsRequest) (*inx.Tips }, nil } -func (s *Server) ValidatePayload(payload *inx.RawPayload) (*inx.PayloadValidationResponse, error) { +func (s *Server) ValidatePayload(_ context.Context, payload *inx.RawPayload) (*inx.PayloadValidationResponse, error) { if err := func() error { blockPayload, unwrapErr := payload.Unwrap(deps.Protocol.CurrentAPI(), serix.WithValidation()) if unwrapErr != nil { From 4fa5e495a2a248c838169dfd375dbb9fc64320e4 Mon Sep 17 00:00:00 2001 From: Hans Moog <3293976+hmoog@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:32:26 +0200 Subject: [PATCH 09/12] Refactor: addressed linter issues --- components/inx/server_issuance.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/components/inx/server_issuance.go b/components/inx/server_issuance.go index 376f8e0c5..828380f08 100644 --- a/components/inx/server_issuance.go +++ b/components/inx/server_issuance.go @@ -39,19 +39,21 @@ func (s *Server) ValidatePayload(_ context.Context, payload *inx.RawPayload) (*i loadedInputs := make([]mempool.State, 0) for _, inputReference := range inputReferences { - if metadata, metadataErr := memPool.StateMetadata(inputReference); metadataErr != nil { + metadata, metadataErr := memPool.StateMetadata(inputReference) + if metadataErr != nil { return metadataErr - } else { - loadedInputs = append(loadedInputs, metadata.State()) } + + loadedInputs = append(loadedInputs, metadata.State()) } - if executionContext, validationErr := memPool.VM().ValidateSignatures(typedPayload, loadedInputs); validationErr != nil { + executionContext, validationErr := memPool.VM().ValidateSignatures(typedPayload, loadedInputs) + if validationErr != nil { return validationErr - } else { - return lo.Return2(memPool.VM().Execute(executionContext, typedPayload.Transaction)) } + return lo.Return2(memPool.VM().Execute(executionContext, typedPayload.Transaction)) + case *iotago.TaggedData: // TaggedData is always valid if serix decoding was successful return nil From cd61f7774ca66e216d354bb3584f9ca94b94b061 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 3 Oct 2023 17:54:32 +0200 Subject: [PATCH 10/12] remove minMana from protocol parameters --- go.mod | 2 +- go.sum | 4 ++-- .../engine/congestioncontrol/scheduler/drr/scheduler.go | 7 +------ pkg/testsuite/testsuite.go | 3 --- tools/evil-spammer/go.mod | 2 +- tools/evil-spammer/go.sum | 4 ++-- tools/gendoc/go.mod | 2 +- tools/gendoc/go.sum | 4 ++-- tools/genesis-snapshot/go.mod | 2 +- tools/genesis-snapshot/go.sum | 4 ++-- 10 files changed, 13 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index ad29cdd90..484cbaff6 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-20231003122130-2871888a9297 + github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388 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 9052996eb..2fd9470ee 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-20231003122130-2871888a9297 h1:kbpsa/gF0x6Cxu5lN9TL8u5EdaGv1P3/OKKPW0w83Og= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003122130-2871888a9297/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388 h1:IGqHrJRmrzfalf1py+FGWzkWoaA5o6avBSYWznVG08s= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388/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/congestioncontrol/scheduler/drr/scheduler.go b/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go index d881dfed4..8eb606cd3 100644 --- a/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go +++ b/pkg/protocol/engine/congestioncontrol/scheduler/drr/scheduler.go @@ -88,14 +88,9 @@ func NewProvider(opts ...options.Option[Scheduler]) module.Provider[*engine.Engi return 0, err } - minMana := s.apiProvider.CurrentAPI().ProtocolParameters().CongestionControlParameters().MinMana - if mana < minMana { - return 0, ierrors.Errorf("account %s has insufficient Mana for block to be scheduled: account Mana %d, min Mana %d", accountID, mana, minMana) - } - mana = lo.Min(mana, iotago.Mana(s.maxDeficit()-1)) - return 1 + Deficit(mana/minMana), nil + return 1 + Deficit(mana), nil } }) s.TriggerConstructed() diff --git a/pkg/testsuite/testsuite.go b/pkg/testsuite/testsuite.go index b01faafb1..ab5e67b5a 100644 --- a/pkg/testsuite/testsuite.go +++ b/pkg/testsuite/testsuite.go @@ -57,7 +57,6 @@ type TestSuite struct { optsRMCIncreaseThreshold iotago.WorkScore optsRMCDecreaseThreshold iotago.WorkScore optsSchedulerRate iotago.WorkScore - optsMinMana iotago.Mana optsMaxBufferSize uint32 optsAccounts []snapshotcreator.AccountDetails optsSnapshotOptions []options.Option[snapshotcreator.Options] @@ -98,7 +97,6 @@ func NewTestSuite(testingT *testing.T, opts ...options.Option[TestSuite]) *TestS optsRMCIncreaseThreshold: 8 * schedulerRate, optsRMCDecreaseThreshold: 5 * schedulerRate, optsSchedulerRate: schedulerRate, - optsMinMana: 1, optsMaxBufferSize: 100 * iotago.MaxBlockSize, }, opts, func(t *TestSuite) { fmt.Println("Setup TestSuite -", testingT.Name(), " @ ", time.Now()) @@ -136,7 +134,6 @@ func NewTestSuite(testingT *testing.T, opts ...options.Option[TestSuite]) *TestS t.optsRMCIncreaseThreshold, t.optsRMCDecreaseThreshold, t.optsSchedulerRate, - t.optsMinMana, t.optsMaxBufferSize, t.optsMaxBufferSize, ), diff --git a/tools/evil-spammer/go.mod b/tools/evil-spammer/go.mod index be4d5ccb5..1fe7c131b 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-20231003122130-2871888a9297 + github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388 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 6388ee5b3..2da3ca0c4 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-20231003122130-2871888a9297 h1:kbpsa/gF0x6Cxu5lN9TL8u5EdaGv1P3/OKKPW0w83Og= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003122130-2871888a9297/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388 h1:IGqHrJRmrzfalf1py+FGWzkWoaA5o6avBSYWznVG08s= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388/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 06bd92756..97a51cd75 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-20231003122130-2871888a9297 // indirect + github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388 // 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 5e53af302..d35f5a5a3 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -311,8 +311,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-20231003122130-2871888a9297 h1:kbpsa/gF0x6Cxu5lN9TL8u5EdaGv1P3/OKKPW0w83Og= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003122130-2871888a9297/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388 h1:IGqHrJRmrzfalf1py+FGWzkWoaA5o6avBSYWznVG08s= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388/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 8a4a3785d..09c576a38 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-20231003122130-2871888a9297 + github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388 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 fcf0ce336..105293b91 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-20231003122130-2871888a9297 h1:kbpsa/gF0x6Cxu5lN9TL8u5EdaGv1P3/OKKPW0w83Og= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003122130-2871888a9297/go.mod h1:+e3bsJFDr9HxmUMe+eQOLNut5wfcB/ivhJdouOJgOnE= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388 h1:IGqHrJRmrzfalf1py+FGWzkWoaA5o6avBSYWznVG08s= +github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388/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 90a5c0bce1adbb1f5c36395d1670d288a0d1e404 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 3 Oct 2023 18:22:03 +0200 Subject: [PATCH 11/12] remove minMana argument from presets --- tools/genesis-snapshot/presets/presets.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/genesis-snapshot/presets/presets.go b/tools/genesis-snapshot/presets/presets.go index c3fab197f..e39a86667 100644 --- a/tools/genesis-snapshot/presets/presets.go +++ b/tools/genesis-snapshot/presets/presets.go @@ -25,7 +25,7 @@ var Base = []options.Option[snapshotcreator.Options]{ iotago.WithTimeProviderOptions(time.Now().Unix(), 10, 13), iotago.WithLivenessOptions(30, 30, 7, 14, 30), // increase/decrease threshold = fraction * slotDurationInSeconds * schedulerRate - iotago.WithCongestionControlOptions(500, 500, 500, 800000, 500000, 100000, 1, 1000, 100), + iotago.WithCongestionControlOptions(500, 500, 500, 800000, 500000, 100000, 1000, 100), iotago.WithWorkScoreOptions(25, 1, 100, 50, 10, 10, 50, 1, 10, 250), ), ), @@ -99,7 +99,7 @@ var Docker = []options.Option[snapshotcreator.Options]{ iotago.WithTimeProviderOptions(time.Now().Unix(), 10, 13), iotago.WithLivenessOptions(30, 30, 7, 14, 30), // increase/decrease threshold = fraction * slotDurationInSeconds * schedulerRate - iotago.WithCongestionControlOptions(500, 500, 500, 800000, 500000, 100000, 1, 1000, 100), + iotago.WithCongestionControlOptions(500, 500, 500, 800000, 500000, 100000, 1000, 100), iotago.WithWorkScoreOptions(25, 1, 100, 50, 10, 10, 50, 1, 10, 250), ), ), @@ -153,7 +153,7 @@ var Feature = []options.Option[snapshotcreator.Options]{ iotago.WithTimeProviderOptions(1689848996, 10, 13), iotago.WithLivenessOptions(30, 30, 10, 20, 30), // increase/decrease threshold = fraction * slotDurationInSeconds * schedulerRate - iotago.WithCongestionControlOptions(500, 500, 500, 800000, 500000, 100000, 1, 1000, 100), + iotago.WithCongestionControlOptions(500, 500, 500, 800000, 500000, 100000, 1000, 100), iotago.WithWorkScoreOptions(25, 1, 100, 50, 10, 10, 50, 1, 10, 250), ), ), From ae3db7f057801ef6b1e64384920fa3fd4af33e36 Mon Sep 17 00:00:00 2001 From: Piotr Macek <4007944+piotrm50@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:03:01 +0200 Subject: [PATCH 12/12] Implement read only flag in Mempool (#396) --- go.mod | 2 +- go.sum | 4 +- pkg/protocol/engine/ledger/ledger/ledger.go | 6 +- pkg/protocol/engine/ledger/ledger/vm.go | 2 +- pkg/protocol/engine/ledger/tests/state.go | 4 + .../engine/ledger/tests/state_resolver.go | 6 +- .../ledger/tests/stored_state_reference.go | 38 ---------- pkg/protocol/engine/mempool/state.go | 2 + .../engine/mempool/state_reference.go | 7 +- .../engine/mempool/tests/testframework.go | 34 ++++++++- pkg/protocol/engine/mempool/tests/tests.go | 74 +++++++++++++++++-- .../engine/mempool/tests/transaction.go | 8 -- pkg/protocol/engine/mempool/v1/mempool.go | 18 +++-- .../engine/mempool/v1/mempool_test.go | 6 +- pkg/protocol/engine/mempool/v1/state_diff.go | 20 +++-- pkg/protocol/engine/utxoledger/output.go | 4 + tools/evil-spammer/go.mod | 2 +- tools/evil-spammer/go.sum | 4 +- tools/gendoc/go.mod | 2 +- tools/gendoc/go.sum | 5 +- tools/genesis-snapshot/go.mod | 2 +- tools/genesis-snapshot/go.sum | 4 +- 22 files changed, 158 insertions(+), 96 deletions(-) delete mode 100644 pkg/protocol/engine/ledger/tests/stored_state_reference.go diff --git a/go.mod b/go.mod index 484cbaff6..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-20231003154311-26aa2f0fd388 + 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 2fd9470ee..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-20231003154311-26aa2f0fd388 h1:IGqHrJRmrzfalf1py+FGWzkWoaA5o6avBSYWznVG08s= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388/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/pkg/protocol/engine/ledger/ledger/ledger.go b/pkg/protocol/engine/ledger/ledger/ledger.go index 5889c1548..fd546ae77 100644 --- a/pkg/protocol/engine/ledger/ledger/ledger.go +++ b/pkg/protocol/engine/ledger/ledger/ledger.go @@ -691,7 +691,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() @@ -727,8 +727,8 @@ 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) + //nolint:forcetypeassert + return p.Resolve(stateRef.(mempool.State)) default: return p.Reject(ierrors.Errorf("unsupported input type %s", stateRef.Type())) } 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 diff --git a/pkg/protocol/engine/ledger/tests/state.go b/pkg/protocol/engine/ledger/tests/state.go index 03513f308..c4d4766c0 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) IsReadOnly() 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 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/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..13c723487 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 + + IsReadOnly() bool } 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 02125a3b3..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) @@ -92,7 +100,7 @@ func (t *TestFramework) CreateTransaction(alias string, referencedStates []strin 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 +178,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 } @@ -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 bfd396627..33cb00f0b 100644 --- a/pkg/protocol/engine/mempool/tests/tests.go +++ b/pkg/protocol/engine/mempool/tests/tests.go @@ -35,13 +35,14 @@ 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)) }) } @@ -79,6 +80,65 @@ 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) + + 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 { + 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")) + 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) diff --git a/pkg/protocol/engine/mempool/tests/transaction.go b/pkg/protocol/engine/mempool/tests/transaction.go index 0726b032b..3e0aae669 100644 --- a/pkg/protocol/engine/mempool/tests/transaction.go +++ b/pkg/protocol/engine/mempool/tests/transaction.go @@ -49,14 +49,6 @@ func (t *Transaction) Inputs() ([]mempool.StateReference, error) { return t.inputs, nil } -func (t *Transaction) CommitmentInput() *iotago.CommitmentInput { - return nil -} - -func (t *Transaction) ContextInputs() (iotago.TransactionContextInputs, error) { - return nil, nil -} - func (t *Transaction) String() string { return "Transaction(" + t.id.String() + ")" } diff --git a/pkg/protocol/engine/mempool/v1/mempool.go b/pkg/protocol/engine/mempool/v1/mempool.go index e82a2ea5a..8e3c80a60 100644 --- a/pkg/protocol/engine/mempool/v1/mempool.go +++ b/pkg/protocol/engine/mempool/v1/mempool.go @@ -133,7 +133,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() { @@ -229,7 +229,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) }) @@ -265,14 +265,20 @@ 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 { + 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) { - input.OnDoubleSpent(func() { - m.forkTransaction(transaction, ds.NewSet(input.state.StateID())) - }) + if !input.state.IsReadOnly() { + input.OnDoubleSpent(func() { + m.forkTransaction(transaction, ds.NewSet(input.state.StateID())) + }) + } }) } diff --git a/pkg/protocol/engine/mempool/v1/mempool_test.go b/pkg/protocol/engine/mempool/v1/mempool_test.go index c4f64dee2..c62e5339a 100644 --- a/pkg/protocol/engine/mempool/v1/mempool_test.go +++ b/pkg/protocol/engine/mempool/v1/mempool_test.go @@ -35,7 +35,7 @@ func TestMempoolV1_ResourceCleanup(t *testing.T) { ledgerState := ledgertests.New(ledgertests.NewMockedState(iotago.TransactionID{}, 0)) conflictDAG := conflictdagv1.New[iotago.TransactionID, mempool.StateID, vote.MockedRank](func() int { return 0 }) memPoolInstance := New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] { - return ledgerState.ResolveOutputState(reference.StateID()) + return ledgerState.ResolveOutputState(reference) }, workers, conflictDAG, func(error) {}) tf := mempooltests.NewTestFramework(t, memPoolInstance, conflictDAG, ledgerState, workers) @@ -104,7 +104,7 @@ func newTestFramework(t *testing.T) *mempooltests.TestFramework { conflictDAG := conflictdagv1.New[iotago.TransactionID, mempool.StateID, vote.MockedRank](account.NewAccounts().SelectCommittee().SeatCount) return mempooltests.NewTestFramework(t, New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] { - return ledgerState.ResolveOutputState(reference.StateID()) + return ledgerState.ResolveOutputState(reference) }, workers, conflictDAG, func(error) {}), conflictDAG, ledgerState, workers) } @@ -115,6 +115,6 @@ func newForkingTestFramework(t *testing.T) *mempooltests.TestFramework { conflictDAG := conflictdagv1.New[iotago.TransactionID, mempool.StateID, vote.MockedRank](account.NewAccounts().SelectCommittee().SeatCount) return mempooltests.NewTestFramework(t, New[vote.MockedRank](new(mempooltests.VM), func(reference mempool.StateReference) *promise.Promise[mempool.State] { - return ledgerState.ResolveOutputState(reference.StateID()) + return ledgerState.ResolveOutputState(reference) }, workers, conflictDAG, func(error) {}, WithForkAllTransactions[vote.MockedRank](true)), conflictDAG, ledgerState, workers) } 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()) } } diff --git a/pkg/protocol/engine/utxoledger/output.go b/pkg/protocol/engine/utxoledger/output.go index 86b557651..285daf29c 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) IsReadOnly() bool { + return false +} + func (o *Output) OutputID() iotago.OutputID { return o.outputID } diff --git a/tools/evil-spammer/go.mod b/tools/evil-spammer/go.mod index 1fe7c131b..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-20231003154311-26aa2f0fd388 + 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 2da3ca0c4..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-20231003154311-26aa2f0fd388 h1:IGqHrJRmrzfalf1py+FGWzkWoaA5o6avBSYWznVG08s= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388/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 97a51cd75..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-20231003154311-26aa2f0fd388 // 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 d35f5a5a3..5e0a9c086 100644 --- a/tools/gendoc/go.sum +++ b/tools/gendoc/go.sum @@ -311,8 +311,9 @@ 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-20231003154311-26aa2f0fd388 h1:IGqHrJRmrzfalf1py+FGWzkWoaA5o6avBSYWznVG08s= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388/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/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 09c576a38..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-20231003154311-26aa2f0fd388 + 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 105293b91..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-20231003154311-26aa2f0fd388 h1:IGqHrJRmrzfalf1py+FGWzkWoaA5o6avBSYWznVG08s= -github.com/iotaledger/iota.go/v4 v4.0.0-20231003154311-26aa2f0fd388/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=