Skip to content

Commit

Permalink
OG-1020: fix some issues in 'calculateDryRunCallGasLimit' AND set ver…
Browse files Browse the repository at this point in the history
…sion to 3.0.0-beta.5

* OG-1020: some issues in 'calculateDryRunCallGasLimit'

1. Take input gas price instead of re-querying fee history

2. Divide by RelayHub pctRelayFeeDev to avoid hitting false 'paymaster
balance too low' error

3. Take 75% to leave some slack for base fee and calldata

4. Console.log what is going on there to simplify debugging

* v3.0.0-beta.5
  • Loading branch information
forshtat authored Mar 15, 2023
1 parent 734a393 commit 3ce127e
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"npmClient": "yarn",
"useWorkspaces": true
}
12 changes: 6 additions & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opengsn/cli",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"license": "GPL-3.0-only",
"main": "dist/index.js",
"bin": {
Expand All @@ -26,11 +26,11 @@
"dependencies": {
"@ethereumjs/tx": "^3.2.0",
"@ethersproject/providers": "^5.7.2",
"@opengsn/common": "^3.0.0-beta.3",
"@opengsn/contracts": "^3.0.0-beta.3",
"@opengsn/logger": "^3.0.0-beta.3",
"@opengsn/provider": "^3.0.0-beta.3",
"@opengsn/relay": "^3.0.0-beta.3",
"@opengsn/common": "^3.0.0-beta.5",
"@opengsn/contracts": "^3.0.0-beta.5",
"@opengsn/logger": "^3.0.0-beta.5",
"@opengsn/provider": "^3.0.0-beta.5",
"@opengsn/relay": "^3.0.0-beta.5",
"@truffle/hdwallet-provider": "^2.0.10",
"@types/asciichart": "^1.5.4",
"@types/clear": "^0.1.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opengsn/common",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"license": "Apache-2.0",
"main": "dist/index.js",
"scripts": {
Expand All @@ -25,7 +25,7 @@
"@ethersproject/networks": "^5.7.1",
"@ethersproject/providers": "^5.7.2",
"@metamask/eth-sig-util": "^4.0.1",
"@opengsn/contracts": "^3.0.0-beta.3",
"@opengsn/contracts": "^3.0.0-beta.5",
"@types/bn.js": "^5.1.0",
"@types/semver": "^7.3.4",
"axios": "^0.21.1",
Expand Down
28 changes: 22 additions & 6 deletions packages/common/src/ContractInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1312,21 +1312,37 @@ calculateTransactionMaxPossibleGas: result: ${result}
): Promise<BN> {
const paymasterBalance = await this.hubBalanceOf(paymasterAddress)
let workerBalance = constants.MAX_UINT256 // skipping worker address balance check in dry-run
let workerBalanceMessage = ''
if (!isSameAddress(workerAddress, constants.DRY_RUN_ADDRESS)) {
const workerBalanceStr = await this.getBalance(workerAddress, 'pending')
workerBalance = toBN(workerBalanceStr)
}
if (maxFeePerGas.eqn(0)) {
// using base fee override to avoid division by zero
maxFeePerGas = toBN((await this.getGasFees(5, 50)).baseFeePerGas)
workerBalanceMessage = `Worker balance: ${workerBalance.toString()}\n`
}
const smallerBalance = BN.min(paymasterBalance, workerBalance)
const pctRelayFeeDev = toBN(this.relayHubConfiguration.pctRelayFee.toString()).addn(100)
const smallerBalanceGasLimit = smallerBalance.div(maxFeePerGas)
.muln(9).divn(10) // hard-coded to use 90% of available worker/paymaster balance
.muln(100)
.div(pctRelayFeeDev)
.muln(3).divn(4) // hard-coded to use 75% of available worker/paymaster balance
const blockGasLimitNum = await this.getBlockGasLimit()
const blockGasLimit = toBN(blockGasLimitNum)
.muln(3).divn(4) // hard-coded to use 75% of available block gas limit
return BN.max(minViewableGasLimit, BN.min(maxViewableGasLimit, BN.min(smallerBalanceGasLimit, blockGasLimit)))

const warningMessage = workerBalanceMessage +
`Paymaster balance: ${paymasterBalance.toString()}\n` +
`This is only enough for ${smallerBalanceGasLimit.toString()} gas for a view call at ${maxFeePerGas.toString()} per gas.\n` +
`Also, block gas limit is: ${blockGasLimit.toString()}\n`
if (smallerBalanceGasLimit.lt(minViewableGasLimit)) {
this.logger.warn(
warningMessage +
`Limiting the view call to minViewableGasLimit (${minViewableGasLimit.toString()}) but successful relaying is not likely.`)
return minViewableGasLimit
}
const minimalLimit = BN.min(maxViewableGasLimit, BN.min(smallerBalanceGasLimit, blockGasLimit))
if (minimalLimit.eq(smallerBalanceGasLimit)) {
this.logger.warn(warningMessage)
}
return minimalLimit
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@opengsn/contracts",
"license": "GPL-3.0-only",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"main": "types/truffle-contracts/index.d.ts",
"scripts": {
"solpp": "yarn --cwd=\"../..\" solpp",
Expand Down
6 changes: 3 additions & 3 deletions packages/deployer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opengsn/deployer",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"private": true,
"author": "Dror Tirosh",
"license": "MIT",
Expand All @@ -18,8 +18,8 @@
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
"@nomiclabs/hardhat-etherscan": "^2.1.8",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@opengsn/common": "^3.0.0-beta.3",
"@opengsn/provider": "^3.0.0-beta.3",
"@opengsn/common": "^3.0.0-beta.5",
"@opengsn/provider": "^3.0.0-beta.5",
"axios": "^0.27.2",
"chai": "^4.3.6",
"chalk": "^4.1.2",
Expand Down
14 changes: 7 additions & 7 deletions packages/dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opengsn/dev",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"license": "GPL-3.0-only",
"main": "dist/src/index.js",
"files": [
Expand All @@ -25,12 +25,12 @@
"rm-dist": "rm -rf tsconfig.tsbuildinfo dist build"
},
"dependencies": {
"@opengsn/cli": "^3.0.0-beta.3",
"@opengsn/common": "^3.0.0-beta.3",
"@opengsn/contracts": "^3.0.0-beta.3",
"@opengsn/logger": "^3.0.0-beta.3",
"@opengsn/provider": "^3.0.0-beta.3",
"@opengsn/relay": "^3.0.0-beta.3"
"@opengsn/cli": "^3.0.0-beta.5",
"@opengsn/common": "^3.0.0-beta.5",
"@opengsn/contracts": "^3.0.0-beta.5",
"@opengsn/logger": "^3.0.0-beta.5",
"@opengsn/provider": "^3.0.0-beta.5",
"@opengsn/relay": "^3.0.0-beta.5"
},
"devDependencies": {
"@ethereumjs/common": "^2.6.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opengsn/logger",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"license": "GPL-3.0-only",
"main": "dist/index.js",
"files": [
Expand All @@ -18,7 +18,7 @@
"rm-dist": "rm -rf tsconfig.tsbuildinfo dist build"
},
"dependencies": {
"@opengsn/common": "^3.0.0-beta.3",
"@opengsn/common": "^3.0.0-beta.5",
"loglevel": "^1.8.0",
"winston": "^3.3.3"
}
Expand Down
12 changes: 6 additions & 6 deletions packages/paymasters/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@opengsn/paymasters",
"license": "GPL-3.0-only",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"scripts": {
"truffle-compile": "truffle compile --compile-all",
"typechain-generate": "yarn truffle-compile && typechain --target truffle-v5 './build/contracts/**/*.json'",
Expand Down Expand Up @@ -30,10 +30,10 @@
},
"dependencies": {
"@metamask/eth-sig-util": "^4.0.1",
"@opengsn/common": "^3.0.0-beta.3",
"@opengsn/contracts": "^3.0.0-beta.3",
"@opengsn/dev": "^3.0.0-beta.3",
"@opengsn/provider": "^3.0.0-beta.3",
"@opengsn/common": "^3.0.0-beta.5",
"@opengsn/contracts": "^3.0.0-beta.5",
"@opengsn/dev": "^3.0.0-beta.5",
"@opengsn/provider": "^3.0.0-beta.5",
"@openzeppelin/contracts": "^4.2.0",
"@uniswap/v3-periphery": "^1.1.1",
"ethereumjs-util": "^7.1.0",
Expand All @@ -46,7 +46,7 @@
"devDependencies": {
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@opengsn/cli": "^3.0.0-beta.3",
"@opengsn/cli": "^3.0.0-beta.5",
"@openzeppelin/test-helpers": "^0.5.15",
"@types/chai-as-promised": "^7.1.3",
"@types/ethereumjs-util": "^6.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opengsn/provider",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"license": "Apache-2.0",
"main": "dist/index.js",
"scripts": {
Expand All @@ -24,7 +24,7 @@
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@metamask/eth-sig-util": "^4.0.1",
"@opengsn/common": "^3.0.0-beta.3",
"@opengsn/common": "^3.0.0-beta.5",
"abi-decoder": "^2.4.0",
"ethereumjs-util": "^7.1.0",
"ethereumjs-wallet": "^1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/provider/src/RelayClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ export class RelayClient {
const viewCallGasLimit = await this.dependencies.contractInteractor.calculateDryRunCallGasLimit(
relayRequest.relayData.paymaster,
relayWorkerAddress,
toBN(maxMaxFeePerGas),
toBN(relayRequest.relayData.maxFeePerGas),
toBN(this.config.maxViewableGasLimit),
toBN(this.config.minViewableGasLimit)
)
Expand Down
8 changes: 4 additions & 4 deletions packages/relay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opengsn/relay",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"license": "GPL-3.0-only",
"main": "dist/runServer.js",
"files": [
Expand All @@ -20,9 +20,9 @@
"dependencies": {
"@ethereumjs/tx": "^3.2.0",
"@ethersproject/providers": "^5.7.2",
"@opengsn/common": "^3.0.0-beta.3",
"@opengsn/contracts": "^3.0.0-beta.3",
"@opengsn/logger": "^3.0.0-beta.3",
"@opengsn/common": "^3.0.0-beta.5",
"@opengsn/contracts": "^3.0.0-beta.5",
"@opengsn/logger": "^3.0.0-beta.5",
"@seald-io/nedb": "^3.0.0",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
Expand Down

0 comments on commit 3ce127e

Please sign in to comment.