neoneo-go/pkg/core/native
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
..
native_test native: rework native NEO next block validators cache 2023-10-10 13:18:05 +03:00
nativenames [#2442] English Check 2022-05-04 19:48:27 +03:00
nativeprices core: move NotaryVerificationPrice to a separate package 2021-03-23 13:56:39 +03:00
noderoles core: adjust value of P2PNotary node role 2022-06-01 15:03:29 +03:00
compatibility_test.go config: add InitialGASSupply, fix #2073 2021-07-20 16:59:54 +03:00
contract.go core: adjust Notary contract ID 2022-06-01 15:03:29 +03:00
contract_test.go core: move TestNativeGetMethod to the native package 2022-06-08 18:51:27 +03:00
crypto.go native: ensure proper endianness is used for CryptoLib's field element multiplier 2023-10-05 13:46:05 +03:00
crypto_blspoints.go native: fix error message on unexpected BLS12-381 curve point 2023-10-05 13:46:05 +03:00
crypto_test.go core: add BLS12_381 interops 2023-04-05 15:37:50 +03:00
designate.go core: add InitializeCache method to Contract interface 2023-04-26 12:57:48 +03:00
doc.go *: add more package-specific documentation 2021-03-19 16:18:45 +03:00
interop.go native: simplify code somewhat, get Metadata() only once 2022-12-16 23:48:04 +03:00
invocation_test.go native: add old management deploy/update call flags to Aspidochelone 2022-12-16 23:45:47 +03:00
ledger.go core: add InitializeCache method to Contract interface 2023-04-26 12:57:48 +03:00
management.go core: move strict script check on deploy under HF condition 2023-08-09 18:32:30 +03:00
management_neotest_test.go core: rename TestManagement_DeployUpdateHardfork 2023-08-18 12:02:43 +03:00
management_test.go dao: simplify NewSimple() 2023-09-04 16:56:59 +03:00
native_gas.go core: add InitializeCache method to Contract interface 2023-04-26 12:57:48 +03:00
native_neo.go native: rework native NEO next block validators cache 2023-10-10 13:18:05 +03:00
native_neo_candidate.go [#2442] English Check 2022-05-04 19:48:27 +03:00
native_neo_test.go stackitem: introduce Convertible interface 2021-07-19 15:42:42 +03:00
native_nep17.go bigint: don't allocate in ToPreallocatedBytes 2022-06-02 15:38:39 +03:00
nativenames_test.go [#2442] English Check 2022-05-04 19:48:27 +03:00
neo_types.go stackitem: reusable serialization context 2022-06-02 15:38:39 +03:00
notary.go core: add InitializeCache method to Contract interface 2023-04-26 12:57:48 +03:00
oracle.go core: add InitializeCache method to Contract interface 2023-04-26 12:57:48 +03:00
oracle_types.go [#2442] English Check 2022-05-04 19:48:27 +03:00
oracle_types_test.go *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
policy.go core: add InitializeCache method to Contract interface 2023-04-26 12:57:48 +03:00
policy_test.go core: move Policy contract tests to native 2022-06-08 22:44:25 +03:00
std.go vm: move JNumbers parsing precision under HFBasilisk 2023-08-10 13:14:16 +03:00
std_test.go *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
util.go bigint: don't allocate in ToPreallocatedBytes 2022-06-02 15:38:39 +03:00