neoneo-go/pkg
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
..
compiler Merge pull request #3149 from nspcc-dev/fix-compiler-version-race 2023-10-10 12:23:08 +03:00
config rpcsrv: set MaxNEP11Tokens to default if not specified 2023-08-29 13:26:10 +03:00
consensus native: rework native NEO next block validators cache 2023-10-10 13:18:05 +03:00
core native: rework native NEO next block validators cache 2023-10-10 13:18:05 +03:00
crypto *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
encoding *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
interop interop: support ABORTMSG, ASSERT, ASSERTMSG opcodes 2023-08-10 12:41:30 +03:00
io *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
neorpc rpcsrv: add getrawnotarypool, getrawnotarytransaction handlers 2023-08-31 18:51:43 +01:00
neotest neotest: improve doc based on #3120 2023-09-05 15:20:00 +03:00
network *: move NVB and Conflicts attributes out of extensions 2023-09-04 16:39:44 +03:00
rpcclient unwrap: add Nothing function 2023-09-03 16:54:50 +01:00
services rpcsrv: use stricter GAS limit for calculatenetworkfee 2023-09-27 19:33:06 +03:00
smartcontract zkpbinding: fix example link 2023-10-05 15:16:11 +03:00
util *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
vm vm: add address&swap endianness to opcode dump for hashes 2023-09-04 08:41:22 +01:00
wallet Merge pull request #2725 from nspcc-dev/move-cli-tests 2022-10-06 13:43:39 +07:00