aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chain/block_manager.go28
-rw-r--r--chain/chain_manager.go13
-rw-r--r--cmd/evm/main.go2
3 files changed, 26 insertions, 17 deletions
diff --git a/chain/block_manager.go b/chain/block_manager.go
index 2e6531dbc..b7c805129 100644
--- a/chain/block_manager.go
+++ b/chain/block_manager.go
@@ -177,24 +177,24 @@ done:
return receipts, handled, unhandled, erroneous, err
}
-func (sm *BlockManager) Process(block *Block) (td *big.Int, err error) {
+func (sm *BlockManager) Process(block *Block) (td *big.Int, msgs state.Messages, err error) {
// Processing a blocks may never happen simultaneously
sm.mutex.Lock()
defer sm.mutex.Unlock()
if sm.bc.HasBlock(block.Hash()) {
- return nil, nil
+ return nil, nil, nil
}
if !sm.bc.HasBlock(block.PrevHash) {
- return nil, ParentError(block.PrevHash)
+ return nil, nil, ParentError(block.PrevHash)
}
parent := sm.bc.GetBlock(block.PrevHash)
return sm.ProcessWithParent(block, parent)
}
-func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, err error) {
+func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, messages state.Messages, err error) {
sm.lastAttemptedBlock = block
state := parent.State().Copy()
@@ -211,33 +211,36 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, er
receipts, err := sm.ApplyDiff(state, parent, block)
if err != nil {
- return nil, err
+ return
}
block.SetReceipts(receipts)
txSha := DeriveSha(block.transactions)
if bytes.Compare(txSha, block.TxSha) != 0 {
- return nil, fmt.Errorf("Error validating transaction sha. Received %x, got %x", block.TxSha, txSha)
+ err = fmt.Errorf("Error validating transaction sha. Received %x, got %x", block.TxSha, txSha)
+ return
}
receiptSha := DeriveSha(receipts)
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
- return nil, fmt.Errorf("Error validating receipt sha. Received %x, got %x", block.ReceiptSha, receiptSha)
+ err = fmt.Errorf("Error validating receipt sha. Received %x, got %x", block.ReceiptSha, receiptSha)
+ return
}
// Block validation
if err = sm.ValidateBlock(block, parent); err != nil {
statelogger.Errorln("Error validating block:", err)
- return nil, err
+ return
}
if err = sm.AccumelateRewards(state, block, parent); err != nil {
statelogger.Errorln("Error accumulating reward", err)
- return nil, err
+ return
}
if bytes.Compare(CreateBloom(block), block.LogsBloom) != 0 {
- return nil, errors.New("Unable to replicate block's bloom")
+ err = errors.New("Unable to replicate block's bloom")
+ return
}
state.Update()
@@ -256,13 +259,14 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, er
sm.transState = state.Copy()
+ messages := state.Manifest().Messages
state.Manifest().Reset()
sm.eth.TxPool().RemoveSet(block.Transactions())
- return td, nil
+ return td, messages, nil
} else {
- return nil, errors.New("total diff failed")
+ return nil, nil, errors.New("total diff failed")
}
}
diff --git a/chain/chain_manager.go b/chain/chain_manager.go
index 18961400c..46e0703c1 100644
--- a/chain/chain_manager.go
+++ b/chain/chain_manager.go
@@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/state"
)
var chainlogger = logger.NewLogger("CHAIN")
@@ -303,8 +304,9 @@ func (bc *ChainManager) Stop() {
}
type link struct {
- block *Block
- td *big.Int
+ block *Block
+ messages state.Messages
+ td *big.Int
}
type BlockChain struct {
@@ -315,7 +317,7 @@ func NewChain(blocks Blocks) *BlockChain {
chain := &BlockChain{list.New()}
for _, block := range blocks {
- chain.PushBack(&link{block, nil})
+ chain.PushBack(&link{block, nil, nil})
}
return chain
@@ -329,6 +331,7 @@ func (self *ChainManager) InsertChain(chain *BlockChain) {
self.SetTotalDifficulty(link.td)
self.add(link.block)
self.Ethereum.EventMux().Post(NewBlockEvent{link.block})
+ self.Ethereum.EventMux().Post(link.messages)
}
}
@@ -350,7 +353,8 @@ func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error)
return
}
- td, err = self.Ethereum.BlockManager().ProcessWithParent(block, parent)
+ var messages state.Messages
+ td, messages, err = self.Ethereum.BlockManager().ProcessWithParent(block, parent)
if err != nil {
chainlogger.Infoln(err)
chainlogger.Debugf("Block #%v failed (%x...)\n", block.Number, block.Hash()[0:4])
@@ -360,6 +364,7 @@ func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error)
return
}
l.td = td
+ l.messages = messages
}
if td.Cmp(self.TD) <= 0 {
diff --git a/cmd/evm/main.go b/cmd/evm/main.go
index aaff5c796..0cc0af62a 100644
--- a/cmd/evm/main.go
+++ b/cmd/evm/main.go
@@ -58,7 +58,7 @@ func main() {
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.LogLevel(*loglevel)))
- ethutil.ReadConfig(".ethtest", "/tmp/evm", "")
+ ethutil.ReadConfig("/tm/evmtest", "/tmp/evm", "")
stateObject := state.NewStateObject([]byte("evmuser"))
closure := vm.NewClosure(nil, stateObject, stateObject, ethutil.Hex2Bytes(*code), ethutil.Big(*gas), ethutil.Big(*price))