From 055407c835328c8b9628c73ddd7ba872d787c09d Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 3 Jan 2014 13:40:25 +0100 Subject: [PATCH] VM Recovery --- block_manager.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/block_manager.go b/block_manager.go index f3aa29ba4..ae9803c8e 100644 --- a/block_manager.go +++ b/block_manager.go @@ -11,7 +11,7 @@ package main import ( - _"fmt" + "fmt" ) type BlockManager struct { @@ -33,7 +33,13 @@ func (bm *BlockManager) ProcessBlock(block *Block) error { // Process each transaction/contract for _, tx := range block.transactions { - go bm.ProcessTransaction(tx, block, lockChan) + // If there's no recipient, it's a contract + if tx.recipient == "" { + go bm.ProcessContract(tx, block, lockChan) + } else { + // "finish" tx which isn't a contract + lockChan <- true + } } // Wait for all Tx to finish processing @@ -44,8 +50,18 @@ func (bm *BlockManager) ProcessBlock(block *Block) error { return nil } -func (bm *BlockManager) ProcessTransaction(tx *Transaction, block *Block, lockChan chan bool) { - bm.vm.RunTransaction(tx, block, func(opType OpType) bool { +func (bm *BlockManager) ProcessContract(tx *Transaction, block *Block, lockChan chan bool) { + // Recovering function in case the VM had any errors + defer func() { + if r := recover(); r != nil { + fmt.Println("Recovered from VM execution with err =", r) + // Let the channel know where done even though it failed (so the execution may resume normally) + lockChan <- true + } + }() + + // Process contract + bm.vm.ProcContract(tx, block, func(opType OpType) bool { // TODO calculate fees return true // Continue