Skip to content

Commit e517183

Browse files
eth, eth/downloader: remove references to LightChain, LightSync (#29711)
Co-authored-by: Gary Rong <[email protected]>
1 parent af0a327 commit e517183

File tree

6 files changed

+46
-90
lines changed

6 files changed

+46
-90
lines changed

eth/backend.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package eth
1919

2020
import (
2121
"encoding/json"
22-
"errors"
2322
"fmt"
2423
"math/big"
2524
"runtime"
@@ -105,9 +104,6 @@ type Ethereum struct {
105104
// whose lifecycle will be managed by the provided node.
106105
func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
107106
// Ensure configuration values are compatible and sane
108-
if config.SyncMode == downloader.LightSync {
109-
return nil, errors.New("can't run eth.Ethereum in light sync mode, light mode has been deprecated")
110-
}
111107
if !config.SyncMode.IsValid() {
112108
return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode)
113109
}

eth/downloader/beaconsync.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
202202
case SnapSync:
203203
chainHead = d.blockchain.CurrentSnapBlock()
204204
default:
205-
chainHead = d.lightchain.CurrentHeader()
205+
panic("unknown sync mode")
206206
}
207207
number := chainHead.Number.Uint64()
208208

@@ -222,7 +222,7 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
222222
case SnapSync:
223223
linked = d.blockchain.HasFastBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
224224
default:
225-
linked = d.blockchain.HasHeader(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
225+
panic("unknown sync mode")
226226
}
227227
if !linked {
228228
// This is a programming error. The chain backfiller was called with a
@@ -257,7 +257,7 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
257257
case SnapSync:
258258
known = d.blockchain.HasFastBlock(h.Hash(), n)
259259
default:
260-
known = d.lightchain.HasHeader(h.Hash(), n)
260+
panic("unknown sync mode")
261261
}
262262
if !known {
263263
end = check

eth/downloader/downloader.go

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ var (
6767
errCancelContentProcessing = errors.New("content processing canceled (requested)")
6868
errCanceled = errors.New("syncing canceled (requested)")
6969
errNoPivotHeader = errors.New("pivot header is not found")
70-
ErrMergeTransition = errors.New("legacy sync reached the merge")
7170
)
7271

7372
// peerDropFn is a callback type for dropping a peer detected as malicious.
@@ -98,7 +97,6 @@ type Downloader struct {
9897
syncStatsChainHeight uint64 // Highest block number known when syncing started
9998
syncStatsLock sync.RWMutex // Lock protecting the sync stats fields
10099

101-
lightchain LightChain
102100
blockchain BlockChain
103101

104102
// Callbacks
@@ -143,8 +141,8 @@ type Downloader struct {
143141
syncLogTime time.Time // Time instance when status was last reported
144142
}
145143

146-
// LightChain encapsulates functions required to synchronise a light chain.
147-
type LightChain interface {
144+
// BlockChain encapsulates functions required to sync a (full or snap) blockchain.
145+
type BlockChain interface {
148146
// HasHeader verifies a header's presence in the local chain.
149147
HasHeader(common.Hash, uint64) bool
150148

@@ -162,11 +160,6 @@ type LightChain interface {
162160

163161
// SetHead rewinds the local chain to a new head.
164162
SetHead(uint64) error
165-
}
166-
167-
// BlockChain encapsulates functions required to sync a (full or snap) blockchain.
168-
type BlockChain interface {
169-
LightChain
170163

171164
// HasBlock verifies a block's presence in the local chain.
172165
HasBlock(common.Hash, uint64) bool
@@ -201,17 +194,13 @@ type BlockChain interface {
201194
}
202195

203196
// New creates a new downloader to fetch hashes and blocks from remote peers.
204-
func New(stateDb ethdb.Database, mux *event.TypeMux, chain BlockChain, lightchain LightChain, dropPeer peerDropFn, success func()) *Downloader {
205-
if lightchain == nil {
206-
lightchain = chain
207-
}
197+
func New(stateDb ethdb.Database, mux *event.TypeMux, chain BlockChain, dropPeer peerDropFn, success func()) *Downloader {
208198
dl := &Downloader{
209199
stateDB: stateDb,
210200
mux: mux,
211201
queue: newQueue(blockCacheMaxItems, blockCacheInitialItems),
212202
peers: newPeerSet(),
213203
blockchain: chain,
214-
lightchain: lightchain,
215204
dropPeer: dropPeer,
216205
headerProcCh: make(chan *headerTask, 1),
217206
quitCh: make(chan struct{}),
@@ -240,15 +229,13 @@ func (d *Downloader) Progress() ethereum.SyncProgress {
240229

241230
current := uint64(0)
242231
mode := d.getMode()
243-
switch {
244-
case d.blockchain != nil && mode == FullSync:
232+
switch mode {
233+
case FullSync:
245234
current = d.blockchain.CurrentBlock().Number.Uint64()
246-
case d.blockchain != nil && mode == SnapSync:
235+
case SnapSync:
247236
current = d.blockchain.CurrentSnapBlock().Number.Uint64()
248-
case d.lightchain != nil:
249-
current = d.lightchain.CurrentHeader().Number.Uint64()
250237
default:
251-
log.Error("Unknown downloader chain/mode combo", "light", d.lightchain != nil, "full", d.blockchain != nil, "mode", mode)
238+
log.Error("Unknown downloader mode", "mode", mode)
252239
}
253240
progress, pending := d.SnapSyncer.Progress()
254241

@@ -402,7 +389,7 @@ func (d *Downloader) syncToHead() (err error) {
402389
if err != nil {
403390
d.mux.Post(FailedEvent{err})
404391
} else {
405-
latest := d.lightchain.CurrentHeader()
392+
latest := d.blockchain.CurrentHeader()
406393
d.mux.Post(DoneEvent{latest})
407394
}
408395
}()
@@ -520,7 +507,7 @@ func (d *Downloader) syncToHead() (err error) {
520507
}
521508
// Rewind the ancient store and blockchain if reorg happens.
522509
if origin+1 < frozen {
523-
if err := d.lightchain.SetHead(origin); err != nil {
510+
if err := d.blockchain.SetHead(origin); err != nil {
524511
return err
525512
}
526513
log.Info("Truncated excess ancient chain segment", "oldhead", frozen-1, "newhead", origin)
@@ -690,34 +677,32 @@ func (d *Downloader) processHeaders(origin uint64) error {
690677
chunkHashes := hashes[:limit]
691678

692679
// In case of header only syncing, validate the chunk immediately
693-
if mode == SnapSync || mode == LightSync {
680+
if mode == SnapSync {
694681
// Although the received headers might be all valid, a legacy
695682
// PoW/PoA sync must not accept post-merge headers. Make sure
696683
// that any transition is rejected at this point.
697684
if len(chunkHeaders) > 0 {
698-
if n, err := d.lightchain.InsertHeaderChain(chunkHeaders); err != nil {
685+
if n, err := d.blockchain.InsertHeaderChain(chunkHeaders); err != nil {
699686
log.Warn("Invalid header encountered", "number", chunkHeaders[n].Number, "hash", chunkHashes[n], "parent", chunkHeaders[n].ParentHash, "err", err)
700687
return fmt.Errorf("%w: %v", errInvalidChain, err)
701688
}
702689
}
703690
}
704-
// Unless we're doing light chains, schedule the headers for associated content retrieval
705-
if mode == FullSync || mode == SnapSync {
706-
// If we've reached the allowed number of pending headers, stall a bit
707-
for d.queue.PendingBodies() >= maxQueuedHeaders || d.queue.PendingReceipts() >= maxQueuedHeaders {
708-
timer.Reset(time.Second)
709-
select {
710-
case <-d.cancelCh:
711-
return errCanceled
712-
case <-timer.C:
713-
}
714-
}
715-
// Otherwise insert the headers for content retrieval
716-
inserts := d.queue.Schedule(chunkHeaders, chunkHashes, origin)
717-
if len(inserts) != len(chunkHeaders) {
718-
return fmt.Errorf("%w: stale headers", errBadPeer)
691+
// If we've reached the allowed number of pending headers, stall a bit
692+
for d.queue.PendingBodies() >= maxQueuedHeaders || d.queue.PendingReceipts() >= maxQueuedHeaders {
693+
timer.Reset(time.Second)
694+
select {
695+
case <-d.cancelCh:
696+
return errCanceled
697+
case <-timer.C:
719698
}
720699
}
700+
// Otherwise insert the headers for content retrieval
701+
inserts := d.queue.Schedule(chunkHeaders, chunkHashes, origin)
702+
if len(inserts) != len(chunkHeaders) {
703+
return fmt.Errorf("%w: stale headers", errBadPeer)
704+
}
705+
721706
headers = headers[limit:]
722707
hashes = hashes[limit:]
723708
origin += uint64(limit)
@@ -1056,7 +1041,7 @@ func (d *Downloader) readHeaderRange(last *types.Header, count int) []*types.Hea
10561041
headers []*types.Header
10571042
)
10581043
for {
1059-
parent := d.lightchain.GetHeaderByHash(current.ParentHash)
1044+
parent := d.blockchain.GetHeaderByHash(current.ParentHash)
10601045
if parent == nil {
10611046
break // The chain is not continuous, or the chain is exhausted
10621047
}

eth/downloader/downloader_test.go

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func newTesterWithNotification(t *testing.T, success func()) *downloadTester {
7676
chain: chain,
7777
peers: make(map[string]*downloadTesterPeer),
7878
}
79-
tester.downloader = New(db, new(event.TypeMux), tester.chain, nil, tester.dropPeer, success)
79+
tester.downloader = New(db, new(event.TypeMux), tester.chain, tester.dropPeer, success)
8080
return tester
8181
}
8282

@@ -384,9 +384,6 @@ func assertOwnChain(t *testing.T, tester *downloadTester, length int) {
384384
t.Helper()
385385

386386
headers, blocks, receipts := length, length, length
387-
if tester.downloader.getMode() == LightSync {
388-
blocks, receipts = 1, 1
389-
}
390387
if hs := int(tester.chain.CurrentHeader().Number.Uint64()) + 1; hs != headers {
391388
t.Fatalf("synchronised headers mismatch: have %v, want %v", hs, headers)
392389
}
@@ -398,9 +395,8 @@ func assertOwnChain(t *testing.T, tester *downloadTester, length int) {
398395
}
399396
}
400397

401-
func TestCanonicalSynchronisation68Full(t *testing.T) { testCanonSync(t, eth.ETH68, FullSync) }
402-
func TestCanonicalSynchronisation68Snap(t *testing.T) { testCanonSync(t, eth.ETH68, SnapSync) }
403-
func TestCanonicalSynchronisation68Light(t *testing.T) { testCanonSync(t, eth.ETH68, LightSync) }
398+
func TestCanonicalSynchronisation68Full(t *testing.T) { testCanonSync(t, eth.ETH68, FullSync) }
399+
func TestCanonicalSynchronisation68Snap(t *testing.T) { testCanonSync(t, eth.ETH68, SnapSync) }
404400

405401
func testCanonSync(t *testing.T, protocol uint, mode SyncMode) {
406402
success := make(chan struct{})
@@ -505,9 +501,8 @@ func testThrottling(t *testing.T, protocol uint, mode SyncMode) {
505501
}
506502

507503
// Tests that a canceled download wipes all previously accumulated state.
508-
func TestCancel68Full(t *testing.T) { testCancel(t, eth.ETH68, FullSync) }
509-
func TestCancel68Snap(t *testing.T) { testCancel(t, eth.ETH68, SnapSync) }
510-
func TestCancel68Light(t *testing.T) { testCancel(t, eth.ETH68, LightSync) }
504+
func TestCancel68Full(t *testing.T) { testCancel(t, eth.ETH68, FullSync) }
505+
func TestCancel68Snap(t *testing.T) { testCancel(t, eth.ETH68, SnapSync) }
511506

512507
func testCancel(t *testing.T, protocol uint, mode SyncMode) {
513508
complete := make(chan struct{})
@@ -538,9 +533,8 @@ func testCancel(t *testing.T, protocol uint, mode SyncMode) {
538533

539534
// Tests that synchronisations behave well in multi-version protocol environments
540535
// and not wreak havoc on other nodes in the network.
541-
func TestMultiProtoSynchronisation68Full(t *testing.T) { testMultiProtoSync(t, eth.ETH68, FullSync) }
542-
func TestMultiProtoSynchronisation68Snap(t *testing.T) { testMultiProtoSync(t, eth.ETH68, SnapSync) }
543-
func TestMultiProtoSynchronisation68Light(t *testing.T) { testMultiProtoSync(t, eth.ETH68, LightSync) }
536+
func TestMultiProtoSynchronisation68Full(t *testing.T) { testMultiProtoSync(t, eth.ETH68, FullSync) }
537+
func TestMultiProtoSynchronisation68Snap(t *testing.T) { testMultiProtoSync(t, eth.ETH68, SnapSync) }
544538

545539
func testMultiProtoSync(t *testing.T, protocol uint, mode SyncMode) {
546540
complete := make(chan struct{})
@@ -578,9 +572,8 @@ func testMultiProtoSync(t *testing.T, protocol uint, mode SyncMode) {
578572

579573
// Tests that if a block is empty (e.g. header only), no body request should be
580574
// made, and instead the header should be assembled into a whole block in itself.
581-
func TestEmptyShortCircuit68Full(t *testing.T) { testEmptyShortCircuit(t, eth.ETH68, FullSync) }
582-
func TestEmptyShortCircuit68Snap(t *testing.T) { testEmptyShortCircuit(t, eth.ETH68, SnapSync) }
583-
func TestEmptyShortCircuit68Light(t *testing.T) { testEmptyShortCircuit(t, eth.ETH68, LightSync) }
575+
func TestEmptyShortCircuit68Full(t *testing.T) { testEmptyShortCircuit(t, eth.ETH68, FullSync) }
576+
func TestEmptyShortCircuit68Snap(t *testing.T) { testEmptyShortCircuit(t, eth.ETH68, SnapSync) }
584577

585578
func testEmptyShortCircuit(t *testing.T, protocol uint, mode SyncMode) {
586579
success := make(chan struct{})
@@ -619,7 +612,7 @@ func testEmptyShortCircuit(t *testing.T, protocol uint, mode SyncMode) {
619612
// Validate the number of block bodies that should have been requested
620613
bodiesNeeded, receiptsNeeded := 0, 0
621614
for _, block := range chain.blocks[1:] {
622-
if mode != LightSync && (len(block.Transactions()) > 0 || len(block.Uncles()) > 0) {
615+
if len(block.Transactions()) > 0 || len(block.Uncles()) > 0 {
623616
bodiesNeeded++
624617
}
625618
}
@@ -694,9 +687,8 @@ func testBeaconSync(t *testing.T, protocol uint, mode SyncMode) {
694687

695688
// Tests that synchronisation progress (origin block number, current block number
696689
// and highest block number) is tracked and updated correctly.
697-
func TestSyncProgress68Full(t *testing.T) { testSyncProgress(t, eth.ETH68, FullSync) }
698-
func TestSyncProgress68Snap(t *testing.T) { testSyncProgress(t, eth.ETH68, SnapSync) }
699-
func TestSyncProgress68Light(t *testing.T) { testSyncProgress(t, eth.ETH68, LightSync) }
690+
func TestSyncProgress68Full(t *testing.T) { testSyncProgress(t, eth.ETH68, FullSync) }
691+
func TestSyncProgress68Snap(t *testing.T) { testSyncProgress(t, eth.ETH68, SnapSync) }
700692

701693
func testSyncProgress(t *testing.T, protocol uint, mode SyncMode) {
702694
success := make(chan struct{})
@@ -734,17 +726,7 @@ func testSyncProgress(t *testing.T, protocol uint, mode SyncMode) {
734726
if err := tester.downloader.BeaconSync(mode, chain.blocks[len(chain.blocks)-1].Header(), nil); err != nil {
735727
t.Fatalf("failed to beacon-sync chain: %v", err)
736728
}
737-
var startingBlock uint64
738-
if mode == LightSync {
739-
// in light-sync mode:
740-
// * the starting block is 0 on the second sync cycle because blocks
741-
// are never downloaded.
742-
// * The current/highest blocks reported in the progress reflect the
743-
// current/highest header.
744-
startingBlock = 0
745-
} else {
746-
startingBlock = uint64(len(chain.blocks)/2 - 1)
747-
}
729+
startingBlock := uint64(len(chain.blocks)/2 - 1)
748730

749731
select {
750732
case <-success:

eth/downloader/modes.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ import "fmt"
2323
type SyncMode uint32
2424

2525
const (
26-
FullSync SyncMode = iota // Synchronise the entire blockchain history from full blocks
27-
SnapSync // Download the chain and the state via compact snapshots
28-
LightSync // Download only the headers and terminate afterwards
26+
FullSync SyncMode = iota // Synchronise the entire blockchain history from full blocks
27+
SnapSync // Download the chain and the state via compact snapshots
2928
)
3029

3130
func (mode SyncMode) IsValid() bool {
32-
return mode >= FullSync && mode <= LightSync
31+
return mode == FullSync || mode == SnapSync
3332
}
3433

3534
// String implements the stringer interface.
@@ -39,8 +38,6 @@ func (mode SyncMode) String() string {
3938
return "full"
4039
case SnapSync:
4140
return "snap"
42-
case LightSync:
43-
return "light"
4441
default:
4542
return "unknown"
4643
}
@@ -52,8 +49,6 @@ func (mode SyncMode) MarshalText() ([]byte, error) {
5249
return []byte("full"), nil
5350
case SnapSync:
5451
return []byte("snap"), nil
55-
case LightSync:
56-
return []byte("light"), nil
5752
default:
5853
return nil, fmt.Errorf("unknown sync mode %d", mode)
5954
}
@@ -65,10 +60,8 @@ func (mode *SyncMode) UnmarshalText(text []byte) error {
6560
*mode = FullSync
6661
case "snap":
6762
*mode = SnapSync
68-
case "light":
69-
*mode = LightSync
7063
default:
71-
return fmt.Errorf(`unknown sync mode %q, want "full", "snap" or "light"`, text)
64+
return fmt.Errorf(`unknown sync mode %q, want "full" or "snap"`, text)
7265
}
7366
return nil
7467
}

eth/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
180180
return nil, errors.New("snap sync not supported with snapshots disabled")
181181
}
182182
// Construct the downloader (long sync)
183-
h.downloader = downloader.New(config.Database, h.eventMux, h.chain, nil, h.removePeer, h.enableSyncedFeatures)
183+
h.downloader = downloader.New(config.Database, h.eventMux, h.chain, h.removePeer, h.enableSyncedFeatures)
184184

185185
fetchTx := func(peer string, hashes []common.Hash) error {
186186
p := h.peers.peer(peer)

0 commit comments

Comments
 (0)