Skip to content

Commit

Permalink
add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed Feb 2, 2024
1 parent 32d6761 commit c1c7808
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
3 changes: 2 additions & 1 deletion packages/executor/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export class Executor {
this.db,
this.chainId,
this.reputationService,
this.networkConfig
this.networkConfig,
this.logger
);
this.bundlingService = new BundlingService(
this.chainId,
Expand Down
16 changes: 13 additions & 3 deletions packages/executor/src/services/BundlingService/relayers/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { MempoolService } from "../../MempoolService";
import { estimateBundleGasLimit } from "../utils";
import { ReputationService } from "../../ReputationService";
import { BaseRelayer } from "./base";
import { wait } from "../../../utils";

export class ClassicRelayer extends BaseRelayer {
constructor(
Expand Down Expand Up @@ -41,12 +40,18 @@ export class ClassicRelayer extends BaseRelayer {

async sendBundle(bundle: Bundle): Promise<void> {
const availableIndex = this.getAvailableRelayerIndex();
if (availableIndex == null) return;
if (availableIndex == null) {
this.logger.error("Relayer: No available relayers");
return;
}
const relayer = this.relayers[availableIndex];
const mutex = this.mutexes[availableIndex];

const { entries, storageMap } = bundle;
if (!bundle.entries.length) return;
if (!bundle.entries.length) {
this.logger.error("Relayer: Bundle is empty");
return;
}

await mutex.runExclusive(async (): Promise<void> => {
const beneficiary = await this.selectBeneficiary(relayer);
Expand Down Expand Up @@ -121,6 +126,11 @@ export class ClassicRelayer extends BaseRelayer {
return;
}

this.logger.debug(
`Trying to submit userops: ${bundle.entries
.map((entry) => entry.userOpHash)
.join(", ")}`
);
await this.submitTransaction(relayer, transaction, storageMap)
.then(async (txHash: string) => {
this.logger.debug(`Bundle submitted: ${txHash}`);
Expand Down
26 changes: 16 additions & 10 deletions packages/executor/src/services/BundlingService/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class BundlingService {
private maxBundleSize: number;
private networkConfig: NetworkConfig;
private relayer: IRelayingMode;
private maxSubmitAttempts = 3;
private maxSubmitAttempts = 10;

constructor(
private chainId: number,
Expand Down Expand Up @@ -166,6 +166,7 @@ export class BundlingService {
if (!entity) continue;
const status = await this.reputationService.getStatus(entity);
if (status === ReputationStatus.BANNED) {
this.logger.debug(`Removing banned ${title} - ${entity}`);
await this.mempoolService.remove(entry);
continue;
} else if (
Expand Down Expand Up @@ -238,6 +239,9 @@ export class BundlingService {
if (
paymasterDeposit[paymaster]?.lt(validationResult.returnInfo.prefund)
) {
this.logger.debug(
`not enough balance in paymaster to pay for all UserOps: ${entry.userOpHash}`
);
// not enough balance in paymaster to pay for all UserOps
// (but it passed validation, so it can sponsor them separately
continue;
Expand Down Expand Up @@ -328,18 +332,16 @@ export class BundlingService {
await this.mutex.runExclusive(async () => {
let relayersCount = this.relayer.getAvailableRelayersCount();
if (relayersCount == 0) {
if (
(await this.mempoolService.getNewEntriesSorted(this.maxBundleSize))
.length > 0
) {
this.logger.debug("All relayers are busy");
}
this.logger.debug("Relayers are busy");
}
while (relayersCount-- > 0) {
let entries = await this.mempoolService.getNewEntriesSorted(
this.maxBundleSize
);
if (!entries.length) return;
if (!entries.length) {
this.logger.debug("No new entries");
return;
};
// remove entries from mempool if submitAttempts are greater than maxAttemps
const invalidEntries = entries.filter(
(entry) => entry.submitAttempts >= this.maxSubmitAttempts
Expand All @@ -353,7 +355,10 @@ export class BundlingService {
this.maxBundleSize
);
}
if (!entries.length) return;
if (!entries.length) {
this.logger.debug("No entries left");
return;
};
const gasFee = await getGasFee(
this.chainId,
this.provider,
Expand All @@ -367,13 +372,14 @@ export class BundlingService {
this.logger.debug("Could not fetch gas prices...");
return;
}
this.logger.debug("Found some entries, trying to create a bundle");
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);
// await this.mempoolService.attemptToBundle(bundle.entries);
void this.relayer.sendBundle(bundle).catch((err) => {
this.logger.error(err);
});
Expand Down
7 changes: 5 additions & 2 deletions packages/executor/src/services/MempoolService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumberish, utils } from "ethers";
import { IDbController } from "types/lib";
import { IDbController, Logger } from "types/lib";
import RpcError from "types/lib/api/errors/rpc-error";
import * as RpcErrorCodes from "types/lib/api/errors/rpc-error-codes";
import { UserOperationStruct } from "types/lib/executor/contracts/EntryPoint";
Expand All @@ -25,7 +25,8 @@ export class MempoolService {
private db: IDbController,
private chainId: number,
private reputationService: ReputationService,
private networkConfig: NetworkConfig
private networkConfig: NetworkConfig,
private logger: Logger
) {
this.USEROP_COLLECTION_KEY = `${chainId}:USEROPKEYS`;
this.USEROP_HASHES_COLLECTION_PREFIX = "USEROPHASH:";
Expand Down Expand Up @@ -72,6 +73,7 @@ export class MempoolService {
});
await this.removeUserOpHash(existingEntry.userOpHash);
await this.saveUserOpHash(entry.userOpHash, entry);
this.logger.debug("Mempool: User op replaced");
} else {
await this.checkEntityCountInMempool(
entry,
Expand All @@ -87,6 +89,7 @@ export class MempoolService {
await this.db.put(this.USEROP_COLLECTION_KEY, userOpKeys);
await this.db.put(key, { ...entry, lastUpdatedTime: now() });
await this.saveUserOpHash(entry.userOpHash, entry);
this.logger.debug("Mempool: User op added");
}
await this.updateSeenStatus(userOp, aggregator);
}
Expand Down

0 comments on commit c1c7808

Please sign in to comment.