Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
update to align with storagescore changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberphysic4l committed Sep 29, 2023
1 parent 470e0ba commit 652a2c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
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

0 comments on commit 652a2c5

Please sign in to comment.