Skip to content
This repository was archived by the owner on Apr 11, 2021. It is now read-only.

First pass at integrating ITX with Optimism#43

Open
stonecoldpat wants to merge 4 commits intoethereum-optimism:masterfrom
stonecoldpat:add-itx-support
Open

First pass at integrating ITX with Optimism#43
stonecoldpat wants to merge 4 commits intoethereum-optimism:masterfrom
stonecoldpat:add-itx-support

Conversation

@stonecoldpat
Copy link
Copy Markdown

It is now set up to send transactions via ITX.

  • If you add an Infura ID into the .env for "ITX_PROVIDER", it will enable it.
  • It reuses the sequencer key for signing messages that are sent to ITX (authenticate to the service)

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.

gasRetryIncrement: this.gasRetryIncrement
}
// Enable ITX by setting a provider. It'll re-use the sequencer key.
if (this.itxProvider !== '') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This string value doesnt appear to be used

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changed

this.log
)
const gas = await itx.estimateGas(
await signer.populateTransaction({ to, data })
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

src/utils.ts Outdated
await wait(2000)

// Let's try to send it again.
return sendTxWithITX(itx, signer, to, data, gas, iteration + 1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should probably have a better name - RETRY_LIMIT is very generic

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

renamed to RETRY_JSON_REQUEST_LIMIT

)

this.log.info(`ITX relay transaction hash: ${relayTransactionHash}`)
return itxWaitForTx(itx, relayTransactionHash)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As mentioned above, this should return the receipt

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

src/utils.ts Outdated

// check each of these hashes to see if their receipt exists and
// has confirmations
for (const response of statusResponse.length) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

changed

src/utils.ts Outdated
} catch (e) {
// Take into account JSON RPC errors that may arise (e.g. rate limiting)

if (iteration === RETRY_LIMIT) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps I'm paranoid, but I always use >= when comparing against a max, just in case someone does something funny with iteration.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +29 to +31
resubmissionTimeout: number
minGasPriceInGwei: number
maxGasPriceInGwei: number
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants