First pass at integrating ITX with Optimism#43
First pass at integrating ITX with Optimism#43stonecoldpat wants to merge 4 commits intoethereum-optimism:masterfrom
Conversation
| gasRetryIncrement: this.gasRetryIncrement | ||
| } | ||
| // Enable ITX by setting a provider. It'll re-use the sequencer key. | ||
| if (this.itxProvider !== '') { |
There was a problem hiding this comment.
This string value doesnt appear to be used
There was a problem hiding this comment.
i've used it to set the provider now
| } | ||
| // Enable ITX by setting a provider. It'll re-use the sequencer key. | ||
| if (this.itxProvider !== '') { | ||
| const itx = new JsonRpcProvider( |
There was a problem hiding this comment.
Could use the provider that already exists on the signer - and check that it's an infura provider
this.signer.provider
Then there's need to connect a new one - in fact you dont have to pass one into sendTxWithITX and can pass this.signer.provider to itxWaitForTx
| this.log | ||
| ) | ||
| const gas = await itx.estimateGas( | ||
| await signer.populateTransaction({ to, data }) |
There was a problem hiding this comment.
I believe populateTransaction already calls estimateGas internally to populate the gasLimit. So if you do that probably dont need to call estimateGas. It may also be overkill, as it call getGasPrice, getTransactionCount, getChainId etc which you dont need just get a gasLimit estimate
src/utils.ts
Outdated
| await wait(2000) | ||
|
|
||
| // Let's try to send it again. | ||
| return sendTxWithITX(itx, signer, to, data, gas, iteration + 1) |
There was a problem hiding this comment.
Probably clearer just to do a while loop here instead of recursion - and you wouldnt need that extra iteration var in the function interface
src/utils.ts
Outdated
| import { BigNumber, Signer, Wallet } from 'ethers' | ||
| import { arrayify, defaultAbiCoder, keccak256 } from 'ethers/lib/utils' | ||
|
|
||
| const RETRY_LIMIT = 3 |
There was a problem hiding this comment.
This should probably have a better name - RETRY_LIMIT is very generic
There was a problem hiding this comment.
renamed to RETRY_JSON_REQUEST_LIMIT
| ) | ||
|
|
||
| this.log.info(`ITX relay transaction hash: ${relayTransactionHash}`) | ||
| return itxWaitForTx(itx, relayTransactionHash) |
There was a problem hiding this comment.
The else block logs:
this.log.debug('Transaction receipt:', receipt)
this.log.info(successMessage)
I think you should log these things too
You can return the receipt from itxWaitForTx
src/utils.ts
Outdated
| if (receipt && receipt.confirmations && receipt.confirmations > 1) { | ||
| // The transaction is now on chain! | ||
| this.log.info(`Ethereum transaction hash: ${receipt.transactionHash}`) | ||
| return |
There was a problem hiding this comment.
As mentioned above, this should return the receipt
src/utils.ts
Outdated
|
|
||
| // check each of these hashes to see if their receipt exists and | ||
| // has confirmations | ||
| for (const response of statusResponse.length) { |
There was a problem hiding this comment.
I'm surprised the typescript compiler accepts this, I assume statusResponse is an array and length is a number.
If so you should have:
for (const response of statusResponse) {
There was a problem hiding this comment.
Fixed. I originally had a normal forloop, but linter requires for-of. Looks like I wrote it wrong here.
src/utils.ts
Outdated
| // check each of these hashes to see if their receipt exists and | ||
| // has confirmations | ||
| for (const response of statusResponse.length) { | ||
| const hashes = response |
There was a problem hiding this comment.
Could set the name in the initial for/of, although I'd suggest broadcast as a better name since the object contains more than hashes.
for (const broadcast of statusResponse) {
src/utils.ts
Outdated
| } catch (e) { | ||
| // Take into account JSON RPC errors that may arise (e.g. rate limiting) | ||
|
|
||
| if (iteration === RETRY_LIMIT) { |
There was a problem hiding this comment.
Perhaps I'm paranoid, but I always use >= when comparing against a max, just in case someone does something funny with iteration.
| resubmissionTimeout: number | ||
| minGasPriceInGwei: number | ||
| maxGasPriceInGwei: number |
There was a problem hiding this comment.
Unrelated to the core functionality implemented here, but there seem to be quite a few stylistic changes made here (like the removal of commas above). We don't have a linting / formatting CI step yet (which we ought to soon hopefully). Absent that could you try to strip them from these commits?
It is now set up to send transactions via ITX.
We need to update the smart contracts of optimism to check ecrecover instead of msg.sender. Then we can test how well ITX works in this script.