Coin Brief ENDE

Geth lets readers of old blocks run in parallel again after a pentest found an exclusive lock

The go-ethereum team merged three small changes early on 16 November, two of them found during a penetration test by the security firm turingpoint.

The main one is pull request 36139. chainFreezer.ReadAncients, the wrapper through which geth reads old chain data from its freezer, took the exclusive write lock. As a result, every read of ancient data that went through it ran one at a time across the whole node. The accessors affected include ReadCanonicalHash, ReadHeaderRLP, ReadBodyRLP and ReadReceiptsRLP, which serve RPC queries for old blocks, headers and receipts, the eth protocol handlers that answer peers, and internal lookups. A burst of RPC or peer requests for frozen blocks therefore made every other reader wait, including internal ones.

The lock exists to keep writers out while a function performs several reads. The underlying Freezer.ReadAncients already does that with the shared read lock, and the writers take the exclusive side; the chain freezer wrapper, added in an earlier change, took the exclusive lock as well, which the author says is not needed for consistency. The fix swaps Lock for RLock. In the author's test, 50 goroutines each holding the call for 20 ms took 1,013 ms in total before the change and 21 ms after. The author notes that the effect on a synced mainnet node was not measured.

Pull request 36138, from the same test, fixes an upgrade problem. A config.toml written by geth dumpconfig from versions 1.17.3 to 1.17.10 contains BinTrieGroupDepth = 5; after that field was removed, the current code refused to start with such a file. The field is now on the list of deprecated fields, so geth logs a warning and ignores it.

A third change, 36146, moves clearTxpool from the admin console module to debug, matching the debug_clearTxpool RPC it calls. Anyone using admin.clearTxpool() in the console has to switch to debug.clearTxpool().

Geth lets readers of old blocks run in parallel again after a pentest found an exclusive lock
Geth lets readers of old blocks run in parallel again after a pentest found an exclusive lock — Coin Brief

Why it matters

Nodes that serve historical data to RPC users or peers were serializing those reads behind one lock. The config fix matters to anyone who keeps a dumped configuration file, because without it the next upgrade would have left the node unable to start until the line was deleted by hand.

Primary source
go-ethereum pull requests
https://github.com/ethereum/go-ethereum/pull/36139
Written by Victoria Shinder.