Skip to content

Commit 59743f2

Browse files
authored
Merge pull request ethereumjs#564 from ethereumjs/state-modifications-doc
Document VM methods' state modifications behavior
2 parents e26585f + 3dfc32b commit 59743f2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export interface VMOpts {
5252
/**
5353
* Execution engine which can be used to run a blockchain, individual
5454
* blocks, individual transactions, or snippets of EVM bytecode.
55+
*
56+
* This class is an AsyncEventEmitter, which means that event handlers are run to completion before
57+
* continuing. If an error is thrown in an event handler, it will bubble up to the VM and thrown
58+
* from the method call that triggered the event.
5559
*/
5660
export default class VM extends AsyncEventEmitter {
5761
opts: VMOpts
@@ -109,6 +113,9 @@ export default class VM extends AsyncEventEmitter {
109113

110114
/**
111115
* Processes blocks and adds them to the blockchain.
116+
*
117+
* This method modifies the state.
118+
*
112119
* @param blockchain - A [blockchain](https://github.com/ethereum/ethereumjs-blockchain) object to process
113120
* @param cb - the callback function
114121
*/
@@ -118,6 +125,11 @@ export default class VM extends AsyncEventEmitter {
118125

119126
/**
120127
* Processes the `block` running all of the transactions it contains and updating the miner's account
128+
*
129+
* This method modifies the state. If `generate` is `true`, the state modifications will be
130+
* reverted if an exception is raised. If it's `false`, it won't revert if the block's header is
131+
* invalid. If an error is thrown from an event handler, the state may or may not be reverted.
132+
*
121133
* @param opts - Default values for options:
122134
* - `generate`: false
123135
*/
@@ -127,20 +139,28 @@ export default class VM extends AsyncEventEmitter {
127139

128140
/**
129141
* Process a transaction. Run the vm. Transfers eth. Checks balances.
142+
*
143+
* This method modifies the state. If an error is thrown, the modifications are reverted, except
144+
* when the error is thrown from an event handler. In the latter case the state may or may not be
145+
* reverted.
130146
*/
131147
runTx(opts: RunTxOpts): Promise<RunTxResult> {
132148
return runTx.bind(this)(opts)
133149
}
134150

135151
/**
136152
* runs a call (or create) operation.
153+
*
154+
* This method modifies the state.
137155
*/
138156
runCall(opts: RunCallOpts): Promise<EVMResult> {
139157
return runCall.bind(this)(opts)
140158
}
141159

142160
/**
143161
* Runs EVM code.
162+
*
163+
* This method modifies the state.
144164
*/
145165
runCode(opts: RunCodeOpts): Promise<ExecResult> {
146166
return runCode.bind(this)(opts)

0 commit comments

Comments
 (0)