Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Maddiaa0
Copy link
Member

@Maddiaa0 Maddiaa0 commented Mar 1, 2025

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

Copy link
Member Author

Maddiaa0 commented Mar 1, 2025

@Maddiaa0 Maddiaa0 force-pushed the md/fix-slasher-client branch from 63c9281 to bc0c510 Compare March 1, 2025 17:26
@Maddiaa0 Maddiaa0 force-pushed the md/remove-p2p-state branch from 9e603da to 3190e47 Compare March 1, 2025 17:26
@Maddiaa0 Maddiaa0 changed the title feat(p2p): no store in the p2p client feat(p2p): no tips store in the p2p client Mar 3, 2025
@Maddiaa0 Maddiaa0 force-pushed the md/fix-slasher-client branch from 2d6e4e9 to e64590b Compare March 3, 2025 15:32
@Maddiaa0 Maddiaa0 requested a review from charlielye as a code owner March 3, 2025 15:32
@Maddiaa0 Maddiaa0 force-pushed the md/remove-p2p-state branch from 6008722 to adfec1f Compare March 3, 2025 15:32
Base automatically changed from md/fix-slasher-client to master March 3, 2025 16:03
@Maddiaa0 Maddiaa0 force-pushed the md/remove-p2p-state branch from adfec1f to a75a866 Compare March 3, 2025 16:27
@Maddiaa0 Maddiaa0 requested review from alexghr and LHerskind March 3, 2025 16:29
Copy link
Contributor

@LHerskind LHerskind left a 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> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Noice Thats Nice GIF

@@ -409,14 +409,15 @@ export class Archiver extends EventEmitter implements ArchiveSource, Traceable {
);
}

const [localProvenEpochNumber, localProvenBlockNumber] = await Promise.all([
this.store.getProvenL2EpochNumber(),
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@alexghr alexghr left a 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));
Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Contributor

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 😁

Comment on lines +241 to +319
// Store references to the wrapper functions for later removal
this.eventHandlers = {
handleChainPruned,
handleBlocksAdded,
handleChainProven,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice one!

Comment on lines -730 to -742
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();
}
}
Copy link
Contributor

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?

Copy link
Member Author

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;
Copy link
Contributor

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.

Copy link
Contributor

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 👍

Copy link
Member Author

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!

@Maddiaa0 Maddiaa0 force-pushed the md/remove-p2p-state branch from ba1798f to 1c82e22 Compare March 3, 2025 20:00
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.

3 participants