The medalla #eth2 testnet hasn't been finalizing for a while which puts some additional stress on clients as the number of possible valid chain histories, or branches, grows - here's what goes on in an @ethnimbus client in this case:
* We use more memory - normally we hover around 500mb but memory consumption now goes up to 1-2gb: In each possible history, votes and validator assignments might be different - we keep a compressed in-memory cache of the most crucial information
The caches are used to process attestations - the network becomes unhealthy if attestation processing is slow or if we have to drop some because we don't have time to recreate the committee to validate them - for this we need access to the shuffling of active validators
Another source of memory usage is the number of branches itself - depending on when the client was started, it will have seen more of less of these - each potential branch takes up some space, and we currently keep all of them around
To manage the branch memory usage, we are implementing pruning of unviable branches - if at some point a branch was created but nobody is building on it, it's unlikely to become the canonical history and we can limit memory waste by dropping it on a probabilistic basis
* We use more disk space - per the protocol, we must be prepared for clients voting for any of the branches and this number keeps growing - to avoid keeping everything in memory, we store them on disk
Storing non-finalized states on disk allows us to recreate any state in constant time, regardless of how long the non-finality is ongoing, and thus decreasing the negative performance impact on the network as a whole
The disk space will eventually be reclaimed as we prune the database, but for that to happen, the chain needs to finalize - after finalization, any alternate history becomes invalid and we can drop it
A few finalized state snapshots are kept for RPC requests - we might have to replay more blocks to recreate a particular finalized state but this will never be needed for the eth2 network and protocol itself, thus we prefer to save on disk space
* Sync becomes slower: when we connect to other peers, they are more likely to not be following the same head - this in turn makes it harder to know that we are synced, so we will spend more time exploring the different histories in the network
Sometimes, we might also have to resync parts, in case the peers we're connected to disagree on which history is valid - in benign cases they might be slow or have poor connectivity with parts of the network - in malicious cases, they might be trying to eclipse us
All in all, the long period of non-finality has served to tune and optimize the client to better handle this unlikely, but potentially disabling scenario - the improvements not only make the client more efficient in normal scenarios but also increase the security buffer ..
.. we have against future attacks on the network as a whole!
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Curious what goes on inside an #eth2 client? Let's take a look at some colourful boxes loosely depicting the @ethnimbus implementation..
#eth2 uses #libp2p to establish a peer-to-peer network - each node opens encrypted connections to other nodes using chronos and nim-libp2p, purpose-built networking libraries in @nim_lang, and multiplex several protocols like gossip and eth2/sync over that link using `mplex`
On top of #libp2p, we build the #eth2 network core - protocol details, serialization, peer scoring, discv5 to feed it with fresh peers etc - we get a little playful here with @nim_lang, using some of its niche features to good performance and readability advantage
So what does an #eth2 beacon node actually do, in practice? Well, here's a tweet storm to find out. We'll follow the logs of a node backwards, just like following a block chain that effectively is a singly linked list going back in time. Reverse engineering, like :)
The beacon node establishes the current head of the list effectively by voting, or attesting, as it's called here. Time progresses in slots, and for every slot, we broadcast and collect votes. Several nodes are voting for block B9F2ED1F, us included.
Apart from the head block, rewards will be handed out for getting a few other pieces of data right - including nailing justification as per Casper: ethresear.ch/t/beacon-chain…. 10 validators connected to this node, but only 3 are voting this round - it's split by shard.