Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/etherspot/skandha into fi…
Browse files Browse the repository at this point in the history
…x-tracer-avalanche
  • Loading branch information
0xSulpiride committed Mar 22, 2024
2 parents e3077b6 + 2feabf7 commit 52170f3
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 39 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ Licensed under the [MIT License](https://github.com/etherspot/skandha/blob/maste
- Mumbai | QmQfRyE9iVTBqZ17hPSP4tuMzaez83Y5wD874ymyRtj9VE | https://ipfs.io/ipfs/QmQfRyE9iVTBqZ17hPSP4tuMzaez83Y5wD874ymyRtj9VE?filename=mumbai_canonical_mempool.yaml
- Goerli | QmTmj4cizhWpEFCCqk5dP67yws7R2PPgCtb2bd2RgVPCbF | https://ipfs.io/ipfs/QmTmj4cizhWpEFCCqk5dP67yws7R2PPgCtb2bd2RgVPCbF?filename=goerli_canonical_mempool.yaml

> [!WARNING]
> This version of the bundler is not compatible with the latest p2p-spec. If you're looking to run a P2P-bundler, switch to this branch - https://github.com/etherspot/skandha/tree/version1-p2p
## 🔢 Statistics
![Alt](https://repobeats.axiom.co/api/embed/4d7ec3ece88b2461c5b1757574321f4f6540cdd5.svg "Skandha analytics image")

Expand Down
6 changes: 0 additions & 6 deletions packages/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,6 @@ export class ApiApp {
case BundlerRPCMethods.web3_clientVersion:
result = web3Api.clientVersion();
break;
case CustomRPCMethods.skandha_validateUserOperation:
result = await skandhaApi.validateUserOp({
userOp: params[0],
entryPoint: params[1],
});
break;
case CustomRPCMethods.skandha_getGasPrice:
result = await skandhaApi.getGasPrice();
break;
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const CustomRPCMethods = {
skandha_validateUserOperation: "skandha_validateUserOperation",
skandha_getGasPrice: "skandha_getGasPrice",
skandha_config: "skandha_config",
skandha_feeHistory: "skandha_feeHistory",
Expand Down
13 changes: 0 additions & 13 deletions packages/api/src/modules/skandha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,11 @@ import { Skandha } from "executor/lib/modules";
import RpcError from "types/lib/api/errors/rpc-error";
import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes";
import { RpcMethodValidator } from "../utils/RpcMethodValidator";
import { SendUserOperationGasArgs } from "../dto/SendUserOperation.dto";
import { FeeHistoryArgs } from "../dto/FeeHistory.dto";

export class SkandhaAPI {
constructor(private ethModule: Eth, private skandhaModule: Skandha) {}

/**
* Validates UserOp. If the UserOp (sender + entryPoint + nonce) match the existing UserOp in mempool,
* validates if new UserOp can replace the old one (gas fees must be higher by at least 10%)
* @param userOp same as eth_sendUserOperation
* @param entryPoint Entry Point
* @returns
*/
@RpcMethodValidator(SendUserOperationGasArgs)
async validateUserOp(args: SendUserOperationGasArgs): Promise<boolean> {
return await this.ethModule.validateUserOp(args);
}

/**
* @param entryPoint Entry Point
* @param useropCount Number of blocks in the requested range
Expand Down
1 change: 1 addition & 0 deletions packages/executor/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class Executor {
this.provider,
this.logger,
this.reputationService,
this.mempoolService,
this.networkConfig.entryPoints,
this.db
);
Expand Down
28 changes: 13 additions & 15 deletions packages/executor/src/services/BundlingService/relayers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,26 @@ export abstract class BaseRelayer implements IRelayingMode {
}

/**
* waits for transaction
* @param hash transaction hash
* @returns false if transaction reverted
* waits entries to get submitted
* @param hashes user op hashes array
*/
protected async waitForTransaction(hash: string): Promise<boolean> {
if (!utils.isHexString(hash)) return false;
protected async waitForEntries(entries: MempoolEntry[]): Promise<void> {
let retries = 0;
if (entries.length == 0) return;
return new Promise((resolve, reject) => {
const interval = setInterval(async () => {
if (retries >= WAIT_FOR_TX_MAX_RETRIES) reject(false);
retries++;
const response = await this.provider.getTransaction(hash);
if (response != null) {
clearInterval(interval);
try {
await response.wait(0);
resolve(true);
} catch (err) {
reject(err);
}
for (const entry of entries) {
const exists = await this.mempoolService.find(entry);
// if some entry exists in the mempool, it means that the EventService did not delete it yet
// because that service has not received UserOperationEvent yet
// so we wait for it to get submitted...
if (exists) return;
}
}, 1000);
clearInterval(interval);
resolve();
}, this.networkConfig.bundleInterval);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ export class ClassicRelayer extends BaseRelayer {
txHash
);

await this.waitForTransaction(txHash).catch((err) =>
await this.waitForEntries(entries).catch((err) =>
this.logger.error(err, "Relayer: Could not find transaction")
);
await this.mempoolService.removeAll(entries);
this.reportSubmittedUserops(txHash, bundle);
})
.catch(async (err: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class FlashbotsRelayer extends BaseRelayer {
MempoolEntryStatus.Submitted,
txHash
);
await this.waitForTransaction(txHash).catch((err) =>
await this.waitForEntries(entries).catch((err) =>
this.logger.error(err, "Flashbots: Could not find transaction")
);
await this.mempoolService.removeAll(entries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class KolibriRelayer extends BaseRelayer {
MempoolEntryStatus.Submitted,
hash
);
await this.waitForTransaction(hash).catch((err) =>
await this.waitForEntries(entries).catch((err) =>
this.logger.error(err, "Kolibri: Could not find transaction")
);
await this.mempoolService.removeAll(entries);
Expand Down
9 changes: 9 additions & 0 deletions packages/executor/src/services/EventsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "types/lib/executor/contracts/EntryPoint";
import { TypedEvent } from "types/lib/executor/contracts/common";
import { ReputationService } from "./ReputationService";
import { MempoolService } from "./MempoolService";

export class EventsService {
private entryPoints: IEntryPoint[] = [];
Expand All @@ -22,6 +23,7 @@ export class EventsService {
private provider: providers.JsonRpcProvider,
private logger: Logger,
private reputationService: ReputationService,
private mempoolService: MempoolService,
private entryPointAddrs: string[],
private db: IDbController
) {
Expand Down Expand Up @@ -116,6 +118,13 @@ export class EventsService {
}

async handleUserOperationEvent(ev: UserOperationEventEvent): Promise<void> {
const entry = await this.mempoolService.getEntryByHash(ev.args.userOpHash);
if (entry) {
this.logger.debug(
`Found UserOperationEvent for ${ev.args.userOpHash}. Deleting userop...`
);
await this.mempoolService.remove(entry);
}
await this.includedAddress(ev.args.sender);
await this.includedAddress(ev.args.paymaster);
await this.includedAddress(this.getEventAggregator(ev));
Expand Down

0 comments on commit 52170f3

Please sign in to comment.