mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
eth/downloader: panic if sync cycle configured with unknown sync mode. remove LightSync mode definition.
This commit is contained in:
parent
5b5023516c
commit
416ae197ad
2 changed files with 9 additions and 12 deletions
|
|
@ -201,6 +201,8 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
|
||||||
chainHead = d.blockchain.CurrentBlock()
|
chainHead = d.blockchain.CurrentBlock()
|
||||||
case SnapSync:
|
case SnapSync:
|
||||||
chainHead = d.blockchain.CurrentSnapBlock()
|
chainHead = d.blockchain.CurrentSnapBlock()
|
||||||
|
default:
|
||||||
|
panic("unknown sync mode")
|
||||||
}
|
}
|
||||||
number := chainHead.Number.Uint64()
|
number := chainHead.Number.Uint64()
|
||||||
|
|
||||||
|
|
@ -220,7 +222,7 @@ func (d *Downloader) findBeaconAncestor() (uint64, error) {
|
||||||
case SnapSync:
|
case SnapSync:
|
||||||
linked = d.blockchain.HasFastBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
|
linked = d.blockchain.HasFastBlock(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
|
||||||
default:
|
default:
|
||||||
linked = d.blockchain.HasHeader(beaconTail.ParentHash, beaconTail.Number.Uint64()-1)
|
panic("unknown sync mode")
|
||||||
}
|
}
|
||||||
if !linked {
|
if !linked {
|
||||||
// This is a programming error. The chain backfiller was called with a
|
// 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)
|
known = d.blockchain.HasBlock(h.Hash(), n)
|
||||||
case SnapSync:
|
case SnapSync:
|
||||||
known = d.blockchain.HasFastBlock(h.Hash(), n)
|
known = d.blockchain.HasFastBlock(h.Hash(), n)
|
||||||
|
default:
|
||||||
|
panic("unknown sync mode")
|
||||||
}
|
}
|
||||||
if !known {
|
if !known {
|
||||||
end = check
|
end = check
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,12 @@ import "fmt"
|
||||||
type SyncMode uint32
|
type SyncMode uint32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FullSync SyncMode = iota // Synchronise the entire blockchain history from full blocks
|
FullSync SyncMode = iota // Synchronise the entire blockchain history from full blocks
|
||||||
SnapSync // Download the chain and the state via compact snapshots
|
SnapSync // Download the chain and the state via compact snapshots
|
||||||
LightSync // Download only the headers and terminate afterwards
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (mode SyncMode) IsValid() bool {
|
func (mode SyncMode) IsValid() bool {
|
||||||
return mode >= FullSync && mode < LightSync
|
return mode == FullSync || mode == SnapSync
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements the stringer interface.
|
// String implements the stringer interface.
|
||||||
|
|
@ -39,8 +38,6 @@ func (mode SyncMode) String() string {
|
||||||
return "full"
|
return "full"
|
||||||
case SnapSync:
|
case SnapSync:
|
||||||
return "snap"
|
return "snap"
|
||||||
case LightSync:
|
|
||||||
return "light"
|
|
||||||
default:
|
default:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
@ -52,8 +49,6 @@ func (mode SyncMode) MarshalText() ([]byte, error) {
|
||||||
return []byte("full"), nil
|
return []byte("full"), nil
|
||||||
case SnapSync:
|
case SnapSync:
|
||||||
return []byte("snap"), nil
|
return []byte("snap"), nil
|
||||||
case LightSync:
|
|
||||||
return []byte("light"), nil
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown sync mode %d", mode)
|
return nil, fmt.Errorf("unknown sync mode %d", mode)
|
||||||
}
|
}
|
||||||
|
|
@ -65,10 +60,8 @@ func (mode *SyncMode) UnmarshalText(text []byte) error {
|
||||||
*mode = FullSync
|
*mode = FullSync
|
||||||
case "snap":
|
case "snap":
|
||||||
*mode = SnapSync
|
*mode = SnapSync
|
||||||
case "light":
|
|
||||||
*mode = LightSync
|
|
||||||
default:
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue