Skip to content

Commit

Permalink
delete hardcoded mempools & configurable mempool id (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride authored Feb 16, 2024
1 parent 9ad43e5 commit b398b9f
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 91 deletions.
11 changes: 4 additions & 7 deletions packages/executor/src/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
estimateArbitrumPVG,
ECDSA_DUMMY_SIGNATURE,
estimateMantlePVG,
getCanonicalMempool,
serializeMempoolId
} from "params/lib";
import { Logger } from "types/lib";
import { PerChainMetrics } from "monitoring/lib";
Expand Down Expand Up @@ -107,17 +107,14 @@ export class Eth {
try {
const nodeApi = this.getNodeAPI();
if (nodeApi) {
const { mempoolId } = getCanonicalMempool(this.chainId, {
entryPoint: this.config.canonicalEntryPoint,
mempoolId: this.config.canonicalMempoolId,
});
if (mempoolId.length > 0) {
const { canonicalEntryPoint, canonicalMempoolId } = this.config;
if (canonicalEntryPoint.toLowerCase() == entryPoint.toLowerCase() && canonicalMempoolId.length > 0) {
const blockNumber = await this.provider.getBlockNumber(); // TODO: fetch blockNumber from simulateValidation
await nodeApi.publishVerifiedUserOperationJSON(
entryPoint,
userOp,
blockNumber.toString(),
mempoolId
serializeMempoolId(canonicalMempoolId)
);
this.metrics?.useropsSent?.inc();
}
Expand Down
2 changes: 2 additions & 0 deletions packages/executor/src/modules/skandha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export class Skandha {
bundleSize: this.networkConfig.bundleSize,
minUnstakeDelay: this.networkConfig.minUnstakeDelay,
pvgMarkup: this.networkConfig.pvgMarkup,
canonicalMempoolId: this.networkConfig.canonicalMempoolId,
canonicalEntryPoint: this.networkConfig.canonicalEntryPoint
};
}

Expand Down
17 changes: 5 additions & 12 deletions packages/node/src/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { PeerId } from "@libp2p/interface-peer-id";
import { ssz, ts } from "types/lib";
import { SignableENR } from "@chainsafe/discv5";
import logger, { Logger } from "api/lib/logger";
import { getCanonicalMempool } from "params/lib";
import { deserializeMempoolId } from "params/lib";
import { deserializeMempoolId, serializeMempoolId } from "params/lib";
import { Config } from "executor/lib/config";
import { AllChainsMetrics } from "monitoring/lib";
import { Executor } from "executor/lib/executor";
Expand Down Expand Up @@ -114,12 +113,9 @@ export class Network implements INetwork {

const chainId = relayersConfig.chainId;
const defaultMetadata = ssz.Metadata.defaultValue();
const canonicalMempool = getCanonicalMempool(
chainId,
relayersConfig.getCanonicalMempool()
);
const canonicalMempool = relayersConfig.getCanonicalMempool()
if (canonicalMempool.mempoolId) {
defaultMetadata.supported_mempools.push(canonicalMempool.mempoolId);
defaultMetadata.supported_mempools.push(serializeMempoolId(canonicalMempool.mempoolId));
}
const metadata = new MetadataController({
chainId,
Expand Down Expand Up @@ -200,12 +196,9 @@ export class Network implements INetwork {

const enr = await this.getEnr();

const canonicalMempool = getCanonicalMempool(
this.relayersConfig.chainId,
this.relayersConfig.getCanonicalMempool()
);
const canonicalMempool = this.relayersConfig.getCanonicalMempool()
if (canonicalMempool.mempoolId) {
const mempoolId = deserializeMempoolId(canonicalMempool.mempoolId);
const mempoolId = deserializeMempoolId(serializeMempoolId(canonicalMempool.mempoolId));
this.subscribeGossipCoreTopics(mempoolId);
}

Expand Down
11 changes: 4 additions & 7 deletions packages/node/src/sync/sync.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logger from "api/lib/logger";
import { PeerId } from "@libp2p/interface-peer-id";
import { ts } from "types/lib";
import { deserializeMempoolId, getCanonicalMempool } from "params/lib";
import { deserializeMempoolId } from "params/lib";
import { deserializeUserOp, userOpHashToString } from "params/lib/utils/userOp";
import { AllChainsMetrics } from "monitoring/lib";
import { Executor } from "executor/lib/executor";
Expand Down Expand Up @@ -126,13 +126,10 @@ export class SyncService implements ISyncService {

try {
for (const mempool of peer.metadata.supported_mempools) {
const canonicalMempool = getCanonicalMempool(
this.executor.chainId,
this.executorConfig.getCanonicalMempool()
);
const mempoolStr = deserializeMempoolId(mempool);
const canonicalMempool = this.executorConfig.getCanonicalMempool();
const mempoolStr = deserializeMempoolId(mempool).toLowerCase();
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (deserializeMempoolId(canonicalMempool.mempoolId) != mempoolStr) {
if (canonicalMempool.mempoolId.toLowerCase() != mempoolStr) {
logger.debug(`mempool not supported: ${mempoolStr}`);
continue;
}
Expand Down
1 change: 0 additions & 1 deletion packages/params/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from "./bannedContracts";
export * from "./networks";
export * from "./utils";
export * from "./mempools";
export * from "./eip1559";
export * from "./gas-estimation";
export * from "./constants";
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions packages/params/src/mempools/dev/index.ts

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions packages/params/src/mempools/goerli/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/params/src/mempools/index.ts

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions packages/params/src/mempools/mumbai/index.ts

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions packages/params/src/mempools/sepolia/index.ts

This file was deleted.

28 changes: 0 additions & 28 deletions packages/params/src/utils/mempool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { MempoolId } from "types/lib/sszTypes";
import { utils } from "ethers";
import { networksConfig } from "../networks";
import { mempoolsConfig } from "../mempools";

export function serializeMempoolId(mempoolId: string): Uint8Array {
const hex = utils.hexlify(utils.toUtf8Bytes(mempoolId));
Expand All @@ -12,29 +10,3 @@ export function deserializeMempoolId(byteArray: Uint8Array): string {
const json = MempoolId.toJson(byteArray) as string;
return utils.toUtf8String(json);
}

export function getCanonicalMempool(
chainId: number,
fallback: { entryPoint: string; mempoolId: string }
): {
entryPoint: string;
mempoolId: Uint8Array;
} {
const config = networksConfig[chainId];
if (config) {
if (config.CANONICAL_MEMPOOL && mempoolsConfig[chainId]) {
const mempoolConfig =
mempoolsConfig[chainId]![
deserializeMempoolId(config.CANONICAL_MEMPOOL)
];
return {
entryPoint: mempoolConfig.entrypoint,
mempoolId: config.CANONICAL_MEMPOOL,
};
}
}
return {
entryPoint: fallback.entryPoint,
mempoolId: serializeMempoolId(fallback.mempoolId),
};
}
2 changes: 2 additions & 0 deletions packages/types/src/api/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export type GetConfigResponse = {
bundleSize: number;
minUnstakeDelay: number;
pvgMarkup: number;
canonicalMempoolId: string;
canonicalEntryPoint: string;
};

export type SupportedEntryPoints = string[];
Expand Down

0 comments on commit b398b9f

Please sign in to comment.