node: allow CHT config per sub-cluster
This commit is contained in:
parent
01fe421903
commit
c7ef35d414
32
geth/node.go
32
geth/node.go
|
@ -13,11 +13,13 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||||
"github.com/ethereum/go-ethereum/les"
|
"github.com/ethereum/go-ethereum/les"
|
||||||
|
"github.com/ethereum/go-ethereum/light"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
@ -158,6 +160,30 @@ func defaultEmbeddedNodeConfig(config *params.NodeConfig) *node.Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// updateCHT changes trusted canonical hash trie root
|
||||||
|
func updateCHT(eth *les.LightEthereum, config *params.NodeConfig) {
|
||||||
|
// 0xabaa042dec1ee30e0e8323d010a9c7d9a09b848631acdf66f66e966903b67755
|
||||||
|
bc := eth.BlockChain()
|
||||||
|
if bc.Genesis().Hash() == params.MainNetGenesisHash {
|
||||||
|
eth.WriteTrustedCht(light.TrustedCht{
|
||||||
|
Number: 805,
|
||||||
|
Root: common.HexToHash("85e4286fe0a730390245c49de8476977afdae0eb5530b277f62a52b12313d50f"),
|
||||||
|
})
|
||||||
|
log.Info("Added trusted CHT for mainnet")
|
||||||
|
}
|
||||||
|
if bc.Genesis().Hash() == params.RopstenNetGenesisHash {
|
||||||
|
root := "28bcafd5504326a34995efc36d3a9ba0b6a22f5832e8e58bacb646b54cb8911a"
|
||||||
|
if config.DevMode {
|
||||||
|
root = "abaa042dec1ee30e0e8323d010a9c7d9a09b848631acdf66f66e966903b67755"
|
||||||
|
}
|
||||||
|
eth.WriteTrustedCht(light.TrustedCht{
|
||||||
|
Number: 226,
|
||||||
|
Root: common.HexToHash(root),
|
||||||
|
})
|
||||||
|
log.Info("Added trusted CHT for Ropsten", "CHT", root)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// activateEthService configures and registers the eth.Ethereum service with a given node.
|
// activateEthService configures and registers the eth.Ethereum service with a given node.
|
||||||
func activateEthService(stack *node.Node, config *params.NodeConfig) error {
|
func activateEthService(stack *node.Node, config *params.NodeConfig) error {
|
||||||
if !config.LightEthConfig.Enabled {
|
if !config.LightEthConfig.Enabled {
|
||||||
|
@ -181,7 +207,11 @@ func activateEthService(stack *node.Node, config *params.NodeConfig) error {
|
||||||
ethConf.MaxPeers = config.MaxPeers
|
ethConf.MaxPeers = config.MaxPeers
|
||||||
ethConf.DatabaseHandles = makeDatabaseHandles()
|
ethConf.DatabaseHandles = makeDatabaseHandles()
|
||||||
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||||
return les.New(ctx, ðConf)
|
lightEth, err := les.New(ctx, ðConf)
|
||||||
|
if err == nil {
|
||||||
|
updateCHT(lightEth, config)
|
||||||
|
}
|
||||||
|
return lightEth, err
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("%v: %v", ErrLightEthRegistrationFailure, err)
|
return fmt.Errorf("%v: %v", ErrLightEthRegistrationFailure, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package params
|
package params
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ClientIdentifier is client identifier to advertise over the network
|
// ClientIdentifier is client identifier to advertise over the network
|
||||||
ClientIdentifier = "StatusIM"
|
ClientIdentifier = "StatusIM"
|
||||||
|
@ -83,3 +87,8 @@ const (
|
||||||
// BootClusterConfigFile is default config file containing boot node list (as JSON array)
|
// BootClusterConfigFile is default config file containing boot node list (as JSON array)
|
||||||
BootClusterConfigFile = "ropsten.dev.json"
|
BootClusterConfigFile = "ropsten.dev.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
RopstenNetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d") // Testnet genesis hash to enforce below configs on
|
||||||
|
MainNetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3") // Mainnet genesis hash to enforce below configs on
|
||||||
|
)
|
||||||
|
|
|
@ -217,3 +217,8 @@ func (s *LightEthereum) Stop() error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteTrustedCht writes trusted CHT root
|
||||||
|
func (s *LightEthereum) WriteTrustedCht(cht light.TrustedCht) {
|
||||||
|
light.WriteTrustedCht(s.chainDb, cht)
|
||||||
|
}
|
||||||
|
|
|
@ -99,11 +99,6 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.
|
||||||
WriteTrustedCht(bc.chainDb, TrustedCht{Number: 805, Root: common.HexToHash("85e4286fe0a730390245c49de8476977afdae0eb5530b277f62a52b12313d50f")})
|
WriteTrustedCht(bc.chainDb, TrustedCht{Number: 805, Root: common.HexToHash("85e4286fe0a730390245c49de8476977afdae0eb5530b277f62a52b12313d50f")})
|
||||||
log.Info("Added trusted CHT for mainnet")
|
log.Info("Added trusted CHT for mainnet")
|
||||||
}
|
}
|
||||||
if bc.genesisBlock.Hash() == params.TestNetGenesisHash {
|
|
||||||
// add trusted CHT
|
|
||||||
WriteTrustedCht(bc.chainDb, TrustedCht{Number: 226, Root: common.HexToHash("28bcafd5504326a34995efc36d3a9ba0b6a22f5832e8e58bacb646b54cb8911a")})
|
|
||||||
log.Info("Added trusted CHT for testnet")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := bc.loadLastState(); err != nil {
|
if err := bc.loadLastState(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue