Commit graph

4059 commits

Author SHA1 Message Date
Leonard Lyubich
3381716ebe oracle/neofs: Use function which combines all NeoFS client errors
Add function which unifies NeoFS API client's errors with failed status
reponses.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-12-02 11:59:25 +03:00
Leonard Lyubich
0c4017cc20 oracle/neofs: Upgrade NeoFS dependencies
Replace `neofs-api-go` module with `neofs-sdk-go`. Adapt to NeoFS
response statuses in the implementation of NeoFS oracle.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-12-02 11:59:20 +03:00
Roman Khimov
aa1da9de5a vm: preallocate for istack
Avoid growing it in runtime.
2021-12-01 21:36:35 +03:00
Roman Khimov
decff2bfb9 stackitem: simplify extracting value from map
Going through interfaces doesn't make it faster.
2021-12-01 21:36:35 +03:00
Roman Khimov
af8a4da6d9 stackitem: use type switch more effectively
Reduce the number of allocations, save some time.

name               old time/op    new time/op    delta
EncodeBinary-8       51.2µs ± 8%    44.6µs ± 7%  -12.79%  (p=0.008 n=5+5)
SerializeSimple-8     523ns ± 5%     449ns ± 4%  -14.27%  (p=0.008 n=5+5)

name               old alloc/op   new alloc/op   delta
EncodeBinary-8        329kB ± 0%     329kB ± 0%   -0.12%  (p=0.008 n=5+5)
SerializeSimple-8      432B ± 0%      408B ± 0%   -5.56%  (p=0.008 n=5+5)

name               old allocs/op  new allocs/op  delta
EncodeBinary-8         36.0 ± 0%      20.0 ± 0%  -44.44%  (p=0.008 n=5+5)
SerializeSimple-8      7.00 ± 0%      6.00 ± 0%  -14.29%  (p=0.008 n=5+5)
2021-12-01 21:36:35 +03:00
Roman Khimov
418ba1dbc3 *: use internal variables for simple big.NewInt() values
Avoid additional allocations.
2021-12-01 21:36:25 +03:00
Roman Khimov
3eed9d06f8 stackitem: add some hint to 'seen' maps
It's empirical, we usually have one container, but four is likely to fit most
of regular cases.
2021-12-01 21:36:25 +03:00
Roman Khimov
9576e10d04 storage: use map size hints to optimize subsequent persist()
We're likely to have something comparable to the current changeset in the
subsequent one. If it's bigger, no big deal, it'll be reallocated, if it's
smaller, no big deal, the next one will be preallocated smaller.
2021-12-01 21:36:25 +03:00
Roman Khimov
428ba48444 mempool: use capacity parameter to avoid map reallocations
Which is what happens in AddBlock that fills a new pool with exactly the
number of transactions we know already.
2021-12-01 21:36:25 +03:00
Roman Khimov
e236ac4067 io: optimize WriteString, avoid allocation
name                          old time/op    new time/op    delta
AppExecResult_EncodeBinary-8     477ns ± 0%     467ns ± 3%     ~     (p=0.190 n=4+5)

name                          old alloc/op   new alloc/op   delta
AppExecResult_EncodeBinary-8      376B ± 0%      368B ± 0%   -2.13%  (p=0.008 n=5+5)

name                          old allocs/op  new allocs/op  delta
AppExecResult_EncodeBinary-8      5.00 ± 0%      4.00 ± 0%  -20.00%  (p=0.008 n=5+5)
2021-12-01 21:36:25 +03:00
Roman Khimov
748a70569a mempool: use uint256 library for fee tracking
It's very effective in avoiding allocations for big.Int, we don't have a
microbenchmark for memppol, but this improves TPS metrics by ~1-2%, so it's
noticeable.
2021-12-01 21:36:25 +03:00
Roman Khimov
ee05f73b6f vm: simplify slot and make it private
Hiding refcounter inside a slot is actually a good idea, but it makes the
structure somewhat bigger, especially given that the refcounter is the same
and belongs more to VM or Context. New structure is a bit more efficient:

name                    old time/op    new time/op    delta
ScriptFibonacci-8          672µs ± 2%     644µs ± 0%  -4.15%  (p=0.008 n=5+5)
ScriptNestedRefCount-8    1.08ms ± 1%    1.05ms ± 2%  -2.56%  (p=0.008 n=5+5)
ScriptPushPop/4-8         1.52µs ± 1%    1.47µs ± 1%  -3.14%  (p=0.008 n=5+5)
ScriptPushPop/16-8        3.66µs ± 1%    3.54µs ± 1%  -3.24%  (p=0.008 n=5+5)
ScriptPushPop/128-8       24.7µs ± 1%    23.2µs ± 1%  -6.14%  (p=0.008 n=5+5)
ScriptPushPop/1024-8       183µs ± 1%     173µs ± 1%  -5.01%  (p=0.008 n=5+5)

name                    old alloc/op   new alloc/op   delta
ScriptFibonacci-8          114kB ± 0%     114kB ± 0%    ~     (p=0.079 n=4+5)
ScriptNestedRefCount-8     241kB ± 0%     241kB ± 0%    ~     (p=0.333 n=5+4)
ScriptPushPop/4-8           160B ± 0%      160B ± 0%    ~     (all equal)
ScriptPushPop/16-8          640B ± 0%      640B ± 0%    ~     (all equal)
ScriptPushPop/128-8       8.70kB ± 0%    8.70kB ± 0%    ~     (all equal)
ScriptPushPop/1024-8      73.2kB ± 0%    73.2kB ± 0%    ~     (all equal)

name                    old allocs/op  new allocs/op  delta
ScriptFibonacci-8          3.17k ± 0%     3.17k ± 0%  -0.03%  (p=0.008 n=5+5)
ScriptNestedRefCount-8     10.7k ± 0%     10.7k ± 0%    ~     (all equal)
ScriptPushPop/4-8           8.00 ± 0%      8.00 ± 0%    ~     (all equal)
ScriptPushPop/16-8          32.0 ± 0%      32.0 ± 0%    ~     (all equal)
ScriptPushPop/128-8          259 ± 0%       259 ± 0%    ~     (all equal)
ScriptPushPop/1024-8       2.05k ± 0%     2.05k ± 0%    ~     (all equal)

It'd be especially nice to internalize static slot, but as we can't compare
slices it's not possible.
2021-12-01 21:36:25 +03:00
Roman Khimov
a0473aca92
Merge pull request #2283 from nspcc-dev/fix-vm-tests
vm: fix cli tests
2021-12-01 11:35:41 +03:00
Roman Khimov
01d15ff473
Merge pull request #2270 from nspcc-dev/vm-invoked-contracts
Add invoked contract tracing
2021-12-01 11:27:27 +03:00
AnnaShaleva
c67d249a8d vm: fix cli tests
* Remove extra symbols during command execution.
* Fix test contract paths.
2021-12-01 11:14:29 +03:00
Roman Khimov
c663d3f39f
Merge pull request #2279 from nspcc-dev/minor-fixes
services: fix Oracle response creation algorithm
2021-11-30 18:15:50 +03:00
Roman Khimov
dbe184a335
Merge pull request #2280 from nspcc-dev/compiler-struct-cast
compiler: allow to slice struct field
2021-11-30 18:14:56 +03:00
Roman Khimov
f12f871432 compiler: use new defer stack for inlined functions, fix #2281
Inlined functions shouldn't care about outer scope defer statements, they
can't.
2021-11-30 18:04:02 +03:00
Roman Khimov
cddd5e1f6d compiler: add a panic on internal lambda inconsistency
It's a bit better than behavior observer in #2281 (which is very cryptic).
2021-11-30 18:02:38 +03:00
Evgeniy Stratonikov
66a4245bef compiler: allow to slice struct field
It makes no sense to restrict to identifiers.
2021-11-30 15:48:46 +03:00
Anna Shaleva
1d1538c566 services: fix Oracle response transaction creation
Problem: transactions with wrong hashes are accepted to the chain if
consensus nodes are designated as Oracle nodes. The result is wrong
MerkleRoot for the accepted block. Consensus nodes got such blocks
right from the dbft and store them without errors, but if
non-consensus nodes are present in the network, they just can't accept
these "bad" blocks:
```
2021-11-29T12:56:40.533+0300	WARN	blockQueue: failed adding block into the blockchain	{"error": "invalid block: MerkleRoot mismatch (expected a866b57ad637934f7a7700e3635a549387e644970b42681d865a54c3b3a46122, calculated d465aafabaf4539a3f619d373d178eeeeab7acb9847e746e398706c8c1582bf8)", "blockHeight": 17, "nextIndex": 18}
```

This problem happens because of transaction hash caching. We can't set
transaction hash if transaction construction wasn't yet completed.
2021-11-30 10:43:58 +03:00
Roman Khimov
33e37e60e5
Merge pull request #2264 from nspcc-dev/fix-win-tests
*: Windows compatibility fixes
2021-11-29 11:25:35 +03:00
AnnaShaleva
aefb6f9fee *: fix tests failing due to path.Join usage
Solution:
Use `file/filepath` package to construct expected path. This package is OS-aware, see https://github.com/golang/go/issues/30616.
2021-11-29 11:11:09 +03:00
Anna Shaleva
6cdb701a9d vm: improve error message for (*executor).checkError
It is helpful if something goes wrong.
2021-11-29 11:09:39 +03:00
AnnaShaleva
7c48177bf7 io: fix TestMakeDirForFile* tests
Problem:
```
--- FAIL: TestMakeDirForFile_HappyPath (0.01s)
    testing.go:894: TempDir RemoveAll cleanup: remove C:\Users\Anna\AppData\Local\Temp\TestMakeDirForFile_HappyPath402638411\001\testDir\testFile.test: The process cannot access the file because it is being used by another process.
--- FAIL: TestMakeDirForFile_Negative (0.01s)
    testing.go:894: TempDir RemoveAll cleanup: remove C:\Users\Anna\AppData\Local\Temp\TestMakeDirForFile_Negative672737582\001\testFile.test: The process cannot access the file because it is being used by another process.
FAIL
```

Solution:
Release resources occupied by os.Create.
2021-11-26 18:26:27 +03:00
AnnaShaleva
06beb4d534 core: fix TestMemCachedPersist test
Problem:
```
--- FAIL: TestMemCachedPersist (0.07s)
    --- FAIL: TestMemCachedPersist/BoltDBStore (0.07s)
        testing.go:894: TempDir RemoveAll cleanup: remove C:\Users\Anna\AppData\Local\Temp\TestMemCachedPersist_BoltDBStore294966711\001\test_bolt_db: The process cannot access the file because it is being used by another process.
```

Solution:
Release the resources occupied by the DB.
2021-11-26 18:26:27 +03:00
Anna Shaleva
e2ef904901 config: use http for oracle nodes
Otherwise the following error occurs:
```
first path segment in URL cannot contain colon
```
2021-11-26 17:17:10 +03:00
Roman Khimov
b455e9338c
Merge pull request #2275 from nspcc-dev/add-more-oracle-logs
oracle: unify filtering and add log for error case
2021-11-25 09:51:48 +03:00
Evgeniy Stratonikov
fac595bbdf core: remove old storage items asynchronously
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-24 16:25:11 +03:00
Evgeniy Stratonikov
582d489c90 dao: add P2PStateExchangeExtensions setting to dao.Version
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-24 16:22:27 +03:00
Evgeniy Stratonikov
f1767f361d dao: add KeepOnlyLatestState setting to dao.Version
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-24 16:22:27 +03:00
Evgeniy Stratonikov
f7e2d3d717 dao: add stateroot-related settings to Version
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-24 16:22:27 +03:00
Evgeniy Stratonikov
856e9cf67b statesync: copy state by swapping prefix
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-24 16:22:27 +03:00
Evgeniy Stratonikov
6c5a7d9b29 dao: include settings in Version
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-24 16:22:26 +03:00
Evgeniy Stratonikov
856385b106 dao: use custom storage prefix
We use 2 prefixes for storing items because of state synchronization.
This commit allows to parametrize dao with the default prefix.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-24 16:22:07 +03:00
Roman Khimov
6de6415a53 oracle: unify filtering and add log for error case
Just to simplify debugging.
2021-11-23 18:43:15 +03:00
Roman Khimov
019af7de46
Merge pull request #2271 from nspcc-dev/fix-sync-oom
core: add and use synchronous persist to avoid OOM
2021-11-23 12:37:48 +03:00
Roman Khimov
f58d424c6d rpc/client: fix custom* scope processing in CreateTxFromScript
Copying just the scope doesn't work for CustomContracts, CustomGroups and
Rules because they all contain additional metadata. Thanks @mialbu for
reporting this.
2021-11-22 12:44:42 +03:00
Roman Khimov
5fbe838fd4 core: add and use synchronous persist to avoid OOM
b9be892bf9 has made Persist asynchronous which
is very effective in allowing the system to continue processing
blocks/transactions while flushing things to disk. It at the same time is very
dangerous in that if the disk is slow and it takes much time to flush KV set
(more than persisting interval), there might be even bigger new KV set in
MemCachedStore by the time it finishes. Even if the system immediately starts
to flush this new data set it (being bigger) can take more time than the
previous one. And while doing so a new data set will appear in memory,
potentially again bigger than this.

So we can easily end up with the system going out of control, consuming more
and more memory and taking more and more time to persist a single set of
data. To avoid this we need to detect such condition and just wait for Persist
to really finish its job and release the resources.
2021-11-22 10:41:40 +03:00
Roman Khimov
c01427ca65 rpc: add verbose parameter to invokefunction and invokescript 2021-11-20 21:57:41 +03:00
Roman Khimov
5b470f14cc rpc: pass single Param to CreateFunctionInvocationScript
N3 contracts require method and array of arguments to function correctly, but
CreateFunctionInvocationScript can produce scripts that won't work correctly
if one is to pass anything but a single array parameter to it. This doesn't
make much sense, so we can always expect there to be an array of parameters in
the third positional invokefunction argument (the same way C# node does).
2021-11-20 21:57:41 +03:00
Roman Khimov
d01f9da8f3 vm: add invocation tree tracing 2021-11-20 21:57:41 +03:00
Roman Khimov
eb96f5a5a2 vm: drop CheckReturnState definition
It's something obsolete from RC phase.
2021-11-20 21:57:41 +03:00
Roman Khimov
b0a8f54776 vm: drop LoadArgs method, it's a Legacy remnant 2021-11-20 21:57:41 +03:00
Roman Khimov
cd3670a199 vm: refactor LoadScript* internals a bit
Reduce code duplication, provide a single point where scripts are being loaded
into the VM (and new contexts are created).
2021-11-20 21:57:41 +03:00
Roman Khimov
83d0b2f465 interop: move invocation counter from VM to Context
It's created for interop and used by interop, VM doesn't care.
2021-11-20 21:57:41 +03:00
Roman Khimov
29cda5112a vm: simplify NEF loading by providing a special method
Offsets are still handled outside of VM to avoid introducing manifest
dependency (that's likely to be circular).
2021-11-20 21:57:41 +03:00
Roman Khimov
82d2231ea6 vm: make retCount an internal member of Context
Doesn't make much sense exposing it, it's only used by vm package itself.
2021-11-20 21:57:41 +03:00
Roman Khimov
c53d978edd vm: drop ParamCount from Context
It's unused and it's useless.
2021-11-20 21:57:41 +03:00
Roman Khimov
765235eca3 vm: omit context parameter from Call()
It's not used and should not be used to switch from contract to contract.
2021-11-20 21:57:41 +03:00
Roman Khimov
7b713762be vm: do not increment invocation counter in Call
Everywhere it matters (and that's callExFromNative() now) it's incremented
already, so when we're doing Call() at the same time (and it's done to invoke
`_initialize` method) we're effectively double-incrementing it.
2021-11-20 21:57:41 +03:00
Roman Khimov
a577d40de9 vm: move Jump method to the Context
Because it's only relevant for execution context itself.
2021-11-20 21:57:35 +03:00
Roman Khimov
8c704a49b5 interop/contract: micro-optimize argument pushes
Calling Estack() again and again is not very productive.
2021-11-19 16:26:01 +03:00
Roman Khimov
d1f4928e29 contract: drop useless code from call processing
It's done already by LoadScriptWithCallingHash()
2021-11-19 16:22:30 +03:00
Roman Khimov
aa06770b3d
Merge pull request #2266 from nspcc-dev/nep-11-tracking
NEP-11 tracking
2021-11-19 13:07:37 +03:00
Roman Khimov
f1145c8943 rpc/client: accept address as util.Uint160 in GetNEPXXTransfers
We're using proper util.Uint160 values everywhere in the client.
2021-11-19 12:58:46 +03:00
Roman Khimov
ce9d0b22cf *: use NEP-XX naming consistently in docs/comments
Standards are NEP-11 and NEP-17, not NEP11, not NEP17, not anything
else. Variable/function names of course can use whatever fits, but documents
and comments should be consistent wrt this.
2021-11-19 12:58:46 +03:00
Roman Khimov
1375918b63 rpc: add client-side NEP-11 methods 2021-11-19 12:58:46 +03:00
Roman Khimov
7f48653e66 rpc: add server-side NEP-11 tracking API 2021-11-19 12:58:46 +03:00
Anna Shaleva
c43c51dac1 neotest: extend Executor with DeployContractCheckFAULT 2021-11-18 12:28:04 +03:00
Anna Shaleva
a06fbae0ee neotest: extend Executor with InvokeScript* helpers
It is useful for tests and allows to omit code duplication.
2021-11-18 12:27:23 +03:00
Roman Khimov
b622c1934d core: only save token logs if there is something to save
Makes no sense storing empty ones.
2021-11-18 00:09:10 +03:00
Roman Khimov
f3278ea5b2 core: reuse the transfer log buffer
Make it a bit more efficient.
2021-11-18 00:09:10 +03:00
Roman Khimov
125e4231b0 core: store NEP-11 transfers, add accessor functions 2021-11-18 00:09:10 +03:00
Roman Khimov
a860e82e9d
Merge pull request #2262 from nspcc-dev/neotest-fixes
neotest: minor usability improvements
2021-11-17 11:26:33 +03:00
Roman Khimov
7f40a0cfd8 state: prime token transfer info with the demand for new logs
Setting NewNEPXXBatch avoids the need to get them from the database which is
useful for newly tracked accounts.
2021-11-16 22:52:10 +03:00
Roman Khimov
095ed3f64e dao: drop unused AppendNEP17Transfer() 2021-11-16 22:51:04 +03:00
Roman Khimov
c63aeb38bb state: prepare for NEP-11 data tracking, refactor/rename
There is a lot of similarity, so try reusing common code and use more neutral
naming.
2021-11-16 19:18:06 +03:00
Anna Shaleva
1194361826 neotest: check deployed contract hash 2021-11-16 18:53:04 +03:00
Anna Shaleva
4057e635af neotest: add API to check notification event 2021-11-16 18:53:01 +03:00
Roman Khimov
ecfe3e7247
Merge pull request #2260 from nspcc-dev/fix-notary-test-failure
Fix notary test failure
2021-11-16 16:09:41 +03:00
Roman Khimov
3b08b5b19b native: add NEP-11 tracking to management contract 2021-11-16 13:28:59 +03:00
Roman Khimov
f96d9d168e native/interop: use oracle request signers for oracle response witness
Oracle responses must use the same set of signers as oracle requests even
though the transaction itself is signed by oracle nodes/contract.

We can probably improve interop.Context by removing Tx field completely and
adding more functionality to Container, but it's not very convenient for
VerifyWitness and will require adding more stub-like methods for Block, so Tx
is used for now (and we do have it in every relevant case).
2021-11-16 11:51:15 +03:00
Roman Khimov
65016e8070 core: fix data race in notary test
I don't think it's possible with regular service functioning, but it happens
during testing because of pointer reuse:

WARNING: DATA RACE
Read at 0x00c003a0e3f0 by goroutine 114:
  github.com/nspcc-dev/neo-go/pkg/services/notary.(*Notary).verifyIncompleteWitnesses()
      /home/runner/work/neo-go/neo-go/pkg/services/notary/notary.go:441 +0x1dc
  github.com/nspcc-dev/neo-go/pkg/services/notary.(*Notary).OnNewRequest()
      /home/runner/work/neo-go/neo-go/pkg/services/notary/notary.go:188 +0x205
  github.com/nspcc-dev/neo-go/pkg/core.TestNotary.func11()
      /home/runner/work/neo-go/neo-go/pkg/core/notary_test.go:347 +0x612
  github.com/nspcc-dev/neo-go/pkg/core.TestNotary()
      /home/runner/work/neo-go/neo-go/pkg/core/notary_test.go:443 +0xe33
  testing.tRunner()
      /opt/hostedtoolcache/go/1.16.10/x64/src/testing/testing.go:1193 +0x202

Previous write at 0x00c003a0e3f0 by goroutine 104:
  github.com/nspcc-dev/neo-go/pkg/services/notary.(*Notary).finalize()
      /home/runner/work/neo-go/neo-go/pkg/services/notary/notary.go:338 +0x50a
  github.com/nspcc-dev/neo-go/pkg/services/notary.(*Notary).PostPersist()
      /home/runner/work/neo-go/neo-go/pkg/services/notary/notary.go:314 +0x297
  github.com/nspcc-dev/neo-go/pkg/services/notary.(*Notary).Run()
      /home/runner/work/neo-go/neo-go/pkg/services/notary/notary.go:169 +0x4a7
2021-11-15 17:33:02 +03:00
Roman Khimov
f48dffe0e6 core: fix fallback VUB value in notary test
Serializing/deserializing the payload yields this:

 Error:          Received unexpected error:
                 both main and fallback transactions should have the same ValidUntil value
2021-11-15 17:32:14 +03:00
Roman Khimov
48de82d902 network: fix data race in TestHandleMPTData, fix #2241 2021-11-15 12:37:01 +03:00
Roman Khimov
cc4a63e454 rpc/server: use dynamic port for P2P service
Fix running tests alongside regular testnet node.

panic: TCP listen error

goroutine 4634 [running]:
go.uber.org/zap/zapcore.(*CheckedEntry).Write(0xc0008540c0, 0xc001a4df80, 0x1, 0x1)
        /home/rik/go/pkg/mod/go.uber.org/zap@v1.18.1/zapcore/entry.go:234 +0x532
go.uber.org/zap.(*Logger).Panic(0xc002399ce0, 0xecd669, 0x10, 0xc001a4df80, 0x1, 0x1)
        /home/rik/go/pkg/mod/go.uber.org/zap@v1.18.1/logger.go:230 +0x85
github.com/nspcc-dev/neo-go/pkg/network.(*TCPTransport).Accept(0xc000fd6960)
        /home/rik/dev/neo-go/pkg/network/tcp_transport.go:49 +0x216
created by github.com/nspcc-dev/neo-go/pkg/network.(*Server).Start
        /home/rik/dev/neo-go/pkg/network/server.go:292 +0x2bb
FAIL    github.com/nspcc-dev/neo-go/pkg/rpc/server      1.095s
2021-11-15 12:19:27 +03:00
Roman Khimov
7fa58a4dc8
Merge pull request #2255 from nspcc-dev/compiler-noreturn-defers
compiler: correctly handle defer in functions without return values
2021-11-15 10:43:00 +03:00
Roman Khimov
db99368e96 compiler: optimize GAS cost of type conversion
CONVERT call base price is 8192. DUP, ISTYPE and JMPIF all cost 2. So we add
0.07% overhead in the worst case and save 99.93% otherwise.

At the same time, old code was just two bytes and new one is seven, but I
think it's tolerable considering how much GAS it can potentially save.

Fix #2250.
2021-11-12 19:58:21 +03:00
Roman Khimov
a91581fa16 compiler: correctly handle defer in functions without return values
Fix #2253.
2021-11-12 19:36:59 +03:00
Roman Khimov
b31a8d750e
Merge pull request #2252 from nspcc-dev/packmap-packstruct
vm: add PACKMAP/PACKSTRUCT, extend UNPACK
2021-11-12 18:25:54 +03:00
Roman Khimov
9cdd360606
Merge pull request #2251 from nspcc-dev/rules-witness-scope
transaction: add new Rules witness scope
2021-11-12 18:25:39 +03:00
Roman Khimov
410aabe7a1 compiler: drop some useless NOPs
They're all obsolete and not needed.
2021-11-12 17:19:59 +03:00
Roman Khimov
0d50730382 compiler: optimize map initialization with PACKMAP 2021-11-12 17:19:59 +03:00
Roman Khimov
a8befeea33 compiler: optimize new empty struct creation with PACKSTRUCT 2021-11-12 17:19:59 +03:00
Roman Khimov
909ea477f4 compiler: create arrays/structs more effectively
Use PACK/PACKSTRUCT.
2021-11-12 17:19:59 +03:00
Roman Khimov
3e6ce3c221 vm: add PACKMAP/PACKSTRUCT, extend UNPACK
See neo-project/neo-vm#443.
2021-11-12 17:19:59 +03:00
Roman Khimov
9875799893 transaction: add new Rules witness scope
See neo-project/neo#2622. The implementation is somewhat asymmetric (and not
very efficient) for binary/JSON encoding/decoding, but it should be
sufficient.
2021-11-12 15:29:28 +03:00
Anna Shaleva
4df5d370c5 neotest: export nonce() method
Sometimes user needs to construct transaction by itself, so it's better
to unify nonce sources for auto-generated and manually-generated
transactions to avoid nonce collisions in tests.
2021-11-11 20:00:40 +03:00
Roman Khimov
0a7f8afcea
Merge pull request #2229 from nspcc-dev/contract-test
Generic contract testing infrastructure
2021-11-11 11:46:55 +03:00
Evgeniy Stratonikov
ce549e4cb2 core/test: allow to determine system fee automatically
Eventually this will be replaced by `pkg/neotest` invocations but for
now it allows us to remove NNS constants together with the tests.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-11 11:15:15 +03:00
Evgeniy Stratonikov
79a48a7800 neotest: allow to use 6-node committee
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-11 11:15:15 +03:00
Evgeniy Stratonikov
bef2a6f7ae neotest: provide both validator and committee
It will become useful for multi-node committee.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-11 11:15:15 +03:00
Evgeniy Stratonikov
950adb7b89 neotest: support painless multi-signing
Implementing a separate `Signer` interface is beneficial in multiple
ways:
1. Support both single and multiple transaction witnesses.
2. It should be easy to add contract signer this way.

Tests should use accounts created with `NewAccount` so hiding all
details doesn't seem to be an issue.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-11 11:15:15 +03:00
Evgeniy Stratonikov
1f9fd4a472 neotest: add contract client wrapper
Reduces amount of boilerplate code in tests.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-11 11:15:15 +03:00
Evgeniy Stratonikov
e3625152c6 core: move NNS test out of core
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-11 11:15:15 +03:00
Evgeniy Stratonikov
233fca0c1e neotest: add contract testing framework
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-11 11:15:14 +03:00
Roman Khimov
6b8e615094
Merge pull request #2234 from nspcc-dev/rpc/params-parsing
rpc: method-specific parameters parsing optimisation
2021-11-10 20:45:44 +03:00
Anna Shaleva
3c13c8b7a5 rpc: refactor GetUint160FromHex helper
We can trim prefix using `strings` library like it is done for uint256.
2021-11-10 14:54:18 +03:00
Anna Shaleva
4072c2fa90 rpc: handlers parameters audit
Make them compatible with C#.
2021-11-10 14:54:09 +03:00
Anna Shaleva
867bb708fc rpc: add cache to basic parameters
Need to cache values of string, bool, int and array because they can be
reused multiple times by RPC handlers. Other values don't need to be
cached.
2021-11-10 14:42:40 +03:00
Anna Shaleva
2fd04fbb35 rpc: allow to pass null parameter to invoke* calls 2021-11-10 14:42:40 +03:00
Anna Shaleva
2e8bbf2a87 rpc: *In parameters marshalling optimisation
Parse request parameters on-demand.
2021-11-10 14:42:08 +03:00
Anna Shaleva
3be2a22af8 rpc: fix Unknown transaction response for gettransactionheight 2021-11-09 16:56:48 +03:00
Anna Shaleva
1a32fcb2dc core: specify method not found call error
It's useful for debugging and external users.
2021-11-08 17:19:00 +03:00
Evgeniy Stratonikov
4ab18d084a rpc/request: add unmarshal benchmark
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-11-01 17:21:04 +03:00
Roman Khimov
1d16016027
Merge pull request #2217 from nspcc-dev/compiler-overload
compiler: allow to overload methods in manifest
2021-11-01 14:49:43 +03:00
Roman Khimov
fe50f6edc7
Merge pull request #2240 from nspcc-dev/fix-panic-in-network
Fix panic on peer disconnect
2021-11-01 12:44:15 +03:00
Roman Khimov
774dee3cd4 network: fix disconnection race between handleConn() and handleIncoming()
handleIncoming() winning the race for p.Disconnect() call might lead to nil
error passed as the reason for peer unregistration.
2021-11-01 12:20:55 +03:00
Roman Khimov
2eeec73770 network: don't panic if there is no reason for disconnect
Although error should always be there, we shouldn't fail like this if it's not:
    | panic: runtime error: invalid memory address or nil pointer dereference
    | [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xc8884c]
    |
    | goroutine 113 [running]:
    | github.com/nspcc-dev/neo-go/pkg/network.(*Server).run(0xc000150580)
    |         github.com/nspcc-dev/neo-go/pkg/network/server.go:396 +0x7ac
    | github.com/nspcc-dev/neo-go/pkg/network.(*Server).Start(0xc000150580, 0x0)
    |         github.com/nspcc-dev/neo-go/pkg/network/server.go:294 +0x3fb
    | created by github.com/nspcc-dev/neo-go/cli/server.startServer
    |         github.com/nspcc-dev/neo-go/cli/server/server.go:344 +0x56f
2021-11-01 12:19:00 +03:00
Roman Khimov
328f8b7954
Merge pull request #2238 from nspcc-dev/fix-block-queue
network: remove priority queue from block queue
2021-11-01 12:03:45 +03:00
Roman Khimov
8bb1ecb45a network: remove priority queue from block queue
Use circular buffer which is a bit more appropriate. The problem is that
priority queue accepts and stores equal items which wastes memory even in
normal usage scenario, but it's especially dangerous if the node is stuck for
some reason. In this case it'll accept from peers and put into queue the same
blocks again and again leaking memory up to OOM condition.

Notice that queue length calculation might be wrong in case circular buffer
wraps, but it's not very likely to happen (usually blocks not coming from the
queue are added by consensus and it's not very fast in doing so).
2021-11-01 11:49:01 +03:00
Evgeniy Stratonikov
7758378d28 compiler: allow to overload methods in manifest
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-29 20:15:21 +03:00
Evgeniy Stratonikov
51127b8918 vmcli: convert base64 string to address in parse
In application logs hashes are serialized as base64 so it is useful
to convert them back to address via `util convert`.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-29 14:55:10 +03:00
Roman Khimov
67eac3a27f
Merge pull request #2196 from nspcc-dev/drop-badger-and-redis
Drop Badger and Redis
2021-10-28 16:08:49 +03:00
AnnaShaleva
3fed7b8eec core: handle empty MPT batch properly
It's OK to have it.
2021-10-27 18:44:39 +03:00
Roman Khimov
1144a03486 storage: drop RedisDB, close #2130 2021-10-27 17:32:25 +03:00
Roman Khimov
fb4b87bb96 storage: drop BadgerDB support, close #2130 2021-10-27 17:31:55 +03:00
Roman Khimov
fdf80dbdc5
Merge pull request #2225 from nspcc-dev/notary/allow-to-combine-witnesses
notary: allow to combine signers of different types
2021-10-26 17:54:07 +03:00
AnnaShaleva
2d196b3f35 rpc: refactor calculatenetworkfee handler
Use (Blockchainer).VerifyWitness() to calculate network fee for
contract-based witnesses.
2021-10-25 19:07:25 +03:00
Anna Shaleva
807fa4a720 services: allow non-empty inv scripts for contract-based notary witness 2021-10-25 17:23:29 +03:00
Evgeniy Stratonikov
4fe188a60d compiler: check correctness of emitted bytecode
The error here indicates a bug in compiler implementation.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-25 13:55:55 +03:00
Evgeniy Stratonikov
a885f84cad compiler: fail if some functions are missing
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-25 13:55:55 +03:00
Evgeniy Stratonikov
8a0429036b compiler: set type information during traversal, fix #2231
Set all necessary context before file traversal, not only import
maps. Also, we can skip restoring import maps because all our code is
processed via `For*` iterators which set necessary context.
We can also refactor this a bit to have all context in one place,
this will be done in #2086.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-25 13:55:55 +03:00
Anna Shaleva
75d7891ca1 services: add ability to combine notary signers
Notes for witnesses:
* [N sig + M multisig + K contract] combination is possible where N, M, K >=0.
* Each verification script should be properly filled in.
* Each invocation script should either be empty or contain exactly one
signature.
2021-10-25 12:22:13 +03:00
Evgeniy Stratonikov
b91de50e65 compiler: remove convert.To* from the list of builtins
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-23 16:16:03 +03:00
Evgeniy Stratonikov
a92bf281c1 compiler: remove custom logic for util builtins
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-23 16:12:47 +03:00
Roman Khimov
6fe8f4565d
Merge pull request #2228 from nspcc-dev/additional-interop
Constants and ABORT in interops
2021-10-22 21:45:57 +03:00
Anna Shaleva
fcc7f7349d services: refactor the logic of notary signatures counting
Maintain the number of signatures left to collect instead of maintaining
the number of already collected signatures and overall number of
signatures.
2021-10-22 17:06:46 +03:00
Roman Khimov
36295357d8 interop: add Abort() function to ABORT things
Related to #2227.
2021-10-22 14:50:51 +03:00
Anna Shaleva
693c376d21 vm: wait more for a test prog execution ending 2021-10-22 12:14:37 +03:00
Roman Khimov
e230040c2e interop: add canonical type lengths as constants
Contracts need them anyway.
2021-10-22 10:56:58 +03:00
Roman Khimov
d551439654
Merge pull request #2193 from nspcc-dev/optimize-find
core: optimise (*MemCachedStorage).Seek
2021-10-21 21:20:33 +03:00
Anna Shaleva
3450371910 core: split (*MemCachedStore) Seek and SeekAsync methods
Use SeekAsync for System.Storage.Find and Seek for the rest of cases.
2021-10-21 10:05:12 +03:00
Anna Shaleva
dcda7bec63 core: squash PS-seeking and merging routines in (*MemCachedStore).Seek
We don't need a separate routine to merge seek results.
2021-10-21 10:05:12 +03:00
Anna Shaleva
c88720bf45 core: remove memstore routine from (*MemCachedStore).SeekAsync
It adds unnecessary overhead to computations.
2021-10-21 10:05:12 +03:00
Anna Shaleva
dfe2c667e1 core: do not hold the lock while seeking over persistent store 2021-10-21 10:05:12 +03:00
Anna Shaleva
07cbe4d253 core: add finalizer functions to interop context
These functions are aimed to free the resources occupied by storage
iterator by the end of script execution or whenever Finilize is called.
2021-10-21 10:05:12 +03:00
Anna Shaleva
0a4f45c9b0 core: add ability to free storage.Iterator resources 2021-10-21 10:05:12 +03:00
Anna Shaleva
89ee2e7720 core: refactor storage.Find and storage.Iterator to work with channel
Add SeekAsync methods in order to fetch matching storage items
on demand. Refactor storage.Find and storage.Iterator wrt these changes.
2021-10-21 10:05:12 +03:00
Anna Shaleva
f2ac07a3c0 core: do not copy key/value results got from MemCachedStore.Seek
They are already copied inside the MemCachedStore.Seek, so that
persistent storage  can't change them anymore.
2021-10-21 10:05:12 +03:00
Anna Shaleva
72726d46d3 core: refactor callers of MemCachedStore.Seek
MemCachedStore.Seek now sorts results, so its callers may omit sorting.
2021-10-21 10:05:12 +03:00
Anna Shaleva
7ba88e98e2 core: optimize (*MemCachedStore).Seek operation
Real persistent storage guarantees that result of Seek is sorted
by keys. The idea of optimisation is to merge two sorted seek
results into one (memStore+persistentStore), so that
(*MemCachedStore).Seek will return sorted list. The only thing
that remains is to sort items got from (*MemoryStore).Seek.
2021-10-21 10:05:12 +03:00
Anna Shaleva
191cc45032 core: sort items in MemoryStore.Seek
MemoryStore is used in a MemCachedStore as a persistent layer in tests.
Further commits suppose that persistent storage returns sorted values
from Seek, so sort the result of MemoryStore.Seek.

Benchmark results for 10000 matching items in MemoryStore compared to
master:
name          old time/op    new time/op    delta
MemorySeek-8     712µs ± 0%    3850µs ± 0%   +440.52%  (p=0.000 n=8+8)

name          old alloc/op   new alloc/op   delta
MemorySeek-8     160kB ± 0%    2724kB ± 0%  +1602.61%  (p=0.000 n=10+8)

name          old allocs/op  new allocs/op  delta
MemorySeek-8     10.0k ± 0%     10.0k ± 0%     +0.24%  (p=0.000 n=10+10)

For details on implementation efficiency see the
https://github.com/nspcc-dev/neo-go/pull/2193#discussion_r722993358.
2021-10-21 10:05:12 +03:00
Anna Shaleva
d8210c0137 core: add benchmarks for iterator.Next, MemCached.Seek, Mem.Seek 2021-10-21 10:05:12 +03:00
Anna Shaleva
8d8071f97e core: distinguish storage.KeyValue and storage.KeyValueExists
We need Exists field for storage batch related code; other cases may go
without Exists, so add new KeyValue structure and refactor related code.
2021-10-21 10:05:12 +03:00
Roman Khimov
b44f9eefb0 rpc: correctly handle RPC invocations with no arguments, fix #2219
In N3 no arguments passed should be treated as empty arguments array not as
missing array of arguments, because the array must be present even for
functions that accept no parameters.
2021-10-16 21:28:43 +03:00
Anna Shaleva
002b5a2c3c core: add Trie.Find compatibility test 2021-10-15 10:28:08 +03:00
Anna Shaleva
55fb221bbb rpc: make getproof work with destroyed contracts
Now it's able to get proof for destroyed contract if the contract wasn't
destroyed before the requested stateroot's height.
2021-10-15 07:06:25 +03:00
Evgeniy Stratonikov
0bc81aecf4 compiler: do not emit code for unused imported functions
Our current algorithm marks function as used if it is called
at least ones, even if the callee function is itself unused.
This commit implements more clever traversal to collect usage
information more precisely.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-13 15:56:07 +03:00
Roman Khimov
2bec43511d
Merge pull request #2207 from nspcc-dev/rpc/gethistoricalstate
rpc: implement `getstate` and `findstates` RPC methods
2021-10-13 15:27:51 +03:00
Anna Shaleva
495aba4174 core: try to collapse traversed Billet part on errStop 2021-10-13 14:47:59 +03:00
Anna Shaleva
360bb220b0 rpc: remove unnecessary base64 encoding
It's default encoding for []byte.
2021-10-13 14:47:59 +03:00
Anna Shaleva
892eadf86d core: mandate passing from as a subprefix for (*Trie).Find
However, we need to distinguish empty subprefix and nil subprefix (no
start specified) to match the C# behaviour.
2021-10-13 14:47:41 +03:00
Anna Shaleva
8e7c76827b core: optimise (*Billet).Traverse and (*Trie).Find
(*Billet).Traverse changes:
1. Get rid of the `offset` argument. We can cut `from` and pass just the
part that remains. This implies that node with path matching `from` will
also be included in the result, so additional check needs to be added to
the callback function.
2. Pass `path` and `from` without search prefix. Append prefix to the
result inside the callback.
3. Remove duplicating code.

(*Trie).Find changes:
1. Properly prepare `from` argument for traversing function. It closly
depends on the `path` argument.
2021-10-13 13:52:33 +03:00
Anna Shaleva
43ac4e1517 rpc: implement findstates RPC handler 2021-10-13 11:41:05 +03:00
Anna Shaleva
7da394fd3f core: check MPT node is not requested twice by StateSync module
This check prevents infinite loop if something goes wrong with MPT nodes
restore process.
2021-10-12 14:08:56 +03:00
Roman Khimov
e2c4b6d393
Merge pull request #2209 from nspcc-dev/vm-exceptions
Catch out-of-bounds exceptions in VM
2021-10-12 09:30:49 +03:00
Roman Khimov
38ba6d735e
Merge pull request #2212 from nspcc-dev/fix-nep17-paging
rpc: use uint64 for timestamp boundaries in GetNEP17Transfers
2021-10-11 17:42:59 +03:00
Anna Shaleva
6eb3cad6d5 rpc: use uint64 for timestamp boundaries in GetNEP17Transfers
Block's timestamp is in milliseconds, so it overflows uint32.
2021-10-11 17:34:05 +03:00
Evgeniy Stratonikov
5c470a6e3d vm: catch out-of-bounds exceptions, fix #2208
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-11 17:28:00 +03:00
Evgeniy Stratonikov
435463e620 vm: allow big string keys in PICKITEM
Because `MaxKeySize` is bigger than integer size, we fail on integer
cast while retreiving items from map. SETITEM is not affected.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-11 17:14:28 +03:00
Anna Shaleva
01143da621 rpc: add getstate RPC handler 2021-10-11 16:43:44 +03:00
Evgeniy Stratonikov
8d562cef99 compiler: allow to use multiple underscores in func arguments
It should still be present in the argument array in VM so just don't
save them in the map.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-09 13:23:11 +03:00
Roman Khimov
fb31a81fd2
Merge pull request #2206 from nspcc-dev/compiler-safe-methods
compiler: check that safe methods exist
2021-10-07 14:53:37 +03:00
Roman Khimov
5ff475383b
Merge pull request #2200 from nspcc-dev/optimize-headers
network: request headers in parallel
2021-10-07 14:51:38 +03:00
Anna Shaleva
c8120a139d core: add MaxKeyLength restrictions to MPT's operations 2021-10-06 16:37:23 +03:00
Evgeniy Stratonikov
cb5b075e7d wallet: do not store file handle
Close immediately after read/write. This can be a bit slower but
we store everything in memory anyway and code size is smaller.
`wallet.Close()` method is now a no-op.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-06 15:29:52 +03:00
Evgeniy Stratonikov
4dd3a0d503 network: request headers in parallel, fix #2158
Do this similarly to how blocks are requested.
See also 4aa1a37.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-06 15:25:54 +03:00
Evgeniy Stratonikov
0c01d89827 compiler: check that safe methods exist
If a method is missing from the manifest, it is most likely a typo
or regression after refactoring. There is no "turn-off" flag
for this error because we can do this precisely.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-06 15:18:58 +03:00
Evgeniy Stratonikov
7b6203d0d4 wallet: allow to open in read-only mode, fix #2182
If wallet was opened via `NewWalletFromFile`, open it as read-only first
and re-open for write if needed.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-10-05 16:25:50 +03:00
Roman Khimov
b4e24bef14
Merge pull request #2202 from nspcc-dev/validatorscount
rpc: add validatorscount to getversion response
2021-09-29 11:55:59 +03:00
Roman Khimov
5a2b77238c rpc: add validatorscount to getversion response
See neo-project/neo-modules#642.
2021-09-28 10:10:26 +03:00
Evgeniy Stratonikov
45976a4111 rpc/response: beautify error message
If `Error.Cause` is nil, omit ugly `%s!<nil>`.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-09-28 09:57:42 +03:00
Evgeniy Stratonikov
e6aa9b76ee mempool: reword ErrConflict message, fix #2197
Make it more user-friendly.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-09-28 09:57:42 +03:00
fyrchik
cfeaeb0f07
Merge pull request #2194 from nspcc-dev/fix-config-types
config: fix duration parameter types
2021-09-27 10:20:15 +03:00
Evgeniy Stratonikov
7fa6c8dcf6 config: fix duration parameter types
These parameters denote seconds and are thus unitless integers, not
durations.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-09-25 13:13:51 +03:00
Anna Shaleva
5c97e0dcf2 rpc: move NotaryRequestEvent to the subscriptions pkg
It is used for subscriptions only, so move it to the subscriptions pkg.
2021-09-24 17:42:59 +03:00
Anna Shaleva
b3ea7504cb subscriptions: add container hash to notification event
External users make use of it. Close #2190.
2021-09-24 17:42:02 +03:00
Roman Khimov
42a9d3d7b8 nef: add Source field
Follow neo-project/neo#2605.
2021-09-24 00:19:37 +03:00
Roman Khimov
c009356b73 core: simplify component flushing in storeBlock
Instead of flushing everything to `cache` and then to `bc.dao`, wrap `bc.dao`
directly for block/tx data and AERs and then flush to it. Block/transactions
are usually processed more quickly than other components, so they easily end
up in `cache` where they directly affect Seek performance for any executing
transaction.

Simple as it is this change improves voter NEO transfer benchmark with 1000
accounts by more than 25%, from ~18500 TPS to ~23500 TPS. It doesn't affect
much other cases.
2021-09-22 17:15:12 +03:00
Roman Khimov
b66bc33cf9 native: short-circuit successive GAS distributions
GAS can only be distributed once in a block for particular address, so it
makes little sense trying to calculate it again and again. This fixes
neo-bench for NEO voter, because without it we get ~2500 TPS for
single-address test and with it it jumps 13-fold to normal values like
~33500.
2021-09-22 17:13:55 +03:00
Anna Shaleva
06d3c21e3f core: remove unused interopnames 2021-09-21 16:43:09 +03:00
Roman Khimov
4743d5aacf
Merge pull request #2181 from nspcc-dev/states-diff_testnet_289026
core: fix NEO balance state handler
2021-09-21 15:39:37 +03:00
Anna Shaleva
c113d682bd core: fix NEO balance state handler
We need to store NEO balance's LastUpdateHeight before GAS mint,
because mint can call onNEP17Payment and onNEP17Payment can call NEO
transfer which also calls GAS mint. Storing balance height allows to
avoid recursion.
2021-09-20 19:23:35 +03:00
Roman Khimov
56dd7b7364
Merge pull request #2177 from nspcc-dev/fix-lint
Replace golint with revive
2021-09-15 17:59:04 +03:00
Roman Khimov
68af14100c
Merge pull request #2174 from nspcc-dev/states-diff_testnet_284177
smartcontract: escape non-ascii characters for manifest.Extra SI
2021-09-15 15:07:25 +03:00
Anna Shaleva
dfc0b25cfe gomod: use nspcc-dev's fork of go-ordered-json
Escape non-ASCII characters while JSON encoding.
2021-09-15 15:01:01 +03:00
Roman Khimov
1480e29548
Merge pull request #2178 from nspcc-dev/fix-oracle-unsupported-code
transaction: fix ContentTypeNotSupported oracle code processing
2021-09-14 18:01:40 +03:00
Roman Khimov
24a3cce1ca
Merge pull request #2169 from nspcc-dev/states-diff_mainnet_131795
core: allow transfer 0 GAS/NEO with zero balance
2021-09-14 17:30:41 +03:00
Roman Khimov
8a440a4016 transaction: fix ContentTypeNotSupported oracle code processing
Fix testnet block 311487 block processing and synchronization errors:
  2021-09-14T15:18:53.611+0300    WARN    peer disconnected       {"addr": "20.198.226.132:20333", "reason": "invalid oracle response code", "peerCount": 10}

Fix 8e9302f40b.
2021-09-14 15:18:38 +03:00
Evgeniy Stratonikov
176b61e317 *: fix linter issues
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-09-14 14:39:39 +03:00
Evgeniy Stratonikov
918d7e65bf smartcontract: unmarhal null values properly
First we unmarshal `null` to `[]byte`, then we marshal it to the empty
string.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-09-14 13:28:01 +03:00
Roman Khimov
5209fe1e09
Merge pull request #2173 from nspcc-dev/fix-race
network: fix race in StateSync module tests
2021-09-14 11:57:21 +03:00
Roman Khimov
621478296c
Merge pull request #2161 from nspcc-dev/rpc-get-version
rpc: return protocol parameters in `getversion`, fix #2160
2021-09-13 19:10:43 +03:00
Anna Shaleva
6357af0bb0 network: fix race in TestHandleGetMPTData
Init server config before server start. Fixes the following data race:

```
WARNING: DATA RACE
Write at 0x00c00032ef20 by goroutine 26:
  github.com/nspcc-dev/neo-go/pkg/network.TestHandleGetMPTData.func2()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server_test.go:755 +0x10a
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1193 +0x202

Previous read at 0x00c00032ef20 by goroutine 24:
  github.com/nspcc-dev/neo-go/internal/fakechain.(*FakeChain).GetConfig()
      /go/src/github.com/nspcc-dev/neo-go/internal/fakechain/fakechain.go:167 +0x6f
  github.com/nspcc-dev/neo-go/pkg/network.(*Server).initStaleMemPools()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server.go:1433 +0x89
  github.com/nspcc-dev/neo-go/pkg/network.(*Server).Start()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server.go:284 +0x288
  github.com/nspcc-dev/neo-go/pkg/network.startWithChannel.func1()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server_test.go:91 +0x44

Goroutine 26 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1238 +0x5d7
  github.com/nspcc-dev/neo-go/pkg/network.TestHandleGetMPTData()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server_test.go:752 +0x8c
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1193 +0x202

Goroutine 24 (running) created at:
  github.com/nspcc-dev/neo-go/pkg/network.startWithChannel()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server_test.go:90 +0x78
  github.com/nspcc-dev/neo-go/pkg/network.startTestServer()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server_test.go:384 +0xbd
  github.com/nspcc-dev/neo-go/pkg/network.TestHandleGetMPTData.func2()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server_test.go:753 +0x55
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1193 +0x202
```
2021-09-13 11:45:48 +03:00
Anna Shaleva
29ef076f4b network: fix race in TestTryInitStateSync
Register peers properly. Fixes the following data race:
```
Read at 0x00c001184ac8 by goroutine 116:
  github.com/nspcc-dev/neo-go/pkg/network.(*localPeer).EnqueueHPPacket()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/helper_test.go:127 +0x1f2
  github.com/nspcc-dev/neo-go/pkg/network.(*localPeer).EnqueuePacket()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/helper_test.go:114 +0xac
  github.com/nspcc-dev/neo-go/pkg/network.(*localPeer).EnqueueMessage()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/helper_test.go:111 +0xc1
  github.com/nspcc-dev/neo-go/pkg/network.(*localPeer).SendPing()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/helper_test.go:159 +0x88
  github.com/nspcc-dev/neo-go/pkg/network.(*Server).runProto()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server.go:446 +0x409

Previous write at 0x00c001184ac8 by goroutine 102:
  github.com/nspcc-dev/neo-go/pkg/network.newLocalPeer()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/helper_test.go:83 +0x476
  github.com/nspcc-dev/neo-go/pkg/network.TestTryInitStateSync.func3()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server_test.go:1064 +0x40f
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1123 +0x202

Goroutine 116 (running) created at:
  github.com/nspcc-dev/neo-go/pkg/network.(*Server).run()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server.go:358 +0x69
  github.com/nspcc-dev/neo-go/pkg/network.(*Server).Start()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server.go:292 +0x488
  github.com/nspcc-dev/neo-go/pkg/network.startWithChannel.func1()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server_test.go:91 +0x44

Goroutine 102 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1168 +0x5bb
  github.com/nspcc-dev/neo-go/pkg/network.TestTryInitStateSync()
      /go/src/github.com/nspcc-dev/neo-go/pkg/network/server_test.go:1056 +0xbb
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1123 +0x202
```
2021-09-13 11:45:48 +03:00
Evgeniy Stratonikov
8a3e05096b *: gofmt -s
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-09-10 21:49:11 +03:00
Evgeniy Stratonikov
c465b18cb2 rpc: return protocol parameters in getversion, fix #2160
`StateRootInHeader` is duplicated similarly to `Network`.
It will be removed in future as it is surely a protocol parameter.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-09-10 21:45:59 +03:00
Roman Khimov
63e00ac128
Merge pull request #2166 from nspcc-dev/fix-nns-compat
Fix NNS compatibility
2021-09-10 18:10:17 +03:00
Anna Shaleva
7fc57c9d58 core: allow transfer 0 GAS/NEO with zero balance
This commit fixes states diff at 131795 block of mainnet.

Transaction:
```
NEO-GO-VM > loadbase64 DAAQDBSPsxdYh6cITC3gUKI4oWmYxJs49gwUj7MXWIenCEwt4FCiOKFpmMSbOPYUwB8MCHRyYW5zZmVyDBT1Y+pAvCg9TQ4FxI6jBbPyoHNA70FifVtSOQwAEQwUj7MXWIenCEwt4FCiOKFpmMSbOPYMFL1Mb4Fqp6gHiEwzM6xSc8fLS+RpFMAfDAh0cmFuc2ZlcgwU9WPqQLwoPU0OBcSOowWz8qBzQO9BYn1bUjk=
READY: loaded 176 instructions
NEO-GO-VM 0 > ops
INDEX    OPCODE       PARAMETER
0        PUSHDATA1     ("")                                       <<
2        PUSH0
3        PUSHDATA1    8fb3175887a7084c2de050a238a16998c49b38f6
25       PUSHDATA1    8fb3175887a7084c2de050a238a16998c49b38f6
47       PUSH4
48       PACK
49       PUSH15
50       PUSHDATA1    7472616e73666572 ("transfer")
60       PUSHDATA1    f563ea40bc283d4d0e05c48ea305b3f2a07340ef    // NEO token
82       SYSCALL      System.Contract.Call (627d5b52)
87       ASSERT
88       PUSHDATA1     ("")
90       PUSH1
91       PUSHDATA1    8fb3175887a7084c2de050a238a16998c49b38f6
113      PUSHDATA1    bd4c6f816aa7a807884c3333ac5273c7cb4be469
135      PUSH4
136      PACK
137      PUSH15
138      PUSHDATA1    7472616e73666572 ("transfer")
148      PUSHDATA1    f563ea40bc283d4d0e05c48ea305b3f2a07340ef    // NEO token
170      SYSCALL      System.Contract.Call (627d5b52)
175      ASSERT

```

Go's applog:
```
{
   "id" : 1,
   "result" : {
      "txid" : "0x97d2ccb01467b22c73a2cb95f7af298f3a5bd8c849d7044371898b8efecdaabd",
      "executions" : [
         {
            "exception" : "at instruction 87 (ASSERT): ASSERT failed",
            "stack" : [],
            "gasconsumed" : "4988995",
            "notifications" : [],
            "trigger" : "Application",
            "vmstate" : "FAULT"
         }
      ]
   },
   "jsonrpc" : "2.0"
}
```

C#'s applog:
```
{
   "jsonrpc" : "2.0",
   "result" : {
      "executions" : [
         {
            "stack" : [],
            "notifications" : [
               {
                  "contract" : "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5",
                  "state" : {
                     "type" : "Array",
                     "value" : [
                        {
                           "type" : "ByteString",
                           "value" : "j7MXWIenCEwt4FCiOKFpmMSbOPY="
                        },
                        {
                           "type" : "ByteString",
                           "value" : "j7MXWIenCEwt4FCiOKFpmMSbOPY="
                        },
                        {
                           "value" : "0",
                           "type" : "Integer"
                        }
                     ]
                  },
                  "eventname" : "Transfer"
               },
               {
                  "contract" : "0xd2a4cff31913016155e38e474a2c06d08be276cf",
                  "state" : {
                     "value" : [
                        {
                           "type" : "Any"
                        },
                        {
                           "type" : "ByteString",
                           "value" : "vUxvgWqnqAeITDMzrFJzx8tL5Gk="
                        },
                        {
                           "value" : "2490",
                           "type" : "Integer"
                        }
                     ],
                     "type" : "Array"
                  },
                  "eventname" : "Transfer"
               },
               {
                  "contract" : "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5",
                  "state" : {
                     "value" : [
                        {
                           "value" : "vUxvgWqnqAeITDMzrFJzx8tL5Gk=",
                           "type" : "ByteString"
                        },
                        {
                           "value" : "j7MXWIenCEwt4FCiOKFpmMSbOPY=",
                           "type" : "ByteString"
                        },
                        {
                           "value" : "1",
                           "type" : "Integer"
                        }
                     ],
                     "type" : "Array"
                  },
                  "eventname" : "Transfer"
               }
            ],
            "vmstate" : "HALT",
            "gasconsumed" : "9977990",
            "trigger" : "Application",
            "exception" : null
         }
      ],
      "txid" : "0x97d2ccb01467b22c73a2cb95f7af298f3a5bd8c849d7044371898b8efecdaabd"
   },
   "id" : 1
}

```
2021-09-10 17:18:09 +03:00
Roman Khimov
aaccf748ac nft-nd-nns: add getAllRecords method
See neo-project/non-native-contracts#5.
2021-09-10 16:30:45 +03:00
Roman Khimov
c4637514d4
Merge pull request #2165 from nspcc-dev/rpc/audit
rpc: request handlers audit
2021-09-10 13:16:40 +03:00
Anna Shaleva
b989fdb462 rpc: fill transaction witnesses during invokescript handling 2021-09-10 11:38:59 +03:00
Anna Shaleva
61fd7bd6ba core: avoid nil values during natives manifest marshalling 2021-09-10 11:38:59 +03:00
Anna Shaleva
61faf28738 rpc: avoid null unverified transactions in getrawmempool response 2021-09-10 11:38:59 +03:00
Anna Shaleva
ed9cdfe667 rpc: use core Header for getblockheader response
Nonce and Primary fields were missing from response.
2021-09-09 18:47:22 +03:00
Anna Shaleva
db13362e86 core: marshal Block.Nonce in upper-case hex 2021-09-09 15:52:51 +03:00
Anna Shaleva
3b04b6d238 vm: refactor stack dump commands 2021-09-09 13:45:10 +03:00
Anna Shaleva
6da458365d vm CLI: allow to dump slots 2021-09-09 13:45:10 +03:00
Roman Khimov
b502c5f148
Merge pull request #2162 from nspcc-dev/docs/update
docs: minor documentation updates and adjustments
2021-09-09 12:38:20 +03:00
Anna Shaleva
2f23d83a49 interop: adjust documentation 2021-09-08 17:53:09 +03:00
Anna Shaleva
df8141ff7d rpc: adjust client documentation 2021-09-08 17:53:09 +03:00
Anna Shaleva
913e3878c5 vm CLI: check whether VM is ready before jumping to the instruction
It allows to avoid panic:
```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xdab469]

goroutine 1 [running]:
github.com/nspcc-dev/neo-go/pkg/vm.(*VM).Jump(...)
	github.com/nspcc-dev/neo-go/pkg/vm/vm.go:1506
github.com/nspcc-dev/neo-go/pkg/vm/cli.handleRun(0xc0005988f0)
	github.com/nspcc-dev/neo-go/pkg/vm/cli/cli.go:413 +0x2e9
github.com/abiosoft/ishell/v2.(*Shell).handleCommand(0xc0004320f0, {0xc00032c7c0, 0xc0002a3920, 0x0})
	github.com/abiosoft/ishell/v2@v2.0.2/ishell.go:279 +0x143
github.com/abiosoft/ishell/v2.handleInput(0xc0004320f0, {0xc00032c7c0, 0x3, 0x4})
	github.com/abiosoft/ishell/v2@v2.0.2/ishell.go:233 +0x31
github.com/abiosoft/ishell/v2.(*Shell).run(0xc0004320f0)
	github.com/abiosoft/ishell/v2@v2.0.2/ishell.go:212 +0x30f
github.com/abiosoft/ishell/v2.(*Shell).Run(0xc0004320f0)
	github.com/abiosoft/ishell/v2@v2.0.2/ishell.go:112 +0x28
github.com/nspcc-dev/neo-go/pkg/vm/cli.(*VMCLI).Run(0xc000224030)
	github.com/nspcc-dev/neo-go/pkg/vm/cli/cli.go:538 +0x39
github.com/nspcc-dev/neo-go/cli/vm.startVMPrompt(0xc0001f46e0)
	github.com/nspcc-dev/neo-go/cli/vm/vm.go:28 +0xb4
github.com/urfave/cli.HandleAction({0xe65fa0, 0x1161c68}, 0x2)
	github.com/urfave/cli@v1.22.5/app.go:524 +0xa8
github.com/urfave/cli.Command.Run({{0xfed435, 0x2}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x100576d, 0x19}, {0x0, ...}, ...}, ...)
	github.com/urfave/cli@v1.22.5/command.go:173 +0x652
github.com/urfave/cli.(*App).Run(0xc0001016c0, {0xc0000c6000, 0x2, 0x2})
	github.com/urfave/cli@v1.22.5/app.go:277 +0x705
main.main()
	./main.go:19 +0x33
```
2021-09-08 17:53:09 +03:00
Anna Shaleva
cbc75afd4d docs: refactor documentation
CLI:
* Typos are fixed
* Documentation on NEP-11 tokens is added
* NeoGo node configuration is moved to a separate file

Compiler:
* Typos and indentations are fixed
* Ops dump example is updated

Consensus:
* Typos are fixed
* Links are fixed

Notifications:
* Minor adjustments

RPC:
* `getversion` response is updated
* `getunclamedgas` comment is removed (not valid since
https://github.com/neo-project/neo-modules/pull/243)

VM:
* Update help message
* `load*` command adjustments
* `astack` command removal
2021-09-08 17:52:46 +03:00
Anna Shaleva
0fa48691f7 network: do not duplicate MPT nodes in GetMPTNodes response
Also tests are added.
2021-09-08 14:25:54 +03:00
Anna Shaleva
51c8c0d82b core: add tests for StateSync module 2021-09-07 19:43:27 +03:00
Anna Shaleva
0aedfd0038 core: fix bug in MPT pool during Update
We need to copy the result of `TryGet` method, otherwice the slice can
be modified inside `Add` or `Update` methods, which leads to
inconsistent MPT pool state.
2021-09-07 19:43:27 +03:00
Anna Shaleva
36808b8904 core: clone MPT node while restoring it multiple times
We need this to avoid collapse collisions. Example of such collapse
described in
https://github.com/nspcc-dev/neo-go/pull/2019#discussion_r689629704.
2021-09-07 19:43:27 +03:00
Anna Shaleva
5cd78c31af core: allow to recover after state jump interruption
We need several stages to manage state jump process in order not to mess
up old and new contract storage items and to be sure about genesis state data
are properly removed from the storage. Other operations do not require
separate stage and can be performed each time `jumpToStateInternal` is
called.
2021-09-07 19:43:27 +03:00
Anna Shaleva
5cda24b3af core: initialize headers before current block 2021-09-07 19:43:27 +03:00
Anna Shaleva
0e0b55350a core: convert (*Blockchain).JumpToState to a callback
We don't need this method to be exposed, the only its user is the
StateSync module. At the same time StateSync module manages its state by
itself which guarantees that (*Blockchain).jumpToState will be called
with proper StateSync stage.
2021-09-07 19:43:27 +03:00
Anna Shaleva
6381173293 core: store statesync-related storage items under temp prefix
State jump should be an atomic operation, we can't modify contract
storage items state on-the-fly. Thus, store fresh items under temp
prefix and replase the outdated ones after state sync is completed.
Related
https://github.com/nspcc-dev/neo-go/pull/2019#discussion_r693350460.
2021-09-07 19:43:27 +03:00
Anna Shaleva
51f405471e core: remove outdated blocks/txs/AERs/MPT nodes during state sync
Before state sync process can be started, outdated MPT nodes
should be removed from storage. After state sync is completed,
outdated blocks/transactions/AERs should also be removed.
2021-09-07 19:43:27 +03:00
Anna Shaleva
a276a85b72 core: unify code of state sync module initialization 2021-09-07 19:43:27 +03:00
Anna Shaleva
3b7807e897 network: request unknown MPT nodes
In this commit:

1. Request unknown MPT nodes from peers. Note, that StateSync module itself
shouldn't be responsible for nodes requests, that's a server duty.
2. Do not request the same node twice, check if it is in storage
already. If so, then the only thing remaining is to update refcounter.
2021-09-07 19:43:27 +03:00
Anna Shaleva
6a04880b49 core: collapse completed parts of Billet
Some kind of marker is needed to check whether node has been collapsed
or not. So introduce (HashNode).Collapsed
2021-09-07 19:43:27 +03:00
Anna Shaleva
74f1848d19 core: adjust LastUpdatedBlock calculation for NEP17 balances
...wrt P2PStateExchange setting.
2021-09-07 19:43:27 +03:00
Anna Shaleva
d67ff30704 core: implement statesync module
And support GetMPTData and MPTData P2P commands.
2021-09-07 19:43:27 +03:00
Anna Shaleva
a22b1caa3e core: implement MPT Billet structure for MPT restore
MPT restore process is much simpler then regular MPT maintaining: trie
has a fixed structure, we don't need to remove or rebuild MPT nodes. The
only thing we should do is to replace Hash nodes to their unhashed
counterparts and increment refcount. It's better not to touch the
regular MPT code and create a separate structure for this.
2021-09-07 19:43:27 +03:00
Roman Khimov
c9e62769a6
Merge pull request #2143 from nspcc-dev/mpt/add_empty_values
core: allow empty MPT Leaf values
2021-09-07 09:18:48 +03:00
Anna Shaleva
c95f2079d5 core: adjust comments on behaviour defferences for MPT TestCompatibility
C# node does not return empty proof enymore in case if path is bad. C#
node also throws an exception on bad Put.

Our node does not return an error on delete if the key is empty.
2021-09-03 13:46:52 +03:00
Anna Shaleva
f721384ead core: allow empty MPT Leaf values
Allow it for (*Trie).Put. And distinguish empty value and nil value for
(*Trie).PutBatch, because batch is already capable of handling both nil
and empty value. For (*Trie).PutBatch putting nil value means deletion,
while putting empty value means just putting LeafNode with an empty
value.
2021-09-03 13:46:48 +03:00
Evgeniy Stratonikov
7371593bdc native/policy: disallow blocking native contracts
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-09-03 11:11:06 +03:00
Evgeniy Stratonikov
9d34547118 rpc/client: add MaxConnsPerHost option, fix #2149
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-09-02 11:26:17 +03:00
Roman Khimov
b07347e602 core: reuse PushItem for interops
Probably less critical here, but still let's push things faster.
2021-08-30 23:43:58 +03:00
Roman Khimov
a3892aa662 vm: don't use PushVal when item type is known
PushVal is very convenient, but type switch is somewhat expensive.

name                    old time/op    new time/op    delta
ScriptFibonacci-8          736µs ± 1%     602µs ± 1%  -18.21%  (p=0.000 n=9+10)
ScriptNestedRefCount-8    1.08ms ± 2%    0.96ms ± 1%  -11.13%  (p=0.000 n=10+10)
ScriptPushPop/4-8         1.48µs ± 3%    1.35µs ± 2%   -9.14%  (p=0.000 n=10+9)
ScriptPushPop/16-8        3.59µs ± 1%    3.38µs ± 1%   -6.01%  (p=0.000 n=10+10)
ScriptPushPop/128-8       23.7µs ± 1%    22.6µs ± 1%   -4.39%  (p=0.000 n=10+8)
ScriptPushPop/1024-8       176µs ± 2%     167µs ± 3%   -5.24%  (p=0.000 n=9+10)

name                    old alloc/op   new alloc/op   delta
ScriptFibonacci-8          123kB ± 0%     114kB ± 0%   -6.88%  (p=0.000 n=10+9)
ScriptNestedRefCount-8     266kB ± 0%     241kB ± 0%   -9.23%  (p=0.000 n=8+10)
ScriptPushPop/4-8           160B ± 0%      160B ± 0%     ~     (all equal)
ScriptPushPop/16-8          640B ± 0%      640B ± 0%     ~     (all equal)
ScriptPushPop/128-8       8.70kB ± 0%    8.70kB ± 0%     ~     (all equal)
ScriptPushPop/1024-8      73.2kB ± 0%    73.2kB ± 0%     ~     (all equal)

name                    old allocs/op  new allocs/op  delta
ScriptFibonacci-8          3.53k ± 0%     3.17k ± 0%   -9.98%  (p=0.000 n=10+10)
ScriptNestedRefCount-8     11.8k ± 0%     10.7k ± 0%   -8.70%  (p=0.000 n=10+10)
ScriptPushPop/4-8           8.00 ± 0%      8.00 ± 0%     ~     (all equal)
ScriptPushPop/16-8          32.0 ± 0%      32.0 ± 0%     ~     (all equal)
ScriptPushPop/128-8          259 ± 0%       259 ± 0%     ~     (all equal)
ScriptPushPop/1024-8       2.05k ± 0%     2.05k ± 0%     ~     (all equal)
2021-08-30 23:43:58 +03:00
Roman Khimov
bc31c97c32 vm: simplify access to context, don't call Context() twice
Avoid going through Value(), avoid doing type casts twice for every
instruction.

name                    old time/op    new time/op    delta
ScriptFibonacci-8          793µs ± 3%     736µs ± 1%  -7.18%  (p=0.000 n=10+9)
ScriptNestedRefCount-8    1.09ms ± 1%    1.08ms ± 2%  -0.96%  (p=0.035 n=10+10)
ScriptPushPop/4-8         1.51µs ± 3%    1.48µs ± 3%    ~     (p=0.072 n=10+10)
ScriptPushPop/16-8        3.76µs ± 1%    3.59µs ± 1%  -4.56%  (p=0.000 n=10+10)
ScriptPushPop/128-8       25.0µs ± 1%    23.7µs ± 1%  -5.28%  (p=0.000 n=10+10)
ScriptPushPop/1024-8       184µs ± 1%     176µs ± 2%  -4.22%  (p=0.000 n=9+9)
2021-08-30 23:43:58 +03:00
Roman Khimov
e09a0f3969 vm: don't allocate for break points in NewContext
They're rarely used and when they're used they're appended to.
2021-08-29 13:15:12 +03:00
Roman Khimov
7b9558d756
Merge pull request #2142 from nspcc-dev/fix-customgroups-witness-scope
runtime: fix CustomGroups witness
2021-08-26 18:13:08 +03:00
Roman Khimov
734eef3290
Merge pull request #2147 from nspcc-dev/drop-go-1.14
Drop Go 1.14, use 1.17
2021-08-26 17:59:21 +03:00
Roman Khimov
932a57e1e4 keys: reuse coordLen where appropriate 2021-08-26 17:30:04 +03:00
Roman Khimov
6d074a96e9 *: make tests use TempDir(), fix #1319
Simplify things, drop TempFile at the same time (refs. #1764)
2021-08-26 17:29:40 +03:00
Roman Khimov
40c6c065d2
Merge pull request #2140 from nspcc-dev/vm-optimize-stack
Optimize VM stack
2021-08-26 10:31:31 +03:00
Roman Khimov
f4ba21a41a keys: use (*Int).FillBytes where appropriate
Allows to avoid some allocations. Refs. #1319.
2021-08-25 22:35:39 +03:00
Roman Khimov
76eca07961 keys: simplify NewPrivateKeyFrom* functions
Avoid allocating a slice and doing double calculations.
2021-08-25 22:35:39 +03:00
Roman Khimov
61ea42c570 keys: simplify end of buffer check 2021-08-25 22:35:39 +03:00
Roman Khimov
4803cc15c7 keys: add (*PublicKey).DecodeBytes benchmark
Attempts to reuse elliptic.Unmarshal() and elliptic.UnmarshalCompressed() lead
to this:
name                 old time/op    new time/op    delta
PublicDecodeBytes-8    59.5µs ± 2%    61.8µs ± 1%  +3.78%  (p=0.000 n=10+9)

name                 old alloc/op   new alloc/op   delta
PublicDecodeBytes-8    3.99kB ± 0%    4.27kB ± 0%  +6.81%  (p=0.000 n=9+10)

name                 old allocs/op  new allocs/op  delta
PublicDecodeBytes-8       136 ± 0%       135 ± 0%  -0.74%  (p=0.000 n=10+10)

So it makes no sense. Refs. #1319.
2021-08-25 22:35:39 +03:00
Roman Khimov
a1d96a7d7d keys: use elliptic package marshalling functions, #1319
name                       old time/op    new time/op    delta
PublicBytes-8                81.4ns ± 6%    71.2ns ± 8%  -12.56%  (p=0.000 n=10+10)
PublicUncompressedBytes-8    93.2ns ±17%    72.5ns ±14%  -22.25%  (p=0.000 n=10+10)

name                       old alloc/op   new alloc/op   delta
PublicBytes-8                 80.0B ± 0%     48.0B ± 0%  -40.00%  (p=0.000 n=10+10)
PublicUncompressedBytes-8     80.0B ± 0%     48.0B ± 0%  -40.00%  (p=0.000 n=10+10)

name                       old allocs/op  new allocs/op  delta
PublicBytes-8                  2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=10+10)
PublicUncompressedBytes-8      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=10+10)
2021-08-25 22:35:39 +03:00
Roman Khimov
217d7bdf44 keys: add equality benchmark
Go 1.15 provides native (*ecdsa.PublicKey).Equal method, but we can't drop our
own Equal because the types are different and there is still code using our
Equal (forcing it to convert types is counterproductive), while changing
(*PublicKey).Equal to use (*ecdsa.PublicKey).Equal internally with some kind of

  (*ecdsa.PublicKey)(p).Equal((*ecdsa.PublicKey)(key))

slows it down:

name           old time/op    new time/op    delta
PublicEqual-8    14.9ns ± 1%    18.4ns ± 2%  +23.55%  (p=0.000 n=9+10)

name           old alloc/op   new alloc/op   delta
PublicEqual-8     0.00B          0.00B          ~     (all equal)

name           old allocs/op  new allocs/op  delta
PublicEqual-8      0.00           0.00          ~     (all equal)

So leave it as is, but add this micro-bench. Refs. #1319.
2021-08-25 15:18:26 +03:00