Skip to content

Commit

Permalink
client: test and update devnet 8 integration sims (#2934)
Browse files Browse the repository at this point in the history
* client: test and update devnet 8 integration sims

* Client test import fix

---------

Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com>
  • Loading branch information
g11tech and holgerd77 committed Aug 2, 2023
1 parent 05bc2b9 commit 6eb9532
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 85 deletions.
2 changes: 1 addition & 1 deletion packages/block/test/from-beacon-payload.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Common, Hardfork } from '@ethereumjs/common'
import { assert, describe, it } from 'vitest'

import * as shardingJson from '../../client/test/sim/configs/sharding.json'
import * as shardingJson from '../../client/test/sim/configs/4844-devnet.json'
import { Block, BlockHeader } from '../src/index.js'

import * as payload87335 from './testdata/payload-slot-87335.json'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -59,43 +59,47 @@ describe(`running txes on ${rpcUrl}`, async () => {
throw e
}

it('run blob transactions', async () => {
const nonceFetch = await client.request(
'eth_getTransactionCount',
[sender.toString(), 'latest'],
2.0
)
const nonce = Number(nonceFetch.result)
assert.ok(true, `fetched ${sender}'s nonce=${nonce} for blob txs`)
it(
'run blob transactions',
async () => {
const nonceFetch = await client.request(
'eth_getTransactionCount',
[sender.toString(), 'latest'],
2.0
)
const nonce = Number(nonceFetch.result)
assert.ok(true, `fetched ${sender}'s nonce=${nonce} for blob txs`)

const txns = await createBlobTxs(
numTxs - 1,
4096,
pkey,
nonce,
{
to: bytesToHex(randomBytes(20)),
chainId,
maxFeePerblobGas: BigInt(process.env.MAX_DATAFEE ?? 100000000n),
maxPriorityFeePerGas: BigInt(process.env.MAX_PRIORITY ?? 100000000n),
maxFeePerGas: BigInt(process.env.MAX_FEE ?? 1000000000n),
gasLimit: BigInt(process.env.GAS_LIMIT ?? 0xffffffn),
},
{ common }
)
const txHashes = []
for (const txn of txns) {
const res = await client.request('eth_sendRawTransaction', [txn], 2.0)
if (res.result === undefined) {
console.log('eth_sendRawTransaction returned invalid response', res)
assert.fail(`Unable to post all txs`)
break
const txns = await createBlobTxs(
numTxs - 1,
pkey,
nonce,
{
to: bytesToHex(randomBytes(20)),
chainId,
maxFeePerblobGas: BigInt(process.env.MAX_DATAFEE ?? 100000000n),
maxPriorityFeePerGas: BigInt(process.env.MAX_PRIORITY ?? 100000000n),
maxFeePerGas: BigInt(process.env.MAX_FEE ?? 1000000000n),
gasLimit: BigInt(process.env.GAS_LIMIT ?? 0xffffffn),
blobSize: Number(process.env.BLOB_SIZE ?? 4096),
},
{ common }
)
const txHashes = []
for (const txn of txns) {
const res = await client.request('eth_sendRawTransaction', [txn], 2.0)
if (res.result === undefined) {
console.log('eth_sendRawTransaction returned invalid response', res)
assert.fail(`Unable to post all txs`)
break
}
assert.ok(true, `posted tx with hash=${res.result}`)
txHashes.push(res.result)
}
assert.ok(true, `posted tx with hash=${res.result}`)
txHashes.push(res.result)
}
assert.ok(true, `posted txs=${txHashes.length}`)
})
assert.ok(true, `posted txs=${txHashes.length}`)
},
10 * 60_000
)

it('cleanup', async () => {
try {
Expand All @@ -104,5 +108,5 @@ describe(`running txes on ${rpcUrl}`, async () => {
} catch (e) {
assert.fail('could not terminate properly')
}
})
}, 60_000)
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Note: All commands should be run from the `client` package directory root (so so
## Running a local devnet

Step 1. To run a single EthereumJS client <> Lodestar CL client for testing, run the following command:
`NETWORK=sharding EXTRA_CL_PARAMS="--params.CAPELLA_FORK_EPOCH 0 --params.DENEB_FORK_EPOCH 0" LODE_IMAGE=g11tech/lodestar:blobs-2467 DATADIR=path/to/your/data/directory test/sim/./single-run.sh`
`NETWORK=sharding EXTRA_CL_PARAMS="--params.CAPELLA_FORK_EPOCH 0 --params.DENEB_FORK_EPOCH 0" LODE_IMAGE=g11tech/lodestar:36-7b0e9f DATADIR=path/to/your/data/directory test/sim/./single-run.sh`

Step 2. (Optional) To run a second EthereumJS <> Lodestar pair, use this command:
`MULTIPEER=syncpeer NETWORK=sharding EXTRA_CL_PARAMS="--params.CAPELLA_FORK_EPOCH 0 --params.DENEB_FORK_EPOCH 0" LODE_IMAGE=g11tech/lodestar:blobs-2467 DATADIR=path/to/your/data/directory test/sim/./single-run.sh`
`MULTIPEER=syncpeer NETWORK=sharding EXTRA_CL_PARAMS="--params.CAPELLA_FORK_EPOCH 0 --params.DENEB_FORK_EPOCH 0" LODE_IMAGE=g11tech/lodestar:36-7b0e9f DATADIR=path/to/your/data/directory test/sim/./single-run.sh`

Step 3. To send a single blob transaction to the network, you may just run spec test:
`EXTERNAL_RUN=true npm run tape -- test/sim/sharding.spec.ts`
`EXTERNAL_RUN=true npx vitest test/sim/sharding.spec.ts`

OR, you can use the `txGenerator.ts` script as follows:

Expand All @@ -25,10 +25,10 @@ You don't need to externally start the nodes, the sim tests will do all that for

Run Step 1 & 3 together:

`LODE_IMAGE=g11tech/lodestar:blobs-2467 DATADIR=path/to/your/data/directory npm run tape -- test/sim/sharding.spec.ts`
`LODE_IMAGE=g11tech/lodestar:36-7b0e9f DATADIR=path/to/your/data/directory npx vitest test/sim/sharding.spec.ts`

### Run Step 1, 2 & 3 together

`WITH_PEER=syncpeer LODE_IMAGE=g11tech/lodestar:blobs-2467 DATADIR=path/to/your/data/directory npm run tape -- test/sim/sharding.spec.ts`
`WITH_PEER=syncpeer LODE_IMAGE=g11tech/lodestar:36-7b0e9f DATADIR=path/to/your/data/directory npx vitest test/sim/sharding.spec.ts`

Note, these tests are adapted from the specification tests contained in the [EIP-4844 Interop repo](https://github.com/Inphi/eip4844-interop)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const pkey = hexToBytes('0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3
const sender = bytesToHex(privateToAddress(pkey))
const client = Client.http({ port: 8545 })

const network = 'sharding'
const network = '4844-devnet'
const shardingJson = require(`./configs/${network}.json`)
const common = Common.fromGethGenesis(shardingJson, { chain: network })

Expand Down Expand Up @@ -98,46 +98,61 @@ describe('sharding/eip4844 hardfork tests', async () => {
bytesToHex(txResult.tx.kzgCommitments![0]),
'found expected blob commitments on CL'
)
})

it('blob gas fee market tests', async () => {
const txns = await createBlobTxs(
4,
4096,
pkey,
// Start with nonce of 1 since a tx previous has already been posted
1,
{
to: bytesToHex(randomBytes(20)),
chainId: 1,
maxFeePerblobGas: BigInt(1000) as any,
maxPriorityFeePerGas: BigInt(1) as any,
maxFeePerGas: '0xff' as any,
gasLimit: BigInt(1000000) as any,
},
{ common }
)
const txHashes = []
for (const txn of txns) {
const res = await client.request('eth_sendRawTransaction', [txn], 2.0)
txHashes.push(res.result)
}
let done = false
let txReceipt
while (!done) {
txReceipt = await client.request('eth_getTransactionReceipt', [txHashes[0]], 2.0)
if (txReceipt.result !== null) {
done = true
}, 60_000)

it(
'blob gas fee market tests',
async () => {
const txns = await createBlobTxs(
4,
pkey,
// Start with nonce of 1 since a tx previous has already been posted
1,
{
to: bytesToHex(randomBytes(20)),
chainId: 1,
maxFeePerblobGas: BigInt(1000) as any,
maxPriorityFeePerGas: BigInt(1) as any,
maxFeePerGas: '0xff' as any,
gasLimit: BigInt(1000000) as any,
blobSize: 4096,
},
{ common }
)
const txHashes = []
for (const txn of txns) {
const res = await client.request('eth_sendRawTransaction', [txn], 2.0)
txHashes.push(res.result)
}
await sleep(2000)
}
const block1 = await client.request(
'eth_getBlockByHash',
[txReceipt.result.blockHash, false],
2.0
)
assert.ok(BigInt(block1.result.excessBlobGas) > 0n, 'block1 has excess blob gas > 0')
})
let done = false
let txReceipt
while (!done) {
txReceipt = await client.request('eth_getTransactionReceipt', [txHashes[0]], 2.0)
if (txReceipt.result !== null) {
done = true
}
await sleep(2000)
}
const block1 = await client.request(
'eth_getBlockByHash',
[txReceipt.result.blockHash, false],
2.0
)
// next block will have the excessBlobGas
done = false
let block2
while (!done) {
const nextBlockNumber = `0x${(Number(block1.result.number) + 1).toString('16')}`
block2 = await client.request('eth_getBlockByNumber', [nextBlockNumber, false], 2.0)
if (block2.result !== null && block2.result !== undefined) {
done = true
}
await sleep(2000)
}
assert.ok(BigInt(block2.result.excessBlobGas) > 0n, 'block1 has excess blob gas > 0')
},
10 * 60_000
)

it('point precompile contract test', async () => {
const nonce = await client.request(
Expand Down Expand Up @@ -186,7 +201,7 @@ describe('sharding/eip4844 hardfork tests', async () => {
receipt.result.contractAddress !== undefined,
'successfully deployed contract that calls precompile'
)
})
}, 60_000)
/*
it('multipeer setup', async () => {
const multiPeer = Client.http({ port: 8947 })
Expand All @@ -202,5 +217,5 @@ describe('sharding/eip4844 hardfork tests', async () => {
} catch (e) {
assert.fail('network not cleaned properly')
}
})
}, 60_000)
})
3 changes: 2 additions & 1 deletion packages/client/test/sim/simutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ export const runBlobTx = async (

export const createBlobTxs = async (
numTxs: number,
blobSize = 2 ** 17 - 1,
pkey: Uint8Array,
startNonce: number = 0,
txMeta: {
Expand All @@ -361,10 +360,12 @@ export const createBlobTxs = async (
maxPriorityFeePerGas: bigint
maxFeePerGas: bigint
gasLimit: bigint
blobSize: number
},
opts?: TxOptions
) => {
const txHashes: string[] = []
const blobSize = txMeta.blobSize ?? 2 ** 17 - 1

const blobs = getBlobs(bytesToHex(randomBytes(blobSize)))
const commitments = blobsToCommitments(blobs)
Expand Down

0 comments on commit 6eb9532

Please sign in to comment.