From 416ae197ad6490db03a5159349d214c484179325 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 6 May 2024 06:24:49 -0700 Subject: [PATCH] eth/downloader: panic if sync cycle configured with unknown sync mode. remove LightSync mode definition. --- eth/downloader/beaconsync.go | 6 +++++- eth/downloader/modes.go | 15 ++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/eth/downloader/beaconsync.go b/eth/downloader/beaconsync.go index 3ce78b046c..57c6eee40a 100644 --- a/eth/downloader/beaconsync.go +++ b/eth/downloader/beaconsync.go @@ -201,6 +201,8 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) { chainHead = d.blockchain.CurrentBlock() case SnapSync: chainHead = d.blockchain.CurrentSnapBlock() + default: + panic("unknown sync mode") } number := chainHead.Number.Uint64() @@ -220,7 +222,7 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) { case SnapSync: linked = d.blockchain.HasFastBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1) default: - linked = d.blockchain.HasHeader(beaconTail.ParentHash, beaconTail.Number.Uint64()-1) + panic("unknown sync mode") } if !linked { // This is a programming error. The chain backfiller was called with a @@ -254,6 +256,8 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) { known = d.blockchain.HasBlock(h.Hash(), n) case SnapSync: known = d.blockchain.HasFastBlock(h.Hash(), n) + default: + panic("unknown sync mode") } if !known { end = check diff --git a/eth/downloader/modes.go b/eth/downloader/modes.go index 7de908849e..9d8e1f313c 100644 --- a/eth/downloader/modes.go +++ b/eth/downloader/modes.go @@ -23,13 +23,12 @@ import "fmt" type SyncMode uint32 const ( - FullSync SyncMode = iota // Synchronise the entire blockchain history from full blocks - SnapSync // Download the chain and the state via compact snapshots - LightSync // Download only the headers and terminate afterwards + FullSync SyncMode = iota // Synchronise the entire blockchain history from full blocks + SnapSync // Download the chain and the state via compact snapshots ) func (mode SyncMode) IsValid() bool { - return mode >= FullSync && mode < LightSync + return mode == FullSync || mode == SnapSync } // String implements the stringer interface. @@ -39,8 +38,6 @@ func (mode SyncMode) String() string { return "full" case SnapSync: return "snap" - case LightSync: - return "light" default: return "unknown" } @@ -52,8 +49,6 @@ func (mode SyncMode) MarshalText() ([]byte, error) { return []byte("full"), nil case SnapSync: return []byte("snap"), nil - case LightSync: - return []byte("light"), nil default: return nil, fmt.Errorf("unknown sync mode %d", mode) } @@ -65,10 +60,8 @@ func (mode *SyncMode) UnmarshalText(text []byte) error { *mode = FullSync case "snap": *mode = SnapSync - case "light": - *mode = LightSync default: - return fmt.Errorf(`unknown sync mode %q, want "full", "snap" or "light"`, text) + return fmt.Errorf(`unknown sync mode %q, want "full" or "snap"`, text) } return nil }