Skip to content

Commit

Permalink
executionclient: add a comment about SubscribeNewHead choice (#1996)
Browse files Browse the repository at this point in the history
* executionclient: add a comment about SubscribeNewHead choice

* update the comment
  • Loading branch information
nkryuchkov authored Jan 26, 2025
1 parent 61ad5b5 commit ff4fa98
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions eth/executionclient/execution_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,21 @@ func (ec *ExecutionClient) isClosed() bool {
func (ec *ExecutionClient) streamLogsToChan(ctx context.Context, logs chan<- BlockLogs, fromBlock uint64) (lastBlock uint64, err error) {
heads := make(chan *ethtypes.Header)

// Generally, execution client can stream logs using SubscribeFilterLogs, but we chose to use SubscribeNewHead + FilterLogs.
//
// We must receive all events as they determine the state of the ssv network, so a discrepancy can result in slashing.
// Therefore, we must be sure that we don't miss any log while streaming.
//
// With SubscribeFilterLogs we cannot specify the block we subscribe from, it always starts at the highest.
// So with streaming we had some bugs because of missing blocks:
// - first sync history from genesis to block 100, but then stream sometimes starts late at 102 (missed 101)
// - inevitably miss blocks during any stream connection interruptions (such as EL restarts)
//
// Thus, we decided not to rely on log streaming and use SubscribeNewHead + FilterLogs.
//
// It also allowed us to implement more 'atomic' behaviour easier:
// We can revert the tx if there was an error in processing all the events of a block.
// So we can restart from this block once everything is good.
sub, err := ec.client.SubscribeNewHead(ctx, heads)
if err != nil {
ec.logger.Error(elResponseErrMsg,
Expand Down

0 comments on commit ff4fa98

Please sign in to comment.