Skip to content

Handle wrong fork/finalization on hello - #598

Merged
wemeetagain merged 5 commits into
masterfrom
tuyen/handle-status-message
Jan 9, 2020
Merged

Handle wrong fork/finalization on hello#598
wemeetagain merged 5 commits into
masterfrom
tuyen/handle-status-message

Conversation

@twoeths

@twoeths twoeths commented Dec 27, 2019

Copy link
Copy Markdown
Member

@twoeths twoeths changed the title Handle wrong fork/finalization on hello [WIP] Handle wrong fork/finalization on hello Dec 27, 2019
Comment thread packages/lodestar/src/sync/reqResp/reqResp.ts Outdated
Comment thread packages/lodestar/src/sync/reqResp/reqResp.ts
@twoeths twoeths changed the title [WIP] Handle wrong fork/finalization on hello Handle wrong fork/finalization on hello Jan 3, 2020
@twoeths
twoeths requested a review from mpetrunic January 3, 2020 10:58
Comment thread packages/lodestar/src/sync/reqResp/reqResp.ts Outdated
return true;
}
if (state.finalizedCheckpoint.epoch >= request.finalizedEpoch &&
!request.finalizedRoot.equals(getBlockRoot(this.config, state, request.finalizedEpoch))) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I'm not mistaken getBlockRoot only contains root for recent slots. I think it's safer to fetch block from database by request.finalizedEpoch start slot.

You should try to avoid fetching entire state here as that call isn't cheap, especially considering that this method will be called on each peer connect.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced getBlockRoot by getting block root from database as you said.

Regarding the state, I still need it for other calculations.

}
// TODO handle incorrect forkVersion or disjoint finalizedCheckpoint
if (await this.shouldDisconnectOnHello(peerInfo, request)) {
this.network.reqResp.goodbye(peerInfo, 0n);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per spec it should be 2n

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I correct the one in stop() too

@twoeths
twoeths requested a review from mpetrunic January 4, 2020 03:51
this.network.reqResp.removeListener("request", this.onRequest);
await Promise.all(
this.network.getPeers().map((peerInfo) =>
this.network.reqResp.goodbye(peerInfo, 0n)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract reason codes to enum

return true;
}
const startSlot = computeStartSlotOfEpoch(this.config, request.finalizedEpoch);
const startBlock = await this.db.block.get(startSlot);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that block is finalized it will be in this.db.blockArchive

@twoeths
twoeths force-pushed the tuyen/handle-status-message branch from 073121b to 6270e00 Compare January 8, 2020 01:47

@wemeetagain wemeetagain left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@wemeetagain
wemeetagain merged commit b497f5b into master Jan 9, 2020
@wemeetagain
wemeetagain deleted the tuyen/handle-status-message branch January 9, 2020 15:20
nflaig pushed a commit that referenced this pull request Jun 9, 2026
- Wires the new `fast_confirmation` Server-Sent Event from beacon-APIs
PR [#598](ethereum/beacon-APIs#598). The event
fires once per slot whenever the Fast Confirmation Rule executes and
carries `{block, slot}`, where `slot` is the slot of the confirmed
beacon block.
- Crosses the fork-choice ↔ beacon-node boundary via a new optional
`onFastConfirmation` callback on `ForkChoiceStore`, mirroring the
existing `onJustified` / `onFinalized` plumbing. The emit is invoked
from `ForkChoice.runFastConfirmation()` after the rule succeeds.
- Removes the now-redundant Lodestar-namespace endpoint `GET
/eth/v1/lodestar/fast_confirmation_info` (and its `getConfirmedBlock`
helper) — the standard SSE event supersedes it, and the head/checkpoint
fields it bundled are already available via standard beacon-API
endpoints.

This PR is aligned with the changes proposed in
ethereum/beacon-APIs#616

### Architecture

```
Chain.onClockSlot → forkChoice.updateTime
  └── (per tick) runFastConfirmation
       └── fcStore.notifyFastConfirmation({block, slot})
            └── ChainEventEmitter.emit(EventType.fastConfirmation, {block, slot})
                 └── SSE subscribers via /eth/v1/events?topics=fast_confirmation
```

`ApiEvents` in `ChainEventEmitter` is derived from
`routes.events.EventType`, so adding the new variant flows through
automatically — no per-event boilerplate in the chain or events API
layers.


### Edge cases

| Scenario | Behavior |
|---|---|
| `--chain.fastConfirmation` disabled (default) | No emit (FCR doesn't
run) |
| FCR rule throws | No emit; existing warn-and-continue catch is
unchanged |
| Confirmed root not in `protoArray` (defensive) | Warn log with
`slot`+`confirmedRoot`, skip emit |
| `updateTime` advances multiple slots | One emit per tick |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle wrong fork/finalization on hello

3 participants