Skip to content

Commit

Permalink
core: adjust storage update fees
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov committed Nov 3, 2020
1 parent 7121686 commit d7502de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions pkg/core/interop_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,12 @@ func putWithContextAndFlags(ic *interop.Context, stc *StorageContext, key []byte
if si == nil {
si = &state.StorageItem{}
sizeInc = len(key) + len(value)
} else if len(value) > len(si.Value) {
sizeInc = len(value) - len(si.Value)
} else if len(value) != 0 {
if len(value) <= len(si.Value) {
sizeInc = (len(value)-1)/4 + 1
} else {
sizeInc = (len(si.Value)-1)/4 + 1 + len(value) - len(si.Value)
}
}
if !ic.VM.AddGas(int64(sizeInc) * StoragePrice) {
return errGasLimitExceeded
Expand Down
4 changes: 3 additions & 1 deletion pkg/core/interop_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ func TestStoragePut(t *testing.T) {
err := storagePut(ic)
require.True(t, errors.Is(err, errGasLimitExceeded), "got: %v", err)
})
initVM(t, []byte{4}, []byte{5, 6, 7, 8}, 2*StoragePrice)
initVM(t, []byte{4}, []byte{5, 6, 7, 8}, 3*StoragePrice)
require.NoError(t, storagePut(ic))
initVM(t, []byte{4}, []byte{5, 6}, StoragePrice)
require.NoError(t, storagePut(ic))
})
}
Expand Down

0 comments on commit d7502de

Please sign in to comment.