@@ -39,7 +39,7 @@ import (
3939// requestBenchmark is an interface for different randomized request generators
4040type requestBenchmark interface {
4141 // init initializes the generator for generating the given number of randomized requests
42- init (pm * ProtocolManager , count int ) error
42+ init (h * serverHandler , count int ) error
4343 // request initiates sending a single request to the given peer
4444 request (peer * peer , index int ) error
4545}
@@ -52,10 +52,10 @@ type benchmarkBlockHeaders struct {
5252 hashes []common.Hash
5353}
5454
55- func (b * benchmarkBlockHeaders ) init (pm * ProtocolManager , count int ) error {
55+ func (b * benchmarkBlockHeaders ) init (h * serverHandler , count int ) error {
5656 d := int64 (b .amount - 1 ) * int64 (b .skip + 1 )
5757 b .offset = 0
58- b .randMax = pm .blockchain .CurrentHeader ().Number .Int64 () + 1 - d
58+ b .randMax = h .blockchain .CurrentHeader ().Number .Int64 () + 1 - d
5959 if b .randMax < 0 {
6060 return fmt .Errorf ("chain is too short" )
6161 }
@@ -65,7 +65,7 @@ func (b *benchmarkBlockHeaders) init(pm *ProtocolManager, count int) error {
6565 if b .byHash {
6666 b .hashes = make ([]common.Hash , count )
6767 for i := range b .hashes {
68- b .hashes [i ] = rawdb .ReadCanonicalHash (pm .chainDb , uint64 (b .offset + rand .Int63n (b .randMax )))
68+ b .hashes [i ] = rawdb .ReadCanonicalHash (h .chainDb , uint64 (b .offset + rand .Int63n (b .randMax )))
6969 }
7070 }
7171 return nil
@@ -85,11 +85,11 @@ type benchmarkBodiesOrReceipts struct {
8585 hashes []common.Hash
8686}
8787
88- func (b * benchmarkBodiesOrReceipts ) init (pm * ProtocolManager , count int ) error {
89- randMax := pm .blockchain .CurrentHeader ().Number .Int64 () + 1
88+ func (b * benchmarkBodiesOrReceipts ) init (h * serverHandler , count int ) error {
89+ randMax := h .blockchain .CurrentHeader ().Number .Int64 () + 1
9090 b .hashes = make ([]common.Hash , count )
9191 for i := range b .hashes {
92- b .hashes [i ] = rawdb .ReadCanonicalHash (pm .chainDb , uint64 (rand .Int63n (randMax )))
92+ b .hashes [i ] = rawdb .ReadCanonicalHash (h .chainDb , uint64 (rand .Int63n (randMax )))
9393 }
9494 return nil
9595}
@@ -108,8 +108,8 @@ type benchmarkProofsOrCode struct {
108108 headHash common.Hash
109109}
110110
111- func (b * benchmarkProofsOrCode ) init (pm * ProtocolManager , count int ) error {
112- b .headHash = pm .blockchain .CurrentHeader ().Hash ()
111+ func (b * benchmarkProofsOrCode ) init (h * serverHandler , count int ) error {
112+ b .headHash = h .blockchain .CurrentHeader ().Hash ()
113113 return nil
114114}
115115
@@ -130,11 +130,11 @@ type benchmarkHelperTrie struct {
130130 sectionCount , headNum uint64
131131}
132132
133- func (b * benchmarkHelperTrie ) init (pm * ProtocolManager , count int ) error {
133+ func (b * benchmarkHelperTrie ) init (h * serverHandler , count int ) error {
134134 if b .bloom {
135- b .sectionCount , b .headNum , _ = pm .server .bloomTrieIndexer .Sections ()
135+ b .sectionCount , b .headNum , _ = h .server .bloomTrieIndexer .Sections ()
136136 } else {
137- b .sectionCount , _ , _ = pm .server .chtIndexer .Sections ()
137+ b .sectionCount , _ , _ = h .server .chtIndexer .Sections ()
138138 b .headNum = b .sectionCount * params .CHTFrequency - 1
139139 }
140140 if b .sectionCount == 0 {
@@ -170,7 +170,7 @@ type benchmarkTxSend struct {
170170 txs types.Transactions
171171}
172172
173- func (b * benchmarkTxSend ) init (pm * ProtocolManager , count int ) error {
173+ func (b * benchmarkTxSend ) init (h * serverHandler , count int ) error {
174174 key , _ := crypto .GenerateKey ()
175175 addr := crypto .PubkeyToAddress (key .PublicKey )
176176 signer := types .NewEIP155Signer (big .NewInt (18 ))
@@ -196,7 +196,7 @@ func (b *benchmarkTxSend) request(peer *peer, index int) error {
196196// benchmarkTxStatus implements requestBenchmark
197197type benchmarkTxStatus struct {}
198198
199- func (b * benchmarkTxStatus ) init (pm * ProtocolManager , count int ) error {
199+ func (b * benchmarkTxStatus ) init (h * serverHandler , count int ) error {
200200 return nil
201201}
202202
@@ -217,7 +217,7 @@ type benchmarkSetup struct {
217217
218218// runBenchmark runs a benchmark cycle for all benchmark types in the specified
219219// number of passes
220- func (pm * ProtocolManager ) runBenchmark (benchmarks []requestBenchmark , passCount int , targetTime time.Duration ) []* benchmarkSetup {
220+ func (h * serverHandler ) runBenchmark (benchmarks []requestBenchmark , passCount int , targetTime time.Duration ) []* benchmarkSetup {
221221 setup := make ([]* benchmarkSetup , len (benchmarks ))
222222 for i , b := range benchmarks {
223223 setup [i ] = & benchmarkSetup {req : b }
@@ -239,7 +239,7 @@ func (pm *ProtocolManager) runBenchmark(benchmarks []requestBenchmark, passCount
239239 if next .totalTime > 0 {
240240 count = int (uint64 (next .totalCount ) * uint64 (targetTime ) / uint64 (next .totalTime ))
241241 }
242- if err := pm .measure (next , count ); err != nil {
242+ if err := h .measure (next , count ); err != nil {
243243 next .err = err
244244 }
245245 }
@@ -275,14 +275,15 @@ func (m *meteredPipe) WriteMsg(msg p2p.Msg) error {
275275
276276// measure runs a benchmark for a single type in a single pass, with the given
277277// number of requests
278- func (pm * ProtocolManager ) measure (setup * benchmarkSetup , count int ) error {
278+ func (h * serverHandler ) measure (setup * benchmarkSetup , count int ) error {
279279 clientPipe , serverPipe := p2p .MsgPipe ()
280280 clientMeteredPipe := & meteredPipe {rw : clientPipe }
281281 serverMeteredPipe := & meteredPipe {rw : serverPipe }
282282 var id enode.ID
283283 rand .Read (id [:])
284- clientPeer := pm .newPeer (lpv2 , NetworkId , p2p .NewPeer (id , "client" , nil ), clientMeteredPipe )
285- serverPeer := pm .newPeer (lpv2 , NetworkId , p2p .NewPeer (id , "server" , nil ), serverMeteredPipe )
284+
285+ clientPeer := newPeer (lpv2 , NetworkId , false , p2p .NewPeer (id , "client" , nil ), clientMeteredPipe )
286+ serverPeer := newPeer (lpv2 , NetworkId , false , p2p .NewPeer (id , "server" , nil ), serverMeteredPipe )
286287 serverPeer .sendQueue = newExecQueue (count )
287288 serverPeer .announceType = announceTypeNone
288289 serverPeer .fcCosts = make (requestCostTable )
@@ -291,10 +292,10 @@ func (pm *ProtocolManager) measure(setup *benchmarkSetup, count int) error {
291292 serverPeer .fcCosts [code ] = c
292293 }
293294 serverPeer .fcParams = flowcontrol.ServerParams {BufLimit : 1 , MinRecharge : 1 }
294- serverPeer .fcClient = flowcontrol .NewClientNode (pm .server .fcManager , serverPeer .fcParams )
295+ serverPeer .fcClient = flowcontrol .NewClientNode (h .server .fcManager , serverPeer .fcParams )
295296 defer serverPeer .fcClient .Disconnect ()
296297
297- if err := setup .req .init (pm , count ); err != nil {
298+ if err := setup .req .init (h , count ); err != nil {
298299 return err
299300 }
300301
@@ -311,7 +312,7 @@ func (pm *ProtocolManager) measure(setup *benchmarkSetup, count int) error {
311312 }()
312313 go func () {
313314 for i := 0 ; i < count ; i ++ {
314- if err := pm .handleMsg (serverPeer ); err != nil {
315+ if err := h .handleMsg (serverPeer ); err != nil {
315316 errCh <- err
316317 return
317318 }
@@ -336,7 +337,7 @@ func (pm *ProtocolManager) measure(setup *benchmarkSetup, count int) error {
336337 if err != nil {
337338 return err
338339 }
339- case <- pm . quitSync :
340+ case <- h . closeCh :
340341 clientPipe .Close ()
341342 serverPipe .Close ()
342343 return fmt .Errorf ("Benchmark cancelled" )
0 commit comments