cmd/faucet: cache internal state, avoid sync-trashing les #17732
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a much needed fix for the Rinkeby faucet.
The issue with the faucet lately was that the for every client connection, the faucet retrieved it's current stats (head, balance, nonce) from
les
. While syncing however, this meant that remote clients who have the page open hammer the light client with requests, which probably clog up theles
queues and make everything time out (i.e. the sync requests time out, because we have data retrieval requests queued up in front).A similar issue was that for every head request, the faucet retrieved its stats, but during a sync, each header is announced as a new head, again causing a ton of requests forced from the faucet towards
les
.The "fix" introduced in this PR is to cache all internal states that the faucet streams to clients, so instead of requesting on demand, we have a loop that updates periodically and streams the cached value to new websocket connections. The second fix was that the faucet will from now on ignore chain head events that are older than 1 hour, to avoid putting extra strain on
les
during sync.These fixes are not yet perfect, as
les
is still overloaded by the sync + data retrieval during normal operation if the faucet only has 1-2 connections, it however does manage to sync up fast and correctly queue and send transactions. The "ugly"-ness still present is that sometimes it takes a couple minutes until the old transactions are flushed out.There are a few takeaways however related to
les
: