mirror of https://github.com/poanetwork/quorum.git
Moved messages eventing to chain manager
This commit is contained in:
parent
ebb7db263f
commit
ad0acb5762
|
@ -177,24 +177,24 @@ done:
|
||||||
return receipts, handled, unhandled, erroneous, err
|
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
|
// Processing a blocks may never happen simultaneously
|
||||||
sm.mutex.Lock()
|
sm.mutex.Lock()
|
||||||
defer sm.mutex.Unlock()
|
defer sm.mutex.Unlock()
|
||||||
|
|
||||||
if sm.bc.HasBlock(block.Hash()) {
|
if sm.bc.HasBlock(block.Hash()) {
|
||||||
return nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !sm.bc.HasBlock(block.PrevHash) {
|
if !sm.bc.HasBlock(block.PrevHash) {
|
||||||
return nil, ParentError(block.PrevHash)
|
return nil, nil, ParentError(block.PrevHash)
|
||||||
}
|
}
|
||||||
parent := sm.bc.GetBlock(block.PrevHash)
|
parent := sm.bc.GetBlock(block.PrevHash)
|
||||||
|
|
||||||
return sm.ProcessWithParent(block, parent)
|
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
|
sm.lastAttemptedBlock = block
|
||||||
|
|
||||||
state := parent.State().Copy()
|
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)
|
receipts, err := sm.ApplyDiff(state, parent, block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
block.SetReceipts(receipts)
|
block.SetReceipts(receipts)
|
||||||
|
|
||||||
txSha := DeriveSha(block.transactions)
|
txSha := DeriveSha(block.transactions)
|
||||||
if bytes.Compare(txSha, block.TxSha) != 0 {
|
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)
|
receiptSha := DeriveSha(receipts)
|
||||||
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
|
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
|
// Block validation
|
||||||
if err = sm.ValidateBlock(block, parent); err != nil {
|
if err = sm.ValidateBlock(block, parent); err != nil {
|
||||||
statelogger.Errorln("Error validating block:", err)
|
statelogger.Errorln("Error validating block:", err)
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = sm.AccumelateRewards(state, block, parent); err != nil {
|
if err = sm.AccumelateRewards(state, block, parent); err != nil {
|
||||||
statelogger.Errorln("Error accumulating reward", err)
|
statelogger.Errorln("Error accumulating reward", err)
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(CreateBloom(block), block.LogsBloom) != 0 {
|
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()
|
state.Update()
|
||||||
|
@ -256,13 +259,14 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, er
|
||||||
|
|
||||||
sm.transState = state.Copy()
|
sm.transState = state.Copy()
|
||||||
|
|
||||||
|
messages := state.Manifest().Messages
|
||||||
state.Manifest().Reset()
|
state.Manifest().Reset()
|
||||||
|
|
||||||
sm.eth.TxPool().RemoveSet(block.Transactions())
|
sm.eth.TxPool().RemoveSet(block.Transactions())
|
||||||
|
|
||||||
return td, nil
|
return td, messages, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("total diff failed")
|
return nil, nil, errors.New("total diff failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
|
"github.com/ethereum/go-ethereum/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
var chainlogger = logger.NewLogger("CHAIN")
|
var chainlogger = logger.NewLogger("CHAIN")
|
||||||
|
@ -304,6 +305,7 @@ func (bc *ChainManager) Stop() {
|
||||||
|
|
||||||
type link struct {
|
type link struct {
|
||||||
block *Block
|
block *Block
|
||||||
|
messages state.Messages
|
||||||
td *big.Int
|
td *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +317,7 @@ func NewChain(blocks Blocks) *BlockChain {
|
||||||
chain := &BlockChain{list.New()}
|
chain := &BlockChain{list.New()}
|
||||||
|
|
||||||
for _, block := range blocks {
|
for _, block := range blocks {
|
||||||
chain.PushBack(&link{block, nil})
|
chain.PushBack(&link{block, nil, nil})
|
||||||
}
|
}
|
||||||
|
|
||||||
return chain
|
return chain
|
||||||
|
@ -329,6 +331,7 @@ func (self *ChainManager) InsertChain(chain *BlockChain) {
|
||||||
self.SetTotalDifficulty(link.td)
|
self.SetTotalDifficulty(link.td)
|
||||||
self.add(link.block)
|
self.add(link.block)
|
||||||
self.Ethereum.EventMux().Post(NewBlockEvent{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
|
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 {
|
if err != nil {
|
||||||
chainlogger.Infoln(err)
|
chainlogger.Infoln(err)
|
||||||
chainlogger.Debugf("Block #%v failed (%x...)\n", block.Number, block.Hash()[0:4])
|
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
|
return
|
||||||
}
|
}
|
||||||
l.td = td
|
l.td = td
|
||||||
|
l.messages = messages
|
||||||
}
|
}
|
||||||
|
|
||||||
if td.Cmp(self.TD) <= 0 {
|
if td.Cmp(self.TD) <= 0 {
|
||||||
|
|
|
@ -58,7 +58,7 @@ func main() {
|
||||||
|
|
||||||
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.LogLevel(*loglevel)))
|
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"))
|
stateObject := state.NewStateObject([]byte("evmuser"))
|
||||||
closure := vm.NewClosure(nil, stateObject, stateObject, ethutil.Hex2Bytes(*code), ethutil.Big(*gas), ethutil.Big(*price))
|
closure := vm.NewClosure(nil, stateObject, stateObject, ethutil.Hex2Bytes(*code), ethutil.Big(*gas), ethutil.Big(*price))
|
||||||
|
|
Loading…
Reference in New Issue