From 73b630db9b6981973b307f4aea70e483b90d3203 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 23 Jun 2020 17:15:35 +0300 Subject: [PATCH] *: switch from fixed8 to int64 Follow C# implementation, we have to marshall JSON Fixed8 fields without taking into account decimals. --- cli/wallet/nep5.go | 2 +- pkg/consensus/consensus_test.go | 6 +-- pkg/core/blockchain.go | 20 ++++----- pkg/core/blockchainer/blockchainer.go | 2 +- pkg/core/gas_price.go | 5 +-- pkg/core/helper_test.go | 14 +++--- pkg/core/interop/context.go | 2 +- pkg/core/interop/crypto/ecdsa.go | 3 +- pkg/core/interop/runtime/util.go | 2 +- pkg/core/interop_neo.go | 3 +- pkg/core/interop_system.go | 2 +- pkg/core/mempool/feer.go | 4 +- pkg/core/mempool/mem_pool.go | 12 ++--- pkg/core/mempool/mem_pool_test.go | 52 +++++++++++----------- pkg/core/native/contract.go | 2 +- pkg/core/native/native_gas.go | 4 +- pkg/core/opcode_price.go | 9 ++-- pkg/core/state/notification_event.go | 6 +-- pkg/core/transaction/transaction.go | 22 ++++----- pkg/core/transaction/transaction_test.go | 3 +- pkg/core/util.go | 24 +++++----- pkg/network/helper_test.go | 6 +-- pkg/rpc/client/nep5.go | 12 ++--- pkg/rpc/client/rpc.go | 4 +- pkg/rpc/client/rpc_test.go | 22 ++++----- pkg/rpc/client/wsclient_test.go | 6 +-- pkg/rpc/request/txBuilder.go | 4 +- pkg/rpc/response/result/application_log.go | 6 +-- pkg/rpc/response/result/invoke.go | 2 +- pkg/rpc/server/server.go | 10 ++--- pkg/rpc/server/server_helper_test.go | 7 +-- pkg/rpc/server/server_test.go | 6 +-- pkg/vm/interop.go | 2 +- pkg/vm/vm.go | 12 ++--- pkg/vm/vm_test.go | 3 +- 35 files changed, 146 insertions(+), 155 deletions(-) diff --git a/cli/wallet/nep5.go b/cli/wallet/nep5.go index e0d09a5f5..129fe5aa8 100644 --- a/cli/wallet/nep5.go +++ b/cli/wallet/nep5.go @@ -360,7 +360,7 @@ func transferNEP5(ctx *cli.Context) error { return cli.NewExitError(err, 1) } - tx, err := c.CreateNEP5TransferTx(acc, to, token.Hash, amount, gas) + tx, err := c.CreateNEP5TransferTx(acc, to, token.Hash, amount, int64(gas)) if err != nil { return cli.NewExitError(err, 1) } diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index fb4c82278..fc3184ae4 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -251,7 +251,7 @@ func addSender(t *testing.T, txs ...*transaction.Transaction) { } } -func signTx(t *testing.T, feePerByte util.Fixed8, txs ...*transaction.Transaction) { +func signTx(t *testing.T, feePerByte int64, txs ...*transaction.Transaction) { validators := make([]*keys.PublicKey, 4) privNetKeys := make([]*keys.PrivateKey, 4) for i := 0; i < 4; i++ { @@ -263,9 +263,9 @@ func signTx(t *testing.T, feePerByte util.Fixed8, txs ...*transaction.Transactio for _, tx := range txs { size := io.GetVarSize(tx) netFee, sizeDelta := core.CalculateNetworkFee(rawScript) - tx.NetworkFee = tx.NetworkFee.Add(netFee) + tx.NetworkFee += +netFee size += sizeDelta - tx.NetworkFee = tx.NetworkFee.Add(util.Fixed8(int64(size) * int64(feePerByte))) + tx.NetworkFee += int64(size) * feePerByte data := tx.GetSignedPart() buf := io.NewBufBinWriter() diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index bb29bd349..96e5f1b73 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -788,23 +788,23 @@ func (bc *Blockchain) GetNEP5Balances(acc util.Uint160) *state.NEP5Balances { } // GetUtilityTokenBalance returns utility token (GAS) balance for the acc. -func (bc *Blockchain) GetUtilityTokenBalance(acc util.Uint160) util.Fixed8 { +func (bc *Blockchain) GetUtilityTokenBalance(acc util.Uint160) int64 { bs, err := bc.dao.GetNEP5Balances(acc) if err != nil { return 0 } - return util.Fixed8(bs.Trackers[bc.contracts.GAS.Hash].Balance) + return bs.Trackers[bc.contracts.GAS.Hash].Balance } // GetGoverningTokenBalance returns governing token (NEO) balance and the height // of the last balance change for the account. -func (bc *Blockchain) GetGoverningTokenBalance(acc util.Uint160) (util.Fixed8, uint32) { +func (bc *Blockchain) GetGoverningTokenBalance(acc util.Uint160) (int64, uint32) { bs, err := bc.dao.GetNEP5Balances(acc) if err != nil { return 0, 0 } neo := bs.Trackers[bc.contracts.NEO.Hash] - return util.Fixed8(neo.Balance), neo.LastUpdatedBlock + return neo.Balance, neo.LastUpdatedBlock } // LastBatch returns last persisted storage batch. @@ -1092,8 +1092,8 @@ func (bc *Blockchain) CalculateClaimable(value int64, startHeight, endHeight uin } // FeePerByte returns transaction network fee per byte. -func (bc *Blockchain) FeePerByte() util.Fixed8 { - return util.Fixed8(bc.contracts.Policy.GetFeePerByteInternal(bc.dao)) +func (bc *Blockchain) FeePerByte() int64 { + return bc.contracts.Policy.GetFeePerByteInternal(bc.dao) } // GetMemPool returns the memory pool of the blockchain. @@ -1147,16 +1147,16 @@ func (bc *Blockchain) verifyTx(t *transaction.Transaction, block *block.Block) e } } balance := bc.GetUtilityTokenBalance(t.Sender) - need := t.SystemFee.Add(t.NetworkFee) - if balance.LessThan(need) { + need := t.SystemFee + t.NetworkFee + if balance < need { return errors.Errorf("insufficient funds: balance is %v, need: %v", balance, need) } size := io.GetVarSize(t) if size > transaction.MaxTransactionSize { return errors.Errorf("invalid transaction size = %d. It shoud be less then MaxTransactionSize = %d", io.GetVarSize(t), transaction.MaxTransactionSize) } - needNetworkFee := util.Fixed8(int64(size) * int64(bc.FeePerByte())) - netFee := t.NetworkFee.Sub(needNetworkFee) + needNetworkFee := int64(size) * bc.FeePerByte() + netFee := t.NetworkFee - needNetworkFee if netFee < 0 { return errors.Errorf("insufficient funds: net fee is %v, need %v", t.NetworkFee, needNetworkFee) } diff --git a/pkg/core/blockchainer/blockchainer.go b/pkg/core/blockchainer/blockchainer.go index ef667c51e..6c5fcad2f 100644 --- a/pkg/core/blockchainer/blockchainer.go +++ b/pkg/core/blockchainer/blockchainer.go @@ -25,7 +25,7 @@ type Blockchainer interface { GetBlock(hash util.Uint256) (*block.Block, error) GetContractState(hash util.Uint160) *state.Contract GetEnrollments() ([]state.Validator, error) - GetGoverningTokenBalance(acc util.Uint160) (util.Fixed8, uint32) + GetGoverningTokenBalance(acc util.Uint160) (int64, uint32) GetHeaderHash(int) util.Uint256 GetHeader(hash util.Uint256) (*block.Header, error) CurrentHeaderHash() util.Uint256 diff --git a/pkg/core/gas_price.go b/pkg/core/gas_price.go index e066266e3..7741206d5 100644 --- a/pkg/core/gas_price.go +++ b/pkg/core/gas_price.go @@ -1,7 +1,6 @@ package core import ( - "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" ) @@ -11,12 +10,12 @@ const StoragePrice = 100000 // getPrice returns a price for executing op with the provided parameter. // Some SYSCALLs have variable price depending on their arguments. -func getPrice(v *vm.VM, op opcode.Opcode, parameter []byte) util.Fixed8 { +func getPrice(v *vm.VM, op opcode.Opcode, parameter []byte) int64 { if op == opcode.SYSCALL { interopID := vm.GetInteropID(parameter) ifunc := v.GetInteropByID(interopID) if ifunc != nil && ifunc.Price > 0 { - return util.Fixed8(ifunc.Price) + return ifunc.Price } } return opcodePrice(op) diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index fb16b2f43..ec59d52c6 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/block" + "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" @@ -180,7 +181,7 @@ func TestCreateBasicChain(t *testing.T) { priv0 := testchain.PrivateKeyByID(0) priv0ScriptHash := priv0.GetScriptHash() - require.Equal(t, util.Fixed8FromInt64(0), bc.GetUtilityTokenBalance(priv0ScriptHash)) + require.Equal(t, int64(0), bc.GetUtilityTokenBalance(priv0ScriptHash)) // Move some NEO to one simple account. txMoveNeo := newNEP5Transfer(neoHash, neoOwner, priv0ScriptHash, neoAmount) txMoveNeo.ValidUntilBlock = validUntilBlock @@ -210,7 +211,7 @@ func TestCreateBasicChain(t *testing.T) { t.Logf("txMoveNeo: %s", txMoveNeo.Hash().StringLE()) t.Logf("txMoveGas: %s", txMoveGas.Hash().StringLE()) - require.True(t, util.Fixed8FromInt64(1000).CompareTo(bc.GetUtilityTokenBalance(priv0ScriptHash)) <= 0) + require.True(t, bc.GetUtilityTokenBalance(priv0ScriptHash) >= 1000*native.GASFactor) // info for getblockheader rpc tests t.Logf("header hash: %s", b.Hash().StringLE()) buf := io.NewBufBinWriter() @@ -241,8 +242,7 @@ func TestCreateBasicChain(t *testing.T) { emit.Syscall(script.BinWriter, "System.Contract.Create") txScript := script.Bytes() - invFee := util.Fixed8FromFloat(100) - txDeploy := transaction.New(testchain.Network(), txScript, invFee) + txDeploy := transaction.New(testchain.Network(), txScript, 100*native.GASFactor) txDeploy.Nonce = getNextNonce() txDeploy.ValidUntilBlock = validUntilBlock txDeploy.Sender = priv0ScriptHash @@ -407,9 +407,9 @@ func signTx(bc *Blockchain, txs ...*transaction.Transaction) error { for _, tx := range txs { size := io.GetVarSize(tx) netFee, sizeDelta := CalculateNetworkFee(rawScript) - tx.NetworkFee = tx.NetworkFee.Add(netFee) + tx.NetworkFee += netFee size += sizeDelta - tx.NetworkFee = tx.NetworkFee.Add(util.Fixed8(int64(size) * int64(bc.FeePerByte()))) + tx.NetworkFee += int64(size) * bc.FeePerByte() data := tx.GetSignedPart() tx.Scripts = []transaction.Witness{{ InvocationScript: testchain.Sign(data), @@ -432,6 +432,6 @@ func addNetworkFee(bc *Blockchain, tx *transaction.Transaction, sender *wallet.A size += sizeDelta } } - tx.NetworkFee += util.Fixed8(int64(size) * int64(bc.FeePerByte())) + tx.NetworkFee += int64(size) * bc.FeePerByte() return nil } diff --git a/pkg/core/interop/context.go b/pkg/core/interop/context.go index af39d9aca..b92e39661 100644 --- a/pkg/core/interop/context.go +++ b/pkg/core/interop/context.go @@ -57,7 +57,7 @@ type Function struct { ID uint32 Name string Func func(*Context, *vm.VM) error - Price int + Price int64 // AllowedTriggers is a set of triggers which are allowed to initiate invocation. AllowedTriggers trigger.Type // RequiredFlags is a set of flags which must be set during script invocations. diff --git a/pkg/core/interop/crypto/ecdsa.go b/pkg/core/interop/crypto/ecdsa.go index cdcee4c23..d744eef20 100644 --- a/pkg/core/interop/crypto/ecdsa.go +++ b/pkg/core/interop/crypto/ecdsa.go @@ -8,7 +8,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -39,7 +38,7 @@ func ECDSACheckMultisig(ic *interop.Context, v *vm.VM) error { if err != nil { return fmt.Errorf("wrong parameters: %s", err.Error()) } - if !v.AddGas(util.Fixed8(ECDSAVerifyPrice * len(pkeys))) { + if !v.AddGas(ECDSAVerifyPrice * int64(len(pkeys))) { return errors.New("gas limit exceeded") } sigs, err := v.Estack().PopSigElements() diff --git a/pkg/core/interop/runtime/util.go b/pkg/core/interop/runtime/util.go index e9a122507..9a79375b9 100644 --- a/pkg/core/interop/runtime/util.go +++ b/pkg/core/interop/runtime/util.go @@ -11,7 +11,7 @@ import ( // GasLeft returns remaining amount of GAS. func GasLeft(_ *interop.Context, v *vm.VM) error { - v.Estack().PushVal(int64(v.GasLimit - v.GasConsumed())) + v.Estack().PushVal(v.GasLimit - v.GasConsumed()) return nil } diff --git a/pkg/core/interop_neo.go b/pkg/core/interop_neo.go index 0c77bbc23..47cff726f 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -9,7 +9,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" - "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -67,7 +66,7 @@ func createContractStateFromVM(ic *interop.Context, v *vm.VM) (*state.Contract, if len(manifestBytes) > manifest.MaxManifestSize { return nil, errors.New("manifest is too big") } - if !v.AddGas(util.Fixed8(StoragePrice * (len(script) + len(manifestBytes)))) { + if !v.AddGas(int64(StoragePrice * (len(script) + len(manifestBytes)))) { return nil, errGasLimitExceeded } var m manifest.Manifest diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index 66fd0e478..c1df13b58 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -346,7 +346,7 @@ func putWithContextAndFlags(ic *interop.Context, v *vm.VM, stc *StorageContext, if len(value) > len(si.Value) { sizeInc = len(value) - len(si.Value) } - if !v.AddGas(util.Fixed8(sizeInc) * StoragePrice) { + if !v.AddGas(int64(sizeInc) * StoragePrice) { return errGasLimitExceeded } si.Value = value diff --git a/pkg/core/mempool/feer.go b/pkg/core/mempool/feer.go index 556432566..9a22295f6 100644 --- a/pkg/core/mempool/feer.go +++ b/pkg/core/mempool/feer.go @@ -6,6 +6,6 @@ import ( // Feer is an interface that abstract the implementation of the fee calculation. type Feer interface { - FeePerByte() util.Fixed8 - GetUtilityTokenBalance(util.Uint160) util.Fixed8 + FeePerByte() int64 + GetUtilityTokenBalance(util.Uint160) int64 } diff --git a/pkg/core/mempool/mem_pool.go b/pkg/core/mempool/mem_pool.go index 7f767d6ab..b20318c4f 100644 --- a/pkg/core/mempool/mem_pool.go +++ b/pkg/core/mempool/mem_pool.go @@ -35,8 +35,8 @@ type items []*item // utilityBalanceAndFees stores sender's balance and overall fees of // sender's transactions which are currently in mempool type utilityBalanceAndFees struct { - balance util.Fixed8 - feeSum util.Fixed8 + balance int64 + feeSum int64 } // Pool stores the unconfirms transactions. @@ -47,7 +47,7 @@ type Pool struct { fees map[util.Uint160]utilityBalanceAndFees capacity int - feePerByte util.Fixed8 + feePerByte int64 } func (p items) Len() int { return len(p) } @@ -64,11 +64,11 @@ func (p *item) CompareTo(otherP *item) int { } // Fees sorted ascending. - if ret := p.txn.FeePerByte().CompareTo(otherP.txn.FeePerByte()); ret != 0 { + if ret := int(p.txn.FeePerByte() - otherP.txn.FeePerByte()); ret != 0 { return ret } - if ret := p.txn.NetworkFee.CompareTo(otherP.txn.NetworkFee); ret != 0 { + if ret := int(p.txn.NetworkFee - otherP.txn.NetworkFee); ret != 0 { return ret } @@ -239,7 +239,7 @@ func (mp *Pool) RemoveStale(isOK func(*transaction.Transaction) bool, feer Feer) // changed. func (mp *Pool) loadPolicy(feer Feer) bool { newFeePerByte := feer.FeePerByte() - if newFeePerByte.GreaterThan(mp.feePerByte) { + if newFeePerByte > mp.feePerByte { mp.feePerByte = newFeePerByte return true } diff --git a/pkg/core/mempool/mem_pool_test.go b/pkg/core/mempool/mem_pool_test.go index bae5196f3..c7b8896cb 100644 --- a/pkg/core/mempool/mem_pool_test.go +++ b/pkg/core/mempool/mem_pool_test.go @@ -13,15 +13,17 @@ import ( ) type FeerStub struct { - feePerByte util.Fixed8 + feePerByte int64 } -func (fs *FeerStub) FeePerByte() util.Fixed8 { +const balance = 10000000 + +func (fs *FeerStub) FeePerByte() int64 { return fs.feePerByte } -func (fs *FeerStub) GetUtilityTokenBalance(uint160 util.Uint160) util.Fixed8 { - return util.Fixed8FromInt64(10000) +func (fs *FeerStub) GetUtilityTokenBalance(uint160 util.Uint160) int64 { + return balance } func testMemPoolAddRemoveWithFeer(t *testing.T, fs Feer) { @@ -70,10 +72,10 @@ func TestOverCapacity(t *testing.T) { Usage: transaction.Hash1, Data: util.Uint256{1, 2, 3, 4}.BytesBE(), }) - tx.NetworkFee = util.Fixed8FromFloat(0.0001) + tx.NetworkFee = 10000 tx.Nonce = txcnt txcnt++ - // size is 84, networkFee is 0.0001 => feePerByte is 0.00000119 + // size is 84, networkFee is 10000 => feePerByte is 119 require.NoError(t, mp.Add(tx, fs)) require.Equal(t, mempoolSize, mp.Count()) require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes))) @@ -84,7 +86,7 @@ func TestOverCapacity(t *testing.T) { Usage: transaction.Hash1, Data: util.Uint256{1, 2, 3, 4}.BytesBE(), }) - tx.NetworkFee = util.Fixed8FromFloat(0.000001) + tx.NetworkFee = 100 tx.Nonce = txcnt txcnt++ require.Error(t, mp.Add(tx, fs)) @@ -94,10 +96,10 @@ func TestOverCapacity(t *testing.T) { // Low net fee, but higher per-byte fee is still a better combination. tx = transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) tx.Nonce = txcnt - tx.NetworkFee = util.Fixed8FromFloat(0.00007) + tx.NetworkFee = 7000 txcnt++ - // size is 51 (no attributes), networkFee is 0.00007 (<0.0001) - // => feePerByte is 0.00000137 (>0.00000119) + // size is 51 (no attributes), networkFee is 7000 (<10000) + // => feePerByte is 137 (>119) require.NoError(t, mp.Add(tx, fs)) require.Equal(t, mempoolSize, mp.Count()) require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes))) @@ -105,7 +107,7 @@ func TestOverCapacity(t *testing.T) { // High priority always wins over low priority. for i := 0; i < mempoolSize; i++ { tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) - tx.NetworkFee = util.Fixed8FromFloat(0.00008) + tx.NetworkFee = 8000 tx.Nonce = txcnt txcnt++ require.NoError(t, mp.Add(tx, fs)) @@ -115,7 +117,7 @@ func TestOverCapacity(t *testing.T) { // Good luck with low priority now. tx = transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) tx.Nonce = txcnt - tx.NetworkFee = util.Fixed8FromFloat(0.00007) + tx.NetworkFee = 7000 require.Error(t, mp.Add(tx, fs)) require.Equal(t, mempoolSize, mp.Count()) require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes))) @@ -182,50 +184,50 @@ func TestMemPoolFees(t *testing.T) { mp := NewMemPool(10) sender0 := util.Uint160{1, 2, 3} tx0 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) - tx0.NetworkFee = util.Fixed8FromInt64(11000) + tx0.NetworkFee = balance + 1 tx0.Sender = sender0 // insufficient funds to add transaction, but balance should be stored require.Equal(t, false, mp.Verify(tx0, &FeerStub{})) require.Error(t, mp.Add(tx0, &FeerStub{})) require.Equal(t, 1, len(mp.fees)) require.Equal(t, utilityBalanceAndFees{ - balance: util.Fixed8FromInt64(10000), + balance: balance, feeSum: 0, }, mp.fees[sender0]) // no problems with adding another transaction with lower fee tx1 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) - tx1.NetworkFee = util.Fixed8FromInt64(7000) + tx1.NetworkFee = balance * 0.7 tx1.Sender = sender0 require.NoError(t, mp.Add(tx1, &FeerStub{})) require.Equal(t, 1, len(mp.fees)) require.Equal(t, utilityBalanceAndFees{ - balance: util.Fixed8FromInt64(10000), - feeSum: util.Fixed8FromInt64(7000), + balance: balance, + feeSum: tx1.NetworkFee, }, mp.fees[sender0]) // balance shouldn't change after adding one more transaction tx2 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) - tx2.NetworkFee = util.Fixed8FromFloat(3000) + tx2.NetworkFee = balance * 0.3 tx2.Sender = sender0 require.NoError(t, mp.Add(tx2, &FeerStub{})) require.Equal(t, 2, len(mp.verifiedTxes)) require.Equal(t, 1, len(mp.fees)) require.Equal(t, utilityBalanceAndFees{ - balance: util.Fixed8FromInt64(10000), - feeSum: util.Fixed8FromInt64(10000), + balance: balance, + feeSum: balance, }, mp.fees[sender0]) // can't add more transactions as we don't have enough GAS tx3 := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) - tx3.NetworkFee = util.Fixed8FromFloat(0.5) + tx3.NetworkFee = 1 tx3.Sender = sender0 require.Equal(t, false, mp.Verify(tx3, &FeerStub{})) require.Error(t, mp.Add(tx3, &FeerStub{})) require.Equal(t, 1, len(mp.fees)) require.Equal(t, utilityBalanceAndFees{ - balance: util.Fixed8FromInt64(10000), - feeSum: util.Fixed8FromInt64(10000), + balance: balance, + feeSum: balance, }, mp.fees[sender0]) // check whether sender's fee updates correctly @@ -237,8 +239,8 @@ func TestMemPoolFees(t *testing.T) { }, &FeerStub{}) require.Equal(t, 1, len(mp.fees)) require.Equal(t, utilityBalanceAndFees{ - balance: util.Fixed8FromInt64(10000), - feeSum: util.Fixed8FromFloat(3000), + balance: balance, + feeSum: tx2.NetworkFee, }, mp.fees[sender0]) // there should be nothing left diff --git a/pkg/core/native/contract.go b/pkg/core/native/contract.go index 47629e485..8dee4230a 100644 --- a/pkg/core/native/contract.go +++ b/pkg/core/native/contract.go @@ -108,7 +108,7 @@ func getNativeInterop(ic *interop.Context, c interop.Contract) func(v *vm.VM) er if !v.Context().GetCallFlags().Has(m.RequiredFlags) { return errors.New("missing call flags") } - if !v.AddGas(util.Fixed8(m.Price)) { + if !v.AddGas(m.Price) { return errors.New("gas limit exceeded") } result := m.Func(ic, args) diff --git a/pkg/core/native/native_gas.go b/pkg/core/native/native_gas.go index dcc17d27f..d7bc10b5e 100644 --- a/pkg/core/native/native_gas.go +++ b/pkg/core/native/native_gas.go @@ -88,7 +88,7 @@ func (g *GAS) OnPersist(ic *interop.Context) error { return nil } for _, tx := range ic.Block.Transactions { - absAmount := big.NewInt(int64(tx.SystemFee + tx.NetworkFee)) + absAmount := big.NewInt(tx.SystemFee + tx.NetworkFee) g.burn(ic, tx.Sender, absAmount) } validators, err := g.NEO.getNextBlockValidatorsInternal(ic.Chain, ic.DAO) @@ -96,7 +96,7 @@ func (g *GAS) OnPersist(ic *interop.Context) error { return fmt.Errorf("cannot get block validators: %v", err) } primary := validators[ic.Block.ConsensusData.PrimaryIndex].GetScriptHash() - var netFee util.Fixed8 + var netFee int64 for _, tx := range ic.Block.Transactions { netFee += tx.NetworkFee } diff --git a/pkg/core/opcode_price.go b/pkg/core/opcode_price.go index 06302c051..d870d6bf6 100644 --- a/pkg/core/opcode_price.go +++ b/pkg/core/opcode_price.go @@ -1,20 +1,19 @@ package core import ( - "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" ) // opcodePrice returns the deployment prices of specified opcodes -func opcodePrice(opcodes ...opcode.Opcode) util.Fixed8 { - var result util.Fixed8 +func opcodePrice(opcodes ...opcode.Opcode) int64 { + var result int64 for _, op := range opcodes { - result += util.Fixed8(prices[op]) + result += prices[op] } return result } -var prices = map[opcode.Opcode]int{ +var prices = map[opcode.Opcode]int64{ opcode.PUSHINT8: 30, opcode.PUSHINT32: 30, opcode.PUSHINT64: 30, diff --git a/pkg/core/state/notification_event.go b/pkg/core/state/notification_event.go index b7efe327f..12699b14a 100644 --- a/pkg/core/state/notification_event.go +++ b/pkg/core/state/notification_event.go @@ -21,7 +21,7 @@ type AppExecResult struct { TxHash util.Uint256 Trigger trigger.Type VMState string - GasConsumed util.Fixed8 + GasConsumed int64 Stack []smartcontract.Parameter Events []NotificationEvent } @@ -43,7 +43,7 @@ func (aer *AppExecResult) EncodeBinary(w *io.BinWriter) { w.WriteBytes(aer.TxHash[:]) w.WriteB(byte(aer.Trigger)) w.WriteString(aer.VMState) - aer.GasConsumed.EncodeBinary(w) + w.WriteU64LE(uint64(aer.GasConsumed)) w.WriteArray(aer.Stack) w.WriteArray(aer.Events) } @@ -53,7 +53,7 @@ func (aer *AppExecResult) DecodeBinary(r *io.BinReader) { r.ReadBytes(aer.TxHash[:]) aer.Trigger = trigger.Type(r.ReadB()) aer.VMState = r.ReadString() - aer.GasConsumed.DecodeBinary(r) + aer.GasConsumed = int64(r.ReadU64LE()) r.ReadArray(&aer.Stack) r.ReadArray(&aer.Events) } diff --git a/pkg/core/transaction/transaction.go b/pkg/core/transaction/transaction.go index 96c0864d1..9785276c6 100644 --- a/pkg/core/transaction/transaction.go +++ b/pkg/core/transaction/transaction.go @@ -36,10 +36,10 @@ type Transaction struct { Sender util.Uint160 // Fee to be burned. - SystemFee util.Fixed8 + SystemFee int64 // Fee to be distributed to consensus nodes. - NetworkFee util.Fixed8 + NetworkFee int64 // Maximum blockchain height exceeding which // transaction should fail verification. @@ -86,7 +86,7 @@ func NewTrimmedTX(hash util.Uint256) *Transaction { // New returns a new transaction to execute given script and pay given system // fee. -func New(network netmode.Magic, script []byte, gas util.Fixed8) *Transaction { +func New(network netmode.Magic, script []byte, gas int64) *Transaction { return &Transaction{ Version: 0, Nonce: rand.Uint32(), @@ -129,12 +129,12 @@ func (t *Transaction) decodeHashableFields(br *io.BinReader) { } t.Nonce = br.ReadU32LE() t.Sender.DecodeBinary(br) - t.SystemFee.DecodeBinary(br) + t.SystemFee = int64(br.ReadU64LE()) if t.SystemFee < 0 { br.Err = errors.New("negative system fee") return } - t.NetworkFee.DecodeBinary(br) + t.NetworkFee = int64(br.ReadU64LE()) if t.NetworkFee < 0 { br.Err = errors.New("negative network fee") return @@ -195,8 +195,8 @@ func (t *Transaction) encodeHashableFields(bw *io.BinWriter) { bw.WriteB(byte(t.Version)) bw.WriteU32LE(t.Nonce) t.Sender.EncodeBinary(bw) - t.SystemFee.EncodeBinary(bw) - t.NetworkFee.EncodeBinary(bw) + bw.WriteU64LE(uint64(t.SystemFee)) + bw.WriteU64LE(uint64(t.NetworkFee)) bw.WriteU32LE(t.ValidUntilBlock) // Attributes @@ -277,8 +277,8 @@ func NewTransactionFromBytes(network netmode.Magic, b []byte) (*Transaction, err // FeePerByte returns NetworkFee of the transaction divided by // its size -func (t *Transaction) FeePerByte() util.Fixed8 { - return util.Fixed8(int64(t.NetworkFee) / int64(io.GetVarSize(t))) +func (t *Transaction) FeePerByte() int64 { + return t.NetworkFee / int64(io.GetVarSize(t)) } // transactionJSON is a wrapper for Transaction and @@ -289,8 +289,8 @@ type transactionJSON struct { Version uint8 `json:"version"` Nonce uint32 `json:"nonce"` Sender string `json:"sender"` - SystemFee util.Fixed8 `json:"sys_fee"` - NetworkFee util.Fixed8 `json:"net_fee"` + SystemFee int64 `json:"sys_fee,string"` + NetworkFee int64 `json:"net_fee,string"` ValidUntilBlock uint32 `json:"valid_until_block"` Attributes []Attribute `json:"attributes"` Cosigners []Cosigner `json:"cosigners"` diff --git a/pkg/core/transaction/transaction_test.go b/pkg/core/transaction/transaction_test.go index b7cbd81d0..37cd3771b 100644 --- a/pkg/core/transaction/transaction_test.go +++ b/pkg/core/transaction/transaction_test.go @@ -6,7 +6,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/internal/testserdes" - "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -65,7 +64,7 @@ func TestDecodeEncodeInvocationTX(t *testing.T) { func TestNew(t *testing.T) { script := []byte{0x51} tx := New(netmode.UnitTestNet, script, 1) - assert.Equal(t, util.Fixed8(1), tx.SystemFee) + assert.Equal(t, int64(1), tx.SystemFee) assert.Equal(t, script, tx.Script) // Update hash fields to match tx2 that is gonna autoupdate them on decode. _ = tx.Hash() diff --git a/pkg/core/util.go b/pkg/core/util.go index 339422900..6082ca8e5 100644 --- a/pkg/core/util.go +++ b/pkg/core/util.go @@ -17,6 +17,10 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/opcode" ) +// ecdsaVerifyInteropPrice returns the price of Neo.Crypto.ECDsaVerify +// syscall to calculate NetworkFee for transaction +const ecdsaVerifyInteropPrice = 100000 + var ( // governingTokenTX represents transaction that is used to create // governing (NEO) token. It's a part of the genesis block. @@ -26,10 +30,6 @@ var ( // utility (GAS) token. It's a part of the genesis block. It's mostly // useful for its hash that represents GAS asset ID. utilityTokenTX transaction.Transaction - - // ecdsaVerifyInteropPrice returns the price of Neo.Crypto.ECDsaVerify - // syscall to calculate NetworkFee for transaction - ecdsaVerifyInteropPrice = util.Fixed8(100000) ) // createGenesisBlock creates a genesis block based on the given configuration. @@ -131,31 +131,31 @@ func headerSliceReverse(dest []*block.Header) { } // CalculateNetworkFee returns network fee for transaction -func CalculateNetworkFee(script []byte) (util.Fixed8, int) { +func CalculateNetworkFee(script []byte) (int64, int) { var ( - netFee util.Fixed8 + netFee int64 size int ) if vm.IsSignatureContract(script) { size += 67 + io.GetVarSize(script) - netFee = netFee.Add(opcodePrice(opcode.PUSHDATA1, opcode.PUSHNULL).Add(ecdsaVerifyInteropPrice)) + netFee += opcodePrice(opcode.PUSHDATA1, opcode.PUSHNULL) + ecdsaVerifyInteropPrice } else if n, pubs, ok := vm.ParseMultiSigContract(script); ok { m := len(pubs) sizeInv := 66 * m size += io.GetVarSize(sizeInv) + sizeInv + io.GetVarSize(script) - netFee = netFee.Add(calculateMultisigFee(m)).Add(calculateMultisigFee(n)) - netFee = netFee.Add(opcodePrice(opcode.PUSHNULL)).Add(util.Fixed8(int64(ecdsaVerifyInteropPrice) * int64(n))) + netFee += calculateMultisigFee(m) + calculateMultisigFee(n) + netFee += opcodePrice(opcode.PUSHNULL) + ecdsaVerifyInteropPrice*int64(n) } else { // We can support more contract types in the future. } return netFee, size } -func calculateMultisigFee(n int) util.Fixed8 { - result := util.Fixed8(int64(opcodePrice(opcode.PUSHDATA1)) * int64(n)) +func calculateMultisigFee(n int) int64 { + result := opcodePrice(opcode.PUSHDATA1) * int64(n) bw := io.NewBufBinWriter() emit.Int(bw.BinWriter, int64(n)) // it's a hack because prices of small PUSH* opcodes are equal - result = result.Add(opcodePrice(opcode.Opcode(bw.Bytes()[0]))) + result += opcodePrice(opcode.Opcode(bw.Bytes()[0])) return result } diff --git a/pkg/network/helper_test.go b/pkg/network/helper_test.go index e09ae2727..e63664b51 100644 --- a/pkg/network/helper_test.go +++ b/pkg/network/helper_test.go @@ -35,7 +35,7 @@ func (chain testChain) CalculateClaimable(int64, uint32, uint32) util.Fixed8 { panic("TODO") } -func (chain testChain) FeePerByte() util.Fixed8 { +func (chain testChain) FeePerByte() int64 { panic("TODO") } @@ -123,11 +123,11 @@ func (chain testChain) GetMemPool() *mempool.Pool { panic("TODO") } -func (chain testChain) GetGoverningTokenBalance(acc util.Uint160) (util.Fixed8, uint32) { +func (chain testChain) GetGoverningTokenBalance(acc util.Uint160) (int64, uint32) { panic("TODO") } -func (chain testChain) GetUtilityTokenBalance(uint160 util.Uint160) util.Fixed8 { +func (chain testChain) GetUtilityTokenBalance(uint160 util.Uint160) int64 { panic("TODO") } diff --git a/pkg/rpc/client/nep5.go b/pkg/rpc/client/nep5.go index 15be912af..651d4e12d 100644 --- a/pkg/rpc/client/nep5.go +++ b/pkg/rpc/client/nep5.go @@ -104,7 +104,7 @@ func (c *Client) NEP5TokenInfo(tokenHash util.Uint160) (*wallet.Token, error) { // method of a given contract (token) to move specified amount of NEP5 assets // (in FixedN format using contract's number of decimals) to given account and // returns it. The returned transaction is not signed. -func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas util.Fixed8) (*transaction.Transaction, error) { +func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas int64) (*transaction.Transaction, error) { from, err := address.StringToUint160(acc.Address) if err != nil { return nil, fmt.Errorf("bad account address: %v", err) @@ -136,12 +136,8 @@ func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, toke if err != nil { return nil, fmt.Errorf("can't add system fee to transaction: %v", err) } - gasConsumed, err := util.Fixed8FromString(result.GasConsumed) - if err != nil { - return nil, fmt.Errorf("can't add system fee to transaction: %v", err) - } - if gasConsumed > 0 { - tx.SystemFee = gasConsumed + if result.GasConsumed > 0 { + tx.SystemFee = result.GasConsumed } tx.ValidUntilBlock, err = c.CalculateValidUntilBlock() @@ -161,7 +157,7 @@ func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, toke // on a given token to move specified amount of NEP5 assets (in FixedN format // using contract's number of decimals) to given account and sends it to the // network returning just a hash of it. -func (c *Client) TransferNEP5(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas util.Fixed8) (util.Uint256, error) { +func (c *Client) TransferNEP5(acc *wallet.Account, to util.Uint160, token util.Uint160, amount int64, gas int64) (util.Uint256, error) { tx, err := c.CreateNEP5TransferTx(acc, to, token, amount, gas) if err != nil { return util.Uint256{}, err diff --git a/pkg/rpc/client/rpc.go b/pkg/rpc/client/rpc.go index d8c3874f7..dd342e6e5 100644 --- a/pkg/rpc/client/rpc.go +++ b/pkg/rpc/client/rpc.go @@ -427,7 +427,7 @@ func (c *Client) SubmitBlock(b block.Block) error { // SignAndPushInvocationTx signs and pushes given script as an invocation // transaction using given wif to sign it and spending the amount of gas // specified. It returns a hash of the invocation transaction and an error. -func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee util.Fixed8, netfee util.Fixed8) (util.Uint256, error) { +func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sysfee int64, netfee util.Fixed8) (util.Uint256, error) { var txHash util.Uint256 var err error @@ -537,6 +537,6 @@ func (c *Client) AddNetworkFee(tx *transaction.Transaction, acc *wallet.Account) if err != nil { return err } - tx.NetworkFee += util.Fixed8(int64(size) * fee) + tx.NetworkFee += int64(size) * fee return nil } diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index 8995948de..d2d9c0693 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -41,13 +41,13 @@ const hexB1 = "000000008aaab19c43c4ca2870c3e616b123f1b689866f44b138ae4d6a5352e54 const hexTxMoveNeo = "0002000000abec5362f11e75b6e02e407bb98d63675d14384100000000000000003e5f0d0000000000b00400000001abec5362f11e75b6e02e407bb98d63675d14384101590218ddf5050c14316e851039019d39dfc2c37d6c3fee19fd5809870c14abec5362f11e75b6e02e407bb98d63675d14384113c00c087472616e736665720c14897720d8cd76f4f00abfa37c0edd889c208fde9b41627d5b523801fd08010c40ae6fc04fe4b6c22218ca9617c98d607d9ec9b1faf8cfdc3391bec485ae76b11adc6cc6abeb31a50b536ea8073e674d62a5566fce5e0a0ceb0718cb971c1ae3d00c40603071b725a58d052cad7afd88e99b27baab931afd5bb50d16e224335aab450170aabe251d3c0c6ad3f31dd7e9b89b209baabe5a1e2fa588bd8118f9e2a6960f0c40d72afcf39e663dba2d70fb8c36a09d1a6a6ad0d2fd38c857a8e7dc71e2b98711324e0d2ec641fe6896ba63ba80d3ea341c1aad11e082fb188ee07e215b4031b10c409afb2808b60286a56343b7ffcef28bb2ab0c595603e7323b5e5b0b9c1c10edfa5c40754d921865cb6fd71668a206b37a1eb10c0029a9fcd3a856aed07742cd3f94130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b413073b3bb" -const b1Verbose = `{"id":5,"jsonrpc":"2.0","result":{"size":1681,"nextblockhash":"0x45f62d72e37b074ecdc9f687222b0f91ec98d6d9af4429a2caa2e076a9196b0d","confirmations":6,"hash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","version":0,"previousblockhash":"0x56fd4244e552536a4dae38b1446f8689b6f123b116e6c37028cac4439cb1aa8a","merkleroot":"0xf9dce467385206ad220a8b85d238f77239766eaffffed19955e3e47d24071140","time":1592472500001,"index":1,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEAPAetjcaE1Un3bIFoNrh9p0tMkg3zOEovq2QMwkYg/nOIebXWaQPaQdGWSsCHTl/CI47e0F/zvc80b/cKAB2lSDECE965dn1igmqVu6y8oJ0SlmoLRfjvg6xx/VObo33liDiYIGRusVygKg22y7Cp3bQfkPxa8dsR9NIsPzQnVbHwyDEArlbTjnsNRYqZAeV/yI+kt7JU5CgcutFf2pDIwUvgHMVF+DfAp5KRXIE93f1JhxqSojUbUw6vexjWm7tWA1sd/DEC5c1dFsd15WiWMMdjm+ofVz8Lps6SJDWENM7z4M7ZMWLDFzqF/OnEo8QZe0ZPmNpcVkPGT8ovdHu67vB/m587l","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"consensus_data":{"primary":0,"nonce":"0000000000000457"},"tx":[{"hash":"0x7fb05b593cf4b1eb2d9a283c5488ca1bfe61191b5775bafa43b8647e7b20f22c","size":575,"version":0,"nonce":2,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"0.0087635","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"Ahjd9QUMFDFuhRA5AZ0538LDfWw/7hn9WAmHDBSr7FNi8R51tuAuQHu5jWNnXRQ4QRPADAh0cmFuc2ZlcgwUiXcg2M129PAKv6N8Dt2InCCP3ptBYn1bUjg=","scripts":[{"invocation":"DECub8BP5LbCIhjKlhfJjWB9nsmx+vjP3DORvsSFrnaxGtxsxqvrMaULU26oBz5nTWKlVm/OXgoM6wcYy5ccGuPQDEBgMHG3JaWNBSytev2I6ZsnuquTGv1btQ0W4iQzWqtFAXCqviUdPAxq0/Md1+m4myCbqr5aHi+liL2BGPnippYPDEDXKvzznmY9ui1w+4w2oJ0aamrQ0v04yFeo59xx4rmHETJODS7GQf5olrpjuoDT6jQcGq0R4IL7GI7gfiFbQDGxDECa+ygItgKGpWNDt//O8ouyqwxZVgPnMjteWwucHBDt+lxAdU2SGGXLb9cWaKIGs3oesQwAKan806hWrtB3Qs0/","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]},{"hash":"0xb661d5e4d9e41c3059b068f8abb6f1566a47ec800879e34c0ebd2799781a2760","size":579,"version":0,"nonce":3,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"0.0088035","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"AwDodkgXAAAADBQxboUQOQGdOd/Cw31sP+4Z/VgJhwwUq+xTYvEedbbgLkB7uY1jZ10UOEETwAwIdHJhbnNmZXIMFDt9NxHG8Mz5sdypA9G/odiW8SOMQWJ9W1I4","scripts":[{"invocation":"DECHEOe12Kxs2NCdb7Nb8tzOX1+zhZXdttBKVwvJJbwsVac83188taH+sKzE8myLvKbEPfO0qYuMPCyAnC8JbrJaDEDBhsECy/cjE/2U31B3/Fu+/NMiJ+0hWaR6RllId/o58zDYIjtFqiSv8AW+u1skJ6UMjE3oYY59ewDXPYNsRJQuDECiQ7W1Zb1LwvC7ES92JPazUUwSQTxalSMIGfrOP3YPA/y5axiPmAOKPyUWhrU6iNaXRPTkqYXmKXADqAzbFp6ADEBKlR5hrJnV7jGDHREXVK23EbSpBgqVJP44OpB3GEPNsJY4JnQCeofyoVqDvXfesrKrH+iz3m5UYpPvPfmxEp4o","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]}]}}` +const b1Verbose = `{"id":5,"jsonrpc":"2.0","result":{"size":1681,"nextblockhash":"0x45f62d72e37b074ecdc9f687222b0f91ec98d6d9af4429a2caa2e076a9196b0d","confirmations":6,"hash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","version":0,"previousblockhash":"0x56fd4244e552536a4dae38b1446f8689b6f123b116e6c37028cac4439cb1aa8a","merkleroot":"0xf9dce467385206ad220a8b85d238f77239766eaffffed19955e3e47d24071140","time":1592472500001,"index":1,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEAPAetjcaE1Un3bIFoNrh9p0tMkg3zOEovq2QMwkYg/nOIebXWaQPaQdGWSsCHTl/CI47e0F/zvc80b/cKAB2lSDECE965dn1igmqVu6y8oJ0SlmoLRfjvg6xx/VObo33liDiYIGRusVygKg22y7Cp3bQfkPxa8dsR9NIsPzQnVbHwyDEArlbTjnsNRYqZAeV/yI+kt7JU5CgcutFf2pDIwUvgHMVF+DfAp5KRXIE93f1JhxqSojUbUw6vexjWm7tWA1sd/DEC5c1dFsd15WiWMMdjm+ofVz8Lps6SJDWENM7z4M7ZMWLDFzqF/OnEo8QZe0ZPmNpcVkPGT8ovdHu67vB/m587l","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"consensus_data":{"primary":0,"nonce":"0000000000000457"},"tx":[{"hash":"0x7fb05b593cf4b1eb2d9a283c5488ca1bfe61191b5775bafa43b8647e7b20f22c","size":575,"version":0,"nonce":2,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"876350","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"Ahjd9QUMFDFuhRA5AZ0538LDfWw/7hn9WAmHDBSr7FNi8R51tuAuQHu5jWNnXRQ4QRPADAh0cmFuc2ZlcgwUiXcg2M129PAKv6N8Dt2InCCP3ptBYn1bUjg=","scripts":[{"invocation":"DECub8BP5LbCIhjKlhfJjWB9nsmx+vjP3DORvsSFrnaxGtxsxqvrMaULU26oBz5nTWKlVm/OXgoM6wcYy5ccGuPQDEBgMHG3JaWNBSytev2I6ZsnuquTGv1btQ0W4iQzWqtFAXCqviUdPAxq0/Md1+m4myCbqr5aHi+liL2BGPnippYPDEDXKvzznmY9ui1w+4w2oJ0aamrQ0v04yFeo59xx4rmHETJODS7GQf5olrpjuoDT6jQcGq0R4IL7GI7gfiFbQDGxDECa+ygItgKGpWNDt//O8ouyqwxZVgPnMjteWwucHBDt+lxAdU2SGGXLb9cWaKIGs3oesQwAKan806hWrtB3Qs0/","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]},{"hash":"0xb661d5e4d9e41c3059b068f8abb6f1566a47ec800879e34c0ebd2799781a2760","size":579,"version":0,"nonce":3,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"880350","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"AwDodkgXAAAADBQxboUQOQGdOd/Cw31sP+4Z/VgJhwwUq+xTYvEedbbgLkB7uY1jZ10UOEETwAwIdHJhbnNmZXIMFDt9NxHG8Mz5sdypA9G/odiW8SOMQWJ9W1I4","scripts":[{"invocation":"DECHEOe12Kxs2NCdb7Nb8tzOX1+zhZXdttBKVwvJJbwsVac83188taH+sKzE8myLvKbEPfO0qYuMPCyAnC8JbrJaDEDBhsECy/cjE/2U31B3/Fu+/NMiJ+0hWaR6RllId/o58zDYIjtFqiSv8AW+u1skJ6UMjE3oYY59ewDXPYNsRJQuDECiQ7W1Zb1LwvC7ES92JPazUUwSQTxalSMIGfrOP3YPA/y5axiPmAOKPyUWhrU6iNaXRPTkqYXmKXADqAzbFp6ADEBKlR5hrJnV7jGDHREXVK23EbSpBgqVJP44OpB3GEPNsJY4JnQCeofyoVqDvXfesrKrH+iz3m5UYpPvPfmxEp4o","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]}]}}` const hexHeader1 = "000000008aaab19c43c4ca2870c3e616b123f1b689866f44b138ae4d6a5352e54442fd56401107247de4e35599d1feffaf6e763972f738d2858b0a22ad06523867e4dcf921f7c1c67201000001000000abec5362f11e75b6e02e407bb98d63675d14384101fd08010c400f01eb6371a135527ddb205a0dae1f69d2d324837cce128bead9033091883f9ce21e6d759a40f690746592b021d397f088e3b7b417fcef73cd1bfdc2800769520c4084f7ae5d9f58a09aa56eeb2f282744a59a82d17e3be0eb1c7f54e6e8df79620e2608191bac57280a836db2ec2a776d07e43f16bc76c47d348b0fcd09d56c7c320c402b95b4e39ec35162a640795ff223e92dec95390a072eb457f6a4323052f80731517e0df029e4a457204f777f5261c6a4a88d46d4c3abdec635a6eed580d6c77f0c40b9735745b1dd795a258c31d8e6fa87d5cfc2e9b3a4890d610d33bcf833b64c58b0c5cea17f3a7128f1065ed193e636971590f193f28bdd1eeebbbc1fe6e7cee594130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b413073b3bb00" const header1Verbose = `{"id":5,"jsonrpc":"2.0","result":{"hash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","size":518,"version":0,"previousblockhash":"0x56fd4244e552536a4dae38b1446f8689b6f123b116e6c37028cac4439cb1aa8a","merkleroot":"0xf9dce467385206ad220a8b85d238f77239766eaffffed19955e3e47d24071140","time":1592472500001,"index":1,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEAPAetjcaE1Un3bIFoNrh9p0tMkg3zOEovq2QMwkYg/nOIebXWaQPaQdGWSsCHTl/CI47e0F/zvc80b/cKAB2lSDECE965dn1igmqVu6y8oJ0SlmoLRfjvg6xx/VObo33liDiYIGRusVygKg22y7Cp3bQfkPxa8dsR9NIsPzQnVbHwyDEArlbTjnsNRYqZAeV/yI+kt7JU5CgcutFf2pDIwUvgHMVF+DfAp5KRXIE93f1JhxqSojUbUw6vexjWm7tWA1sd/DEC5c1dFsd15WiWMMdjm+ofVz8Lps6SJDWENM7z4M7ZMWLDFzqF/OnEo8QZe0ZPmNpcVkPGT8ovdHu67vB/m587l","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"confirmations":6,"nextblockhash":"0x45f62d72e37b074ecdc9f687222b0f91ec98d6d9af4429a2caa2e076a9196b0d"}}` -const txMoveNeoVerbose = `{"id":5,"jsonrpc":"2.0","result":{"blockhash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","confirmations":6,"blocktime":1592472500001,"hash":"0x7fb05b593cf4b1eb2d9a283c5488ca1bfe61191b5775bafa43b8647e7b20f22c","size":575,"version":0,"nonce":2,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"0.0087635","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"Ahjd9QUMFDFuhRA5AZ0538LDfWw/7hn9WAmHDBSr7FNi8R51tuAuQHu5jWNnXRQ4QRPADAh0cmFuc2ZlcgwUiXcg2M129PAKv6N8Dt2InCCP3ptBYn1bUjg=","scripts":[{"invocation":"DECub8BP5LbCIhjKlhfJjWB9nsmx+vjP3DORvsSFrnaxGtxsxqvrMaULU26oBz5nTWKlVm/OXgoM6wcYy5ccGuPQDEBgMHG3JaWNBSytev2I6ZsnuquTGv1btQ0W4iQzWqtFAXCqviUdPAxq0/Md1+m4myCbqr5aHi+liL2BGPnippYPDEDXKvzznmY9ui1w+4w2oJ0aamrQ0v04yFeo59xx4rmHETJODS7GQf5olrpjuoDT6jQcGq0R4IL7GI7gfiFbQDGxDECa+ygItgKGpWNDt//O8ouyqwxZVgPnMjteWwucHBDt+lxAdU2SGGXLb9cWaKIGs3oesQwAKan806hWrtB3Qs0/","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]}}` +const txMoveNeoVerbose = `{"id":5,"jsonrpc":"2.0","result":{"blockhash":"0x4f2c5539b0213ea444608cc217c5cb191255c1858ccd051ad9a36f08df26a288","confirmations":6,"blocktime":1592472500001,"hash":"0x7fb05b593cf4b1eb2d9a283c5488ca1bfe61191b5775bafa43b8647e7b20f22c","size":575,"version":0,"nonce":2,"sender":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","sys_fee":"0","net_fee":"876350","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x4138145d67638db97b402ee0b6751ef16253ecab","scopes":"CalledByEntry"}],"script":"Ahjd9QUMFDFuhRA5AZ0538LDfWw/7hn9WAmHDBSr7FNi8R51tuAuQHu5jWNnXRQ4QRPADAh0cmFuc2ZlcgwUiXcg2M129PAKv6N8Dt2InCCP3ptBYn1bUjg=","scripts":[{"invocation":"DECub8BP5LbCIhjKlhfJjWB9nsmx+vjP3DORvsSFrnaxGtxsxqvrMaULU26oBz5nTWKlVm/OXgoM6wcYy5ccGuPQDEBgMHG3JaWNBSytev2I6ZsnuquTGv1btQ0W4iQzWqtFAXCqviUdPAxq0/Md1+m4myCbqr5aHi+liL2BGPnippYPDEDXKvzznmY9ui1w+4w2oJ0aamrQ0v04yFeo59xx4rmHETJODS7GQf5olrpjuoDT6jQcGq0R4IL7GI7gfiFbQDGxDECa+ygItgKGpWNDt//O8ouyqwxZVgPnMjteWwucHBDt+lxAdU2SGGXLb9cWaKIGs3oesQwAKan806hWrtB3Qs0/","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}]}}` // getResultBlock1 returns data for block number 1 which is used by several tests. func getResultBlock1() *result.Block { @@ -114,7 +114,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ TxHash: txHash, Trigger: "Application", VMState: "HALT", - GasConsumed: "1", + GasConsumed: 1, Stack: []smartcontract.Parameter{{Type: smartcontract.IntegerType, Value: int64(1)}}, Events: []result.NotificationEvent{}, } @@ -325,7 +325,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetFeePerByte() }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"0.0200739","script":"10c00c0d676574466565506572427974650c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"1000"}]}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"2007390","script":"10c00c0d676574466565506572427974650c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"1000"}]}}`, result: func(c *Client) interface{} { return int64(1000) }, @@ -337,7 +337,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetMaxTransactionsPerBlock() }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"0.0200739","script":"10c00c1a6765744d61785472616e73616374696f6e73506572426c6f636b0c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"512"}]}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"2007390","script":"10c00c1a6765744d61785472616e73616374696f6e73506572426c6f636b0c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"512"}]}}`, result: func(c *Client) interface{} { return int64(512) }, @@ -349,7 +349,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetMaxBlockSize() }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"0.0200739","script":"10c00c0f6765744d6178426c6f636b53697a650c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"262144"}]}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"2007390","script":"10c00c0f6765744d6178426c6f636b53697a650c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Integer","value":"262144"}]}}`, result: func(c *Client) interface{} { return int64(262144) }, @@ -361,7 +361,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetBlockedAccounts() }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"0.0200739","script":"10c00c12676574426c6f636b65644163636f756e74730c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Array","value":[]}]}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gas_consumed":"2007390","script":"10c00c12676574426c6f636b65644163636f756e74730c149a61a46eec97b89306d7ce81f15b462091d0093241627d5b52","stack":[{"type":"Array","value":[]}]}}`, result: func(c *Client) interface{} { return native.BlockedAccounts{} }, @@ -625,7 +625,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ Account: util.Uint160{1, 2, 3}, }}) }, - serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"1426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf","state":"HALT","gas_consumed":"0.311","stack":[{"type":"ByteArray","value":"JivsCEQy"}],"tx":"d101361426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf000000000000000000000000"}}`, + serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"1426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf","state":"HALT","gas_consumed":"31100000","stack":[{"type":"ByteArray","value":"JivsCEQy"}],"tx":"d101361426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf000000000000000000000000"}}`, result: func(c *Client) interface{} { bytes, err := hex.DecodeString("262bec084432") if err != nil { @@ -633,7 +633,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ } return &result.Invoke{ State: "HALT", - GasConsumed: "0.311", + GasConsumed: 31100000, Script: "1426ae7c6c9861ec418468c1f0fdc4a7f2963eb89151c10962616c616e63654f6667be39e7b562f60cbfe2aebca375a2e5ee28737caf", Stack: []smartcontract.Parameter{ { @@ -653,7 +653,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ Account: util.Uint160{1, 2, 3}, }}) }, - serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"00046e616d656724058e5e1b6008847cd662728549088a9ee82191","state":"HALT","gas_consumed":"0.161","stack":[{"type":"ByteArray","value":"TkVQNSBHQVM="}],"tx":"d1011b00046e616d656724058e5e1b6008847cd662728549088a9ee82191000000000000000000000000"}}`, + serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"script":"00046e616d656724058e5e1b6008847cd662728549088a9ee82191","state":"HALT","gas_consumed":"16100000","stack":[{"type":"ByteArray","value":"TkVQNSBHQVM="}],"tx":"d1011b00046e616d656724058e5e1b6008847cd662728549088a9ee82191000000000000000000000000"}}`, result: func(c *Client) interface{} { bytes, err := hex.DecodeString("4e45503520474153") if err != nil { @@ -661,7 +661,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ } return &result.Invoke{ State: "HALT", - GasConsumed: "0.161", + GasConsumed: 16100000, Script: "00046e616d656724058e5e1b6008847cd662728549088a9ee82191", Stack: []smartcontract.Parameter{ { diff --git a/pkg/rpc/client/wsclient_test.go b/pkg/rpc/client/wsclient_test.go index 09e331d8e..ad31eadf1 100644 --- a/pkg/rpc/client/wsclient_test.go +++ b/pkg/rpc/client/wsclient_test.go @@ -116,10 +116,10 @@ func TestWSClientEvents(t *testing.T) { var ok bool // Events from RPC server test chain. var events = []string{ - `{"jsonrpc":"2.0","method":"transaction_executed","params":[{"txid":"0xe1cd5e57e721d2a2e05fb1f08721b12057b25ab1dd7fd0f33ee1639932fdfad7","trigger":"Application","vmstate":"HALT","gas_consumed":"2.291","stack":[],"notifications":[{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}]}},{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}}]}]}`, + `{"jsonrpc":"2.0","method":"transaction_executed","params":[{"txid":"0xe1cd5e57e721d2a2e05fb1f08721b12057b25ab1dd7fd0f33ee1639932fdfad7","trigger":"Application","vmstate":"HALT","gas_consumed":"22910000","stack":[],"notifications":[{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}]}},{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}}]}]}`, `{"jsonrpc":"2.0","method":"notification_from_execution","params":[{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}]}}]}`, - `{"jsonrpc":"2.0","method":"transaction_executed","params":[{"txid":"0xf97a72b7722c109f909a8bc16c22368c5023d85828b09b127b237aace33cf099","trigger":"Application","vmstate":"HALT","gas_consumed":"0.0604261","stack":[],"notifications":[{"contract":"0xe65ff7b3a02d207b584a5c27057d4e9862ef01da","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"ByteArray","value":"IHKCdK+vw29DoHHTKM+j5inZy7A="},{"type":"Integer","value":"123"}]}]}},{"contract":"0xe65ff7b3a02d207b584a5c27057d4e9862ef01da","state":{"type":"Array","value":[{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"ByteArray","value":"IHKCdK+vw29DoHHTKM+j5inZy7A="},{"type":"Integer","value":"123"}]}}]}]}`, - `{"jsonrpc":"2.0","method":"block_added","params":[{"hash":"0x2d312f6379ead13cf62634c703091b750e7903728df2a3cf5bd96ce80b84a849","version":0,"previousblockhash":"0xb8237d34c156cac6be7b01578decf8ac8c99a62f0b6f774d622aad7be0fe189d","merkleroot":"0xf89169e89361692b71e671f13c088e84c5325015c413e8f89e7ba38efdb41287","time":1592472500006,"index":6,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEDblVguNGXWbUswDvBfVJzBt76BJyJ0Ga6siquyjioGn4Dbr6zy1IvcLl3xN5akcejRy9e+Mr1qvpe/gkLgtW4QDEDRwPISZagMFjE/plXTnZ/gEU0IbBAAe23U29zVWteUmzRsPxF/MdzXvdffR9W0edkj17AmkWpn+5rqzH9aCOpLDECEvjgxZaRoAHEDNzp1REllLcGzMwrwSjudtzfgRglQL3g1BKerDx6cGHH73medRVkL9QVm4KzSxlywVtvhwBMrDEBuPKvzg5TtakFW2jr/bfmy1bn2FiLARlOySwaGdKRV93ozA5lVEIAvHbBlJtT4/5H8jHjbncXXMrP3OUHqebZz","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"consensus_data":{"primary":0,"nonce":"0000000000000457"},"tx":[{"hash":"0xf97a72b7722c109f909a8bc16c22368c5023d85828b09b127b237aace33cf099","size":265,"version":0,"nonce":9,"sender":"NQRLhCpAru9BjGsMwk67vdMwmzKMRgsnnN","sys_fee":"0","net_fee":"0.0036521","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x870958fd19ee3f6c7dc3c2df399d013910856e31","scopes":"CalledByEntry"}],"script":"AHsMFCBygnSvr8NvQ6Bx0yjPo+Yp2cuwDBQxboUQOQGdOd/Cw31sP+4Z/VgJhxPADAh0cmFuc2ZlcgwU2gHvYphOfQUnXEpYeyAtoLP3X+ZBYn1bUjg=","scripts":[{"invocation":"DECwklSj3liZOJbktRtkVdUCu8U2LQlrU6Dv8NtMgd0xXbk5lXjc2p68xv6xtJXbJ4aoFMJZ9lkcNpGoeUCcaCet","verification":"DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQQqQatQ="}]}]}]}`, + `{"jsonrpc":"2.0","method":"transaction_executed","params":[{"txid":"0xf97a72b7722c109f909a8bc16c22368c5023d85828b09b127b237aace33cf099","trigger":"Application","vmstate":"HALT","gas_consumed":"6042610","stack":[],"notifications":[{"contract":"0xe65ff7b3a02d207b584a5c27057d4e9862ef01da","state":{"type":"Array","value":[{"type":"ByteArray","value":"Y29udHJhY3QgY2FsbA=="},{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"ByteArray","value":"IHKCdK+vw29DoHHTKM+j5inZy7A="},{"type":"Integer","value":"123"}]}]}},{"contract":"0xe65ff7b3a02d207b584a5c27057d4e9862ef01da","state":{"type":"Array","value":[{"type":"ByteArray","value":"dHJhbnNmZXI="},{"type":"ByteArray","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"ByteArray","value":"IHKCdK+vw29DoHHTKM+j5inZy7A="},{"type":"Integer","value":"123"}]}}]}]}`, + `{"jsonrpc":"2.0","method":"block_added","params":[{"hash":"0x2d312f6379ead13cf62634c703091b750e7903728df2a3cf5bd96ce80b84a849","version":0,"previousblockhash":"0xb8237d34c156cac6be7b01578decf8ac8c99a62f0b6f774d622aad7be0fe189d","merkleroot":"0xf89169e89361692b71e671f13c088e84c5325015c413e8f89e7ba38efdb41287","time":1592472500006,"index":6,"nextconsensus":"Nbb1qkwcwNSBs9pAnrVVrnFbWnbWBk91U2","witnesses":[{"invocation":"DEDblVguNGXWbUswDvBfVJzBt76BJyJ0Ga6siquyjioGn4Dbr6zy1IvcLl3xN5akcejRy9e+Mr1qvpe/gkLgtW4QDEDRwPISZagMFjE/plXTnZ/gEU0IbBAAe23U29zVWteUmzRsPxF/MdzXvdffR9W0edkj17AmkWpn+5rqzH9aCOpLDECEvjgxZaRoAHEDNzp1REllLcGzMwrwSjudtzfgRglQL3g1BKerDx6cGHH73medRVkL9QVm4KzSxlywVtvhwBMrDEBuPKvzg5TtakFW2jr/bfmy1bn2FiLARlOySwaGdKRV93ozA5lVEIAvHbBlJtT4/5H8jHjbncXXMrP3OUHqebZz","verification":"EwwhAhA6f33QFlWFl/eWDSfFFqQ5T9loueZRVetLAT5AQEBuDCECp7xV/oaE4BGXaNEEujB5W9zIZhnoZK3SYVZyPtGFzWIMIQKzYiv0AXvf4xfFiu1fTHU/IGt9uJYEb6fXdLvEv3+NwgwhA9kMB99j5pDOd5EuEKtRrMlEtmhgI3tgjE+PgwnnHuaZFAtBMHOzuw=="}],"consensus_data":{"primary":0,"nonce":"0000000000000457"},"tx":[{"hash":"0xf97a72b7722c109f909a8bc16c22368c5023d85828b09b127b237aace33cf099","size":265,"version":0,"nonce":9,"sender":"NQRLhCpAru9BjGsMwk67vdMwmzKMRgsnnN","sys_fee":"0","net_fee":"365210","valid_until_block":1200,"attributes":[],"cosigners":[{"account":"0x870958fd19ee3f6c7dc3c2df399d013910856e31","scopes":"CalledByEntry"}],"script":"AHsMFCBygnSvr8NvQ6Bx0yjPo+Yp2cuwDBQxboUQOQGdOd/Cw31sP+4Z/VgJhxPADAh0cmFuc2ZlcgwU2gHvYphOfQUnXEpYeyAtoLP3X+ZBYn1bUjg=","scripts":[{"invocation":"DECwklSj3liZOJbktRtkVdUCu8U2LQlrU6Dv8NtMgd0xXbk5lXjc2p68xv6xtJXbJ4aoFMJZ9lkcNpGoeUCcaCet","verification":"DCECs2Ir9AF73+MXxYrtX0x1PyBrfbiWBG+n13S7xL9/jcILQQqQatQ="}]}]}]}`, `{"jsonrpc":"2.0","method":"event_missed","params":[]}`, } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { diff --git a/pkg/rpc/request/txBuilder.go b/pkg/rpc/request/txBuilder.go index a28f94d4b..953ef7287 100644 --- a/pkg/rpc/request/txBuilder.go +++ b/pkg/rpc/request/txBuilder.go @@ -17,7 +17,7 @@ import ( // CreateDeploymentScript returns a script that deploys given smart contract // with its metadata and system fee require for this. -func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, util.Fixed8, error) { +func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, int64, error) { script := io.NewBufBinWriter() rawManifest, err := manif.MarshalJSON() if err != nil { @@ -26,7 +26,7 @@ func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, util. emit.Bytes(script.BinWriter, rawManifest) emit.Bytes(script.BinWriter, avm) emit.Syscall(script.BinWriter, "System.Contract.Create") - sysfee := util.Fixed8(core.StoragePrice * (len(avm) + len(rawManifest))) + sysfee := int64(core.StoragePrice * (len(avm) + len(rawManifest))) return script.Bytes(), sysfee, nil } diff --git a/pkg/rpc/response/result/application_log.go b/pkg/rpc/response/result/application_log.go index d08eac7f2..35c1b63f3 100644 --- a/pkg/rpc/response/result/application_log.go +++ b/pkg/rpc/response/result/application_log.go @@ -1,8 +1,6 @@ package result import ( - "strconv" - "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" @@ -15,7 +13,7 @@ type ApplicationLog struct { TxHash util.Uint256 `json:"txid"` Trigger string `json:"trigger"` VMState string `json:"vmstate"` - GasConsumed string `json:"gas_consumed"` + GasConsumed int64 `json:"gas_consumed,string"` Stack []smartcontract.Parameter `json:"stack"` Events []NotificationEvent `json:"notifications"` } @@ -48,7 +46,7 @@ func NewApplicationLog(appExecRes *state.AppExecResult) ApplicationLog { TxHash: appExecRes.TxHash, Trigger: appExecRes.Trigger.String(), VMState: appExecRes.VMState, - GasConsumed: strconv.FormatInt(int64(appExecRes.GasConsumed), 10), + GasConsumed: appExecRes.GasConsumed, Stack: appExecRes.Stack, Events: events, } diff --git a/pkg/rpc/response/result/invoke.go b/pkg/rpc/response/result/invoke.go index 35c7b5548..34531dbc2 100644 --- a/pkg/rpc/response/result/invoke.go +++ b/pkg/rpc/response/result/invoke.go @@ -8,7 +8,7 @@ import ( // that invoke functions, scripts and generic bytecode. type Invoke struct { State string `json:"state"` - GasConsumed string `json:"gas_consumed"` + GasConsumed int64 `json:"gas_consumed,string"` Script string `json:"script"` Stack []smartcontract.Parameter `json:"stack"` } diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 36c5e367b..8cb69d7b7 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -741,7 +741,7 @@ func (s *Server) getBlockSysFee(reqParams request.Params) (interface{}, *respons return 0, response.NewRPCError(errBlock.Error(), "", nil) } - var blockSysFee util.Fixed8 + var blockSysFee int64 for _, tx := range block.Transactions { blockSysFee += tx.SystemFee } @@ -786,8 +786,8 @@ func (s *Server) getUnclaimedGas(ps request.Params) (interface{}, *response.Erro if neo == 0 { return "0", nil } - gas := s.chain.CalculateClaimable(int64(neo), neoHeight, s.chain.BlockHeight()+1) // +1 as in C#, for the next block. - return strconv.FormatInt(int64(gas), 10), nil // It's not represented as Fixed8 in C#. + gas := s.chain.CalculateClaimable(neo, neoHeight, s.chain.BlockHeight()+1) // +1 as in C#, for the next block. + return strconv.FormatInt(int64(gas), 10), nil // It's not represented as Fixed8 in C#. } // getValidators returns the current NEO consensus nodes information and voting status. @@ -862,12 +862,12 @@ func (s *Server) invokescript(reqParams request.Params) (interface{}, *response. // result. func (s *Server) runScriptInVM(script []byte, tx *transaction.Transaction) *result.Invoke { vm := s.chain.GetTestVM(tx) - vm.GasLimit = s.config.MaxGasInvoke + vm.GasLimit = int64(s.config.MaxGasInvoke) vm.LoadScriptWithFlags(script, smartcontract.All) _ = vm.Run() result := &result.Invoke{ State: vm.State(), - GasConsumed: vm.GasConsumed().String(), + GasConsumed: vm.GasConsumed(), Script: hex.EncodeToString(script), Stack: vm.Estack().ToContractParameters(), } diff --git a/pkg/rpc/server/server_helper_test.go b/pkg/rpc/server/server_helper_test.go index 6d0258626..c36333f9d 100644 --- a/pkg/rpc/server/server_helper_test.go +++ b/pkg/rpc/server/server_helper_test.go @@ -10,6 +10,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core/block" + "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/network" @@ -85,10 +86,10 @@ func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, *Server, *http type FeerStub struct{} -func (fs *FeerStub) FeePerByte() util.Fixed8 { +func (fs *FeerStub) FeePerByte() int64 { return 0 } -func (fs *FeerStub) GetUtilityTokenBalance(acc util.Uint160) util.Fixed8 { - return util.Fixed8FromInt64(1000000) +func (fs *FeerStub) GetUtilityTokenBalance(acc util.Uint160) int64 { + return 1000000 * native.GASFactor } diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 80c727c0d..8ca736379 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -259,7 +259,7 @@ var rpcTestCases = map[string][]rpcTestCase{ // take burned gas into account u := testchain.PrivateKeyByID(0).GetScriptHash() for i := 0; i <= int(e.chain.BlockHeight()); i++ { - var netFee util.Fixed8 + var netFee int64 h := e.chain.GetHeaderHash(i) b, err := e.chain.GetBlock(h) require.NoError(t, err) @@ -453,7 +453,7 @@ var rpcTestCases = map[string][]rpcTestCase{ result: func(e *executor) interface{} { block, _ := e.chain.GetBlock(e.chain.GetHeaderHash(1)) - var expectedBlockSysFee util.Fixed8 + var expectedBlockSysFee int64 for _, tx := range block.Transactions { expectedBlockSysFee += tx.SystemFee } @@ -862,7 +862,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] netFee, sizeDelta := core.CalculateNetworkFee(acc0.Contract.Script) tx.NetworkFee += netFee size += sizeDelta - tx.NetworkFee = tx.NetworkFee.Add(util.Fixed8(int64(size) * int64(chain.FeePerByte()))) + tx.NetworkFee += int64(size) * chain.FeePerByte() } newTx := func() *transaction.Transaction { diff --git a/pkg/vm/interop.go b/pkg/vm/interop.go index 2cc188bc6..f24a1bcf4 100644 --- a/pkg/vm/interop.go +++ b/pkg/vm/interop.go @@ -17,7 +17,7 @@ type InteropFunc func(vm *VM) error // InteropFuncPrice represents an interop function with a price. type InteropFuncPrice struct { Func InteropFunc - Price int + Price int64 // AllowedTriggers is a mask representing triggers which should be allowed by an interop. // 0 is interpreted as All. AllowedTriggers trigger.Type diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 61cbc4004..ee3bfa163 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -64,7 +64,7 @@ type VM struct { getInterop []InteropGetterFunc // callback to get interop price - getPrice func(*VM, opcode.Opcode, []byte) util.Fixed8 + getPrice func(*VM, opcode.Opcode, []byte) int64 istack *Stack // invocation stack. estack *Stack // execution stack. @@ -77,8 +77,8 @@ type VM struct { refs *refCounter - gasConsumed util.Fixed8 - GasLimit util.Fixed8 + gasConsumed int64 + GasLimit int64 trigger trigger.Type @@ -125,17 +125,17 @@ func (v *VM) RegisterInteropGetter(f InteropGetterFunc) { // SetPriceGetter registers the given PriceGetterFunc in v. // f accepts vm's Context, current instruction and instruction parameter. -func (v *VM) SetPriceGetter(f func(*VM, opcode.Opcode, []byte) util.Fixed8) { +func (v *VM) SetPriceGetter(f func(*VM, opcode.Opcode, []byte) int64) { v.getPrice = f } // GasConsumed returns the amount of GAS consumed during execution. -func (v *VM) GasConsumed() util.Fixed8 { +func (v *VM) GasConsumed() int64 { return v.gasConsumed } // AddGas consumes specified amount of gas. It returns true iff gas limit wasn't exceeded. -func (v *VM) AddGas(gas util.Fixed8) bool { +func (v *VM) AddGas(gas int64) bool { v.gasConsumed += gas return v.GasLimit == 0 || v.gasConsumed <= v.GasLimit } diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index ca93b2bd7..35f3b33a8 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -14,7 +14,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" - "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" @@ -71,7 +70,7 @@ func TestVM_SetPriceGetter(t *testing.T) { require.EqualValues(t, 0, v.GasConsumed()) }) - v.SetPriceGetter(func(_ *VM, op opcode.Opcode, p []byte) util.Fixed8 { + v.SetPriceGetter(func(_ *VM, op opcode.Opcode, p []byte) int64 { if op == opcode.PUSH4 { return 1 } else if op == opcode.PUSHDATA1 && bytes.Equal(p, []byte{0xCA, 0xFE}) {