eth: listen for mined blocks and propagate using the protocol manager
This commit is contained in:
parent
ecc74d76cc
commit
12e8d9c4dd
|
@ -139,7 +139,7 @@ type Ethereum struct {
|
||||||
net *p2p.Server
|
net *p2p.Server
|
||||||
eventMux *event.TypeMux
|
eventMux *event.TypeMux
|
||||||
txSub event.Subscription
|
txSub event.Subscription
|
||||||
//blockSub event.Subscription
|
minedBlockSub event.Subscription
|
||||||
miner *miner.Miner
|
miner *miner.Miner
|
||||||
|
|
||||||
// logger logger.LogSystem
|
// logger logger.LogSystem
|
||||||
|
@ -387,8 +387,8 @@ func (s *Ethereum) Start() error {
|
||||||
go s.txBroadcastLoop()
|
go s.txBroadcastLoop()
|
||||||
|
|
||||||
// broadcast mined blocks
|
// broadcast mined blocks
|
||||||
//s.blockSub = s.eventMux.Subscribe(core.ChainHeadEvent{})
|
s.minedBlockSub = s.eventMux.Subscribe(core.NewMinedBlockEvent{})
|
||||||
go s.blockBroadcastLoop()
|
go s.minedBroadcastLoop()
|
||||||
|
|
||||||
glog.V(logger.Info).Infoln("Server started")
|
glog.V(logger.Info).Infoln("Server started")
|
||||||
return nil
|
return nil
|
||||||
|
@ -420,7 +420,7 @@ func (s *Ethereum) Stop() {
|
||||||
defer s.extraDb.Close()
|
defer s.extraDb.Close()
|
||||||
|
|
||||||
s.txSub.Unsubscribe() // quits txBroadcastLoop
|
s.txSub.Unsubscribe() // quits txBroadcastLoop
|
||||||
//s.blockSub.Unsubscribe() // quits blockBroadcastLoop
|
s.minedBlockSub.Unsubscribe() // quits blockBroadcastLoop
|
||||||
|
|
||||||
s.txPool.Stop()
|
s.txPool.Stop()
|
||||||
s.eventMux.Stop()
|
s.eventMux.Stop()
|
||||||
|
@ -462,16 +462,14 @@ func (self *Ethereum) syncAccounts(tx *types.Transaction) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Ethereum) blockBroadcastLoop() {
|
func (self *Ethereum) minedBroadcastLoop() {
|
||||||
// automatically stops if unsubscribe
|
// automatically stops if unsubscribe
|
||||||
/*
|
for obj := range self.minedBlockSub.Chan() {
|
||||||
for obj := range self.blockSub.Chan() {
|
|
||||||
switch ev := obj.(type) {
|
switch ev := obj.(type) {
|
||||||
case core.ChainHeadEvent:
|
case core.NewMinedBlockEvent:
|
||||||
self.net.BroadcastLimited("eth", NewBlockMsg, math.Sqrt, []interface{}{ev.Block, ev.Block.Td})
|
self.protocolManager.BroadcastBlock(ev.Block)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveProtocolVersion(db common.Database, protov int) {
|
func saveProtocolVersion(db common.Database, protov int) {
|
||||||
|
|
Loading…
Reference in New Issue