Skip to content
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

feat: block gas limit should be 30_000_000 #2938

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/relay/src/lib/clients/sdkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export class SDKClient {
}

const tinybarsGasFee = await this.getTinyBarGasFee('eth_sendRawTransaction', requestId);
ethereumTransaction.setMaxTransactionFee(Hbar.fromTinybars(Math.floor(tinybarsGasFee * constants.BLOCK_GAS_LIMIT)));
ethereumTransaction.setMaxTransactionFee(Hbar.fromTinybars(Math.floor(tinybarsGasFee * constants.MAX_GAS_PER_SEC)));

return {
fileId,
Expand Down
3 changes: 2 additions & 1 deletion packages/relay/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export default {
DEFAULT_FEE_HISTORY_MAX_RESULTS: 10,
ORDER,

BLOCK_GAS_LIMIT: 15_000_000,
BLOCK_GAS_LIMIT: 30_000_000,
MAX_GAS_PER_SEC: 15_000_000,
CONTRACT_CALL_GAS_LIMIT: 50_000_000,
ISTANBUL_TX_DATA_NON_ZERO_COST: 16,
TX_BASE_COST: 21_000,
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/lib/errors/JsonRpcError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const predefined = {
GAS_LIMIT_TOO_HIGH: (gasLimit, maxGas) =>
new JsonRpcError({
code: -32005,
message: `Transaction gas limit '${gasLimit}' exceeds block gas limit '${maxGas}'`,
message: `Transaction gas limit '${gasLimit}' exceeds max gas per sec limit '${maxGas}'`,
}),
GAS_LIMIT_TOO_LOW: (gasLimit, requiredGas) =>
new JsonRpcError({
Expand Down
9 changes: 4 additions & 5 deletions packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2179,11 +2179,11 @@ export class EthImpl implements Eth {
// Gas limit for `eth_call` is 50_000_000, but the current Hedera network limit is 15_000_000
// With values over the gas limit, the call will fail with BUSY error so we cap it at 15_000_000
const gas = Number.parseInt(gasString);
if (gas > constants.BLOCK_GAS_LIMIT) {
if (gas > constants.MAX_GAS_PER_SEC) {
this.logger.trace(
`${requestIdPrefix} eth_call gas amount (${gas}) exceeds network limit, capping gas to ${constants.BLOCK_GAS_LIMIT}`,
`${requestIdPrefix} eth_call gas amount (${gas}) exceeds network limit, capping gas to ${constants.MAX_GAS_PER_SEC}`,
);
return constants.BLOCK_GAS_LIMIT;
return constants.MAX_GAS_PER_SEC;
}

return gas;
Expand Down Expand Up @@ -2241,7 +2241,6 @@ export class EthImpl implements Eth {
undefined,
requestIdPrefix,
);
const maxGasLimit = constants.BLOCK_GAS_LIMIT;
const gasUsed = blockResponse.gas_used;
const params = { timestamp: timestampRangeParams };

Expand Down Expand Up @@ -2285,7 +2284,7 @@ export class EthImpl implements Eth {
baseFeePerGas: await this.gasPrice(requestIdPrefix),
difficulty: EthImpl.zeroHex,
extraData: EthImpl.emptyHex,
gasLimit: numberTo0x(maxGasLimit),
gasLimit: numberTo0x(constants.BLOCK_GAS_LIMIT),
gasUsed: numberTo0x(gasUsed),
hash: blockHash,
logsBloom: blockResponse.logs_bloom === EthImpl.emptyHex ? EthImpl.emptyBloom : blockResponse.logs_bloom,
Expand Down
6 changes: 3 additions & 3 deletions packages/relay/src/lib/precheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ export class Precheck {

const intrinsicGasCost = Precheck.transactionIntrinsicGasCost(tx.data);

if (gasLimit > constants.BLOCK_GAS_LIMIT) {
if (gasLimit > constants.MAX_GAS_PER_SEC) {
this.logger.trace(
`${requestIdPrefix} ${failBaseLog} Gas Limit was too high: %s, block gas limit: %s`,
JSON.stringify(tx),
gasLimit,
constants.BLOCK_GAS_LIMIT,
constants.MAX_GAS_PER_SEC,
);
throw predefined.GAS_LIMIT_TOO_HIGH(gasLimit, constants.BLOCK_GAS_LIMIT);
throw predefined.GAS_LIMIT_TOO_HIGH(gasLimit, constants.MAX_GAS_PER_SEC);
} else if (gasLimit < intrinsicGasCost) {
this.logger.trace(
`${requestIdPrefix} ${failBaseLog} Gas Limit was too low: %s, intrinsic gas cost: %s`,
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/tests/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default class RelayAssertions {
};

static verifyBlockConstants = (block: Block) => {
expect(block.gasLimit).equal(numberTo0x(15000000));
expect(block.gasLimit).equal(numberTo0x(constants.BLOCK_GAS_LIMIT));
expect(block.baseFeePerGas).equal(BASE_FEE_PER_GAS_DEFAULT);
expect(block.difficulty).equal(EthImpl.zeroHex);
expect(block.extraData).equal(EthImpl.emptyHex);
Expand Down
13 changes: 13 additions & 0 deletions packages/relay/tests/lib/eth/eth_call.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
} from './eth-config';
import { JsonRpcError, predefined } from '../../../src/lib/errors/JsonRpcError';
import RelayAssertions from '../../assertions';
import constants from '../../../src/lib/constants';
import {
defaultCallData,
defaultContractResults,
Expand Down Expand Up @@ -540,6 +541,18 @@ describe('@ethCall Eth Call spec', async function () {
expect(result).to.equal('0x00');
});

it('eth_call with gas capping', async function () {
const callData = {
...defaultCallData,
gas: 25_000_000,
};
await mockContractCall({ ...callData, gas: constants.MAX_GAS_PER_SEC, block: 'latest' }, false, 200, {
result: '0x00',
});
const res = await ethImpl.call(callData, 'latest');
expect(res).to.equal('0x00');
});

it('eth_call with all fields and value', async function () {
const callData = {
...defaultCallData,
Expand Down
4 changes: 2 additions & 2 deletions packages/relay/tests/lib/precheck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ describe('Precheck', async function () {
const signed = await signTransaction(tx);
const parsedTx = ethers.Transaction.from(signed);
const message =
gasLimit > constants.BLOCK_GAS_LIMIT
? `Transaction gas limit '${gasLimit}' exceeds block gas limit '${constants.BLOCK_GAS_LIMIT}'`
gasLimit > constants.MAX_GAS_PER_SEC
? `Transaction gas limit '${gasLimit}' exceeds max gas per sec limit '${constants.MAX_GAS_PER_SEC}'`
: `Transaction gas limit provided '${gasLimit}' is insufficient of intrinsic gas required `;
try {
await precheck.gasLimit(parsedTx);
Expand Down
14 changes: 7 additions & 7 deletions packages/server/tests/acceptance/rpc_batch1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
nonce: await relay.getAccountNonce(accounts[2].address, requestId),
maxPriorityFeePerGas: gasPrice,
maxFeePerGas: gasPrice,
gasLimit: Constants.BLOCK_GAS_LIMIT,
gasLimit: Constants.MAX_GAS_PER_SEC,
data: '0x' + '00'.repeat(40000),
};

Expand All @@ -1355,7 +1355,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
BigInt(balanceBefore - balanceAfter) / BigInt(Constants.TINYBAR_TO_WEIBAR_COEF) / BigInt(100_000_000);
expect(Number(diffInHbars)).to.be.greaterThan(2);
expect(Number(diffInHbars)).to.be.lessThan(
(gasPrice * Constants.BLOCK_GAS_LIMIT) / Constants.TINYBAR_TO_WEIBAR_COEF / 100_000_000,
(gasPrice * Constants.MAX_GAS_PER_SEC) / Constants.TINYBAR_TO_WEIBAR_COEF / 100_000_000,
);
});

Expand All @@ -1367,7 +1367,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
nonce: await relay.getAccountNonce(accounts[2].address, requestId),
maxPriorityFeePerGas: gasPrice,
maxFeePerGas: gasPrice,
gasLimit: Constants.BLOCK_GAS_LIMIT,
gasLimit: Constants.MAX_GAS_PER_SEC,
data: '0x' + '00'.repeat(60000),
};
const signedTx = await accounts[2].wallet.signTransaction(transaction);
Expand Down Expand Up @@ -1401,7 +1401,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
};

const signedTx = await accounts[2].wallet.signTransaction(transaction);
const error = predefined.GAS_LIMIT_TOO_LOW(gasLimit, Constants.BLOCK_GAS_LIMIT);
const error = predefined.GAS_LIMIT_TOO_LOW(gasLimit, Constants.MAX_GAS_PER_SEC);

await Assertions.assertPredefinedRpcError(error, sendRawTransaction, false, relay, [signedTx, requestId]);
});
Expand All @@ -1417,7 +1417,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
};

const signedTx = await accounts[2].wallet.signTransaction(transaction);
const error = predefined.GAS_LIMIT_TOO_HIGH(gasLimit, Constants.BLOCK_GAS_LIMIT);
const error = predefined.GAS_LIMIT_TOO_HIGH(gasLimit, Constants.MAX_GAS_PER_SEC);

await Assertions.assertPredefinedRpcError(error, sendRawTransaction, false, relay, [signedTx, requestId]);
});
Expand All @@ -1431,7 +1431,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
gasLimit: gasLimit,
};
const signedTx = await accounts[2].wallet.signTransaction(transaction);
const error = predefined.GAS_LIMIT_TOO_LOW(gasLimit, Constants.BLOCK_GAS_LIMIT);
const error = predefined.GAS_LIMIT_TOO_LOW(gasLimit, Constants.MAX_GAS_PER_SEC);

await Assertions.assertPredefinedRpcError(error, sendRawTransaction, false, relay, [signedTx, requestId]);
});
Expand All @@ -1445,7 +1445,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
gasLimit: gasLimit,
};
const signedTx = await accounts[2].wallet.signTransaction(transaction);
const error = predefined.GAS_LIMIT_TOO_HIGH(gasLimit, Constants.BLOCK_GAS_LIMIT);
const error = predefined.GAS_LIMIT_TOO_HIGH(gasLimit, Constants.MAX_GAS_PER_SEC);

await Assertions.assertPredefinedRpcError(error, sendRawTransaction, false, relay, [signedTx, requestId]);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/server/tests/helpers/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class Assertions {
static defaultGasPrice = 710_000_000_000;
static datedGasPrice = 570_000_000_000;
static updatedGasPrice = 640_000_000_000;
static maxBlockGasLimit = 15_000_000;
static maxBlockGasLimit = 30_000_000;
static defaultGasUsed = 0.5;

static gasPriceDeviation = parseFloat(process.env.TEST_GAS_PRICE_DEVIATION ?? '0.2');
Expand Down
Loading