Skip to content

Commit

Permalink
Merge pull request #385 from iotaledger/chore/storage-score
Browse files Browse the repository at this point in the history
Update to align with storagescore changes
  • Loading branch information
cyberphysic4l authored Sep 29, 2023
2 parents 470e0ba + d26a111 commit 9c6afcc
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
25 changes: 15 additions & 10 deletions pkg/protocol/engine/accounts/mana/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion pkg/protocol/engine/ledger/tests/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/testsuite/transactions_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/evil-spammer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions tools/evil-spammer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/gendoc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion tools/genesis-snapshot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/genesis-snapshot/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 9c6afcc

Please sign in to comment.