aboutsummaryrefslogtreecommitdiffstats
path: root/les/handler.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-07-10 01:30:24 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-07-10 01:34:42 +0800
commit213690cdfd8e49940b68210da05e3836005b96b8 (patch)
tree08225fc3870740c2b12a1802d9d6f55df10fee68 /les/handler.go
parent8c249cb82f713c5c5b5a8160c92da7fe145e799d (diff)
downloadgo-tangerine-213690cdfd8e49940b68210da05e3836005b96b8.tar
go-tangerine-213690cdfd8e49940b68210da05e3836005b96b8.tar.gz
go-tangerine-213690cdfd8e49940b68210da05e3836005b96b8.tar.bz2
go-tangerine-213690cdfd8e49940b68210da05e3836005b96b8.tar.lz
go-tangerine-213690cdfd8e49940b68210da05e3836005b96b8.tar.xz
go-tangerine-213690cdfd8e49940b68210da05e3836005b96b8.tar.zst
go-tangerine-213690cdfd8e49940b68210da05e3836005b96b8.zip
cmd, eth, les: fix up ultra light config integration
Diffstat (limited to 'les/handler.go')
-rw-r--r--les/handler.go29
1 files changed, 12 insertions, 17 deletions
diff --git a/les/handler.go b/les/handler.go
index ea2ec3324..743776bd0 100644
--- a/les/handler.go
+++ b/les/handler.go
@@ -31,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
- "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
@@ -130,7 +129,7 @@ type ProtocolManager struct {
// NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable
// with the ethereum network.
-func NewProtocolManager(chainConfig *params.ChainConfig, checkpoint *params.TrustedCheckpoint, indexerConfig *light.IndexerConfig, ulcConfig *eth.ULCConfig, client bool, networkId uint64, mux *event.TypeMux, peers *peerSet, blockchain BlockChain, txpool txPool, chainDb ethdb.Database, odr *LesOdr, serverPool *serverPool, registrar *checkpointOracle, quitSync chan struct{}, wg *sync.WaitGroup, synced func() bool) (*ProtocolManager, error) {
+func NewProtocolManager(chainConfig *params.ChainConfig, checkpoint *params.TrustedCheckpoint, indexerConfig *light.IndexerConfig, ulcServers []string, ulcFraction int, client bool, networkId uint64, mux *event.TypeMux, peers *peerSet, blockchain BlockChain, txpool txPool, chainDb ethdb.Database, odr *LesOdr, serverPool *serverPool, registrar *checkpointOracle, quitSync chan struct{}, wg *sync.WaitGroup, synced func() bool) (*ProtocolManager, error) {
// Create the protocol manager with the base fields
manager := &ProtocolManager{
client: client,
@@ -157,10 +156,14 @@ func NewProtocolManager(chainConfig *params.ChainConfig, checkpoint *params.Trus
manager.reqDist = odr.retriever.dist
}
- if ulcConfig != nil {
- manager.ulc = newULC(ulcConfig)
+ if ulcServers != nil {
+ ulc, err := newULC(ulcServers, ulcFraction)
+ if err != nil {
+ log.Warn("Failed to initialize ultra light client", "err", err)
+ } else {
+ manager.ulc = ulc
+ }
}
-
removePeer := manager.removePeer
if disableClientRemovePeer {
removePeer = func(id string) {}
@@ -247,11 +250,11 @@ func (pm *ProtocolManager) runPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWrit
}
func (pm *ProtocolManager) newPeer(pv int, nv uint64, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
- var isTrusted bool
- if pm.isULCEnabled() {
- isTrusted = pm.ulc.isTrusted(p.ID())
+ var trusted bool
+ if pm.ulc != nil {
+ trusted = pm.ulc.trusted(p.ID())
}
- return newPeer(pv, nv, isTrusted, p, newMeteredMsgWriter(rw))
+ return newPeer(pv, nv, trusted, p, newMeteredMsgWriter(rw))
}
// handle is the callback invoked to manage the life cycle of a les peer. When
@@ -1197,14 +1200,6 @@ func (pm *ProtocolManager) txStatus(hash common.Hash) light.TxStatus {
return stat
}
-// isULCEnabled returns true if we can use ULC
-func (pm *ProtocolManager) isULCEnabled() bool {
- if pm.ulc == nil || len(pm.ulc.trustedKeys) == 0 {
- return false
- }
- return true
-}
-
// downloaderPeerNotify implements peerSetNotify
type downloaderPeerNotify ProtocolManager