Skip to content

Commit

Permalink
les: cosmetic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
b00ris committed Nov 12, 2018
1 parent cba5a99 commit 8eec8b6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 32 deletions.
19 changes: 2 additions & 17 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion eth/ulc_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eth

const DefaultUTCMinTrustedFraction = 75
const DefaultULCMinTrustedFraction = 75

// ULCConfig is a Ultra Light client options.
type ULCConfig struct {
Expand Down
10 changes: 6 additions & 4 deletions les/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion les/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 2 additions & 5 deletions les/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
5 changes: 1 addition & 4 deletions les/txrelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8eec8b6

Please sign in to comment.