lighthouse/beacon_node
Michael Sproul 01556f6f01 Optimise payload attributes calculation and add SSE (#4027)
## Issue Addressed

Closes #3896
Closes #3998
Closes #3700

## Proposed Changes

- Optimise the calculation of withdrawals for payload attributes by avoiding state clones, avoiding unnecessary state advances and reading from the snapshot cache if possible.
- Use the execution layer's payload attributes cache to avoid re-calculating payload attributes. I actually implemented a new LRU cache just for withdrawals but it had the exact same key and most of the same data as the existing payload attributes cache, so I deleted it.
- Add a new SSE event that fires when payloadAttributes are calculated. This is useful for block builders, a la https://github.com/ethereum/beacon-APIs/issues/244.
- Add a new CLI flag `--always-prepare-payload` which forces payload attributes to be sent with every fcU regardless of connected proposers. This is intended for use by builders/relays.

For maximum effect, the flags I've been using to run Lighthouse in "payload builder mode" are:

```
--always-prepare-payload \
--prepare-payload-lookahead 12000 \
--suggested-fee-recipient 0x0000000000000000000000000000000000000000
```

The fee recipient is required so Lighthouse has something to pack in the payload attributes (it can be ignored by the builder). The lookahead causes fcU to be sent at the start of every slot rather than at 8s. As usual, fcU will also be sent after each change of head block. I think this combination is sufficient for builders to build on all viable heads. Often there will be two fcU (and two payload attributes) sent for the same slot: one sent at the start of the slot with the head from `n - 1` as the parent, and one sent after the block arrives with `n` as the parent.

Example usage of the new event stream:

```bash
curl -N "http://localhost:5052/eth/v1/events?topics=payload_attributes"
```

## Additional Info

- [x] Tests added by updating the proposer re-org tests. This has the benefit of testing the proposer re-org code paths with withdrawals too, confirming that the new changes don't interact poorly.
- [ ] Benchmarking with `blockdreamer` on devnet-7 showed promising results but I'm yet to do a comparison to `unstable`.


Co-authored-by: Michael Sproul <micsproul@gmail.com>
2023-03-05 23:43:30 +00:00
..
beacon_chain Optimise payload attributes calculation and add SSE (#4027) 2023-03-05 23:43:30 +00:00
builder_client Merge remote-tracking branch 'origin/unstable' into capella 2023-01-12 16:22:00 +11:00
client Allow compilation with no slasher backend (#3888) 2023-02-28 02:20:49 +00:00
eth1 exchangeCapabilities & Capella Readiness Logging (#3918) 2023-01-31 18:26:23 +01:00
execution_layer Optimise payload attributes calculation and add SSE (#4027) 2023-03-05 23:43:30 +00:00
genesis Fix the new BLS to execution change test 2023-01-25 15:47:07 +11:00
http_api Optimise payload attributes calculation and add SSE (#4027) 2023-03-05 23:43:30 +00:00
http_metrics Add content-type header to metrics server response (#3970) 2023-02-28 02:20:50 +00:00
lighthouse_network Cleaner logic for gossip subscriptions for new forks (#4030) 2023-03-01 09:22:48 +00:00
network Cleaner logic for gossip subscriptions for new forks (#4030) 2023-03-01 09:22:48 +00:00
operation_pool Fix Capella schema downgrades (#4004) 2023-02-20 17:50:42 +11:00
src Optimise payload attributes calculation and add SSE (#4027) 2023-03-05 23:43:30 +00:00
store Clean capella (#4019) 2023-03-01 03:19:02 +00:00
tests Altair consensus changes and refactors (#2279) 2021-07-09 06:15:32 +00:00
timer Use async code when interacting with EL (#3244) 2022-07-03 05:36:50 +00:00
Cargo.toml Allow compilation with no slasher backend (#3888) 2023-02-28 02:20:49 +00:00