native: rename Price to CPUFee

Method price is now multiplied by `BaseExecFee`.
This commit is contained in:
Evgeniy Stratonikov 2021-03-05 13:30:16 +03:00
parent 5dff7afd5a
commit 3278d23852
16 changed files with 76 additions and 76 deletions

View file

@ -1029,7 +1029,7 @@ func TestVerifyTx(t *testing.T) {
fee.Opcode(bc.GetBaseExecFee(), // Notary verification script fee.Opcode(bc.GetBaseExecFee(), // Notary verification script
opcode.PUSHDATA1, opcode.RET, // invocation script opcode.PUSHDATA1, opcode.RET, // invocation script
opcode.PUSH0, opcode.SYSCALL, opcode.RET) + // Neo.Native.Call opcode.PUSH0, opcode.SYSCALL, opcode.RET) + // Neo.Native.Call
native.NotaryVerificationPrice // Notary witness verification price native.NotaryVerificationPrice*bc.GetBaseExecFee() // Notary witness verification price
tx.Scripts = []transaction.Witness{ tx.Scripts = []transaction.Witness{
{ {
InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64, 64)...), InvocationScript: append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64, 64)...),

View file

@ -90,7 +90,7 @@ type Method = func(ic *Context, args []stackitem.Item) stackitem.Item
type MethodAndPrice struct { type MethodAndPrice struct {
Func Method Func Method
MD *manifest.Method MD *manifest.Method
Price int64 CPUFee int64
SyscallOffset int SyscallOffset int
RequiredFlags callflag.CallFlag RequiredFlags callflag.CallFlag
} }

View file

@ -92,13 +92,13 @@ func newDesignate(p2pSigExtensionsEnabled bool) *Designate {
desc := newDescriptor("getDesignatedByRole", smartcontract.ArrayType, desc := newDescriptor("getDesignatedByRole", smartcontract.ArrayType,
manifest.NewParameter("role", smartcontract.IntegerType), manifest.NewParameter("role", smartcontract.IntegerType),
manifest.NewParameter("index", smartcontract.IntegerType)) manifest.NewParameter("index", smartcontract.IntegerType))
md := newMethodAndPrice(s.getDesignatedByRole, 1000000, callflag.ReadStates) md := newMethodAndPrice(s.getDesignatedByRole, 1<<15, callflag.ReadStates)
s.AddMethod(md, desc) s.AddMethod(md, desc)
desc = newDescriptor("designateAsRole", smartcontract.VoidType, desc = newDescriptor("designateAsRole", smartcontract.VoidType,
manifest.NewParameter("role", smartcontract.IntegerType), manifest.NewParameter("role", smartcontract.IntegerType),
manifest.NewParameter("nodes", smartcontract.ArrayType)) manifest.NewParameter("nodes", smartcontract.ArrayType))
md = newMethodAndPrice(s.designateAsRole, 0, callflag.States) md = newMethodAndPrice(s.designateAsRole, 1<<15, callflag.States)
s.AddMethod(md, desc) s.AddMethod(md, desc)
return s return s

View file

@ -34,8 +34,7 @@ func Call(ic *interop.Context) error {
return fmt.Errorf("missing call flags for native %d `%s` operation call: %05b vs %05b", return fmt.Errorf("missing call flags for native %d `%s` operation call: %05b vs %05b",
version, m.MD.Name, ic.VM.Context().GetCallFlags(), m.RequiredFlags) version, m.MD.Name, ic.VM.Context().GetCallFlags(), m.RequiredFlags)
} }
// Native contract prices are not multiplied by `BaseExecFee`. if !ic.VM.AddGas(m.CPUFee * ic.Chain.GetPolicer().GetBaseExecFee()) {
if !ic.VM.AddGas(m.Price) {
return errors.New("gas limit exceeded") return errors.New("gas limit exceeded")
} }
ctx := ic.VM.Context() ctx := ic.VM.Context()

View file

@ -42,32 +42,32 @@ func newLedger() *Ledger {
defer l.UpdateHash() defer l.UpdateHash()
desc := newDescriptor("currentHash", smartcontract.Hash256Type) desc := newDescriptor("currentHash", smartcontract.Hash256Type)
md := newMethodAndPrice(l.currentHash, 1000000, callflag.ReadStates) md := newMethodAndPrice(l.currentHash, 1<<15, callflag.ReadStates)
l.AddMethod(md, desc) l.AddMethod(md, desc)
desc = newDescriptor("currentIndex", smartcontract.IntegerType) desc = newDescriptor("currentIndex", smartcontract.IntegerType)
md = newMethodAndPrice(l.currentIndex, 1000000, callflag.ReadStates) md = newMethodAndPrice(l.currentIndex, 1<<15, callflag.ReadStates)
l.AddMethod(md, desc) l.AddMethod(md, desc)
desc = newDescriptor("getBlock", smartcontract.ArrayType, desc = newDescriptor("getBlock", smartcontract.ArrayType,
manifest.NewParameter("indexOrHash", smartcontract.ByteArrayType)) manifest.NewParameter("indexOrHash", smartcontract.ByteArrayType))
md = newMethodAndPrice(l.getBlock, 1000000, callflag.ReadStates) md = newMethodAndPrice(l.getBlock, 1<<15, callflag.ReadStates)
l.AddMethod(md, desc) l.AddMethod(md, desc)
desc = newDescriptor("getTransaction", smartcontract.ArrayType, desc = newDescriptor("getTransaction", smartcontract.ArrayType,
manifest.NewParameter("hash", smartcontract.Hash256Type)) manifest.NewParameter("hash", smartcontract.Hash256Type))
md = newMethodAndPrice(l.getTransaction, 1000000, callflag.ReadStates) md = newMethodAndPrice(l.getTransaction, 1<<15, callflag.ReadStates)
l.AddMethod(md, desc) l.AddMethod(md, desc)
desc = newDescriptor("getTransactionHeight", smartcontract.IntegerType, desc = newDescriptor("getTransactionHeight", smartcontract.IntegerType,
manifest.NewParameter("hash", smartcontract.Hash256Type)) manifest.NewParameter("hash", smartcontract.Hash256Type))
md = newMethodAndPrice(l.getTransactionHeight, 1000000, callflag.ReadStates) md = newMethodAndPrice(l.getTransactionHeight, 1<<15, callflag.ReadStates)
l.AddMethod(md, desc) l.AddMethod(md, desc)
desc = newDescriptor("getTransactionFromBlock", smartcontract.ArrayType, desc = newDescriptor("getTransactionFromBlock", smartcontract.ArrayType,
manifest.NewParameter("blockIndexOrHash", smartcontract.ByteArrayType), manifest.NewParameter("blockIndexOrHash", smartcontract.ByteArrayType),
manifest.NewParameter("txIndex", smartcontract.IntegerType)) manifest.NewParameter("txIndex", smartcontract.IntegerType))
md = newMethodAndPrice(l.getTransactionFromBlock, 2000000, callflag.ReadStates) md = newMethodAndPrice(l.getTransactionFromBlock, 1<<16, callflag.ReadStates)
l.AddMethod(md, desc) l.AddMethod(md, desc)
return l return l

View file

@ -69,7 +69,7 @@ func newManagement() *Management {
desc := newDescriptor("getContract", smartcontract.ArrayType, desc := newDescriptor("getContract", smartcontract.ArrayType,
manifest.NewParameter("hash", smartcontract.Hash160Type)) manifest.NewParameter("hash", smartcontract.Hash160Type))
md := newMethodAndPrice(m.getContract, 1000000, callflag.ReadStates) md := newMethodAndPrice(m.getContract, 1<<15, callflag.ReadStates)
m.AddMethod(md, desc) m.AddMethod(md, desc)
desc = newDescriptor("deploy", smartcontract.ArrayType, desc = newDescriptor("deploy", smartcontract.ArrayType,
@ -99,16 +99,16 @@ func newManagement() *Management {
m.AddMethod(md, desc) m.AddMethod(md, desc)
desc = newDescriptor("destroy", smartcontract.VoidType) desc = newDescriptor("destroy", smartcontract.VoidType)
md = newMethodAndPrice(m.destroy, 1000000, callflag.States|callflag.AllowNotify) md = newMethodAndPrice(m.destroy, 1<<15, callflag.States|callflag.AllowNotify)
m.AddMethod(md, desc) m.AddMethod(md, desc)
desc = newDescriptor("getMinimumDeploymentFee", smartcontract.IntegerType) desc = newDescriptor("getMinimumDeploymentFee", smartcontract.IntegerType)
md = newMethodAndPrice(m.getMinimumDeploymentFee, 100_0000, callflag.ReadStates) md = newMethodAndPrice(m.getMinimumDeploymentFee, 1<<15, callflag.ReadStates)
m.AddMethod(md, desc) m.AddMethod(md, desc)
desc = newDescriptor("setMinimumDeploymentFee", smartcontract.VoidType, desc = newDescriptor("setMinimumDeploymentFee", smartcontract.VoidType,
manifest.NewParameter("value", smartcontract.IntegerType)) manifest.NewParameter("value", smartcontract.IntegerType))
md = newMethodAndPrice(m.setMinimumDeploymentFee, 300_0000, callflag.States) md = newMethodAndPrice(m.setMinimumDeploymentFee, 1<<15, callflag.States)
m.AddMethod(md, desc) m.AddMethod(md, desc)
hashParam := manifest.NewParameter("Hash", smartcontract.Hash160Type) hashParam := manifest.NewParameter("Hash", smartcontract.Hash160Type)

View file

@ -104,27 +104,27 @@ func newNameService() *NameService {
desc := newDescriptor("addRoot", smartcontract.VoidType, desc := newDescriptor("addRoot", smartcontract.VoidType,
manifest.NewParameter("root", smartcontract.StringType)) manifest.NewParameter("root", smartcontract.StringType))
md := newMethodAndPrice(n.addRoot, 3000000, callflag.States) md := newMethodAndPrice(n.addRoot, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("setPrice", smartcontract.VoidType, desc = newDescriptor("setPrice", smartcontract.VoidType,
manifest.NewParameter("price", smartcontract.IntegerType)) manifest.NewParameter("price", smartcontract.IntegerType))
md = newMethodAndPrice(n.setPrice, 3000000, callflag.States) md = newMethodAndPrice(n.setPrice, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("getPrice", smartcontract.IntegerType) desc = newDescriptor("getPrice", smartcontract.IntegerType)
md = newMethodAndPrice(n.getPrice, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.getPrice, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("isAvailable", smartcontract.BoolType, desc = newDescriptor("isAvailable", smartcontract.BoolType,
manifest.NewParameter("name", smartcontract.StringType)) manifest.NewParameter("name", smartcontract.StringType))
md = newMethodAndPrice(n.isAvailable, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.isAvailable, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("register", smartcontract.BoolType, desc = newDescriptor("register", smartcontract.BoolType,
manifest.NewParameter("name", smartcontract.StringType), manifest.NewParameter("name", smartcontract.StringType),
manifest.NewParameter("owner", smartcontract.Hash160Type)) manifest.NewParameter("owner", smartcontract.Hash160Type))
md = newMethodAndPrice(n.register, 1000000, callflag.States) md = newMethodAndPrice(n.register, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("renew", smartcontract.IntegerType, desc = newDescriptor("renew", smartcontract.IntegerType,
@ -135,32 +135,32 @@ func newNameService() *NameService {
desc = newDescriptor("setAdmin", smartcontract.VoidType, desc = newDescriptor("setAdmin", smartcontract.VoidType,
manifest.NewParameter("name", smartcontract.StringType), manifest.NewParameter("name", smartcontract.StringType),
manifest.NewParameter("admin", smartcontract.Hash160Type)) manifest.NewParameter("admin", smartcontract.Hash160Type))
md = newMethodAndPrice(n.setAdmin, 3000000, callflag.States) md = newMethodAndPrice(n.setAdmin, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("setRecord", smartcontract.VoidType, desc = newDescriptor("setRecord", smartcontract.VoidType,
manifest.NewParameter("name", smartcontract.StringType), manifest.NewParameter("name", smartcontract.StringType),
manifest.NewParameter("type", smartcontract.IntegerType), manifest.NewParameter("type", smartcontract.IntegerType),
manifest.NewParameter("data", smartcontract.StringType)) manifest.NewParameter("data", smartcontract.StringType))
md = newMethodAndPrice(n.setRecord, 30000000, callflag.States) md = newMethodAndPrice(n.setRecord, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("getRecord", smartcontract.StringType, desc = newDescriptor("getRecord", smartcontract.StringType,
manifest.NewParameter("name", smartcontract.StringType), manifest.NewParameter("name", smartcontract.StringType),
manifest.NewParameter("type", smartcontract.IntegerType)) manifest.NewParameter("type", smartcontract.IntegerType))
md = newMethodAndPrice(n.getRecord, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.getRecord, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("deleteRecord", smartcontract.VoidType, desc = newDescriptor("deleteRecord", smartcontract.VoidType,
manifest.NewParameter("name", smartcontract.StringType), manifest.NewParameter("name", smartcontract.StringType),
manifest.NewParameter("type", smartcontract.IntegerType)) manifest.NewParameter("type", smartcontract.IntegerType))
md = newMethodAndPrice(n.deleteRecord, 1000000, callflag.States) md = newMethodAndPrice(n.deleteRecord, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("resolve", smartcontract.StringType, desc = newDescriptor("resolve", smartcontract.StringType,
manifest.NewParameter("name", smartcontract.StringType), manifest.NewParameter("name", smartcontract.StringType),
manifest.NewParameter("type", smartcontract.IntegerType)) manifest.NewParameter("type", smartcontract.IntegerType))
md = newMethodAndPrice(n.resolve, 3000000, callflag.ReadStates) md = newMethodAndPrice(n.resolve, 1<<17, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
return n return n

View file

@ -111,44 +111,44 @@ func newNEO() *NEO {
desc := newDescriptor("unclaimedGas", smartcontract.IntegerType, desc := newDescriptor("unclaimedGas", smartcontract.IntegerType,
manifest.NewParameter("account", smartcontract.Hash160Type), manifest.NewParameter("account", smartcontract.Hash160Type),
manifest.NewParameter("end", smartcontract.IntegerType)) manifest.NewParameter("end", smartcontract.IntegerType))
md := newMethodAndPrice(n.unclaimedGas, 3000000, callflag.ReadStates) md := newMethodAndPrice(n.unclaimedGas, 1<<17, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("registerCandidate", smartcontract.BoolType, desc = newDescriptor("registerCandidate", smartcontract.BoolType,
manifest.NewParameter("pubkey", smartcontract.ByteArrayType)) manifest.NewParameter("pubkey", smartcontract.ByteArrayType))
md = newMethodAndPrice(n.registerCandidate, 1000_00000000, callflag.States) md = newMethodAndPrice(n.registerCandidate, 0, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("unregisterCandidate", smartcontract.BoolType, desc = newDescriptor("unregisterCandidate", smartcontract.BoolType,
manifest.NewParameter("pubkey", smartcontract.ByteArrayType)) manifest.NewParameter("pubkey", smartcontract.ByteArrayType))
md = newMethodAndPrice(n.unregisterCandidate, 5000000, callflag.States) md = newMethodAndPrice(n.unregisterCandidate, 1<<16, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("vote", smartcontract.BoolType, desc = newDescriptor("vote", smartcontract.BoolType,
manifest.NewParameter("account", smartcontract.Hash160Type), manifest.NewParameter("account", smartcontract.Hash160Type),
manifest.NewParameter("voteTo", smartcontract.ByteArrayType)) manifest.NewParameter("voteTo", smartcontract.ByteArrayType))
md = newMethodAndPrice(n.vote, 5000000, callflag.States) md = newMethodAndPrice(n.vote, 1<<16, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("getCandidates", smartcontract.ArrayType) desc = newDescriptor("getCandidates", smartcontract.ArrayType)
md = newMethodAndPrice(n.getCandidatesCall, 100000000, callflag.ReadStates) md = newMethodAndPrice(n.getCandidatesCall, 1<<22, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("getCommittee", smartcontract.ArrayType) desc = newDescriptor("getCommittee", smartcontract.ArrayType)
md = newMethodAndPrice(n.getCommittee, 100000000, callflag.ReadStates) md = newMethodAndPrice(n.getCommittee, 1<<22, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("getNextBlockValidators", smartcontract.ArrayType) desc = newDescriptor("getNextBlockValidators", smartcontract.ArrayType)
md = newMethodAndPrice(n.getNextBlockValidators, 100000000, callflag.ReadStates) md = newMethodAndPrice(n.getNextBlockValidators, 1<<22, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("getGasPerBlock", smartcontract.IntegerType) desc = newDescriptor("getGasPerBlock", smartcontract.IntegerType)
md = newMethodAndPrice(n.getGASPerBlock, 100_0000, callflag.ReadStates) md = newMethodAndPrice(n.getGASPerBlock, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("setGasPerBlock", smartcontract.VoidType, desc = newDescriptor("setGasPerBlock", smartcontract.VoidType,
manifest.NewParameter("gasPerBlock", smartcontract.IntegerType)) manifest.NewParameter("gasPerBlock", smartcontract.IntegerType))
md = newMethodAndPrice(n.setGASPerBlock, 500_0000, callflag.States) md = newMethodAndPrice(n.setGASPerBlock, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
return n return n

View file

@ -55,12 +55,12 @@ func newNEP17Native(name string, id int32) *nep17TokenNative {
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("totalSupply", smartcontract.IntegerType) desc = newDescriptor("totalSupply", smartcontract.IntegerType)
md = newMethodAndPrice(n.TotalSupply, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.TotalSupply, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("balanceOf", smartcontract.IntegerType, desc = newDescriptor("balanceOf", smartcontract.IntegerType,
manifest.NewParameter("account", smartcontract.Hash160Type)) manifest.NewParameter("account", smartcontract.Hash160Type))
md = newMethodAndPrice(n.balanceOf, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.balanceOf, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
transferParams := []manifest.Parameter{ transferParams := []manifest.Parameter{
@ -71,7 +71,7 @@ func newNEP17Native(name string, id int32) *nep17TokenNative {
desc = newDescriptor("transfer", smartcontract.BoolType, desc = newDescriptor("transfer", smartcontract.BoolType,
append(transferParams, manifest.NewParameter("data", smartcontract.AnyType))..., append(transferParams, manifest.NewParameter("data", smartcontract.AnyType))...,
) )
md = newMethodAndPrice(n.Transfer, 9000000, callflag.States|callflag.AllowCall|callflag.AllowNotify) md = newMethodAndPrice(n.Transfer, 1<<17, callflag.States|callflag.AllowCall|callflag.AllowNotify)
n.AddMethod(md, desc) n.AddMethod(md, desc)
n.AddEvent("Transfer", transferParams...) n.AddEvent("Transfer", transferParams...)
@ -283,10 +283,10 @@ func newDescriptor(name string, ret smartcontract.ParamType, ps ...manifest.Para
} }
} }
func newMethodAndPrice(f interop.Method, price int64, flags callflag.CallFlag) *interop.MethodAndPrice { func newMethodAndPrice(f interop.Method, cpuFee int64, flags callflag.CallFlag) *interop.MethodAndPrice {
return &interop.MethodAndPrice{ return &interop.MethodAndPrice{
Func: f, Func: f,
Price: price, CPUFee: cpuFee,
RequiredFlags: flags, RequiredFlags: flags,
} }
} }

View file

@ -77,37 +77,37 @@ func newNonFungible(name string, id int32, symbol string, decimals byte) *nonfun
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("totalSupply", smartcontract.IntegerType) desc = newDescriptor("totalSupply", smartcontract.IntegerType)
md = newMethodAndPrice(n.totalSupply, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.totalSupply, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("ownerOf", smartcontract.Hash160Type, desc = newDescriptor("ownerOf", smartcontract.Hash160Type,
manifest.NewParameter("tokenId", smartcontract.ByteArrayType)) manifest.NewParameter("tokenId", smartcontract.ByteArrayType))
md = newMethodAndPrice(n.OwnerOf, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.OwnerOf, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("balanceOf", smartcontract.IntegerType, desc = newDescriptor("balanceOf", smartcontract.IntegerType,
manifest.NewParameter("owner", smartcontract.Hash160Type)) manifest.NewParameter("owner", smartcontract.Hash160Type))
md = newMethodAndPrice(n.BalanceOf, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.BalanceOf, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("properties", smartcontract.MapType, desc = newDescriptor("properties", smartcontract.MapType,
manifest.NewParameter("tokenId", smartcontract.ByteArrayType)) manifest.NewParameter("tokenId", smartcontract.ByteArrayType))
md = newMethodAndPrice(n.Properties, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.Properties, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("tokens", smartcontract.AnyType) desc = newDescriptor("tokens", smartcontract.AnyType)
md = newMethodAndPrice(n.tokens, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.tokens, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("tokensOf", smartcontract.AnyType, desc = newDescriptor("tokensOf", smartcontract.AnyType,
manifest.NewParameter("owner", smartcontract.Hash160Type)) manifest.NewParameter("owner", smartcontract.Hash160Type))
md = newMethodAndPrice(n.tokensOf, 1000000, callflag.ReadStates) md = newMethodAndPrice(n.tokensOf, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("transfer", smartcontract.BoolType, desc = newDescriptor("transfer", smartcontract.BoolType,
manifest.NewParameter("to", smartcontract.Hash160Type), manifest.NewParameter("to", smartcontract.Hash160Type),
manifest.NewParameter("tokenId", smartcontract.ByteArrayType)) manifest.NewParameter("tokenId", smartcontract.ByteArrayType))
md = newMethodAndPrice(n.transfer, 9000000, callflag.States|callflag.AllowNotify) md = newMethodAndPrice(n.transfer, 1<<17, callflag.States|callflag.AllowNotify)
n.AddMethod(md, desc) n.AddMethod(md, desc)
n.AddEvent("Transfer", n.AddEvent("Transfer",

View file

@ -41,7 +41,7 @@ type Notary struct {
const ( const (
notaryContractID = reservedContractID - 1 notaryContractID = reservedContractID - 1
// NotaryVerificationPrice is the price of `verify` Notary method. // NotaryVerificationPrice is the price of `verify` Notary method.
NotaryVerificationPrice = 100_0000 NotaryVerificationPrice = 1 << 15
// prefixDeposit is a prefix for storing Notary deposits. // prefixDeposit is a prefix for storing Notary deposits.
prefixDeposit = 1 prefixDeposit = 1
@ -60,29 +60,29 @@ func newNotary() *Notary {
manifest.NewParameter("from", smartcontract.Hash160Type), manifest.NewParameter("from", smartcontract.Hash160Type),
manifest.NewParameter("amount", smartcontract.IntegerType), manifest.NewParameter("amount", smartcontract.IntegerType),
manifest.NewParameter("data", smartcontract.AnyType)) manifest.NewParameter("data", smartcontract.AnyType))
md := newMethodAndPrice(n.onPayment, 100_0000, callflag.States) md := newMethodAndPrice(n.onPayment, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("lockDepositUntil", smartcontract.BoolType, desc = newDescriptor("lockDepositUntil", smartcontract.BoolType,
manifest.NewParameter("address", smartcontract.Hash160Type), manifest.NewParameter("address", smartcontract.Hash160Type),
manifest.NewParameter("till", smartcontract.IntegerType)) manifest.NewParameter("till", smartcontract.IntegerType))
md = newMethodAndPrice(n.lockDepositUntil, 100_0000, callflag.States) md = newMethodAndPrice(n.lockDepositUntil, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("withdraw", smartcontract.BoolType, desc = newDescriptor("withdraw", smartcontract.BoolType,
manifest.NewParameter("from", smartcontract.Hash160Type), manifest.NewParameter("from", smartcontract.Hash160Type),
manifest.NewParameter("to", smartcontract.Hash160Type)) manifest.NewParameter("to", smartcontract.Hash160Type))
md = newMethodAndPrice(n.withdraw, 100_0000, callflag.States) md = newMethodAndPrice(n.withdraw, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("balanceOf", smartcontract.IntegerType, desc = newDescriptor("balanceOf", smartcontract.IntegerType,
manifest.NewParameter("addr", smartcontract.Hash160Type)) manifest.NewParameter("addr", smartcontract.Hash160Type))
md = newMethodAndPrice(n.balanceOf, 100_0000, callflag.ReadStates) md = newMethodAndPrice(n.balanceOf, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("expirationOf", smartcontract.IntegerType, desc = newDescriptor("expirationOf", smartcontract.IntegerType,
manifest.NewParameter("addr", smartcontract.Hash160Type)) manifest.NewParameter("addr", smartcontract.Hash160Type))
md = newMethodAndPrice(n.expirationOf, 100_0000, callflag.ReadStates) md = newMethodAndPrice(n.expirationOf, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("verify", smartcontract.BoolType, desc = newDescriptor("verify", smartcontract.BoolType,
@ -91,12 +91,12 @@ func newNotary() *Notary {
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("getMaxNotValidBeforeDelta", smartcontract.IntegerType) desc = newDescriptor("getMaxNotValidBeforeDelta", smartcontract.IntegerType)
md = newMethodAndPrice(n.getMaxNotValidBeforeDelta, 100_0000, callflag.ReadStates) md = newMethodAndPrice(n.getMaxNotValidBeforeDelta, 1<<15, callflag.ReadStates)
n.AddMethod(md, desc) n.AddMethod(md, desc)
desc = newDescriptor("setMaxNotValidBeforeDelta", smartcontract.VoidType, desc = newDescriptor("setMaxNotValidBeforeDelta", smartcontract.VoidType,
manifest.NewParameter("value", smartcontract.IntegerType)) manifest.NewParameter("value", smartcontract.IntegerType))
md = newMethodAndPrice(n.setMaxNotValidBeforeDelta, 300_0000, callflag.States) md = newMethodAndPrice(n.setMaxNotValidBeforeDelta, 1<<15, callflag.States)
n.AddMethod(md, desc) n.AddMethod(md, desc)
return n return n

View file

@ -91,7 +91,7 @@ func newOracle() *Oracle {
manifest.NewParameter("callback", smartcontract.StringType), manifest.NewParameter("callback", smartcontract.StringType),
manifest.NewParameter("userData", smartcontract.AnyType), manifest.NewParameter("userData", smartcontract.AnyType),
manifest.NewParameter("gasForResponse", smartcontract.IntegerType)) manifest.NewParameter("gasForResponse", smartcontract.IntegerType))
md := newMethodAndPrice(o.request, oracleRequestPrice, callflag.States|callflag.AllowNotify) md := newMethodAndPrice(o.request, 0, callflag.States|callflag.AllowNotify)
o.AddMethod(md, desc) o.AddMethod(md, desc)
desc = newDescriptor("finish", smartcontract.VoidType) desc = newDescriptor("finish", smartcontract.VoidType)
@ -99,7 +99,7 @@ func newOracle() *Oracle {
o.AddMethod(md, desc) o.AddMethod(md, desc)
desc = newDescriptor("verify", smartcontract.BoolType) desc = newDescriptor("verify", smartcontract.BoolType)
md = newMethodAndPrice(o.verify, 100_0000, callflag.NoneFlag) md = newMethodAndPrice(o.verify, 1<<15, callflag.NoneFlag)
o.AddMethod(md, desc) o.AddMethod(md, desc)
o.AddEvent("OracleRequest", manifest.NewParameter("Id", smartcontract.IntegerType), o.AddEvent("OracleRequest", manifest.NewParameter("Id", smartcontract.IntegerType),

View file

@ -72,45 +72,45 @@ func newPolicy() *Policy {
defer p.UpdateHash() defer p.UpdateHash()
desc := newDescriptor("getFeePerByte", smartcontract.IntegerType) desc := newDescriptor("getFeePerByte", smartcontract.IntegerType)
md := newMethodAndPrice(p.getFeePerByte, 1000000, callflag.ReadStates) md := newMethodAndPrice(p.getFeePerByte, 1<<15, callflag.ReadStates)
p.AddMethod(md, desc) p.AddMethod(md, desc)
desc = newDescriptor("isBlocked", smartcontract.BoolType, desc = newDescriptor("isBlocked", smartcontract.BoolType,
manifest.NewParameter("account", smartcontract.Hash160Type)) manifest.NewParameter("account", smartcontract.Hash160Type))
md = newMethodAndPrice(p.isBlocked, 1000000, callflag.ReadStates) md = newMethodAndPrice(p.isBlocked, 1<<15, callflag.ReadStates)
p.AddMethod(md, desc) p.AddMethod(md, desc)
desc = newDescriptor("getExecFeeFactor", smartcontract.IntegerType) desc = newDescriptor("getExecFeeFactor", smartcontract.IntegerType)
md = newMethodAndPrice(p.getExecFeeFactor, 1000000, callflag.ReadStates) md = newMethodAndPrice(p.getExecFeeFactor, 1<<15, callflag.ReadStates)
p.AddMethod(md, desc) p.AddMethod(md, desc)
desc = newDescriptor("setExecFeeFactor", smartcontract.VoidType, desc = newDescriptor("setExecFeeFactor", smartcontract.VoidType,
manifest.NewParameter("value", smartcontract.IntegerType)) manifest.NewParameter("value", smartcontract.IntegerType))
md = newMethodAndPrice(p.setExecFeeFactor, 3000000, callflag.States) md = newMethodAndPrice(p.setExecFeeFactor, 1<<15, callflag.States)
p.AddMethod(md, desc) p.AddMethod(md, desc)
desc = newDescriptor("getStoragePrice", smartcontract.IntegerType) desc = newDescriptor("getStoragePrice", smartcontract.IntegerType)
md = newMethodAndPrice(p.getStoragePrice, 1000000, callflag.ReadStates) md = newMethodAndPrice(p.getStoragePrice, 1<<15, callflag.ReadStates)
p.AddMethod(md, desc) p.AddMethod(md, desc)
desc = newDescriptor("setStoragePrice", smartcontract.VoidType, desc = newDescriptor("setStoragePrice", smartcontract.VoidType,
manifest.NewParameter("value", smartcontract.IntegerType)) manifest.NewParameter("value", smartcontract.IntegerType))
md = newMethodAndPrice(p.setStoragePrice, 3000000, callflag.States) md = newMethodAndPrice(p.setStoragePrice, 1<<15, callflag.States)
p.AddMethod(md, desc) p.AddMethod(md, desc)
desc = newDescriptor("setFeePerByte", smartcontract.VoidType, desc = newDescriptor("setFeePerByte", smartcontract.VoidType,
manifest.NewParameter("value", smartcontract.IntegerType)) manifest.NewParameter("value", smartcontract.IntegerType))
md = newMethodAndPrice(p.setFeePerByte, 3000000, callflag.States) md = newMethodAndPrice(p.setFeePerByte, 1<<15, callflag.States)
p.AddMethod(md, desc) p.AddMethod(md, desc)
desc = newDescriptor("blockAccount", smartcontract.BoolType, desc = newDescriptor("blockAccount", smartcontract.BoolType,
manifest.NewParameter("account", smartcontract.Hash160Type)) manifest.NewParameter("account", smartcontract.Hash160Type))
md = newMethodAndPrice(p.blockAccount, 3000000, callflag.States) md = newMethodAndPrice(p.blockAccount, 1<<15, callflag.States)
p.AddMethod(md, desc) p.AddMethod(md, desc)
desc = newDescriptor("unblockAccount", smartcontract.BoolType, desc = newDescriptor("unblockAccount", smartcontract.BoolType,
manifest.NewParameter("account", smartcontract.Hash160Type)) manifest.NewParameter("account", smartcontract.Hash160Type))
md = newMethodAndPrice(p.unblockAccount, 3000000, callflag.States) md = newMethodAndPrice(p.unblockAccount, 1<<15, callflag.States)
p.AddMethod(md, desc) p.AddMethod(md, desc)
return p return p

View file

@ -56,7 +56,7 @@ func (bc *Blockchain) registerNative(c interop.Contract) {
bc.contracts.Contracts = append(bc.contracts.Contracts, c) bc.contracts.Contracts = append(bc.contracts.Contracts, c)
} }
const testSumPrice = 1 << 15 * interop.DefaultBaseExecFee // same as contract.Call const testSumCPUFee = 1 << 15 // same as contract.Call
func newTestNative() *testNative { func newTestNative() *testNative {
tn := &testNative{ tn := &testNative{
@ -76,7 +76,7 @@ func newTestNative() *testNative {
} }
md := &interop.MethodAndPrice{ md := &interop.MethodAndPrice{
Func: tn.sum, Func: tn.sum,
Price: testSumPrice, CPUFee: testSumCPUFee,
RequiredFlags: callflag.NoneFlag, RequiredFlags: callflag.NoneFlag,
} }
tn.meta.AddMethod(md, desc) tn.meta.AddMethod(md, desc)
@ -93,7 +93,7 @@ func newTestNative() *testNative {
} }
md = &interop.MethodAndPrice{ md = &interop.MethodAndPrice{
Func: tn.callOtherContractNoReturn, Func: tn.callOtherContractNoReturn,
Price: testSumPrice, CPUFee: testSumCPUFee,
RequiredFlags: callflag.NoneFlag} RequiredFlags: callflag.NoneFlag}
tn.meta.AddMethod(md, desc) tn.meta.AddMethod(md, desc)
@ -108,7 +108,7 @@ func newTestNative() *testNative {
} }
md = &interop.MethodAndPrice{ md = &interop.MethodAndPrice{
Func: tn.callOtherContractWithReturn, Func: tn.callOtherContractWithReturn,
Price: testSumPrice, CPUFee: testSumCPUFee,
RequiredFlags: callflag.NoneFlag} RequiredFlags: callflag.NoneFlag}
tn.meta.AddMethod(md, desc) tn.meta.AddMethod(md, desc)
@ -182,7 +182,7 @@ func TestNativeContract_Invoke(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// System.Contract.Call + "sum" itself + opcodes for pushing arguments. // System.Contract.Call + "sum" itself + opcodes for pushing arguments.
price := int64(testSumPrice * 2) price := int64(testSumCPUFee * chain.GetBaseExecFee() * 2)
price += 3 * fee.Opcode(chain.GetBaseExecFee(), opcode.PUSHINT8) price += 3 * fee.Opcode(chain.GetBaseExecFee(), opcode.PUSHINT8)
price += 2 * fee.Opcode(chain.GetBaseExecFee(), opcode.SYSCALL, opcode.PUSHDATA1, opcode.PUSHINT8) price += 2 * fee.Opcode(chain.GetBaseExecFee(), opcode.SYSCALL, opcode.PUSHDATA1, opcode.PUSHINT8)
price += fee.Opcode(chain.GetBaseExecFee(), opcode.PACK) price += fee.Opcode(chain.GetBaseExecFee(), opcode.PACK)
@ -281,15 +281,16 @@ func TestNativeContract_InvokeOtherContract(t *testing.T) {
cs, _ := getTestContractState(chain) cs, _ := getTestContractState(chain)
require.NoError(t, chain.contracts.Management.PutContractState(chain.dao, cs)) require.NoError(t, chain.contracts.Management.PutContractState(chain.dao, cs))
baseFee := chain.GetBaseExecFee()
t.Run("non-native, no return", func(t *testing.T) { t.Run("non-native, no return", func(t *testing.T) {
res, err := invokeContractMethod(chain, testSumPrice*4+10000, tn.Metadata().Hash, "callOtherContractNoReturn", cs.Hash, "justReturn", []interface{}{}) res, err := invokeContractMethod(chain, testSumCPUFee*baseFee*4+10000, tn.Metadata().Hash, "callOtherContractNoReturn", cs.Hash, "justReturn", []interface{}{})
require.NoError(t, err) require.NoError(t, err)
drainTN(t) drainTN(t)
require.Equal(t, vm.HaltState, res.VMState, res.FaultException) require.Equal(t, vm.HaltState, res.VMState, res.FaultException)
checkResult(t, res, stackitem.Null{}) // simple call is done with EnsureNotEmpty checkResult(t, res, stackitem.Null{}) // simple call is done with EnsureNotEmpty
}) })
t.Run("non-native, with return", func(t *testing.T) { t.Run("non-native, with return", func(t *testing.T) {
res, err := invokeContractMethod(chain, testSumPrice*4+10000, tn.Metadata().Hash, res, err := invokeContractMethod(chain, testSumCPUFee*baseFee*4+10000, tn.Metadata().Hash,
"callOtherContractWithReturn", cs.Hash, "ret7", []interface{}{}) "callOtherContractWithReturn", cs.Hash, "ret7", []interface{}{})
require.NoError(t, err) require.NoError(t, err)
drainTN(t) drainTN(t)

View file

@ -98,8 +98,8 @@ func TestCreateResponseTx(t *testing.T) {
tx, err := orc.CreateResponseTx(int64(req.GasForResponse), 1, resp) tx, err := orc.CreateResponseTx(int64(req.GasForResponse), 1, resp)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, 166, tx.Size()) assert.Equal(t, 166, tx.Size())
assert.Equal(t, int64(2215610), tx.NetworkFee) assert.Equal(t, int64(2198650), tx.NetworkFee)
assert.Equal(t, int64(97784390), tx.SystemFee) assert.Equal(t, int64(97801350), tx.SystemFee)
} }
func TestOracle_InvalidWallet(t *testing.T) { func TestOracle_InvalidWallet(t *testing.T) {

View file

@ -694,7 +694,7 @@ func (c *Client) CalculateNotaryFee(nKeys uint8) (int64, error) {
fee.Opcode(baseExecFee, // Notary node witness fee.Opcode(baseExecFee, // Notary node witness
opcode.PUSHDATA1, opcode.RET, // invocation script opcode.PUSHDATA1, opcode.RET, // invocation script
opcode.PUSH0, opcode.SYSCALL, opcode.RET) + // System.Contract.CallNative opcode.PUSH0, opcode.SYSCALL, opcode.RET) + // System.Contract.CallNative
native.NotaryVerificationPrice + // Notary witness verification price native.NotaryVerificationPrice*baseExecFee + // Notary witness verification price
feePerByte*int64(io.GetVarSize(make([]byte, 66))) + // invocation script per-byte fee feePerByte*int64(io.GetVarSize(make([]byte, 66))) + // invocation script per-byte fee
feePerByte*int64(io.GetVarSize([]byte{})), // verification script per-byte fee feePerByte*int64(io.GetVarSize([]byte{})), // verification script per-byte fee
nil nil