Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop' of github.com-enya:omgnetwork/optimism into bu…
Browse files Browse the repository at this point in the history
…gfix/issue-516-refactor-input-number-consistnecy
  • Loading branch information
sk-enya committed Oct 4, 2021
2 parents 81388c9 + b93fec3 commit bf8eee6
Show file tree
Hide file tree
Showing 23 changed files with 391 additions and 294 deletions.
1 change: 1 addition & 0 deletions packages/message-relayer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@eth-optimism/common-ts": "^0.1.5",
"@eth-optimism/contracts": "^0.4.11",
"@eth-optimism/core-utils": "^0.5.5",
"@eth-optimism/ynatm": "^0.2.2",
"@sentry/node": "6.2.5",
"bcfg": "^0.1.6",
"dotenv": "^8.2.0",
Expand Down
21 changes: 21 additions & 0 deletions packages/message-relayer/src/exec/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ const main = async () => {
'filter-polling-interval',
parseInt(env.FILTER_POLLING_INTERVAL, 10) || 60000
)
const MAX_GAS_PRICE_IN_GWEI = config.uint(
'max-gas-price-in-gwei',
parseInt(env.MAX_GAS_PRICE_IN_GWEI, 10) || 100
)
const GAS_RETRY_INCREMENT = config.uint(
'gas-retry-increment',
parseInt(env.GAS_RETRY_INCREMENT, 10) || 5
)
const RESUBMISSION_TIMEOUT = config.uint(
'resubmission-timeout',
parseInt(env.RESUBMISSION_TIMEOUT, 10) || 60
)
const NUM_CONFIRMATIONS = config.uint(
'num-confirmations',
parseInt(env.NUM_CONFIRMATIONS, 10) || 0
)

if (!ADDRESS_MANAGER_ADDRESS) {
throw new Error('Must pass ADDRESS_MANAGER_ADDRESS')
Expand Down Expand Up @@ -128,6 +144,11 @@ const main = async () => {
logger,
filterEndpoint: FILTER_ENDPOINT,
filterPollingInterval: FILTER_POLLING_INTERVAL,
// gas price
maxGasPriceInGwei: MAX_GAS_PRICE_IN_GWEI,
gasRetryIncrement: GAS_RETRY_INCREMENT,
numConfirmations: NUM_CONFIRMATIONS,
resubmissionTimeout: RESUBMISSION_TIMEOUT * 1000,
})

await service.start()
Expand Down
104 changes: 63 additions & 41 deletions packages/message-relayer/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Contract, ethers, Wallet, BigNumber, providers } from 'ethers'
import * as rlp from 'rlp'
import { MerkleTree } from 'merkletreejs'
import fetch from 'node-fetch';
import * as ynatm from '@eth-optimism/ynatm';

/* Imports: Internal */
import { fromHexString, sleep } from '@eth-optimism/core-utils'
Expand Down Expand Up @@ -56,6 +57,15 @@ interface MessageRelayerOptions {
filterEndpoint?: string

filterPollingInterval?: number

// gas fee
maxGasPriceInGwei?: number

gasRetryIncrement?: number

numConfirmations?: number

resubmissionTimeout?: number
}

const optionSettings = {
Expand Down Expand Up @@ -635,70 +645,75 @@ export class MessageRelayerService extends BaseService<MessageRelayerOptions> {
return
}

const result = await this.state.OVM_L1CrossDomainMessenger.connect(
this.options.l1Wallet
).relayMessage(
message.target,
message.sender,
message.message,
message.messageNonce,
proof,
{
gasLimit: this.options.relayGasLimit,
}
)
const sendTxAndWaitForReceipt = async (gasPrice): Promise<any> => {
const txResponse = await this.state.OVM_L1CrossDomainMessenger.connect(
this.options.l1Wallet
).relayMessage(
message.target,
message.sender,
message.message,
message.messageNonce,
proof,
{ gasPrice }
)
return this.options.l1Wallet.provider.waitForTransaction(
txResponse.hash,
this.options.numConfirmations
)
}

this.logger.info('Relay message transaction sent', {
transactionHash: result,
})
const minGasPrice = await this._getGasPriceInGwei(this.options.l1Wallet)

let receipt
try {
const receipt = await result.wait()

this.logger.info('Relay message included in block', {
transactionHash: receipt.transactionHash,
blockNumber: receipt.blockNumber,
gasUsed: receipt.gasUsed.toString(),
confirmations: receipt.confirmations,
status: receipt.status,
receipt = await ynatm.send({
sendTransactionFunction: sendTxAndWaitForReceipt,
minGasPrice: ynatm.toGwei(minGasPrice),
maxGasPrice: ynatm.toGwei(this.options.maxGasPriceInGwei),
gasPriceScalingFunction: ynatm.LINEAR(this.options.gasRetryIncrement),
delay: this.options.resubmissionTimeout,
})

this.logger.info('Relay message transaction sent', { receipt })
} catch (err) {
this.logger.error('Real relay attempt failed, skipping.', {
this.logger.error('Relay attempt failed, skipping.', {
message: err.toString(),
stack: err.stack,
code: err.code,
})
return
}

this.logger.info('Message successfully relayed to Layer 1!')
}

private async _relayMultiMessageToL1(
messages: Array<BatchMessage>
): Promise<any> {

const result = await this.state.OVM_L1MultiMessageRelayer.connect(
this.options.l1Wallet
).batchRelayMessages(messages, {
gasLimit: this.options.relayGasLimit,
})
const sendTxAndWaitForReceipt = async (gasPrice): Promise<any> => {
const txResponse = await this.state.OVM_L1MultiMessageRelayer.connect(
this.options.l1Wallet
).batchRelayMessages(messages, { gasPrice })
return this.options.l1Wallet.provider.waitForTransaction(
txResponse.hash,
this.options.numConfirmations
)
}

this.logger.info('Relay message transaction sent', {
transactionHash: result,
})
const minGasPrice = await this._getGasPriceInGwei(this.options.l1Wallet)

let receipt

try {
receipt = await result.wait()

this.logger.info('Relay messages included in block', {
transactionHash: receipt.transactionHash,
blockNumber: receipt.blockNumber,
gasUsed: receipt.gasUsed.toString(),
confirmations: receipt.confirmations,
status: receipt.status,
receipt = await ynatm.send({
sendTransactionFunction: sendTxAndWaitForReceipt,
minGasPrice: ynatm.toGwei(minGasPrice),
maxGasPrice: ynatm.toGwei(this.options.maxGasPriceInGwei),
gasPriceScalingFunction: ynatm.LINEAR(this.options.gasRetryIncrement),
delay: this.options.resubmissionTimeout,
})

this.logger.info('Relay message transaction sent', { receipt })
} catch (err) {
this.logger.error('Relay attempt failed, skipping.', {
message: err.toString(),
Expand All @@ -707,10 +722,17 @@ export class MessageRelayerService extends BaseService<MessageRelayerOptions> {
})
return
}

this.logger.info('Message Batch successfully relayed to Layer 1!')
return receipt
}

private async _getGasPriceInGwei(signer): Promise<number> {
return parseInt(
ethers.utils.formatUnits(await signer.getGasPrice(), 'gwei'), 10
)
}

private async _getFilter(): Promise<void> {
try {
if (this.options.filterEndpoint) {
Expand Down
1 change: 1 addition & 0 deletions packages/omgx/message-relayer-fast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@eth-optimism/common-ts": "^0.1.0",
"@eth-optimism/core-utils": "^0.5.1",
"@eth-optimism/hardhat-ovm": "^0.0.2",
"@eth-optimism/ynatm": "^0.2.2",
"@openzeppelin/contracts": "3.4.1",
"bcfg": "^0.1.6",
"chalk": "^4.1.1",
Expand Down
21 changes: 21 additions & 0 deletions packages/omgx/message-relayer-fast/src/exec/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ const main = async () => {
'filter-polling-interval',
parseInt(env.FILTER_POLLING_INTERVAL, 10) || 60000
)
const MAX_GAS_PRICE_IN_GWEI = config.uint(
'max-gas-price-in-gwei',
parseInt(env.MAX_GAS_PRICE_IN_GWEI, 10) || 100
)
const GAS_RETRY_INCREMENT = config.uint(
'gas-retry-increment',
parseInt(env.GAS_RETRY_INCREMENT, 10) || 5
)
const RESUBMISSION_TIMEOUT = config.uint(
'resubmission-timeout',
parseInt(env.RESUBMISSION_TIMEOUT, 10) || 60
)
const NUM_CONFIRMATIONS = config.uint(
'num-confirmations',
parseInt(env.NUM_CONFIRMATIONS, 10) || 0
)

if (!ADDRESS_MANAGER_ADDRESS) {
throw new Error('Must pass ADDRESS_MANAGER_ADDRESS')
Expand Down Expand Up @@ -106,6 +122,11 @@ const main = async () => {
getLogsInterval: GET_LOGS_INTERVAL,
filterEndpoint: FILTER_ENDPOINT,
filterPollingInterval: FILTER_POLLING_INTERVAL,
// gas price
maxGasPriceInGwei: MAX_GAS_PRICE_IN_GWEI,
gasRetryIncrement: GAS_RETRY_INCREMENT,
numConfirmations: NUM_CONFIRMATIONS,
resubmissionTimeout: RESUBMISSION_TIMEOUT * 1000,
})

await service.start()
Expand Down
Loading

0 comments on commit bf8eee6

Please sign in to comment.