Skip to content

Commit

Permalink
fix batch counting & add error filter (#107)
Browse files Browse the repository at this point in the history
- Fix batch counting before sending a full batch transaction.
- Add new nonce error filter.
  • Loading branch information
ngmachado authored Jan 20, 2022
1 parent aee7d79 commit 108ac80
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "superfluid-sentinel",
"version": "0.9.3",
"version": "0.9.4",
"description": "Superfluid Sentinel",
"main": "main.js",
"scripts": {
Expand Down
17 changes: 10 additions & 7 deletions src/utils/errors/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,26 @@ class TimeoutError extends BaseError {
}

function EVMErrorParser(err) {
if(err.message.toLowerCase().includes("block gas limit")) {
const message = err.message.toLowerCase();
if(message.includes("block gas limit")) {
return new GasBlockLimitError("block gas limit", err.message);
}
if(err.message.toLowerCase().includes("insufficient funds")) {
if(message.includes("insufficient funds")) {
return new AccountFundsError("insufficient funds", err.message);
}
if(err.message.toLowerCase().includes("nonce too low")) {
if(message.includes("nonce too low") ||
message.includes("transaction nonce"))
{
return new AccountNonceError("nonce too low", err.message);
}
if(err.message.toLowerCase().includes("transaction underpriced")) {
if(message.includes("transaction underpriced")) {
return new TxUnderpricedError("transaction underpriced", err.message);
}
if(err.message.toLowerCase().includes("already known")) {
if(message.includes("already known")) {
return new TxUnderpricedError("tx already known", err.message);
}

if(err.message.toLowerCase().includes("execution reverted") ||
if(message.includes("execution reverted") ||
err.message.toLowerCase().includes("reverted by the evm")
) {
return new SmartContractError("execution reverted", err.message);
Expand All @@ -90,7 +93,7 @@ function EVMErrorParser(err) {
return err;
}

return new BaseError(true, err.message);
return new BaseError(true, message);
}

module.exports = {
Expand Down
12 changes: 5 additions & 7 deletions src/web3client/liquidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,11 @@ class Liquidator {
await this.app.timer.timeout(500);
}

if (senders.length === this.app.config.MAX_BATCH_TX) {
if (senders.length === parseInt(this.app.config.MAX_BATCH_TX)) {
this.app.logger.debug(`sending a full batch work: load ${senders.length}`);
await this.sendBatch(batch.superToken, senders, receivers);
senders = [];
receivers = [];
}
if (senders.length === parseInt(this.app.config.MAX_BATCH_TX)) {
this.app.logger.debug(`sending a full batch work: load ${senders.length}`);
await this.sendBatch(batch.superToken, senders, receivers);
senders = [];
receivers = [];
}
}

Expand Down
1 change: 1 addition & 0 deletions test/unit-tests/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("Custom errors", () => {
expect(Errors.EVMErrorParser(new Error("block gas limit"))).to.be.an.instanceof(Errors.GasBlockLimitError);
expect(Errors.EVMErrorParser(new Error("insufficient funds"))).to.be.an.instanceof(Errors.AccountFundsError);
expect(Errors.EVMErrorParser(new Error("nonce too low"))).to.be.an.instanceof(Errors.AccountNonceError);
expect(Errors.EVMErrorParser(new Error("transaction nonce"))).to.be.an.instanceof(Errors.AccountNonceError);
expect(Errors.EVMErrorParser(new Error("transaction underpriced"))).to.be.an.instanceof(Errors.TxUnderpricedError);
expect(Errors.EVMErrorParser(new Error("already known"))).to.be.an.instanceof(Errors.TxUnderpricedError);
expect(Errors.EVMErrorParser(new Error("execution reverted"))).to.be.an.instanceof(Errors.SmartContractError);
Expand Down

0 comments on commit 108ac80

Please sign in to comment.