Skip to content

Commit

Permalink
Perf improvement for multiple relayers (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride authored Jan 25, 2024
1 parent 0d46c35 commit a8b3f1f
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 83 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"stream": "true",
"command": {
"version": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "root",
"private": true,
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"engines": {
"node": ">=18.0.0"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"description": "The API module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -35,13 +35,13 @@
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"ethers": "5.7.2",
"executor": "^1.0.31-alpha",
"executor": "^1.0.32-alpha",
"fastify": "4.14.1",
"monitoring": "^1.0.31-alpha",
"monitoring": "^1.0.32-alpha",
"pino": "8.11.0",
"pino-pretty": "10.0.0",
"reflect-metadata": "0.1.13",
"types": "^1.0.31-alpha"
"types": "^1.0.32-alpha"
},
"devDependencies": {
"@types/connect": "3.4.35"
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cli",
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"description": "> TODO: description",
"author": "zincoshine <[email protected]>",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -38,15 +38,15 @@
"@libp2p/peer-id-factory": "2.0.1",
"@libp2p/prometheus-metrics": "1.1.3",
"@multiformats/multiaddr": "12.1.3",
"api": "^1.0.31-alpha",
"db": "^1.0.31-alpha",
"executor": "^1.0.31-alpha",
"api": "^1.0.32-alpha",
"db": "^1.0.32-alpha",
"executor": "^1.0.32-alpha",
"find-up": "5.0.0",
"got": "12.5.3",
"js-yaml": "4.1.0",
"monitoring": "^1.0.31-alpha",
"node": "^1.0.31-alpha",
"types": "^1.0.31-alpha",
"monitoring": "^1.0.32-alpha",
"node": "^1.0.32-alpha",
"types": "^1.0.32-alpha",
"yargs": "17.6.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/db/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "db",
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"description": "The DB module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/etherspot-bundler#readme",
Expand Down Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"@chainsafe/ssz": "0.10.1",
"@farcaster/rocksdb": "5.5.0",
"types": "^1.0.31-alpha"
"types": "^1.0.32-alpha"
},
"devDependencies": {
"@types/rocksdb": "3.0.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/executor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "executor",
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"description": "The Relayer module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -34,8 +34,8 @@
"@flashbots/ethers-provider-bundle": "0.6.2",
"async-mutex": "0.4.0",
"ethers": "5.7.2",
"monitoring": "^1.0.31-alpha",
"params": "^1.0.31-alpha",
"types": "^1.0.31-alpha"
"monitoring": "^1.0.32-alpha",
"params": "^1.0.32-alpha",
"types": "^1.0.32-alpha"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export type Relayer = Wallet | providers.JsonRpcSigner;
export interface IRelayingMode {
isLocked(): boolean;
sendBundle(bundle: Bundle): Promise<void>;
getAvailableRelayersCount(): number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export abstract class BaseRelayer implements IRelayingMode {
throw new Error("Method not implemented.");
}

getAvailableRelayersCount(): number {
return this.mutexes.filter((mutex) => !mutex.isLocked()).length;
}

/**
* waits for transaction
* @param hash transaction hash
Expand Down
94 changes: 46 additions & 48 deletions packages/executor/src/services/BundlingService/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,57 +326,55 @@ export class BundlingService {

async sendNextBundle(): Promise<void> {
await this.mutex.runExclusive(async () => {
let entries = await this.mempoolService.getNewEntriesSorted(
this.maxBundleSize
);
if (!entries.length) return;
if (this.relayer.isLocked()) {
this.logger.debug("Have userops, but all relayers are busy.");
return;
}

// remove entries from mempool if submitAttempts are greater than maxAttemps
const invalidEntries = entries.filter(
(entry) => entry.submitAttempts >= this.maxSubmitAttempts
);
if (invalidEntries.length > 0) {
this.logger.debug(
`Found ${invalidEntries.length} problematic user ops, deleting...`
);
await this.mempoolService.removeAll(invalidEntries);
entries = await this.mempoolService.getNewEntriesSorted(
let relayersCount = this.relayer.getAvailableRelayersCount();
while (relayersCount-- > 0) {
let entries = await this.mempoolService.getNewEntriesSorted(
this.maxBundleSize
);
}
if (!entries.length) return;
const gasFee = await getGasFee(
this.chainId,
this.provider,
this.networkConfig.etherscanApiKey
);
if (
gasFee.gasPrice == undefined &&
gasFee.maxFeePerGas == undefined &&
gasFee.maxPriorityFeePerGas == undefined
) {
this.logger.debug("Could not fetch gas prices...");
return;
}
const bundle = await this.createBundle(gasFee, entries);
if (!bundle.entries.length) return;
await this.mempoolService.setStatus(
bundle.entries,
MempoolEntryStatus.Pending
);
await this.mempoolService.attemptToBundle(bundle.entries);
void this.relayer.sendBundle(bundle).catch((err) => {
this.logger.error(err);
});
this.logger.debug("Sent new bundle to Skandha relayer...");
if (!entries.length) return;
// remove entries from mempool if submitAttempts are greater than maxAttemps
const invalidEntries = entries.filter(
(entry) => entry.submitAttempts >= this.maxSubmitAttempts
);
if (invalidEntries.length > 0) {
this.logger.debug(
`Found ${invalidEntries.length} problematic user ops, deleting...`
);
await this.mempoolService.removeAll(invalidEntries);
entries = await this.mempoolService.getNewEntriesSorted(
this.maxBundleSize
);
}
if (!entries.length) return;
const gasFee = await getGasFee(
this.chainId,
this.provider,
this.networkConfig.etherscanApiKey
);
if (
gasFee.gasPrice == undefined &&
gasFee.maxFeePerGas == undefined &&
gasFee.maxPriorityFeePerGas == undefined
) {
this.logger.debug("Could not fetch gas prices...");
return;
}
const bundle = await this.createBundle(gasFee, entries);
if (!bundle.entries.length) return;
await this.mempoolService.setStatus(
bundle.entries,
MempoolEntryStatus.Pending
);
await this.mempoolService.attemptToBundle(bundle.entries);
void this.relayer.sendBundle(bundle).catch((err) => {
this.logger.error(err);
});
this.logger.debug("Sent new bundle to Skandha relayer...");

// during testing against spec-tests we need to wait the block to be submitted
if (this.config.testingMode) {
await wait(500);
// during testing against spec-tests we need to wait the block to be submitted
if (this.config.testingMode) {
await wait(500);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export class SafeValidationService {
let gasPrice: GetGasPriceResponse | null = null;
if (this.networkConfig.gasFeeInSimulation) {
gasPrice = await this.skandhaUtils.getGasPrice();
gasPrice.maxFeePerGas = BigNumber.from(gasPrice.maxFeePerGas)._hex;
gasPrice.maxPriorityFeePerGas = BigNumber.from(
gasPrice.maxPriorityFeePerGas
)._hex;
}
const entryPointContract = IEntryPoint__factory.connect(
entryPoint,
Expand Down
4 changes: 2 additions & 2 deletions packages/monitoring/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monitoring",
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"description": "The Monitoring module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/etherspot-bundler#readme",
Expand Down Expand Up @@ -32,6 +32,6 @@
},
"dependencies": {
"prom-client": "^14.2.0",
"types": "^1.0.31-alpha"
"types": "^1.0.32-alpha"
}
}
16 changes: 8 additions & 8 deletions packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node",
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"description": "The bundler node module of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -56,25 +56,25 @@
"@libp2p/tcp": "6.1.0",
"@multiformats/multiaddr": "11.4.0",
"abstract-leveldown": "7.2.0",
"api": "^1.0.31-alpha",
"api": "^1.0.32-alpha",
"datastore-core": "8.0.1",
"db": "^1.0.31-alpha",
"db": "^1.0.32-alpha",
"ethers": "5.7.2",
"executor": "^1.0.31-alpha",
"executor": "^1.0.32-alpha",
"it-filter": "1.0.2",
"it-map": "1.0.5",
"it-sort": "1.0.0",
"it-take": "1.0.1",
"libp2p": "0.42.2",
"monitoring": "^1.0.31-alpha",
"params": "^1.0.31-alpha",
"monitoring": "^1.0.32-alpha",
"params": "^1.0.32-alpha",
"prettier": "2.8.4",
"snappy": "7.2.2",
"snappyjs": "0.7.0",
"stream-to-it": "0.2.4",
"strict-event-emitter-types": "2.0.0",
"types": "^1.0.31-alpha",
"utils": "^1.0.31-alpha",
"types": "^1.0.32-alpha",
"utils": "^1.0.32-alpha",
"varint": "6.0.0",
"xxhash-wasm": "1.0.2"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/params/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "params",
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"description": "Various bundler parameters",
"author": "Etherspot",
"homepage": "https://github.com/etherspot/skandha#readme",
Expand All @@ -26,8 +26,8 @@
"@eth-optimism/sdk": "3.0.0",
"@mantleio/sdk": "0.2.1",
"ethers": "5.7.2",
"types": "^1.0.31-alpha",
"utils": "^1.0.31-alpha"
"types": "^1.0.32-alpha",
"utils": "^1.0.32-alpha"
},
"scripts": {
"clean": "rm -rf lib && rm -f *.tsbuildinfo",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "types",
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"description": "The types of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "utils",
"version": "1.0.31-alpha",
"version": "1.0.32-alpha",
"description": "utils of Etherspot bundler client",
"author": "Etherspot",
"homepage": "https://https://github.com/etherspot/skandha#readme",
Expand Down Expand Up @@ -37,6 +37,6 @@
"case": "^1.6.3",
"pino": "8.11.0",
"pino-pretty": "10.0.0",
"types": "^1.0.31-alpha"
"types": "^1.0.32-alpha"
}
}

0 comments on commit a8b3f1f

Please sign in to comment.