neoneo-go/pkg/consensus
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
..
testdata wallet: fix wallet version to conform to NEP-6 2022-08-07 22:41:40 +03:00
block.go [#2442] English Check 2022-05-04 19:48:27 +03:00
block_test.go block: drop Network from the Header 2021-03-26 13:45:18 +03:00
cache.go [#2442] English Check 2022-05-04 19:48:27 +03:00
cache_test.go consensus: refactor payloads structure 2021-01-22 10:38:32 +03:00
change_view.go [#2442] English Check 2022-05-04 19:48:27 +03:00
change_view_test.go consensus: replace magic 1000000 with something more meaningful 2020-07-11 19:54:50 +03:00
commit.go [#2442] English Check 2022-05-04 19:48:27 +03:00
commit_test.go pkg: move internal/ package to the root directory 2020-11-24 16:39:56 +03:00
consensus.go native: rework native NEO next block validators cache 2023-10-10 13:18:05 +03:00
consensus_test.go *: use require.ErrorIs instead of require.True(t, error.Is()) 2023-05-04 17:03:47 +03:00
crypto.go consensus: update dbft, drop marshaling from private key 2022-09-02 14:44:18 +03:00
crypto_test.go consensus: update dbft, drop marshaling from private key 2022-09-02 14:44:18 +03:00
doc.go *: add more package-specific documentation 2021-03-19 16:18:45 +03:00
payload.go *: replace interface{} with any keyword 2023-04-04 13:22:42 +03:00
payload_test.go *: use uint*Size and SignatureLen constants where appropriate 2022-10-05 10:45:52 +03:00
prepare_request.go consensus: don't use WriteArray for PrepareRequests 2022-06-02 15:38:39 +03:00
prepare_request_test.go consensus: remove nonce from PrepareRequest 2021-03-18 21:32:43 +03:00
prepare_response.go [#2442] English Check 2022-05-04 19:48:27 +03:00
prepare_response_test.go *: move all packages from CityOfZion to nspcc-dev 2020-03-03 17:21:42 +03:00
recovery_message.go network/consensus: always process dBFT messages as high priority 2022-08-02 13:07:18 +03:00
recovery_message_test.go *: remove dead code 2021-05-12 18:13:14 +03:00
recovery_request.go [#2442] English Check 2022-05-04 19:48:27 +03:00
recovery_request_test.go consensus: replace magic 1000000 with something more meaningful 2020-07-11 19:54:50 +03:00