neoneo-go/pkg/core/native/native_test
Anna Shaleva 96449d803a native: rework native NEO next block validators cache
Blockchain passes his own pure unwrapped DAO to
(*Blockchain).ComputeNextBlockValidators which means that native
RW NEO cache structure stored inside this DAO can be modified by
anyone who uses exported ComputeNextBlockValidators Blockchain API,
and technically it's valid, and we should allow this, because it's
the only purpose of `validators` caching. However, at the same time
some RPC server is allowed to request a subsequent wrapped DAO for
some test invocation. It means that descendant wrapped DAO
eventually will request RW NEO cache and try to `Copy()`
the underlying's DAO cache which is in direct use of
ComputeNextBlockValidators. Here's the race:
ComputeNextBlockValidators called by Consensus service tries to
update cached `validators` value, and descendant wrapped DAO
created by the  RPC server tries to copy DAO's native cache and
read the cached `validators` value.

So the problem is that native cache not designated to handle
concurrent access between parent DAO layer and derived (wrapped)
DAO layer. I've carefully reviewed all the usages of native cache,
and turns out that the described situation is the only place where
parent DAO is used directly to modify its cache concurrently with
some descendant DAO that is trying to access the cache. All other
usages of native cache (not only NEO, but also all other native
contrcts) strictly rely on the hierarchical DAO structure and don't
try to perform these concurrent operations between DAO layers.
There's also persist operation, but it keeps cache RW lock taken,
so it doesn't have this problem as far. Thus, in this commit we rework
NEO's `validators` cache value so that it always contain the relevant
list for upper Blockchain's DAO and is updated every PostPersist (if
needed).

Note: we must be very careful extending our native cache in the
future, every usage of native cache must be checked against the
described problem.

Close #2989.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-10-10 13:18:05 +03:00
..
helpers/policyhelper nativetest: migrate Policy contract tests to neotest 2022-01-14 16:34:33 +03:00
common_test.go *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
cryptolib_test.go examples: add compatibility example for Groth16 veification 2023-10-05 11:01:25 +03:00
designate_test.go *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
gas_test.go *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
ledger_test.go config: add a special Blockchain type to configure Blockchain 2022-12-07 17:35:53 +03:00
management_test.go Revert "core: remove contract script check on deploy/update" 2023-08-09 18:30:47 +03:00
neo_test.go native: rework native NEO next block validators cache 2023-10-10 13:18:05 +03:00
notary_test.go vm: allow to emit convertible 2023-05-17 12:47:31 +03:00
oracle_test.go *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
policy_test.go core: keep Policy cache always valid and up-to-date 2022-04-29 16:10:04 +03:00