Skip to content
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

Refactor/minor things before chain integrations #754

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ dist/
*.code-workspace
config/development.json
config/production.json

# Random scripts that we shouldn't commit
dont-commit/
4 changes: 2 additions & 2 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"fundRelayers": true
},
"health": {
"checkRelayers": true
"checkRelayers": false
},
"config": {
"validate": true
Expand Down Expand Up @@ -1045,7 +1045,7 @@
"networksNotSupportingEthCallStateOverrides": [
1101, 81, 592, 169, 1715, 7116, 9980, 88882, 88888, 81457, 666666666, 2442,
8101902, 7001, 196, 195, 167009, 713715, 167000, 1328, 1329, 997, 995,
28882, 288, 920637907288165, 4202, 1135
28882, 288, 920637907288165
],
"trustWalletSupportedNetworks": [137, 56, 204, 42161, 10, 8453],
"networksNotSupportingEthCallBytecodeStateOverrides": [
Expand Down
8 changes: 6 additions & 2 deletions src/common/status/StatusService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ describe("StatusService", () => {
expect(errors).toEqual([]);
expect(durationSeconds).toBeGreaterThan(0);
});
});

describe("checkMasterAccount", () => {
it("should return an error if the master account was never funded", async () => {
// we mock only the services that are used
const statusService = new StatusService({
Expand Down Expand Up @@ -170,9 +172,11 @@ describe("StatusService", () => {
});

const { durationSeconds, errors } =
await statusService.checkRelayers(chainId);
await statusService.checkMasterAccount(chainId);

expect(errors).toEqual([`Relayer for chainId: ${chainId} is not funded`]);
expect(errors).toEqual([
`Master account for chainId: ${chainId} is not funded`,
]);
expect(durationSeconds).toBeGreaterThan(0);
});
});
Expand Down
30 changes: 26 additions & 4 deletions src/common/status/StatusService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ export class StatusService implements IStatusService {
}),
);

promises.push(
new Promise((resolve, reject) => {
this.checkMasterAccount(chainId)
.then((res) => {
errors = errors.concat(res.errors);
latencies.masterAccount = res.durationSeconds;
resolve(res);
})
.catch((err) => reject(err));
}),
);

if (nodeconfig.get<boolean>("health.checkRelayers")) {
promises.push(
new Promise((resolve, reject) => {
Expand Down Expand Up @@ -250,24 +262,34 @@ export class StatusService implements IStatusService {
});
}

// checkRelayers (tries to) check if the relayers can actually relay transactions
async checkRelayers(chainId: number): Promise<StatusCheckResult> {
async checkMasterAccount(chainId: number): Promise<StatusCheckResult> {
return statusCheck(async () => {
const relayerManager = this.evmRelayerManagerMap["RM1"][chainId];
if (!relayerManager) {
throw new Error(
`Relayers are temporarily unavailable for chainId: ${chainId}`,
);
}

// A basic sanity check: this will be 0 if and only if it was never funded.
// Even if it was funded and then drained, the balance will be non-zero.
const masterAccount = relayerManager.ownerAccountDetails.getPublicKey();
const masterAccountBalance =
await this.networkServiceMap[chainId].getBalance(masterAccount);

if (masterAccountBalance === 0n) {
throw new Error(`Relayer for chainId: ${chainId} is not funded`);
throw new Error(`Master account for chainId: ${chainId} is not funded`);
}
});
}

// checkRelayers (tries to) check if the relayers can actually relay transactions
async checkRelayers(chainId: number): Promise<StatusCheckResult> {
return statusCheck(async () => {
const relayerManager = this.evmRelayerManagerMap["RM1"][chainId];
if (!relayerManager) {
throw new Error(
`Relayers are temporarily unavailable for chainId: ${chainId}`,
);
}

// The following checks if the relayers are low on balance and returns an error only if the master account is also low on balance
Expand Down
Loading