Skip to content

Commit

Permalink
remove verification from downloader for trusted
Browse files Browse the repository at this point in the history
  • Loading branch information
b00ris committed Apr 16, 2018
1 parent bf691f9 commit d1a79df
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
8 changes: 7 additions & 1 deletion eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/params"
)

Expand Down Expand Up @@ -113,7 +114,8 @@ type Downloader struct {
blockchain BlockChain

// Callbacks
dropPeer peerDropFn // Drops a peer for misbehaving
dropPeer peerDropFn // Drops a peer for misbehaving
IsTrustedPeer func(p discover.NodeID) bool

// Status
synchroniseMock func(id string, hash common.Hash) error // Replacement for synchronise during testing
Expand Down Expand Up @@ -1261,6 +1263,10 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
frequency := fsHeaderCheckFrequency
if chunk[len(chunk)-1].Number.Uint64()+uint64(fsHeaderForceVerify) > pivot {
frequency = 1
//disable validation for trusted peers
if d.IsTrustedPeer != nil {
frequency = 0
}
}
if n, err := d.lightchain.InsertHeaderChain(chunk, frequency); err != nil {
// If some headers were inserted, add them too to the rollback list
Expand Down
1 change: 1 addition & 0 deletions les/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ func (f *lightFetcher) processResponse(req fetchRequest, resp fetchResponse) boo
if f.pm.ulc != nil && len(f.pm.ulc.trustedKeys) > 0 {
checkFreq = 0
}

if _, err := f.chain.InsertHeaderChain(headers, checkFreq); err != nil {
if err == consensus.ErrFutureBlock {
return true
Expand Down
6 changes: 3 additions & 3 deletions les/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ func TestFetcherULCPeerSelector(t *testing.T) {
rand.Read(id4[:])

ftn1 := &fetcherTreeNode{
hash: common.StringToHash("1"),
hash: common.HexToHash("1"),
td: big.NewInt(1),
}
ftn2 := &fetcherTreeNode{
hash: common.StringToHash("2"),
hash: common.HexToHash("2"),
td: big.NewInt(2),
parent: ftn1,
}
ftn3 := &fetcherTreeNode{
hash: common.StringToHash("3"),
hash: common.HexToHash("3"),
td: big.NewInt(3),
parent: ftn2,
}
Expand Down
17 changes: 12 additions & 5 deletions les/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ func NewProtocolManager(

if lightSync {
manager.downloader = downloader.New(downloader.LightSync, chainDb, manager.eventMux, nil, blockchain, removePeer)
if manager.ulc != nil && len(manager.ulc.trustedKeys) > 0 {
manager.downloader.IsTrustedPeer = manager.ulc.isTrusted
}
manager.peers.notify((*downloaderPeerNotify)(manager))
manager.fetcher = newLightFetcher(manager)
}
Expand Down Expand Up @@ -1274,14 +1277,18 @@ func (pc *peerConnection) RequestHeadersByNumber(origin uint64, amount int, skip

func (d *downloaderPeerNotify) registerPeer(p *peer) {
pm := (*ProtocolManager)(d)
pc := &peerConnection{
manager: pm,
peer: p,
if pm.ulc == nil || p.isTrusted {
pc := &peerConnection{
manager: pm,
peer: p,
}
pm.downloader.RegisterLightPeer(p.id, ethVersion, pc)
}
pm.downloader.RegisterLightPeer(p.id, ethVersion, pc)
}

func (d *downloaderPeerNotify) unregisterPeer(p *peer) {
pm := (*ProtocolManager)(d)
pm.downloader.UnregisterPeer(p.id)
if pm.ulc == nil || p.isTrusted {
pm.downloader.UnregisterPeer(p.id)
}
}
4 changes: 2 additions & 2 deletions les/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const (
)

var (
hash = common.StringToHash("some string")
genesis = common.StringToHash("genesis hash")
hash = common.HexToHash("some string")
genesis = common.HexToHash("genesis hash")
headNum = uint64(1234)
td = big.NewInt(123)
)
Expand Down

0 comments on commit d1a79df

Please sign in to comment.