Commit graph

789 commits

Author SHA1 Message Date
Anna Shaleva
c647f8e4ed core: add maxBlockSystemFee to native Policy
Closes #1195
2020-08-04 10:59:00 +03:00
Anna Shaleva
13336f9dba core: adjust calling flags of native Policy methods 2020-08-03 16:09:10 +03:00
Anna Shaleva
60f9abae40 core: chenge maxBlockSizeKey of native Policy 2020-08-03 16:00:15 +03:00
fyrchik
e4fc655115
Merge pull request #1239 from nspcc-dev/store_nep5_with_id
core: store contract IDs instead of hashes for NEP5Balances and Transfers
2020-07-30 12:56:19 +03:00
Roman Khimov
e21c65c59f core: add state height to prometheus metrics
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
5ee3ecf381 core: update verified state root height
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
ab802cdd5f state: implement JSON marshaling for MPT* items
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
236438d799 core: do MPT compaction every once in a while
We need to compact our in-memory MPT from time to time, otherwise it quickly
fills up all available memory. This raises two obvious quesions --- when to do
that and to what level do that.

As for 'when', I think it's quite easy to use our regular persistence interval
as an anchor (and it also frees up some memory), but we can't do that in the
persistence routine itself because of synchronization issues (adding some
synchronization primitives would add some cost that I'd also like to avoid),
so do it indirectly by comparing persisted and current height in `storeBlock`.

Choosing proper level is another problem, but if we're to roughly estimate one
full branch node to use 1K of memory (usually it's way less than that) then we
can easily store 1K of these nodes and that gives us a depth of 10 for our
trie.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
58b7e16e0e core: fix PrevHash calculation for MPTRoot
This was differing from C# notion of PrevHash. It's not a previous root, but
rather a hash of the previous serialized MPTRoot structure (that is to be
signed by CNs).

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
caea6d6ca8 mpt: fix extension node cache invalidation
It should always be invalidated if something changes in the `next` (below the
extension node).

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
0e29382035 core: update MPT during block processing
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
2b53877dff mpt: don't flush nodes already present in the DB
It's just a waste of time.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Roman Khimov
475bf2445a mpt: restructure nodes a bit, implement serialization and hash cache
It drastically reduces the number of allocations and hash calculations.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
6ca22027d5 mpt: implement (*Trie).Collapse()
Because trie size is rather big, it can't be stored in memory.
Thus some form of caching should also be implemented. To avoid
marshaling/unmarshaling of items which are close to root and are used
very frequenly we can save them across the persists.
This commit implements pruning items at the specified depth,
replacing them by hash nodes.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
f0b85f8af7 mpt: implement JSON marshaling/unmarshaling
Because there is no distinct type field in JSONized nodes, distinction
is made via payload itself, thus all unmarshaling is done via
NodeObject.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
9b328240dd mpt: implement MPT proof Get and Verify
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Evgenii Stratonikov
dc6741bce7 mpt: implement MPT trie
MPT is a trie with a branching factor = 16, i.e. it consists of sequences in
16-element alphabet.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-30 12:42:15 +03:00
Anna Shaleva
0dd1730632 core: store NEP5Transfer asset by ID instead of hash
To avoid problems with retrieving decimals for migrated contracts.
2020-07-29 15:15:48 +03:00
Anna Shaleva
b9bdab8ec8 core: store nep5balances using contract id
Closes #1194
2020-07-29 15:15:48 +03:00
Anna Shaleva
dbd460d883 core: retrieve contract hash by ID
We'll need this ability further to retrieve contracts hashes for Nep5Balances.
2020-07-29 15:14:24 +03:00
Evgenii Stratonikov
9a992865b1 interop: add Secp2k to the list of crypto interops
Allow to use them during verification.
2020-07-29 13:43:33 +03:00
Evgenii Stratonikov
23a1430395 core: allow to restrict creating callbacks from syscalls
Specify DisallowCallback flag if syscall is not allowed to be used in a
callback.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
99b0397a61 core: implement System.Callback.CreateFromSyscall interop
Allow to create callbacks from syscalls.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
c54b45e76d core: implement System.Callback.CreateFromMethod interop
Support creating callbacks from contract methods.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
f96c217aba core/tests: refactor getting contract state
Get 2 contracts in pair which is useful everytime we need to test
syscall with one contract calling the other.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
e654d22991 core/tests: introduce loadScript helper
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
382a7f5b3e core: implement System.Callback.* interops
Support creating callbacks from pointers.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +03:00
Evgenii Stratonikov
c09ea04df3 core: add prices for TRY* opcodes
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2020-07-29 13:41:08 +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
Anna Shaleva
4bf88ba6b0 core: decouple native contracts from interop service
Closes #1191.
2020-07-29 10:33:18 +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
685d44dbc1 *: support _initialize method in contracts
Invoke `_initialize` method on every call if present.
In NEO3 there is no entrypoint and methods are invoked by offset,
thus `Main` function is no longer required.
We still have special `Main` method in tests to simplify them.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
466af55dea vm: isolate stack in LoadScript
When calling contract it must be provided with a new stack containing
only it's arguments. The result is then copied back on RET.

Fix #1220.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
d2ddf7b7cb *: support invoking methods by offset
Allow to invoke methods by offset:
1. Every invoked contract must have manifest.
2. Check arguments count on invocation.
3. Change AppCall to a regular syscall.
4. Add test suite for `System.Contract.Call`.
2020-07-27 13:00:35 +03:00
Evgenii Stratonikov
54d7882acf core: compiler contract on-the-fly in helper test
Generate proper manifest file too.
2020-07-27 13:00:34 +03:00
Evgenii Stratonikov
7d8fead1fd native: change onPersist return type to Void 2020-07-27 11:08:01 +03:00
Evgenii Stratonikov
e52c39ae7e manifest: remove EntryPoint from manifest 2020-07-27 11:08:01 +03:00
Roman Khimov
d2c823daa6
Merge pull request #1233 from nspcc-dev/fix/gasverify
core: restrict maximum gas allow for verification
2020-07-26 22:40:13 +03:00
Evgenii Stratonikov
121c9664b4 core: restrict maximum gas allow for verification
Disallow costly verification methods. We put this limit in policy
contract as it may be a subject to change in future.
In fact this value also overrides gas limit for header verification.
Close #1202.
2020-07-25 14:33:38 +03:00
Evgenii Stratonikov
8931c9a794 core/interop: increase coverate for crypto interops 2020-07-25 12:16:56 +03:00
Evgenii Stratonikov
83e53fab24 core/test: ensure public key is invalid in test
When providing public key as a subslice, it still can be
decoded as a valid key, thus interop will not return an error
but rather push `false` on stack. This test is about providing
invalid key, so ensure this via setting invalid prefix.
2020-07-25 12:01:16 +03:00
Anna Shaleva
8fde41001e core, vm: remove allowed triggers from syscalls
Closes #1205.
2020-07-23 20:44:39 +03:00
Roman Khimov
d8a1c3de46
Merge pull request #1221 from nspcc-dev/neo3/interop/post-preview2_adjustment3
interop: post-preview2 adjustment, part 3
2020-07-23 20:35:53 +03:00
Anna Shaleva
ef8de3b2dc core: adjust System.Runtime.GetNotifications interop
Part of #1055.

Forgot to add this pretty interop to the list of system interops.
2020-07-23 07:54:51 +03:00
Anna Shaleva
120eff92f7 core: adjust System.Runtime.Notify interop
Part of #1198.

Notification name should be UTF8-encoded.
2020-07-23 07:55:12 +03:00
Anna Shaleva
2c41b7b254 core: adjust System.Runtime.Log interop
Part of #1055 and #1198.

It should check the message length and encoding.
2020-07-23 07:54:51 +03:00
Anna Shaleva
88e003d219 core: adjust System.Runtime.GetTime interop
Part of #1055.

It should have AllowStates flag.
2020-07-23 07:51:24 +03:00
Anna Shaleva
990ef5525c core: adjust System.Runtime.GasLeft interop
Part of #1055.

In test mode it should return -1.
2020-07-23 07:51:24 +03:00
Anna Shaleva
8fed383523 core: adjust System.Runtime.CheckWitness interop
Part of #1055.

It should have `AllowStates` flag.

Also removed unreachable code: we can't have such situation when
script container is not a transaction in the scope of `CheckWitness`
method because:
1. Blocks have their own implementation of CheckWitness for
internal usage (it's (bc *Blockchain) verifyHeaderWitnesses method).
2. For the outside calls of System.Runtime.CheckWitness interop (e.g.
calls from smart-contract) script container is always a transaction.
2020-07-23 07:51:24 +03:00