cmd, eth: fix required blocks regression

This commit is contained in:
Péter Szilágyi 2022-05-04 19:55:17 +03:00
parent 0a9e384cd5
commit ecae8e4f65
No known key found for this signature in database
GPG Key ID: E9AE538CEDF8293D
7 changed files with 55 additions and 58 deletions

View File

@ -105,7 +105,7 @@ var (
utils.UltraLightFractionFlag, utils.UltraLightFractionFlag,
utils.UltraLightOnlyAnnounceFlag, utils.UltraLightOnlyAnnounceFlag,
utils.LightNoSyncServeFlag, utils.LightNoSyncServeFlag,
utils.EthPeerRequiredBlocksFlag, utils.EthRequiredBlocksFlag,
utils.LegacyWhitelistFlag, utils.LegacyWhitelistFlag,
utils.BloomFilterSizeFlag, utils.BloomFilterSizeFlag,
utils.CacheFlag, utils.CacheFlag,

View File

@ -46,7 +46,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.EthStatsURLFlag, utils.EthStatsURLFlag,
utils.IdentityFlag, utils.IdentityFlag,
utils.LightKDFFlag, utils.LightKDFFlag,
utils.EthPeerRequiredBlocksFlag, utils.EthRequiredBlocksFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags), }, utils.NetworkFlags, utils.DatabasePathFlags),
}, },
{ {

View File

@ -240,13 +240,13 @@ var (
Name: "lightkdf", Name: "lightkdf",
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength", Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
} }
EthPeerRequiredBlocksFlag = cli.StringFlag{ EthRequiredBlocksFlag = cli.StringFlag{
Name: "eth.requiredblocks", Name: "eth.requiredblocks",
Usage: "Comma separated block number-to-hash mappings to require for peering (<number>=<hash>)", Usage: "Comma separated block number-to-hash mappings to require for peering (<number>=<hash>)",
} }
LegacyWhitelistFlag = cli.StringFlag{ LegacyWhitelistFlag = cli.StringFlag{
Name: "whitelist", Name: "whitelist",
Usage: "Comma separated block number-to-hash mappings to enforce (<number>=<hash>) (deprecated in favor of --peer.requiredblocks)", Usage: "Comma separated block number-to-hash mappings to enforce (<number>=<hash>) (deprecated in favor of --eth.requiredblocks)",
} }
BloomFilterSizeFlag = cli.Uint64Flag{ BloomFilterSizeFlag = cli.Uint64Flag{
Name: "bloomfilter.size", Name: "bloomfilter.size",
@ -1501,33 +1501,31 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
} }
} }
func setPeerRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) { func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) {
peerRequiredBlocks := ctx.GlobalString(EthPeerRequiredBlocksFlag.Name) requiredBlocks := ctx.GlobalString(EthRequiredBlocksFlag.Name)
if requiredBlocks == "" {
if peerRequiredBlocks == "" {
if ctx.GlobalIsSet(LegacyWhitelistFlag.Name) { if ctx.GlobalIsSet(LegacyWhitelistFlag.Name) {
log.Warn("The flag --rpc is deprecated and will be removed, please use --peer.requiredblocks") log.Warn("The flag --whitelist is deprecated and will be removed, please use --eth.requiredblocks")
peerRequiredBlocks = ctx.GlobalString(LegacyWhitelistFlag.Name) requiredBlocks = ctx.GlobalString(LegacyWhitelistFlag.Name)
} else { } else {
return return
} }
} }
cfg.RequiredBlocks = make(map[uint64]common.Hash)
cfg.PeerRequiredBlocks = make(map[uint64]common.Hash) for _, entry := range strings.Split(requiredBlocks, ",") {
for _, entry := range strings.Split(peerRequiredBlocks, ",") {
parts := strings.Split(entry, "=") parts := strings.Split(entry, "=")
if len(parts) != 2 { if len(parts) != 2 {
Fatalf("Invalid peer required block entry: %s", entry) Fatalf("Invalid required block entry: %s", entry)
} }
number, err := strconv.ParseUint(parts[0], 0, 64) number, err := strconv.ParseUint(parts[0], 0, 64)
if err != nil { if err != nil {
Fatalf("Invalid peer required block number %s: %v", parts[0], err) Fatalf("Invalid required block number %s: %v", parts[0], err)
} }
var hash common.Hash var hash common.Hash
if err = hash.UnmarshalText([]byte(parts[1])); err != nil { if err = hash.UnmarshalText([]byte(parts[1])); err != nil {
Fatalf("Invalid peer required block hash %s: %v", parts[1], err) Fatalf("Invalid required block hash %s: %v", parts[1], err)
} }
cfg.PeerRequiredBlocks[number] = hash cfg.RequiredBlocks[number] = hash
} }
} }
@ -1594,7 +1592,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
setTxPool(ctx, &cfg.TxPool) setTxPool(ctx, &cfg.TxPool)
setEthash(ctx, cfg) setEthash(ctx, cfg)
setMiner(ctx, &cfg.Miner) setMiner(ctx, &cfg.Miner)
setPeerRequiredBlocks(ctx, cfg) setRequiredBlocks(ctx, cfg)
setLes(ctx, cfg) setLes(ctx, cfg)
// Cap the cache allowance and tune the garbage collector // Cap the cache allowance and tune the garbage collector

View File

@ -229,7 +229,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
BloomCache: uint64(cacheLimit), BloomCache: uint64(cacheLimit),
EventMux: eth.eventMux, EventMux: eth.eventMux,
Checkpoint: checkpoint, Checkpoint: checkpoint,
PeerRequiredBlocks: config.PeerRequiredBlocks, RequiredBlocks: config.RequiredBlocks,
}); err != nil { }); err != nil {
return nil, err return nil, err
} }

View File

@ -138,10 +138,10 @@ type Config struct {
TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
// PeerRequiredBlocks is a set of block number -> hash mappings which must be in the // RequiredBlocks is a set of block number -> hash mappings which must be in the
// canonical chain of all remote peers. Setting the option makes geth verify the // canonical chain of all remote peers. Setting the option makes geth verify the
// presence of these blocks for every new peer connection. // presence of these blocks for every new peer connection.
PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` RequiredBlocks map[uint64]common.Hash `toml:"-"`
// Light client options // Light client options
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests

View File

@ -26,7 +26,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
NoPruning bool NoPruning bool
NoPrefetch bool NoPrefetch bool
TxLookupLimit uint64 `toml:",omitempty"` TxLookupLimit uint64 `toml:",omitempty"`
PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` RequiredBlocks map[uint64]common.Hash `toml:"-"`
LightServ int `toml:",omitempty"` LightServ int `toml:",omitempty"`
LightIngress int `toml:",omitempty"` LightIngress int `toml:",omitempty"`
LightEgress int `toml:",omitempty"` LightEgress int `toml:",omitempty"`
@ -71,7 +71,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.NoPruning = c.NoPruning enc.NoPruning = c.NoPruning
enc.NoPrefetch = c.NoPrefetch enc.NoPrefetch = c.NoPrefetch
enc.TxLookupLimit = c.TxLookupLimit enc.TxLookupLimit = c.TxLookupLimit
enc.PeerRequiredBlocks = c.PeerRequiredBlocks enc.RequiredBlocks = c.RequiredBlocks
enc.LightServ = c.LightServ enc.LightServ = c.LightServ
enc.LightIngress = c.LightIngress enc.LightIngress = c.LightIngress
enc.LightEgress = c.LightEgress enc.LightEgress = c.LightEgress
@ -120,7 +120,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
NoPruning *bool NoPruning *bool
NoPrefetch *bool NoPrefetch *bool
TxLookupLimit *uint64 `toml:",omitempty"` TxLookupLimit *uint64 `toml:",omitempty"`
PeerRequiredBlocks map[uint64]common.Hash `toml:"-"` RequiredBlocks map[uint64]common.Hash `toml:"-"`
LightServ *int `toml:",omitempty"` LightServ *int `toml:",omitempty"`
LightIngress *int `toml:",omitempty"` LightIngress *int `toml:",omitempty"`
LightEgress *int `toml:",omitempty"` LightEgress *int `toml:",omitempty"`
@ -184,8 +184,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.TxLookupLimit != nil { if dec.TxLookupLimit != nil {
c.TxLookupLimit = *dec.TxLookupLimit c.TxLookupLimit = *dec.TxLookupLimit
} }
if dec.PeerRequiredBlocks != nil { if dec.RequiredBlocks != nil {
c.PeerRequiredBlocks = dec.PeerRequiredBlocks c.RequiredBlocks = dec.RequiredBlocks
} }
if dec.LightServ != nil { if dec.LightServ != nil {
c.LightServ = *dec.LightServ c.LightServ = *dec.LightServ

View File

@ -86,8 +86,7 @@ type handlerConfig struct {
BloomCache uint64 // Megabytes to alloc for snap sync bloom BloomCache uint64 // Megabytes to alloc for snap sync bloom
EventMux *event.TypeMux // Legacy event mux, deprecate for `feed` EventMux *event.TypeMux // Legacy event mux, deprecate for `feed`
Checkpoint *params.TrustedCheckpoint // Hard coded checkpoint for sync challenges Checkpoint *params.TrustedCheckpoint // Hard coded checkpoint for sync challenges
RequiredBlocks map[uint64]common.Hash // Hard coded map of required block hashes for sync challenges
PeerRequiredBlocks map[uint64]common.Hash // Hard coded map of required block hashes for sync challenges
} }
type handler struct { type handler struct {
@ -116,7 +115,7 @@ type handler struct {
txsSub event.Subscription txsSub event.Subscription
minedBlockSub *event.TypeMuxSubscription minedBlockSub *event.TypeMuxSubscription
peerRequiredBlocks map[uint64]common.Hash requiredBlocks map[uint64]common.Hash
// channels for fetcher, syncer, txsyncLoop // channels for fetcher, syncer, txsyncLoop
quitSync chan struct{} quitSync chan struct{}
@ -141,7 +140,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
chain: config.Chain, chain: config.Chain,
peers: newPeerSet(), peers: newPeerSet(),
merger: config.Merger, merger: config.Merger,
peerRequiredBlocks: config.PeerRequiredBlocks, requiredBlocks: config.RequiredBlocks,
quitSync: make(chan struct{}), quitSync: make(chan struct{}),
} }
if config.Sync == downloader.FullSync { if config.Sync == downloader.FullSync {
@ -425,7 +424,7 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error {
}() }()
} }
// If we have any explicit peer required block hashes, request them // If we have any explicit peer required block hashes, request them
for number := range h.peerRequiredBlocks { for number, hash := range h.requiredBlocks {
resCh := make(chan *eth.Response) resCh := make(chan *eth.Response)
if _, err := peer.RequestHeadersByNumber(number, 1, 0, false, resCh); err != nil { if _, err := peer.RequestHeadersByNumber(number, 1, 0, false, resCh); err != nil {
return err return err