Commit graph

1187 commits

Author SHA1 Message Date
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
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