-
Notifications
You must be signed in to change notification settings - Fork 115
Type 2 transactions for miner / mtx broadcaster #1174
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e3e2ed6
Try to support EIP1559 in packages
area 4818a62
Make MTX broadcaster more gas(limit) efficient
area 6593dfb
Page previous mining cycles in miner
area 2367cd8
Improve fallback plan when gas oracle fails
area de4b9cd
Page past mining cycles more smartly
area a2c619f
First changes following review
area f9edd05
Fix package-lock.json
area 81a0078
When gas price oracle down, still delete gasPrice from feeData
area 5b7d30d
Some abstraction in the miner
area 100937e
Refactor ReputationMiner for clarity
kronosapiens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const ethers = require("ethers"); | ||
const axios = require("axios"); | ||
|
||
/** | ||
* Update the gas estimate | ||
* @param {string} Transaction speed (fastest, fast, safeLow) | ||
* @param {number} Chain ID | ||
* @param {object} Adapter | ||
* @param {object} Provider | ||
* @return {Promise} | ||
*/ | ||
const getFeeData = async function (_type, chainId, adapter, provider) { | ||
let defaultGasPrice; | ||
let factor; | ||
let feeData; | ||
|
||
let type = _type; | ||
const options = { | ||
headers: { | ||
"User-Agent": "Request-Promise", | ||
}, | ||
json: true, // Automatically parses the JSON string in the response | ||
}; | ||
|
||
if (chainId === 100) { | ||
options.url = "https://blockscout.com/xdai/mainnet/api/v1/gas-price-oracle"; | ||
defaultGasPrice = ethers.BigNumber.from(10000000000); | ||
factor = 1; | ||
// This oracle presents the information slightly differently from ethgasstation. | ||
if (_type === "safeLow") { | ||
type = "slow"; | ||
} | ||
} else if (chainId === 1) { | ||
options.url = "https://ethgasstation.info/json/ethgasAPI.json"; | ||
defaultGasPrice = ethers.BigNumber.from(10000000000); | ||
factor = 10; | ||
} else { | ||
// We don't have an oracle, so just use the provided fee data | ||
adapter.log(`During gas estimation: unknown chainid ${chainId}`); | ||
feeData = await provider.getFeeData(); | ||
delete feeData.lastBaseFeePerGas; | ||
if (feeData.maxFeePerGas) { | ||
delete feeData.gasPrice; | ||
} | ||
return feeData; | ||
} | ||
|
||
try { | ||
feeData = await provider.getFeeData(); | ||
delete feeData.lastBaseFeePerGas; | ||
if (feeData.maxFeePerGas) { | ||
delete feeData.gasPrice; | ||
} | ||
// Update gas prices from whichever oracle | ||
try { | ||
const request = await axios.request(options); | ||
const gasEstimates = request.data; | ||
|
||
if (feeData.maxFeePerGas) { | ||
// Update the EIP1559 fee data based on the type | ||
const ratio = gasEstimates[type] / gasEstimates.average; | ||
// Increase the priority fee by this ratio | ||
const newMaxPriorityFeePerGas = ethers.BigNumber.from(Math.floor(feeData.maxPriorityFeePerGas * 1000)) | ||
.mul(Math.floor(ratio * 1000)) | ||
.div(1000 * 1000); | ||
// Increase the max fee per gas by the same amount (not the same ratio) | ||
feeData.maxFeePerGas = feeData.maxFeePerGas.add(newMaxPriorityFeePerGas).sub(feeData.maxPriorityFeePerGas); | ||
feeData.maxPriorityFeePerGas = newMaxPriorityFeePerGas; | ||
return feeData; | ||
} | ||
|
||
// If we get here, chain is not EIP1559, so just update gasPrice | ||
if (gasEstimates[type]) { | ||
feeData.gasPrice = ethers.BigNumber.from(gasEstimates[type] * 1e9).div(factor); | ||
} else { | ||
feeData.gasPrice = defaultGasPrice; | ||
} | ||
} catch (err) { | ||
adapter.error(`Error during gas estimation: ${err}`); | ||
adapter.error(`Using default fee data from node`); | ||
} | ||
} catch (err) { | ||
adapter.error(`Error getting fee data from provider: ${err}`); | ||
adapter.error(`Using default static gas fee. Hopefully it's not too low...`); | ||
feeData = { gasPrice: defaultGasPrice }; | ||
} | ||
return feeData; | ||
}; | ||
|
||
module.exports = getFeeData; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.