-
-
Notifications
You must be signed in to change notification settings - Fork 437
Cache and retransmit bls changes if submitted early #5031
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
Changes from all commits
a39a1dd
b438d81
97fb72f
6f65957
5cc993c
6e3bf0a
dd6d8f7
31b59b9
bc695e3
3c674ff
adb54fd
06e3bb3
1ea60b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,11 +104,20 @@ export function getBeaconPoolApi({ | |
| try { | ||
| await validateBlsToExecutionChange(chain, blsToExecutionChange); | ||
| chain.opPool.insertBlsToExecutionChange(blsToExecutionChange); | ||
| await network.gossip.publishBlsToExecutionChange(blsToExecutionChange); | ||
| if ( | ||
| chain.clock.currentEpoch >= chain.config.CAPELLA_FORK_EPOCH && | ||
| // TODO: Remove below condition | ||
| // Only used for testing in devnet-3 of withdrawals | ||
| network.isSubscribedToGossipCoreTopics() | ||
| ) { | ||
| await network.gossip.publishBlsToExecutionChange(blsToExecutionChange); | ||
| } else { | ||
| await chain.cacheBlsToExecutionChanges(blsToExecutionChange); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it necessary to explicitly call this? |
||
| } | ||
| } catch (e) { | ||
| errors.push(e as Error); | ||
| logger.error( | ||
| `Error on submitPoolSyncCommitteeSignatures [${i}]`, | ||
| `Error on submitPoolBlsToExecutionChange [${i}]`, | ||
| {validatorIndex: blsToExecutionChange.message.validatorIndex}, | ||
| e as Error | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import {routes} from "@lodestar/api"; | |
| import {IMetrics} from "../metrics/index.js"; | ||
| import {ChainEvent, IBeaconChain, IBeaconClock} from "../chain/index.js"; | ||
| import {BlockInput, BlockInputType, getBlockInput} from "../chain/blocks/types.js"; | ||
| import {isValidBlsToExecutionChangeForBlockInclusion} from "../chain/opPools/utils.js"; | ||
| import {INetworkOptions} from "./options.js"; | ||
| import {INetwork, Libp2p} from "./interface.js"; | ||
| import {ReqRespBeaconNode, ReqRespHandlers, doBeaconBlocksMaybeBlobsByRange} from "./reqresp/index.js"; | ||
|
|
@@ -32,6 +33,9 @@ import {PeersData} from "./peers/peersData.js"; | |
| import {getConnectionsMap, isPublishToZeroPeersError} from "./util.js"; | ||
| import {Discv5Worker} from "./discv5/index.js"; | ||
|
|
||
| // How many changes to batch cleanup | ||
| const CACHED_BLS_BATCH_CLEANUP_LIMIT = 10; | ||
|
|
||
| interface INetworkModules { | ||
| config: IBeaconConfig; | ||
| libp2p: Libp2p; | ||
|
|
@@ -63,6 +67,7 @@ export class Network implements INetwork { | |
| private readonly signal: AbortSignal; | ||
|
|
||
| private subscribedForks = new Set<ForkName>(); | ||
| private cachedBlsChangesPromise: Promise<void> | null = null; | ||
|
|
||
| constructor(private readonly opts: INetworkOptions, modules: INetworkModules) { | ||
| const {config, libp2p, logger, metrics, chain, reqRespHandlers, gossipHandlers, signal} = modules; | ||
|
|
@@ -411,6 +416,17 @@ export class Network implements INetwork { | |
| } | ||
| } | ||
| } | ||
|
|
||
| // If we are subscribed and post capella fork epoch, try gossiping the cached bls changes | ||
| if ( | ||
| this.isSubscribedToGossipCoreTopics() && | ||
| epoch >= this.config.CAPELLA_FORK_EPOCH && | ||
| !this.cachedBlsChangesPromise | ||
| ) { | ||
| this.cachedBlsChangesPromise = this.gossipCachedBlsChanges().then(() => { | ||
| this.cachedBlsChangesPromise = null; | ||
| }); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just move this code above under the |
||
| } catch (e) { | ||
| this.logger.error("Error on BeaconGossipHandler.onEpoch", {epoch}, e as Error); | ||
| } | ||
|
|
@@ -482,6 +498,48 @@ export class Network implements INetwork { | |
| return topics; | ||
| } | ||
|
|
||
| private async gossipCachedBlsChanges(): Promise<void> { | ||
| let gossipedKeys: number[] = []; | ||
| let includedKeys: number[] = []; | ||
| let totalProcessed = 0; | ||
| this.logger.info("Re-gossiping the cached bls changes"); | ||
|
|
||
| try { | ||
| const headState = this.chain.getHeadState(); | ||
| for await (const value of this.chain.db.blsToExecutionChangeCache.valuesStream()) { | ||
| if (isValidBlsToExecutionChangeForBlockInclusion(headState, value)) { | ||
| await this.gossip.publishBlsToExecutionChange(value); | ||
| gossipedKeys.push(value.message.validatorIndex); | ||
| } else { | ||
| // No need to gossip if its already been in the headState | ||
| // TODO: Should use final state? | ||
| includedKeys.push(value.message.validatorIndex); | ||
| } | ||
| totalProcessed += 1; | ||
|
|
||
| // Cleanup in small batches | ||
| if (totalProcessed % CACHED_BLS_BATCH_CLEANUP_LIMIT === 0) { | ||
| await this.chain.db.blsToExecutionChangeCache.batchDelete(gossipedKeys); | ||
| await this.chain.db.blsToExecutionChangeCache.batchDelete(includedKeys); | ||
| includedKeys = []; | ||
| gossipedKeys = []; | ||
| } | ||
| } | ||
| } catch (e) { | ||
| this.logger.error("Failed to gossip all cached bls changes", {totalProcessed}, e as Error); | ||
| } finally { | ||
| this.logger.info("Gossiped cached blsChanges", { | ||
| gossipedIndexes: `${gossipedKeys}`, | ||
| alreadyIncludedIndexes: `${includedKeys}`, | ||
| totalProcessed, | ||
| }); | ||
| // Cleanup whatever was in the last batch | ||
| await this.chain.db.blsToExecutionChangeCache.batchDelete(gossipedKeys); | ||
| await this.chain.db.blsToExecutionChangeCache.batchDelete(includedKeys); | ||
| } | ||
| this.logger.info("Processed cached blsChanges", {totalProcessed}); | ||
| } | ||
|
|
||
| private onLightClientFinalityUpdate = async (finalityUpdate: altair.LightClientFinalityUpdate): Promise<void> => { | ||
| if (this.hasAttachedSyncCommitteeMember()) { | ||
| try { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.