Skip to content

Commit 0feb99d

Browse files
ryanioholgerd77
authored andcommitted
develop: fix client parse, move modifyAccountFields to baseStateManager (#1765)
* client fix parse: now with common default being london, explicitly setHardforkByBlockNumber(0) when creating genesis header * vm: move new modifyAccountFields to baseStateManager * fix lint
1 parent 044479b commit 0feb99d

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

packages/client/lib/util/parse.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,16 @@ async function createGethGenesisBlockHeader(json: any) {
148148
stateRoot,
149149
baseFeePerGas,
150150
}
151-
let common
151+
let common = new Common({ chain: 1 })
152152
if (json.config.londonBlock === 0) {
153153
// chainId is not important here, we just want to set
154154
// hardfork to London for baseFeePerGas support
155-
const hardforks = new Common({ chain: 1 })
155+
const hardforks = common
156156
.hardforks()
157157
.map((h) => (h.name === Hardfork.London ? { ...h, block: 0 } : h))
158158
common = Common.custom({ chainId: 1, hardforks })
159-
common.setHardforkByBlockNumber(0)
160159
}
160+
common.setHardforkByBlockNumber(0)
161161
return BlockHeader.fromHeaderData(headerData, { common })
162162
}
163163

packages/client/test/miner/miner.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Common, { Chain as CommonChain, Hardfork } from '@ethereumjs/common'
44
import { FeeMarketEIP1559Transaction, Transaction } from '@ethereumjs/tx'
55
import { Block, BlockHeader } from '@ethereumjs/block'
66
import { DefaultStateManager, StateManager } from '@ethereumjs/vm/dist/state'
7-
import { Account, Address, BN, keccak256 } from 'ethereumjs-util'
7+
import { Address, BN, keccak256 } from 'ethereumjs-util'
88
import { Config } from '../../lib/config'
99
import { FullEthereumService } from '../../lib/service'
1010
import { Chain } from '../../lib/blockchain'

packages/client/test/miner/pendingBlock.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Transaction } from '@ethereumjs/tx'
55
import { BlockHeader } from '@ethereumjs/block'
66
import VM from '@ethereumjs/vm'
77
import { DefaultStateManager, StateManager } from '@ethereumjs/vm/dist/state'
8-
import { Account, Address, BN } from 'ethereumjs-util'
8+
import { Address, BN } from 'ethereumjs-util'
99
import { Config } from '../../lib/config'
1010
import { TxPool } from '../../lib/service/txpool'
1111
import { PendingBlock } from '../../lib/miner'

packages/vm/src/state/baseStateManager.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { debug as createDebugLogger, Debugger } from 'debug'
55
import { Account, Address, toBuffer } from 'ethereumjs-util'
66
import { ripemdPrecompileAddress } from '../evm/precompiles'
77
import Cache from './cache'
8+
import { AccountFields } from './interface'
89
import { DefaultStateManagerOpts } from './stateManager'
910

1011
type AddressHex = string
@@ -108,6 +109,22 @@ export abstract class BaseStateManager {
108109
this.touchAccount(address)
109110
}
110111

112+
/**
113+
* Gets the account associated with `address`, modifies the given account
114+
* fields, then saves the account into state. Account fields can include
115+
* `nonce`, `balance`, `stateRoot`, and `codeHash`.
116+
* @param address - Address of the account to modify
117+
* @param accountFields - Object containing account fields and values to modify
118+
*/
119+
async modifyAccountFields(address: Address, accountFields: AccountFields): Promise<void> {
120+
const account = await this.getAccount(address)
121+
account.nonce = accountFields.nonce ?? account.nonce
122+
account.balance = accountFields.balance ?? account.balance
123+
account.stateRoot = accountFields.stateRoot ?? account.stateRoot
124+
account.codeHash = accountFields.codeHash ?? account.codeHash
125+
await this.putAccount(address, account)
126+
}
127+
111128
/**
112129
* Deletes an account from state under the provided `address`. The account will also be removed from the state trie.
113130
* @param address - Address of the account which should be deleted

packages/vm/src/state/stateManager.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
setLengthLeft,
1616
} from 'ethereumjs-util'
1717
import Common from '@ethereumjs/common'
18-
import { StateManager, StorageDump, AccountFields } from './interface'
18+
import { StateManager, StorageDump } from './interface'
1919
import Cache, { getCb, putCb } from './cache'
2020
import { BaseStateManager } from './'
2121
import { short } from '../evm/opcodes'
@@ -518,20 +518,4 @@ export default class DefaultStateManager extends BaseStateManager implements Sta
518518
}
519519
return false
520520
}
521-
522-
/**
523-
* Gets the account associated with `address`, modifies the given account
524-
* fields, then saves the account into state. Account fields can include
525-
* `nonce`, `balance`, `stateRoot`, and `codeHash`.
526-
* @param address - Address of the account to modify
527-
* @param accountFields - Object containing account fields and values to modify
528-
*/
529-
async modifyAccountFields(address: Address, accountFields: AccountFields): Promise<void> {
530-
const account = await this.getAccount(address)
531-
account.nonce = accountFields.nonce ?? account.nonce
532-
account.balance = accountFields.balance ?? account.balance
533-
account.stateRoot = accountFields.stateRoot ?? account.stateRoot
534-
account.codeHash = accountFields.codeHash ?? account.codeHash
535-
await this.putAccount(address, account)
536-
}
537521
}

0 commit comments

Comments
 (0)