Skip to content

feat(p2p): no tips store in the p2p client#12395

Closed
Maddiaa0 wants to merge 9 commits intomasterfrom
md/remove-p2p-state
Closed

feat(p2p): no tips store in the p2p client#12395
Maddiaa0 wants to merge 9 commits intomasterfrom
md/remove-p2p-state

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 LHerskind and alexghr 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.

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

}

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? 🤔

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


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 😁

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

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!

] 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
@Maddiaa0 Maddiaa0 removed the request for review from charlielye March 13, 2025 19:00
@Maddiaa0
Copy link
Member Author

stale

@Maddiaa0 Maddiaa0 closed this Jun 23, 2025
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