Skip to content

Commit

Permalink
imp: deploy contracts when the corresponding worker type is present (#10
Browse files Browse the repository at this point in the history
)
  • Loading branch information
GAtom22 authored Apr 6, 2023
1 parent 503d83d commit 0fb0b71
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/common/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export async function sendCosmosTxWithNonceRefresher(
break;
} else {
const errMsg = res.message || res.tx_response.raw_log;
if (errMsg.includes('sequence mismatch')) {
if (errMsg && errMsg.includes('sequence mismatch')) {
// in case it is invalid nonce, retry with the refreshed signer
logger?.debug(
`nonce error while ${
Expand All @@ -185,9 +185,9 @@ export async function sendCosmosTxWithNonceRefresher(
return res;
}

export function getFailedTxReason(error: string): string {
if (error.includes(TX_NOT_FOUND)) {
export function getFailedTxReason(error: string | undefined): string {
if (error?.includes(TX_NOT_FOUND)) {
return TX_NOT_FOUND;
}
return error.split(':')[0];
return error?.split(':')[0] || '';
}
24 changes: 13 additions & 11 deletions src/orchestrator/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class Orchestrator {
} else if (error.code == 'SERVER_ERROR') {
try {
errorString = JSON.parse(error.body)['error']['message'];
if (errorString.includes('nonce')) {
if (errorString && errorString.includes('nonce')) {
errorString = 'INVALID_NONCE';
}
} catch (e) {
Expand Down Expand Up @@ -140,7 +140,6 @@ export class Orchestrator {
this.logger.info('initializing orchestrator');
this.validators = await getValidatorsAddresses(this.params.apiUrl);
await this._throwIfOrchestratorBalanceBelowThreshold();
await this._initializeContracts();
await this._initializeWorkers();
this._startWorkers();
this._initializeRefunder();
Expand All @@ -158,6 +157,16 @@ export class Orchestrator {
async _initializeWorkers() {
this.logger.info(`initializing ${this.params.numberOfWorkers} workers`);
const typesCount = this.params.workerTypes.length;

if (this.params.workerTypes.includes(gasConsumer)) {
await this._deployGasConsumerContract();
}

if (this.params.workerTypes.includes(converter)) {
const contractAddress = await this._deployERC20();
await this.registerPair(contractAddress);
}

for (let i = 0; i < this.params.numberOfWorkers; i++) {
const workerType = this.params.workerTypes[i % typesCount];
await this.addWorker(workerType, {});
Expand Down Expand Up @@ -218,13 +227,6 @@ export class Orchestrator {
}
}

async _initializeContracts() {
this.logger.info('initializing contracts');
await this._deployGasConsumerContract();
const contractAddress = await this._deployERC20();
await this.registerPair(contractAddress);
}

async _initializeRefunder() {
this.logger.info('initializing refunder');
while (!this.isStopped) {
Expand Down Expand Up @@ -270,7 +272,7 @@ export class Orchestrator {
} catch (e: any) {
err = e;
const errStr = JSON.stringify(e);
if (errStr.includes('nonce')) {
if (errStr && errStr.includes('nonce')) {
// in case it is invalid nonce, retry with the refreshed signer
this.logger.debug(
'nonce error while funding account. retrying with refreshed nonce'
Expand Down Expand Up @@ -453,7 +455,7 @@ export class Orchestrator {
} catch (e: any) {
err = e;
const errStr = JSON.stringify(e);
if (errStr.includes('nonce')) {
if (errStr && errStr.includes('nonce')) {
// in case it is invalid nonce, retry with the refreshed signer
this.logger.debug(
`nonce error while deploying ${contractType} contract. retrying with refreshed nonce`
Expand Down
4 changes: 2 additions & 2 deletions src/worker/eth-sender-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export class EthSenderWorker extends IWorker {
async onFailedTx(error: any) {
super.onFailedTx(error);
const errorMessage = JSON.parse(error.body)['error']['message'];
if (errorMessage.includes('nonce')) {
if (errorMessage && errorMessage.includes('nonce')) {
this.nonce = await this.wallet.getTransactionCount('latest');
} else if (errorMessage.includes('insufficient fee')) {
} else if (errorMessage && errorMessage.includes('insufficient fee')) {
this.gasPrice = await this.wallet.getGasPrice();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/worker/evmos-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export abstract class EvmosWorker extends IWorker {

async onFailedTx(error: any) {
super.onFailedTx({ code: error.code, message: error.raw_log });
if (error.raw_log.includes('account sequence mismatch')) {
if (error.raw_log && error.raw_log.includes('account sequence mismatch')) {
this.logger.debug('invalid nonce (sequence), updated to the expected');
const expectedSequence = getExpectedNonce(error.raw_log);
if (expectedSequence) {
Expand Down
7 changes: 5 additions & 2 deletions src/worker/iworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ export abstract class IWorker {
});
// for some reason our nonce expired cases are not being categorized
// by ethers library as so
if (errorMessage.includes('nonce')) {
if (errorMessage && errorMessage.includes('nonce')) {
await this.refreshSignerNonce('latest');
} else if (errorMessage.includes('tx already in mempool')) {
} else if (
errorMessage &&
errorMessage.includes('tx already in mempool')
) {
await this.refreshSignerNonce('pending');
}
break;
Expand Down

0 comments on commit 0fb0b71

Please sign in to comment.