Skip to content

Commit f315fc0

Browse files
authored
Statemanager doc update (#3675)
* Change DefaultStateManager to MerkleStateManager * Fix mispelling * Reword and add example to example description * Update example * Update and reembed example
1 parent d7a9ff2 commit f315fc0

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

packages/statemanager/README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ The `StateManager` provides high-level access and manipulation methods to and fo
2626
This library includes several different implementations that all implement the `StateManager` interface which is accepted by the `vm` library. These include:
2727

2828
- [`SimpleStateManager`](./src/simpleStateManager.ts) -a minimally functional (and dependency minimized) version of the state manager suitable for most basic EVM bytecode operations
29-
- [`DefaultStateManager`](./src//stateManager.ts) - a Merkle-Patricia Trie-based `DefaultStateManager` implementation that is used by the `@ethereumjs/client` and `@ethereumjs/vm`
29+
- [`MerkleStateManager`](./src//stateManager.ts) - a Merkle-Patricia Trie-based `MerkleStateManager` implementation that is used by the `@ethereumjs/client` and `@ethereumjs/vm`
3030
- [`RPCStateManager`](./src/rpcStateManager.ts) - a light-weight implementation that sources state and history data from an external JSON-RPC provider
3131
- [`StatelessVerkleStateManager`](./src/statelessVerkleStateManager.ts) - an experimental implementation of a "stateless" state manager that uses Verkle proofs to provide necessary state access for processing verkle-trie based blocks
3232

3333
It also includes a checkpoint/revert/commit mechanism to either persist or revert state changes and provides a sophisticated caching mechanism under the hood to reduce the need reading state accesses from disk.
3434

35-
### `DefaultStateManager`
35+
### `MerkleStateManager`
3636

3737
#### Usage example
3838

@@ -69,7 +69,7 @@ There are now two cache options available: an unbounded cache (`CacheType.ORDERE
6969

7070
Caches now "survive" a flush operation and especially long-lived usage scenarios will benefit from increased performance by a growing and more "knowing" cache leading to less and less trie reads.
7171

72-
Have a loot at the extended `CacheOptions` on how to use and leverage the new cache system.
72+
Have a look at the extended `CacheOptions` on how to use and leverage the new cache system.
7373

7474
### `SimpleStateManager`
7575

@@ -95,11 +95,20 @@ const main = async () => {
9595
void main()
9696
```
9797

98-
### `DefaultStateManager` -> Proofs
98+
### `MerkleStateManager` -> Proofs
9999

100100
#### Instantiating from a Proof
101101

102-
The `DefaultStateManager` has a static constructor `fromProof` that accepts one or more [EIP-1186](https://eips.ethereum.org/EIPS/eip-1186) [proofs](./src/stateManager.ts) and will instantiate a `DefaultStateManager` with a partial trie containing the state provided by the proof(s). Be aware that this constructor accepts the `StateManagerOpts` dictionary as a third parameter (i.e. `stateManager.fromProof(proof, safe, opts)`). Therefore, if you need to use a customized trie (e.g. one that does not use key hashing) or specify caching options, you can pass them in here. If you do instantiate a trie and pass it into the `fromProof` constructor, you also need to instantiate the trie using the corresponding `fromProof` constructor to ensure the state root matches when the proof data is added to the trie. See [this test](./test/stateManager.spec.ts#L287-L288) for more details.
102+
The `MerkleStateManager` has a standalone constructor function `fromMerkleStateProof` that accepts one or more [EIP-1186](https://eips.ethereum.org/EIPS/eip-1186) [proofs](./src/stateManager.ts) and will instantiate a `MerkleStateManager` with a partial trie containing the state provided by the proof(s). Be aware that this constructor accepts the `StateManagerOpts` dictionary as a third parameter (i.e. `fromMerkleStateProof(proof, safe, opts)`).
103+
104+
Therefore, if you need to use a customized trie (e.g. one that does not use key hashing) or specify caching options, you can pass them in here. If you do instantiate a trie and pass it into the `createTrieFromProof` constructor, you also need to instantiate the trie using the corresponding `createStateManagerFromProof` constructor to ensure the state root matches when the proof data is added to the trie, consider an example:
105+
106+
```ts
107+
const newTrie = await createTrieFromProof(proof, { useKeyHashing: false })
108+
const partialSM = await fromMerkleStateProof([proof], true, {
109+
trie: newTrie,
110+
})
111+
```
103112

104113
See below example for common usage:
105114

@@ -108,9 +117,9 @@ See below example for common usage:
108117

109118
import {
110119
MerkleStateManager,
111-
getMerkleStateProof,
112-
fromMerkleStateProof,
113120
addMerkleStateProofData,
121+
fromMerkleStateProof,
122+
getMerkleStateProof,
114123
} from '@ethereumjs/statemanager'
115124
import { Address, hexToBytes } from '@ethereumjs/util'
116125

@@ -139,7 +148,7 @@ const main = async () => {
139148
])
140149
const partialStateManager = await fromMerkleStateProof(proof)
141150

142-
// To add more proof data, use `addProofData`
151+
// To add more proof data, use `addMerkleStateProofData`
143152
await addMerkleStateProofData(partialStateManager, proofWithStorage)
144153
console.log(await partialStateManager.getCode(contractAddress)) // contract bytecode is not included in proof
145154
console.log(await partialStateManager.getStorage(contractAddress, storageKey1), storageValue1) // should match

packages/statemanager/examples/fromProofInstantiation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const main = async () => {
3131
])
3232
const partialStateManager = await fromMerkleStateProof(proof)
3333

34-
// To add more proof data, use `addProofData`
34+
// To add more proof data, use `addMerkleStateProofData`
3535
await addMerkleStateProofData(partialStateManager, proofWithStorage)
3636
console.log(await partialStateManager.getCode(contractAddress)) // contract bytecode is not included in proof
3737
console.log(await partialStateManager.getStorage(contractAddress, storageKey1), storageValue1) // should match

0 commit comments

Comments
 (0)