Merge bitcoin/bitcoin#26395: rpc: add missing lock around chainman.ActiveTip()

f5ff3d773c rpc: add missing lock around chainman.ActiveTip() (Andrew Toth)

Pull request description:

  https://github.com/bitcoin/bitcoin/pull/23927 seems to have missed a lock around `chainman.ActiveChain()`.

ACKs for top commit:
  aureleoules:
    ACK f5ff3d773c

Tree-SHA512: 3f116ca44c1b2bc0c7042698249ea3417dfb7c0bb81158a7ceecd087f1e02baa89948f9bb7924b1757798a1691a7de6e886aa72a0a9e227c13a3f512cc59d6c9
This commit is contained in:
MacroFake 2022-10-26 18:05:27 +02:00
commit ec92d23fb8
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -461,7 +461,7 @@ static RPCHelpMan getblockfrompeer()
// Fetching blocks before the node has syncing past their height can prevent block files from
// being pruned, so we avoid it if the node is in prune mode.
if (index->nHeight > chainman.ActiveChain().Tip()->nHeight && node::fPruneMode) {
if (node::fPruneMode && index->nHeight > WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip()->nHeight)) {
throw JSONRPCError(RPC_MISC_ERROR, "In prune mode, only blocks that the node has already synced previously can be fetched from a peer");
}