Partially refactored server/txpool/block manager/block chain

The Ethereum structure now complies to a EthManager interface which is
being used by the tx pool, block manager and block chain in order to
gain access to each other. It's become simpeler.
TODO: BlockManager => StateManager
This commit is contained in:
obscuren
2014-03-05 10:42:51 +01:00
parent 5b1613d65b
commit 92f2abdf76
8 changed files with 204 additions and 82 deletions

View File

@ -37,10 +37,12 @@ type Ethereum struct {
//db *ethdb.LDBDatabase
db ethutil.Database
// Block manager for processing new blocks and managing the block chain
BlockManager *ethchain.BlockManager
blockManager *ethchain.BlockManager
// The transaction pool. Transaction can be pushed on this pool
// for later including in the blocks
TxPool *ethchain.TxPool
txPool *ethchain.TxPool
// The canonical chain
blockChain *ethchain.BlockChain
// Peers (NYI)
peers *list.List
// Nonce
@ -87,19 +89,28 @@ func New(caps Caps, usePnp bool) (*Ethereum, error) {
serverCaps: caps,
nat: nat,
}
ethereum.TxPool = ethchain.NewTxPool()
ethereum.TxPool.Speaker = ethereum
ethereum.BlockManager = ethchain.NewBlockManager(ethereum)
ethereum.TxPool.BlockManager = ethereum.BlockManager
ethereum.BlockManager.TransactionPool = ethereum.TxPool
ethereum.txPool = ethchain.NewTxPool(ethereum)
ethereum.blockChain = ethchain.NewBlockChain(ethereum)
ethereum.blockManager = ethchain.NewBlockManager(ethereum)
// Start the tx pool
ethereum.TxPool.Start()
ethereum.txPool.Start()
return ethereum, nil
}
func (s *Ethereum) BlockChain() *ethchain.BlockChain {
return s.blockChain
}
func (s *Ethereum) StateManager() *ethchain.BlockManager {
return s.blockManager
}
func (s *Ethereum) TxPool() *ethchain.TxPool {
return s.txPool
}
func (s *Ethereum) AddPeer(conn net.Conn) {
peer := NewPeer(conn, s, true)
@ -253,7 +264,7 @@ func (s *Ethereum) Start() {
if ethutil.Config.Seed {
ethutil.Config.Log.Debugln("Seeding")
// Testnet seed bootstrapping
resp, err := http.Get("http://www.ethereum.org/servers.poc3.txt")
resp, err := http.Get("https://www.ethereum.org/servers.poc3.txt")
if err != nil {
log.Println("Fetching seed failed:", err)
return
@ -292,8 +303,8 @@ func (s *Ethereum) Stop() {
close(s.quit)
s.TxPool.Stop()
s.BlockManager.Stop()
s.txPool.Stop()
s.blockManager.Stop()
close(s.shutdownChan)
}