Skip to content

Commit b6fa3d4

Browse files
authored
Retry Fixes (#123)
* updated retry to not retry if gas value is lower than previously sent. Dynamic Wallet Add doesn't work. Will be fixed in Adam/Furqans branch * updated log to warn & updated message
1 parent 869a119 commit b6fa3d4

File tree

3 files changed

+26
-38
lines changed

3 files changed

+26
-38
lines changed

server/helpers/dbOperations.ts

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,15 @@ import { FastifyInstance, FastifyRequest } from "fastify";
1010
import { StatusCodes } from "http-status-codes";
1111
import { Knex } from "knex";
1212
import { v4 as uuid } from "uuid";
13-
import { addWalletToDB, connectToDatabase } from "../../core";
13+
import { connectToDatabase, getWalletDetails } from "../../core";
1414
import { createCustomError } from "../../core/error/customError";
15-
import { WalletData } from "../../core/interfaces";
1615
import {
1716
TransactionSchema,
1817
TransactionStatusEnum,
1918
transactionResponseSchema,
2019
} from "../schemas/transaction";
2120
import { walletTableSchema } from "../schemas/wallet";
2221

23-
const checkNetworkInWalletDB = async (
24-
database: Knex,
25-
chainId: string,
26-
walletAddress: string,
27-
): Promise<WalletData> => {
28-
try {
29-
const walletData = await database("wallets")
30-
.where("chainId", chainId)
31-
.where("walletAddress", walletAddress.toLowerCase())
32-
.first();
33-
34-
return walletData;
35-
} catch (error) {
36-
throw error;
37-
}
38-
};
39-
4022
export const queueTransaction = async (
4123
request: FastifyRequest,
4224
tx: Transaction<any> | DeployTransaction,
@@ -74,14 +56,23 @@ export const queueTransaction = async (
7456
const chainId = chainData.chainId.toString();
7557
const dbInstance = await connectToDatabase();
7658
const walletAddress = await tx.getSignerAddress();
77-
const checkForNetworkData = await checkNetworkInWalletDB(
78-
dbInstance,
79-
chainId,
59+
const walletDetails = await getWalletDetails(
8060
walletAddress.toLowerCase(),
61+
chainId,
62+
dbInstance,
8163
);
8264

83-
if (!checkForNetworkData) {
84-
await addWalletToDB(chainId, walletAddress, chainData.slug, dbInstance);
65+
if (!walletDetails) {
66+
// await addWalletToDB(
67+
// chainId,
68+
// dbInstance,
69+
// walletAddress,
70+
// chainData.slug,
71+
// getWalletType(),
72+
// );
73+
throw new Error(
74+
`Import Wallet Address ${walletAddress} to DB using /wallet/import end-point`,
75+
);
8576
}
8677
// encode tx
8778
const value = await tx.getValue();

server/schemas/wallet/index.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@ export const walletParamSchema = Type.Object({
1111
}),
1212
});
1313

14-
// CREATE TABLE IF NOT EXISTS wallets (
15-
// "walletAddress" VARCHAR(255) NOT NULL,
16-
// "chainId" VARCHAR(255) NOT NULL,
17-
// "walletType" VARCHAR(255) NOT NULL,
18-
// "blockchainNonce" BIGINT NOT NULL,
19-
// "lastSyncedTimestamp" TIMESTAMP,
20-
// "lastUsedNonce" BIGINT NOT NULL,
21-
// -- AWS
22-
// "aws_kms_keyId" VARCHAR(255),
23-
// "aws_kms_arn" VARCHAR(255),
24-
// -- KEYID
25-
// -- ARN
26-
// -- GCP
27-
// PRIMARY KEY ("walletAddress", "chainId")
2814
export const walletTableSchema = Type.Optional(
2915
Type.Object({
3016
walletAddress: Type.String({

worker/controller/retryTransaction.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ export const retryTransactions = async (server: FastifyInstance) => {
8888
`Gas Data MaxFeePerGas: ${gasData.maxFeePerGas}, MaxPriorityFeePerGas: ${gasData.maxPriorityFeePerGas}, gasPrice`,
8989
);
9090

91+
if (
92+
gasData.maxFeePerGas?.lte(
93+
BigNumber.from(txReceiptData.txData.maxFeePerGas),
94+
)
95+
) {
96+
server.log.warn(
97+
`Gas Data MaxFeePerGas: ${gasData.maxFeePerGas} is less than or equal to Previously Submitted Transaction: ${txReceiptData.txData.maxFeePerGas} for queueId: ${txReceiptData.queueId}. Will Retry Later`,
98+
);
99+
continue;
100+
}
101+
91102
// Re-Submit transaction to the blockchain
92103
// Create transaction object
93104
const txObject: providers.TransactionRequest = {

0 commit comments

Comments
 (0)