Working on new (blocking) event machine.

The new event machine will be used for loose coupling and handle the
communications between the services:

1) Block pool finds blocks which "links" with our current canonical
chain
2) Posts the blocks on to the event machine
3) State manager receives blocks & processes them
4) Broadcasts new post block event
This commit is contained in:
obscuren
2014-09-29 12:57:51 +02:00
parent ea0357bf02
commit ab6ede51d7
9 changed files with 323 additions and 181 deletions

View File

@ -22,6 +22,7 @@ import (
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"github.com/ethereum/eth-go/eventer"
)
const (
@ -58,7 +59,9 @@ type Ethereum struct {
blockChain *ethchain.BlockChain
// The block pool
blockPool *BlockPool
// Peers (NYI)
// Eventer
eventer *eventer.EventMachine
// Peers
peers *list.List
// Nonce
Nonce uint64
@ -123,6 +126,7 @@ func New(db ethutil.Database, clientIdentity ethwire.ClientIdentity, keyManager
filters: make(map[int]*ethchain.Filter),
}
ethereum.reactor = ethreact.New()
ethereum.eventer = eventer.New()
ethereum.blockPool = NewBlockPool(ethereum)
ethereum.txPool = ethchain.NewTxPool(ethereum)
@ -161,6 +165,9 @@ func (s *Ethereum) TxPool() *ethchain.TxPool {
func (s *Ethereum) BlockPool() *BlockPool {
return s.blockPool
}
func (s *Ethereum) Eventer() *eventer.EventMachine {
return s.eventer
}
func (self *Ethereum) Db() ethutil.Database {
return self.db
}
@ -387,6 +394,8 @@ func (s *Ethereum) ReapDeadPeerHandler() {
func (s *Ethereum) Start(seed bool) {
s.reactor.Start()
s.blockPool.Start()
s.stateManager.Start()
// Bind to addr and port
ln, err := net.Listen("tcp", ":"+s.Port)
if err != nil {