diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 1646aa986ab7..972b26f2dcd8 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -300,7 +300,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable { deps.p2pClientDeps, ); - // We should really not be modifying the config object + // Start world state and wait for it to sync to the archiver. + await worldStateSynchronizer.start(); + + // Start p2p. Note that it depends on world state to be running. + await p2pClient.start(); + config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()); const blockBuilder = new BlockBuilder( @@ -311,35 +316,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable { telemetry, ); - // We'll accumulate sentinel watchers here const watchers: Watcher[] = []; - // Create validator client if required - const validatorClient = createValidatorClient(config, { - p2pClient, - telemetry, - dateProvider, - epochCache, - blockBuilder, - blockSource: archiver, - l1ToL2MessageSource: archiver, - keyStoreManager, - }); - - // If we have a validator client, register it as a source of offenses for the slasher, - // and have it register callbacks on the p2p client *before* we start it, otherwise messages - // like attestations or auths will fail. - if (validatorClient) { - watchers.push(validatorClient); - await validatorClient.registerHandlers(); - } - - // Start world state and wait for it to sync to the archiver. - await worldStateSynchronizer.start(); - - // Start p2p. Note that it depends on world state to be running. - await p2pClient.start(); - const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config); if (validatorsSentinel) { // we can run a sentinel without trying to slash. @@ -371,6 +349,21 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable { watchers.push(attestationsBlockWatcher); } + const validatorClient = createValidatorClient(config, { + p2pClient, + telemetry, + dateProvider, + epochCache, + blockBuilder, + blockSource: archiver, + l1ToL2MessageSource: archiver, + keyStoreManager, + }); + + if (validatorClient) { + watchers.push(validatorClient); + } + log.verbose(`All Aztec Node subsystems synced`); // Validator enabled, create/start relevant service diff --git a/yarn-project/p2p/src/services/peer-manager/peer_manager.ts b/yarn-project/p2p/src/services/peer-manager/peer_manager.ts index 792efa6f4e39..7fa8bb57632e 100644 --- a/yarn-project/p2p/src/services/peer-manager/peer_manager.ts +++ b/yarn-project/p2p/src/services/peer-manager/peer_manager.ts @@ -883,7 +883,7 @@ export class PeerManager implements PeerManagerInterface { const response = await this.reqresp.sendRequestToPeer(peerId, ReqRespSubProtocol.AUTH, authRequest.toBuffer()); const { status } = response; if (status !== ReqRespStatus.SUCCESS) { - this.logger.verbose(`Disconnecting peer ${peerId} who failed to respond auth handshake`, { + this.logger.debug(`Disconnecting peer ${peerId} who failed to respond auth handshake`, { peerId, status: ReqRespStatus[status], }); @@ -899,7 +899,7 @@ export class PeerManager implements PeerManagerInterface { const peerStatusMessage = peerAuthResponse.status; if (!ourStatus.validate(peerStatusMessage)) { - this.logger.verbose(`Disconnecting peer ${peerId} due to failed status handshake as part of auth.`, logData); + this.logger.debug(`Disconnecting peer ${peerId} due to failed status handshake as part of auth.`, logData); this.markAuthHandshakeFailed(peerId); this.markPeerForDisconnect(peerId); return; @@ -911,9 +911,12 @@ export class PeerManager implements PeerManagerInterface { const registeredValidators = await this.epochCache.getRegisteredValidators(); const found = registeredValidators.find(v => v.toString() === sender.toString()) !== undefined; if (!found) { - this.logger.verbose( + this.logger.debug( `Disconnecting peer ${peerId} due to failed auth handshake, peer is not a registered validator.`, - { ...logData, address: sender.toString() }, + { + peerId, + address: sender.toString(), + }, ); this.markAuthHandshakeFailed(peerId); this.markPeerForDisconnect(peerId); @@ -923,9 +926,8 @@ export class PeerManager implements PeerManagerInterface { // Check to see that this validator address isn't already allocated to a different peer const peerForAddress = this.authenticatedValidatorAddressToPeerId.get(sender.toString()); if (peerForAddress !== undefined && peerForAddress.toString() !== peerIdString) { - this.logger.verbose( + this.logger.debug( `Received auth for validator ${sender.toString()} from peer ${peerIdString}, but this validator is already authenticated to peer ${peerForAddress.toString()}`, - { ...logData, address: sender.toString() }, ); return; } @@ -935,13 +937,12 @@ export class PeerManager implements PeerManagerInterface { this.authenticatedValidatorAddressToPeerId.set(sender.toString(), peerId); this.logger.info( `Successfully completed auth handshake with peer ${peerId}, validator address ${sender.toString()}`, - { ...logData, address: sender.toString() }, + logData, ); } catch (err: any) { //TODO: maybe hard ban these peers in the future - this.logger.verbose(`Disconnecting peer ${peerId} due to error during auth handshake: ${err.message}`, { + this.logger.debug(`Disconnecting peer ${peerId} due to error during auth handshake: ${err.message ?? err}`, { peerId, - err, }); this.markAuthHandshakeFailed(peerId); this.markPeerForDisconnect(peerId); diff --git a/yarn-project/stdlib/src/interfaces/validator.ts b/yarn-project/stdlib/src/interfaces/validator.ts index c401114a1c84..900ab756b080 100644 --- a/yarn-project/stdlib/src/interfaces/validator.ts +++ b/yarn-project/stdlib/src/interfaces/validator.ts @@ -54,6 +54,7 @@ export const ValidatorClientConfigSchema = z.object({ export interface Validator { start(): Promise; + registerBlockProposalHandler(): void; updateConfig(config: Partial): void; // Block validation responsibilities diff --git a/yarn-project/validator-client/src/validator.ts b/yarn-project/validator-client/src/validator.ts index 1e663f4def44..5fedc8e0ad32 100644 --- a/yarn-project/validator-client/src/validator.ts +++ b/yarn-project/validator-client/src/validator.ts @@ -62,9 +62,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter) private validationService: ValidationService; private metrics: ValidatorMetrics; - // Whether it has already registered handlers on the p2p client - private hasRegisteredHandlers = false; - // Used to check if we are sending the same proposal twice private previousProposal?: BlockProposal; @@ -215,9 +212,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter) return; } - await this.registerHandlers(); + this.registerBlockProposalHandler(); + // Sync the committee from the smart contract + // https://github.com/AztecProtocol/aztec-packages/issues/7962 const myAddresses = this.getValidatorAddresses(); + const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses); if (inCommittee.length > 0) { this.log.info( @@ -230,6 +230,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter) } this.epochCacheUpdateLoop.start(); + this.p2pClient.registerThisValidatorAddresses(myAddresses); + await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this)); + return Promise.resolve(); } @@ -237,20 +240,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter) await this.epochCacheUpdateLoop.stop(); } - /** Register handlers on the p2p client */ - public async registerHandlers() { - if (!this.hasRegisteredHandlers) { - this.hasRegisteredHandlers = true; - - const handler = (block: BlockProposal, proposalSender: PeerId): Promise => - this.attestToProposal(block, proposalSender); - this.p2pClient.registerBlockProposalHandler(handler); - - const myAddresses = this.getValidatorAddresses(); - this.p2pClient.registerThisValidatorAddresses(myAddresses); - - await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this)); - } + public registerBlockProposalHandler() { + const handler = (block: BlockProposal, proposalSender: PeerId): Promise => + this.attestToProposal(block, proposalSender); + this.p2pClient.registerBlockProposalHandler(handler); } async attestToProposal(proposal: BlockProposal, proposalSender: PeerId): Promise {