Skip to content

Commit

Permalink
t8n tool support --state.reward -1
Browse files Browse the repository at this point in the history
fixes #1313
  • Loading branch information
jangko committed Nov 23, 2022
1 parent e56bd99 commit 77102c4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
29 changes: 24 additions & 5 deletions tools/t8n/config.nim
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import
std/[options, os, strutils],
confutils,
confutils, stint,
./types

export
options
options, stint

func combineForks(): string =
for x in low(TestFork)..high(TestFork):
Expand Down Expand Up @@ -83,9 +83,10 @@ type
name: "input.txs" }: string

stateReward* {.
desc: "Mining reward. Set to 0 to disable"
defaultValue: 0
name: "state.reward" }: HexOrInt
desc: "Mining reward. Set to -1 to disable"
defaultValue: none(UInt256)
defaultValueDesc: "-1"
name: "state.reward" }: Option[UInt256]

stateChainId* {.
desc: "ChainID to use"
Expand All @@ -105,6 +106,17 @@ type
defaultValue: 3
name: "verbosity" }: int

proc parseCmdArg*(T: type Option[UInt256], p: TaintedString): T =
if p.string == "-1":
none(UInt256)
elif startsWith(p.string, "0x"):
some(parse(p.string, UInt256, 16))
else:
some(parse(p.string, UInt256, 10))

proc completeCmdArg*(T: type Option[UInt256], val: TaintedString): seq[string] =
return @[]

proc parseCmdArg*(T: type HexOrInt, p: TaintedString): T =
if startsWith(p.string, "0x"):
parseHexInt(p.string).T
Expand All @@ -116,6 +128,13 @@ proc completeCmdArg*(T: type HexOrInt, val: TaintedString): seq[string] =

proc notCmd(x: string): bool =
if x.len == 0: return true

# negative number
if x.len >= 2 and
x[0] == '-' and
x[1].isDigit: return true

# else
x[0] != '-'

proc convertToNimStyle(cmds: openArray[string]): seq[string] =
Expand Down
9 changes: 9 additions & 0 deletions tools/t8n/t8n_test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ const
output: T8nOutput(alloc: false, result: false),
expExitCode: ErrorConfig.int,
),
TestSpec(
name : "Test state-reward -1",
base : "testdata/3",
input : t8nInput(
"alloc.json", "txs.json", "env.json", "Berlin", "-1"
),
output: T8nOutput(alloc: true, result: true),
expOut: "exp.json",
),
]

proc main() =
Expand Down
7 changes: 4 additions & 3 deletions tools/t8n/transition.nim
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ proc dumpTrace(txIndex: int, txHash: Hash256, traceResult: JsonNode) =

proc exec(ctx: var TransContext,
vmState: BaseVMState,
blockReward: UInt256,
stateReward: Option[UInt256],
header: BlockHeader): ExecOutput =

var
Expand Down Expand Up @@ -174,7 +174,8 @@ proc exec(ctx: var TransContext,
)
includedTx.add tx

if blockReward > 0.u256:
if stateReward.isSome:
let blockReward = stateReward.get()
var mainReward = blockReward
for uncle in ctx.env.ommers:
var uncleReward = 8.u256 - uncle.delta.u256
Expand Down Expand Up @@ -355,7 +356,7 @@ proc transitionAction*(ctx: var TransContext, conf: T8NConf) =
db.setupAlloc(ctx.alloc)
db.persist(clearCache = false)

let res = exec(ctx, vmState, conf.stateReward.uint64.u256, header)
let res = exec(ctx, vmState, conf.stateReward, header)

if vmState.hashError.len > 0:
raise newError(ErrorMissingBlockhash, vmState.hashError)
Expand Down

0 comments on commit 77102c4

Please sign in to comment.