Skip to content

Commit

Permalink
fix timeout parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Apr 1, 2024
1 parent 961ba90 commit 608083a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
17 changes: 7 additions & 10 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ module.exports = {
count: 10,
},
signerId: process.env.SIGNER || undefined,
gasMultiplier: parseFloat(process.env.GAS_PRICE_MULTIPLIER) || 1,
},
gnosis: {
url: process.env.ETH_NODE_URL,
Expand All @@ -137,7 +136,6 @@ module.exports = {
count: 10,
},
signerId: process.env.SIGNER || undefined,
gasMultiplier: parseFloat(process.env.GAS_PRICE_MULTIPLIER) || 1,
},
harmony: {
url: process.env.ETH_NODE_URL,
Expand All @@ -149,7 +147,6 @@ module.exports = {
count: 10,
},
signerId: process.env.SIGNER || undefined,
gasMultiplier: parseFloat(process.env.GAS_PRICE_MULTIPLIER) || 1,
},
polygon: {
url: process.env.ETH_NODE_URL,
Expand All @@ -162,9 +159,10 @@ module.exports = {
},
signerId: process.env.SIGNER || undefined,
gasMultiplier: parseFloat(process.env.GAS_PRICE_MULTIPLIER) || 1,
increaseFactor: 135,
maxRetries: 5,
timeout: 5 * 60 * 1000, // 5 minute
increaseFactor: parseInt(process.env.GAS_INCREASE_FACTOR) || 135, // base 100 (35% increase by default)
maxRetries: parseInt(process.env.TX_MAX_RETRIES) || 5, // 5 maximum retries for a tx
txTimeoutMs: parseInt(process.env.TX_TIMEOUT_MS) || 5 * 60 * 1000, // 5 minutes in milliseconds (timeout for each tx send to the network)
timeout: parseInt(process.env.TX_TIMEOUT_MS) || 5 * 60 * 1000, // in milliseconds (timeout for the http request needs to match the txTimeout)
},
avalanche: {
url: process.env.ETH_NODE_URL,
Expand All @@ -176,7 +174,6 @@ module.exports = {
count: 10,
},
signerId: process.env.SIGNER || undefined,
gasMultiplier: parseFloat(process.env.GAS_PRICE_MULTIPLIER) || 1,
},
},

Expand Down Expand Up @@ -222,10 +219,10 @@ module.exports = {

etherscan: {
apiKey: {
goerli: process.env.ETHERSCAN_API_KEY,
sepolia: process.env.ETHERSCAN_API_KEY,
gnosis: process.env.ETHERSCAN_API_KEY,
mainnet: process.env.ETHERSCAN_API_KEY,
polygon: process.env.ETHERSCAN_API_KEY,
gnosis: process.env.ETHERSCAN_API_KEY,
sepolia: process.env.ETHERSCAN_API_KEY,
},
},
};
24 changes: 8 additions & 16 deletions signers/GcpKmsSignerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ export class GcpKmsSignerProvider extends ProviderWrapper {
public signer: GcpKmsSigner;
public maxRetries: number;
public network: string;
public timeout: number;
public txTimeout: number;
public increaseFactor: number;

constructor(
provider: EIP1193Provider,
config: GcpKmsSignerConfig,
chainId: number,
network: string,
increaseFactor: number,
timeout: number = 3 * 60 * 1000, // 3 minutes
maxRetries: number = 3,
increaseFactor: number = 135, // base 100 (35% increase)
txTimeout: number = 5 * 60 * 1000, // 5 minutes
maxRetries: number = 5, // maximum number of retries
) {
super(provider);
this.chainId = chainId;
Expand All @@ -47,7 +47,7 @@ export class GcpKmsSignerProvider extends ProviderWrapper {
this.network = network;
this.increaseFactor = increaseFactor;
this.maxRetries = maxRetries;
this.timeout = timeout;
this.txTimeout = txTimeout;
}

public async request(args: RequestArguments): Promise<unknown> {
Expand Down Expand Up @@ -80,20 +80,12 @@ export class GcpKmsSignerProvider extends ProviderWrapper {
? numberToHex(txRequest.gas.toString())
: undefined,
gasPrice: txRequest.gasPrice,

data: txRequest.data, //BytesLike;
value: txRequest.value
? numberToHex(txRequest.value.toString())
: undefined,
chainId: this.chainId,

// Typed-Transaction features - EIP-1559; Type 2
type: 2,

// EIP-2930; Type 1 & EIP-1559; Type 2
// accessList: txRequest.accessList ? txRequest.accessList : undefined,

// EIP-1559; Type 2
type: 2, // Typed-Transaction features - EIP-1559; Type 2
// @ts-ignore
maxPriorityFeePerGas: maxPriorityFeePerGas,
// @ts-ignore
Expand Down Expand Up @@ -151,7 +143,7 @@ export class GcpKmsSignerProvider extends ProviderWrapper {
}

private async waitForTransaction(txHash: string): Promise<boolean> {
const timeoutMs: number = this.timeout;
const timeoutMs: number = this.txTimeout;

return new Promise<boolean>((resolve) => {
let timeout = setTimeout(() => {
Expand All @@ -175,7 +167,7 @@ export class GcpKmsSignerProvider extends ProviderWrapper {
// Log the error but don't reject to keep checking until timeout
console.error("Error checking transaction receipt:", err);
}
}, 30000); // Check every 10 seconds
}, 30000); // Check every 30 seconds to prevent rate limiting
});
}

Expand Down
2 changes: 1 addition & 1 deletion signers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const buildSignerProvider = (
// @ts-ignore
networkConfig.increaseFactor,
// @ts-ignore
networkConfig.timeout,
networkConfig.txTimeout,
// @ts-ignore
networkConfig.maxRetries
);
Expand Down

0 comments on commit 608083a

Please sign in to comment.