Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquidator & disputer bot: Improve bot gas estimation #1801

Merged
merged 19 commits into from
Aug 7, 2020

Conversation

chrismaree
Copy link
Member

Motivation

Right now the bots do not implement any gas estimation before sending liquidation or dispute transactions. This means that a transaction will default to the bots txnGasLimit which is 9 million. This makes the transactions inefficient as they require to send way more gas than they will actually use.
Summary

This PR uses the estimateGas function before sending the transaction. If this value is less than the bots configured txnGasLimit, it uses 1.5x this value as the gas limit.

close #1791

nicholaspai and others added 4 commits July 31, 2020 00:43
Signed-off-by: Christopher Maree <[email protected]>
Signed-off-by: Christopher Maree <[email protected]>
disputer/disputer.js Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Aug 4, 2020

Coverage Status

Coverage remained the same at 92.683% when pulling 7978564 on chrismaree/patch-liquidator-bot-gass-price into 4568d16 on master.

@chrismaree chrismaree requested review from nicholaspai and mrice32 and removed request for nicholaspai August 4, 2020 12:34
disputer/disputer.js Outdated Show resolved Hide resolved
Copy link
Member

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome but see my comment about catching errors from estimateGas

Signed-off-by: Christopher Maree <[email protected]>
Signed-off-by: Christopher Maree <[email protected]>
disputer/disputer.js Outdated Show resolved Hide resolved
try {
await dispute.call({ from: this.account, gasPrice: this.gasEstimator.getCurrentFastPrice() });
await dispute.call({ from: this.account });
gasLimit = Math.floor((await dispute.estimateGas({ from: this.account })) * 1.5);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we really need the 1.5 buffer? If so, maybe define this in the config or as a constant above the file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think truffle uses 1.25 by default: trufflesuite/truffle#2539. Not sure of all the details around why that's necessary, but I've always been unclear if it's estimating the gas required or the gas used (since the used gas may be lower than the gas that you must send to get a successful txn).

Copy link
Member Author

@chrismaree chrismaree Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think we need the buffer. Often the gas used by the tx is different from what the estimation provides. It could be a config but I dont think there are any situations in which the user should be messing with this. I have set it to the same that Truffle estimates to at 1.25. PTAL and let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I think you should set the 1.25x multiple early as a constant and then re-use that so you and future devs don't fat finger any multiples

Copy link
Member

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting estimateGas within a try-catch. I think you can simplify some of the txnGasLimit vs gasEstimation logic and also have questions about the arbitrary 1.5x buffer

Copy link
Member

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once @nicholaspai's comments are resolved!

try {
await dispute.call({ from: this.account, gasPrice: this.gasEstimator.getCurrentFastPrice() });
await dispute.call({ from: this.account });
gasLimit = Math.floor((await dispute.estimateGas({ from: this.account })) * 1.5);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think truffle uses 1.25 by default: trufflesuite/truffle#2539. Not sure of all the details around why that's necessary, but I've always been unclear if it's estimating the gas required or the gas used (since the used gas may be lower than the gas that you must send to get a successful txn).

nicholaspai and others added 10 commits August 4, 2020 23:29
…PClient once in sponsor reporter

Signed-off-by: Nick Pai <[email protected]>
Signed-off-by: Nick Pai <[email protected]>
Signed-off-by: Christopher Maree <[email protected]>
…quidator-bot-gass-price

Signed-off-by: Christopher Maree <[email protected]>
Signed-off-by: Christopher Maree <[email protected]>
…om:UMAprotocol/protocol into chrismaree/patch-liquidator-bot-gass-price

Signed-off-by: Christopher Maree <[email protected]>
try {
await dispute.call({ from: this.account, gasPrice: this.gasEstimator.getCurrentFastPrice() });
totalPaid = await dispute.call({ from: this.account });
gasLimit = Math.floor((await dispute.estimateGas({ from: this.account })) * 1.25);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps const GAS_LIMIT_BUFFER = 1.25 would be safer

Signed-off-by: Christopher Maree <[email protected]>
disputer/disputer.js Outdated Show resolved Hide resolved
Copy link
Member

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after this passes CI

chrismaree and others added 2 commits August 7, 2020 13:37
@nicholaspai
Copy link
Member

LGTM!

@chrismaree chrismaree merged commit f882de6 into master Aug 7, 2020
@chrismaree chrismaree deleted the chrismaree/patch-liquidator-bot-gass-price branch August 7, 2020 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Liquidator bot defaults to crazy high gas limits
4 participants