make some 'beginTransaction' usages safer

This commit is contained in:
Zahary Karadjov 2019-02-07 11:10:04 +01:00
parent b8ada41ce0
commit 48cdc6da0b
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
3 changed files with 7 additions and 10 deletions

View File

@ -19,19 +19,17 @@ proc executeBlock(blockEnv: JsonNode, memoryDB: TrieDatabaseRef, blockNumber: Ui
header = chainDB.getBlockHeader(blockNumber)
body = chainDB.getBlockBody(header.blockHash)
let transaction = memoryDB.beginTransaction()
defer: transaction.dispose()
let
transaction = memoryDB.beginTransaction()
vmState = newBaseVMState(parent, chainDB)
validationResult = processBlock(chainDB, parent, header, body, vmState)
if validationResult != ValidationResult.OK:
if validationResult != ValidationResult.OK:
error "block validation error", validationResult
else:
info "block validation success", validationResult, blockNumber
# success or not dispose it
transaction.dispose()
dumpDebuggingMetaData(chainDB, header, body, vmState, false)
let
fileName = "debug" & $blockNumber & ".json"

View File

@ -16,8 +16,9 @@ proc dumpDebug(chainDB: BaseChainDB, blockNumber: Uint256) =
captureTrieDB = trieDB captureDB
captureChainDB = newBaseChainDB(captureTrieDB, false)
let transaction = memoryDB.beginTransaction()
defer: transaction.dispose()
let
transaction = memoryDB.beginTransaction()
parentNumber = blockNumber - 1
parent = captureChainDB.getBlockHeader(parentNumber)
header = captureChainDB.getBlockHeader(blockNumber)
@ -28,8 +29,6 @@ proc dumpDebug(chainDB: BaseChainDB, blockNumber: Uint256) =
captureChainDB.setHead(parent, true)
let validationResult = processBlock(captureChainDB, parent, header, body, vmState)
# success or not dispose it
transaction.dispose()
dumpDebuggingMetaData(captureChainDB, header, body, vmState, false)
proc main() =

View File

@ -68,13 +68,13 @@ proc huntProblematicBlock(blockNumber: Uint256): ValidationResult =
chainDB.setHead(parentBlock.header, true)
let transaction = memoryDB.beginTransaction()
defer: transaction.dispose()
let
transaction = memoryDB.beginTransaction()
vmState = newBaseVMState(parentBlock.header, chainDB)
validationResult = processBlock(chainDB, parentBlock.header, thisBlock.header, thisBlock.body, vmState)
if validationResult != ValidationResult.OK:
transaction.dispose()
dumpDebuggingMetaData(chainDB, thisBlock.header, thisBlock.body, vmState, false)
result = validationResult