@@ -28,6 +28,7 @@ import (
2828
2929 ethereum "github.com/XinFinOrg/XDPoSChain"
3030 "github.com/XinFinOrg/XDPoSChain/common"
31+ "github.com/XinFinOrg/XDPoSChain/core"
3132 "github.com/XinFinOrg/XDPoSChain/core/rawdb"
3233 "github.com/XinFinOrg/XDPoSChain/core/types"
3334 "github.com/XinFinOrg/XDPoSChain/ethdb"
@@ -36,15 +37,9 @@ import (
3637 "github.com/XinFinOrg/XDPoSChain/trie"
3738)
3839
39- // Reduce some of the parameters to make the tester faster.
40- func init () {
41- MaxForkAncestry = uint64 (10000 )
42- blockCacheMaxItems = 1024
43- fsHeaderContCheck = 500 * time .Millisecond
44- }
45-
4640// downloadTester is a test simulator for mocking out local block chain.
4741type downloadTester struct {
42+ chain * core.BlockChain
4843 downloader * Downloader
4944
5045 genesis * types.Block // Genesis blocks used by the tester and peers
@@ -64,6 +59,7 @@ type downloadTester struct {
6459// newTester creates a new downloader test mocker.
6560func newTester () * downloadTester {
6661 tester := & downloadTester {
62+ chain : chain ,
6763 genesis : testGenesis ,
6864 peerDb : testDB ,
6965 peers : make (map [string ]* downloadTesterPeer ),
@@ -83,20 +79,22 @@ func newTester() *downloadTester {
8379// held resources.
8480func (dl * downloadTester ) terminate () {
8581 dl .downloader .Terminate ()
82+ dl .chain .Stop ()
83+
8684}
8785
8886// sync starts synchronizing with a remote peer, blocking until it completes.
8987func (dl * downloadTester ) sync (id string , td * big.Int , mode SyncMode ) error {
9088 dl .lock .RLock ()
9189 hash := dl .peers [id ].chain .headBlock ().Hash ()
9290 // If no particular TD was requested, load from the peer's blockchain
91+ head := dl .peers [id ].chain .CurrentBlock ()
9392 if td == nil {
94- td = dl .peers [id ].chain .td (hash )
93+ // If no particular TD was requested, load from the peer's blockchain
94+ td = dl .peers [id ].chain .GetTd (head .Hash (), head .NumberU64 ())
9595 }
96- dl .lock .RUnlock ()
97-
9896 // Synchronise with the chosen peer and ensure proper cleanup afterwards
99- err := dl .downloader .synchronise (id , hash , td , mode )
97+ err := dl .downloader .synchronise (id , head . Hash () , td , mode )
10098 select {
10199 case <- dl .downloader .cancelCh :
102100 // Ok, downloader fully cancelled after sync cycle
@@ -107,25 +105,6 @@ func (dl *downloadTester) sync(id string, td *big.Int, mode SyncMode) error {
107105 return err
108106}
109107
110- // HasHeader checks if a header is present in the testers canonical chain.
111- func (dl * downloadTester ) HasHeader (hash common.Hash , number uint64 ) bool {
112- return dl .GetHeaderByHash (hash ) != nil
113- }
114-
115- // HasBlock checks if a block is present in the testers canonical chain.
116- func (dl * downloadTester ) HasBlock (hash common.Hash , number uint64 ) bool {
117- return dl .GetBlockByHash (hash ) != nil
118- }
119-
120- // HasFastBlock checks if a block is present in the testers canonical chain.
121- func (dl * downloadTester ) HasFastBlock (hash common.Hash , number uint64 ) bool {
122- dl .lock .RLock ()
123- defer dl .lock .RUnlock ()
124-
125- _ , ok := dl .ownReceipts [hash ]
126- return ok
127- }
128-
129108// GetHeader retrieves a header from the testers canonical chain.
130109func (dl * downloadTester ) GetHeaderByHash (hash common.Hash ) * types.Header {
131110 dl .lock .RLock ()
0 commit comments