From 8eec8b64a25387399cab08c8a43570558351ab25 Mon Sep 17 00:00:00 2001 From: b00ris Date: Mon, 12 Nov 2018 18:36:11 +0300 Subject: [PATCH] les: cosmetic fixes --- cmd/utils/flags.go | 19 ++----------------- eth/ulc_config.go | 2 +- les/fetcher.go | 10 ++++++---- les/fetcher_test.go | 2 +- les/handler.go | 7 ++----- les/txrelay.go | 5 +---- 6 files changed, 13 insertions(+), 32 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index d44300d16476..4082bc20ac1e 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -174,21 +174,6 @@ var ( Name: "ulc.trusted", Usage: "List of trusted ULC servers", } - Name: "les.ulcconfig", - Usage: "Config file to use for ULC mode", - } - OnlyAnnounceModeFlag = cli.BoolFlag{ - Name: "les.onlyannounce", - Usage: "LES server sends only announce", - } - ULCMinTrustedFractionFlag = cli.IntFlag{ - Name: "les.mintrustedfraction", - Usage: "LES server sends only announce", - } - ULCTrustedNodesFlag = cli.StringFlag{ - Name: "les.trusted", - Usage: "List of trusted nodes", - } defaultSyncMode = eth.DefaultConfig.SyncMode SyncModeFlag = TextMarshalerFlag{ @@ -878,8 +863,8 @@ func SetULC(ctx *cli.Context, cfg *eth.Config) { cfg.ULC.MinTrustedFraction = trustedFraction } if cfg.ULC.MinTrustedFraction <= 0 && cfg.ULC.MinTrustedFraction > 100 { - log.Error("MinTrustedFraction is invalid", "MinTrustedFraction", cfg.ULC.MinTrustedFraction, "Changed to default", eth.DefaultUTCMinTrustedFraction) - cfg.ULC.MinTrustedFraction = eth.DefaultUTCMinTrustedFraction + log.Error("MinTrustedFraction is invalid", "MinTrustedFraction", cfg.ULC.MinTrustedFraction, "Changed to default", eth.DefaultULCMinTrustedFraction) + cfg.ULC.MinTrustedFraction = eth.DefaultULCMinTrustedFraction } } diff --git a/eth/ulc_config.go b/eth/ulc_config.go index 960cb0da5648..effa6da217b3 100644 --- a/eth/ulc_config.go +++ b/eth/ulc_config.go @@ -1,6 +1,6 @@ package eth -const DefaultUTCMinTrustedFraction = 75 +const DefaultULCMinTrustedFraction = 75 // ULCConfig is a Ultra Light client options. type ULCConfig struct { diff --git a/les/fetcher.go b/les/fetcher.go index d9dc9b086c64..ad3b491f101a 100644 --- a/les/fetcher.go +++ b/les/fetcher.go @@ -424,7 +424,7 @@ func (f *lightFetcher) nextRequest() (*distReq, uint64) { bestTd *big.Int bestSyncing bool ) - bestHash, bestAmount, bestTd, bestSyncing = f.findBestValues() + bestHash, bestAmount, bestTd, bestSyncing = f.findBestRequest() if bestTd == f.maxConfirmedTd { return nil, 0 @@ -442,8 +442,10 @@ func (f *lightFetcher) nextRequest() (*distReq, uint64) { return rq, reqID } -// findBestValues retrieves the best values for LES or ULC mode. -func (f *lightFetcher) findBestValues() (bestHash common.Hash, bestAmount uint64, bestTd *big.Int, bestSyncing bool) { +// findBestRequest finds the best head to request that has been announced by but not yet requested from a known peer. +// It also returns the announced Td (which should be verified after fetching the head), +// the necessary amount to request and whether a downloader sync is necessary instead of a normal header request. +func (f *lightFetcher) findBestRequest() (bestHash common.Hash, bestAmount uint64, bestTd *big.Int, bestSyncing bool) { bestTd = f.maxConfirmedTd bestSyncing = false @@ -691,7 +693,7 @@ func (f *lightFetcher) checkAnnouncedHeaders(fp *fetcherPeerInfo, headers []*typ } } -// §ncedHeaders updates peer's block tree after synchronisation by marking +// checkSyncedHeaders updates peer's block tree after synchronisation by marking // downloaded headers as known. If none of the announced headers are found after // syncing, the peer is dropped. func (f *lightFetcher) checkSyncedHeaders(p *peer) { diff --git a/les/fetcher_test.go b/les/fetcher_test.go index e5b6ef3464b1..4ae7f6d04ad9 100644 --- a/les/fetcher_test.go +++ b/les/fetcher_test.go @@ -101,7 +101,7 @@ func TestFetcherULCPeerSelector(t *testing.T) { }, }, } - bestHash, bestAmount, bestTD, sync := lf.findBestValues() + bestHash, bestAmount, bestTD, sync := lf.findBestRequest() if bestTD == nil { t.Fatal("Empty result") diff --git a/les/handler.go b/les/handler.go index 774c8b5694e8..46a1ed2d7ba1 100644 --- a/les/handler.go +++ b/les/handler.go @@ -1254,8 +1254,7 @@ func (pc *peerConnection) RequestHeadersByNumber(origin uint64, amount int, skip return peer.GetRequestCost(GetBlockHeadersMsg, amount) }, canSend: func(dp distPeer) bool { - p := dp.(*peer) - return p == pc.peer + return dp.(*peer) == pc.peer }, request: func(dp distPeer) func() { peer := dp.(*peer) @@ -1282,7 +1281,5 @@ func (d *downloaderPeerNotify) registerPeer(p *peer) { func (d *downloaderPeerNotify) unregisterPeer(p *peer) { pm := (*ProtocolManager)(d) - if pm.ulc == nil || p.isTrusted { - pm.downloader.UnregisterPeer(p.id) - } + pm.downloader.UnregisterPeer(p.id) } diff --git a/les/txrelay.go b/les/txrelay.go index 38fc66af9dc3..6d22856f9ff5 100644 --- a/les/txrelay.go +++ b/les/txrelay.go @@ -121,10 +121,7 @@ func (self *LesTxRelay) send(txs types.Transactions, count int) { return peer.GetRequestCost(SendTxMsg, len(ll)) }, canSend: func(dp distPeer) bool { - if !dp.(*peer).isOnlyAnnounce { - return dp.(*peer) == pp - } - return false + return !dp.(*peer).isOnlyAnnounce && dp.(*peer) == pp }, request: func(dp distPeer) func() { peer := dp.(*peer)