Skip to content

Commit

Permalink
download diff layer: fix accroding comments
Browse files Browse the repository at this point in the history
Signed-off-by: kyrie-yl <lei.y@binance.com>
  • Loading branch information
kyrie-yl committed Sep 2, 2021
1 parent 66f5dab commit cd49920
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ type IPeerSet interface {

func DiffBodiesFetchOption(peers IPeerSet) DownloadOption {
return func(dl *Downloader) *Downloader {
var hook = func(headers []*types.Header, options ...interface{}) {
if len(options) < 2 {
var hook = func(headers []*types.Header, args ...interface{}) {
if len(args) < 2 {
return
}
if mode, ok := options[0].(SyncMode); ok {
if mode, ok := args[0].(SyncMode); ok {
if mode == FullSync {
if peerID, ok := options[1].(string); ok {
if peerID, ok := args[1].(string); ok {
if ep := peers.GetDiffPeer(peerID); ep != nil {
hashes := make([]common.Hash, 0, len(headers))
for _, header := range headers {
Expand Down
4 changes: 2 additions & 2 deletions eth/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,10 @@ func testEmptyShortCircuit(t *testing.T, protocol uint, mode SyncMode) {

// Instrument the downloader to signal body requests
bodiesHave, receiptsHave := int32(0), int32(0)
tester.downloader.bodyFetchHook = func(headers []*types.Header, options ...interface{}) {
tester.downloader.bodyFetchHook = func(headers []*types.Header, _ ...interface{}) {
atomic.AddInt32(&bodiesHave, int32(len(headers)))
}
tester.downloader.receiptFetchHook = func(headers []*types.Header, options ...interface{}) {
tester.downloader.receiptFetchHook = func(headers []*types.Header, _ ...interface{}) {
atomic.AddInt32(&receiptsHave, int32(len(headers)))
}
// Synchronise with the peer and make sure all blocks were retrieved
Expand Down
6 changes: 3 additions & 3 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
h.stateBloom = trie.NewSyncBloom(config.BloomCache, config.Database)
}
var downloadOptions []downloader.DownloadOption
if h.lightSync {
if h.diffSync {
downloadOptions = append(downloadOptions, downloader.DiffBodiesFetchOption(h.peers))
}
h.downloader = downloader.New(h.checkpointNumber, config.Database, h.stateBloom, h.eventMux, h.chain, nil, h.removePeer, downloadOptions...)
Expand Down Expand Up @@ -484,8 +484,8 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) {
}
diff := h.chain.GetDiffLayerRLP(block.Hash())
for _, peer := range transfer {
if len(diff) != 0 && peer.DiffExt != nil {
peer.DiffExt.AsyncSendDiffLayer([]rlp.RawValue{diff})
if len(diff) != 0 && peer.diffExt != nil {
peer.diffExt.AsyncSendDiffLayer([]rlp.RawValue{diff})
}
peer.AsyncSendNewBlock(block, td)
}
Expand Down
4 changes: 2 additions & 2 deletions eth/handler_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (h *diffHandler) RunPeer(peer *diff.Peer, hand diff.Handler) error {
// PeerInfo retrieves all known `diff` information about a peer.
func (h *diffHandler) PeerInfo(id enode.ID) interface{} {
if p := h.peers.peer(id.String()); p != nil {
if p.DiffExt != nil {
return p.DiffExt.info()
if p.diffExt != nil {
return p.diffExt.info()
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions eth/handler_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func (h *ethHandler) handleBlockAnnounces(peer *eth.Peer, hashes []common.Hash,
var diffFetcher fetcher.DiffRequesterFn
if h.diffSync {
// the peer support diff protocol
if ep := h.peers.peer(peer.ID()); ep != nil && ep.DiffExt != nil {
diffFetcher = ep.DiffExt.RequestDiffLayers
if ep := h.peers.peer(peer.ID()); ep != nil && ep.diffExt != nil {
diffFetcher = ep.diffExt.RequestDiffLayers
}
}

Expand Down
2 changes: 1 addition & 1 deletion eth/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type ethPeerInfo struct {
type ethPeer struct {
*eth.Peer
snapExt *snapPeer // Satellite `snap` connection
DiffExt *diffPeer
diffExt *diffPeer

syncDrop *time.Timer // Connection dropper if `eth` sync progress isn't validated in time
snapWait chan struct{} // Notification channel for snap connections
Expand Down
8 changes: 4 additions & 4 deletions eth/peerset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package eth

import (
"errors"
"github.com/ethereum/go-ethereum/eth/downloader"
"math/big"
"sync"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/protocols/diff"
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/eth/protocols/snap"
Expand Down Expand Up @@ -207,8 +207,8 @@ func (ps *peerSet) waitDiffExtension(peer *eth.Peer) (*diff.Peer, error) {
}

func (ps *peerSet) GetDiffPeer(pid string) downloader.IDiffPeer {
if p := ps.peer(pid); p != nil && p.DiffExt != nil {
return p.DiffExt
if p := ps.peer(pid); p != nil && p.diffExt != nil {
return p.diffExt
}
return nil
}
Expand All @@ -235,7 +235,7 @@ func (ps *peerSet) registerPeer(peer *eth.Peer, ext *snap.Peer, diffExt *diff.Pe
ps.snapPeers++
}
if diffExt != nil {
eth.DiffExt = &diffPeer{diffExt}
eth.diffExt = &diffPeer{diffExt}
}
ps.peers[id] = eth
return nil
Expand Down

0 comments on commit cd49920

Please sign in to comment.