Skip to content

Commit

Permalink
change into diff sync
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezoro committed Sep 2, 2021
1 parent 9a268c5 commit 42e86d8
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var (
utils.ExternalSignerFlag,
utils.NoUSBFlag,
utils.DirectBroadcastFlag,
utils.LightSyncFlag,
utils.DiffSyncFlag,
utils.RangeLimitFlag,
utils.USBFlag,
utils.SmartCardDaemonPathFlag,
Expand Down
10 changes: 5 additions & 5 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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{}),
}
Expand Down
2 changes: 1 addition & 1 deletion eth/handler_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion eth/handler_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions eth/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions eth/protocols/diff/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -57,7 +57,7 @@ func (p *Peer) Handshake(lightSync bool) error {
return p2p.DiscReadTimeout
}
}
p.lightSync = cap.LightSync
p.diffSync = cap.DiffSync
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions eth/protocols/diff/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/diff/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (p *DiffLayersPacket) Unpack() ([]*types.DiffLayer, error) {
}

type DiffCapPacket struct {
LightSync bool
DiffSync bool
}

type DiffLayersPacket []rlp.RawValue
Expand Down

0 comments on commit 42e86d8

Please sign in to comment.