mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd, eth, les, params: address comments
This commit is contained in:
parent
1e51c9a14f
commit
75be69752d
10 changed files with 53 additions and 40 deletions
|
|
@ -1468,34 +1468,16 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||||
cfg.NetworkId = 3
|
cfg.NetworkId = 3
|
||||||
}
|
}
|
||||||
cfg.Genesis = core.DefaultTestnetGenesisBlock()
|
cfg.Genesis = core.DefaultTestnetGenesisBlock()
|
||||||
// Only override default checkpoint so that user can customize checkpoint
|
|
||||||
// by themselves.
|
|
||||||
if cfg.Checkpoint == eth.DefaultConfig.Checkpoint {
|
|
||||||
cfg.Checkpoint = params.TestnetTrustedCheckpoint
|
|
||||||
}
|
|
||||||
case ctx.GlobalBool(RinkebyFlag.Name):
|
case ctx.GlobalBool(RinkebyFlag.Name):
|
||||||
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
||||||
cfg.NetworkId = 4
|
cfg.NetworkId = 4
|
||||||
}
|
}
|
||||||
cfg.Genesis = core.DefaultRinkebyGenesisBlock()
|
cfg.Genesis = core.DefaultRinkebyGenesisBlock()
|
||||||
// Only override default checkpoint so that user can customize checkpoint
|
|
||||||
// by themselves.
|
|
||||||
if cfg.Checkpoint == eth.DefaultConfig.Checkpoint {
|
|
||||||
cfg.Checkpoint = params.RinkebyTrustedCheckpoint
|
|
||||||
}
|
|
||||||
if cfg.CheckpointConfig == nil {
|
|
||||||
cfg.CheckpointConfig = params.RinkebyCheckpointConfig // Enable checkpoint contract for rinkeby testnet.
|
|
||||||
}
|
|
||||||
case ctx.GlobalBool(GoerliFlag.Name):
|
case ctx.GlobalBool(GoerliFlag.Name):
|
||||||
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
||||||
cfg.NetworkId = 5
|
cfg.NetworkId = 5
|
||||||
}
|
}
|
||||||
cfg.Genesis = core.DefaultGoerliGenesisBlock()
|
cfg.Genesis = core.DefaultGoerliGenesisBlock()
|
||||||
// Only override default checkpoint so that user can customize checkpoint
|
|
||||||
// by themselves.
|
|
||||||
if cfg.Checkpoint == eth.DefaultConfig.Checkpoint {
|
|
||||||
cfg.Checkpoint = params.GoerliTrustedCheckpoint
|
|
||||||
}
|
|
||||||
case ctx.GlobalBool(DeveloperFlag.Name):
|
case ctx.GlobalBool(DeveloperFlag.Name):
|
||||||
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
||||||
cfg.NetworkId = 1337
|
cfg.NetworkId = 1337
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,10 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
|
|
||||||
// Permit the downloader to use the trie cache allowance during fast sync
|
// Permit the downloader to use the trie cache allowance during fast sync
|
||||||
cacheLimit := cacheConfig.TrieCleanLimit + cacheConfig.TrieDirtyLimit
|
cacheLimit := cacheConfig.TrieCleanLimit + cacheConfig.TrieDirtyLimit
|
||||||
|
checkpoint := config.Checkpoint
|
||||||
|
if checkpoint == nil {
|
||||||
|
checkpoint, _ = params.TrustedCheckpoints[genesisHash]
|
||||||
|
}
|
||||||
if eth.protocolManager, err = NewProtocolManager(chainConfig, config.Checkpoint, config.SyncMode, config.NetworkId, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb, cacheLimit, config.Whitelist); err != nil {
|
if eth.protocolManager, err = NewProtocolManager(chainConfig, config.Checkpoint, config.SyncMode, config.NetworkId, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb, cacheLimit, config.Whitelist); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,6 @@ var DefaultConfig = Config{
|
||||||
Blocks: 20,
|
Blocks: 20,
|
||||||
Percentile: 60,
|
Percentile: 60,
|
||||||
},
|
},
|
||||||
Checkpoint: params.MainnetTrustedCheckpoint,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -154,6 +153,6 @@ type Config struct {
|
||||||
// Checkpoint is a hardcoded checkpoint which can be nil.
|
// Checkpoint is a hardcoded checkpoint which can be nil.
|
||||||
Checkpoint *params.TrustedCheckpoint
|
Checkpoint *params.TrustedCheckpoint
|
||||||
|
|
||||||
// CheckpointConfig is a set of checkpoint contract configs.
|
// CheckpointOracle is the configuration for checkpoint oracle.
|
||||||
CheckpointConfig *params.CheckpointContractConfig
|
CheckpointOracle *params.CheckpointOracleConfig
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
ConstantinopleOverride *big.Int
|
ConstantinopleOverride *big.Int
|
||||||
RPCGasCap *big.Int `toml:",omitempty"`
|
RPCGasCap *big.Int `toml:",omitempty"`
|
||||||
Checkpoint *params.TrustedCheckpoint
|
Checkpoint *params.TrustedCheckpoint
|
||||||
CheckpointConfig *params.CheckpointContractConfig
|
CheckpointOracle *params.CheckpointOracleConfig
|
||||||
}
|
}
|
||||||
var enc Config
|
var enc Config
|
||||||
enc.Genesis = c.Genesis
|
enc.Genesis = c.Genesis
|
||||||
|
|
@ -81,7 +81,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
enc.ConstantinopleOverride = c.ConstantinopleOverride
|
enc.ConstantinopleOverride = c.ConstantinopleOverride
|
||||||
enc.RPCGasCap = c.RPCGasCap
|
enc.RPCGasCap = c.RPCGasCap
|
||||||
enc.Checkpoint = c.Checkpoint
|
enc.Checkpoint = c.Checkpoint
|
||||||
enc.CheckpointConfig = c.CheckpointConfig
|
enc.CheckpointOracle = c.CheckpointOracle
|
||||||
return &enc, nil
|
return &enc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,7 +118,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
ConstantinopleOverride *big.Int
|
ConstantinopleOverride *big.Int
|
||||||
RPCGasCap *big.Int `toml:",omitempty"`
|
RPCGasCap *big.Int `toml:",omitempty"`
|
||||||
Checkpoint *params.TrustedCheckpoint
|
Checkpoint *params.TrustedCheckpoint
|
||||||
CheckpointConfig *params.CheckpointContractConfig
|
CheckpointOracle *params.CheckpointOracleConfig
|
||||||
}
|
}
|
||||||
var dec Config
|
var dec Config
|
||||||
if err := unmarshal(&dec); err != nil {
|
if err := unmarshal(&dec); err != nil {
|
||||||
|
|
@ -214,8 +214,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
if dec.Checkpoint != nil {
|
if dec.Checkpoint != nil {
|
||||||
c.Checkpoint = dec.Checkpoint
|
c.Checkpoint = dec.Checkpoint
|
||||||
}
|
}
|
||||||
if dec.CheckpointConfig != nil {
|
if dec.CheckpointOracle != nil {
|
||||||
c.CheckpointConfig = dec.CheckpointConfig
|
c.CheckpointOracle = dec.CheckpointOracle
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,9 +124,13 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
|
||||||
leth.bloomTrieIndexer = light.NewBloomTrieIndexer(chainDb, leth.odr, params.BloomBitsBlocksClient, params.BloomTrieFrequency)
|
leth.bloomTrieIndexer = light.NewBloomTrieIndexer(chainDb, leth.odr, params.BloomBitsBlocksClient, params.BloomTrieFrequency)
|
||||||
leth.odr.SetIndexers(leth.chtIndexer, leth.bloomTrieIndexer, leth.bloomIndexer)
|
leth.odr.SetIndexers(leth.chtIndexer, leth.bloomTrieIndexer, leth.bloomIndexer)
|
||||||
|
|
||||||
|
checkpoint := config.Checkpoint
|
||||||
|
if checkpoint == nil {
|
||||||
|
checkpoint, _ = params.TrustedCheckpoints[genesisHash]
|
||||||
|
}
|
||||||
// Note: NewLightChain adds the trusted checkpoint so it needs an ODR with
|
// Note: NewLightChain adds the trusted checkpoint so it needs an ODR with
|
||||||
// indexers already set but not started yet
|
// indexers already set but not started yet
|
||||||
if leth.blockchain, err = light.NewLightChain(leth.odr, leth.chainConfig, leth.engine, config.Checkpoint); err != nil {
|
if leth.blockchain, err = light.NewLightChain(leth.odr, leth.chainConfig, leth.engine, checkpoint); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Note: AddChildIndexer starts the update process for the child
|
// Note: AddChildIndexer starts the update process for the child
|
||||||
|
|
@ -150,8 +154,12 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
|
||||||
}
|
}
|
||||||
leth.ApiBackend.gpo = gasprice.NewOracle(leth.ApiBackend, gpoParams)
|
leth.ApiBackend.gpo = gasprice.NewOracle(leth.ApiBackend, gpoParams)
|
||||||
|
|
||||||
registrar := newCheckpointRegistrar(config.CheckpointConfig, leth.getLocalCheckpoint)
|
oracle := config.CheckpointOracle
|
||||||
if leth.protocolManager, err = NewProtocolManager(leth.chainConfig, config.Checkpoint, light.DefaultClientIndexerConfig, config.ULC, true, config.NetworkId, leth.eventMux, leth.peers, leth.blockchain, nil, chainDb, leth.odr, leth.serverPool, registrar, quitSync, &leth.wg, nil); err != nil {
|
if oracle == nil {
|
||||||
|
oracle, _ = params.CheckpointOracles[genesisHash]
|
||||||
|
}
|
||||||
|
registrar := newCheckpointRegistrar(oracle, leth.getLocalCheckpoint)
|
||||||
|
if leth.protocolManager, err = NewProtocolManager(leth.chainConfig, checkpoint, light.DefaultClientIndexerConfig, config.ULC, true, config.NetworkId, leth.eventMux, leth.peers, leth.blockchain, nil, chainDb, leth.odr, leth.serverPool, registrar, quitSync, &leth.wg, nil); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if leth.protocolManager.isULCEnabled() {
|
if leth.protocolManager.isULCEnabled() {
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ func newTestProtocolManager(lightSync bool, blocks int, odr *LesOdr, indexers []
|
||||||
if lightSync {
|
if lightSync {
|
||||||
indexConfig = light.TestClientIndexerConfig
|
indexConfig = light.TestClientIndexerConfig
|
||||||
}
|
}
|
||||||
config := ¶ms.CheckpointContractConfig{
|
config := ¶ms.CheckpointOracleConfig{
|
||||||
Address: crypto.CreateAddress(bankAddr, 0),
|
Address: crypto.CreateAddress(bankAddr, 0),
|
||||||
Signers: []common.Address{signerAddr},
|
Signers: []common.Address{signerAddr},
|
||||||
Threshold: 1,
|
Threshold: 1,
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import (
|
||||||
// generated and announced by the contract admins on-chain. The checkpoint is
|
// generated and announced by the contract admins on-chain. The checkpoint is
|
||||||
// verified by clients locally during the checkpoint syncing.
|
// verified by clients locally during the checkpoint syncing.
|
||||||
type checkpointRegistrar struct {
|
type checkpointRegistrar struct {
|
||||||
config *params.CheckpointContractConfig
|
config *params.CheckpointOracleConfig
|
||||||
contract *registrar.Registrar
|
contract *registrar.Registrar
|
||||||
|
|
||||||
// Whether the contract backend is set.
|
// Whether the contract backend is set.
|
||||||
|
|
@ -44,7 +44,7 @@ type checkpointRegistrar struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newCheckpointRegistrar returns a checkpoint registrar handler.
|
// newCheckpointRegistrar returns a checkpoint registrar handler.
|
||||||
func newCheckpointRegistrar(config *params.CheckpointContractConfig, getLocal func(uint64) params.TrustedCheckpoint) *checkpointRegistrar {
|
func newCheckpointRegistrar(config *params.CheckpointOracleConfig, getLocal func(uint64) params.TrustedCheckpoint) *checkpointRegistrar {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
log.Info("Checkpoint registrar is not enabled")
|
log.Info("Checkpoint registrar is not enabled")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -120,8 +120,13 @@ func NewLesServer(e *eth.Ethereum, config *eth.Config) (*LesServer, error) {
|
||||||
|
|
||||||
srv.chtIndexer.Start(e.BlockChain())
|
srv.chtIndexer.Start(e.BlockChain())
|
||||||
|
|
||||||
registrar := newCheckpointRegistrar(config.CheckpointConfig, srv.getLocalCheckpoint)
|
oracle := config.CheckpointOracle
|
||||||
pm, err := NewProtocolManager(e.BlockChain().Config(), config.Checkpoint, light.DefaultServerIndexerConfig, config.ULC, false, config.NetworkId, e.EventMux(), newPeerSet(), e.BlockChain(), e.TxPool(), e.ChainDb(), nil, nil, registrar, quitSync, new(sync.WaitGroup), e.Synced)
|
if oracle == nil {
|
||||||
|
oracle, _ = params.CheckpointOracles[e.BlockChain().Genesis().Hash()]
|
||||||
|
}
|
||||||
|
registrar := newCheckpointRegistrar(oracle, srv.getLocalCheckpoint)
|
||||||
|
// TODO(rjl493456442) Checkpoint is useless for les server, separate handler for client and server.
|
||||||
|
pm, err := NewProtocolManager(e.BlockChain().Config(), nil, light.DefaultServerIndexerConfig, config.ULC, false, config.NetworkId, e.EventMux(), newPeerSet(), e.BlockChain(), e.TxPool(), e.ChainDb(), nil, nil, registrar, quitSync, new(sync.WaitGroup), e.Synced)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
|
||||||
log.Debug("Disable checkpoint syncing", "reason", "empty checkpoint")
|
log.Debug("Disable checkpoint syncing", "reason", "empty checkpoint")
|
||||||
case latest.Number.Uint64() >= (checkpoint.SectionIndex+1)*pm.iConfig.ChtSize-1:
|
case latest.Number.Uint64() >= (checkpoint.SectionIndex+1)*pm.iConfig.ChtSize-1:
|
||||||
mode = lightSync
|
mode = lightSync
|
||||||
log.Debug("Disable checkpoint syncing", "reason", "local chain beyonds the checkpoint")
|
log.Debug("Disable checkpoint syncing", "reason", "local chain beyond the checkpoint")
|
||||||
case hardcoded:
|
case hardcoded:
|
||||||
mode = legacyCheckpointSync
|
mode = legacyCheckpointSync
|
||||||
log.Debug("Disable checkpoint syncing", "reason", "checkpoint is hardcoded")
|
log.Debug("Disable checkpoint syncing", "reason", "checkpoint is hardcoded")
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,21 @@ var (
|
||||||
GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
|
GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TrustedCheckpoints associates each known checkpoint with the genesis hash of
|
||||||
|
// the chain it belongs to.
|
||||||
|
var TrustedCheckpoints = map[common.Hash]*TrustedCheckpoint{
|
||||||
|
MainnetGenesisHash: MainnetTrustedCheckpoint,
|
||||||
|
TestnetGenesisHash: TestnetTrustedCheckpoint,
|
||||||
|
RinkebyGenesisHash: RinkebyTrustedCheckpoint,
|
||||||
|
GoerliGenesisHash: GoerliTrustedCheckpoint,
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckpointOracles associates each known checkpoint oracles with the genesis hash of
|
||||||
|
// the chain it belongs to.
|
||||||
|
var CheckpointOracles = map[common.Hash]*CheckpointOracleConfig{
|
||||||
|
RinkebyGenesisHash: RinkebyCheckpointOracleConfig,
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// MainnetChainConfig is the chain parameters to run a node on the main network.
|
// MainnetChainConfig is the chain parameters to run a node on the main network.
|
||||||
MainnetChainConfig = &ChainConfig{
|
MainnetChainConfig = &ChainConfig{
|
||||||
|
|
@ -109,8 +124,8 @@ var (
|
||||||
BloomRoot: common.HexToHash("0xa3048fe8b7e30f77f11bc755a88478363d7d3e71c2bdfe4e8ab9e269cd804ba2"),
|
BloomRoot: common.HexToHash("0xa3048fe8b7e30f77f11bc755a88478363d7d3e71c2bdfe4e8ab9e269cd804ba2"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// RinkebyCheckpointConfig contains a set of checkpoint contract configs for the Rinkeby test network.
|
// RinkebyCheckpointOracleConfig contains a set of configs for the Rinkeby test network oracle.
|
||||||
RinkebyCheckpointConfig = &CheckpointContractConfig{
|
RinkebyCheckpointOracleConfig = &CheckpointOracleConfig{
|
||||||
Address: common.HexToAddress("0x62652ed8e969ce7bd5e3dd13590efa1e569215f1"),
|
Address: common.HexToAddress("0x62652ed8e969ce7bd5e3dd13590efa1e569215f1"),
|
||||||
Signers: []common.Address{
|
Signers: []common.Address{
|
||||||
common.HexToAddress("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"), // Peter
|
common.HexToAddress("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"), // Peter
|
||||||
|
|
@ -199,9 +214,9 @@ func (c *TrustedCheckpoint) Empty() bool {
|
||||||
return c.SectionHead == (common.Hash{}) || c.CHTRoot == (common.Hash{}) || c.BloomRoot == (common.Hash{})
|
return c.SectionHead == (common.Hash{}) || c.CHTRoot == (common.Hash{}) || c.BloomRoot == (common.Hash{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckpointContractConfig represents a set of checkpoint contract config
|
// CheckpointOracleConfig represents a set of checkpoint contract(which acts as an oracle)
|
||||||
// which used for light client checkpoint syncing.
|
// config which used for light client checkpoint syncing.
|
||||||
type CheckpointContractConfig struct {
|
type CheckpointOracleConfig struct {
|
||||||
Address common.Address `json:"address"`
|
Address common.Address `json:"address"`
|
||||||
Signers []common.Address `json:"signers"`
|
Signers []common.Address `json:"signers"`
|
||||||
Threshold uint64 `json:"threshold"`
|
Threshold uint64 `json:"threshold"`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue