-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(p2p): no tips store in the p2p client #12395
base: master
Are you sure you want to change the base?
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
63c9281
to
bc0c510
Compare
9e603da
to
3190e47
Compare
2d6e4e9
to
e64590b
Compare
6008722
to
adfec1f
Compare
adfec1f
to
a75a866
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Tiny comment around the epochs to avoid a potential race condition.
@@ -150,31 +150,18 @@ export class SlasherClient extends WithTracer { | |||
return EthAddress.fromString(payloadAddress); | |||
} | |||
|
|||
public handleBlockStreamEvent(event: L2BlockSourceEvent): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -409,14 +409,15 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable { | |||
); | |||
} | |||
|
|||
const [localProvenEpochNumber, localProvenBlockNumber] = await Promise.all([ | |||
this.store.getProvenL2EpochNumber(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in #12380 might be better if these depends on each other, and not be pulled as there could be a race condition. e.g., given the block number we should be able to get the slot number and then the epoch number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
epoch can be inferred from block, gotcha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
epoch number is entirely not required, here, opening pr to remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question on synching really, otherwise the code looks good and lot simpler than before!
With these changes do we really don't have to ask the P2P client if it's synched up the latest block? 🤔
/** | ||
* Allows consumers to stop the instance of the slasher client. | ||
* 'ready' will now return 'false' and the running promise that keeps the client synced is interrupted. | ||
*/ | ||
public stop() { | ||
this.log.debug('Stopping Slasher client...'); | ||
this.l2BlockSource.removeListener(L2BlockSourceEvents.L2PruneDetected, this.handlePruneL2Blocks.bind(this)); | ||
this.l2BlockSource.removeListener(L2BlockSourceEvents.ChainPruned, this.handlePruneL2Blocks.bind(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realise this isn't new code (in this PR) but this bind
will create a new function instance and won't remove the original.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good spot
it('deletes txs once block is proven', async () => { | ||
blockSource.setProvenBlockNumber(0); | ||
await client.start(); | ||
expect(txPool.deleteTxs).not.toHaveBeenCalled(); | ||
|
||
await advanceToProvenBlock(5); | ||
advanceToProvenBlock(5); | ||
await sleep(100); // wait for the event to be emitted and handled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is needed because advanceToProvenBlock
is no longer async? Slightly worried this might flake in the future, but probably fine for now 😁
// Store references to the wrapper functions for later removal | ||
this.eventHandlers = { | ||
handleChainPruned, | ||
handleBlocksAdded, | ||
handleChainProven, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one!
private async startServiceIfSynched() { | ||
if ( | ||
this.currentState === P2PClientState.SYNCHING && | ||
(await this.getSyncedLatestBlockNum()) >= this.latestBlockNumberAtStart && | ||
(await this.getSyncedProvenBlockNum()) >= this.provenBlockNumberAtStart | ||
) { | ||
this.log.debug(`Synched to blocks at start`); | ||
this.setCurrentState(P2PClientState.RUNNING); | ||
if (this.syncResolve !== undefined) { | ||
this.syncResolve(); | ||
await this.p2pService.start(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not needed anymore? My understanding was that this function would block the node from 'starting' until all of its components had synched.
Is there a risk that after a restart a node would have components at different heights because they synched at different speeds from the archiver?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're completely correct, myself and lasse have just discussed this. I'm currently bringing this logic back!
this.l1ToL2MessageSource.getBlockNumber(), | ||
] as const); | ||
|
||
const [worldState, l2BlockSource, p2p, l1ToL2MessageSource] = syncedBlocks; | ||
const [worldState, l2BlockSource, l1ToL2MessageSource] = syncedBlocks; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should still ask the P2P node if it's synched up the latest block otherwise the sequencer could start building a block before the P2P client had a chance to react to the BlocksAdded
event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happened in the ci 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly what happened in the failing prover test!
ba1798f
to
1c82e22
Compare
Overview
Migrates the p2p client to use the archiver's event emitter that was created in the pr above in this stack.
This removes usage of the L2BlockStream from the p2p client for dealing with state changes, and instead uses events to deal with these situations