Commit graph

2697 commits

Author SHA1 Message Date
Evgenii Stratonikov
7b4ca57e33 *: change address to the new format
NEO3 uses new prefix for address (53 = 0x35), thus string representations as
well as encrypted WIFs should be changed.
2020-06-17 15:58:21 +03:00
Evgenii Stratonikov
651976b2ca config: remove AddressVersion from the configuration
It is never used and is the same constant for both mainnet, testnet and
privnet.
2020-06-17 15:55:22 +03:00
Evgenii Stratonikov
b3b1137030 cli: allow to convert wallet from NEO2 to NEO3 format
This command may be helpful to have during transition.
2020-06-17 15:49:34 +03:00
Evgenii Stratonikov
61cae8d8b1 compiler: implement missing System.Contract.* interops
Support System.Contract.IsStandard/CreateStandardAccount syscall.
2020-06-17 11:38:34 +03:00
Evgenii Stratonikov
3762ebdd08 core: implement System.Runtime.GetInvocationCounter syscall 2020-06-17 11:24:11 +03:00
Evgenii Stratonikov
75e597f880 core: implement System.Runtime.GetNotifications syscall 2020-06-17 11:24:11 +03:00
Evgenii Stratonikov
afd8f3b87a compiler: push Null item for nil values 2020-06-17 11:24:11 +03:00
Evgenii Stratonikov
a4e4439967 core,vm: implement System.Runtime.GasLeft syscall 2020-06-17 11:24:11 +03:00
Evgenii Stratonikov
a7d4fff897 vm: make (*VM).GasLimit public
VM is inherently single-threaded and replacing setter/getter methods
with public field simplifies code a bit.
2020-06-16 15:13:20 +03:00
Evgenii Stratonikov
1f97f3abd8 core: adjust prices and flags for System.Runtime.* interops
Related #1055.
2020-06-16 12:30:55 +03:00
Evgenii Stratonikov
ad2a75a500 core: move System.ExecutionEngine.* interops to System.Runtime.* 2020-06-16 12:30:55 +03:00
Evgenii Stratonikov
52a27e9be4 core: implement System.Contract.CreateStandardAccount syscall 2020-06-16 12:12:29 +03:00
Evgenii Stratonikov
5b4f38d717 core: implement System.Contract.IsStandard syscall 2020-06-16 12:12:27 +03:00
Evgenii Stratonikov
b1d2d70c02 core: adjust prices for blockchain/contract syscalls 2020-06-16 12:04:57 +03:00
Evgenii Stratonikov
becb8a0f72 compiler: support System.Json.* syscalls 2020-06-16 11:35:08 +03:00
Evgenii Stratonikov
6339efac11 core: implement System.Json.* interops 2020-06-16 11:35:06 +03:00
Evgenii Stratonikov
d836233352 stackitem: allow to (de-)serialize items to JSON
This commit implements behavior identical to that of C# `System.Json.*` interops.
2020-06-16 11:34:01 +03:00
Evgenii Stratonikov
f2f01a08c9 vm: move MaxArraySize and MaxItemSize to stackitem package 2020-06-16 11:32:16 +03:00
Evgenii Stratonikov
aae312d408 core,vm: adjust prices for iterator/enumerator syscalls
Closes #1027.
2020-06-16 11:05:26 +03:00
Evgenii Stratonikov
18066143bd core,vm: adjust binary (de-)serialization syscalls
Related #1027.

1. Move System.Runtime.(De)serialize to System.Binary.*
2. Rename compiler stubs.
3. Adjust opcode prices.
2020-06-16 11:00:38 +03:00
Roman Khimov
b3507d490d
Merge pull request #1051 from nspcc-dev/neo3/rpc/scopes
core: add json marshaller for Cosigner's scopes
2020-06-15 16:13:48 +03:00
Anna Shaleva
3568ab3d6d core: add json marshaller for Cosigner's scopes
Following C# implementation, we should marshal Scopes as a set of
strings instead of single byte.
2020-06-15 13:48:15 +03:00
Evgenii Stratonikov
2e996ea57d core: adjust System.Storage.* interop prices 2020-06-15 12:02:28 +03:00
Evgenii Stratonikov
61bba1a39c core: store precise gas price in interop descriptions
In NEO3 sycalls can have prices less than 10^5, we need to store them
precisely. Adjusting actual prices is to be done in the following tasks.
2020-06-15 12:02:28 +03:00
Evgenii Stratonikov
fd2cd291e7 core: calculate opcode prices correctly 2020-06-15 12:02:22 +03:00
Evgenii Stratonikov
8f20a70969 core: calculate a price of System.Storage.Put correctly
It also depends on the item already stored by key.
2020-06-15 12:02:21 +03:00
Roman Khimov
fe31c7ed2d
Merge pull request #1047 from nspcc-dev/neo3/rpc/invoke
rpc: update invoke* RPC-calls
2020-06-11 21:39:20 +03:00
Anna Shaleva
9e7fca013e rpc: update CLI and RPC client invoke* calls
part of #1036
2020-06-11 20:32:05 +03:00
Anna Shaleva
d5355acfa9 rpc: update RPC server invoke* calls
part of #1036
2020-06-11 19:34:13 +03:00
Evgenii Stratonikov
971ab0646f core: specify allowed triggers for interops
Related #1026, #1027, #1028, #1031.
2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
4dfce07d11 vm: provide trigger upon VM creation 2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
b12add5a78 smartcontract: rewrite trigger types for NEO3 2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
a3b876d55c native: specify call flags for native contract methods 2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
0dd00a49f5 core: specify require call flags in interop description
Related #1026, #1027, #1028, #1031.
2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
bda94c74c3 vm: check calling flags on syscall invocation 2020-06-11 13:16:07 +03:00
Evgenii Stratonikov
55ab7535be core: optimize contractCallEx
Provide script hash upon script load.
2020-06-11 13:06:10 +03:00
Evgenii Stratonikov
61edc8705e smartcontract: start flags with 1
`iota` keyword is equal to the index of the declaration in the
corresponding block, thus AllowStates was 2 in our case.
2020-06-11 13:03:55 +03:00
Evgenii Stratonikov
532262827d smartcontract: add CallFlag.Has() helper 2020-06-11 13:03:55 +03:00
Evgenii Stratonikov
ebbf0321b2 smartcontract: add AllowStates call flag 2020-06-11 13:03:55 +03:00
Evgenii Stratonikov
a86e1910e1 core: remove unused interops
Missed in #1040.
2020-06-11 10:51:19 +03:00
Evgenii Stratonikov
f8a11f61b6 core: update *.Contract.* interops
1. Remove GetScript, IsPayable, GetStorageContext.
2. Revert 82319538 related to GetStorageContext.
3. Rename Migrate to Update.
4. Move remaining to System.Contract.*.

Related #1031.
2020-06-11 10:50:35 +03:00
Evgenii Stratonikov
c69f8a2fa3 core: check for permission in System.Contract.Call(Ex) 2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
5514b3f52f smartcontract,vm: remove DynamicInvoke feature
It doesn't exist in NEO3.
2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
76a2f62fbd cli: use manifest during contract deployment 2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
a03af55732 core: provide monotonically increasing ID for contracts
ID is a contract identifier which doesn't change during migration.
It is also used as a part of storage context instead of contract hash.
2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
20616cc97f interop: perform contract checks in CheckWitness 2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
7256efd1ed vm: implement (*VM).AddGas
Calculating interop prices can be tricky. It is more convenitent to burn
gas inside interops where necessary parameters are popped.
2020-06-11 10:45:25 +03:00
Evgenii Stratonikov
df958caf93 core: add Manifest to state.Contract 2020-06-11 10:45:24 +03:00
Anna Shaleva
3549515fd7 rpc: fix typo in method description 2020-06-10 20:31:09 +03:00
Anna Shaleva
0af5b9339d rpc, cli: remove invoke RPC-call
part of #1036
2020-06-10 20:30:55 +03:00
Evgenii Stratonikov
425277098c native: set ContractID for NEO & GAS contracts 2020-06-10 14:23:25 +03:00
Evgenii Stratonikov
38d020d1a2 core: move Neo.Storage.* interops to System.* 2020-06-10 12:13:35 +03:00
Evgenii Stratonikov
0472a0b0b1 core: move Neo.Runtime/Enumerator/Iterator.* interops to System.* 2020-06-10 12:13:35 +03:00
Evgenii Stratonikov
97c6ac7a73 core: move Neo.Blockchain.* syscalls to System.* 2020-06-10 12:13:18 +03:00
Evgenii Stratonikov
3d3fe9398e core: remove Neo.Header/Witness/Account.* interops
They are not present in NEO3.
2020-06-10 12:13:18 +03:00
Roman Khimov
4264a758ac
Merge pull request #1039 from nspcc-dev/neo3/rpc/getversion
rpc: update `getversion` RPC-call
2020-06-10 11:08:45 +03:00
Anna Shaleva
3418e4f7f4 rpc: update getversion RPC-call
closes #1035
2020-06-10 10:47:11 +03:00
Anna Shaleva
8b7abd36c9 core: remove Block.GetTransactions, Block.GetTransactionsCount interops
Updated System.Blockchain.GetBlock interop replaced the functionality of
the following interops:
	System.Block.GetTransactions
	System.Block.GetTransactionCount
	Neo.Block.GetTransactions
	Neo.Block.GetTransactionsCount
2020-06-09 23:24:11 +03:00
Anna Shaleva
7a2d37cf7e core: update System.Blockchain.GetBlock interop
closes #1025

Now we put on stack stackitem.Array instead of Interop, so we're able to
use all available block properties without extra interop getters.
Removed Neo.Blockchain.GetBlock interop as we don't need it anymore.
2020-06-09 23:24:04 +03:00
Anna Shaleva
e2187c0a96 core: remove Block.GetTransaction interops
Removed Neo.Block.GetTransaction and System.Block.GetTransaction
interops. These interops were replaced by new
System.Blockchain.GetTransactionFromBlock interop.
2020-06-09 22:54:21 +03:00
Anna Shaleva
d692de5ea4 core: add System.Blockchain.GetTransactionFromBlock interop 2020-06-09 22:54:16 +03:00
Anna Shaleva
1e63ae4b3f core: update System.Blockchain.GetTransactionHeight interop
Update System.Blockchain.GetTransactionHeight and removed
Neo.Blockchain.GetTransactionHeight interop as we don't need it.
2020-06-09 22:04:18 +03:00
Anna Shaleva
53655c5ac2 core: implement new System.Blockchain.GetTransaction interop
closes #1023

Now we put on stack stackitem.Array instead of Interop, so we don't
need old transaction-related interops anymore. Removed the following
interops:
	System.Transaction.GetHash
	Neo.Transaction.GetAttributes
	Neo.Transaction.GetHash
	Neo.Transaction.GetWitnesses
	Neo.Attribute.GetData
	Neo.Attribute.GetUsage

Also removed the following duplicated NEO interop:
	Neo.Blockchain.GetTransaction
2020-06-09 22:04:13 +03:00
Anna Shaleva
f2e3be6fef core: remove old AntShares interops
We don't need them anymore.
2020-06-09 20:54:00 +03:00
Evgenii Stratonikov
ed45ff98e3 compiler: process interop together with package
Closes #913.
Provide package info in the funcScope to check if function is defined
insided an interop package. As a good side-effect bytecode for builtins from `util`
is no longer emitted.

Related #941.
2020-06-09 12:41:33 +03:00
Roman Khimov
795523f5cd
Merge pull request #1013 from nspcc-dev/neo3/vm/stackitem_refactoring
vm: move StackItem to a separate package
2020-06-08 15:30:44 +03:00
Anna Shaleva
4bf103ca12 core: update native contract data serialisation format
closes #908
2020-06-08 13:29:35 +03:00
Anna Shaleva
d0ccf456c4 vm: replace hardcoded Bool type constant with BooleanT type
There's no import cycle problem anymore, so we can do this. Part of #912
2020-06-08 13:27:13 +03:00
Anna Shaleva
7ca2807875 vm/encoding: move bigint from vm to encoding package 2020-06-08 13:27:13 +03:00
Anna Shaleva
783f5ecb01 vm: move StackItem to a separate package
closes #912
2020-06-08 13:27:08 +03:00
Evgenii Stratonikov
b28a8f2548 rpc: encode ContractState.Script in base64 2020-06-08 10:40:52 +03:00
Evgenii Stratonikov
138385e512 transaction: encode Script in base64 2020-06-08 10:31:51 +03:00
Evgenii Stratonikov
96c2cc0322 smartcontract: marshal ByteArray and Signature in base64 2020-06-08 10:27:39 +03:00
Evgenii Stratonikov
1fa25efa79 transaction: encode witness scripts in base64 2020-06-08 10:23:56 +03:00
Roman Khimov
3677358057 rpc/result: fix block confirmations counting
It should be the same as for headers and transactions.
2020-06-05 19:27:39 +03:00
Roman Khimov
63f4f34659 mempool: drop TxWithFee type
All the fees are in transaction, this makes no sense.
2020-06-05 19:21:40 +03:00
Roman Khimov
a986e2a064 *: drop support for old on-chain assets
You no longer can transfer them, so creating/renewing/storing doesn't make
much sense.
2020-06-05 19:21:37 +03:00
Roman Khimov
bf6435eeaa storage: drop STValidator prefix, it's not used 2020-06-05 19:20:16 +03:00
Roman Khimov
709146f295 transaction: drop Inputs and Outputs, forget UTXO 2020-06-05 19:20:16 +03:00
Roman Khimov
21efccd300 transaction: remove type field, set Version to 0
Two changes being done here, because they require a lot of updates to
tests. Now we're back into version 0 and we only have one type of
transaction.

It also removes GetType and GetScript interops, both are obsolete in Neo 3.
2020-06-05 19:20:16 +03:00
Roman Khimov
2ef9ec0756 rpc/server: allow specifying number for getblockheader
As it should be allowed.
2020-06-05 19:20:16 +03:00
Roman Khimov
dfb26f9ab2 block: don't attempt verification if there was a decoding error 2020-06-05 19:20:16 +03:00
Roman Khimov
f63b286c35 core: update genesis block to store timestamp in ms 2020-06-05 19:20:16 +03:00
Roman Khimov
35b30ccfdf core: drop OLDPUSH1, it's no longer needed
Fixes #927.
2020-06-05 19:20:16 +03:00
Roman Khimov
0a09a20900 transaction: drop Register transaction type
And everything associated like SystemFee configuration.
2020-06-05 19:20:16 +03:00
Roman Khimov
169c5ae775 transaction: drop Issue TX support 2020-06-05 19:20:16 +03:00
Roman Khimov
f445f7c602 transaction: drop Contract transaction type 2020-06-05 19:20:16 +03:00
Roman Khimov
6853470603 block: precompute ConsensusData hash on UnmarshalJSON
That's what we usually do for block or transaction hashes.
2020-06-05 19:20:16 +03:00
Roman Khimov
dfc7a9bfd1 transaction: drop Claim TX type 2020-06-05 19:20:16 +03:00
Roman Khimov
3d18f09def core: fix CalculateClaimable for NEP5 NEO
It's not stored as Fixed8, so calculations need to be adjusted for that.
2020-06-05 19:20:16 +03:00
Roman Khimov
39dfebccc4 core: no longer treat sysfee as claimable
As it's not on Neo 3, it just gets burned and that's it. Only network fee is
being redistributed to CNs.
2020-06-05 19:20:16 +03:00
Roman Khimov
50ed4c5967 core: don't return an error from CalculateClaimable
As it never returns one.
2020-06-05 19:20:16 +03:00
Roman Khimov
1bc6d29c0d core: fix potential NPE in GetUtilityTokenBalance 2020-06-05 19:20:16 +03:00
Roman Khimov
9f5fd21160 core: drop UXTO NEO and GAS transactions from the genesis block
They're no longer required. Adjust test chain for that, now it only has
invocations, transfers NEO/GAS and pays the fees with NEP5 GAS.
2020-06-05 19:20:16 +03:00
Roman Khimov
a9955719da native: make mint/burn for 0 no-ops
Prevent emitting useless transfer events and doing useless gets/puts.
2020-06-05 19:20:16 +03:00
Roman Khimov
fed95e0069 smartcontract: (un)marshal AnyType value as null
Neo 3 can emit Null in its transfer notifications in `from` or `to` fields
when minting/burning tokens (unlike Neo 2 that emitted util.Uint256{} for this
case), then it gets converted to Parameter as AnyType and we have to JSONize
it somehow for proper RPC functioning.
2020-06-05 19:20:16 +03:00
Roman Khimov
c6ae954e4e rpc: drop getaccountstate method
It's not relevant for Neo 3.
2020-06-05 19:20:16 +03:00
Roman Khimov
657bb7575e rpc: change getunclaimed to getunclaimedgas
getunclaimed doesn't exist on Neo 3 and getunclaimedgas works for NEP5 GAS.
2020-06-05 19:20:16 +03:00
Roman Khimov
d856df36a7 rpc: drop support for gettxout method
Neo 3 doesn't need it.
2020-06-05 19:20:16 +03:00
Roman Khimov
232e1a2598 rpc: drop support for getassetstate
It's for UTXO assets and it's absent in Neo 3.
2020-06-05 19:20:16 +03:00
Roman Khimov
63eb6069b2 rpc: drop support for getunspents method
Irrelevant for Neo 3.
2020-06-05 19:20:16 +03:00
Roman Khimov
337e65b696 rpc: drop UTXO transfer support, remove Balancer
Nothing uses them now and they're irrelevant for Neo 3.
2020-06-05 19:20:16 +03:00
Roman Khimov
c0e044961d cli/wallet: add ability to save NEP5 transfer transaction
It allows to use multisig cli operations for multisig transaction creation and
send.
2020-06-05 19:20:16 +03:00
Roman Khimov
9a4e53b58e rpc/client: no longer add UTXO GAS for fees
It's already being paid with NEP5 GAS.
2020-06-05 19:20:16 +03:00
Roman Khimov
670396b908 rpc: drop getclaimable RPC call support
It's not present in NEO 3 and it's not needed there.
2020-06-05 19:20:16 +03:00
Roman Khimov
3b2644da4f rpc/client: pass token as simple hash into TransferNEP5
It doesn't need full wallet.Token structure.
2020-06-05 19:20:16 +03:00
Roman Khimov
ed0a3e4af5 rpc/client: drop neoscan support
It was used as getunspents substitute and it's not longer relevant for NEO 3.
2020-06-05 19:20:16 +03:00
Roman Khimov
31ef0c4339 core: don't check systemfee with UTXO outputs
SystemFee is already being checked by verifyTx against Sender's balance.
2020-06-05 19:20:16 +03:00
Roman Khimov
d9400800e3 transaction: drop Gas field from InvocationTX
It essentialy is the new SystemFee, so use that. Had to increase GAS transfer
in test chain to 1000 to pay for deployment.
2020-06-05 19:20:16 +03:00
Roman Khimov
30c74152ce core: add balance checks for NEP5 transfer to TestCreateBasicChain 2020-06-05 19:20:16 +03:00
Roman Khimov
0a35ee00c6 core: print txes in LE in TestCreateBasicChain
LE is human and RPC compatible representation, BE hex is almost unusable.
2020-06-05 19:20:16 +03:00
Roman Khimov
bf6525e54d core: fix GetUtilityTokenBalance
The value stored in NEP5 tracker for GAS is Fixed8 already, so we need to
type-cast it, but not multiply by 10⁸ again.
2020-06-05 19:20:16 +03:00
Roman Khimov
7e586cc6ab native: deduce transferred assets from sender on transfer
When money is being sent usually they go away from someone's pocket, so that
there is a little less money left there. Not in our case as it turns out, we
actually were adding money both to sender and receiver which is nice, but a
bit different from usual economic's expectations.
2020-06-05 19:20:16 +03:00
Roman Khimov
46cd14a892
Merge pull request #1002 from nspcc-dev/neo3/interop/sort_find
core: sort results of Storage.Find interop and NEO.getRegisterValidators
2020-05-30 15:34:41 +03:00
Anna Shaleva
8fb67615f8 core: sort results of Storage.Find and NEO.getRegisterValidators
Closes #909
We need to match elements order with C# implementation.
2020-05-29 17:33:01 +03:00
Roman Khimov
eec462b00c network: fix Inv types for Neo 3
They actually use the same types as for messages. Fixes
2020-05-29T00:06:17.593+0300    WARN    peer disconnected       {"addr": "168.62.167.190:20333", "reason": "handling CMDInv message: invalid inventory type", "peerCount": 3}
2020-05-29 15:02:20 +03:00
Roman Khimov
56b24bf83e capability: prevent panic on wrong capabilities receival
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xad7b95]

goroutine 134 [running]:
github.com/nspcc-dev/neo-go/pkg/network/capability.(*Capability).DecodeBinary(0xc00024a300, 0xc00015c900)
        /home/rik/dev/neo-go/pkg/network/capability/capability.go:69 +0x85
github.com/nspcc-dev/neo-go/pkg/io.(*BinReader).ReadArray(0xc00015c900, 0xd54880, 0xc00018ecd8, 0xc00071fbe0, 0x1, 0x1)
        /home/rik/dev/neo-go/pkg/io/binaryReader.go:141 +0x22f
github.com/nspcc-dev/neo-go/pkg/network/capability.(*Capabilities).DecodeBinary(0xc00018ecd8, 0xc00015c900)
        /home/rik/dev/neo-go/pkg/network/capability/capability.go:17 +0x6d
github.com/nspcc-dev/neo-go/pkg/network/payload.(*AddressAndTime).DecodeBinary(0xc00018ecc0, 0xc00015c900)
        /home/rik/dev/neo-go/pkg/network/payload/address.go:34 +0x59
github.com/nspcc-dev/neo-go/pkg/io.(*BinReader).ReadArray(0xc00015c900, 0xcb9e00, 0xc00024a2a0, 0x0, 0x0, 0x0)
        /home/rik/dev/neo-go/pkg/io/binaryReader.go:141 +0x22f
github.com/nspcc-dev/neo-go/pkg/network/payload.(*AddressList).DecodeBinary(0xc00024a2a0, 0xc00015c900)
        /home/rik/dev/neo-go/pkg/network/payload/address.go:78 +0x54
github.com/nspcc-dev/neo-go/pkg/network.(*Message).decodePayload(0xc000277890, 0xc000292020, 0xc0003da000)
        /home/rik/dev/neo-go/pkg/network/message.go:158 +0x31a
github.com/nspcc-dev/neo-go/pkg/network.(*Message).Decode(0xc000277890, 0xc00071ff48, 0xc00036e090, 0xc000276e40)
        /home/rik/dev/neo-go/pkg/network/message.go:114 +0x19b
github.com/nspcc-dev/neo-go/pkg/network.(*TCPPeer).handleConn(0xc00036e090)
        /home/rik/dev/neo-go/pkg/network/tcp_peer.go:154 +0x244
created by github.com/nspcc-dev/neo-go/pkg/network.(*TCPTransport).Dial
        /home/rik/dev/neo-go/pkg/network/tcp_transport.go:40 +0x1ad
2020-05-29 00:11:54 +03:00
Anna Shaleva
1dffe0bea9 network: remove outdated fields
After #980 there were outdated fields present in message test.
2020-05-27 19:32:50 +03:00
Roman Khimov
a446821753
Merge pull request #980 from nspcc-dev/neo3/protocol/version_payload_optimisation
protocol: add node capabilities
2020-05-27 19:13:00 +03:00
Anna Shaleva
7547a3efe1 network: minor code refactoring
We need to handle IPv6 addresses correctly and net.JoinHostPort takes it
into account.
2020-05-27 19:04:09 +03:00
Anna Shaleva
8c5c248e79 protocol: add capabilities to address payload
Part of #871
2020-05-27 19:02:25 +03:00
Anna Shaleva
c590cc02f4 protocol: add capabilities to version payload
closes #871
2020-05-27 19:01:14 +03:00
Roman Khimov
fba4b20cc8
Merge pull request #989 from nspcc-dev/doc-update
Documentation update
2020-05-27 14:29:43 +03:00
Evgenii Stratonikov
f39b51deee compiler: restore support for GetUnspentCoins
Revert a587274.
2020-05-27 12:01:50 +03:00
Evgenii Stratonikov
44709cf6fe core: make GetUnspentCoins interop return array, fix #978. 2020-05-27 12:01:50 +03:00
Roman Khimov
77b92de074 interop: add some top-level doc.go 2020-05-27 12:01:50 +03:00
Roman Khimov
7e96f82a5b compiler/interop: add support for working with witnesses 2020-05-27 12:01:50 +03:00
Roman Khimov
87e7e157ae interop/util: extend documentation 2020-05-27 12:01:50 +03:00
Roman Khimov
85cc0639bb interop/transaction: update documentation 2020-05-27 12:01:50 +03:00
Roman Khimov
e32d0e01af compiler|transaction: remove transaction.GetUnspentCoins support
It's useless. Even though there is Neo.Transaction.GetUnspentCoins syscall
that can be used, its return type is an interop structure that's not accepted
by any other syscall, so you can't really do anything with it. And there is no
such interface for the .net Framework.
2020-05-27 12:01:50 +03:00
Roman Khimov
1cbd75ab9e compiler|transaction: fix transaction.GetScript build, add to interop
There is no such syscall as Neo.Transaction.GetScript and GetScript should be
available for contract's use.
2020-05-27 12:01:50 +03:00
Roman Khimov
559e8a16da compiler/storage: add read-only related interops 2020-05-27 12:01:50 +03:00
Roman Khimov
bfd8fe5960 interop/storage: update documentation 2020-05-27 12:01:50 +03:00
Roman Khimov
ddb9497649 interop/runtime: update documentation, fix Notify
Notify doesn't return anything!
2020-05-27 12:01:50 +03:00
Roman Khimov
6d2b2d7263 compiler/iterator: add missing iterator.Concat function
We have a syscall for it, so it should be exposed.
2020-05-27 12:01:50 +03:00
Roman Khimov
5733573d2e
Merge pull request #987 from nspcc-dev/neo3/protocol/compression
protocol: add payload compression
2020-05-26 23:31:17 +03:00
Anna Shaleva
0cbd7823ab protocol: add payload compression
closes #872
2020-05-26 22:19:10 +03:00
Roman Khimov
01b5299355 interop/iterator: documentation update 2020-05-26 20:07:44 +03:00
Roman Khimov
2bf7329a15 interop/input|output: update documentation 2020-05-26 20:07:37 +03:00
Roman Khimov
80b39649aa interop/header: update documentation 2020-05-26 20:07:31 +03:00
Roman Khimov
4e21e43e72 compiler: add support for enumerator interop package 2020-05-26 20:07:19 +03:00
Roman Khimov
a0e9673c3e interop/enumerator: update doc, fix Next return value 2020-05-26 20:06:33 +03:00
Roman Khimov
a44bdea890 interop/engine: update documentation 2020-05-26 20:05:17 +03:00
Roman Khimov
71f29c1f9f interop/crypto: update documentation 2020-05-26 20:02:46 +03:00
Roman Khimov
1e83a5e318 interop/contract: update documentation, fix some interfaces
Some functions were just not correct in their interfaces.
2020-05-26 19:58:59 +03:00
Roman Khimov
8231953842 core: fix Neo.Contract.GetStorageContext security check
This syscall should only work for contracts created by current transaction and
that is what is supposed to be checked here. Do so by looking at the
differences between ic.dao and original lower DAO.
2020-05-26 19:58:49 +03:00
Roman Khimov
14409addd9 compiler/interop: expose GetTransactionHeight
And sort syscall names as they change the indentation anyway.
2020-05-26 19:55:21 +03:00
Roman Khimov
afe23ce239 interop/blockchain: update documentation 2020-05-26 19:53:51 +03:00
Roman Khimov
aaf65729bf interop/block: update documentation, fix GetTransaction
GetTransaction never worked with hash, it works with indexes.
2020-05-26 19:53:39 +03:00
Roman Khimov
9718891d79 compiler: add support for attribute syscalls 2020-05-26 19:53:28 +03:00
Roman Khimov
60bea7e224 interop/attribute: update documentation 2020-05-26 19:52:57 +03:00
Roman Khimov
6fac273d5d compiler: add missing asset syscalls, sort them 2020-05-26 19:52:46 +03:00
Roman Khimov
ff583a10a5 asset: update documentation and fix Create/Renew
Both Create and Renew have things returned from them.
2020-05-26 19:52:39 +03:00
Roman Khimov
41337732be compiler: add support for account syscalls
Turns out, they never functioned correctly.
2020-05-26 19:52:24 +03:00
Roman Khimov
7c1a54b725 account: add missing IsStandard interop function
There is a Neo.Account.IsStandard syscall, but we didn't have a wrapper for
it.
2020-05-26 19:51:32 +03:00
Roman Khimov
19c21452c9 interop/account: update and extend documentation 2020-05-26 19:51:20 +03:00
alexvanin
aca6f2f3ad rpc/client: handle client creation error in new wsclient
Client returns error if it can't parse endpoint string. WSClient
should check client error or there could be panic at `cl.cli = nil`
expression.
2020-05-26 11:36:47 +03:00
Roman Khimov
29e66925aa rpc/client: deduplicate block/header tests a bit
The same data is copied at least twice here. Also use this block for header
test making it a bit more convenient.
2020-05-26 11:36:47 +03:00
Roman Khimov
5432530df4 result: use witnesses field in result.Header JSON
Follow new Neo 3.0 standard for these outputs.
2020-05-26 11:36:47 +03:00
Roman Khimov
7633439845 rpc/block: rework the way Block is JSONized
Our block.Block was JSONized in a bit different fashion than result.Block in
its NextConsensus and Index fields. It's not good for notifications because
third-party clients would probably expect to see the same format. Also, using
completely different Block representation is probably making our client a bit
weaker as this representation is harder to use with other neo-go components.

So use the same approach we took for Transactions and wrap block.Block which is
to be serialized in proper way.

Fix `Script` JSONization along the way, 3.0 node wraps it within `witnesses`.
2020-05-26 11:36:47 +03:00
Roman Khimov
393ce1c230 rpc/server: add notification filters
And check state string correctness on unmarshaling.
2020-05-26 11:36:47 +03:00
Roman Khimov
2dc16c0694 transaction: add json.Unmarshaler to Attribute
It actually was missing and it might affect Transaction conversion to/from
JSON.
2020-05-26 11:36:47 +03:00
Roman Khimov
725b47ddef rpc/client: add support for notification filters
Differing a bit from #895 draft specification, we won't add `sender` or
`cosigner` to `transaction_executed`.
2020-05-26 11:36:47 +03:00
Roman Khimov
c4c080d240 rpc: add subscriber queue overflow check
Server-side test is added, but disabled because of its unreliability.
2020-05-26 11:36:47 +03:00
Roman Khimov
44ae9086b6 core: improve and fix locking in storeBlock
Getting batch, updating Prometheus metrics and pushing events doesn't require
any locking: batch is a local cache batch that no one outside cares about,
Prometheus metrics are not critical to be in perfect sync and events are
asynchronous anyway.

Native contracts also don't require any locks and they should be processed
before dumping storage changes.
2020-05-26 11:36:47 +03:00
Roman Khimov
bef14977a2 rpc/client: add notifications support for WSClient
It differs from #895 design in that we have Notifications channel always
exposed as WSClient field, probably it simplifies things a little.
2020-05-26 11:36:47 +03:00
Roman Khimov
fc22a46a4c rpc/server: add notification subscription
Note that the protocol differs a bit from #895 in its notifications format,
to avoid additional server-side processing we're omitting some metadata like:
 * block size and confirmations
 * transaction fees, confirmations, block hash and timestamp
 * application execution doesn't have ScriptHash populated

Some block fields may also differ in encoding compared to `getblock` results
(like nonce field).

I think these differences are unnoticieable for most use cases, so we can
leave them as is, but it can be changed in the future.
2020-05-26 11:36:47 +03:00
Roman Khimov
03ecab5eec smartcontract: add JSON marshal/unmarshal for InteropType
We actually have to do that in order to answer getapplicationlog requests for
transactions that leave some interop items on the stack. It follows the same
logic our binary serializer/deserializes does leaving the type and stripping
the value (whatever that is).
2020-05-25 00:27:39 +03:00
Roman Khimov
612500ed96 rpc/server: start and shutdown Server in tests
It will be important for proper subscription testing and it doesn't hurt even
though technically we've got two http servers listening after this change (one
is a regular Server's http.Server and one is httptest's Server). Reusing
rpc.Server would be nice, but it requires some changes to Start sequence to
start Listener with net.Listen and then communicate back its resulting
Addr. It's not very convenient especially given that no other code needs it,
so doing these changes just for a bit cleaner testing seems like and
overkill.

Update config appropriately. Update Start comment along the way.
2020-05-25 00:27:39 +03:00
Roman Khimov
b7d2b659b4 network: get blocks directly from the chain for rebroadcasting
Simplify network<->consensus relations, also broadcast blocks received by
other means like RPC.
2020-05-25 00:27:39 +03:00
Roman Khimov
462022bbdd consensus: remove OnNewBlock(), use Blockchain subscription
Get new blocks directly from the Blockchain. It may lead to some duplications
(as we'll also receive our own blocks), but at the same time it's more
correct, because technically we can also get blocks via other means besides
network server like RPC (submitblock call). And it simplifies network server
at the same time.
2020-05-25 00:27:39 +03:00
Roman Khimov
3ca71d5e8d core: add Blockchain event subscription mechanism
A deep internal part of #895. Blockchainer interface is also extended for
various uses of these methods.
2020-05-25 00:27:39 +03:00
Roman Khimov
ac40d357f0 core: improve documentation a little 2020-05-24 23:54:01 +03:00
Roman Khimov
f2033b5e54 wallet: check for t.GetSignedPart() result correctness
It can return nil easily and signing that is a big mistake.
2020-05-24 23:53:38 +03:00
Roman Khimov
c9b1d359d8 core: ensure we produce correct blocks for tests
Check for correct merkle root generation.
2020-05-24 23:52:54 +03:00
Roman Khimov
bd98940a54
Merge pull request #982 from nspcc-dev/neo3/protocol/getblockdata
protocol: implement getblockdata p2p command
2020-05-22 19:28:42 +03:00
Anna Shaleva
8142caaf8b protocol: implement getblockdata p2p command
closes #891
2020-05-22 19:16:49 +03:00
Roman Khimov
d12d198eed
Merge pull request #983 from nspcc-dev/neo3/protocol/getblocks
protocol: refactor getblocks payload
2020-05-22 17:46:54 +03:00
Anna Shaleva
2f6a3e9af5 protocol: refactor getblocks payload
closes #890
2020-05-22 17:33:59 +03:00
Evgenii Stratonikov
d26758dd31 vm/tests: restore NEO3 JSON tests
The only skipped RN are ROT.json (see #927) and MEMCPY.json (not a valid
JSON).
2020-05-22 14:17:15 +03:00
Evgenii Stratonikov
673e6c84d1 vm/tests: preserve order when decoding Map item.
When using Go's `map` for decoding, order can change from time to time,
while we may want to check it too. Use custom decoder for saving items
in order.
2020-05-22 14:17:15 +03:00
Evgenii Stratonikov
9dca2288ba vm: make LEFT fail if count is too big 2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
22791272bf vm/tests: compare static slot contents in JSON tests
Make use of "staticFields" test field to compare vm static slots.
Also remove altStack because it is doesn't exist.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
16bf72f9cc vm/tests: do not load empty script
In case we load a zero-length script, VM should end in HALT state.
https://github.com/neo-project/neo-vm/blob/master/tests/neo-vm.Tests/Tests/Others/OtherCases.json#L22
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
86c4f1abc5 vm: do not use State as a mask
In NEO2 state could be used as a mask, but now it contains only a single
value.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
063c29636b vm: fail if NEWSTRUCT/NEWARRAY argument is not an integer
NEO3 VM does not support creating new Array from a Struct.
For this purpose CONVERT opcode is used.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
1a0290edc6 vm: copy slice when converting between Array<->Struct
Related #437. Becase in NEO3 NEWSTRUCT/NEWARRAY accept only an integer
change tests too.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
781def735d vm: use Null item as a default value for Array/Struct elements 2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
f4fa712440 vm: make PUSH0 emit Integer 2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
820b050b18 vm/tests: make test interop push non-nil InteropItem 2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
a44acd25bb vm/tests: restore JSON tests parsing
Make sure we support new test format. Tests itself will be restored
later.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
61b1722745 opcode: swap ROT and OLDPUSH1
Because of how stringer generates String() method, the first of them
will be used as the result.
2020-05-22 14:16:32 +03:00
Evgenii Stratonikov
646c247b31 vm/tests: unmarshal Map keys properly in JSON tests 2020-05-22 14:16:31 +03:00
Evgenii Stratonikov
128a99dec2 vm/tests: unmarshal action in JSON tests properly 2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
7ddb23abe3 vm/tests: unmarshal stack items in JSON tests properly
New item types were added in NEO3 and they can be capitalized or not.
2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
e71cc04c70 vm/tests: unmarshal VM state in JSON tests properly 2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
0c7b163280 vm/tests: unmarshal script in JSON tests properly
Script is no specified via stringified opcodes and their arguments.
2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
1100f629df opcode: implement FromString() 2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
e53055a560 opcode: use underscored names in String() 2020-05-22 13:36:11 +03:00
Evgenii Stratonikov
3917b4b4e4 vm: update stack size in SETITEM properly 2020-05-21 18:00:51 +03:00
Anna Shaleva
64a2fb63e1 protocol: move magic exchange to version payload
closes #889
2020-05-21 14:23:41 +03:00
Anna Shaleva
3bcc56bdcf protocol: switch to binary MessageCommand
closes #888
2020-05-21 13:57:49 +03:00
Evgenii Stratonikov
8cf7871c26 compiler: support nested slice element assignment 2020-05-21 08:30:32 +03:00
Evgenii Stratonikov
5b0e73ddf0 compiler: initialize struct fields explicitly
By default VM initializes every field of a new struct to a Boolean.
If field contains another struct, we need to initialize it to default
value explicitly. This commit sets default values for uninitialized
field.
2020-05-21 08:30:32 +03:00
Evgenii Stratonikov
051e3608ff compiler: support nested struct fielid assignment 2020-05-21 08:30:32 +03:00
Evgenii Stratonikov
1e40f9dac0 compiler: support nested struct reading 2020-05-21 08:30:31 +03:00
Anna Shaleva
9f2cb1726b core: add witness check to nep5 transfer method
We have to check, whether transaction's sender is authorised to transfer
nep5 assets.
2020-05-20 23:34:27 +03:00
Anna Shaleva
1afd630169 core: add senders' fees monitor to mempool
In order to simplify maintainance of overall current senders` fees
in the mempool we are to keep them in a separate map.
2020-05-20 23:34:25 +03:00
Anna Shaleva
c3e08afe34 util: fixed typo in method description 2020-05-20 23:26:51 +03:00
Anna Shaleva
7acf5b2841 core: add SystemFee and NetworkFee to transaction
closes #831
2020-05-20 23:26:48 +03:00
Anna Shaleva
fc3acdc80c core: add native contracts' hashes getters 2020-05-20 23:16:04 +03:00
Anna Shaleva
6b2f4efdd4 core: fix bug in nep5TokenNative.addTokens method
Sometimes we want to add negative amount (e.g. when burning tokens).
2020-05-20 23:16:04 +03:00
Anna Shaleva
c7a040ff81 core: fix bug with native contracts methods initialisation
`NewNEO()` and `NewGAS()` methods are trying to initialise
both `onPersist` and `incBalance` methods of NEO and GAS AFTER
nep5TokenNative is set to the VALUE of created nep5 token.
In this situation an attemmpt to call the corresponding native contracts
methods (e.g. transfer native GAS) leads to contract invocation failure,
as far as `nep5TokenNative.incBalance` method is nil.

Fixed this by initializing both `onPersist` and `incBalance` methods
before getting the value of nep5 contract.
2020-05-20 23:16:04 +03:00
Anna Shaleva
4ebac5a069 core: fix bug in nep5 notifications handling
Native contracts deployment creates `Transfer` notifications and adds
them into interop context. However, these notifications were not stored
for two reasons:
1. typo in `Transfer` (so these notifications were not recognised during
processing of the invocation tx in (*Blockchain).storeBlock(...) method)
2. these notifications have `from` adress setted to null, so conversion
to []byte fails. Same thing could happen with `to`.

Related C# issue: https://github.com/neo-project/neo/issues/1646

For now, made both `transfer` and `Transfer` valid.
2020-05-20 23:16:04 +03:00
Anna Shaleva
45b8bdb51c core: fix bug in consensus
We should set MerkleRoot in approving block irrespective to
transactions presented in the block.
2020-05-20 23:16:04 +03:00
Evgenii Stratonikov
22067d400d rpc: update testchain 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
1a4a0c154b compiler: support var-declaration of byte slices
Related #801.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
3a4ed7dfe8 compiler: emit Buffer for byte slices
All byte slices are mutable so buffer is a right stack item.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
b4f1142149 compiler: emit byte constants properly 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
98c508d361 vm: implement MEMCPY opcode
MEMCPY copies byte-slice to a destination buffer.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
a5f6e0e53d vm: implement NEWBUFFER opcode 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
a3a3a77431 vm: make slice opcodes emit Buffer 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
c3f7832f3b vm: implement Buffer stack item
Buffer is a stack item type introduced in NEO3
which represents mutable byte-array.
2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
ee9adcdc5c vm: check ByteArray size before converting to Integer 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
8f5f6fba07 vm: copy slice in (*ByteArrayItem).TryBytes() 2020-05-20 17:45:56 +03:00
Evgenii Stratonikov
1b105a9f1d compiler: allow using OP= with struct fields and slice elements
Do it in a generic way, there is no need in restricting to only
variables.
Port of #954.
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
fdb217ec81 compiler: process _ as a special variable
It is more convenient to drop values inside `emitStoreVar` because this
makes other code has less special cases.
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
3926456d86 compiler: add test for iterating over map with range 2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
d0735257ce compiler: support range loops with value variables
Closes #958.
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
b126056f04 compiler: use iterators in range loops
It is simpler than having some counters on stack and will help us to
support maps in future.
2020-05-20 14:14:29 +03:00
Evgenii Stratonikov
34a4c15932 compiler: support byte slice declaration 2020-05-20 11:10:02 +03:00
Evgenii Stratonikov
582469028b compiler: emit default values in a generic way 2020-05-20 11:10:01 +03:00
Evgenii Stratonikov
2cc58c3c9e compiler: allow to declare multiple compound types in a var decl 2020-05-19 16:57:02 +03:00
Evgenii Stratonikov
b4bad11699 compiler: count the number of variables correctly 2020-05-19 16:47:43 +03:00
Evgenii Stratonikov
0629479560 compiler: support non-struct methods
There is no need to restrict ourselves just to structs.
2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
87f6ba34db compiler: process index expresstions in a generic way
All type errors such as string index in slice will be catched during parse phase.
2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
aeaa4a8210 compiler: process bool literals in a generic way 2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
70d0ff869d compiler: refactor typeinfo functions 2020-05-19 16:40:26 +03:00
Evgenii Stratonikov
89b5e92b83 compiler: add tests for function literal
Add test forgotten in #934.
2020-05-12 16:23:09 +03:00
Evgenii Stratonikov
e21015233b compiler: implement shadowing of global variables
Before introducing slots it was hard to change global variables
preserving changes across multiple function calls.
This commit implements such possibility.
Closes #638.
2020-05-12 16:23:09 +03:00
Evgenii Stratonikov
0cb6dc47e4 vm: implement slot-related opcodes
1. Slot is a new mechanism for storing variables during execution
which is more convenient than alt.stack. This commit implements
support for slot opcodes in both vm and compiler.
2. Remove old alt.stack opcodes.
3. Do not process globals at the start of every function, but instead
load them single time at main.
2020-05-12 16:23:08 +03:00
Evgenii Stratonikov
a6271f6bf2 vm: reorder splice opcodes 2020-05-12 16:15:35 +03:00
Evgenii Stratonikov
2cec088f08 vm: add reference counter to slots 2020-05-12 16:15:14 +03:00
Evgenii Stratonikov
af2abedd86 vm: implement reference counter
It is convenient to have all reference-counting logic
in a separate struct.
2020-05-12 16:15:14 +03:00
Evgenii Stratonikov
81cbf183af vm: implement storage slots 2020-05-12 16:15:14 +03:00
Evgenii Stratonikov
75fb3af48f compiler: add basic support for function literals
Implement basic support for function literals.
Nested function literals and variables from closure are not supported for now.
2020-05-12 12:56:52 +03:00
Evgenii Stratonikov
1d3fb3d6f5 vm: implement PUSHA/CALLA opcodes 2020-05-12 12:56:51 +03:00
Evgenii Stratonikov
7fcd537b09 vm: implement Pointer stack item
Pointer is a generic address type in VM.
It is used for calling lambda-expressions.
2020-05-12 12:55:31 +03:00
Roman Khimov
b83ee77698
Merge pull request #938 from nspcc-dev/fix/appcall
vm: remove APPCALL, TAILCALL
2020-05-08 13:11:02 +03:00
Evgenii Stratonikov
c0147c76ac emit: remove tailCall argument from AppCall
There is no TAILCALL opcode in NEO3.
2020-05-07 14:59:01 +03:00
Evgenii Stratonikov
73c82584a3 vm,compiler: replace APPCALL with System.Contract.Call
Contract calls are performed via syscall System.Contract.Call
in NEO3. This implements this in compiler and removes APPCALL from the
VM.
2020-05-07 14:52:03 +03:00
Evgenii Stratonikov
ec900c7ff7 core: implement System.Contract.Call interop 2020-05-07 14:39:06 +03:00
Evgenii Stratonikov
301c1b7601 native: save native contract state on deploy 2020-05-07 14:03:14 +03:00
Evgenii Stratonikov
f9f3192b48 vm: move RET and SYSCALL opcodes 2020-05-07 13:23:05 +03:00
Evgenii Stratonikov
7ac15a7557 compiler: support implicit type in function arguments
Go supports declaring multiple arguments of the same type without
duplicating type name. Now we support this too.
2020-05-07 11:33:09 +03:00
Evgenii Stratonikov
b0a89e8a1a compiler: support named returns 2020-05-06 18:22:52 +03:00
Evgenii Stratonikov
156a2eddc5 compiler: support using return in some branches
When `return` is used in one codepath, but not the other,
we do not clean altstack properly. This commit fixes it.
2020-05-06 18:22:52 +03:00
Evgenii Stratonikov
770cff8b91 compiler: allow to use return with no arguments 2020-05-06 18:22:52 +03:00
Evgenii Stratonikov
5ab4b9284b core: remove unused function from tests 2020-05-06 16:00:16 +03:00
Evgenii Stratonikov
977c431bf1 vm: implement ASSERT/ABORT opcodes
Rename THROWIFNOT to ASSERT, add ABORT opcode.
ABORT cannot be caught, but the implementation should be postponed until
exception handling is implemented.
2020-05-06 15:54:19 +03:00
Roman Khimov
963a70d54a
Merge pull request #926 from nspcc-dev/feature/stack
Implement NEO3 VM stack opcodes
2020-05-06 14:51:04 +03:00
Roman Khimov
7287c01bd0 rpc/server: rework submitblock empty test
The original intention here was to check for server reaction in presence of
validation errors (response.ErrValidationFailed) and it was very easy to make
validation fail for block without transactions in Neo 2. But in Neo 3
transactionless blocks are perfectly valid (see
29d321b5e1) which broke this test even though we
didn't see it until websocket addition (which required
8cec6694ae to make this test work initially).

So make a valid block and then spoil its verification script.
2020-05-06 14:20:35 +03:00
Roman Khimov
fd72f0635e rpc/server: prevent test panicing in checkErrGetResult()
If we expect some resp.Error, then check for it explicitly.
2020-05-06 13:11:12 +03:00
Evgenii Stratonikov
dd20320615 vm: remove XSWAP/XTUCK opcodes
Regenerate RPC testchain as these were used in compiler.
2020-05-06 13:05:22 +03:00
Evgenii Stratonikov
d18199ce42 vm: implement REVERSE* opcodes
Use new opcodes in the compiler instead of XSWAP/ROLL.
2020-05-06 13:03:49 +03:00
Evgenii Stratonikov
c8a1188ee1 vm: implement CLEAR opcode 2020-05-06 13:02:57 +03:00
Evgenii Stratonikov
525527f750 vm: reorder stack opcodes
Leave *ALTSTACK opcodes for now as they are needed in compiler while
slot opcodes are not yet here.
2020-05-06 13:02:14 +03:00
Evgenii Stratonikov
115919aaf7 vm: process OLDPUSH1 at the context level
The only usecase for this opcode is single-byte verification scripts.
2020-05-06 13:00:00 +03:00
Roman Khimov
b04c8623c5
Merge pull request #925 from nspcc-dev/rpc-over-websocket
RPC over websocket
2020-05-06 12:52:58 +03:00
Roman Khimov
ec6ade4c9b
Merge pull request #920 from nspcc-dev/neo3/transaction/cosigners
core: implement cosigners mechanism
2020-05-04 17:15:07 +03:00
Roman Khimov
3de48d7d90 rpc/client: add minimalistic websocket client 2020-05-04 16:54:35 +03:00
Roman Khimov
a458a17748 rpc/client: separate out http-related functionality 2020-05-04 16:54:35 +03:00
Roman Khimov
6d202ad4c5 rpc/client: drop Version from Options
It makes no sense at all, it's a JSON-RPC version.
2020-05-04 16:54:35 +03:00
Roman Khimov
19397ec4a8 rpc/client: fix some comments 2020-05-04 16:54:35 +03:00
Roman Khimov
20d477cbd8 client: remove Balancer getter/setter, make it an Option
Keep it internal to the client instance, it makes no sense exposing it to the
outside user.
2020-05-04 16:54:35 +03:00
Roman Khimov
315aabde56 client: make http.Client internal to the Client
Exposing it the outside users is strange, so incapsulate it completely.

Fix DialTimeout setting along the way, handle negative timeouts as invalid.
2020-05-04 16:54:35 +03:00
Roman Khimov
ec62edac68 rpc/server: add websockets support via '/ws' URL 2020-05-04 16:54:35 +03:00
Roman Khimov
8cec6694ae rpc/server: fix test block encoding
The end result of the previous code wasn't even a valid JSON.
2020-05-04 16:54:35 +03:00
Roman Khimov
d275652b37 rpc/server: use httptest.Server for testing
Which allows to reuse it for websockets.
2020-05-04 16:54:35 +03:00
Roman Khimov
1b523be4b6 rpc: shuffle handleHttpRequest/handleRequest responsibilities
Make handleRequest reusable in other contexts like websockets.
2020-05-04 13:57:23 +03:00
Roman Khimov
236f3dabdd rpc: change handlers to always return response.Error for errors
As it's expected by WriteErrorResponse() actually.
2020-05-04 13:57:15 +03:00
Roman Khimov
57de98e1a3 rpc/server: refactor handler methods a little
request.In is a natural request representation, one can always get
request.Params from it.
2020-05-04 13:57:08 +03:00
Anna Shaleva
5ece9922c1 vm: hide GetContextScriptHash() method
After adding ScriptHashGetter interface to vm, there's no need in
GetContextScriptHash() to be exported.
2020-05-04 11:53:31 +03:00
Anna Shaleva
73167999cc core: add cosigners field to transaction
closes #864
2020-05-04 11:53:31 +03:00
Anna Shaleva
9ecac14aee vm: fix bug in GetContextScriptHash()
v.Istack.Peek(n) can return nil pointer, so .Value() on this pointer
leads to panic here. Fixed by adding nil check.
2020-05-04 11:49:14 +03:00
Anna Shaleva
d1ec01c45e util: implement Serializable interface over Uint160 2020-05-04 11:49:14 +03:00
Anna Shaleva
08f5708edb core: remove Script attribute type 2020-05-04 11:49:14 +03:00
Anna Shaleva
2ec1d76320 compiler: add ability to generate .abi.json file
A part of integration with NEO Blockchain Toolkit (see #902). To be
able to deploy smart-contract compiled with neo-go compiler via NEO
Express, we have to generate additional .abi.json file. This file
contains the following information:
 - hash of the compiled contract
 - smart-contract metadata (title, description, version, author,
email, has-storage, has-dynamic-invoke, is-payable)
 - smart-contract entry point
 - functions
 - events

However, this .abi.json file is slightly different from the one,
described in manifest.go, so we have to add auxilaury stractures for
json marshalling. The .abi.json format used by NEO-Express is described
[here](https://github.com/neo-project/neo-devpack-dotnet/blob/master/src/Neo.Compiler.MSIL/FuncExport.cs#L66).
2020-05-04 08:37:39 +03:00
Anna Shaleva
ab7f2cb4fb compiler: fix bug with missing methods parameters
Method `methodInfoFromScope(...)` always returned an empty parameters
set, so we were missing this information in both .abi.json and
.debug.json files. Fixed now.
2020-05-04 08:37:39 +03:00
Anna Shaleva
861aca1547 rpc, smartcontract: move contract metadata to smartcontract package 2020-05-04 08:37:39 +03:00
Evgenii Stratonikov
c8328981ec vm: refactor tests
Most of the tests follow the same logic:
push items on stack -> execute program -> check single result.
This commit reuses this function in most of the tests.
2020-04-30 19:29:52 +03:00
Evgenii Stratonikov
9081211f12 vm: implement NOTEQUAL opcode 2020-04-30 18:00:15 +03:00
Evgenii Stratonikov
70f0c656b0 vm: check Integer size on creation 2020-04-30 18:00:15 +03:00
Evgenii Stratonikov
a64a0f2681 vm: reorder arithmetic opcodes 2020-04-30 18:00:15 +03:00
Evgenii Stratonikov
519b31a704 vm: remove crypto-related opcodes
All cryptography has moved to interops in NEO3.
There is no SHA256 interop RN, but it is to appear later.
Closes #777.
2020-04-29 19:16:38 +03:00
Roman Khimov
c1aa96d614
Merge pull request #911 from nspcc-dev/feature/convert
vm: implement CONVERT opcode
2020-04-28 18:08:36 +03:00
Evgenii Stratonikov
4b064e18aa emit: converto to Boolean in Bool() 2020-04-28 17:36:58 +03:00
Evgenii Stratonikov
2fd63387c0 compiler: support CONVERT interops
When result is needed to have certain type, we should have ability
to convert it, with the help of CONVERT opcode.
2020-04-28 16:44:06 +03:00
Evgenii Stratonikov
bfcb1a409f compiler: extend possible returned values
All integer values (int32, uint64...) should be able to be returned.
2020-04-28 16:44:06 +03:00
Evgenii Stratonikov
7e98a2ffa0 vm: implements CONVERT opcode 2020-04-28 16:38:52 +03:00
Evgenii Stratonikov
be38798785 vm: move Bool method to the StackItem interface 2020-04-28 15:13:41 +03:00
Anna Shaleva
fa467ce628 core: add txes duplication check on block.DecodeBinary 2020-04-27 18:00:01 +03:00
Anna Shaleva
dbda721599 consensus.Block: removed unnecessary setters
As far as we have consensus context in NewBlockFromContext, we don't
need them anymore.
2020-04-27 17:59:56 +03:00
Anna Shaleva
6db4ca874d consensus: replace NewBlock() with NewBlockFromContext(ctx *Context)
We have to set ConsensusData.PrimaryIndex field of Block, so this value
can be retrieved from consensus context.
2020-04-27 17:58:25 +03:00
Anna Shaleva
29d321b5e1 *: drop miner transaction
1. Completely remove miner transaction

2. Change validation rule for block: block without transactions is
valid.
2020-04-27 17:57:37 +03:00
Anna Shaleva
55fd9f8d24 core: change block.ConsensusData to neo3 format
1. Dropped `Base.ConsensusData` block field

2. Added `Block.ConsensusData` field with `Nonce` and `PrimaryIndex`

3. Removed "Neo.Header.GetConsensusData" and
"AntShares.Header.GetConsensusData" interops
2020-04-27 17:57:37 +03:00
Anna Shaleva
0de5cb1bde core, consensus: nanoseconds-precision timestamp
Keep timestamp of consensus messages in nanoseconds-precision state
2020-04-27 17:57:32 +03:00
Anna Shaleva
aa554f0a9a core: update block timestamp format
Changed block.Timestamp from uint32 to uint64
2020-04-27 17:56:44 +03:00
Evgenii Stratonikov
dca257f584 vm: move ISNULL opcode
Change it according to NEO3-preview2.
2020-04-27 16:09:03 +03:00
Roman Khimov
e6f5cffff6 transaction: drop Enrollment and State types
They're completely replaced now by the NEO native contract voting system.
2020-04-27 16:06:58 +03:00
Roman Khimov
b83e84ca08 core: switch to the new voting system (via native NEO contract)
It has all the methods required now, so you can register, vote and get
voting results. Fixes #865.
2020-04-27 16:06:50 +03:00
Roman Khimov
2fa3bdf6a9 core/native: move Votes from account to native NEO state 2020-04-27 12:30:39 +03:00
Roman Khimov
bc4a6a6bab core/native: move NextValidators storage to NEO contract 2020-04-27 12:30:39 +03:00
Roman Khimov
66c80d429e native: update voting information when changing Neo balance 2020-04-27 12:30:39 +03:00
Roman Khimov
36c6c6690b native: distribute GAS even for empty transfers
As it's one of the use cases.
2020-04-27 12:30:39 +03:00
Roman Khimov
064636768b core/native: move ValidatorsCount processing into native NEO contract 2020-04-27 12:30:39 +03:00
Roman Khimov
3476a18fa9 core/native: store validators in NEO native contract state
This technically breaks voting with UTXO-based NEO (processTXWithValidators*),
but we're moving towards the new system.
2020-04-27 12:30:39 +03:00
Roman Khimov
4e8ee697ee native: store NEO and GAS state in the storage
As it should be done (although current serialization format is not quite
right).
2020-04-27 12:30:39 +03:00
Roman Khimov
8c02c6b22c native: put proper Null StackItem for transfer event
nil is not a good StackItem, we have proper VM-level Null for this.
2020-04-27 12:30:39 +03:00
Roman Khimov
1dcace1594 native: don't distribute gas at block 0
It fails at the moment and it doesn't make sense at conceptual level.
2020-04-27 12:30:39 +03:00
Roman Khimov
30836ca69b core/native: untangle native contracts initialization
The notion of NativeContractState shouldn't ever existed, native contract is a
contract and its state is saved as regular contract state which is critical
because we'll have MPT calculations over this state soon.

Initial minting should be done in Neo.Native.Deploy because it generates
notification that should have proper transaction context.

RegisterNative() shouldn't exist as a public method, native contracts are only
registered at block 0 and they can do it internally, no outside user should be
able to mess with it.

Move some structures from `native` package to `interop` also to avoid circular
references as interop.Context has to have a list of native contracts (exposing
them via Blockchainer is again too dangerous, it's too powerful tool).
2020-04-27 12:30:39 +03:00
Anna Shaleva
869c7d6afa core: init native interops in the genesis block
closes #836
2020-04-27 12:30:39 +03:00
Evgenii Stratonikov
7c3d7c0261 vm: implement NEWARRAYT opcode 2020-04-27 09:06:48 +03:00
Evgenii Stratonikov
d3b9aef8e2 vm: implement ISTYPE opcode
Also make StackItemType public and reorder it according to NEO3.
2020-04-27 09:01:26 +03:00
Evgenii Stratonikov
48a41bd737 vm: implement CLEARITEMS opcode 2020-04-27 09:01:26 +03:00
Evgenii Stratonikov
9fd04aefa5 vm: implement NEWARRAY0 and NEWSTRUCT0 opcodes 2020-04-24 13:49:10 +03:00
Evgenii Stratonikov
03761421f8 vm: reorder Array/Map opcodes
Also SIZE can be used for both Arrays/Maps and ByteArrays.
2020-04-24 13:48:44 +03:00
Evgenii Stratonikov
d6624a92ca vm: implement new JMP* and CALL* opcodes
In compiler JMP*_L opcodes are always used, as this requires less effort.
2020-04-24 10:16:41 +03:00
Evgenii Stratonikov
fba185cd99 vm: remove stack isolation opcodes
They are not present in NEO3 and will be creating additional difficulties
during future flow-control opcodes implementation.
2020-04-24 10:15:14 +03:00
Evgenii Stratonikov
7caa81a81c rpc/test: generate block for submitblock on-the-fly
There is no need to provide hex when chain is dumped.
2020-04-24 08:54:22 +03:00
Evgenii Stratonikov
0f17402599 testchain: implement Sign function
Sign any data by all consensus nodes.
2020-04-23 17:09:09 +03:00
Evgenii Stratonikov
76a6937f32 rpc: simplify getblockheader RPC test
Set up hash once and get header via provided chain.
2020-04-23 17:09:08 +03:00
Evgenii Stratonikov
008e6eb233 vm: implement new PUSH opcodes 2020-04-23 10:52:28 +03:00
Evgenii Stratonikov
2c39e6fcec consensus: use unencrypted WIFs for test validators
They are easier to work with, because of having no dependencies of VM.
2020-04-23 10:37:45 +03:00
Evgenii Stratonikov
cc20ba651d core: use opcodes instead of raw bytes in tests
It will be helpful during future opcode reordering in NEO3.
2020-04-23 10:37:01 +03:00
Evgenii Stratonikov
f50eaba202 consensus: remove debug test 2020-04-23 10:37:01 +03:00
Evgenii Stratonikov
1a54be279e vm: simplify SimpleCall test
It was taken from the compiler output, but there is
no need in using a lot of complex instructions.
2020-04-23 10:36:44 +03:00
Evgenii Stratonikov
351fdd469f core: calcultate NEO owner on-the-fly 2020-04-23 10:36:44 +03:00
Evgenii Stratonikov
1e50016a91 core,test: move helper functions for testchain to the internal package
Our test chain is used in core,rpc and (in future) interop packages.
It is better to have all related declarations in one place to avoid
code duplication.
2020-04-22 18:17:11 +03:00
Evgenii Stratonikov
c508a36827 core,network: shutdown services in tests properly 2020-04-22 17:53:59 +03:00
Evgenii Stratonikov
70b183fb9d wallet: add test for regenerating test/docker wallets
When changing accounts or VM, it is useful to be able to
regenerate all wallets easy and fast.
2020-04-22 17:17:22 +03:00
Anna Shaleva
2b5c14160c core: add sender field to transaction
closes #860
2020-04-20 17:21:28 +03:00
Evgenii Stratonikov
cde4ccf01c vm: remove CHECKSIG/VERIFY/CHECKMULTISIG opcodes 2020-04-20 11:55:24 +03:00
Evgenii Stratonikov
4740d937aa vm: dont use SetCheckedHash outside of vm package 2020-04-20 11:55:24 +03:00
Evgenii Stratonikov
941410a840 core: change verification scripts to new format
Verification scripts now invoke Neo.Crypto.* interops instead of
CHECKSIG/VERIFY opcodes.
2020-04-20 11:55:24 +03:00
Evgenii Stratonikov
3657f2e21d consensus: set Nonce and ValidUntilBlock on proposal
Related #841.
2020-04-20 11:55:24 +03:00
Roman Khimov
c10c7d2100
Merge pull request #874 from nspcc-dev/disallow-negative-SHL-SHR
vm: disallow negative shifts for SHL/SHR
2020-04-20 10:30:33 +03:00
Roman Khimov
9a67bfac0b network: drop checksums from messages
Follow neo-project/neo#710 changes.
2020-04-19 23:40:31 +03:00
Roman Khimov
91f8626c42 vm: disallow negative shifts for SHL/SHR
Follow neo-project/neo-vm#257 change for Neo 3.
2020-04-19 19:15:00 +03:00
Anna Shaleva
b809d09b24 rpc: add validUntilBlock to transferNEP5
In #856 I forgot to add validUntilBlock to NEP5 transfer transaction,
so added now.
2020-04-17 13:52:23 +03:00
Roman Khimov
ab8296bc57
Merge pull request #857 from nspcc-dev/neo3/verifiable
core,crypto: implement Verifiable interface
2020-04-17 13:06:55 +03:00
Evgenii Stratonikov
ceff8736f2 vm: use ID-based syscalls
In NEO3 SYSCALL opcode has 4-byte ID parameter.
This commit removes support for string-based syscalls and
changes SYSCALL's parameter to be fixed 4-byte value.
2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
bfbbef952a vm: move InteropNameToID to emit package 2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
93d2a3e031 vm: serialize zero Integer to an empty ByteArray 2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
5dba30a49d vm: update bool -> []byte conversion to NEO 3
This reverts commit 4c688355bc.
2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
2fd26287c5 vm: update SUBSTR to NEO3 version
This reverts commit 9ebb793009.
2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
f5933c83c6 vm: update json tests to neo3 branch
Skip them until all opcodes will be implemented.
2020-04-17 11:46:31 +03:00
Evgenii Stratonikov
a224917229 consensus: implement Verifiable interface for Payload 2020-04-17 11:12:40 +03:00
Evgenii Stratonikov
82b230f19f core: rename *block.Base.GetHashableData to GetSignedPart()
This allow to use `Block` as a Verifiable item.
When tx is provided, it is set as an interop's script container.
Otherwise, block is set.
2020-04-17 11:12:40 +03:00
Evgenii Stratonikov
a92872931c interop/crypto: allow ECDsaVerify to verify ScriptContainer
When verifying transaction or block, verification script can be
a simple PUSHNULL + SYSCALL, which means that script-encontaining
entity should be verified.
2020-04-17 11:12:40 +03:00
Evgenii Stratonikov
8f08065a8e interop/crypto: allow ECDsaVerify to accept interop items
When invokes with interop item on stack, it should check
for the signature of Verifiable item it contains.
2020-04-17 11:12:40 +03:00
Evgenii Stratonikov
2879f89337 crypto: declare Verifiable and ScriptContainer interfaces 2020-04-17 11:12:40 +03:00
Roman Khimov
c7ab99ddc1 consensus: drop timestamp from outer payload
It's not used really and NEO3 doesn't have it on the wire.
2020-04-17 00:09:40 +03:00
Roman Khimov
888be75445
Merge pull request #863 from nspcc-dev/drop-publish-tx
Drop publish tx
2020-04-16 21:23:37 +03:00
Roman Khimov
c7c788d10b
Merge pull request #781 from nspcc-dev/neo3/native
Implement Native contract mechanism
2020-04-16 18:41:13 +03:00
Roman Khimov
e150bd7bb0
Merge pull request #859 from nspcc-dev/neo3/partial_consensus_message_decoding
consensus: added partial message decoding
2020-04-16 16:58:59 +03:00
Evgenii Stratonikov
76700f31cf core: implement skeletons for NEO/GAS native contracts 2020-04-16 15:55:35 +03:00
Evgenii Stratonikov
25354c44f9 core: implement NativeContract support 2020-04-16 15:55:34 +03:00
Evgenii Stratonikov
3831aec53f vm: make NewBigInteger accept *big.Int
It creates big.Int internally anyway, so this is the most flexible way.
2020-04-16 15:54:58 +03:00
Evgenii Stratonikov
9586af32f2 core: move runtime.CheckWitness interop to a separate package 2020-04-16 15:54:58 +03:00
Evgenii Stratonikov
8a2130f5b6 core: extend Blockchainer with GetStandByValidators()
A list of standby validators can be needed in native contracts.
2020-04-16 15:54:58 +03:00
Evgenii Stratonikov
b446753c57 core,vm: move get/putContextScriptHash to vm package 2020-04-16 15:54:52 +03:00
Roman Khimov
40991d3be3 transaction: drop AgencyType and VotingType
I have no idea what are they about.
2020-04-16 14:44:46 +03:00
Roman Khimov
4912e4f425 *: drop Publish transaction type
It shouldn't be used even in NEO 2 as it was substituted by contract
deployment interop functions.
2020-04-16 14:40:20 +03:00
Anna Shaleva
9dd5ab5e2b consensus: added partial message decoding
closes #849
2020-04-16 14:35:58 +03:00
Evgenii Stratonikov
be407332b9 vm: add TryInteger() to StackItem interface
Conversion should be done in a StackItem, not in an Element.
2020-04-16 14:05:32 +03:00
Evgenii Stratonikov
dd38e3ec3b smartcontract: add smartcontract manifest
Manifest contains all of smartcontract's metadata including
parameters, return value, permissions etc.
2020-04-16 14:05:32 +03:00
Anna Shaleva
70da3c86f1 rpc: fix typo
Fixed typo in annotation of CalculateInputs method of RPC Client.
2020-04-15 13:46:44 +03:00
Anna Shaleva
5fa11987d2 core: add validUntilBlock field to transaction
1. closes #841

2. Commented out test cases where binary transaction are used.
These test cases marked with `TODO NEO3.0: Update binary` and need to be
updated.

3. Updated other tests.

4. Added cache to calculateValidUntilBlock() RPC-client method.
2020-04-15 13:46:43 +03:00
Roman Khimov
1e3c36433f
Merge pull request #844 from nspcc-dev/neo3/nonce
core: add nonce field to transaction
2020-04-14 16:24:02 +03:00
Anna Shaleva
65503aa9b4 core: add nonce field to transaction
1. Closes #840: added Nonce field to transaction.Transaction and
removed Nonce field from transaction.MinerTx

2. Added following methods to different tx types:
  - NewMinerTx()
  - NewMinerTxWithNonce(...)
  - NewEnrollmentTx(...)
  - NewIssueTx()
  - NewPublishTx(...)
  - NewRegisterTx(...)
  - NewStateTx(...)
in order to avoid code duplication when new transaction is created.

3. Commented out test cases where binary transaction/block are used.
These test cases marked with `TODO NEO3.0: Update binary` and need to be
updated.

4. Updated other tests

5. Added constant Nonce to GoveringTockenTx, UtilityTokenTx and genesis
block to avoid data variability. Also marked with TODO.
2020-04-14 16:19:41 +03:00
Evgenii Stratonikov
a99e0d7ba6 core: fix typo in TestECDSAVerify 2020-04-14 16:15:50 +03:00
Roman Khimov
ace5614a3d
Merge pull request #783 from nspcc-dev/neo3/movecrypto
Implement Neo.Crypto.* interops
2020-04-14 15:54:30 +03:00
Roman Khimov
c40d7aa7f4 core: bump DB version to make it differ from 2.0 branch 2020-04-14 12:54:57 +03:00
Evgenii Stratonikov
4ad29d0867 compiler: emit Neo.Crypto.ECDsaVerify syscall instead of CHECKSIG
Also change the name of `VerifySignature` interop, to match
syscall's name. It also accepts arguments in different order.
2020-04-13 13:47:39 +03:00
Evgenii Stratonikov
948729137f vm: remove HASH160/HASH256 opcodes 2020-04-13 13:47:39 +03:00
Evgenii Stratonikov
c23af595c9 core: implement Neo.Crypto.ECDsaCheckMultisig interop 2020-04-13 13:47:39 +03:00
Evgenii Stratonikov
5a30af2c75 core: implement Neo.Crypto.ECDsaVerify interop 2020-04-13 13:46:31 +03:00
Evgenii Stratonikov
1611ede58c crypto/keys: implement NewPublicKeyFromBytes()
It is convenient to have a single function instead of
allocating new `PublicKey` and using `DecodeBytes()` on it.
2020-04-13 13:13:15 +03:00
Anna Shaleva
d1f92a585b core: add NewTransactionFromBytes method to Transaction
Added `NewTransactionFromBytes(b []byte)` method to
transaction.Transaction in order to avoid code duplication.
2020-04-13 12:04:43 +03:00
Evgenii Stratonikov
30cc2c5783 core: move enumerator/iterator interops to a separate packages 2020-04-11 10:56:36 +03:00
Evgenii Stratonikov
7ffc6c0936 core: move interopContext to a separate package 2020-04-11 10:56:36 +03:00
Evgenii Stratonikov
90a08986d6 core: fix typo in function doc-comment 2020-04-11 10:56:36 +03:00
Evgenii Stratonikov
89d1f7ce75 core: remove unneeded comment
Serialization interops are already implemented.
2020-04-11 10:56:36 +03:00
Evgenii Stratonikov
a7c19d445b core: move Blockchainer interface to a separate package 2020-04-11 10:56:36 +03:00
Evgenii Stratonikov
efddcf3bfe core: remove interop methods from interopContext
If interops are defined as a separate functions
they can be implemented in a separate packages
which can help us to structure core.
2020-04-11 10:56:35 +03:00
Roman Khimov
5a22651e36
Merge pull request #784 from nspcc-dev/neo3/null
vm: support NULL stack item
2020-04-10 10:38:17 +03:00
Roman Khimov
bfaa025a34
Merge pull request #839 from nspcc-dev/feature/badgerdb_support
storage: add support of BadgerDB
2020-04-09 15:57:50 +03:00
Anna Shaleva
54cdfe4a23 storage: add support of BadgerDB
closes #820
2020-04-09 13:55:59 +03:00
Roman Khimov
54a95810a4
Merge pull request #833 from nspcc-dev/test/vm_calls
vm: missing tests for CALL* instructions
2020-04-09 12:12:41 +03:00
Anna Shaleva
9f0bc2aaf5 vm: add tests to CALL* instructions
closes #452
2020-04-09 11:20:39 +03:00
Evgenii Stratonikov
c71ad6a5db cli: output contract after compiling only with --verbose flag
Also remove Debug from compiler option as it is used only in CLI.
2020-04-08 13:09:51 +03:00
Evgenii Stratonikov
ee0ba9b1b4 core: make SpawnVM a method of context
spawnVMWithInterops is rather long too type and
it doesn't use Blockchain in any way.
2020-04-08 08:38:45 +03:00
Evgenii Stratonikov
a71cd0961e core/dao: remove unnecessary slice type
It is used only once, so a simple `sort.Slice`
invocation will suffice.
2020-04-08 08:38:45 +03:00
Evgenii Stratonikov
030b7754ad core: move DAO to a separate package 2020-04-08 08:38:44 +03:00
Anna Shaleva
495c1b0565 vm: add tests for missing bit and numeric operations
Added tests for:
  - bit operatoins: AND, OR, XOR
  - numeric operations: BOOLOR, MIN, MAX, WITHIN, NEGATE
2020-04-07 18:10:31 +03:00
Roman Khimov
4e0c3fab0f
Merge pull request #811 from nspcc-dev/feature/debug
compiler: support neo-debugger
2020-04-06 19:18:13 +03:00
Evgenii Stratonikov
da826522f8 compiler: set variable index on first declaration
This way variables will have indices corresponding to their
order of appearance in a source file.
2020-04-06 15:30:07 +03:00
Evgenii Stratonikov
457e7e006a compiler: support exporting method variables in debug info 2020-04-06 15:30:07 +03:00
Evgenii Stratonikov
5bdee683e6 cli,compiler: support emitting debug info in a file 2020-04-06 15:30:07 +03:00
Evgenii Stratonikov
5d3da26e1e compiler: support sequence points in debug info
Sequence points is a way to map a specific instruction offset
from a compiled contract to a text span in a source file.

This commit implements mapping only for `return` statements.
Further improvements are straight-forward.
2020-04-06 15:30:07 +03:00
Evgenii Stratonikov
24fef35ead compiler: split Compile info sub-functions
Also add tests for basic debug info.
2020-04-06 15:30:07 +03:00
Evgenii Stratonikov
00c40b58aa compiler: record basic debug info
Save info about method's byte-code sections.
2020-04-06 15:30:06 +03:00
Roman Khimov
9997661998
Merge pull request #821 from nspcc-dev/fix-cache-propagation-to-invocations
core: wrap cached dao properly, don't miss cached data
2020-04-06 11:52:41 +03:00
Evgenii Stratonikov
96806262bf vm: handle negative arguments in SHL/SHR
Do it as in reference implementation: a >> -b == a << b.
2020-04-06 10:46:35 +03:00
Roman Khimov
83a02f42f7
Merge pull request #825 from nspcc-dev/fix/compiler
compiler: accept varargs in `runtime.Notify`
2020-04-06 10:08:02 +03:00
Evgenii Stratonikov
1fcc019bf3 rpc: update test chain
Also provide info for getblockheader RPC while
generating test chain.
2020-04-06 09:31:09 +03:00
Evgenii Stratonikov
004023920e rpc: use Notify with varargs in the test contract 2020-04-06 09:31:09 +03:00
Evgenii Stratonikov
efad66aee1 compiler: make Notify accept varargs 2020-04-06 09:31:09 +03:00
Evgenii Stratonikov
0023c4f1f6 vm: use truncated division in MOD
Mimic C#'s `%` behavior.
Related 4b44190 (#773).
2020-04-06 09:30:48 +03:00
Roman Khimov
5f09381cf4 core: wrap cached dao properly, don't miss cached data
Fixes #817 where invoked contract missed updated account information because
it got it one layer below cachedDao used to process the block.
2020-04-03 10:15:11 +03:00
Evgenii Stratonikov
f7f48d0048 vm: implement ISNULL opcode 2020-04-02 14:15:17 +03:00
Evgenii Stratonikov
3db030bbb6 vm: implement PUSHNULL opcode 2020-04-02 14:15:17 +03:00
Evgenii Stratonikov
e50b529631 vm: implement Null item 2020-04-02 14:15:17 +03:00
Evgenii Stratonikov
6b7a57a66f smartcontract: add Any type for parameter
It is used as a wildcard for default return type of a contract and
for a Null stack item.
2020-04-02 14:15:17 +03:00
Roman Khimov
f64aa201c7
Merge pull request #819 from nspcc-dev/fix/util160_marshalling
smartcontract: fix uint160 marshalling in smartcontract.Parameter
2020-04-01 22:04:30 +03:00
Anna Shaleva
5a62eb923e smartcontract: fix uint160 marshalling in smartcontract.Parameter
There's a bug after #785: smartcontract.Parameter of type hash160 should
be marshalled in LE (as default marshaller for uint160 does) instead of
BE, so fixed.
2020-04-01 20:48:46 +03:00
Roman Khimov
2d0ad30fcf vm: rework Map with internal slice representation
Which makes iterating over map stable which is important for serialization and
and even fixes occasional test failures. We use the same ordering here as
NEO 3.0 uses, but it should also be fine for NEO 2.0 because it has no
defined order.
2020-04-01 19:33:53 +03:00
Roman Khimov
25201d480d smartcontract: simplify Array JSON marshalling 2020-04-01 19:21:00 +03:00
Roman Khimov
3dbe549a61 smartcontract: store MapType Parameter as a slice of KV pairs
Fixes #809.

Basically, there are three alternative approaches to fixing it:
 * allowing both []byte and string for ByteArrayType value
   minimal invasion into existing code, but ugly as hell and will probably
   backfire at some point
 * storing string values in ByteArrayType
   incurs quite a number of type conversions (and associated data copying),
   though note that these values are not changed usually, so dynamic
   properties of []byte are almost irrelevant here
 * storing only []byte values in ByteArrayType
   makes it impossible to use them as map keys which can be solved in several
   ways:
   - via an interface (Marshalable)
     which is good, but makes testing and comparing values in general harder,
     because of keys mismatch
   - using serialized Parameter as a key (in a string)
     which will need some additional marshaling/unmarshaling
   - converting MapType from map to a slice of key-value pairs
     not a bad idea as we don't use this map as a map really, the type
     itself is all about input/output for real VM types and this approach is
     also a bit closer to JSON representation of the Map
2020-04-01 19:21:00 +03:00
Evgenii Stratonikov
a43c9b9246 compiler: calculate stack size more precisely
When calculating number of local variables, only
defining assignments (i.e. via `:=`) must be taken into account.
2020-04-01 17:36:19 +03:00
Roman Khimov
9b5dab57e8
Merge pull request #810 from nspcc-dev/refactor/config
config: move config.go out of config
2020-04-01 10:29:57 +03:00
Anna Shaleva
5a984fdf88 config: move config.go out of config/
closes #423
2020-03-31 17:55:59 +03:00
Anna Shaleva
a8fa9c9244 vm: add tests to stack_item.go
closes #199
2020-03-31 17:18:13 +03:00
Roman Khimov
e41853d0a4
Merge pull request #789 from nspcc-dev/fix/tx_specific_data_marshalling
rpc: fix marshalling of type-specific tx data
2020-03-30 16:10:25 +03:00
Anna Shaleva
9c09ad9c89 rpc: fix marshalling of type-specific tx data
closes #585
2020-03-30 15:48:50 +03:00
Roman Khimov
6f13455cc9
Merge pull request #800 from nspcc-dev/fix/slice
compiler: declare compoud types with var keyword
2020-03-30 00:14:59 +03:00
Roman Khimov
92bafffcd8
Merge pull request #805 from nspcc-dev/fix-rpc-invocation-json
rpc: fix stack field name for invocation results
2020-03-29 13:41:46 +03:00
Roman Khimov
237de73dec
Merge pull request #807 from nspcc-dev/optimize-memcached-persist
storage: optimize (*MemCachedStore).Persist for memory-backed ps
2020-03-29 13:41:21 +03:00
Roman Khimov
0d482ceb7f
Merge pull request #808 from nspcc-dev/fix-map-serialization
vm: make map serialization more compatible with C#
2020-03-29 13:40:52 +03:00
Roman Khimov
665bf78d11 vm: make map serialization more compatible with C#
C# pushes value and key to the stack of non-serialized items, so key gets
serialized first followed by value. Fixes #806.

Notice though that neither IDictionary in C#, nor map in Go have elements
ordered, so we can easily get a difference in KV pairs order and it would be
impossible to fix.
2020-03-28 17:25:42 +03:00
Roman Khimov
4758de71ec storage: optimize (*MemCachedStore).Persist for memory-backed ps
Most of the time it's persisted into the MemoryStore or MemCachedStore, when
that's the case there is no real need to go through the Batch mechanism as it
incurs multiple copies of the data.

Importing 1.5M mainnet blocks with verification turned off, before:
real    12m39,484s
user    20m48,300s
sys     2m25,022s

After:
real    11m15,053s
user    18m2,755s
sys     2m4,162s

So it's around 10% improvement which looks good enough.
2020-03-28 17:21:50 +03:00
Roman Khimov
2316e2c4a7 rpc: fix stack field name for invocation results
Follow C# implementation:
https://docs.neo.org/docs/en-us/reference/rpc/latest-version/api/invokefunction.html
2020-03-28 13:59:42 +03:00
Anna Shaleva
0be237beb6 rpc: fix double-pointer bugs in RPC Client
Fixed double-pointer bug in following methods:
	- GetRawTransactionVerbose
	- GetBlockVerbose
	- GetBlockHeader
	- GetTxOut
	- ValidateAddress
2020-03-27 16:04:11 +03:00
Evgenii Stratonikov
3cbd138b67 compiler: allow to declare variables of struct type
Previously, struct variables were initialize with VM's nil value
which is of primitive type. Thus SETITEM used for struct's field
updating wasn't working.
2020-03-27 13:50:09 +03:00
Evgenii Stratonikov
6baed7a010 compiler: allow to declare slices of compound types
Previously this declarations were ignored which resulted
in runtime errors, because VM's nil is an element of primitive type
and can't be converted to an array.
2020-03-27 13:50:09 +03:00
Roman Khimov
c738975b7b
Merge pull request #803 from nspcc-dev/feature/appcall
emit: implement AppCallWithOperationAndArgs
2020-03-27 13:30:48 +03:00
Evgenii Stratonikov
db2dccf7cb emit: implement AppCallWithOperationAndArgs
It is nice to have a typical task of calling contract method
with specific arguments incapsulated inside some function.
2020-03-27 11:05:36 +03:00
Evgenii Stratonikov
0036b3e52b random: make use or random package in tests
Also implement Bytes/Fill routines for generating byte slices.
2020-03-27 10:27:46 +03:00
Evgenii Stratonikov
9abda40171 testserdes: implement helpers for encode/decode routines
Frequently one needs to check if struct serializes/deserializes
properly. This commit implements helpers for such cases including:
1. JSON
2. io.Serializable interface
2020-03-27 10:27:46 +03:00
Anna Shaleva
37cb60a0b5 compiler/interop: add missing methods to interop.Iterator
Add Next() and Value() to interop.Iterator and corresponding syscalls to
compiler
2020-03-26 16:39:10 +03:00
Evgenii Stratonikov
f0b6f783aa compiler: allow for loops with empty condition 2020-03-26 15:00:14 +03:00
Evgenii Stratonikov
4522eed1bb vm: fix offset for CALLI opcode
It is different from other JMP* and +2 should be added to the parameter.
2020-03-26 13:09:55 +03:00
Roman Khimov
396c78c722
Merge pull request #793 from nspcc-dev/update/boltdb
go.mod: update boltdb to v1.3.4

Related to #771.
2020-03-25 17:33:54 +03:00
Evgenii Stratonikov
4e92642dec rpc: allow to unmarshal integer params from string 2020-03-25 17:23:13 +03:00
Evgenii Stratonikov
fcc4877f43 go.mod: update boltdb to v1.3.4
Also import lib as declared in it's go.mod:
via `go.etcd.io/bbolt`.
2020-03-25 17:07:54 +03:00
Evgenii Stratonikov
5f876aaeda smartcontract: do not require pointer in MarshalYAML
It is a single byte anyway.
Now `contract init` works properly.
2020-03-25 16:26:39 +03:00
Evgenii Stratonikov
43495a49f4 rpc: reuse handlers map for prometheus metrics 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
57f37bc7a0 rpc: add metrics for invoke* RPCs 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
2ed417388b rpc: unify RPC handlers
Move all of them to a map. This can make it easier
to add/remove RPC based on plugins and makes code less verbose.
2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
8236217a01 rpc: make all handler have the same signature 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
6e801d33f0 rpc: make a separate handler for every RPC
Move getbestblockhash, getblockcount, getconnectioncount RPC.
2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
969ed6e6e1 rpc: move getaccountstate/getunspents RPCs to a separate func 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
2ec5b9f08a rpc: move getblock RPC to a separate func 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
e442ebdb69 rpc: move getblockhash RPC to a separate func 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
90fdde4018 rpc: move getversion RPC to a separate func 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
99d02d5de0 rpc: move getpeers RPC to a separate func 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
dfb4171e3c rpc: move getrawmempool RPC to a separate func 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
4e25c9121b rpc: move validateaddress RPC to a separate func 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
70eb0b175a rpc: move getassetstate RPC to a separate func 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
9e6785bed9 rpc: unify counter metrics update 2020-03-25 15:25:12 +03:00
Evgenii Stratonikov
c992d6c518 core: reuse buffer in (*cacheddao).Persist()
When serializing multiple accounts, cost of a buffer grow
can become significant. This commit tries to amortize it by
reusing the same buffer in a single `Persist()` call.
2020-03-25 13:13:54 +03:00
Anna Shaleva
6998c5044b rpc: add testing infrastructure to RPC client package
closes #716

NOTE: RPC client tests contain `serverResponse` json data fetched from examples
published in official C# JSON-RPC API v2.10.3 reference
(see https://docs.neo.org/docs/en-us/reference/rpc/latest-version/api.html)
2020-03-24 16:02:08 +03:00
Anna Shaleva
8e05bfe99c rpc/crypto: fix validator field marshalling in getvalidators RPC server
Problem: wrong `PublicKey` field json marshalling of result.Validator

Solution: add marshaller to publickey (crypto)
2020-03-24 15:52:51 +03:00
Anna Shaleva
ca12c75b12 rpc: fix name of json nep5balance field
Problem: wrong json field name of result.NEP5Balances.Balances
(see for details:
https://github.com/neo-project/neo-modules/blob/master-2.x/RpcNep5Tracker/RpcNep5Tracker.cs#L295)

Solution: rename field from `balances` to `balance` to be consistent with C# client
2020-03-24 14:55:20 +03:00
Anna Shaleva
4911837949 rpc: fix wrong script marshalling in getcontractstate RPC server
problem: `script` field of result.ContractState is marshalled as []byte

solution: add marshaller for result.ContractState
2020-03-24 14:55:20 +03:00
Anna Shaleva
79f7862496 rpc: fix blockheader marshalling in getblockheader RPC server
Problem: wrong json marshalling of `nextconsensus` field of
result.Header

Solution: change field type from util.uint160 to address string
2020-03-24 14:55:20 +03:00
Roman Khimov
751e79d480
Merge pull request #785 from nspcc-dev/feature/uint160_marshalling
util: JSONify uint160 using LE instead of BE
2020-03-24 12:41:07 +03:00
Evgenii Stratonikov
dc8fb13021 vm: make NewBigInteger accept int64
It is more correct upconvert to int64 if needed,
so precision is never lost.
2020-03-24 11:10:56 +03:00
Roman Khimov
5148b98f43
Merge pull request #773 from nspcc-dev/fix/bigint
vm: use truncated division for Integers
2020-03-23 18:01:21 +03:00
Anna Shaleva
2187346158 rpc: fix json marshalling of result.AssetState
Modified result.AssetState:
	- removed `FeeMode` and `FeeAddress` fields
	- fixed json name of `ID` and `AssetType` fields
to be consistent with C# RPC server
2020-03-23 17:44:15 +03:00
Anna Shaleva
2001a40312 util: JSONify uint160 using LE instead of BE
closes #769
2020-03-23 17:38:58 +03:00
Evgenii Stratonikov
6ed2bd63b9 core: marshal AppExecResult.Stack as an array
Closes #782.
2020-03-23 16:27:47 +03:00
Evgenii Stratonikov
6ac69d075e smartcontract: implement io.Serializable for Parameter 2020-03-23 16:27:47 +03:00
Evgenii Stratonikov
0f17b9be1d smartcontract: use int64 for Integer parameter value 2020-03-23 16:24:57 +03:00
Roman Khimov
b37c5939f8
Merge pull request #780 from nspcc-dev/fix/776
vm: allow to push integer-like items to stack
2020-03-18 13:27:31 +03:00
Evgenii Stratonikov
954e8cdcf1 vm: allow to push integer-like items to stack
Perform automatic conversion of non-standard integer types to
int64 if possible.

Closes #776.
2020-03-18 12:58:31 +03:00
Evgenii Stratonikov
9666e99a17 smartcontract: marshal Integer values to JSON-strings
It is done so in C# implementation, we better be
as compatible as possible.
Closes #770.
2020-03-18 11:58:17 +03:00
Evgenii Stratonikov
1e7b47ec05 smartcontract: always use int64 for integers
It is good when internal representation is unique.
2020-03-18 11:58:17 +03:00
Roman Khimov
8400f0add2 mempool: gofmt -s 2020-03-17 16:47:51 +03:00
Evgenii Stratonikov
4b44190485 vm: use truncated division for Integers
When divisor is negative, the result is truncated towards
zero.
2020-03-17 15:45:56 +03:00
Evgenii Stratonikov
dfbb84ef38 rpc: support https
Allow to start TLS RPC server on a separate port.
Closes #702.
2020-03-17 12:44:23 +03:00
Roman Khimov
ec76a0bf15 mempool: disallow more than one issue tx at once
Technically they could conflict for available asset amount, but as they're
very rare (and even can be considered obsolete) we can simplify this check.
2020-03-17 11:40:01 +03:00
Roman Khimov
d5d0479671 core: verify results of issue transaction
It shouldn't try to issue more tokens than there is available.
2020-03-17 11:40:01 +03:00
Roman Khimov
10601cb375 core: add issuer hashes into the verification list for Issue TX
As it should be done.
2020-03-17 11:40:00 +03:00
Roman Khimov
dca637d2d0 core: add owner hash to verified list for Register TX
As it should be done.
2020-03-17 11:37:02 +03:00
Roman Khimov
77a799f7d0 core: add missing state tx verifications 2020-03-16 20:14:59 +03:00
Roman Khimov
6ede65610d core: add appropriate hashes to check for State TX
These checks are important for proper transaction verification.
2020-03-16 19:52:28 +03:00
Roman Khimov
a5e862c351 rpc/client: add TransferNEP5 method to easily transfer tokens
We have TransferAsset for regular tokens, so it'd be nice to have TransferNEP5
for NEP5 ones. Relates to #599.
2020-03-16 17:52:32 +03:00
Evgenii Stratonikov
9a41ffb9fb wallet: support token removal
Also add tests for Add/RemoveToken
2020-03-16 15:12:50 +03:00
Evgenii Stratonikov
03d0a6519a wallet: support account removal 2020-03-16 15:12:50 +03:00
Evgenii Stratonikov
b193e78def core: remove duplication from IsDoubleClaim/IsDoubleSpend 2020-03-16 14:11:19 +03:00
Evgenii Stratonikov
cdf025bf89 transaction: implement AddVerificationHash() method 2020-03-16 14:11:19 +03:00
Roman Khimov
e9429374aa
Merge pull request #756 from nspcc-dev/feature/unclaimed
core/state: do not unmarshal Unclaimed balances in account
2020-03-16 13:21:23 +03:00
Roman Khimov
cff6e226dd
Merge pull request #760 from nspcc-dev/fix-contract-storage-migration
core: fix contract's state migration and don't swallow errors
2020-03-16 12:25:15 +03:00
Evgenii Stratonikov
e503d1001d core/state: do not unmarshal Unclaimed balances in account 2020-03-16 12:19:32 +03:00
Roman Khimov
e6e8761d35 core: fix contract's state migration and don't swallow errors
Fixes difference in state changes at mainnet's block 2442790 because contract
migration in b4eb2dc35226e6520ee4e09a56197dff91547b50a7f57edc82930fc18c75dffc
doesn't actually transfer the storage state, it only deletes the old one.

And add an error check just in case.
2020-03-16 11:52:09 +03:00
Evgenii Stratonikov
66727ab8fa rpc: marshal Asset hash in LE in getnep5balances RPC 2020-03-16 10:14:55 +03:00
Roman Khimov
ba1c3bfccb
Merge pull request #758 from nspcc-dev/rpc-fix-hash160
rpc: fix invocations of contracts using hash160
2020-03-13 16:50:31 +03:00
Roman Khimov
c8f4eee5f4 rpc: fix invocations of contracts using hash160
ERROR   Error encountered with rpc request      {"error": "expected string size of 40 got 42",...
2020-03-13 16:47:08 +03:00
Anna Shaleva
784bac0b38 rpc: bug with empty stack marshalling in getapplicationlog
Problem: cannot marshall empty raw message from appExecResult.Stack

Solution: add handler for case when appExecResult.Stack is an empty string
2020-03-13 12:50:51 +03:00
Roman Khimov
d9a83373ed
Merge pull request #748 from nspcc-dev/feature/splitnep5
core: store NEP5 balances separately from account
2020-03-12 18:31:25 +03:00
Evgenii Stratonikov
ac475940a0 core: cache NEP5Transfers in cached DAO 2020-03-12 17:16:11 +03:00
Evgenii Stratonikov
6fa2a998f4 core: cache NEP5Balances in cached DAO 2020-03-12 17:06:20 +03:00
Roman Khimov
734778c1f9
Merge pull request #747 from nspcc-dev/fix-contract-deploy-gas-parameter
Use wallet in smartcontract deploy/invoke commands and calculate GAS properly
2020-03-12 17:00:04 +03:00
Roman Khimov
25da5a30d8 cli: change deploy and invoke commands to use wallet
Passing WIF directly in the command line is not something we should be doing.

Also split netfee and sysfee in the RPC as they're different (and add a script
attribute for free transactions).
2020-03-12 16:19:12 +03:00
Anna Shaleva
307b3b162b rpc: implement missing RPC client methods
Implemented following RPC client methods:
	- getapplicationlog
	- getassetstate
	- getbestblockhash
	- getblockcount
	- getblockhash
	- getblockheader
	- getblocksysfee
	- getconnectioncount
	- getcontractstate
	- getpeers
	- getrawmempool
	- getstorage
	- gettransactionheight
	- gettxout
	- getunclaimed
	- getvalidators
	- getversion
	- submitblock
	- validateaddress
2020-03-12 15:56:59 +03:00
Evgenii Stratonikov
6e0a57075f *: gofmt 2020-03-12 14:51:13 +03:00
Evgenii Stratonikov
32401a567e core: store NEP5Transfers in batches
This is an append-only log which is read only during some RPCs.
It is rather slow to get it from base every time we need to append to
it. This commit stores all NEP5Transfers in batches, so that
only a last batch needs to be unmarshaled during block processing.
2020-03-12 14:51:12 +03:00
Evgenii Stratonikov
3c6d9653b0 core/state: add Size() method to NEP5TransferLog 2020-03-12 12:58:30 +03:00
Evgenii Stratonikov
df2598c8dc core: store NEP5 balances separately
There is no need to take and unmarshal an account structure only
to get it's NEP5 balances.
2020-03-12 12:58:28 +03:00
Evgenii Stratonikov
d25dddc780 rpc: refactor getDecimals
Use existing functions to invoke smartcontract's
method instead of constructing ad-hoc script.
2020-03-12 12:19:31 +03:00
Evgenii Stratonikov
05544a1510 rpc: return empty arrays instead of null in getnep5* RPCs 2020-03-12 12:19:30 +03:00
Roman Khimov
1b5dd53e07
Merge pull request #746 from nspcc-dev/fix/equal
vm: implement EQUAL opcode properly

Fixes #745, #749.
2020-03-12 11:46:51 +03:00
Roman Khimov
bbd802681e cli: make gas parameter to deployment add gas to the base price
That's how it was intended to behave originally. One thing questionable here
is contract price (policy thing, basically) being moved to smartcontract
package, but it's probably fine for NEO 2.0 (as it won't change) and we'll
make something better for NEO 3.0.
2020-03-11 20:34:36 +03:00
Roman Khimov
695c4dd6ae
Merge pull request #744 from nspcc-dev/feature/getunclaimed
rpc: implement getunclaimed
2020-03-11 19:18:36 +03:00
Anna Shaleva
c23a522d25 rpc: implement getunclaimed
closes #712
2020-03-11 18:33:15 +03:00
Roman Khimov
5f1868af28
Merge pull request #743 from nspcc-dev/optimize-some-db-accesses
Optimize some db accesses
2020-03-11 17:33:36 +03:00
Roman Khimov
abd7855890
Merge pull request #742 from nspcc-dev/add-dynamic-appcall
vm: add support for dynamic invocations in APPCALL
2020-03-11 17:27:05 +03:00
Evgenii Stratonikov
dfc59129c7 vm: implement EQUAL opcode properly
When comparing elements of different types, conversions
should be performed. This commit implement custom equality
predicate for each stack item type.
2020-03-11 17:19:10 +03:00
Evgenii Stratonikov
5da82e8cf0 vm: add TryBytes() to StackItem interface
Conversion should be done in a StackItem, not in an Element.
2020-03-11 16:33:46 +03:00
Roman Khimov
8c902a7223 core: cache UnspentCoins in cachedDao
1.5M block import time (VerifyBlocks disabled) on AMD Ryzen 5 1600/16GB/HDD,
before:
real    159m16.551s
user    69m58.279s
sys     7m34.334s

after:
real    139m41.836s
user    67m12.477s
sys     6m19.420s

12% which is even a bit more than could be expected from inputs analysis (that
has around 10% cache hits for a block-wide cache), worth doing.
2020-03-11 12:40:02 +03:00
Roman Khimov
23464401bc core/state: merge spent and unspent coins state, use it to store more things
This change reduces pressure on DB by doing the following things:
 * not storing additional KV pair for SpentCoin
 * storing Output right in the UnspentCoin, thus eliminating the need to get a
   full transaction from DB

At the same time it makes UnspentCoin more fat and hot, but it should probably
worth it.

Also drop `GetUnspentCoinStateOrNew` as it shouldn't ever existed, UTXOs
can't come out of nowhere.

1.5M block import time (VerifyBlocks disabled) on AMD Ryzen 5 1600/16GB/HDD,
before:
real    302m9.895s
user    96m17.200s
sys     13m37.084s

after:
real    159m16.551s
user    69m58.279s
sys     7m34.334s

So it's almost two-fold which is a great improvement.
2020-03-11 12:40:02 +03:00
Roman Khimov
e1f194ea7b core: treat state.Coin as a bitfield
As it was intended to.
2020-03-11 12:22:57 +03:00
Roman Khimov
377fb382aa core: move (un)SpentCoin structs into the state package
As they're all about the state.
2020-03-11 12:22:52 +03:00
Roman Khimov
aab7dd515f
Merge pull request #728 from nspcc-dev/feature/nep5cli
cli: implement NEP5-related commands
2020-03-10 18:10:00 +03:00
Roman Khimov
b7fa8dd40f
Merge pull request #741 from nspcc-dev/fix/network
network: fix possible deadlock in DefaultDiscovery
2020-03-10 17:29:45 +03:00
Roman Khimov
8318adac56 vm: add support for dynamic invocations in APPCALL
Fixes #740.
2020-03-10 17:17:36 +03:00
Evgenii Stratonikov
b7dee156e2 network: fix a deadlock in DefaultDiscovery
Why a deadlock can occur:
1. (*DefaultDiscovery).run() has a for loop over requestCh channel.
2. (*DefaultDiscovery).RequestRemote() send to this channel while
    holding a mutex.
3. (*DefaultDiscovery).RegisterBadAddr() tries to take mutex for write.
4. Second select-case can't take mutex for read because of (3).
2020-03-10 15:40:23 +03:00
Evgenii Stratonikov
2a1402f25d compiler: clean up stack on branch statements
When `return` or `break` statement is encountered inside
a for/range/switch statement, top stack items can be auxilliary.
They need to be cleaned up before returning from the function.
2020-03-10 15:26:00 +03:00
Evgenii Stratonikov
22e99a5b3e rpc: implement (*Client).NEP5TokenInfo()
It can be useful to receive all NEP5 token info at once.
2020-03-10 13:02:14 +03:00
Evgenii Stratonikov
564a8e429d wallet: allow to add token contracts to the wallet 2020-03-10 13:02:14 +03:00
Evgenii Stratonikov
d447064515 util: implement FixedN from string
When working with NEP5 contracts we frequently need
to parse fixed-point decimals with arbitrary precision.
2020-03-10 13:02:14 +03:00
Evgenii Stratonikov
cdeba6d417 rpc: implement (*Client).NEP5* methods 2020-03-10 13:02:14 +03:00
Evgenii Stratonikov
ebf867b11d state: add a test for NEP5Transfer size
It's size is used in NEP5TransferLog so we need to be
sure it reflects reality.
2020-03-10 13:02:14 +03:00
Roman Khimov
15a5c7f3d6
Merge pull request #738 from nspcc-dev/feature/fallthrough
compiler: implement fallthrough in switch
2020-03-10 12:44:35 +03:00
Evgenii Stratonikov
91301df161 compiler: implement fallthrough in switch
Closes #628.
2020-03-10 12:34:07 +03:00
Roman Khimov
ee57b96566
Merge pull request #733 from nspcc-dev/fix-getreferences-interop-regression
Fix GetReferences interop regression
2020-03-10 10:27:36 +03:00
Roman Khimov
0e2bda4f21 core: drop txHash from SpentCoinState
It's a key for it, makes no sense storing it as data.
2020-03-09 16:58:21 +03:00
Roman Khimov
eb404ceae3 core: fix max contract description limit check
It differs from other parameters in C# code. Fixes #735.
2020-03-09 14:18:51 +03:00
Roman Khimov
4587121c7f core: fix error propagation in contract-related interops
Obvious bug that hides failed contract deployments.
2020-03-09 14:18:00 +03:00
Roman Khimov
4b83e9a5cd
Merge pull request #732 from nspcc-dev/feature/getvalidators
rpc: implement getvalidators
2020-03-07 21:43:38 +03:00
Anna Shaleva
456a2d55fd rpc: implement getvalidators
closes #714
2020-03-07 18:05:40 +03:00
Roman Khimov
baeaa3dbe6 core: optimize tx verification, only get references and results once
Getting references requires DB access and that is expensive.
2020-03-06 20:15:01 +03:00
Evgeniy Kulikov
b34ac22434
[rpc/server] fix getblock verbose response
- Nonce should not trim leading zeros
- NextConsensus should returns address (uint160 -> base58)
2020-03-06 19:53:11 +03:00
Roman Khimov
fe4916f691 core: simplify GetTransactionResults() a bit
Make less movements.
2020-03-06 19:26:39 +03:00
Roman Khimov
ced5ddbb9e core: fix wrong references ordering in interop function
Broken by 9f7018503a. Almost the same problem as
in 01082a8988 (though it is deterministic now,
just not the way the contract expects).
2020-03-06 19:20:55 +03:00
Roman Khimov
0e8ff558d1
Merge pull request #727 from nspcc-dev/fix-wrong-endian-in-interop-hashes
core: fix wrong endian used in interop functions
2020-03-06 19:07:28 +03:00
Roman Khimov
f8eee778f4
Merge pull request #724 from nspcc-dev/feature/submitblock
rpc: implement submitblock
2020-03-06 12:08:45 +03:00
Anna Shaleva
2031d8d103 rpc: add custom errors to sendrawtransaction
In case of unsuccessful relyReason sendRawTransaction should return
errors with codes [-500, ..., -505] instead of error with code -32603
2020-03-06 12:04:51 +03:00
Roman Khimov
b4eb05c1c1
Merge pull request #730 from nspcc-dev/feature/optimize
core: get rid of unnecessary copies
2020-03-06 12:03:38 +03:00
Anna Shaleva
a746d8e6e6 rpc: implement submitblock RPC
closes #344
2020-03-06 12:03:08 +03:00
Evgenii Stratonikov
40188c5400 core: get rid of unnecessary copies
There is no need to keep Balances and Unclaimed slices
sorted, we need only to remove a single element.
2020-03-05 20:42:20 +03:00
Anna Shaleva
d3063c26e1 core: add custom error to blockhain.go
Add InvalidBlockIndex error to AddBlock func
2020-03-05 20:30:19 +03:00
Roman Khimov
a9abd3d841 core: fix wrong endian used in interop functions
C# uses ToArray() or UintXXX(bytes) here which interprets hashes as they
should be interpreted (BE, although they always convert to LE when converting
to String just for the fun of it). It leads to state difference for us at
block 2025204 where even though we have the same value for the key, the key
itself differs, ours:

dd2b538e2a0c1db1ae5061c15be14f916bd1e678e512ffcda6d9499d8e7fe97ee71fd6b8004583d9afe09cc4dadbd5deb63d01e061009b7cffdaa674beae0f930ebe6085af900093e5fe56b34a5c220ccdcf6efc336fc5000000000000000000000000000000000010

theirs:

dd2b538e2a0c1db1ae5061c15be14f916bd1e67861e0013db6ded5dbdac49ce0afd9834500b8d61fe77ee97f8e9d49d9a6cdff12e5009b7cffdaa674beae0f930ebe6085af900093e5fe56b34a5c220ccdcf6efc336fc5000000000000000000000000000000000010

In this key there is a tx hash encoded
(e512ffcda6d9499d8e7fe97ee71fd6b84583d9afe09cc4dadbd5deb63d01e061 in LE used
by all the tools like neoscan).

I love Neo.
2020-03-05 19:44:09 +03:00
Anna Shaleva
ccd88c3af8 rpc: implement gettransactionheight
closes #713
2020-03-05 19:34:11 +03:00
Anna Shaleva
5cfa1bc2a8 rpc: fixed getblockheader tests 2020-03-05 19:16:22 +03:00
Roman Khimov
fbdc60b731
Merge pull request #723 from nspcc-dev/feature/nep5
core,rpc: implement NEP5-related logic
2020-03-05 18:33:58 +03:00
Evgenii Stratonikov
c019ce565f rpc: move test contract hash to constant
When changing test chain it can be rather annoying
to replace all of the occurences of the contract hash.
2020-03-05 18:26:55 +03:00
Evgenii Stratonikov
547bd3bde3 rpc: display for NEP5 token amount properly
Every NEP5 contract MUST have `decimals` method which
is used to properly display token amount.
2020-03-05 18:22:40 +03:00
Evgenii Stratonikov
95a8fa234f rpc: implement getnep5transfers RPC 2020-03-05 18:22:40 +03:00
Evgenii Stratonikov
2757882d26 rpc: implement getnep5balances RPC 2020-03-05 18:22:40 +03:00
Evgenii Stratonikov
6d270c4550 core,rpc: add NEP5 contract to testdata
Also transfer tokens between accounts.
2020-03-05 18:22:40 +03:00
Evgenii Stratonikov
b945f4346a smartcontract: marshal Arrays properly 2020-03-05 18:22:40 +03:00
Evgenii Stratonikov
f92fd3c948 core: track NEP5 transfers 2020-03-05 18:22:40 +03:00
Evgenii Stratonikov
e8c4179a9c core: track NEP5 balances 2020-03-05 18:22:19 +03:00
Roman Khimov
b273f3126a
Merge pull request #722 from nspcc-dev/feature/getblockheader
rpc: implement getblockheader RPC
2020-03-05 17:18:54 +03:00
Roman Khimov
44c392450a
Merge pull request #721 from nspcc-dev/fix-panic-in-tcptransport-close
network: add a nil check in (*TCPTransport).Close, prevent panic
2020-03-05 16:02:15 +03:00
Evgenii Stratonikov
3a510b9dad core: allow transfer amount to be bytes
VM can produce both big.Int and []byte because they
are converted to each other on demand.
2020-03-05 15:18:38 +03:00
Anna Shaleva
42e2aff381 rpc: implement getblockheader RPC
closes #711
2020-03-05 14:47:45 +03:00
Roman Khimov
d03b2ef4a1
Merge pull request #706 from nspcc-dev/feature/transfer
cli: implement transfer from multisig accounts
2020-03-05 12:28:01 +03:00
Roman Khimov
31948ee4a7 network: add a nil check in (*TCPTransport).Close, prevent panic
You have to try to trigger that, but in the event of server shutdown before it
actually started listening Close will easily panic like this:

2020-03-05T11:48:08.660+0300    INFO    node started    {"blockHeight": 6458, "headerHeight": 15605}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x9d5f0a]

goroutine 1 [running]:
github.com/nspcc-dev/neo-go/pkg/network.(*TCPTransport).Close(0xc000fd7050)
        /home/rik/dev/neo-go/pkg/network/tcp_transport.go:78 +0x2a
github.com/nspcc-dev/neo-go/pkg/network.(*Server).Shutdown(0xc000182280)
        /home/rik/dev/neo-go/pkg/network/server.go:190 +0x189
github.com/nspcc-dev/neo-go/cli/server.startServer(0xc000200160, 0x0, 0x0)
        /home/rik/dev/neo-go/cli/server/server.go:367 +0x79e
github.com/urfave/cli.HandleAction(0xb84860, 0xccf240, 0xc000200160, 0xc0001c4500, 0x0)
        /home/rik/dev/neo-go/vendor/github.com/urfave/cli/app.go:490 +0xc8
github.com/urfave/cli.Command.Run(0xc9a160, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0xca407f, 0x10, 0x0, ...)
        /home/rik/dev/neo-go/vendor/github.com/urfave/cli/command.go:210 +0x996
github.com/urfave/cli.(*App).Run(0xc0001d64e0, 0xc0000ca000, 0x3, 0x3, 0x0, 0x0)
        /home/rik/dev/neo-go/vendor/github.com/urfave/cli/app.go:255 +0x6af
main.main()
        /home/rik/dev/neo-go/cli/main.go:25 +0x505
2020-03-05 11:53:26 +03:00
Roman Khimov
5c781be08d
Merge pull request #718 from nspcc-dev/fix-invocation-tx-checks-and-fee
Fix Invocation TX checks and fee
2020-03-05 11:51:51 +03:00
Roman Khimov
2032dd8e9f
Merge pull request #720 from nspcc-dev/fix-keycache-concurrent-access
core: protect (*Blockchain).keyCache with a lock
2020-03-05 11:46:23 +03:00
Evgenii Stratonikov
85755a4628 smartcontract: implement (*ParameterContext).GetWitness()
After all signatures were accumulated it should be possible
to extract Witness for the verifiable item.
2020-03-05 09:45:33 +03:00
Evgenii Stratonikov
cd487e3ad4 smartcontract: implement (*ParameterContext).AddSignature() 2020-03-05 09:45:11 +03:00
Evgenii Stratonikov
44901ca867 wallet: export contractParam
It is needed to be able to create Contracts
from the outside.
2020-03-05 09:43:14 +03:00
Evgenii Stratonikov
0d419d3899 smartcontract: implement ParameterContext 2020-03-05 09:43:14 +03:00
Evgenii Stratonikov
8819d4f970 vm: implement ParseMultisigContract()
When creating witness for a multisig contract, it is
needed to extract the order of public keys from it.
2020-03-05 09:43:14 +03:00
Roman Khimov
9ac8001c7d core: protect (*Blockchain).keyCache with a lock
Avoid failures like this:
fatal error: concurrent map writes

goroutine 103 [running]:
runtime.throw(0xca6fe3, 0x15)
        /usr/lib64/go/1.12/src/runtime/panic.go:617 +0x72 fp=0xc000687988 sp=0xc000687958 pc=0x42d8d2
runtime.mapassign(0xb9d4a0, 0xc0000b1f80, 0xc000687a6c, 0x13bd940)
        /usr/lib64/go/1.12/src/runtime/map.go:590 +0x5e3 fp=0xc000687a10 sp=0xc000687988 pc=0x40e2a3
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).verifyHashAgainstScript(0xc0000f8000, 0x1300d1f5a3d348be, 0x78607089e4fe9fab, 0xc0a21e4f71, 0xc000d16070, 0x1e2b8881f8178e92, 0xd589cfa965287bb8, 0x24a4e4f292ebc797, 0xb90d3120d878e619, 0xc0001d01e0, ...)
        /home/rik/dev/neo-go/pkg/core/blockchain.go:1866 +0x371 fp=0xc000687ad8 sp=0xc000687a10 pc=0x984ed1
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).verifyHeaderWitnesses(0xc0000f8000, 0xc000d16000, 0xc00042d950, 0x1, 0xc00008a6c0)
        /home/rik/dev/neo-go/pkg/core/blockchain.go:1914 +0x209 fp=0xc000687c90 sp=0xc000687ad8 pc=0x985999
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).verifyHeader(0xc0000f8000, 0xc000d16000, 0xc00042d950, 0xf0ee0049d611101f, 0xf8967398a8f9351b)
        /home/rik/dev/neo-go/pkg/core/blockchain.go:1254 +0x235 fp=0xc000687d70 sp=0xc000687c90 pc=0x97e4e5
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).addHeaders(0xc0000f8000, 0x1, 0xc000d12000, 0x7d0, 0x7d0, 0x0, 0x1)
        /home/rik/dev/neo-go/pkg/core/blockchain.go:369 +0x266 fp=0xc000687e68 sp=0xc000687d70 pc=0x973f46
github.com/nspcc-dev/neo-go/pkg/core.(*Blockchain).AddHeaders(0xc0000f8000, 0xc000d12000, 0x7d0, 0x7d0, 0x0, 0xc0003640c0)
        /home/rik/dev/neo-go/pkg/core/blockchain.go:338 +0x51 fp=0xc000687eb0 sp=0xc000687e68 pc=0x973cb1
github.com/nspcc-dev/neo-go/pkg/network.(*Server).handleHeadersCmd(0xc00022c140, 0xdd0ca0, 0xc000374000, 0xc00000c020)
        /home/rik/dev/neo-go/pkg/network/server.go:431 +0x74 fp=0xc000687fc0 sp=0xc000687eb0 pc=0x9ce5e4
runtime.goexit()
        /usr/lib64/go/1.12/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc000687fc8 sp=0xc000687fc0 pc=0x45ca51
created by github.com/nspcc-dev/neo-go/pkg/network.(*Server).handleMessage
        /home/rik/dev/neo-go/pkg/network/server.go:705 +0xa4a
...
2020-03-04 20:26:18 +03:00
Evgenii Stratonikov
acea3867b2 smartcontract: implement ContextItem 2020-03-04 20:01:26 +03:00
Evgenii Stratonikov
46db4e9d9d smartcontract: rename param_context.go to parameter.go 2020-03-04 20:01:26 +03:00
Evgenii Stratonikov
924d920423 smartcontract: support JSON unmarshaling of Signature param 2020-03-04 20:01:26 +03:00
Evgenii Stratonikov
7eaeb18f18 transaction: marshal ContractTX even if Data is nil
It contains no information so it doesn't matter anyway.
2020-03-04 20:01:26 +03:00
Evgenii Stratonikov
634e9483d3 transaction: unmarshal Witness properly
Both verification and invocation scripts need to
be unmarshaled from hex.
Also fix failing RPC tests: block contains non-pointer
`transaction.Witness` field and (*Witness).MarshalJSON method
is not called.
2020-03-04 20:01:26 +03:00
Evgenii Stratonikov
33f99104e8 transaction: unmarshal Output properly
Address is marshaled in base58 and needs to be
decoded accordingly.
2020-03-04 20:01:26 +03:00
Evgenii Stratonikov
b4f8d66bd3 smartcontract: allow to marshal nil parameters 2020-03-04 19:55:04 +03:00
Evgenii Stratonikov
7cde58f731 smartcontract: adjust parameter value to type properly 2020-03-04 19:49:50 +03:00
Roman Khimov
81d89cd502 core: fix SystemFee calculation for Invocation TXes
They have it specified right in the transaction. Unfortunately, this little
change rendered invalid our RPC test chain, but I think it became even better
after it, especially given that chain generation is a nice test by itself, so
it should be running as a regular test.
2020-03-04 19:23:23 +03:00
Roman Khimov
ae6edf0601 core: add a check for fractional gas in invocation TXes
It's not allowed in C# code and that's reasonable as it's a sysfee essentially
that can only be integer.
2020-03-04 19:23:23 +03:00
Roman Khimov
823798514a util: rename Int64Value to IntegralValue, add FractionalValue
Makes it's interface more clear and allows to easily access fractional part.
2020-03-04 19:23:23 +03:00
Roman Khimov
7cc847d655 transaction: add some missing InvocationTX decoding checks
Script must have something inside and GAS can't be negative.
2020-03-04 19:23:23 +03:00
Roman Khimov
a9d8c9e0d3 rpc/client: implement GetRawTransaction, fix #586 2020-03-03 20:43:57 +03:00
Roman Khimov
f01766131b rpc/client: add a set of GetBlock methods
They differ in input and output types (and data), thus four methods are
added.
2020-03-03 20:26:56 +03:00
Roman Khimov
685e34d83c rpc: update client documentation
Add missing methods, move example into something that can be compiled (and fix
it along the way).
2020-03-03 18:59:21 +03:00
Roman Khimov
f747b39bc6 docs: update RPC server documentation, add missing methods
And drop doc.go from server package as it duplicates docs/rpc.md and has no
value of its own (TODO list is managed with GitHub issues, really). Also, RPC
server is not really expected to be used by non-neo-go packages (contrary to
the client).
2020-03-03 18:18:56 +03:00
Roman Khimov
f5a1b928ce pkg: fix gofmt issues 2020-03-03 17:22:15 +03:00
Roman Khimov
e41d434a49 *: move all packages from CityOfZion to nspcc-dev 2020-03-03 17:21:42 +03:00
Roman Khimov
59e6dac351
Merge pull request #708 from nspcc-dev/fix/trigger
core: convert trigger.Type to byte when pushing on stack
2020-03-03 16:17:01 +03:00
Evgenii Stratonikov
fe3bbbd78a core: convert trigger.Type to byte when pushing on stack 2020-03-03 16:13:19 +03:00
Roman Khimov
032cb513a6
Merge pull request #707 from nspcc-dev/skip-outdated-headers-on-add
core: don't reverify stale headers in addHeader
2020-03-03 15:43:40 +03:00
Roman Khimov
4c8d327353 rpc: drop duplicating Invoke* structures
And use smartcontract.Parameter instead of vm.StackItem where
appropriate. Closes #689.
2020-03-03 15:38:03 +03:00
Roman Khimov
56e37ad6ba vm: drop duplicating stackItem structure, build JSON from Parameters
smartcontract.Parameter has everything needed now.
2020-03-03 15:38:03 +03:00
Roman Khimov
9b4fd99fbc vm: break circular references when recursing into ToContractParameters
Reference types can have circular pointers to each other, thus we need to
control recursion.
2020-03-03 15:38:03 +03:00
Roman Khimov
c3e73c5b7d core: don't reverify stale headers in addHeader
During networked synchronization we expect there to be a lot of duplicate
headers received and it makes no sense for us reverifying them.
2020-03-03 15:34:03 +03:00
Roman Khimov
3282c6ed41
Merge pull request #704 from nspcc-dev/feature/getrawmempool
rpc: implement getrawmempool RPC
2020-03-02 19:44:19 +03:00
Anna Shaleva
e1fe12a07f rpc: implement getrawmempool RPC
closes #175
2020-03-02 19:35:51 +03:00
Evgenii Stratonikov
1264b629f1 smartcontract: parse Struct item type same way as Array 2020-03-02 18:05:26 +03:00
Evgenii Stratonikov
05a3625b7d wallet: implement (*Account).SignTx
It is used in both CLI and RPC.
2020-03-02 18:03:56 +03:00
Evgenii Stratonikov
6541bd4d42 vm: use Boolean in (*BoolItem).String() 2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
6add4f3e50 transaction: disallow negative outputs
Otherwise it is possible to make outputs which will sum
to the expected value, but steal GAS from some other account.
2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
9e9d59b49a core: set NetworkFee to 0 for Claim and Miner transactions
Claim tx have no GAS inputs and a positive output which
can lead to negative network fee.
2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
21ef2638c0 consensus: log error if GetValidators() failed 2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
de5215a564 core: use GetAccountStateOrNew() in (*Blockchain).GetValidators()
Target of the transaction output may not yet exist in database.
2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
1b9968df67 core: optimize CalculateClaimable()
Because accumulated system fee is stored for every block,
it is easy to calculate sum with just to reads.
2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
258d8be1dd core: store all accumulated SystemFee with every block 2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
f69c8a763b core: store system fee together with block
Recalculating system fee can be rather costly if done
frequently.
2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
972e0d8ad1 core: add one more Contract tx to the test chain
When testing CLI it is useful to have some spent coins
on an account with a known key.
2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
37c2bc4733 rpc: implement (*Client).GetClaimable()
This is needed to form correct Claim transaction.
2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
45b8669b42 core: verify Claim transactions 2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
9d5841df38 rpc: make (*Client).SendRawTransaction public 2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
44792ed5f7 core: make test chain format compatible with mainnet
Write uint32 length before every block.
2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
51c4868641 rpc: implement getclaimable RPC 2020-03-02 18:01:49 +03:00
Evgenii Stratonikov
0e2a1f40ba core: add ContractTX to a testchain generator
Simple transfer from multisig account to the account
of one of the validators.
2020-03-02 18:00:00 +03:00
Evgenii Stratonikov
72d72296c3 core: implement (*Transaction).GetSignedPart()
Marshalling it and taking all but last byte violates incapsulation
and is just wrong in case transaction already contains any witnesses.
2020-03-02 18:00:00 +03:00
Evgenii Stratonikov
95d9f36c98 core: implement UnclaimedBalance tracking
To make it easy to get unclaimed coins for the
specified account they must be tracked together.
2020-03-02 18:00:00 +03:00
Evgenii Stratonikov
7095ec6c51 core: implement (*Blockchain).CalculateClaimable
Calculating amount of GAS that can be claimed is required
for getclaimable RPC.
2020-03-02 18:00:00 +03:00
Roman Khimov
252a9f2f31
Merge pull request #690 from nspcc-dev/feature/getapplicationlog
rpc: implement getapplicationlog RPC
2020-03-02 17:41:32 +03:00
Anna Shaleva
ff4384d7ff rpc: implement getapplicationlog RPC
Closes #500
2020-03-02 17:25:27 +03:00
Anna Shaleva
7d46404e2d smartcontract: turn trigger types into Type
1) Turn trigger types from byte constants into Type
2) Add auto-generated stringer for future purposes
2020-03-02 17:25:27 +03:00
Anna Shaleva
b3621d4a86 smartcontract: remove unused structures
Removed following unused structures:
	-smartcontract.ContextItem
	-smartcontract.Signature
	-smartcontract.ParameterContext
2020-03-02 17:25:27 +03:00
Anna Shaleva
535f391550 smartcontract: add marshaller for Parameter
1) Add marshaller and tests for smartcontract.Parameter
2) Add unmarshaller and tests for missing types of smartcontract.Parameter:
	- MapType
	- BoolType
2020-03-02 17:25:27 +03:00
Anna Shaleva
648e0bb242 rpc/smartcontract: merge contract parameter types
Merged two types:
	- smartcontract.ParamType
	- rpc.StackParamType
into single one:
	- smartcontract.ParamType
as they duplicated the functionality.

NOTE: type smartcontract.MapType was added (as in C# implementation).

From now, list of supported smartcontract parameter types:
	UnknownType
	SignatureType
	BoolType
	IntegerType
	Hash160Type
	Hash256Type
	ByteArrayType
	PublicKeyType
	StringType
	ArrayType
	MapType
	InteropInterfaceType
	VoidType
2020-03-02 17:25:21 +03:00
Evgenii Stratonikov
a3dacd3b74 tests: replace t.Fatal with require where possible
This makes tests less verbose and unifies the style
they are written in.
2020-03-02 17:22:27 +03:00
Evgenii Stratonikov
66f96e3f32 core: shutdown Blockchain gracefully in tests 2020-03-02 17:22:27 +03:00
Evgenii Stratonikov
3a5224344e core: verify headers in AddHeaders()
Headers can be malformed so public methods should verify them
before adding.
2020-03-02 17:22:26 +03:00
Evgenii Stratonikov
357bb4ce41 core: get rid of global variables in tests
It can lead to unnecessary race conditions and is just
a bad practice.
2020-03-02 17:04:08 +03:00
Evgenii Stratonikov
8ca94e23c8 core: replace makeBlocks() with addBlocks() in tests
This simplifies tests a bit.
2020-03-02 17:04:08 +03:00
Evgenii Stratonikov
cbf26bac83 mempool: do not allocate new slice for verified transactions
Because transactions a iterated in an increasing order,
we can filter slice in-place.
2020-03-02 10:38:27 +03:00
Evgenii Stratonikov
0ef7a76e84 network: batch transactions on broadcast 2020-03-02 10:37:27 +03:00
Roman Khimov
ff551d2015
Merge pull request #700 from nspcc-dev/fix/forloop
compiler: do not short-circuit in complex conditions
2020-02-28 20:14:26 +03:00
Roman Khimov
36197056b1
Merge pull request #691 from nspcc-dev/network-conn-overflow-and-shutdown
Network conn overflow and shutdown
2020-02-28 18:16:29 +03:00
Evgenii Stratonikov
b461a6ab63 compiler: do not short-circuit in complex conditions
Current implementation of short-circuting is just plain wrong
as it uses `last` or `before-last` labels which meaning depend
on context. It doesn't even handle simple assignements like
`a := x == 1 && y == 2`.

This commit makes all jumps in such conditions local
and adds tests.

Closes #699, #700.
2020-02-28 17:44:46 +03:00
Roman Khimov
e213e69a33 network: rework shutdown sequence of Server
Close transport and disconnect peers right in the Shutdown(), so that no new
connections would be accepted and so that all the peers would be disconnected
correctly (avoiding the same deadlock as in e2116e4c3f).
2020-02-28 16:22:04 +03:00
Roman Khimov
77624a8847 network: add Close() to discoverer, shut it down on exit 2020-02-28 16:22:04 +03:00
Evgenii Stratonikov
624a14f730 rpc: rename (*Client).SendToAddress to TransferAsset
SendToAddress name is similar to the `sendtoaddress` RPC call,
this can cause confusion.

Closes #686.
2020-02-28 14:16:39 +03:00
Roman Khimov
3e2b490025 mempool: rework inputs verification, check Claim txes
Use more efficient check for Input and also check Claims to avoid double
claiming.
2020-02-27 13:43:35 +03:00
Roman Khimov
f329de73e8 mempool: fix Remove bug (dropping wrong tx!)
Uncovered by TestMemPoolAddRemoveWithInputsAndClaims (to be added later)
2020-02-27 13:43:35 +03:00
Roman Khimov
7d59fa0066
Merge pull request #696 from nspcc-dev/tx-verification-fixes
Claim and enrollment TX verification fixes
2020-02-27 12:45:36 +03:00
Roman Khimov
00d199ed85 core: fix NetworkFee calculation
Add doesn't change the variable state. Thanks to GolangCI for catching this.
2020-02-27 12:32:56 +03:00
Roman Khimov
7bea6e043e core: add double claim verification check 2020-02-27 12:32:56 +03:00
Roman Khimov
29586f2aa7 core: add duplicate Claim verification check
Refactor HaveInputsDuplicate() out of the core and Blockchain, it doesn't
depend on the Blockchain state. Make it more efficient.
2020-02-27 12:32:56 +03:00
Roman Khimov
9b1ad40273 core: drop GetScriptHashesForVerifyingClaim, fix Claim's ScriptHash getter
Claim transactions should _add_ claims scripthashes to the standard list, not
replace them. And this code is actually very reusable.
2020-02-27 12:32:56 +03:00
Roman Khimov
9f7018503a core/transaction: use new transaction.InOut for References
We don't need a map here, use simpler structures.
2020-02-27 12:00:03 +03:00
Roman Khimov
80de208a68 transaction: unbind GroupInputsByPrevHash from Transaction
Which allows to use it for ClaimTX. Make it also a bit more efficient as maps
are expensive.
2020-02-27 12:00:03 +03:00
Roman Khimov
71a18b1727
Merge pull request #688 from nspcc-dev/fix/jmplabels
compiler: use uint16 for labels
2020-02-27 00:28:46 +03:00
Roman Khimov
b1b184f77f
Merge pull request #692 from nspcc-dev/persist-timer-fix
core: reschedule the next persist in a second from previous one
2020-02-26 10:34:40 +03:00
Roman Khimov
2f2a4afe21
Merge pull request #693 from nspcc-dev/memorystore-seek-lock
storage: add locking into (*MemoryStore).Seek
2020-02-26 10:15:40 +03:00
Roman Khimov
c258adb532 core: move spent coin management out of the inner storeBlock loop
prevHash == input.PrevHash, so make less DB accesses and more real work. Fix
some bugs along the way:
 * spentCoins structure may already be present in the DB when persisting TX,
   there is nothing wrong with that and we shouldn't overwrite it
 * it's only used for NEO and only to check for claim validity. Thus, when
   processing claim tx the corresponding spentCoins should always be present
   in the DB
2020-02-25 17:21:09 +03:00
Roman Khimov
36c6b6af14 core: put unspents get/put one loop above in storeBlock
Everywhere in this code prevHash == input.PrevHash, thus we can easily move
some common code out of the loop saving on DB accesses and
serialization/deserialization.
2020-02-24 18:53:10 +03:00
Roman Khimov
5c9681508b transaction: strip off a layer of redirection from ClaimTX.Claims
We don't need a pointer here and this change makes this field compatible with
Transaction.Inputs which is useful in many scenarios.
2020-02-24 18:22:27 +03:00
Roman Khimov
ed9e9e8590 storage: add locking into (*MemoryStore).Seek
It was missing there.
2020-02-24 17:51:50 +03:00
Roman Khimov
b49808b766 core: reschedule the next persist in a second from previous one
It makes little sense queueing up several persistence goroutines (or actually
even running them concurrently).
2020-02-24 17:17:25 +03:00
Roman Khimov
e2116e4c3f network: don't deadlock on connection overflow
(*Peer).Disconnect send an unregister signal to this goroutine, so invoking it
from here is not a good idea, run it asynchronously.
2020-02-24 15:56:49 +03:00
Roman Khimov
d5e6028c13 core: add validator public key into the list of hashes to verify
That should be done for Enrollment transactions.
2020-02-21 20:04:16 +03:00
Anna Shaleva
76a0a6e7e8 rpc: implement getblocksysfee RPC
Closes #341
2020-02-21 18:45:52 +03:00
Evgenii Stratonikov
177b725dc1 compiler: make writeJumps return error for bad jumps
The script is invalid anyway so it is better to notify user.
2020-02-21 17:45:45 +03:00
Evgenii Stratonikov
5e229d84d4 compiler: use uint16 for label numbers
As noted in #687 this will make compiler a bit more predictable.
2020-02-21 17:45:45 +03:00
Roman Khimov
8da20055d6 rpc: drop duplicating structures used in tests
We have proper results now, so use those. The only left is Invoke, but that
depends on another issue at the moment.
2020-02-21 15:23:11 +03:00
Roman Khimov
6a3be6081c smartcontract: support "ByteArray" string for ByteArrayType
We actually do emit it ourselves in String()
2020-02-21 15:23:11 +03:00
Roman Khimov
3fa9de764b rpc/client: only return the Result from calls, handle Error internally
Adjust structures accordingly and throw away most of them, they're useless.
2020-02-21 15:23:11 +03:00
Roman Khimov
28a26d2cae rpc/client: look into data first, then HTTP error code
In case of error our own server responds with an HTTP error and proper
JSON-RPC error in the body, so look there first as it has more specific data.
2020-02-21 15:12:04 +03:00
Roman Khimov
877b987ecf rpc: omitempty some fields in TransactionOutputRaw
These might be undefined for mempool transactions, thus they should be defined
as omitempty.
2020-02-21 15:12:04 +03:00
Roman Khimov
bba8ac15ff rpc: introduce proper type for sendrawtransaction, drop useless types
sendrawtransaction just returns a bool, sendtoaddress returns a proper
transaction and that should be the same as the one we have in
TransactionOutputRaw.
2020-02-21 15:12:04 +03:00
Roman Khimov
465476201c rpc/response: drop duplicating AccountState structure 2020-02-21 15:12:04 +03:00
Evgenii Stratonikov
b50704fd3b rpc: move server-related code to a separate package 2020-02-21 15:12:04 +03:00
Evgenii Stratonikov
d24c6d1d9e rpc: move client-related code to a separate package
This includes Client struct with RPC methods and
BalanceGetter implementation with NeoSCAN.
2020-02-21 15:12:04 +03:00
Evgenii Stratonikov
b6bc4e580a rpc: move functions for Tx building in request package/ 2020-02-21 15:12:04 +03:00
Evgenii Stratonikov
98a1e2170a rpc: move ContractDetails to request/ package 2020-02-21 15:12:04 +03:00
Evgenii Stratonikov
63751a6e6b rpc: merge neoscan-related definitions into one file
It will make refactoring easier.
2020-02-21 15:12:04 +03:00
Roman Khimov
f330f2f40b rpc: separate out request and response structures
Mostly as is, no real effort done yet to optimize them, so there are still a
lot of duplicates there, but at least we sort them out into different smaller
packages.
2020-02-21 15:12:04 +03:00
Roman Khimov
69e1ad512f rpc: move result package into response
`response` is to be populated soon.
2020-02-21 15:12:04 +03:00
Roman Khimov
1801e545a0 rpc: remove wrappers package, move things to result
These are all RPC call results, `wrappers` package doesn't make much sense to
me.
2020-02-21 15:12:04 +03:00
Roman Khimov
b8f7ab8e6a rpc: move Invoke to result package
It's just a data.
2020-02-21 15:12:04 +03:00
Roman Khimov
c189062f40 rpc: move ValidateAddress to the result package
Because it is a result of the RPC call.
2020-02-21 15:12:04 +03:00
Roman Khimov
bfa2d54e16 rpc: move validateAddress() function from wrappers into server
It's a server implementation detail, it has nothing to do with the data format
itself. It also makes no sense exporing it.
2020-02-21 15:12:04 +03:00
Roman Khimov
72a62f1292 result: add trivial test for peers management functions 2020-02-21 15:12:04 +03:00
Roman Khimov
723b33e108 network: implement unconnected/bad peers getters
Which allows node to respond to `getpeers` RPC request correctly.
2020-02-21 15:12:03 +03:00
Roman Khimov
d92e193e63 rpc/network: refactor getpeers logic
Deduplicate and simplify code.
2020-02-21 15:12:03 +03:00
Roman Khimov
336a94456f rpc: make blockHeightFromParam a pointer method
Makes no sense copying Server here.
2020-02-21 15:12:03 +03:00
Roman Khimov
f345db58ab
Merge pull request #678 from nspcc-dev/feature/breakfor
compiler: support break statement in for loops and switch statements

Closes #677.
Implements 4-th point from #628.
2020-02-21 12:22:16 +03:00
Evgenii Stratonikov
da89f18999 compiler: support break and continue in range loops 2020-02-21 12:03:37 +03:00
Evgenii Stratonikov
ccb53414f2 compiler: support break in switch statements 2020-02-21 12:03:37 +03:00
Evgenii Stratonikov
03dc6f7cbb compiler: support continue statement in for loops 2020-02-21 12:03:36 +03:00
Evgenii Stratonikov
fa2edc46e0 compiler: support break statement in for loops 2020-02-21 11:38:23 +03:00
Evgenii Stratonikov
25ffb56982 wallet: support creating multisig accounts
(*Account).ConvertMultisig() will convert an existing account
into a multisig one.
2020-02-21 11:19:35 +03:00
Evgenii Stratonikov
5a727cabf8 wallet: add signature check contracts to new accounts 2020-02-21 10:45:57 +03:00
Evgenii Stratonikov
eacea8bff5 smartcontract: implement json.Unmarshaler for ParamType 2020-02-20 15:52:08 +03:00
Evgenii Stratonikov
ea30122a09 wallet: rewrite file on save
When we are opening a file, it is expected that
it will be rewritten, not appended to a already existing wallet.
2020-02-20 15:52:08 +03:00
Evgenii Stratonikov
ad6fa2aea9 wallet: set WIF and public key on account decrypt
They are set during account creation and open+decrypt is
expected to put account in the same state.
2020-02-20 15:52:08 +03:00
Evgenii Stratonikov
d837eb3761 wallet: allow to create accounts from encrypted WIFs 2020-02-20 15:52:08 +03:00
Roman Khimov
a903147b60 keys: rename Signature to GetScriptHash, make it return Uint160
Signature itself wasn't used at all and its name is very misleading, Uint160
script hash is way more useful.
2020-02-19 12:19:03 +03:00
Roman Khimov
eb11e5fb11 core: implement basic policying support, fix #370
Implement mempool and consensus block creation policies, almost the same as
SimplePolicy plugin for C# node provides with two caveats:
 * HighPriorityTxType is not configured and hardcoded to ClaimType
 * BlockedAccounts are not supported

Other than that it allows us to run successfuly as testnet CN, previously our
proposals were rejected because we were proposing blocks with oversized
transactions (that are rejected by PoolTx() now).

Mainnet and testnet configuration files are updated accordingly, but privnet
is left as is with no limits.

Configuration is currently attached to the Blockchain and so is the code that
does policying, it may be moved somewhere in the future, but it works for
now.
2020-02-19 12:19:02 +03:00
Roman Khimov
22f5667530 mempool: return fee along with tx when requesting tx
Users of GetVerifiedTransactions() don't want to recalculate tx fee and it's
nice to have it returned from TryGetValue() also sometimes.
2020-02-19 12:19:02 +03:00
Roman Khimov
06daeb44f3 core: make IsLowPriority work with pre-calculated fee
Don't recalculate it again and again.
2020-02-19 12:19:02 +03:00
Roman Khimov
37c48b00b4 consensus/network: reinit dbft after block addition
Don't stall on some height if everyone else have moved up already. Fix #673.
2020-02-19 12:19:02 +03:00
Roman Khimov
c5d54e9992 network: introduce (*Server).IsInSync, start consensus in synced state
We define synchronized state as a combination of minimum number of peers and
chain height being not behind of more than 2/3 of these peers.
2020-02-19 12:13:27 +03:00
Roman Khimov
a2616cfafe consensus: correctly generate miner TX outputs based on net fee 2020-02-19 12:13:27 +03:00
Roman Khimov
17d1b1a2ae wallet: implement GetChangeAddress()
To select the default address to send tokens to.
2020-02-19 12:13:27 +03:00
Roman Khimov
a4294f4b5f core: export UtilityTokenID and GoverningTokenID
Both are very useful outside of the core, this change also makes respective
transactions initialize with the package as they don't depend on any kind of
input and it makes no sense recreating them again and again on every use.
2020-02-19 12:13:27 +03:00
Roman Khimov
b41a5239c6 core: always sort the result of GetValidators
It wasn't sorted when all validators were elected. There is also no need to do
`Unique()` on the result because validators are distinguished by the key, so
no two registered validators can have the same key.
2020-02-18 20:36:22 +03:00
Evgenii Stratonikov
ee8514d88b consensus: provide message type and view inside RecoveryMessage
PrepareRequest inside RecoveryMessage should contain both
message type and view.
2020-02-18 15:25:29 +03:00
Evgenii Stratonikov
9b82bbaa8a rpc: implement getstorage RPC 2020-02-18 11:59:31 +03:00
Evgenii Stratonikov
a2f012e589 core: deploy new smart-contract in test blocks
Also put smart-contract sources in testdata and
add invocation TX with APPCALL and storage.Put.
2020-02-18 11:59:28 +03:00
Anna Shaleva
2b9e63c511 core: add func to generate RPC test data
newRPCTestChain function generates test chain "testblocks.acc" for RPC
tests
2020-02-17 23:54:25 +03:00
Anna Shaleva
c99b42f738 rpc: add tests for getcontractstate RPC 2020-02-17 23:54:25 +03:00
Anna Shaleva
3c63ef3dc3 rpc: implement getcontractstate RPC 2020-02-17 23:54:25 +03:00
Anna Shaleva
b8715ddf11 rpc: refactor code of NewAccountState function
Simplified reversing of scriptHash
2020-02-17 23:52:20 +03:00
Anna Shaleva
f310145612 rpc: fix getrawtransaction error returncode
Changed returncode of getrowtransaction method in case when transaction
with specified hash does not exists. Now it returns error with code -100
instead of -32602 (as in c# node)
2020-02-17 23:52:20 +03:00
Anna Shaleva
5dca765bd1 rpc: add custom error with code -100
Fixed getassetstate method: it should return error with code -100 when
asset with specified id is not found (as in c# node).
2020-02-17 23:52:20 +03:00
Evgenii Stratonikov
7ee10ecea5 rpc: implement gettxout RPC 2020-02-17 11:58:18 +03:00
Roman Khimov
dfb38e1da1
Merge pull request #649 from nspcc-dev/feature/dump_storage
cli: add possibility to dump storage changes on restore
2020-02-16 23:50:31 +03:00
Roman Khimov
d16121c10a
Merge pull request #654 from nspcc-dev/feat/subslice
compiler: support sub-slicing
2020-02-16 23:49:53 +03:00
Roman Khimov
4a4cd6416c
Merge pull request #658 from nspcc-dev/feature/range
compiler: support for-range loops
2020-02-16 23:49:30 +03:00
Roman Khimov
b5453ad24f
Merge pull request #672 from nspcc-dev/fix-sigsegv-on-reference-check
core: deal with bad transaction Inputs
2020-02-14 13:23:42 +03:00
Roman Khimov
0fceaf12d2 core: deal with bad transaction Inputs
They may not really have a reference. Fixes #671.
2020-02-14 09:42:10 +03:00
Roman Khimov
992ccc0b26
Merge pull request #664 from nspcc-dev/sort-validator-keys
core: sort GetValidators() result
2020-02-13 21:46:26 +03:00
Evgeniy Kulikov
8d410a6659
Add JSON tags for RPC response types
- Attribute should have 2 fields (usage, data)
- VOut should have 4 (5) fields (asset, value, address, n)
- Script should have 2 fields (invocation, verification)
2020-02-13 19:06:54 +03:00
Roman Khimov
d8a8dc94b4
Merge pull request #657 from nspcc-dev/fix/struct_fields
compiler: support initializing struct fields from a variable
2020-02-13 17:54:01 +03:00
Roman Khimov
d4cd134aef core: sort GetValidators() result
As C# node does it. Technically it's only needed for consensus and could be
implemented in the appropriate package, but for better compatibility with C#
node we're better returning it sorted right here.
2020-02-13 17:07:27 +03:00
Roman Khimov
d1a2296939 network: change the disconnect procedure
We can still lock the (*Server).run with dead peers:

Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: goroutine 40 [select, 871 minutes]:
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).putPacketIntoQueue(0xc030ab5320, 0xc02f251f20, 0xc00af0dcc0, 0x18, 0x40, 0x100000000000000, 0xffffffffffffffff)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:82 +0xf4
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).EnqueueHPPacket(0xc030ab5320, 0xc00af0dcc0, 0x18, 0x40, 0x1367240, 0xc03090ef98)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:124 +0x52
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*Server).iteratePeersWithSendMsg(0xc0000ca000, 0xc00af35800, 0xcb2a58, 0x0)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:720 +0x12a
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*Server).broadcastHPMessage(...)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:731
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*Server).run(0xc0000ca000)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:203 +0xee4
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*Server).Start(0xc0000ca000, 0xc000072ba0)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:173 +0x2ec
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: created by github.com/CityOfZion/neo-go/cli/server.startServer
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/cli/server/server.go:331 +0x476
...
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: goroutine 2199 [chan send, 870 minutes]:
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).Disconnect.func1()
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:366 +0x85
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: sync.(*Once).Do(0xc030ab403c, 0xc02f262788)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/usr/local/go/src/sync/once.go:44 +0xb3
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).Disconnect(0xc030ab4000, 0xd92440, 0xc000065a00)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:365 +0x6d
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).SendPing.func1()
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:394 +0x42
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: created by time.goFunc
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/usr/local/go/src/time/sleep.go:169 +0x44
...
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: goroutine 3448 [chan send, 854 minutes]:
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).handleConn(0xc01ed203f0)
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:143 +0x6c
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: created by github.com/CityOfZion/neo-go/pkg/network.(*TCPTransport).Accept
Feb 13 16:14:50 neo-go-node-2 neo-go[9448]: #011/go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_transport.go:62 +0x44c
...

The problem is that the select in putPacketIntoQueue() only works the way it
was intended to after the `close(p.done)`, but that happens only after
successful unregistration request send. Thus, do disconnects the other way
around, first unblock queueing and exit goroutines, then destroy the
connection (if it wasn't previously destroyed) and only after that signal to
the Server.
2020-02-13 16:24:46 +03:00
Roman Khimov
ef870d0c9d
Merge pull request #661 from nspcc-dev/make-voting-system-work
Make voting system work
2020-02-13 15:16:29 +03:00
Roman Khimov
26af9200b0 core: refactor voting processing, fix pending tx subtractions
Deduplicate code and add missing token check for subtractions that are being
done in GetValidators() for pending transactions.
2020-02-13 13:07:34 +03:00
Roman Khimov
c8a248596e core: introduce ValidatorsCount, make a proper count
We were completely lacking ValidatorsCount that is supposed to track the
number of votes with particular count of consensus nodes which in theory can
change the number of active consensus nodes (if it ever to exceed the number
of standby validators), so we were not producing the right count and based on
that not giving the right set of validators.

Fixes #512.
2020-02-13 13:07:34 +03:00
Roman Khimov
357b675090 core: don't choose duplicating standby validators
We may already have chosen some of standby validators, so don't repeat.
2020-02-13 13:07:34 +03:00
Roman Khimov
f9c6a0d77c core: make voting choose the best validators
They need to be sorted in order for voting system to work.
2020-02-13 13:07:34 +03:00
Roman Khimov
2ff7ceb8cf core: properly update validator votes for Account descriptor
ValidatorsCount is not implemented yet, but we need to update validators
properly, adding account's vote to their votes count.
2020-02-13 13:07:34 +03:00
Roman Khimov
8310b76d28 core: properly save votes when processing Account descriptor
They were ignored basically.
2020-02-13 13:07:34 +03:00
Roman Khimov
807309a0de core/state: only drop unregistered non-voted validators
Simple as that: UnregisteredAndHasNoVotes != !RegisteredAndHasVotes

Registered validators should stay in the DB, we might be in the process of
updating votes for them and that starts with subtraction.
2020-02-13 13:07:34 +03:00
Evgeniy Kulikov
64e325d9af
Update tests for getblock action
- replace `GetBlockResponse.Result` with `wrappers.Block`
- update `getblock` checker and add more assets
2020-02-12 21:58:43 +03:00
Roman Khimov
32a064aa31 keys: add Cmp method to PublicKey
It can be used by code that doesn't operate with PublicKeys, but still needs
to be able to compare keys for some purposes.
2020-02-12 21:27:40 +03:00
Roman Khimov
38d0efc96c core: fix Registered state descriptor processing
It has simple boolean value encoded, no `strconv` needed (it actually chokes
on such input).
2020-02-12 21:27:40 +03:00
Roman Khimov
141553da4c keys: fix PublicKeys decoding
It changes the slice, thus it has to work via a pointer.
2020-02-12 21:23:28 +03:00
Roman Khimov
803fb39bb0 transaction: fix wrong state descriptor serdes
Wrong field order.
2020-02-12 21:23:28 +03:00
Evgeniy Kulikov
41ebf12eb3
Update getblock RPC action response 2020-02-12 19:43:51 +03:00
Evgenii Stratonikov
0a894db7f8 storage: add Exists flag to KeyValue in batch
Set Exists flag if an item with the specified key was already
present in storage before persisting.
2020-02-12 12:16:31 +03:00
Evgenii Stratonikov
b1d9e1132d cli: dump storage changes into JSON files 2020-02-12 12:16:31 +03:00
Evgenii Stratonikov
fb9af98179 storage: implement GetBatch() to view storage changes
GetBatch returns changes to be persisted.
2020-02-12 12:16:31 +03:00
Evgenii Stratonikov
8ea3ef0b62 compiler: process empty []byte{} literals as ByteArrays
It is wrong to count an empty byte slice as an Array.
2020-02-12 12:16:15 +03:00
Evgenii Stratonikov
32bce30777 compiler: support sub-slicing 2020-02-12 12:16:15 +03:00
Evgenii Stratonikov
310f7449d7 compiler: support for-range loops 2020-02-12 12:16:04 +03:00
Evgenii Stratonikov
ae03560589 compiler: support initializing struct fields from a variable
While initializing a struct, it is a top item on ALTSTACK.
This means that if we need to load a local variable,
DUPFROMALTSTACK won't longer push an array of locals on stack
but rather a currently initializing struct.

Closes #656.
2020-02-12 12:15:54 +03:00
Evgenii Stratonikov
3e84f2bdf8 compiler: rewrite jump targets properly
Old implementation could view 0x62 byte in
a script as a JMP instruction irregardless of whether it is
a real opcode or a part of a parameter of another instruction.
In this commit instructions are decoded together with parameters
during jump label rewriting.
2020-02-12 10:58:53 +03:00
Roman Khimov
d3badc3f97 consensus: log more like neo-cli, update dbft 2020-02-11 18:02:13 +03:00
Roman Khimov
38de2af073
Merge pull request #655 from nspcc-dev/fix-mempool-deadlock-on-reverification
core: get transactions from dao when mempool should not be used
2020-02-11 13:34:23 +03:00
Roman Khimov
292051d8df core: get transactions from dao when mempool should not be used
All of these places deal strictly with the chain and shouldn't ever be
bothered with mempool. It also fixes a deadlock on reverification of
non-standard tx:

1 @ 0x42f62f 0x43fbe9 0x43fbbf 0x43f95d 0x967059 0x966f66 0x972c7c 0x974e13 0x97a5d9 0x97bdf0 0x976147 0x966cc0 0x970f70 0x96c8cb 0x9ba858 0x45ca51
	0x43f95c	sync.runtime_SemacquireMutex+0x3c							/usr/local/go/src/runtime/sema.go:71
	0x967058	sync.(*RWMutex).RLock+0x128								/usr/local/go/src/sync/rwmutex.go:50
	0x966f65	github.com/CityOfZion/neo-go/pkg/core/mempool.(*Pool).TryGetValue+0x35			/go/src/github.com/CityOfZion/neo-go/pkg/core/mempool/mem_pool.go:229
	0x972c7b	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).GetTransaction+0x4b			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:782
	0x974e12	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).References+0x132			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:944
	0x97a5d8	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).GetScriptHashesForVerifying+0x58	/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:1410
	0x97bdef	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).verifyTxWitnesses+0x4f		/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:1545
	0x976146	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).isTxStillRelevant+0x216		/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:1067
	0x966cbf	github.com/CityOfZion/neo-go/pkg/core/mempool.(*Pool).RemoveStale+0xff			/go/src/github.com/CityOfZion/neo-go/pkg/core/mempool/mem_pool.go:208
	0x970f6f	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).storeBlock+0x2ecf			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:614
	0x96c8ca	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).AddBlock+0xea			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:308
	0x9ba857	github.com/CityOfZion/neo-go/pkg/network.(*blockQueue).run+0x157			/go/src/github.com/CityOfZion/neo-go/pkg/network/blockqueue.go:48
2020-02-10 18:53:22 +03:00
Roman Khimov
0461827fa3
Merge pull request #653 from nspcc-dev/fix-net-locks-and-leaks
network: fix networking stalls caused by stale peers
2020-02-10 18:51:56 +03:00
Roman Khimov
f7749cea67
Merge pull request #652 from nspcc-dev/Fix_FreeGasLimit
core: fix FreeGasLimit constraint
2020-02-10 18:49:09 +03:00
Roman Khimov
7ee8f9c5d8 network: fix networking stalls caused by stale peers
We can leak sending goroutines and stall broadcasts because of already gone
peers that happened to be cached by some s.Peers() user (more than 800 of
these can be seen in nodoka log along with (*Server).run blocking on
CMDGetAddr send):

Feb 10 16:35:15 nodoka neo-go[1563]: goroutine 41 [chan send, 3320 minutes]:
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).putPacketIntoQueue(...)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:81
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*TCPPeer).EnqueueHPPacket(0xc0083d57a0, 0xc017206100, 0x18, 0x40, 0x136a240, 0xc018ef9720)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/tcp_peer.go:119 +0x98
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*Server).iteratePeersWithSendMsg(0xc0000ca000, 0xc0001848a0, 0xcb4550, 0x0)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:720 +0x12a
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*Server).broadcastHPMessage(...)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:731
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*Server).run(0xc0000ca000)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:203 +0xee4
Feb 10 16:35:15 nodoka neo-go[1563]: github.com/CityOfZion/neo-go/pkg/network.(*Server).Start(0xc0000ca000, 0xc000072c60)
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/pkg/network/server.go:173 +0x2ec
Feb 10 16:35:15 nodoka neo-go[1563]: created by github.com/CityOfZion/neo-go/cli/server.startServer
Feb 10 16:35:15 nodoka neo-go[1563]:         /go/src/github.com/CityOfZion/neo-go/cli/server/server.go:331 +0x476
2020-02-10 18:47:52 +03:00
Anna Shaleva
9b03f968b1 core: fixe FreeGasLimit constraint
Lack of FreeGasLimit in privnet leads to gas limit exceeding in case of transactions with small amount of GAS to be used for invoke operation (< real cost of the transaction). Solution: Fixed constraint in case when FreeGasLimit == 0. So now we are able to perform transactions in privnet with FreeGasLimit = 0 for free.
2020-02-10 18:07:19 +03:00
Evgenii Stratonikov
895a8d9ebc compiler: reverse args in AppCall
Invoked contract is expecting first argument to be on top of the stack.
Change test to use non-commutative operation to catch this behaviour.
2020-02-10 10:53:58 +03:00
Evgenii Stratonikov
52d8d58593 compiler,interop: make AppCall accept varargs 2020-02-10 10:51:29 +03:00
Evgenii Stratonikov
1fc64d515f compiler: abstract out emitReverse
Extract logic of reversing top n items of the stack
in a separate function.
2020-02-10 10:43:31 +03:00
Roman Khimov
268cad5c06
Merge pull request #548 from nspcc-dev/feature/multisig
vm: implement parallel algorithm for CHECKMULTISIG
2020-02-08 16:10:34 +03:00
Roman Khimov
9b9adb28c1
Merge pull request #642 from nspcc-dev/feature/emit
vm, compiler: move Emit* functions to a separate package

Closes #449, #534.
2020-02-08 15:56:48 +03:00
Roman Khimov
c896e2b731 network: fix minor gofmt issues (spotted by goreportcard) 2020-02-08 15:53:08 +03:00
Roman Khimov
7ccf7974b6 core: substitute bad notifications with error messages
Tesnet sync failed with:
Feb 07 00:04:19 nodoka neo-go[1747]: 2020-02-07T00:04:19.838+0300        WARN        blockQueue: failed adding block into the blockchain        {"error": "failed to store notifications: not supported", "blockHeight": 713984, "nextIndex": 713985}

because some (not so) smart contract emitted a notification with an
InteropItem inside.
2020-02-07 15:34:59 +03:00
Roman Khimov
b805b1a71b vm: make SerializeItem/DeserializeItem public APIs
They're useful as wrappers around EncodeBinaryStackItem/DecodeBinaryStackItem.
2020-02-07 15:34:59 +03:00
Roman Khimov
7e7ce7f19f vm: rephrase serialization errors
Seeing some
    blockQueue: failed adding block into the blockchain        {"error": "failed to store notifications: not supported", "blockHeight": 713984, "nextIndex": 713985}
in logs is not very helpful.
2020-02-07 11:53:53 +03:00
Evgenii Stratonikov
a8dc704197 emit: add tests for Int 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
6fd3f0fa48 emit: add tests for Bytes 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
5e992d8cdd emit: add tests for Syscall, Jmp 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
dbc41b3044 compiler: replace emit* instructions with those from emit/ package 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
8243a8b3a7 emit: use io.BinWriter instead of bytes.Buffer 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
698c647f07 emit: refactor tests
Add structure and call Bytes() method on buffer once.
2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
1400ecfdde emit: fix Int to serialize integers in correct format
Related #605, #623.
2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
c821e1c4c8 vm: move IntToBytes and BytesToInt to emit package 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
4d8a3a359b vm: move Emit* functions to a separate package
Also strip 'Emit' prefix because 'emit' is now
in the package name.
2020-02-06 18:45:37 +03:00
Roman Khimov
ab14a4619d
Merge pull request #647 from nspcc-dev/fix-mempool-and-chain-locking
Fix mempool and chain locking

This allows us easily make 1000 Tx/s in 4-nodes privnet, fixes potential
double spends and improves mempool testing coverage.
2020-02-06 18:43:29 +03:00
Evgenii Stratonikov
9204b95d5b core: fix GAS price definitions 2020-02-06 18:19:08 +03:00
Roman Khimov
7445655437 consensus: switch test to using the new PoolTx API
Fixes GolangCI:
  Error return value of
  (*github.com/CityOfZion/neo-go/pkg/core/mempool.Pool).Add is not checked
  (from errcheck)

and allows us to almost completely forget about mempool here.
2020-02-06 17:50:11 +03:00
Roman Khimov
18695e660b mempool: drop RemoveOverCapacity(), handle it right in the Add()
Simplifies things a lot and removes useless code.
2020-02-06 17:50:11 +03:00
Roman Khimov
684cbf5bac mempool: make it almost 100% test-covered 2020-02-06 17:50:11 +03:00
Roman Khimov
6672f4b26f mempool: iterate over slice in GetVerifiedTransactions()
It's more efficient and keeps transactions sorted by priority.
2020-02-06 16:59:20 +03:00
Roman Khimov
e97396e56c mempool: test addition of conflicting tx to the pool 2020-02-06 15:57:20 +03:00
Roman Khimov
1133bbe584 mempool: remove unverified transactions pool
Our mempool only contains valid verified transactions all the time, it never
has any unverified ones. Unverified pool made some sense for quick unverifying
after the new block acceptance (and gradual background reverification), but
reverification needs some non-trivial locking between blockchain and mempool
and internal mempool state locking (reverifying tx and moving it between
unverified and verified pools must be atomic). But our current reverification
is fast enough (and has all the appropriate locks), so bothering with
unverified pool makes little sense.
2020-02-06 15:45:16 +03:00
Roman Khimov
b675903f52 mempool/core: redesign mempool dances on block acceptance
We not only need to remove transactions stored in the block, but also
invalidate some potential double spends caused by these transactions. Usually
new block contains a substantial number of transactions from the pool, so it's
easier to make one pass over it only keeping valid items rather than remove
them one by one and make an additional pass to recheck inputs/witnesses.
2020-02-06 15:45:16 +03:00
Roman Khimov
b567ce86ac mempool: implement insertion to sorted slice
Which is way faster than sort.Sort'ing things all the time.
2020-02-06 15:44:18 +03:00
Roman Khimov
35183b6dba mempool: reverse the order of sorted slice
Chopping off the last element of the slice if way easier than doing it with
the first one.
2020-02-06 15:44:16 +03:00
Roman Khimov
794027a90b mempool: use one slice for both priorities
It doesn't harm as we have transactions naturally ordered by fee anyway and it
makes managing them a little easier. This also makes slices store item itself
instead of pointers to it which reduces the pressure on the memory subsystem.
2020-02-06 15:43:45 +03:00
Roman Khimov
325bea3fa9 mempool: cache Feer invocation results in the item
They shouldn't depend on the chain state and for the same transaction they
should always produce the same result. Thus, it makes no sense recalculating
them over and over again.
2020-02-06 15:41:56 +03:00
Roman Khimov
e01bfeeb4d mempool: remove lock indirection from the Pool
After the f0bb886be3 with all methods of Pool
being pointer-based it makes no sense having this lock as a pointer.
2020-02-06 15:41:56 +03:00
Roman Khimov
a928ad9cfa mempool: make item an internal thing of mempool package
Nobody outside should care about these details, mempool operates on
transactions and that's it.
2020-02-06 15:41:56 +03:00
Roman Khimov
f0e3a31bc8 mempool: fix appending to sorted pools
Appending and not changing the real Items is utterly wrong.
2020-02-06 15:41:56 +03:00
Roman Khimov
b9b77ac1be network: fix block relaying, don't spit out useless errors
We can only add one block of the given height and we have two competing
goroutines to do that --- consensus and block queue. Whomever adds the block
first shouldn't trigger an error in another one.

Fix block relaying for blocks added via the block queue also, previously one
consensus-generated blocks were broadcasted.
2020-02-06 15:41:56 +03:00
Roman Khimov
f9963cca37 core: short-circuit verifyInputs when there are no inputs 2020-02-06 15:41:56 +03:00
Roman Khimov
70b3839fd0 core/mempool: fix AddBlock and tx pooling concurrency issues
Eliminate races between tx checks and adding them to the mempool, ensure the
chain doesn't change while we're working with the new tx. Ensure only one
block addition attempt could be in progress.
2020-02-06 15:41:52 +03:00
Evgenii Stratonikov
24bb66e606 util: fix a bug with not copying slice of len=1 in ArrayReverse
ArrayReverse copies it's argument only if it's len is > 1.
It needs to be consistent in all cases.
2020-02-06 12:15:35 +03:00
Evgenii Stratonikov
d07d6f3371 util: refactor tests for ArrayReverse 2020-02-06 12:15:35 +03:00
Evgenii Stratonikov
2a86149c82 vm: leave single CHECKMULTISIG implementation
Remove sequential implementation and benchmarks.
They will be still present in commit history.
2020-02-05 17:17:22 +03:00
Roman Khimov
02a5e036fc vm: deduplicate checkMultisigPar
Make its logic more clear.
2020-02-05 17:12:23 +03:00
Evgenii Stratonikov
d93d060010 vm: parallelize CHECKMULTISIG 2020-02-05 17:12:18 +03:00
Roman Khimov
f0bb886be3 mempool: make all methods pointer methods
Makes no sense copying the Pool around.
2020-02-04 17:36:11 +03:00
Roman Khimov
70c22ebc7b
Merge pull request #641 from nspcc-dev/consensus-update
Consensus update
2020-02-04 15:39:53 +03:00
Roman Khimov
9ceefe17e2 consensus: check current chain height before processing timer
The chain may already be more current than our dBFT state (like when the node
has commited something at view 0, but all the other nodes changed view and
accepted something at view 1), so in this case we should reinit dBFT on new
height.
2020-02-04 13:16:09 +03:00
Evgenii Stratonikov
e65b5c9914 consensus: fill preparation hash in recovery message 2020-02-04 13:16:05 +03:00
Evgenii Stratonikov
e441cb1414 consensus: add preparation hash to logger 2020-02-04 13:16:00 +03:00
Evgenii Stratonikov
42dfb52e98 consensus: add more logging in consensus service 2020-02-04 13:15:54 +03:00
Roman Khimov
553b2391a3 consensus: handle encoding errors in Hash() 2020-02-03 16:33:03 +03:00
Roman Khimov
388fed06e5 transaction: forbid serializing invalid transactions
Transaction that has no data is invalid and can't be serialized, so throw an
error if someone tries to.
2020-02-03 16:33:03 +03:00
Roman Khimov
9374c5e7c2
Merge pull request #639 from nspcc-dev/networking-improvements
Networking improvements
2020-02-03 16:26:04 +03:00
Evgenii Stratonikov
c3094123a1 compiler: do not store constants as variables
Because the constants are loaded directly via `emitLoadConst`, there is no need to store
them in an array of locals. It can have a big overhead, because it
is done at the beginning of every function.
2020-02-03 13:29:28 +03:00
Roman Khimov
e5d0125a3f network: do async broadcast when processing P2P TX
It can lead to some goroutine explosion, but supposedly it's better than
stalling other processing and eventually all of these goroutines should finish
their sends. Note that this doesn't change the behavior for RPC-relayed
transactions that are still waiting for the broadcast to finish ensuring
proper transaction distribution before returning the result to the client.
2020-01-30 14:03:52 +03:00
Roman Khimov
0fcbc697ca network: only tell consensus service about new valid transactions
Transactions can be bad and can duplicate each other, consensus service
shouldn't be bothered with that.
2020-01-30 14:03:52 +03:00
Roman Khimov
fdbaac7a30 network: prevent broadcast queue starving, share time with p2p
Blocked broadcast queue of one peer may affect broadcasting capabilities of
the server, so prevent total blocking of it by p2p queue.
2020-01-30 14:03:52 +03:00
Roman Khimov
b2c4587dad network: fix PeerAddr() for not-yet-handshaked case
If we have already got Version message, we don't need the rest of handshake to
complete before being able to properly answer the PeerAddr() requests. Fixes
some duplicate connections between machines.
2020-01-30 14:03:52 +03:00
Roman Khimov
49bd7aada5 network: log peerCount on connection registration
Symmetrical to disconnects, make it easier to look through the logs.
2020-01-30 14:03:52 +03:00
Roman Khimov
32695b4f40 network: don't unregister connected peers
If we drop connection because we're already connected don't unregister this
connected address because it's connected anyway!
2020-01-30 14:03:52 +03:00
Roman Khimov
eb4ec61b8b network: register connected addr in handleVersionCmd()
Prevent useless attempts to connect to this peer if the peer has already made
a connection to us.
2020-01-30 14:03:52 +03:00
Roman Khimov
9eafec0d1d network: introduce peer-to-peer message queue
This one is designed to give more priority to direct nodes communication, that
is that their messaging would have more priority than generic broadcasts. It
should improve consensus process under TX pressure and allow to handle
pings in time (preventing disconnects).
2020-01-30 14:03:52 +03:00
Roman Khimov
72e4eb7172 network: fix wrong NewPing() parameters
They have the opposite order, height first and nonce second. It was done wrong
in 4e6ed902 and never fixed since. Fixes sending wrong peer state leading to
useless getheaders messages (and disconnects when the other side is lagging
behind).
2020-01-30 14:03:52 +03:00
Roman Khimov
da09fda575 network: add debug on message receival 2020-01-30 14:03:52 +03:00
Roman Khimov
1c28dd2567 network: add message type to disconnect error message
If it was caused by message processing, but only after the handshake to
preserve errIdenticalID and other handshaking errors.
2020-01-30 14:03:52 +03:00
Roman Khimov
b79abd1e27 network: detect duplicate connections before handshake completes
We can have more than one connection attempt in progress and not yet completed
the handshake, so if there is a Version already received we should look it.
2020-01-30 14:03:52 +03:00
Roman Khimov
b1b660c779 rpc: fix getaccountstate/getunspents for unknown addresses
Returning error string as a result (not an error) is utterly wrong, but C#
implementation just returns a zero balance for unknown addresses, so we should
follow that.
2020-01-29 19:01:00 +03:00
Roman Khimov
0ccc59628c
Merge pull request #631 from nspcc-dev/fix/return3
compiler: fix a bug with assignment to underscore
2020-01-29 18:32:43 +03:00
Evgenii Stratonikov
390bf58f97 consensus: use our implementations of Recovery* messages
While decoding payload, local implementations of Recovery*
messages were used, but when creating RecoveryMessage inside dBFT
library default NewRecoveryMessage was invoked. This lead to parsing
errors.
2020-01-29 17:56:26 +03:00
Evgenii Stratonikov
8b922c057c compiler: fix a bug with assignment to underscore
When using underscore it does not appear in the list
of local variables, so it can't be assigned.
In this commit the value is dropped.
2020-01-29 17:07:55 +03:00
Evgenii Stratonikov
7053b3b2c0 compiler: optimize append argument processing
Append should leave it's result on top of the stack.
Thus we need to transform top of the stack:
(top) a . b --> (top) a . b . b
It can be done with just OVER + SWAP.
2020-01-29 12:28:38 +03:00
Evgenii Stratonikov
b6629fb6bd compiler: refactor argument handling for builtins
It is more convenient to have all unusual logic in one place.
2020-01-29 12:28:38 +03:00
Evgenii Stratonikov
d2326a8b96 compiler: support panic in source
In situations where VM's FAULT state needs to be reached,
panic function can be used. It compiles to THROW instruction.
2020-01-29 12:28:38 +03:00
Evgenii Stratonikov
e0f47decc7 compiler: replace ROLL(2) with equivalent ROT 2020-01-29 09:56:16 +03:00
Evgenii Stratonikov
28571bd3dc compiler: implement switch statement support 2020-01-29 09:56:16 +03:00
Roman Khimov
0ce0ecb95e
Merge pull request #624 from nspcc-dev/feature/bigint
compiler: emit integers correctly
2020-01-28 18:04:32 +03:00
Roman Khimov
ab03aee2cf
Merge pull request #627 from nspcc-dev/fix-getdata-and-pings
Fix getdata and pings
2020-01-28 17:43:13 +03:00
Roman Khimov
06c3fbe455 network: rework ping sends, fix overpinging
Our node was too pingy because of wrong timer setups (that divided timeout
Duration by time.Second), it also was wrong in its time calculations (using
UTC time to calculate intervals). At the same time missing block is a
server-wide problem, so it's better solved with server-wide protocol loop.
2020-01-28 17:39:52 +03:00
Roman Khimov
39800aecb3 network: fix getdata handling
It was broken by 0ba6b2a7, the peer only responded with one message instead of
full requested set.
2020-01-28 17:39:52 +03:00
Evgenii Stratonikov
d190b3a2e0 compiler: emit integers correctly
A while ago VM serialization format for Integer items was changed
but compiler continued to emit Integers in old format.
This commit changes compiler behaviour to be compatible with VM.
2020-01-28 16:39:19 +03:00
Evgenii Stratonikov
f15ceff592 vm: make IntToBytes, BytesToInt public
VM serialization format should be able to be reused.
2020-01-28 16:39:19 +03:00
Evgenii Stratonikov
77f9a2ee26 compiler: convert AppCall parameter from string properly 2020-01-27 15:34:03 +03:00
Evgenii Stratonikov
d65d6ab08d compiler: allow to convert string constants to []byte
Also load constant directly into stack, not by name.
2020-01-27 15:29:52 +03:00
Evgenii Stratonikov
097d35b9d5 compiler: fix a bug with FromAddress handling
Conversion of string to address with FromAddress is performed
at compile time so there is no need to push parameters on stack.
2020-01-27 13:14:40 +03:00
Evgenii Stratonikov
330db36168 compiler: implement engine.AppCall interop 2020-01-27 13:14:36 +03:00
Evgenii Stratonikov
4fd766fe09 compiler: allow usage of string literals in index expressions 2020-01-23 17:28:35 +03:00
Evgenii Stratonikov
058958729d compiler: support map literals 2020-01-23 17:06:15 +03:00
Evgenii Stratonikov
def73db8e9 compiler: support variables in slice literals 2020-01-23 15:51:16 +03:00
Evgeniy Kulikov
eb59460032
Merge pull request #614 from nspcc-dev/configurable-mempool-size
config: add MemPoolSize configuration parameter
2020-01-23 13:25:27 +03:00
Roman Khimov
67fe99b0ba
Merge pull request #618 from nspcc-dev/feature/for
compiler: support for loops with no init/post condition
2020-01-23 13:19:55 +03:00
Roman Khimov
04db87c770
Merge pull request #617 from nspcc-dev/feature/checksig
compiler: implement ECDSA signature verification
2020-01-23 13:18:21 +03:00
Roman Khimov
9aa5d0cf1e
Merge pull request #615 from nspcc-dev/network-peer-updates
Network peer updates
2020-01-23 13:15:43 +03:00
Roman Khimov
d6784e8f45 config: add MemPoolSize configuration parameter
Allow tuning/experimenting with mempool.
2020-01-23 13:10:44 +03:00
Evgenii Stratonikov
328267ca6f compiler: support for loops with no init/post condition
Make it possible to use `for` loop with a single condition.
2020-01-23 11:48:43 +03:00
Evgenii Stratonikov
bd37359393 compiler: implement ECDSA signature verification
Add VerifySignature interop for signature verification.
It is converted to VERIFY opcode.
2020-01-23 10:56:15 +03:00
Evgenii Stratonikov
303b82cc44 core: set free GAS limit via config 2020-01-22 14:32:21 +03:00
Evgenii Stratonikov
54e0b5a4a7 rpc: set MaxGasInvoke in config
Implement ability to restrict maximum amount of GAS
available for free RPC calls.
2020-01-22 14:31:57 +03:00
Evgenii Stratonikov
4718375db1 rpc: return amount of consumed GAS in invoke* 2020-01-22 14:31:57 +03:00
Evgenii Stratonikov
2f865480d3 util: add YAML marshaler to Fixed8 2020-01-22 14:31:57 +03:00
Evgenii Stratonikov
7a6d6f43ce vm: get rid of recursive (*VM).execute calls
Recursive execute() calls can affect gas calculation.
This commit makes execute() be called only for real opcodes
and moves duplicate logic for CALL/JMP into a separate function.
2020-01-22 14:31:57 +03:00
Evgenii Stratonikov
4eae55143f core: restrict GAS available for invocation transactions
There are 10 GAS available for free plus any amount of GAS
attached to a transaction.
2020-01-22 14:31:54 +03:00
Evgenii Stratonikov
d72d978a19 vm: abstract out GetInterop() function 2020-01-22 14:04:40 +03:00
Evgenii Stratonikov
c22d09adad vm: set GAS limit
Make it possible to set maximum amount of GAS which can be spent
during execution.
2020-01-22 14:04:40 +03:00
Evgenii Stratonikov
0662a7e3c2 vm: calculate GAS spent during execution
If getPrice callback is provided, accumulate spent GAS.
2020-01-22 14:04:40 +03:00
Roman Khimov
99dfdc19e7 network: drop now useless addrReq queue from the server
Just broadcast a high-priority message to everyone.
2020-01-22 11:28:59 +03:00
Roman Khimov
ea3b76ded1 network: make NewServer return an error, fix #612
It can return nil in two cases, so we're better return an error and handle
it.
2020-01-22 11:17:51 +03:00
Roman Khimov
f2ffffddb7 network: rework broadcasting functions, tune priorities
This gives more priority to anything related to consensus.
2020-01-22 11:01:13 +03:00
Roman Khimov
34b863d645 network: introduce Server's MkMsg()
That wraps NewMessage() for a configured network.
2020-01-21 17:31:51 +03:00
Roman Khimov
1f672e0da7 network: move SendVersion() to the Peer
Only leave server-specific `getVersionMsg()` in the Server, all the other
logic is peer-related.
2020-01-21 17:26:08 +03:00
Roman Khimov
9befd8de99
Merge pull request #610 from nspcc-dev/ping-improvements
Ping improvements
2020-01-21 13:34:15 +03:00
Roman Khimov
760b39e324 consensus: close chain in tests
Avoid test failures like this one:

=== RUN   TestService_OnPayload
==================
WARNING: DATA RACE
Read at 0x00c00015a843 by goroutine 112:
  testing.(*common).logDepth()
      /usr/local/go/src/testing/testing.go:665 +0xa1
  testing.(*common).Logf()
      /usr/local/go/src/testing/testing.go:658 +0x8f
  testing.(*T).Logf()
      <autogenerated>:1 +0x75
  go.uber.org/zap/zaptest.testingWriter.Write()
      /go/pkg/mod/go.uber.org/zap@v1.10.0/zaptest/logger.go:130 +0x11f
  go.uber.org/zap/zaptest.(*testingWriter).Write()
      <autogenerated>:1 +0xa9
  go.uber.org/zap/zapcore.(*ioCore).Write()
      /go/pkg/mod/go.uber.org/zap@v1.10.0/zapcore/core.go:90 +0x1c3
  go.uber.org/zap/zapcore.(*CheckedEntry).Write()
      /go/pkg/mod/go.uber.org/zap@v1.10.0/zapcore/entry.go:215 +0x1e7
  go.uber.org/zap.(*Logger).Info()
      /go/pkg/mod/go.uber.org/zap@v1.10.0/logger.go:187 +0x95
  github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).persist()
      /go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:720 +0x6bb
  github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).Run.func2()
      /go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:228 +0x53

Previous write at 0x00c00015a843 by goroutine 98:
  testing.tRunner.func1()
      /usr/local/go/src/testing/testing.go:900 +0x353
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:913 +0x1bb

Goroutine 112 (running) created at:
  github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).Run()
      /go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:227 +0x264

Goroutine 98 (finished) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:960 +0x651
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1202 +0xa6
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:909 +0x199
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1200 +0x521
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1117 +0x2ff
  main.main()
      _testmain.go:162 +0x337
==================
--- FAIL: TestService_OnPayload (4.11s)
2020-01-20 19:40:52 +03:00
Roman Khimov
f56383e9c8 network: use p.LastBlockIndex() in requestBlocks()
Always compare to the best known block index, comparing to the StartHeight is
just plain wrong now.
2020-01-20 19:37:17 +03:00
Roman Khimov
2c4ace022e network/config: redesign ping timeout handling a bit
1) Make timeout a timeout, don't do magic ping counts.
2) Drop additional timer from the main peer's protocol loop, create it
   dynamically and make it disconnect the peer.
3) Don't expose the ping counter to the outside, handle more logic inside the
   Peer.

Relates to #430.
2020-01-20 19:37:17 +03:00
Roman Khimov
62092c703d network: use local timestamp to decide when to ping
We don't and we won't have synchronized clocks in the network so the only
timestamp that we can compare our local time with is the one made
ourselves. What this ping mechanism is used for is to recover from missing the
block broadcast, thus it's appropriate for it to trigger after X seconds of
the local time since the last block received.

Relates to #430.
2020-01-20 19:37:17 +03:00
Roman Khimov
a8252ecc05 network: remove wrong ping condition
In reality it will never be true exactly in the case where we want this ping
mechanism to work --- when the node failed to get a block from the net. It
won't get the header either and thus its block height will be equal to header
height. The only moment when this condition is met is when the node does
initial synchronization and this synchronization works just fine without any
pings.

Relates to #430.
2020-01-20 19:37:17 +03:00
Roman Khimov
247cfa4165 network: either request blocks or ping a peer, but not both
It makes to sense to do both actions, pings are made for a different purpose.

Relates to #430.
2020-01-20 19:37:17 +03:00
Roman Khimov
0ba6b2a754 network: introduce peer sending queues
Two queues for high-priority and ordinary messages. Fixes #590. These queues
are deliberately made small to avoid buffer bloat problem, there is gonna be
another queueing layer above them to compensate for that. The queues are
designed to be synchronous in enqueueing, async capabilities are to be added
layer above later.
2020-01-20 17:23:26 +03:00
Roman Khimov
7f0882767c network: remove useless Done() method from the peer
It's internal state of the peer that no one should care about.
2020-01-20 17:23:26 +03:00
Roman Khimov
f39d5d5a10 network: fix unregistration on peer Disconnect
It should always signal to the server, not duplicating this send and not
missing it like it happened in the Server.run().
2020-01-20 17:23:26 +03:00
Roman Khimov
907a236285 network: move per-peer goroutines into the TCPPeer
As they're directly tied to it.
2020-01-20 17:23:26 +03:00
Roman Khimov
32213b1454
Merge pull request #601 from nspcc-dev/refactoring/core
core: refactor out Block, BlockBase and Header, closes #597.
2020-01-20 16:19:20 +03:00
Roman Khimov
f4aa088d04
Merge pull request #603 from nspcc-dev/feature/wallet
consensus: use wallets instead of WIF, closes #588.
2020-01-20 16:16:10 +03:00
Roman Khimov
bb80ba9b9e
Merge pull request #456 from nspcc-dev/pingpong_430
add ping pong processing
2020-01-20 16:10:29 +03:00
Evgenii Stratonikov
f0083b94c5 vm: use new big.Int (de-)serialization routines
Also fix a test with CAT.
2020-01-17 17:37:50 +03:00
Evgenii Stratonikov
f26bdae2c5 vm: implement proper big.Int to []byte conversions
Big.Int Bytes()/SetBytes() methods are not symmetric.
Moreover we need to mimic C# node behavior:
- if a positive number has MSB set, 0x00 byte should be appended
  to distinguish positive number from negatives
- negative numbers should serialize as two's-complement
2020-01-17 17:37:50 +03:00
Evgenii Stratonikov
55d98ab19a consensus: update keys from wallet after every block 2020-01-17 17:30:45 +03:00
Evgenii Stratonikov
aaefcdecae consensus: use wallet in service 2020-01-17 17:25:51 +03:00
Evgenii Stratonikov
36cfa5b1f4 wallet: add GetAccount() method to Wallet
It is useful to be able to get account specified by script hash.
2020-01-17 17:25:51 +03:00
Evgenii Stratonikov
a798e4e0fa wallet: add ScriptHash() method to Contract 2020-01-17 17:25:51 +03:00
Evgenii Stratonikov
a871f75063 wallet: use a script instead a hash
NEO wallets (e.g. used in privnet setup) use hex-encoded
script inside the wallet, not a script hash.
2020-01-17 17:25:51 +03:00
Roman Khimov
46b82b4fb5 keys: don't return error from PrivateKey.Sign
As it can't ever happen.
2020-01-17 17:00:30 +03:00
Vsevolod Brekelov
4e6ed9021c network: add ping pong processing
add pingInterval same as used in ref C# implementation with the same logic
add pingTimeout which is used to check whether pong received. If not -- drop the peer.
add pingLimit which is hardcoded to 4 in TCPPeer. It's limit for unsuccessful ping/pong calls (where pong wasn't received in pingTimeout interval)
2020-01-17 13:24:14 +03:00
Roman Khimov
e2fff3bb1d keys: update to newer rfc6979 package
Fixes #592.
2020-01-16 18:21:10 +03:00
Evgenii Stratonikov
28183b81d6 mempool: simplify names of exported types
With the move to a separate package, naming can be simplified:
MemPool -> Pool, PoolItem -> Item, PoolItems -> Items.
2020-01-16 10:16:24 +03:00
Evgenii Stratonikov
fed6fba9b6 core: refactor out MemPool 2020-01-16 10:16:24 +03:00
Evgenii Stratonikov
79bceb3e40 block: use require in tests 2020-01-16 10:16:24 +03:00
Evgenii Stratonikov
489b88afbb block: rename BlockBase to Base 2020-01-16 10:16:24 +03:00
Evgenii Stratonikov
63c56cca5c core: refactor out Block, BlockBase and Header structs
See #597.
2020-01-16 10:16:24 +03:00
Roman Khimov
7d4d57351e network: fix requestTx() behaviour for consensus service
It wasn't actually requesting transactions but rather sending an inventory
message telling everyone that we have them which is completely wrong and
easily leads to ChangeView that could be avoided.
2020-01-15 14:31:56 +03:00
Roman Khimov
0420d48e56 network: micro-optimize relayInventory
Do less allocations, we're sending the same message with the same payload.
2020-01-15 13:16:09 +03:00
Roman Khimov
9eb880a095
Merge pull request #568 from nspcc-dev/feature/compiler_clean_and_tests
compiler: clean and tests
2020-01-14 18:44:07 +03:00
Vsevolod Brekelov
7084925e4b compiler: add test for compile and save 2020-01-14 17:33:04 +03:00
Evgenii Stratonikov
3d704a3a3a consensus: try to use previous proposal after ChangeView
When system and network pressure is high it can be beneficial
to use transactions which and were already proposed.
The assumption is that they will be in other node's memory pool
with more probability.
2020-01-14 16:05:27 +03:00
Roman Khimov
7ba5267494
Merge pull request #596 from nspcc-dev/feature/single_node
network: allow single-node privnet setup. Closes #595.
2020-01-14 13:17:04 +03:00
Evgenii Stratonikov
70b23076f8 network: allow single-node privnet setup 2020-01-13 18:01:20 +03:00
Evgenii Stratonikov
5f5d0097e2 network: use TimePerBlock from config 2020-01-13 17:58:12 +03:00
Roman Khimov
2192b6602a network: fix logic and logging for sendVersion() errors
It doesn't make sense trying to read from a broken connection and the
disconnect is to be logger from the server on unregistration.
2020-01-13 17:33:29 +03:00
Roman Khimov
b5f234ddef rpc: make rpc request logging at Debug level
Makes no sense polluting logs with Info. It also affects benchmarking.
2020-01-13 17:33:29 +03:00
Evgenii Stratonikov
f3921ea3bd network: fix NPE in logging 2020-01-13 15:06:57 +03:00
Roman Khimov
565c1940e3
Merge pull request #587 from nspcc-dev/feature/zap
Closes #284.
2020-01-10 14:50:09 +03:00
Evgenii Stratonikov
9dc5571327 core,rpc: close Blockchain in tests
If blockchain is not closed, logging in defer can occur
after test has finished, which will lead to a panic with
"Log in goroutine after Test* has completed".
2020-01-10 11:47:56 +03:00
Evgenii Stratonikov
dc65684708 consensus: replace SugaredLogger with Logger
SugaredLogger was used to make output look more similar to logrus.
This is no longer needed.
2020-01-10 11:14:29 +03:00
Evgenii Stratonikov
9b8b77c9ea network: return error if header message is too big
Big messages can still be processed but only first
2000 headers will be used.
2020-01-10 11:14:29 +03:00
Evgenii Stratonikov
637c99eda7 core: simplify newInteropContext 2020-01-10 11:14:29 +03:00
Evgenii Stratonikov
45a4524054 rpc: remove EnableCORSWorkaround from Request 2020-01-10 11:14:29 +03:00
Evgenii Stratonikov
289cb1c1d9 rpc: use zap.Logger 2020-01-10 11:14:29 +03:00
Evgenii Stratonikov
aecdf470e7 cli,pkg: use zap.Logger 2020-01-10 11:14:27 +03:00
Roman Khimov
e96b4bc82e wallet: fix TestNewAccount
It duplicated TestNewFromWif.
2020-01-09 18:40:30 +03:00
Roman Khimov
9bb68d7025 wallet: make DecryptAccount a method of Account
Otherwise it almost duplicates keys.NEP2Decrypt().
2020-01-09 18:40:30 +03:00
Roman Khimov
951ee383e9 keys: improve NEP2 testing 2020-01-09 18:06:03 +03:00
Roman Khimov
b5b05a969c keys: make NEP2Decrypt return a PrivateKey rather than WIF
There is no point in encoding the output of this function in a WIF format,
most of the users actually want the real key and those who need a WIF can
easily get if from the key (and it's simpler than getting the key from the
WIF).

It also fixes a severe bug in NEP2Decrypt, base58 decoding errors were not
processed correctly.
2020-01-09 18:05:14 +03:00
Evgenii Stratonikov
9c79684516 storage: panic on error in boltdb.Seek
Error in Seek means something is terribly wrong (e.g. db was not opened) and
error drop is not the right thing to do, because caller
will continue working with the wrong view.
2020-01-09 15:17:35 +03:00
Evgenii Stratonikov
8d1f564411 consensus: add tests for getTx 2019-12-27 14:12:58 +03:00
Evgenii Stratonikov
d803dffca8 consensus: return nil interface from getTx 2019-12-27 13:54:11 +03:00
Roman Khimov
c306d2f07c
Merge pull request #581 from nspcc-dev/feat/storage_find
core: implement Neo.Storage.Find interop, closes #422.
2019-12-26 15:46:46 +03:00
Evgenii Stratonikov
48cf4f4a84 core: implement Neo.Storage.Find interop 2019-12-26 15:21:41 +03:00
Evgenii Stratonikov
7b5c47e7f5 vm: add NewMapIterator() 2019-12-26 14:34:15 +03:00
Roman Khimov
f8887b63ba
Merge pull request #578 from nspcc-dev/fix/sign
consensus: verify payloads correctly, closes #555.
2019-12-26 13:07:40 +03:00
Evgenii Stratonikov
64d24d8ddd consensus: verify payloads correctly 2019-12-26 10:49:56 +03:00
Evgenii Stratonikov
714c466c2c core: add ScriptFromWitness function
Extracting verification script from witness became a common task.
This commit adds such a possibility.
2019-12-26 10:49:56 +03:00
Roman Khimov
234d94d27e network: implement getblocks command
Fixes #577, tested with C# nodes connecting to neo-go privnet.
2019-12-25 19:46:57 +03:00
Roman Khimov
9145855d2c
Merge pull request #579 from nspcc-dev/refactor-crypto
This moves some functionality into micro-packages, improves testing,
unexports some code and fixes bugs along the way.
2019-12-25 18:12:50 +03:00
Roman Khimov
604b2c8240 keys: add a successful test for 04-encoded public key 2019-12-25 18:06:25 +03:00
Roman Khimov
fa0537758f keys: add a test for X/Y > P decoding case 2019-12-25 18:01:54 +03:00
Roman Khimov
6c471ecd98 keys: move IsOnCurve decoding check, add a test for it
This check only makes sense for 04-encoded points, because 02 and 03 derive Y
from X and they're on the curve by definition.
2019-12-25 18:00:25 +03:00
Roman Khimov
5ac8cae221 keys: fix bad compressed public key decoding, add a test
The error was not propagated properly here.
2019-12-25 17:44:30 +03:00
Roman Khimov
b246653f62 address: rename functions as per #579 comments
Make them more clear to understand.
2019-12-25 17:34:18 +03:00
Roman Khimov
53e6fbbbf9 base58: add a test for a025b9c42d
As noted by @fyrchik in #579 comments.
2019-12-25 17:33:48 +03:00
Roman Khimov
e25133a385 keys: reuse address package for address generation
Deduplicates code and makes prefix overridable.
2019-12-25 16:03:39 +03:00
Roman Khimov
b7702f3a2e address: improve testing, make it 100% covered 2019-12-25 15:55:39 +03:00
Roman Khimov
c5ceb9128a address: check for prefix when decoding 2019-12-25 15:50:52 +03:00
Roman Khimov
89b6cbf795 address: make Prefix overridable
As it should be, it's specified in the configuration file (and it should be
treated as byte in the config)
2019-12-25 15:42:18 +03:00
Roman Khimov
e685e9bf9a address: move into its own package
Doesn't really belong to the crypto.
2019-12-25 15:22:02 +03:00
Roman Khimov
a025b9c42d base58: remove bogus code from CheckDecode
No other implementation does that and it looks weird, I see nothing meaninful
here.
2019-12-25 15:07:11 +03:00
Roman Khimov
369ac01a27 base58: move into its own package
It doesn't belong to crypto in any way other than it uses hash function
internally.
2019-12-25 15:05:54 +03:00
Roman Khimov
5dd8d29534 hash: improve merkle tree testing
Make it 100% covered.
2019-12-25 14:43:50 +03:00
Roman Khimov
ddad9ac9a3 hash: simplify merkle tree error handling
buildMerkleTree() is internal to the hash package and if anyone calls it with
`len(leaves) == 0` he deserves a panic. As it's the only error case in it, we
can remove error value return from this function and simplify NewMerkleTree().
2019-12-25 14:38:48 +03:00
Roman Khimov
ee28fb08f6 crypto: move merkle tree into the hash package
It's all about hashes, so it makes sense putting it there.
2019-12-25 11:28:59 +03:00
Roman Khimov
db5555bb15 crypto: internalize aes functions into the keys package
This is the only user of it and no one outside should care about these
details.
2019-12-25 11:25:05 +03:00
Roman Khimov
9cc0fca9d2
Merge pull request #574 from nspcc-dev/feature/multireturn
compiler: implement multiple return support, closes #562.
2019-12-25 08:46:38 +03:00
Vsevolod Brekelov
606616618f rpc: add ability to answer as C# with block as []byte 2019-12-25 01:44:37 +03:00
Vsevolod Brekelov
7f1844a39e transaction: add unmarshaling for TXType 2019-12-25 01:44:37 +03:00
Evgenii Stratonikov
f4571ba8cf compiler: implement multiple return support 2019-12-24 16:46:43 +03:00
Evgenii Stratonikov
5bc32b523a vm: implement Neo.Iterator.* interops 2019-12-24 10:21:47 +03:00
Evgenii Stratonikov
3ff7fd5262 vm: implement Neo.Enumerator.* interops 2019-12-24 10:21:46 +03:00
Roman Khimov
bf84e1f2fb core: cache top block
Turns out, our dApps use it a lot and we were going to the DB to get it which
is a useless waste of time. Technically we could also remove blockHeight here,
but not doing it at the moment as it's more involved.

It eliminates this time waste from the pprof graph, but doesn't change 1.4M ->
1.5M 100K mainnet block import test case in any noticeable way.
2019-12-23 19:18:12 +03:00
Roman Khimov
cc16dac0b4 vm: optimize script loading a bit
Preseed the scriptHash value when we already know it. Eliminates this time
waste from the pprof graph, but doesn't really change anything in the 1.4M ->
1.5M 100K mainnet blocks import test.
2019-12-23 18:02:39 +03:00
Roman Khimov
094c8474b7 compiler: move tests from vm/tests
These don't belong to VM as they compile some Go code and run it in a VM. One
may call them integration tests, but I prefer to attribute them to
compiler. Moving these tests into pkg/compiler also allows to properly count
the compiler coverage they add:

-ok     github.com/CityOfZion/neo-go/pkg/compiler       (cached)        coverage: 69.7% of statements
+ok     github.com/CityOfZion/neo-go/pkg/compiler       (cached)        coverage: 84.2% of statements

This change also fixes `contant` typo and removes fake packages exposed to the
public by moving foo/bar/foobar into the testdata directory.
2019-12-23 17:05:34 +03:00
Roman Khimov
deb76c5199 core: add negative non-interop test for all interops
Try to feed some garbage into these functions.
2019-12-23 16:14:43 +03:00
Roman Khimov
76d69ee5ee core: restore proper interops ordering 2019-12-23 16:14:43 +03:00
Roman Khimov
c287a9e93c core: implement Neo.Witness.GetVerificationScript interop 2019-12-23 16:14:43 +03:00
Roman Khimov
9d638d0fee core: implement Neo.InvocationTransaction.GetScript 2019-12-23 16:14:43 +03:00
Roman Khimov
33958be45f
Merge pull request #559 from nspcc-dev/feature/stack_limits
vm: don't refcount simple items

Improves 1.4M to 1.5M 100K mainnet block import test by ~4%.
2019-12-23 12:44:01 +03:00
Vsevolod Brekelov
d576aa2753 compiler: remove not used functions 2019-12-20 13:05:47 +03:00
Roman Khimov
79323cc10b
Merge pull request #567 from nspcc-dev/feature/codegen_add_mod
compiler: Add Mod token, closes #563
2019-12-19 15:32:18 +03:00
Vsevolod Brekelov
1458116567 vm: add tests 2019-12-19 15:23:14 +03:00
Vsevolod Brekelov
b68e9591aa compiler: add test for codegen 2019-12-19 15:23:14 +03:00
Vsevolod Brekelov
3c7ac7eb95 compiler: add mod 2019-12-19 15:23:14 +03:00
Roman Khimov
26ea4799c3
Merge pull request #565 from nspcc-dev/hashed-interop-callback
vm/core: add ID support for SYSCALL, redo interop registration
2019-12-19 15:02:53 +03:00
Roman Khimov
5f3a220b48
Merge pull request #566 from nspcc-dev/feature/varindex
compiler: implement assignment to a variable index
2019-12-19 13:40:32 +03:00
Roman Khimov
a7457d08a1 vm/core: add ID support for SYSCALL, redo interop registration
This solves two problems:
 * adds support for shortened SYSCALL form that uses IDs (similar to #434, but
   for NEO 2.0, supporting both forms), which is important for compatibility
   with C# node and mainnet chain that uses it from some height
 * reworks interop plugging to use callbacks rather than appending to the map,
   these map mangling functions are clearly visible in the VM profiling
   statistics and we want spawning a VM to be fast, so it makes sense
   optimizing it. This change moves most of the work to the init() phase
   making VM setup cheaper.

Caveats:
 * InteropNameToID accepts `[]byte` because that's the thing we have in
   SYSCALL processing and that's the most often usecase for it, it leads to
   some conversions in other places but that's acceptable because those are
   either tests or init()
 * three getInterop functions are: `getDefaultVMInterop`, `getSystemInterop`
   and `getNeoInterop`

Our 100K (1.4M->1.5M) block import time improves by ~4% with this change.
2019-12-19 13:35:42 +03:00
Evgenii Stratonikov
891a878af1 compiler: implement assignment to a variable index
Fixes #564.
2019-12-19 13:14:17 +03:00
Evgenii Stratonikov
f957af35d4 vm: do not store items of scalar types in map
As they do not contain any other items,
they can be only accounted via total size.
2019-12-18 11:12:19 +03:00
Roman Khimov
1a26548be8
Merge pull request #561 from nspcc-dev/fix-duping-and-and-tests
Fix duping and add tests.

C# node actually implements DUP in the same way we did, but it does create a
new element when accessing some particular value (like BigInt() or Bytes()) so
in the end this DUP implementation doesn't lead to any visible side-effects. In
our case I think it's more appropriate to fix the DUP (and its variants) itself
avoiding useless allocations in the VM.
2019-12-18 11:07:41 +03:00
Roman Khimov
10766fe813 vm: add tests for hashing instructions
These were cross-checked with the C# implementation.
2019-12-17 20:31:16 +03:00
Roman Khimov
21efcb012b vm: fix non-dupped items in PICKITEM
TestPICKITEMDupMap and TestPICKITEMDupArray were failing.
2019-12-17 20:26:30 +03:00
Roman Khimov
a6d60e387a vm: fix OVER and PICK to duplicate stack items
TestPICKDup and TestOVERDup failed without this.
2019-12-17 20:26:30 +03:00
Roman Khimov
60dfa05b19 vm: duplicate an item in Dup
TestDupByteArray and TestDupInt were failing before this patch.
2019-12-17 20:26:30 +03:00
Roman Khimov
c596a6b273 vm: fix INVERT behaviour for converted values
Tests added were failing before this change.
2019-12-17 20:26:30 +03:00
Evgenii Stratonikov
884779e501 *: goimports 2019-12-17 14:51:28 +03:00
Evgenii Stratonikov
014be31a0a network: fix link in pprof 2019-12-17 14:49:28 +03:00
Vsevolod
27a5825d42
Merge pull request #536 from nspcc-dev/feature/pprof
network: add Pprof metrics
2019-12-17 14:21:25 +03:00
Vsevolod Brekelov
0085831ec5 network: add Pprof metrics
Since we have some perf issues from time to time it is good to have pprof debugger. Disabled by default.
2019-12-17 14:13:07 +03:00
Roman Khimov
587cfc7c66 vm: optimize ROLL/ROT, refactor common code
Add `Roll` method to Stack that doesn't pop and push values and use it for
ROLL and ROT.

1.4M->1.5M 100K block import test before:
real    3m44,292s
user    5m43,494s
sys     0m34,741s

After:
real    3m40,449s
user    5m42,701s
sys     0m35,500s
2019-12-16 19:53:21 +03:00
Roman Khimov
2627628387 vm: optimize SWAP instruction, refactor common code
Add `Swap` method to the Stack and use it for both SWAP and XSWAP. Avoid
element popping and pushing (and associated accounting costs).

1.4M->1.5M 100K block import test before:
real    3m51,885s
user    5m54,744s
sys     0m38,444s

After:
real    3m44,292s
user    5m43,494s
sys     0m34,741s
2019-12-16 19:02:40 +03:00
Roman Khimov
7a5e995030 core: add MemPool Verify() test 2019-12-14 00:05:45 +03:00
Roman Khimov
5d68f88196 core: fix and speed up mempool Verify()
First of all, it was wrong, it was not checking for inputs really, it compared
tx hashes for some reason, second, when it did compare inputs it compared only
the PrevIndex part of them which is also wrong.

Also, there is absolutely no reason to go through GetVerifiedTransactions()
here, we don't need this copy of pointers and it can also be outdated by the
time we're to finish our check.

Before:
BenchmarkTXPerformanceTest-4
    5000            485506 ns/op           65886 B/op        409 allocs/op
ok      github.com/CityOfZion/neo-go/integration        3.212s

After:
enchmarkTXPerformanceTest-4
    5000            371104 ns/op           44367 B/op        408 allocs/op
ok      github.com/CityOfZion/neo-go/integration        2.712s
2019-12-13 23:23:33 +03:00
Roman Khimov
35f7f4137e
Merge pull request #556 from nspcc-dev/optimize-dao-and-things
Optimize dao and things, this set improves 1.4M->1.5M import of 100K blocks
by more than 43%.
2019-12-13 22:43:41 +03:00
Roman Khimov
e631e75718 core: optimize GetVerifiedTransactions()
This simple change improves our BenchmarkTXPerformanceTest by 14%, just
because we don't waste time on reallocations during append().

Before:
   10000            439754 ns/op          218859 B/op        428 allocs/op
ok      github.com/CityOfZion/neo-go/integration        5.423s

After:
   10000            369833 ns/op           87209 B/op        412 allocs/op
ok      github.com/CityOfZion/neo-go/integration        4.612s
2019-12-13 19:57:17 +03:00
Roman Khimov
c9257c3de4 vm: optimize Next() in Context
Creating a new BinReader for every instruction is a bit too much and it adds
about 1% overhead on block import (and actually is quite visible in the VM
profiling statistics). So use a bit more ugly but efficient method.
2019-12-13 19:57:17 +03:00
Roman Khimov
a9401e2ec7 core: do not write new dao elements into DB
It's useless work being done before it's actually needed. These (updated with
new values) are going to be written with some kind of Put anyway, so writing
them here is just a waste of time.
2019-12-13 19:57:17 +03:00
Roman Khimov
6896b40dee state: use open-coded array (de)serialization for accounts
We're spending a lot of time here, 100K blocks import starting at 1.4M, before
this patch:
real    4m17,748s
user    6m23,316s
sys     0m37,866s

After:
real    3m54,968s
user    5m56,547s
sys     0m39,398s

9% is quite a substantial improvement to justify this change.
2019-12-13 19:57:17 +03:00
Roman Khimov
0d0a27d271 core: add cachedDao to cache accounts and contracts
Importing 100K blocks starting at 1.4M, before this patch:
real    6m0,356s
user    8m52,293s
sys     0m47,372s

After this patch:
real    4m17,748s
user    6m23,316s
sys     0m37,866s

Almost 30% better.
2019-12-13 19:57:17 +03:00
Roman Khimov
212cf44e26 core: get data from dao in interops
It's more logically correct as Blockchain can be several transactions behind
in terms of its state.
2019-12-13 17:17:14 +03:00
Roman Khimov
0abd55c2c2 vm: add cached ScriptHash() to Context
Avoid recalculating it over and over again in interop.
2019-12-13 17:05:03 +03:00
Roman Khimov
0afaff2f79 vm: microoptimize RegisterInteropFuncs()
Avoid useless copying.
2019-12-13 17:02:28 +03:00
Evgenii Stratonikov
0efd9a6062 consensus: fix payload sign test
Do not fill verification script randomly as there is a probability
for it to be executed sucessfully.

time="2019-12-12T17:24:22+03:00" level=info msg="blockchain persist completed" blockHeight=0 headerHeight=0 persistedBlocks=0 persistedKeys=15 took="54.474µs"
time="2019-12-12T17:24:23+03:00" level=info msg="blockchain persist completed" blockHeight=0 headerHeight=0 persistedBlocks=0 persistedKeys=15 took="49.312µs"
2019-12-12T17:24:24.026+0300    DEBUG   can't verify payload from #%d1  {"module": "dbft"}
--- FAIL: TestPayload_Sign (0.00s)
    payload_test.go:302:
                Error Trace:    payload_test.go:302
                Error:          Should be false
                Test:           TestPayload_Sign
FAIL
coverage: 75.8% of statements
FAIL    github.com/CityOfZion/neo-go/pkg/consensus      2.145s
2019-12-13 12:09:51 +03:00
Evgenii Stratonikov
8a2e1c3d0a io: remove ReadLE/BE and WriteLE/BE
It was replaced with faster specialized versions earlier.
2019-12-13 11:38:28 +03:00
Roman Khimov
09223236f9 core: add Persist() to dao()
Hide its internals a little, which is gonna be useful for future composition.
2019-12-12 21:17:13 +03:00
Roman Khimov
eb1749d190 core: remove persisting from GetValidators()
It's a getter function and even though it's quite fancy with its transactions
processing (for consensus operation) it shouldn't ever change the state of the
Blockchain. If we're to change anything here these changes may conflict with
the actual block processing later or may lead to broken state (if transactions
won't be approved for some reason).
2019-12-12 21:14:33 +03:00
Roman Khimov
31dbc35279 core: gofmt dao_test.go 2019-12-12 21:05:36 +03:00
Roman Khimov
c5ed3b788b core: simplify dao creation with newDao() 2019-12-12 21:04:55 +03:00
Roman Khimov
8b3080b972 io: rename Read/WriteBytes to Read/WriteB
go vet is not happy about them:
  pkg/io/binaryReader.go:92:21: method ReadByte() byte should have signature ReadByte() (byte, error)
  pkg/io/binaryWriter.go:75:21: method WriteByte(u8 byte) should have signature WriteByte(byte) error
2019-12-12 20:19:50 +03:00
Roman Khimov
0b14916d79 io: use optimized Read/WriteUXX for Read/WriteVarUint() 2019-12-12 20:19:50 +03:00
Roman Khimov
54d888ba70 io: add type-specific read/write methods
This seriously improves the serialization/deserialization performance for
several reasons:
 * no time spent in `binary` reflection
 * no memory allocations being made on every read/write
 * uses fast ReadBytes everywhere it's appropriate

It also makes Fixed8 Serializable just for convenience.
2019-12-12 20:19:50 +03:00
Roman Khimov
89d7f6d26e core/tx: microoptimize block/tx hashing
Don't hash the data twice.
2019-12-12 18:01:30 +03:00
Roman Khimov
7e83078d13 hash: remove useless no-op decoding
It changes nothing here.
2019-12-12 17:58:34 +03:00
Vsevolod Brekelov
c93a8d2bc4 core: extracted same logic to separate methods 2019-12-11 13:14:45 +03:00
Vsevolod Brekelov
c1f39d5c7b internal: moved testutil method to internal package 2019-12-11 13:14:43 +03:00
Vsevolod Brekelov
2d42b14a1d core: renames entities-> state and removed State prefix 2019-12-11 13:14:18 +03:00
Vsevolod Brekelov
8809fe437d core: unit tests for dao 2019-12-11 13:13:51 +03:00
Vsevolod Brekelov
c0e59ebd4e core: unit tests for entities 2019-12-11 13:05:31 +03:00
Vsevolod Brekelov
c7ac4b6dff core: fix encoding and decoding for notification event 2019-12-11 13:05:31 +03:00
Vsevolod Brekelov
ec17654986 core: refactoring blockchain state and storage
add dao which takes care about all CRUD operations on storage
remove blockchain state since everything is stored on change
remove storage operations from structs(entities)
move structs to entities package
2019-12-11 13:05:31 +03:00
Roman Khimov
d0f9a28196 vm/core: improve block import speed with PublicKey caching
This change (closely related to the neo-project/neo#1321 proposal) speeds up
1.4M mainnet blocks import by 30%. Basically, we're eliminating key decoding
for block's multisignature that has the same keys most of the time.

Things I don't like about this patch:
 * yet another parameter for verifyHashAgainstScript()
 * vm keys are not copied in/out

But it's rather simple and solves the problem for this particular case, so I
think it's worth it.
2019-12-10 19:13:29 +03:00
Roman Khimov
35e368c241 io: add a note for WriteArray, fix #519
It can't be really solved in many cases (it's used in P2P protocol and we have
to follow the usual conventions there) and in most of the cases we don't care
about the difference between nil slice and zero-length slice.
2019-12-09 18:39:30 +03:00
Roman Khimov
f1856bfa8b core/tx: remove publickey indirection from assets and txes
It makes very little sense having pointers here, these structures MUST have
some kind of key and this key is not gonna be wandering somewhere on its
own. Fixes a part of #519.
2019-12-09 18:33:04 +03:00
Roman Khimov
5b6c5af704 *: implement EncodeBinary with pointer receivers where appropriate
Everywhere except ParamType (which is just a byte), reduce copying things
around for no real reason.
2019-12-09 18:25:15 +03:00
Roman Khimov
7e371588a7 core/tx: remove one layer of indirection for scripts and inouts
It reduces heap pressure a little for these elements as we don't have to
allocate/free them individually. And they're directly tied to transactions or
block, not being shared or anything like that, so it makes little sense for
them to be pointer-based. It only makes building transactions a little easier,
but that's obviously a minor usecase.
2019-12-09 17:14:10 +03:00
Roman Khimov
b542a5e7a0 io: add support for pointer receivers in WriteArray()
It's actually preferable to have pointer receivers for serializable types, so
this should be supported.
2019-12-09 16:57:25 +03:00
Roman Khimov
052ba1e94f
Merge pull request #545 from nspcc-dev/feat/optimizeio
Remove some reflection from the io package
2019-12-09 15:12:13 +03:00
Evgenii Stratonikov
fccb008594 io: implement ReadBytes() 2019-12-09 15:00:15 +03:00
Evgenii Stratonikov
838050f8b5 io: rename ReadBytes() to ReadVarBytes() 2019-12-09 15:00:15 +03:00
Evgenii Stratonikov
f01fc1cc29 io: optimize BinWriter.WriteArray()
Replace reflect.MethodByName with a simple interface cast.
2019-12-09 14:59:49 +03:00
Evgenii Stratonikov
1784a14148 io: optimize BinReader.ReadArray()
reflect.MethodByName is a rather expensive function especially when
called on hot path. This became obvious during profiling of db restore.
This commit replaces reflection with a cast to an interface.
2019-12-09 14:58:37 +03:00
Roman Khimov
3898aadcec rpc: simplify uint160 handling
Use new Uint160DecodeStringLE() function.
2019-12-06 19:47:58 +03:00
Roman Khimov
e4d821f32d
Merge pull request #546 from nspcc-dev/write-optimizations
Write optimizations
2019-12-06 19:40:38 +03:00
Roman Khimov
9992a98007 core: optimize balance utxo removal
One of my samples had 8 (out of 30) seconds spent here, but values of 100ms
are more typical. After this change it becomes invisible.
2019-12-06 18:46:24 +03:00
Roman Khimov
844491d365 *: use more efficient WriteBytes where appropriate
Before this patch on block import we could easily be spending more than 6
seconds out of 30 in Uint256 encoding for UnspentBalance, now it's completely
off the radar.
2019-12-06 18:22:21 +03:00
Roman Khimov
e7687d620d io: simplify WriteBytes()
Which speeds it up at least twofold for a typical 32-bytes write (and that's
for a very naïve test that allocates new BufBinWriter on every iteration):

pkg: github.com/CityOfZion/neo-go/pkg/io
BenchmarkWriteBytes-8           10000000               124 ns/op
BenchmarkWriteBytesOld-8         5000000               251 ns/op
2019-12-06 17:40:47 +03:00
Evgenii Stratonikov
aa20a95181 util: add Uint256DecodeStringBE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
72fe884faa util: add Uint160DecodeStringLE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
07e832f046 util: add Uint160DecodeBytesLE() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
09b295d727 util: add Uint160.Reverse() 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
9e04e61533 util: make Uint160Size public 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
7179e4ba9f util: add LE suffix to Uint256 methods 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
57efad912c util: add LE suffix to Uint160 methods 2019-12-06 12:16:55 +03:00
Evgenii Stratonikov
138c94eda3 consensus: sign and verify consensus messages 2019-12-06 11:35:06 +03:00
Evgenii Stratonikov
765c354793 consensus: return signed messages from recovery.Get* 2019-12-06 11:33:32 +03:00
Roman Khimov
652ede03c8
Merge pull request #543 from nspcc-dev/force-neo-vm-tests-run
vm: force neo-vm tests presence
2019-12-05 12:42:57 +03:00
Roman Khimov
8beb135829
Merge pull request #542 from nspcc-dev/fix-storage-interop-reads
core: fix wrong data being read in interops (part of #501)
2019-12-05 09:08:38 +03:00
Roman Khimov
becd4f2333 vm: force neo-vm tests presence
We succeeded this test without running anything real which is certainly not
good and I think we should always run this tests.
2019-12-04 20:30:27 +03:00