Commit graph

1900 commits

Author SHA1 Message Date
Anna Shaleva
27b0193da0 core: use native cache to check whether the same contract exists on deploy 2022-04-29 16:10:04 +03:00
Anna Shaleva
c0b490c7bf core: keep Management cache always valid and up-to-date 2022-04-29 16:10:04 +03:00
Anna Shaleva
11ab42d91c core: keep Designation cache always valid and up-to-date
Always use cache instead of DAO where possible. Update cache in-place
each time new designated node is chosen.
2022-04-29 16:10:04 +03:00
Anna Shaleva
c8bdd2ad1a core: remove Persist from NativeCache interface
Lower native cache should be assigned to the upper's value during persist.
2022-04-29 16:10:04 +03:00
Anna Shaleva
8ec8511d9d core: remove mutexes and atomic values from native cache
Native cache is always wrapped into independant layers, so concurrent
RW access is no-op.
2022-04-29 16:10:04 +03:00
Anna Shaleva
7b632c8ee8 core: refactor natives cache
1. Use layered natives cache. With layered cache the storeblock
process includes the following steps: create a wrapper over
current nativeCache, put changes into upper nativeCache layer,
persist (or discard) changes.
2. Split contract getters to read-only and read-and-change. Read-only
ones doesn't require the copy of an existing nativeCache item.
Read-and-change ones create a copy and after that change the copy.
2022-04-29 16:10:04 +03:00
Anna Shaleva
aa886f67ce core: use dao-binded cache for native contracts
All native cached values are binded to DAO, so that it's possible
to properly handle historic calls.
2022-04-29 16:10:04 +03:00
Anna Shaleva
812fa3f76a core: initialize NEO config cache in constructor
It isn't changed within the contract lifetime, thus initialisation can be
safely performed in constructor.
2022-04-29 16:10:04 +03:00
Anna Shaleva
e63d6aeff7 core: move natives cache initialisation to a separate method 2022-04-29 16:10:04 +03:00
Anna Shaleva
93fde3b4e6 core: fix typo in TestCreateBasicChain 2022-04-29 16:10:04 +03:00
Anna Shaleva
63c26ca270 core, rpc: support [invokefunction, invokescript, invokecontractverify]historic 2022-04-29 16:10:04 +03:00
Anna Shaleva
f8b5972f61 core: support Store interface over MPT 2022-04-29 16:10:04 +03:00
Anna Shaleva
0cf525d62e core: add ability to traverse backwards for Billet 2022-04-29 16:10:04 +03:00
Roman Khimov
3ae1647940
Merge pull request #2447 from nspcc-dev/gettransactionsigners
core: add GetTransactionSigners method to native Ledger
2022-04-29 11:58:38 +03:00
Anna Shaleva
1762fd9128 core: add test to check GetTransactionSigners interop API 2022-04-29 11:34:26 +03:00
Anna Shaleva
47d52bd9c5 core: add getTransactionSigners method to native Ledger 2022-04-29 11:18:58 +03:00
Anna Shaleva
aaf7c423b4 core: remove voter reward per committee properly
(*Simple).Seek cuts search prefix, thus to remove voterRewardPerCommittee
we need to append it again to the height value. May affect dumps.
2022-04-28 17:15:18 +03:00
Roman Khimov
10acdbe40e
Merge pull request #2453 from nspcc-dev/check-policy-for-committee-members
Check policy for committee members
2022-04-28 12:58:07 +03:00
Roman Khimov
a8607e43b1 native: check candidates againt Policy blocked list
Follow neo-project/neo#2695 and neo-project/neo#2707.
2022-04-27 22:58:52 +03:00
Anna Shaleva
35d930951c core: consider Rules witness scope as valid 2022-04-27 12:48:33 +03:00
Anna Shaleva
1890e7cdc1 core: upgrade storage version 2022-04-22 18:38:05 +03:00
Anna Shaleva
8be6823cb1 core: fix broken stateroot storage
Store stateroot by DataMPTAux prefix instead of storing it by index only.
2022-04-22 18:37:56 +03:00
Anna Shaleva
d942940a82 core: support System.Runtime.GetAddressVersion syscall 2022-04-21 19:26:16 +03:00
Anna Shaleva
51a54fa248 core: return default BaseExecFee if blockchain height is 0
For (bc *Blockchain).GetBaseExecFee().
2022-04-08 14:28:30 +03:00
Anna Shaleva
d3672eb14a core: use BaseExecFee from InteropContext instead of Blockchain's one
The InteropContext's one contains all relevant fee changes applied in
the prevouse transactions of the current block.
2022-04-08 12:56:46 +03:00
Anna Shaleva
544f2c2cb2 core: use proper storage price within the whole interop context
We shouldn't use StoragePrice from Blockchain because its dao doesn't
contain the whole set of changes from previouse transactions in the
current block. Instead, we should use an updated storage price for
each transaction and retrieve the price from cached DAO.
2022-04-08 12:50:56 +03:00
Anna Shaleva
91a4bc5beb core: use proper DAO to get ExecFeeFactor
The usage of the Blockchain's one leads to the same ExecFeeFactor within
a single block. What we need is to update ExecFeeFactor after each
transaction invocation, thus, cached DAO should be used as it contains
all relevant changes.
2022-04-08 12:50:50 +03:00
Anna Shaleva
16f952270c core: add murmur32 to CryptoLib native contract
Close #2415.
2022-04-05 10:46:52 +03:00
Anna Shaleva
b431e47d2a core: add GetTransactionVMState to native Ledger contract
Close #2343.
2022-04-05 10:37:02 +03:00
Anna Shaleva
4254407a9b dao: add GetTxExecResult method 2022-04-05 10:36:50 +03:00
Anna Shaleva
18c5f638b9 dao: adjust usages of Internal DB inconsistency error 2022-04-04 19:16:58 +03:00
Anna Shaleva
6343720adf dao: return ErrKeyNotFound from GetAppExecResults for dummy txs
Otherwise decoding error may be returned which can be misleading.
2022-04-04 12:49:52 +03:00
Anna Shaleva
9a41356a3b core: add getUint256FromItem helper to native ledger 2022-04-04 12:33:29 +03:00
Roman Khimov
4e375fd8f4
Merge pull request #2414 from nspcc-dev/eliminate-getstorageitems
Eliminate GetStorageItems
2022-04-01 09:16:42 +03:00
Roman Khimov
c12a3b71d4 dao: drop GetStorageItems* APIs
They're just adding another useless caching layer to the Seek.
2022-03-31 19:18:51 +03:00
Roman Khimov
60375e9db3 core: drop GetStorageItems interface
It's not used and not useful.
2022-03-31 16:46:41 +03:00
Roman Khimov
3ab2ab5cba core: drop outdated comment from storageFind 2022-03-31 16:39:11 +03:00
Anna Shaleva
8965441288 core: rebase core tests onto neotest 2022-03-30 19:00:53 +03:00
Anna Shaleva
35ef58a47e core: move Oracle response script creation to a separate function 2022-03-30 18:59:43 +03:00
Anna Shaleva
a4dab3a5ba core: adjust error message of native call 2022-03-30 12:18:01 +03:00
Anna Shaleva
59f3fa1ef1 neotest: adapt framework to work with *testing.B 2022-03-30 12:17:55 +03:00
Anna Shaleva
ff13af804d core: adjust persist-related Blockchain tests
`newTestChain` runs blockchain, so persist is likely already happened
before the first test iteration. Explicit call to persist makes no sence
here.
2022-03-30 11:46:44 +03:00
Anna Shaleva
28e936eb95 core: export GetMaxNotValidBeforeDelta blockchain API
Mostly for tests, but it can also be useful as a separate API.
2022-03-30 11:46:44 +03:00
Anna Shaleva
e0ab4ec6f0 core: adjust helper test contract
Method is allowed to have single return value on stack after its invocation.
Make sure that test contract follows this rule.
2022-03-30 11:46:44 +03:00
Anna Shaleva
13252bb941 core: refactor helper test contracts generation
* Move generator to a separate package.
* Move loader to a separate package and get rid of the code duplications.
2022-03-30 11:46:29 +03:00
Anna Shaleva
889a7ec378 rpc: regenerate basic chain and adjust RPC server tests 2022-03-30 11:32:30 +03:00
Anna Shaleva
4a74c117ee *: refactor TestCreateBasicChain and its dependencies
Close #2355
2022-03-30 11:32:26 +03:00
Anna Shaleva
150041d25e core: unexport native Management's GetMinimumDeploymentFee
This method is used only from Management contract. We also have
neotest-based tests for `getMinimumDeploymentFee`, it should be enough.
2022-03-29 15:01:10 +03:00
Roman Khimov
d5a9af5860 Revert "Revert "interop: use All flags for management deploy and update calls""
This reverts commit 526c423a61, heading to 3.2.0.
2022-03-21 17:41:37 +03:00
Roman Khimov
526c423a61 Revert "interop: use All flags for management deploy and update calls"
This reverts commit 37ca96c20b and a part of
7945097543, we need 0.98.2 release to be
3.1.0-compatible and this one breaks the testnet.
2022-03-21 14:32:11 +03:00
Roman Khimov
906d99571b
Merge pull request #2369 from nspcc-dev/goshechka
*: go 1.18 support 🎉😍🎊🍰🥂
2022-03-18 15:07:20 +03:00
Roman Khimov
5616585697 block/dao: simplify trimming, avoid allocations
The only user of (*Block).Trim() is in DAO and it already has a nice buffer
usually, so creating another one makes no sense. It also simplifies error
handling a lot.
2022-03-18 10:49:25 +03:00
Anna Shaleva
2096ad6e81 *: remove io/ioutil uses
Close #1764.
2022-03-17 19:39:18 +03:00
Roman Khimov
6ece74a7c7
Merge pull request #2383 from nspcc-dev/oracle-redirection
services: check Oracle response redirections
2022-03-04 22:19:22 +03:00
AnnaShaleva
537de18ac3 services: check Oracle response redirections
1. Move redirections check to the tcp level. Manually resolve request address
and create connection for the first suitable resolved address.
2. Remove URIValidator. Redirections checks are set in the custom http client,
so the user should take care of validation by himself when customizing the
client.
2022-03-04 13:10:22 +03:00
Roman Khimov
ff60571869
Merge pull request #2378 from nspcc-dev/notary-adjustments
*: several Notary subsystem adjustments, part 1
2022-03-02 11:58:36 +03:00
AnnaShaleva
92282c70cb *: support customisable NotaryServiceFeePerKey value
* Add corresponding methods to Notary contract.
* Extend RPC Client API.
* Adjust tests.
2022-03-01 19:08:16 +03:00
Anna Shaleva
49c995ec06 core: add tests for blockchain initialisation
Close #1577.
2022-02-28 19:00:43 +03:00
AnnaShaleva
8e3f2417f4 core: add check for native activations history
It should be consistent with storage states.
2022-02-28 18:49:18 +03:00
Anna Shaleva
032d9749c2 core: improve blockchain error messages 2022-02-28 18:49:18 +03:00
Anna Shaleva
a57c3f4842 core: fix InitWithIncompleteStateJump test 2022-02-28 18:49:18 +03:00
Anna Shaleva
9adcefc2ef core: gracefully wrap Seek error if failed to retrieve header hases 2022-02-28 18:49:18 +03:00
Anna Shaleva
8d6aa1782d core: fix StateRootInHeader error message for (*Blockchain).init() 2022-02-28 18:49:18 +03:00
Anna Shaleva
ad0c53c067 core: unify the format of error messages for (*Blockchain).init() 2022-02-28 18:49:12 +03:00
Anna Shaleva
21515e1835 core: refactor Level store creation for tests
We don't need to create the whole DB configuration structure.
2022-02-25 12:14:17 +03:00
Anna Shaleva
339bec1632 core: adjust TestDumpAndRestore test
`with state root` test should consider StateRootInHeader set to true.
2022-02-25 11:47:13 +03:00
Roman Khimov
7d6f087337 storage: drop (KeyPrefix).Bytes() API
It allocates and most of the time we can avoid that.
2022-02-18 15:19:57 +03:00
Roman Khimov
7223caf369 dao: improve PutCurrentHeader logic
Move serialization out of the core.
2022-02-18 15:05:25 +03:00
Roman Khimov
522229d731 storage: drop AppendPrefix/AppendPrefixInt APIs
We're not using them anymore and they allocate.
2022-02-18 14:59:59 +03:00
Roman Khimov
d2db58d748 dao: move header hash store logic out of the core
Which allows for more efficient buffer use along the way.
2022-02-18 14:54:05 +03:00
Roman Khimov
de2579ec07 dao: put contract IDs into keys using big endianness
We don't have a need to iterate over them at the moment, but since we're
changing the DB format in the next release anyway let's add this ability also,
just in case.
2022-02-18 14:38:51 +03:00
Roman Khimov
600da6909c storage: put uint32 into keys using in big endianness
Which allows to iterate over the contents easily.
2022-02-18 14:35:17 +03:00
Roman Khimov
1ca918e631 dao: delay buffer creation until it's needed
Verification contexts don't ever touch the storage, so these allocations can
be avoided for them.
2022-02-18 14:24:45 +03:00
Roman Khimov
e864768c88 dao: simplify NewPrivate 2022-02-18 14:18:56 +03:00
Roman Khimov
5402e654d1 core: don't create useless DAO layer in GetTestVM
We're already wrapping in interop.NewContext.
2022-02-18 14:12:44 +03:00
Roman Khimov
b60d4ff191 dao: deduplicate header->KV conversion 2022-02-18 14:12:44 +03:00
Roman Khimov
d8cf879499 dao: deduplicate DeleteBlock, no functional changes 2022-02-18 14:12:44 +03:00
Roman Khimov
f80680187e storage: expose private storage map for more efficient MPT batch
It couldn't be done previously with two maps and mixed storage, but now all of
the storage changes are located in a single map, so it's trivial to do exact
slice allocations and avoid string->[]byte conversions.
2022-02-17 23:41:10 +03:00
Roman Khimov
7dc8fc443f dao: simplify buffer management for private DAO
Private DAO is only used in a single thread which means we can safely reuse
key/data buffers most of the time and handle it all in DAO.

Doesn't affect any benchmarks.
2022-02-17 22:27:39 +03:00
Roman Khimov
9bfb3357f2 storage: add "private" mode to MemCachedStore
Most of the time we don't need locking on the higher-level stores and we drop
them after Persist, so that's what private MemCachedStore is for.

It doesn't improve things in any noticeable way, some ~1% can be observed in
neo-bench under various loads and even less than that in chain processing. But
it seems to be a bit better anyway (less allocations, less locks).
2022-02-17 22:27:39 +03:00
Roman Khimov
aefb26255a dao: drop DAO interface
It's a remnant from the days when we had Simple and Cached DAO
implementations, now it makes zero sense.
2022-02-16 18:24:20 +03:00
Roman Khimov
9d2ef775cf storage: simplify (*MemCachedStore).Put/Delete interface
They never return errors, so their interface should reflect that. This allows
to remove quite a lot of useless and never tested code.

Notice that Get still does return an error. It can be made not to do that, but
usually we need to differentiate between successful/unsuccessful accesses
anyway, so this doesn't help much.
2022-02-16 18:24:20 +03:00
Roman Khimov
be24bf6412 storage: drop Put and Delete from Store interface
It's only changed with PutChangeSet, single KV operations are handled by
MemCachedStore.
2022-02-16 18:24:20 +03:00
Roman Khimov
017795c9c1 storage: completely remove MemoryBatch
If you need something like that, just wrap another MemCachedStore layer around
it.
2022-02-16 16:13:12 +03:00
Roman Khimov
17a43b19e0 storage: remove Batch from Store
We never use it for real underlying stores, so these implementations are
useless (everything goes though PutChangeSet now).
2022-02-16 15:55:48 +03:00
Roman Khimov
35bdfc5eca storage: use two maps for MemoryStore
Simple and dumb as it is, this allows to separate contract storage from other
things and dramatically improve Seek() time over storage (even though it's
still unordered!) which in turn improves block processing speed.

        LevelDB             LevelDB (KeepOnlyLatest)  BoltDB              BoltDB (KeepOnlyLatest)
Master  real    16m27,936s  real    10m9,440s         real    16m39,369s  real    8m1,227s
        user    20m12,619s  user    26m13,925s        user    18m9,162s   user    18m5,846s
        sys     2m56,377s   sys     1m32,051s         sys     9m52,576s   sys     2m9,455s

2 maps  real    10m49,495s  real    8m53,342s         real    11m46,204s  real    5m56,043s
        user    14m19,922s  user    24m6,225s         user    13m25,691s  user    15m4,694s
        sys     1m53,021s   sys     1m23,006s         sys     4m31,735s   sys     2m8,714s

neo-bench performance is mostly unaffected, ~0.5% for 1-1 test and 4% for
10K-10K test both fall within regular test error range.
2022-02-16 15:55:48 +03:00
Roman Khimov
b6a4947cfd storage: drop STAccount prefix
It's unused for a long time.
2022-02-16 13:06:57 +03:00
Roman Khimov
54bc603831 core: remove old storage items synchronously during jump
There won't be a lot of them and GC experience we have shows that iterating
over 1-2M of entries is not a huge problem for DBs we have.
2022-02-16 13:03:13 +03:00
Roman Khimov
805d81e441 core: drop old transfer data during state jump 2022-02-16 12:12:03 +03:00
Roman Khimov
3a2b800e5f core: remove stale transfer entries, fix #2096
Initially I thought of doing it in the next persist cycle, but testing shows
that it needs just ~2-5% of the time MPT GC does, so doing it in the same
cycle doesn't affect anything.
2022-02-15 15:51:03 +03:00
Roman Khimov
c4b49a2d52 storage: deduplicate storage closing in tests 2022-02-14 17:29:21 +03:00
Roman Khimov
261552516b stateroot: use a better word for logs 2022-02-14 17:29:21 +03:00
Roman Khimov
ccdda21718 stateroot: add and use DataMPTAux for auxiliary data
Use DataMPT for nodes only, otherwise with 1M blocks with have 1M
height-stateroot mapping entries that our GC has to iterate over for no
reason.
2022-02-14 17:29:21 +03:00
Roman Khimov
ad606101c7 storage: add SeekGC interface for GC
It's very special, single-purpose thing, but it improves cumulative time spent
in GC by ~10% for LevelDB and by ~36% for BoltDB during 1050K mainnet chain
processing. While the overall chain import time doesn't change in any
noticeable way (~1%), I think it's still worth it, for machines with slower
disks the difference might be more noticeable.
2022-02-14 17:29:21 +03:00
Roman Khimov
51b804ab0e storage: generalize Level/Bolt seek implementations
Too much in common. Just refactoring. no functional changes.
2022-02-12 23:09:37 +03:00
Roman Khimov
a5f8b8870a storage: use Update for changeset processing
Batch is only relevant in multithreaded context, internally it'll do some
magic and use the same locking/updating Update does, so it makes little sense
for us. This doesn't change benchmarks in any noticeable way.
2022-02-11 16:48:35 +03:00
Roman Khimov
6380647770
Merge pull request #2354 from nspcc-dev/mpt-value-based-gc
Value-based MPT GC
2022-02-11 16:25:08 +03:00
Roman Khimov
c5f1e2fbcd mpt: don't allocate for every key
Microoptimization.
2022-02-11 14:19:54 +03:00
Roman Khimov
423c7883b8 core: implement basic GC for value-based storage scheme
The key idea here is that even though we can't ensure MPT code won't make the
node active again we can order the changes made to the persistent store in
such a way that it practically doesn't matter. What happens is:
 * after persist if it's time to collect our garbage we do it synchronously
   right in the same thread working the underlying persistent store directly
 * all the other node code doesn't see much of it, it works with bc.dao or
   layers above it
 * if MPT doesn't find some stale deactivated node in the storage it's OK,
   it'll recreate it in bc.dao
 * if MPT finds it and activates it, it's OK too, bc.dao will store it
 * while GC is being performed nothing else changes the persistent store
 * all subsequent bc.dao persists only happen after the GC is completed which
   means that any changes to the (potentially) deleted nodes have a priority,
   it's OK for GC to delete something that'll be recreated with the next
   persist cycle

Otherwise it's a simple scheme with node status/last active height stored in
the value. Preliminary tests show that it works ~18% worse than the simple
KeepOnlyLatest scheme, but this seems to be the best result so far.

Fixes #2095.
2022-02-11 14:19:54 +03:00
Roman Khimov
c4ee310e85 mpt: modify refcounted storage scheme to make GC possible
Add "active" flag into the node data and make the remainder modal, for active
nodes it's a reference counter, for inactive ones the deactivation height is
stored.

Technically, refcounted chains storing just one trie don't need a flag, but
it's a bit simpler this way.
2022-02-10 21:56:20 +03:00