log errors in more detail when block production fails (#2135)

* log errors in more detail when block production fails

* pass through block header error

* make everything cstring
This commit is contained in:
tersec 2020-12-02 13:23:10 +01:00 committed by GitHub
parent 94c66f15a9
commit d5e3712609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 22 deletions

View File

@ -177,7 +177,8 @@ proc state_transition*(
trace "state_transition: processing block, signature passed", trace "state_transition: processing block, signature passed",
signature = shortLog(signedBlock.signature), signature = shortLog(signedBlock.signature),
blockRoot = shortLog(signedBlock.root) blockRoot = shortLog(signedBlock.root)
if process_block(preset, state.data, signedBlock.message, flags, stateCache): let res = process_block(preset, state.data, signedBlock.message, flags, stateCache)
if res.isOk:
if skipStateRootValidation in flags or verifyStateRoot(state.data, signedBlock.message): if skipStateRootValidation in flags or verifyStateRoot(state.data, signedBlock.message):
# State root is what it should be - we're done! # State root is what it should be - we're done!
@ -190,6 +191,13 @@ proc state_transition*(
else: signedBlock.message.state_root else: signedBlock.message.state_root
return true return true
else:
debug "state_transition: process_block failed",
blck = shortLog(signedBlock.message),
slot = state.data.slot,
eth1_deposit_index = state.data.eth1_deposit_index,
deposit_root = shortLog(state.data.eth1_data.deposit_root),
error = res.error
# Block processing failed, roll back changes # Block processing failed, roll back changes
rollback(state) rollback(state)
@ -236,10 +244,15 @@ proc makeBeaconBlock*(
voluntary_exits: voluntary_exits:
List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS](voluntaryExits))) List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS](voluntaryExits)))
let ok = process_block(preset, state.data, blck, {skipBlsValidation}, cache) let res = process_block(preset, state.data, blck, {skipBlsValidation}, cache)
if not ok: if res.isErr:
warn "Unable to apply new block to state", blck = shortLog(blck) warn "Unable to apply new block to state",
blck = shortLog(blck),
slot = state.data.slot,
eth1_deposit_index = state.data.eth1_deposit_index,
deposit_root = shortLog(state.data.eth1_data.deposit_root),
error = res.error
rollback(state) rollback(state)
return return

View File

@ -342,33 +342,20 @@ proc process_operations(preset: RuntimePreset,
proc process_block*( proc process_block*(
preset: RuntimePreset, preset: RuntimePreset,
state: var BeaconState, blck: SomeBeaconBlock, flags: UpdateFlags, state: var BeaconState, blck: SomeBeaconBlock, flags: UpdateFlags,
stateCache: var StateCache): bool {.nbench.}= stateCache: var StateCache): Result[void, cstring] {.nbench.}=
## When there's a new block, we need to verify that the block is sane and ## When there's a new block, we need to verify that the block is sane and
## update the state accordingly - the state is left in an unknown state when ## update the state accordingly - the state is left in an unknown state when
## block application fails (!) ## block application fails (!)
logScope: ? process_block_header(state, blck, flags, stateCache)
blck = shortLog(blck)
let res_block = process_block_header(state, blck, flags, stateCache)
if res_block.isErr:
debug "Block header not valid",
block_header_error = $(res_block.error),
slot = state.slot
return false
if not process_randao(state, blck.body, flags, stateCache): if not process_randao(state, blck.body, flags, stateCache):
debug "Randao failure", slot = shortLog(state.slot) return err("Randao failure".cstring)
return false
process_eth1_data(state, blck.body) process_eth1_data(state, blck.body)
let res_ops = process_operations(preset, state, blck.body, flags, stateCache) let res_ops = process_operations(preset, state, blck.body, flags, stateCache)
if res_ops.isErr: if res_ops.isErr:
debug "process_operations encountered error", return err("process_operations encountered error".cstring)
operation_error = $(res_ops.error),
slot = state.slot,
eth1_deposit_index = state.eth1_deposit_index,
deposit_root = shortLog(state.eth1_data.deposit_root)
return false
true ok()