Skip to content

Commit 32a5533

Browse files
gap-editoracolytec3am1r021
authored
docs: updated inrenal structure part (#4047)
* Update README.md * Update packages/vm/README.md Co-authored-by: acolytec3 <[email protected]> * Update README.md * Update packages/vm/README.md --------- Co-authored-by: acolytec3 <[email protected]> Co-authored-by: Scorbajio <[email protected]>
1 parent e300b10 commit 32a5533

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

packages/vm/README.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ The following loggers are currently available:
373373
| Logger | Description |
374374
| ----------- | ------------------------------------------------------------------ |
375375
| `vm:block` | Block operations (run txs, generating receipts, block rewards,...) |
376-
| `vm:tx` |  Transaction operations (account updates, checkpointing,...)  |
377-
| `vm:tx:gas` |  Transaction gas logger |
376+
| `vm:tx` | Transaction operations (account updates, checkpointing,...) |
377+
| `vm:tx:gas` | Transaction gas logger |
378378
| `vm:state` | StateManager logger |
379379
380380
Note that there are additional EVM-specific loggers in the [@ethereumjs/evm](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/evm) package.
@@ -413,20 +413,32 @@ DEBUG=ethjs,vm:tx,vm:evm,vm:ops:sstore,vm:*:gas tsx test.ts
413413
414414
## Internal Structure
415415
416-
The VM processes state changes at many levels.
417-
418-
- **runBlockchain**
419-
- for every block, runBlock
420-
- **runBlock**
421-
- for every tx, runTx
422-
- pay miner and uncles
423-
- **runTx**
424-
- check sender balance
425-
- check sender nonce
426-
- runCall
427-
- transfer gas charges
428-
429-
TODO: this section likely needs an update.
416+
The VM processes state changes at several levels:
417+
418+
- **[`runBlock`](./src/runBlock.ts)**: Processes a single block.
419+
- Performs initial setup: Validates hardfork compatibility, sets the state root (if provided), applies DAO fork logic if necessary.
420+
- Manages state checkpoints before and after processing.
421+
- Iterates through transactions within the block:
422+
- For each transaction, calls `runTx`.
423+
- Processes withdrawals (post-Shanghai/EIP-4895).
424+
- Calculates and assigns block rewards to the miner (and uncles, pre-Merge).
425+
- Finalizes the block state (state root, receipts root, logs bloom).
426+
- Commits or reverts state changes based on success.
427+
- **[`runTx`](./src/runTx.ts)**: Processes a single transaction.
428+
- Performs pre-execution checks: Sender balance sufficient for gas+value, sender nonce validity, transaction gas limit against block gas limit, EIP activations (e.g., 2930 Access Lists, 1559 Fee Market, 4844 Blobs).
429+
- Warms up state access based on Access Lists (EIP-2929/2930).
430+
- Pays intrinsic gas cost.
431+
- Executes the transaction code using `vm.evm.runCall` (or specific logic for contract creation).
432+
- Calculates gas used and refunds remaining gas.
433+
- Transfers gas fees to the fee recipient (recipient receives all pre EIP-1559, base fee is burned post EIP-1559).
434+
- Generates a transaction receipt.
435+
- Manages state checkpoints and commits/reverts changes for the transaction.
436+
- **[`vm.evm.runCall`](../evm/src/evm.ts)** (within `@ethereumjs/evm`): Executes the EVM code for a transaction (message call or contract creation).
437+
- Steps through EVM opcodes.
438+
- Manages memory, stack, and storage changes.
439+
- Handles exceptions and gas consumption during execution.
440+
441+
Note: The process of iterating through the blockchain (block by block) is typically managed by components outside the core VM package, such as `@ethereumjs/blockchain` or a full client implementation, which then utilize the VM's `runBlock` method.
430442
431443
## Development
432444

0 commit comments

Comments
 (0)