diff --git a/go.mod b/go.mod index 2083b8e6c..2c22b2149 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/iotaledger/hive.go/stringify v0.0.0-20230928074706-d58e32f86729 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-20230929074901-a2fa34aa5a35 + github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c 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 173041a08..49a8b5b59 100644 --- a/go.sum +++ b/go.sum @@ -305,8 +305,8 @@ github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182 h1:lQikt github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182/go.mod h1:q24QEsS887ZWJVX76w2kwSgC84KS7wIKOy1otuqZ2ZM= github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd h1:nFG3Zq/zFA4KhBYFX2IezX1C74zfE0DqCt0LrgTa9Ig= github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= -github.com/iotaledger/iota.go/v4 v4.0.0-20230929074901-a2fa34aa5a35 h1:DyXUG4CZkJAgMUCMFUzG1DWNUVmstg6MCt6IZnHD/gY= -github.com/iotaledger/iota.go/v4 v4.0.0-20230929074901-a2fa34aa5a35/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= +github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c h1:faTwv2r4EZ6FixcFtaSD5M02YRm+/kmQKsLBsYSJl3I= +github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= 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/accounts/mana/manager.go b/pkg/protocol/engine/accounts/mana/manager.go index 6861c5a48..7ea1a90e8 100644 --- a/pkg/protocol/engine/accounts/mana/manager.go +++ b/pkg/protocol/engine/accounts/mana/manager.go @@ -3,8 +3,10 @@ package mana import ( "github.com/zyedidia/generic/cache" + "github.com/iotaledger/hive.go/core/safemath" "github.com/iotaledger/hive.go/ds" "github.com/iotaledger/hive.go/ierrors" + "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/protocol/engine/accounts" @@ -45,12 +47,15 @@ func (m *Manager) GetManaOnAccount(accountID iotago.AccountID, currentSlot iotag if err != nil { return 0, ierrors.Errorf("failed to resolve AccountOutput for %s in slot %s: %w", accountID, currentSlot, err) } - minDeposit := m.apiProvider.CurrentAPI().RentStructure().MinDeposit(output.Output()) - if output.BaseTokenAmount() <= minDeposit { - mana = accounts.NewMana(output.StoredMana(), 0, output.SlotCreated()) - } else { - mana = accounts.NewMana(output.StoredMana(), output.BaseTokenAmount()-minDeposit, output.SlotCreated()) + minDeposit, err := m.apiProvider.CurrentAPI().RentStructure().MinDeposit(output.Output()) + if err != nil { + return 0, ierrors.Errorf("failed to get min deposit for %s: %w", accountID, err) + } + excessBaseTokens, err := safemath.SafeSub(output.BaseTokenAmount(), minDeposit) + if err != nil { + excessBaseTokens = 0 } + mana = accounts.NewMana(output.StoredMana(), excessBaseTokens, output.SlotCreated()) if !exists { m.manaVectorCache.Put(accountID, mana) @@ -92,12 +97,12 @@ func (m *Manager) ApplyDiff(slot iotago.SlotIndex, destroyedAccounts ds.Set[iota for accountID, output := range accountOutputs { mana, exists := m.manaVectorCache.Get(accountID) if exists { - minDeposit := m.apiProvider.CurrentAPI().RentStructure().MinDeposit(output.Output()) - if output.BaseTokenAmount() <= minDeposit { - mana.Update(output.StoredMana(), 0, slot) - } else { - mana.Update(output.StoredMana(), output.BaseTokenAmount()-minDeposit, slot) + minDeposit := lo.PanicOnErr(m.apiProvider.CurrentAPI().RentStructure().MinDeposit(output.Output())) + excessBaseTokens, err := safemath.SafeSub(output.BaseTokenAmount(), minDeposit) + if err != nil { + excessBaseTokens = 0 } + mana.Update(output.StoredMana(), excessBaseTokens, slot) } } } diff --git a/pkg/protocol/engine/ledger/tests/output.go b/pkg/protocol/engine/ledger/tests/output.go index 3ba6c946b..19ecabac0 100644 --- a/pkg/protocol/engine/ledger/tests/output.go +++ b/pkg/protocol/engine/ledger/tests/output.go @@ -16,7 +16,7 @@ func (m *MockedOutput) WorkScore(_ *iotago.WorkScoreStructure) (iotago.WorkScore panic("implement me") } -func (m *MockedOutput) VBytes(_ *iotago.RentStructure, _ iotago.VBytesFunc) iotago.VBytes { +func (m *MockedOutput) StorageScore(_ *iotago.RentStructure, _ iotago.StorageScoreFunc) iotago.StorageScore { panic("implement me") } diff --git a/pkg/testsuite/transactions_framework.go b/pkg/testsuite/transactions_framework.go index 967ac1065..e2bc2dcfe 100644 --- a/pkg/testsuite/transactions_framework.go +++ b/pkg/testsuite/transactions_framework.go @@ -555,7 +555,7 @@ func WithAccountInput(input *utxoledger.Output, governorTransition bool) options func WithAllotments(allotments iotago.Allotments) options.Option[builder.TransactionBuilder] { return func(txBuilder *builder.TransactionBuilder) { for _, allotment := range allotments { - txBuilder.AddAllotment(allotment) + txBuilder.IncreaseAllotment(allotment.AccountID, allotment.Value) } } } diff --git a/tools/evil-spammer/go.mod b/tools/evil-spammer/go.mod index 2f14a2b02..1bf9c21c4 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-20230928074706-d58e32f86729 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-20230929074901-a2fa34aa5a35 + github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c 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 033886f91..6b2afa47f 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.20230928074706-d58e32f github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230928074706-d58e32f86729/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230928074706-d58e32f86729 h1:gZlIK1OzdA3aZ78PsiWe3poVzawyw4S3zboMHE1TrY0= github.com/iotaledger/hive.go/stringify v0.0.0-20230928074706-d58e32f86729/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/iota.go/v4 v4.0.0-20230929074901-a2fa34aa5a35 h1:DyXUG4CZkJAgMUCMFUzG1DWNUVmstg6MCt6IZnHD/gY= -github.com/iotaledger/iota.go/v4 v4.0.0-20230929074901-a2fa34aa5a35/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= +github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c h1:faTwv2r4EZ6FixcFtaSD5M02YRm+/kmQKsLBsYSJl3I= +github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= 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 4ec83b193..159e19742 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-20230928074706-d58e32f86729 // 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-20230929074901-a2fa34aa5a35 // indirect + github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c // 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 397b885d4..8a69e6b1b 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.20230927140518-622f63be6182 h1:lQikt github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230927140518-622f63be6182/go.mod h1:q24QEsS887ZWJVX76w2kwSgC84KS7wIKOy1otuqZ2ZM= github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd h1:nFG3Zq/zFA4KhBYFX2IezX1C74zfE0DqCt0LrgTa9Ig= github.com/iotaledger/inx/go v1.0.0-rc.2.0.20230927140257-bfa0bb0af2bd/go.mod h1:c5778OnWpLq108YE+Eb2m8Ri/t/4ydV0TvI/Sy5YivQ= -github.com/iotaledger/iota.go/v4 v4.0.0-20230929074901-a2fa34aa5a35 h1:DyXUG4CZkJAgMUCMFUzG1DWNUVmstg6MCt6IZnHD/gY= -github.com/iotaledger/iota.go/v4 v4.0.0-20230929074901-a2fa34aa5a35/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= +github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c h1:faTwv2r4EZ6FixcFtaSD5M02YRm+/kmQKsLBsYSJl3I= +github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= 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 511b81306..43f5de5bf 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-20230928074706-d58e32f86729 github.com/iotaledger/hive.go/runtime v0.0.0-20230928074706-d58e32f86729 github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000 - github.com/iotaledger/iota.go/v4 v4.0.0-20230929074901-a2fa34aa5a35 + github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c 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 2454061e8..ef08c5fab 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.20230928074706-d58e32f github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230928074706-d58e32f86729/go.mod h1:IJgaaxbgKCsNat18jlJJEAxCY2oVYR3F30B+M4vJ89I= github.com/iotaledger/hive.go/stringify v0.0.0-20230928074706-d58e32f86729 h1:gZlIK1OzdA3aZ78PsiWe3poVzawyw4S3zboMHE1TrY0= github.com/iotaledger/hive.go/stringify v0.0.0-20230928074706-d58e32f86729/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs= -github.com/iotaledger/iota.go/v4 v4.0.0-20230929074901-a2fa34aa5a35 h1:DyXUG4CZkJAgMUCMFUzG1DWNUVmstg6MCt6IZnHD/gY= -github.com/iotaledger/iota.go/v4 v4.0.0-20230929074901-a2fa34aa5a35/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= +github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c h1:faTwv2r4EZ6FixcFtaSD5M02YRm+/kmQKsLBsYSJl3I= +github.com/iotaledger/iota.go/v4 v4.0.0-20230929090257-1620d009ba8c/go.mod h1:wR9xBbsofns9hFyRHFZ2bDYIb861qsfmQPVMBKcPvDo= 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=