diff --git a/tools/t8n/config.nim b/tools/t8n/config.nim index 686138eee..6d81e24a1 100644 --- a/tools/t8n/config.nim +++ b/tools/t8n/config.nim @@ -84,7 +84,7 @@ type stateReward* {. desc: "Mining reward. Set to -1 to disable" - defaultValue: none(UInt256) + defaultValue: some(0.u256) defaultValueDesc: "-1" name: "state.reward" }: Option[UInt256] diff --git a/tools/t8n/readme.md b/tools/t8n/readme.md index 96f07d8b9..6f5c49b6f 100644 --- a/tools/t8n/readme.md +++ b/tools/t8n/readme.md @@ -56,7 +56,7 @@ The following options are available: extension is '.rlp', then the data is interpreted as an RLP list of signed transactions. The '.rlp' format is identical to the output.body format. [=txs.json]. - --state.reward Mining reward. Set to 0 to disable [=0]. + --state.reward Mining reward. Set to -1 to disable [=0]. --state.chainid ChainID to use [=1]. --state.fork Name of ruleset to use. [=GrayGlacier]. - Frontier. diff --git a/tools/t8n/transition.nim b/tools/t8n/transition.nim index 5fc6e943c..ccbe281aa 100644 --- a/tools/t8n/transition.nim +++ b/tools/t8n/transition.nim @@ -1,5 +1,5 @@ import - std/[json, strutils, times, tables, os], + std/[json, strutils, times, tables, os, sets], eth/[rlp, trie], stint, chronicles, stew/results, "."/[config, types, helpers], @@ -176,7 +176,7 @@ proc exec(ctx: var TransContext, ) includedTx.add tx - if stateReward.isSome: + if stateReward.isSome and stateReward.get >= 0: let blockReward = stateReward.get() var mainReward = blockReward for uncle in ctx.env.ommers: @@ -191,6 +191,18 @@ proc exec(ctx: var TransContext, db.addBalance(ctx.env.currentCoinbase, mainReward) db.persist(clearCache = false) + let miner = ctx.env.currentCoinbase + vmState.mutateStateDB: + if miner in vmState.selfDestructs: + db.deleteAccount miner + if vmState.com.forkGTE(Spurious): + # EIP158/161 state clearing + if db.accountExists(miner) and db.isEmptyAccount(miner): + db.deleteAccount(miner) + # do not clear cache, we need the cache when constructing + # post state + db.persist(clearCache = false) + let stateDB = vmState.stateDB stateDB.postState(result.alloc) result.result = ExecutionResult( @@ -232,7 +244,6 @@ proc setupAlloc(stateDB: AccountsCache, alloc: GenesisAlloc) = method getAncestorHash(vmState: TestVMState; blockNumber: BlockNumber): Hash256 {.gcsafe.} = # we can't raise exception here, it'll mess with EVM exception handler. # so, store the exception for later using `hashError` - let num = blockNumber.truncate(uint64) var h = Hash256() if vmState.blockHashes.len == 0: