diff options
author | obscuren <obscuren@obscura.com> | 2014-01-03 20:40:25 +0800 |
---|---|---|
committer | obscuren <obscuren@obscura.com> | 2014-01-03 20:40:25 +0800 |
commit | 055407c835328c8b9628c73ddd7ba872d787c09d (patch) | |
tree | 7e584e145c75cdeec731b7d867c9f1fd80ffa8d1 | |
parent | 78d18b134ffbd4d28d49ef3fe51774a202bb20df (diff) | |
download | go-tangerine-055407c835328c8b9628c73ddd7ba872d787c09d.tar go-tangerine-055407c835328c8b9628c73ddd7ba872d787c09d.tar.gz go-tangerine-055407c835328c8b9628c73ddd7ba872d787c09d.tar.bz2 go-tangerine-055407c835328c8b9628c73ddd7ba872d787c09d.tar.lz go-tangerine-055407c835328c8b9628c73ddd7ba872d787c09d.tar.xz go-tangerine-055407c835328c8b9628c73ddd7ba872d787c09d.tar.zst go-tangerine-055407c835328c8b9628c73ddd7ba872d787c09d.zip |
VM Recovery
-rw-r--r-- | block_manager.go | 24 |
1 files 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 |