aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-05-15 19:12:46 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-05-15 19:12:46 +0800
commitc1f0d40e34a80f4453a9a54f90e2d4551c3bdb05 (patch)
tree7ab7c369420a05ff51337a4aed7c5ec88490b90f /eth
parent158efbaa459c534bfb53624e1df7f65e7e8ca24a (diff)
parentcfb2b51b749a5897eb47bee15e67a0f9d850bfbd (diff)
downloaddexon-c1f0d40e34a80f4453a9a54f90e2d4551c3bdb05.tar.gz
dexon-c1f0d40e34a80f4453a9a54f90e2d4551c3bdb05.tar.zst
dexon-c1f0d40e34a80f4453a9a54f90e2d4551c3bdb05.zip
Merge pull request #987 from obscuren/develop
Miner updates and downloader events
Diffstat (limited to 'eth')
-rw-r--r--eth/backend.go4
-rw-r--r--eth/downloader/downloader.go17
-rw-r--r--eth/downloader/downloader_test.go4
-rw-r--r--eth/downloader/events.go5
4 files changed, 26 insertions, 4 deletions
diff --git a/eth/backend.go b/eth/backend.go
index 362a7eab7..064018955 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -265,12 +265,12 @@ func New(config *Config) (*Ethereum, error) {
}
eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux())
- eth.downloader = downloader.New(eth.chainManager.HasBlock, eth.chainManager.GetBlock)
+ eth.downloader = downloader.New(eth.EventMux(), eth.chainManager.HasBlock, eth.chainManager.GetBlock)
eth.pow = ethash.New()
eth.txPool = core.NewTxPool(eth.EventMux(), eth.chainManager.State, eth.chainManager.GasLimit)
eth.blockProcessor = core.NewBlockProcessor(stateDb, extraDb, eth.pow, eth.txPool, eth.chainManager, eth.EventMux())
eth.chainManager.SetProcessor(eth.blockProcessor)
- eth.miner = miner.New(eth, eth.pow)
+ eth.miner = miner.New(eth, eth.EventMux(), eth.pow)
eth.miner.SetGasPrice(config.GasPrice)
eth.protocolManager = NewProtocolManager(config.ProtocolVersion, config.NetworkId, eth.eventMux, eth.txPool, eth.chainManager, eth.downloader)
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index cc75c3014..616971f73 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
)
@@ -55,6 +56,8 @@ type hashPack struct {
}
type Downloader struct {
+ mux *event.TypeMux
+
mu sync.RWMutex
queue *queue
peers *peerSet
@@ -76,8 +79,9 @@ type Downloader struct {
cancelLock sync.RWMutex // Lock to protect the cancel channel in delivers
}
-func New(hasBlock hashCheckFn, getBlock getBlockFn) *Downloader {
+func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloader {
downloader := &Downloader{
+ mux: mux,
queue: newQueue(),
peers: newPeerSet(),
hasBlock: hasBlock,
@@ -93,6 +97,11 @@ func (d *Downloader) Stats() (current int, max int) {
return d.queue.Size()
}
+// Synchronising returns the state of the downloader
+func (d *Downloader) Synchronising() bool {
+ return atomic.LoadInt32(&d.synchronising) > 0
+}
+
// RegisterPeer injects a new download peer into the set of block source to be
// used for fetching hashes and blocks from.
func (d *Downloader) RegisterPeer(id string, head common.Hash, getHashes hashFetcherFn, getBlocks blockFetcherFn) error {
@@ -129,6 +138,9 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error {
if atomic.CompareAndSwapInt32(&d.notified, 0, 1) {
glog.V(logger.Info).Infoln("Block synchronisation started")
}
+
+ d.mux.Post(StartEvent{})
+
// Create cancel channel for aborting mid-flight
d.cancelLock.Lock()
d.cancelCh = make(chan struct{})
@@ -166,6 +178,9 @@ func (d *Downloader) syncWithPeer(p *peer, hash common.Hash) (err error) {
// reset on error
if err != nil {
d.queue.Reset()
+ d.mux.Post(FailedEvent{err})
+ } else {
+ d.mux.Post(DoneEvent{})
}
}()
diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go
index cfa6257a3..50fe00d42 100644
--- a/eth/downloader/downloader_test.go
+++ b/eth/downloader/downloader_test.go
@@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/event"
)
var (
@@ -67,7 +68,8 @@ func newTester(t *testing.T, hashes []common.Hash, blocks map[common.Hash]*types
done: make(chan bool),
}
- downloader := New(tester.hasBlock, tester.getBlock)
+ var mux event.TypeMux
+ downloader := New(&mux, tester.hasBlock, tester.getBlock)
tester.downloader = downloader
return tester
diff --git a/eth/downloader/events.go b/eth/downloader/events.go
new file mode 100644
index 000000000..333feb976
--- /dev/null
+++ b/eth/downloader/events.go
@@ -0,0 +1,5 @@
+package downloader
+
+type DoneEvent struct{}
+type StartEvent struct{}
+type FailedEvent struct{ Err error }