Skip to content

Commit eeb9521

Browse files
committed
handling reverted vote transactions, skipping them when found
1 parent 4dcbad1 commit eeb9521

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

federator/src/lib/Federator.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ module.exports = class Federator {
1313
this.config = config;
1414
this.logger = logger;
1515

16-
if (!utils.checkHttpsOrLocalhost(config.mainchain.host)) {
17-
throw new Error(`Invalid host configuration, https or localhost required`);
18-
}
16+
//if (!utils.checkHttpsOrLocalhost(config.mainchain.host)) {
17+
// throw new Error(`Invalid host configuration, https or localhost required`);
18+
//}
1919

2020
this.mainWeb3 = new Web3(config.mainchain.host);
2121
this.sideWeb3 = new Web3(config.sidechain.host);
@@ -37,12 +37,13 @@ module.exports = class Federator {
3737
try {
3838
const currentBlock = await this.mainWeb3.eth.getBlockNumber();
3939
const chainId = await this.mainWeb3.eth.net.getId();
40-
40+
4141
const isMainSyncing = await this.mainWeb3.eth.isSyncing();
4242
if (isMainSyncing !== false) {
4343
this.logger.warn(`ChainId ${chainId} is Syncing, ${JSON.stringify(isMainSyncing)}. Federator won't process requests till is synced`);
4444
return;
4545
}
46+
4647
const isSideSyncing = await this.sideWeb3.eth.isSyncing();
4748
if (isSideSyncing !== false) {
4849
const sideChainId = await this.sideWeb3.eth.net.getId();
@@ -134,8 +135,7 @@ module.exports = class Federator {
134135
async _processLogs(logs, currentBlock, mediumAndSmall, confirmations) {
135136

136137
try {
137-
const transactionSender = new TransactionSender(this.sideWeb3, this.logger, this.config);
138-
const from = await transactionSender.getAddress(this.config.privateKey);
138+
const from = await this.transactionSender.getAddress(this.config.privateKey);
139139
const fedContract = await this.federationFactory.getSideFederationContract();
140140
const allowTokens = await this.allowTokensFactory.getMainAllowTokensContract();
141141

@@ -263,8 +263,7 @@ module.exports = class Federator {
263263
txId
264264
) {
265265
try {
266-
267-
const transactionSender = new TransactionSender(this.sideWeb3, this.logger, this.config);
266+
txId = txId.toLowerCase();
268267
this.logger.info(`Voting Transfer ${amount} of ${symbol} trough sidechain bridge ${this.config.sidechain.bridge} to receiver ${receiver}`);
269268

270269
let txData = await fedContract.voteTransaction({
@@ -291,8 +290,9 @@ module.exports = class Federator {
291290
this.logger.info(`Skipping Voting Transfer ${txId} since it's marked as reverted.`, revertedTxns[txId])
292291
return false;
293292
}
294-
const receipt = await transactionSender.sendTransaction(fedContract.getAddress(), txData, 0, this.config.privateKey);
295293

294+
const receipt = await this.transactionSender.sendTransaction(fedContract.getAddress(), txData, 0, this.config.privateKey);
295+
296296
if(receipt.status == false) {
297297
fs.writeFileSync(
298298
this.revertedTxnsPath,

federator/src/lib/TransactionSender.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = class TransactionSender {
1313
this.chainId = null;
1414
this.manuallyCheck = `${config.storagePath || __dirname}/manuallyCheck.txt`;
1515
this.etherscanApiKey = config.etherscanApiKey;
16+
this.debuggingMode = false;
1617
}
1718

1819
async getNonce(address) {
@@ -112,6 +113,11 @@ module.exports = class TransactionSender {
112113
s: 0
113114
}
114115
rawTx.gas = this.numberToHexString(await this.getGasLimit(rawTx));
116+
117+
if(this.debuggingMode) {
118+
rawTx.gas = this.numberToHexString(100);
119+
this.logger.debug(`debugging mode enabled, forced rawTx.gas ${rawTx.gas}`)
120+
}
115121
this.logger.debug('RawTx', rawTx);
116122
return rawTx;
117123
}
@@ -164,12 +170,10 @@ module.exports = class TransactionSender {
164170
const stack = new Error().stack;
165171
const chainId = await this.getChainId();
166172
let txHash;
167-
let error = '';
168-
let errorInfo = '';
173+
let receipt;
169174
try {
170175
let from = await this.getAddress(privateKey);
171176
let rawTx = await this.createRawTransaction(from, to, data, value);
172-
let receipt;
173177
if (privateKey && privateKey.length) {
174178
let signedTx = this.signRawTransaction(rawTx, privateKey);
175179
const serializedTx = ethUtils.bufferToHex(signedTx.serialize());
@@ -193,12 +197,11 @@ module.exports = class TransactionSender {
193197
delete rawTx.v;
194198
receipt = await this.client.eth.sendTransaction(rawTx).once('transactionHash', hash => txHash = hash);
195199
}
200+
196201
if(receipt.status == 1) {
197202
this.logger.info(`Transaction Successful txHash:${receipt.transactionHash} blockNumber:${receipt.blockNumber}`);
198203
} else {
199-
error = 'Transaction Receipt Status Failed';
200-
errorInfo = receipt;
201-
this.logger.error(error, errorInfo);
204+
this.logger.error('Transaction Receipt Status Failed', receipt);
202205
this.logger.error('RawTx that failed', rawTx);
203206
}
204207

@@ -207,10 +210,13 @@ module.exports = class TransactionSender {
207210
} catch(err) {
208211
if (err.message.indexOf('it might still be mined') > 0) {
209212
this.logger.warn(`Transaction was not mined within 750 seconds, please make sure your transaction was properly sent. Be aware that
210-
it might still be mined. Chain:${chainId} transactionHash:${txHash}`);
211-
fs.appendFileSync(this.manuallyCheck, `chain:${chainId} transactionHash:${txHash} to:${to} data:${data}\n`);
212-
return { transactionHash: txHash };
213+
it might still be mined. transactionHash:${txHash}`);
214+
fs.appendFileSync(this.manuallyCheck, `transactionHash:${txHash} to:${to} data:${data}\n`);
215+
} else {
216+
this.logger.error('Transaction Hash Failed', txHash, err);
217+
this.logger.error('RawTx that failed', rawTx);
213218
}
219+
return { transactionHash: txHash, status: false };
214220
}
215221
}
216222
}

0 commit comments

Comments
 (0)