Fix blobs (#2762)
* add blobGasUsed calculation * enable old tests * add blob tests in kurtosis * add blobGasUsed validation * revert * introduce blobs in test * fix: kzg setup * prevent regression
This commit is contained in:
parent
070f117d3c
commit
c9f97e6cd6
|
@ -20,11 +20,12 @@ additional_services:
|
|||
- tx_spammer
|
||||
- assertoor
|
||||
- beacon_metrics_gazer
|
||||
- blob_spammer
|
||||
mev_type: null
|
||||
assertoor_params:
|
||||
image: "ethpandaops/assertoor:latest"
|
||||
run_stability_check: false
|
||||
run_block_proposal_check: true
|
||||
run_transaction_test: true
|
||||
run_blob_transaction_test: false
|
||||
run_blob_transaction_test: true
|
||||
run_opcodes_transaction_test: true
|
||||
|
|
|
@ -204,6 +204,11 @@ proc vmExecGrabItem(pst: var TxPacker; item: TxItemRef): GrabResult
|
|||
return ContinueWithNextAccount
|
||||
pst.numBlobPerBlock += item.tx.versionedHashes.len
|
||||
|
||||
let blobGasUsed = item.tx.getTotalBlobGas
|
||||
if vmState.blobGasUsed + blobGasUsed > MAX_BLOB_GAS_PER_BLOCK:
|
||||
return ContinueWithNextAccount
|
||||
vmState.blobGasUsed += blobGasUsed
|
||||
|
||||
# Verify we have enough gas in gasPool
|
||||
if vmState.gasPool < item.tx.gasLimit:
|
||||
# skip this transaction and
|
||||
|
|
|
@ -9,11 +9,14 @@
|
|||
# according to those terms.
|
||||
|
||||
import
|
||||
std/tables,
|
||||
std/[tables, math],
|
||||
eth/common/keys,
|
||||
results, unittest2,
|
||||
results,
|
||||
unittest2,
|
||||
../hive_integration/nodocker/engine/tx_sender,
|
||||
../nimbus/db/ledger,
|
||||
../nimbus/core/chain,
|
||||
../nimbus/core/eip4844,
|
||||
../nimbus/[config, transaction, constants],
|
||||
../nimbus/core/tx_pool,
|
||||
../nimbus/core/tx_pool/tx_desc,
|
||||
|
@ -29,8 +32,7 @@ const
|
|||
repoDir = [".", "customgenesis"]
|
||||
genesisFile = "merge.json"
|
||||
|
||||
type
|
||||
TestEnv = object
|
||||
type TestEnv = object
|
||||
nonce: uint64
|
||||
chainId: ChainId
|
||||
vaultKey: PrivateKey
|
||||
|
@ -59,8 +61,8 @@ proc privKey(keyHex: string): PrivateKey =
|
|||
kRes.get()
|
||||
|
||||
func makeTx(
|
||||
t: var TestEnv, recipient: Address, amount: UInt256,
|
||||
payload: openArray[byte] = []): Transaction =
|
||||
t: var TestEnv, recipient: Address, amount: UInt256, payload: openArray[byte] = []
|
||||
): Transaction =
|
||||
const
|
||||
gasLimit = 75000.GasInt
|
||||
gasPrice = 30.gwei
|
||||
|
@ -73,28 +75,43 @@ func makeTx(
|
|||
gasLimit: gasLimit,
|
||||
to: Opt.some(recipient),
|
||||
value: amount,
|
||||
payload : @payload
|
||||
payload: @payload,
|
||||
)
|
||||
|
||||
inc t.nonce
|
||||
signTransaction(tx, t.vaultKey, eip155 = true)
|
||||
|
||||
func signTxWithNonce(
|
||||
t: TestEnv, tx: Transaction, nonce: AccountNonce): Transaction =
|
||||
proc createPooledTransactionWithBlob(
|
||||
t: var TestEnv, recipient: Address, amount: UInt256
|
||||
): PooledTransaction =
|
||||
# Create the transaction
|
||||
let
|
||||
tc = BlobTx(
|
||||
recipient: Opt.some(recipient),
|
||||
gasLimit: 100000.GasInt,
|
||||
gasTip: GasInt(10 ^ 9),
|
||||
gasFee: GasInt(10 ^ 9),
|
||||
blobGasFee: u256(1),
|
||||
blobCount: 1,
|
||||
blobID: 1,
|
||||
)
|
||||
params = MakeTxParams(chainId: t.chainId, key: t.vaultKey, nonce: t.nonce)
|
||||
|
||||
inc t.nonce
|
||||
params.makeTx(tc)
|
||||
|
||||
func signTxWithNonce(t: TestEnv, tx: Transaction, nonce: AccountNonce): Transaction =
|
||||
var tx = tx
|
||||
tx.nonce = nonce
|
||||
signTransaction(tx, t.vaultKey, eip155 = true)
|
||||
|
||||
proc initEnv(envFork: HardFork): TestEnv =
|
||||
var
|
||||
conf = makeConfig(@[
|
||||
"--custom-network:" & genesisFile.findFilePath(baseDir,repoDir).value
|
||||
])
|
||||
|
||||
conf.networkParams.genesis.alloc[recipient] = GenesisAccount(
|
||||
code: contractCode
|
||||
var conf = makeConfig(
|
||||
@["--custom-network:" & genesisFile.findFilePath(baseDir, repoDir).value]
|
||||
)
|
||||
|
||||
conf.networkParams.genesis.alloc[recipient] = GenesisAccount(code: contractCode)
|
||||
|
||||
if envFork >= MergeFork:
|
||||
conf.networkParams.config.mergeForkBlock = Opt.some(0'u64)
|
||||
conf.networkParams.config.terminalTotalDifficulty = Opt.some(100.u256)
|
||||
|
@ -106,11 +123,8 @@ proc initEnv(envFork: HardFork): TestEnv =
|
|||
conf.networkParams.config.cancunTime = Opt.some(0.EthTime)
|
||||
|
||||
let
|
||||
com = CommonRef.new(
|
||||
newCoreDbRef DefaultDbMemory,
|
||||
conf.networkId,
|
||||
conf.networkParams
|
||||
)
|
||||
com =
|
||||
CommonRef.new(newCoreDbRef DefaultDbMemory, conf.networkId, conf.networkParams)
|
||||
chain = newForkedChain(com, com.genesisHeader)
|
||||
|
||||
result = TestEnv(
|
||||
|
@ -120,7 +134,7 @@ proc initEnv(envFork: HardFork): TestEnv =
|
|||
xp: TxPoolRef.new(com),
|
||||
vaultKey: privKey(vaultKeyHex),
|
||||
chainId: conf.networkParams.config.chainId,
|
||||
nonce: 0'u64
|
||||
nonce: 0'u64,
|
||||
)
|
||||
|
||||
const
|
||||
|
@ -129,8 +143,7 @@ const
|
|||
prevRandao = Bytes32 EMPTY_UNCLE_HASH # it can be any valid hash
|
||||
|
||||
proc runTxPoolPosTest() =
|
||||
var
|
||||
env = initEnv(MergeFork)
|
||||
var env = initEnv(MergeFork)
|
||||
|
||||
var
|
||||
tx = env.makeTx(recipient, amount)
|
||||
|
@ -159,10 +172,7 @@ proc runTxPoolPosTest() =
|
|||
return
|
||||
|
||||
blk = r.get.blk
|
||||
body = BlockBody(
|
||||
transactions: blk.txs,
|
||||
uncles: blk.uncles
|
||||
)
|
||||
body = BlockBody(transactions: blk.txs, uncles: blk.uncles)
|
||||
check blk.txs.len == 1
|
||||
|
||||
test "PoS persistBlocks":
|
||||
|
@ -182,12 +192,11 @@ proc runTxPoolPosTest() =
|
|||
check not bal.isZero
|
||||
|
||||
proc runTxPoolBlobhashTest() =
|
||||
var
|
||||
env = initEnv(Cancun)
|
||||
var env = initEnv(Cancun)
|
||||
|
||||
var
|
||||
tx1 = env.makeTx(recipient, amount)
|
||||
tx2 = env.makeTx(recipient, amount)
|
||||
tx1 = env.createPooledTransactionWithBlob(recipient, amount)
|
||||
tx2 = env.createPooledTransactionWithBlob(recipient, amount)
|
||||
xp = env.xp
|
||||
com = env.com
|
||||
chain = env.chain
|
||||
|
@ -196,8 +205,8 @@ proc runTxPoolBlobhashTest() =
|
|||
|
||||
suite "Test TxPool with blobhash block":
|
||||
test "TxPool jobCommit":
|
||||
xp.add(PooledTransaction(tx: tx1))
|
||||
xp.add(PooledTransaction(tx: tx2))
|
||||
xp.add(tx1)
|
||||
xp.add(tx2)
|
||||
check xp.nItems.total == 2
|
||||
|
||||
test "TxPool ethBlock":
|
||||
|
@ -216,17 +225,20 @@ proc runTxPoolBlobhashTest() =
|
|||
body = BlockBody(
|
||||
transactions: blk.txs,
|
||||
uncles: blk.uncles,
|
||||
withdrawals: Opt.some(newSeq[Withdrawal]())
|
||||
withdrawals: Opt.some(newSeq[Withdrawal]()),
|
||||
)
|
||||
check blk.txs.len == 2
|
||||
|
||||
let
|
||||
gasUsed1 = xp.vmState.receipts[0].cumulativeGasUsed
|
||||
gasUsed2 = xp.vmState.receipts[1].cumulativeGasUsed - gasUsed1
|
||||
blockValue = gasUsed1.u256 * tx1.effectiveGasTip(blk.header.baseFeePerGas).u256 +
|
||||
gasUsed2.u256 * tx2.effectiveGasTip(blk.header.baseFeePerGas).u256
|
||||
totalBlobGasUsed = tx1.tx.getTotalBlobGas + tx2.tx.getTotalBlobGas
|
||||
blockValue =
|
||||
gasUsed1.u256 * tx1.tx.effectiveGasTip(blk.header.baseFeePerGas).u256 +
|
||||
gasUsed2.u256 * tx2.tx.effectiveGasTip(blk.header.baseFeePerGas).u256
|
||||
|
||||
check blockValue == bundle.blockValue
|
||||
check totalBlobGasUsed == blk.header.blobGasUsed.get()
|
||||
|
||||
test "Blobhash persistBlocks":
|
||||
let rr = chain.importBlock(EthBlock.init(blk.header, body))
|
||||
|
@ -276,12 +288,12 @@ proc runTxHeadDelta(noisy = true) =
|
|||
|
||||
block:
|
||||
for n in 0 ..< numBlocks:
|
||||
|
||||
for tn in 0 ..< txPerblock:
|
||||
let tx = env.makeTx(recipient, amount)
|
||||
xp.add(PooledTransaction(tx: tx))
|
||||
|
||||
noisy.say "***", "txDB",
|
||||
noisy.say "***",
|
||||
"txDB",
|
||||
&" n={n}",
|
||||
# pending/staged/packed : total/disposed
|
||||
&" stats={xp.nItems.pp}"
|
||||
|
@ -298,9 +310,7 @@ proc runTxHeadDelta(noisy = true) =
|
|||
return
|
||||
|
||||
let blk = r.get.blk
|
||||
let body = BlockBody(
|
||||
transactions: blk.txs,
|
||||
uncles: blk.uncles)
|
||||
let body = BlockBody(transactions: blk.txs, uncles: blk.uncles)
|
||||
|
||||
# Commit to block chain
|
||||
check chain.importBlock(EthBlock.init(blk.header, body)).isOk
|
||||
|
@ -383,8 +393,9 @@ proc runGetBlockBodyTest() =
|
|||
check env.chain.forkChoice(currHash, currHash).isOk
|
||||
|
||||
proc txPool2Main*() =
|
||||
const
|
||||
noisy = defined(debug)
|
||||
const noisy = defined(debug)
|
||||
|
||||
assert loadKzgTrustedSetup().isOk, "Failed to load KZG trusted setup"
|
||||
|
||||
setErrorLevel() # mute logger
|
||||
|
||||
|
|
Loading…
Reference in New Issue