Commit graph

46 commits

Author SHA1 Message Date
Roman Khimov
cb64957af5 vm: don't use Stack for istack
We don't use all of the Stack functionality for it, so drop useless methods
and avoid some interface conversions. It increases single-node TPS by about
0.9%, so nothing really important there, but not a bad change either. Maybe it
can be reworked again with generics though.
2022-11-18 11:35:29 +03:00
Roman Khimov
13f5fdbe8a vm: extract shared parts of the Context
Local calls reuse them, cross-contract calls create new ones. This allows to
avoid some allocations and use a little less memory.
2022-08-05 14:26:25 +03:00
Roman Khimov
fab8dfb9f8 vm: move State type into a package of its own
It's used a lot in other places that need it, but don't need whole VM at the
same time.
2022-07-08 18:34:52 +03:00
Anna Shaleva
2096ad6e81 *: remove io/ioutil uses
Close #1764.
2022-03-17 19:39:18 +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
Evgeniy Stratonikov
4f98ec2f53 vm: embed reference counter in compound items
```
name              old time/op  new time/op  delta
RefCounter_Add-8  44.8ns ± 4%  11.7ns ± 3%  -73.94%  (p=0.000 n=10+10)
```

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-13 14:41:26 +03:00
Evgeniy Stratonikov
cff8b1c24e stackitem: use Bool item directly
It is always copied.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-12 17:53:36 +03:00
Roman Khimov
de5e61588d vm: simplify some test code
gosimple: S1017: should replace this `if` statement with an unconditional `strings.TrimPrefix`
2021-05-12 18:44:35 +03:00
Evgenii Stratonikov
dbe81f9b80 smartcontract: move flags to a separate package 2021-01-14 17:52:09 +03:00
Roman Khimov
77ea3d361b vm: update neo-vm tests, simplify parsing
We no longer have "*N" notation, see neo-project/neo-vm#326.
2020-08-22 23:35:29 +03:00
Roman Khimov
0e2784cd2c always wrap errors when creating new ones with fmt.Errorf()
It doesn't really change anything in most of the cases, but it's a useful
habit anyway.

Fix #350.
2020-08-07 12:21:52 +03:00
Roman Khimov
5ef08f60ae remove github.com/pkg/errors from dependencies
It's not needed any more with Go 1.13 as we have wrapping/unwrapping in base
packages. All errors.Wrap calls are replaced with fmt.Errorf, some strings are
improved along the way.
2020-08-07 12:21:52 +03:00
Evgenii Stratonikov
51ae12e4fd *: move syscall handling out of VM
Remove interop-related structures from the `vm` package.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
fyrchik
b187dfe3ce
Merge pull request #1236 from nspcc-dev/rpc/getrawmempool
rpc: update `getrawmempool` and `getrawtransaction` RPC-calls
2020-07-29 10:18:51 +03:00
Anna Shaleva
70ef733ce7 core, vm: store VMState as byte instead of string
Part of #1183
2020-07-29 10:14:08 +03:00
Evgenii Stratonikov
6ecd1ae437 vm: allow to initialize static slot in method 2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
299491080a vm: simplify interop id in json tests 2020-07-24 10:44:02 +03:00
Evgenii Stratonikov
68ad620af0 vm: update json tests to master 2020-07-24 10:44:02 +03:00
Anna Shaleva
8fde41001e core, vm: remove allowed triggers from syscalls
Closes #1205.
2020-07-23 20:44:39 +03:00
Roman Khimov
1bb26dcdc1 vm: fix INITSSLOT, it's context-wide, not VM-wide
It's tied to the current contract, not to VM.
2020-07-09 15:00:49 +03:00
Evgenii Stratonikov
4dfce07d11 vm: provide trigger upon VM creation 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
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
Roman Khimov
35b30ccfdf core: drop OLDPUSH1, it's no longer needed
Fixes #927.
2020-06-05 19:20:16 +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
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
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
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
f5933c83c6 vm: update json tests to neo3 branch
Skip them until all opcodes will be implemented.
2020-04-17 11:46:31 +03:00
Roman Khimov
8318adac56 vm: add support for dynamic invocations in APPCALL
Fixes #740.
2020-03-10 17:17:36 +03:00
Roman Khimov
e41d434a49 *: move all packages from CityOfZion to nspcc-dev 2020-03-03 17:21:42 +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
c821e1c4c8 vm: move IntToBytes and BytesToInt to emit package 2020-02-06 18:45:37 +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
f0083b94c5 vm: use new big.Int (de-)serialization routines
Also fix a test with CAT.
2020-01-17 17:37:50 +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
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
Roman Khimov
8d4dd2d2e1 vm: move opcodes into their own package
This allows easier reuse of opcodes and in some cases allows to eliminate
dependencies on the whole vm package, like in compiler that only needs opcodes
and doesn't care about VM for any other purpose.

And yes, they're opcodes because an instruction is a whole thing with
operands, that's what context.Next() returns.
2019-12-03 18:22:14 +03:00
Evgenii Stratonikov
6c002297cd vm: implement json tests from neoVM
Add neo-vm submodule @master2.x .
Closes #196.
2019-11-06 16:22:56 +03:00