diff options
author | zelig <viktor.tron@gmail.com> | 2015-03-20 06:53:15 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-03-20 18:41:40 +0800 |
commit | 391e89d70a43b4a2153db8acac9a6af7a4f76adf (patch) | |
tree | a2412ea8fcac7f7d52e727675f7cf3a0daa4fc4c /blockpool/peers_test.go | |
parent | 50661f0e683b4975894a0e8fe16024724adef72d (diff) | |
download | dexon-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 'blockpool/peers_test.go')
-rw-r--r-- | blockpool/peers_test.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/blockpool/peers_test.go b/blockpool/peers_test.go index e53d7160b..99dd16ba1 100644 --- a/blockpool/peers_test.go +++ b/blockpool/peers_test.go @@ -3,8 +3,12 @@ package blockpool import ( "math/big" "testing" + "time" "github.com/ethereum/go-ethereum/blockpool/test" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" ) // the actual tests @@ -115,6 +119,26 @@ func TestAddPeer(t *testing.T) { } peer0.waitBlocksRequests(3) - blockPool.Stop() + newblock := &types.Block{Td: common.Big3} + blockPool.chainEvents.Post(core.ChainHeadEvent{newblock}) + time.Sleep(100 * time.Millisecond) + if blockPool.peers.best != nil { + t.Errorf("no peer should be ahead of self") + } + best = peer1.AddPeer() + if blockPool.peers.best != nil { + t.Errorf("still no peer should be ahead of self") + } + best = peer2.AddPeer() + if !best { + t.Errorf("peer2 (TD=4) not accepted as best") + } + + blockPool.RemovePeer("peer2") + if blockPool.peers.best != nil { + t.Errorf("no peer should be ahead of self") + } + + blockPool.Stop() } |