Workaround for 0 gas price estimation (#2180)

* Workaround for 0 gas price estimation

The transaction spammer from Kurtosis estimates the gas price of its
transactions using 'eth_gasPrice'. Our implementation returns 0 when
no transactions have been executed yet, not taking into account the
EIP-1559 block base fee. Force a hardcoded minimum for now to unstuck.

* Adjust tests to cover new minimum gas fee

* Skip gas price test
This commit is contained in:
Etan Kissling 2024-05-28 08:36:38 +02:00 committed by GitHub
parent ca60b13e6a
commit b7a7745e24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 6 deletions

View File

@ -80,6 +80,16 @@ proc calculateMedianGasPrice*(chain: CoreDbRef): GasInt
else:
result = prices[middle]
# TODO: This should properly incorporate the base fee in the block data,
# and recommend a gas fee that likely gets the block to confirm.
# This also has to work on Genesis where no prior transaction data exists.
# For compatibility with `kurtosis-tech/ethereum-package`, set this to a
# sane minimum for compatibility to unblock testing.
# Note: When this is fixed, update `tests/graphql/queries.toml` and
# re-enable the "query.gasPrice" test case (remove `skip = true`).
const minGasPrice = 30_000_000_000.GasInt
result = max(result, minGasPrice)
proc unsignedTx*(tx: TransactionArgs, chain: CoreDbRef, defaultNonce: AccountNonce): Transaction
{.gcsafe, raises: [CatchableError].} =
if tx.to.isSome:

View File

@ -333,6 +333,7 @@
[[units]]
name = "query.gasPrice"
skip = true
code = """
{
gasPrice

View File

@ -113,8 +113,8 @@ proc setupEnv(com: CommonRef, signer, ks2: EthAddress, ctx: EthContext): TestEnv
com = com)
vmState.stateDB.setCode(ks2, code)
vmState.stateDB.addBalance(signer, 9_000_000_000.u256)
vmState.stateDB.addBalance(
signer, 1.u256 * 1_000_000_000.u256 * 1_000_000_000.u256) # 1 ETH
# Test data created for eth_getProof tests
let regularAcc = ethAddr("0x0000000000000000000000000000000000000001")
@ -136,7 +136,7 @@ proc setupEnv(com: CommonRef, signer, ks2: EthAddress, ctx: EthContext): TestEnv
unsignedTx1 = Transaction(
txType : TxLegacy,
nonce : 0,
gasPrice: 1_100,
gasPrice: 30_000_000_000,
gasLimit: 70_000,
value : 1.u256,
to : some(zeroAddress)
@ -144,7 +144,7 @@ proc setupEnv(com: CommonRef, signer, ks2: EthAddress, ctx: EthContext): TestEnv
unsignedTx2 = Transaction(
txType : TxLegacy,
nonce : 1,
gasPrice: 1_200,
gasPrice: 30_000_000_100,
gasLimit: 70_000,
value : 2.u256,
to : some(zeroAddress)
@ -160,7 +160,7 @@ proc setupEnv(com: CommonRef, signer, ks2: EthAddress, ctx: EthContext): TestEnv
for txIndex, tx in txs:
let sender = tx.getSender()
let rc = vmState.processTransaction(tx, sender, vmHeader)
doAssert(rc.isOk, "Invalid transaction")
doAssert(rc.isOk, "Invalid transaction: " & rc.error)
vmState.receipts[txIndex] = makeReceipt(vmState, tx.txType)
let
@ -314,7 +314,7 @@ proc rpcMain*() =
test "eth_gasPrice":
let res = await client.eth_gasPrice()
check res == w3Qty(0x47E'u64)
check res == w3Qty(30_000_000_050) # Avg of `unsignedTx1` / `unsignedTx2`
test "eth_accounts":
let res = await client.eth_accounts()