aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-03-20 06:53:15 +0800
committerzelig <viktor.tron@gmail.com>2015-03-20 18:41:40 +0800
commit391e89d70a43b4a2153db8acac9a6af7a4f76adf (patch)
treea2412ea8fcac7f7d52e727675f7cf3a0daa4fc4c /eth
parent50661f0e683b4975894a0e8fe16024724adef72d (diff)
downloaddexon-391e89d70a43b4a2153db8acac9a6af7a4f76adf.tar
dexon-391e89d70a43b4a2153db8acac9a6af7a4f76adf.tar.gz
dexon-391e89d70a43b4a2153db8acac9a6af7a4f76adf.tar.bz2
dexon-391e89d70a43b4a2153db8acac9a6af7a4f76adf.tar.lz
dexon-391e89d70a43b4a2153db8acac9a6af7a4f76adf.tar.xz
dexon-391e89d70a43b4a2153db8acac9a6af7a4f76adf.tar.zst
dexon-391e89d70a43b4a2153db8acac9a6af7a4f76adf.zip
use own total difficulty to limit best peer
- update blockpool td by subscribing to ChainHeadEvent - if ahead of best peer, demote it - addPeer now take own td as current td - removePeer now take own td as current td - add relevant tests to peers_test - eth: backend now calls blockpool with eth.eventMux and chainManager.Td
Diffstat (limited to 'eth')
-rw-r--r--eth/backend.go3
-rw-r--r--eth/protocol_test.go13
2 files changed, 5 insertions, 11 deletions
diff --git a/eth/backend.go b/eth/backend.go
index afe314d74..141c6c605 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -195,7 +195,8 @@ func New(config *Config) (*Ethereum, error) {
hasBlock := eth.chainManager.HasBlock
insertChain := eth.chainManager.InsertChain
- eth.blockPool = blockpool.New(hasBlock, insertChain, eth.pow.Verify)
+ td := eth.chainManager.Td()
+ eth.blockPool = blockpool.New(hasBlock, insertChain, eth.pow.Verify, eth.EventMux(), td)
netprv, err := config.nodeKey()
if err != nil {
diff --git a/eth/protocol_test.go b/eth/protocol_test.go
index 7620b3854..8ca6d1be6 100644
--- a/eth/protocol_test.go
+++ b/eth/protocol_test.go
@@ -41,17 +41,10 @@ type testChainManager struct {
type testBlockPool struct {
addBlockHashes func(next func() (common.Hash, bool), peerId string)
addBlock func(block *types.Block, peerId string) (err error)
- addPeer func(td *big.Int, currentBlock common.Hash, peerId string, requestHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool)
+ addPeer func(td *big.Int, currentBlock common.Hash, peerId string, requestHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool, suspended bool)
removePeer func(peerId string)
}
-// func (self *testTxPool) GetTransactions() (txs []*types.Transaction) {
-// if self.getTransactions != nil {
-// txs = self.getTransactions()
-// }
-// return
-// }
-
func (self *testTxPool) AddTransactions(txs []*types.Transaction) {
if self.addTransactions != nil {
self.addTransactions(txs)
@@ -93,9 +86,9 @@ func (self *testBlockPool) AddBlock(block *types.Block, peerId string) {
}
}
-func (self *testBlockPool) AddPeer(td *big.Int, currentBlock common.Hash, peerId string, requestBlockHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool) {
+func (self *testBlockPool) AddPeer(td *big.Int, currentBlock common.Hash, peerId string, requestBlockHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool, suspended bool) {
if self.addPeer != nil {
- best = self.addPeer(td, currentBlock, peerId, requestBlockHashes, requestBlocks, peerError)
+ best, suspended = self.addPeer(td, currentBlock, peerId, requestBlockHashes, requestBlocks, peerError)
}
return
}