VM Recovery
This commit is contained in:
parent
78d18b134f
commit
055407c835
|
@ -11,7 +11,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BlockManager struct {
|
type BlockManager struct {
|
||||||
|
@ -33,7 +33,13 @@ func (bm *BlockManager) ProcessBlock(block *Block) error {
|
||||||
|
|
||||||
// Process each transaction/contract
|
// Process each transaction/contract
|
||||||
for _, tx := range block.transactions {
|
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
|
// Wait for all Tx to finish processing
|
||||||
|
@ -44,8 +50,18 @@ func (bm *BlockManager) ProcessBlock(block *Block) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bm *BlockManager) ProcessTransaction(tx *Transaction, block *Block, lockChan chan bool) {
|
func (bm *BlockManager) ProcessContract(tx *Transaction, block *Block, lockChan chan bool) {
|
||||||
bm.vm.RunTransaction(tx, block, func(opType OpType) 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
|
// TODO calculate fees
|
||||||
|
|
||||||
return true // Continue
|
return true // Continue
|
||||||
|
|
Loading…
Reference in New Issue