From 42e86d84a3085b9803a41f581f14265a8863dcb3 Mon Sep 17 00:00:00 2001 From: fudongbai <296179868@qq.com> Date: Thu, 2 Sep 2021 19:32:52 +0800 Subject: [PATCH] change into diff sync --- cmd/geth/main.go | 2 +- cmd/utils/flags.go | 10 +++++----- eth/backend.go | 4 ++-- eth/ethconfig/config.go | 2 +- eth/handler.go | 6 +++--- eth/handler_diff.go | 2 +- eth/handler_eth.go | 2 +- eth/peer.go | 8 ++++---- eth/protocols/diff/handshake.go | 4 ++-- eth/protocols/diff/peer.go | 8 ++++---- eth/protocols/diff/protocol.go | 2 +- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index a0540c9362..3c2f5ff219 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -65,7 +65,7 @@ var ( utils.ExternalSignerFlag, utils.NoUSBFlag, utils.DirectBroadcastFlag, - utils.LightSyncFlag, + utils.DiffSyncFlag, utils.RangeLimitFlag, utils.USBFlag, utils.SmartCardDaemonPathFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 9b5d2b14a6..e7648a00cd 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -117,9 +117,9 @@ var ( Name: "directbroadcast", Usage: "Enable directly broadcast mined block to all peers", } - LightSyncFlag = cli.BoolFlag{ - Name: "lightsync", - Usage: "Enable difflayer light sync, Please note that enable lightsync will improve the syncing speed, " + + DiffSyncFlag = cli.BoolFlag{ + Name: "diffsync", + Usage: "Enable difflayer light sync, Please note that enable diffsync will improve the syncing speed, " + "but will degrade the security to light client level", } RangeLimitFlag = cli.BoolFlag{ @@ -1592,8 +1592,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if ctx.GlobalIsSet(DirectBroadcastFlag.Name) { cfg.DirectBroadcast = ctx.GlobalBool(DirectBroadcastFlag.Name) } - if ctx.GlobalIsSet(LightSyncFlag.Name) { - cfg.LightSync = ctx.GlobalBool(LightSyncFlag.Name) + if ctx.GlobalIsSet(DiffSyncFlag.Name) { + cfg.DiffSync = ctx.GlobalBool(DiffSyncFlag.Name) } if ctx.GlobalIsSet(RangeLimitFlag.Name) { cfg.RangeLimit = ctx.GlobalBool(RangeLimitFlag.Name) diff --git a/eth/backend.go b/eth/backend.go index 36db5ac5ba..6be178371a 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -200,7 +200,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { } ) bcOps := make([]core.BlockChainOption, 0) - if config.LightSync { + if config.DiffSync { bcOps = append(bcOps, core.EnableLightProcessor) } eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, chainConfig, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit, bcOps...) @@ -238,7 +238,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { Checkpoint: checkpoint, Whitelist: config.Whitelist, DirectBroadcast: config.DirectBroadcast, - LightSync: config.LightSync, + DiffSync: config.DiffSync, }); err != nil { return nil, err } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index b36498df58..e5f01b550a 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -133,7 +133,7 @@ type Config struct { NoPruning bool // Whether to disable pruning and flush everything to disk DirectBroadcast bool - LightSync bool // Whether support light sync + DiffSync bool // Whether support diff sync RangeLimit bool TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. diff --git a/eth/handler.go b/eth/handler.go index d169b4e58b..90d2e96159 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -83,7 +83,7 @@ type handlerConfig struct { TxPool txPool // Transaction pool to propagate from Network uint64 // Network identifier to adfvertise Sync downloader.SyncMode // Whether to fast or full sync - LightSync bool // Whether to light sync + DiffSync bool // Whether to diff sync BloomCache uint64 // Megabytes to alloc for fast sync bloom EventMux *event.TypeMux // Legacy event mux, deprecate for `feed` Checkpoint *params.TrustedCheckpoint // Hard coded checkpoint for sync challenges @@ -99,7 +99,7 @@ type handler struct { snapSync uint32 // Flag whether fast sync should operate on top of the snap protocol acceptTxs uint32 // Flag whether we're considered synchronised (enables transaction processing) directBroadcast bool - lightSync bool // Flag whether light sync should operate on top of the diff protocol + diffSync bool // Flag whether light sync should operate on top of the diff protocol checkpointNumber uint64 // Block number for the sync progress validator to cross reference checkpointHash common.Hash // Block hash for the sync progress validator to cross reference @@ -147,7 +147,7 @@ func newHandler(config *handlerConfig) (*handler, error) { peers: newPeerSet(), whitelist: config.Whitelist, directBroadcast: config.DirectBroadcast, - lightSync: config.LightSync, + diffSync: config.DiffSync, txsyncCh: make(chan *txsync), quitSync: make(chan struct{}), } diff --git a/eth/handler_diff.go b/eth/handler_diff.go index be05877506..ea310c38c2 100644 --- a/eth/handler_diff.go +++ b/eth/handler_diff.go @@ -32,7 +32,7 @@ func (h *diffHandler) Chain() *core.BlockChain { return h.chain } // RunPeer is invoked when a peer joins on the `diff` protocol. func (h *diffHandler) RunPeer(peer *diff.Peer, hand diff.Handler) error { - if err := peer.Handshake(h.lightSync); err != nil { + if err := peer.Handshake(h.diffSync); err != nil { return err } return (*handler)(h).runDiffExtension(peer, hand) diff --git a/eth/handler_eth.go b/eth/handler_eth.go index 802df1b64a..d9fcfb2058 100644 --- a/eth/handler_eth.go +++ b/eth/handler_eth.go @@ -193,7 +193,7 @@ func (h *ethHandler) handleBlockAnnounces(peer *eth.Peer, hashes []common.Hash, } // self support light sync var diffFetcher fetcher.DiffRequesterFn - if h.lightSync { + if h.diffSync { // the peer support diff protocol if ep := h.peers.peer(peer.ID()); ep != nil && ep.diffExt != nil { diffFetcher = ep.diffExt.RequestDiffLayers diff --git a/eth/peer.go b/eth/peer.go index 89139f0b53..2fb6fabf26 100644 --- a/eth/peer.go +++ b/eth/peer.go @@ -65,8 +65,8 @@ type snapPeerInfo struct { // diffPeerInfo represents a short summary of the `diff` sub-protocol metadata known // about a connected peer. type diffPeerInfo struct { - Version uint `json:"version"` // diff protocol version negotiated - LightSync bool `json:"light_sync"` + Version uint `json:"version"` // diff protocol version negotiated + DiffSync bool `json:"diff_sync"` } // snapPeer is a wrapper around snap.Peer to maintain a few extra metadata. @@ -82,8 +82,8 @@ type diffPeer struct { // info gathers and returns some `diff` protocol metadata known about a peer. func (p *diffPeer) info() *diffPeerInfo { return &diffPeerInfo{ - Version: p.Version(), - LightSync: p.LightSync(), + Version: p.Version(), + DiffSync: p.DiffSync(), } } diff --git a/eth/protocols/diff/handshake.go b/eth/protocols/diff/handshake.go index 0d96c5294e..21cf3b4e43 100644 --- a/eth/protocols/diff/handshake.go +++ b/eth/protocols/diff/handshake.go @@ -39,7 +39,7 @@ func (p *Peer) Handshake(lightSync bool) error { gopool.Submit(func() { errc <- p2p.Send(p.rw, DiffCapMsg, &DiffCapPacket{ - LightSync: lightSync, + DiffSync: lightSync, }) }) gopool.Submit(func() { @@ -57,7 +57,7 @@ func (p *Peer) Handshake(lightSync bool) error { return p2p.DiscReadTimeout } } - p.lightSync = cap.LightSync + p.diffSync = cap.DiffSync return nil } diff --git a/eth/protocols/diff/peer.go b/eth/protocols/diff/peer.go index c55a7e1581..0f02152baa 100644 --- a/eth/protocols/diff/peer.go +++ b/eth/protocols/diff/peer.go @@ -14,7 +14,7 @@ const maxQueuedDiffLayers = 12 // Peer is a collection of relevant information we have about a `diff` peer. type Peer struct { id string // Unique ID for the peer, cached - lightSync bool // whether the peer can light sync + diffSync bool // whether the peer can diff sync queuedDiffLayers chan []rlp.RawValue // Queue of diff layers to broadcast to the peer *p2p.Peer // The embedded P2P package peer @@ -32,7 +32,7 @@ func NewPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter) *Peer { id: id, Peer: p, rw: rw, - lightSync: false, + diffSync: false, version: version, logger: log.New("peer", id[:8]), queuedDiffLayers: make(chan []rlp.RawValue, maxQueuedDiffLayers), @@ -66,8 +66,8 @@ func (p *Peer) Version() uint { return p.version } -func (p *Peer) LightSync() bool { - return p.lightSync +func (p *Peer) DiffSync() bool { + return p.diffSync } // Log overrides the P2P logget with the higher level one containing only the id. diff --git a/eth/protocols/diff/protocol.go b/eth/protocols/diff/protocol.go index 881ff828b8..650ba4f51e 100644 --- a/eth/protocols/diff/protocol.go +++ b/eth/protocols/diff/protocol.go @@ -96,7 +96,7 @@ func (p *DiffLayersPacket) Unpack() ([]*types.DiffLayer, error) { } type DiffCapPacket struct { - LightSync bool + DiffSync bool } type DiffLayersPacket []rlp.RawValue