Skip to content

Commit

Permalink
qlight: refactor qlight config logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolae-leonte-go committed Mar 16, 2022
1 parent 6fe9787 commit 7834143
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 79 deletions.
36 changes: 5 additions & 31 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,36 +137,11 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
utils.Fatalf("%v", err)
}
}
if ctx.GlobalIsSet(utils.QuorumLightServerFlag.Name) {
cfg.Node.QP2P = &p2p.Config{
ListenAddr: ":30305",
MaxPeers: 10,
NAT: nil,
NoDial: true,
NoDiscovery: true,
}
}
if ctx.GlobalIsSet(utils.QuorumLightServerFlag.Name) {
cfg.Node.QP2P = &p2p.Config{
ListenAddr: ":30305",
MaxPeers: 10,
NAT: nil,
NoDial: true,
NoDiscovery: true,
}
}

// Apply flags.
utils.SetNodeConfig(ctx, &cfg.Node)
// TODO QLight - until DialCandidates is sorted add the server node url as a static node
if ctx.GlobalIsSet(utils.QuorumLightClientServerNodeFlag.Name) {
serverUrl := ctx.GlobalString(utils.QuorumLightClientServerNodeFlag.Name)
cfg.Node.P2P.StaticNodes = append(cfg.Node.P2P.StaticNodes, enode.MustParse(serverUrl))
// TODO QLight - must devise a way to warn that qlight client overrides settings like port/peers config
cfg.Node.P2P.MaxPeers = 1
// force the qlight client node to disable the local P2P listener
cfg.Node.P2P.ListenAddr = ""
}
utils.SetQLightConfig(ctx, &cfg.Node, &cfg.Eth)

stack, err := node.New(&cfg.Node)
if err != nil {
utils.Fatalf("Failed to create the protocol stack: %v", err)
Expand All @@ -176,7 +151,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
cfg.Ethstats.URL = ctx.GlobalString(utils.EthStatsURLFlag.Name)
}
applyMetricConfig(ctx, &cfg)
if ctx.GlobalIsSet(utils.QuorumLightServerFlag.Name) {
if cfg.Eth.QuorumLightServer {
p2p.SetQLightTLSConfig(readQLightServerTLSConfig(ctx))
// permissioning for the qlight P2P server
stack.QServer().SetNewTransportFunc(p2p.NewQlightServerTransport)
Expand All @@ -189,7 +164,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
stack.QServer().SetIsNodePermissioned(fbp.IsNodePermissionedEnode)
}
}
if ctx.GlobalIsSet(utils.QuorumLightClientFlag.Name) {
if cfg.Eth.QuorumLightClient {
p2p.SetQLightTLSConfig(readQLightClientTLSConfig(ctx))
stack.Server().SetNewTransportFunc(p2p.NewQlightClientTransport)
}
Expand All @@ -201,7 +176,6 @@ func readQLightClientTLSConfig(ctx *cli.Context) *tls.Config {
if !ctx.GlobalIsSet(utils.QuorumLightTLSFlag.Name) {
return nil
}
// TODO - QLight should this be mandatory. Maybe we can default to system ca certs.
if !ctx.GlobalIsSet(utils.QuorumLightTLSCACertsFlag.Name) {
utils.Fatalf("QLight tls flag is set but no client certificate authorities has been provided")
}
Expand Down Expand Up @@ -271,7 +245,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
utils.RegisterPermissionService(stack, ctx.Bool(utils.RaftDNSEnabledFlag.Name), backend.ChainConfig().ChainID)
}

if ctx.GlobalBool(utils.RaftModeFlag.Name) && !ctx.GlobalBool(utils.QuorumLightClientFlag.Name) {
if ctx.GlobalBool(utils.RaftModeFlag.Name) && !cfg.Eth.QuorumLightClient {
utils.RegisterRaftService(stack, ctx, &cfg.Node, ethService)
}

Expand Down
136 changes: 89 additions & 47 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ var (
}
QuorumLightTLSClientAuthFlag = cli.IntFlag{
Name: "qlight.tls.clientauth",
Usage: "The way the client is authenticated. Possible values: 0=NoClientCert(default) 1=tRequestClientCert 2=RequireAnyClientCert 3=VerifyClientCertIfGiven 4=RequireAndVerifyClientCert",
Usage: "The way the client is authenticated. Possible values: 0=NoClientCert(default) 1=RequestClientCert 2=RequireAnyClientCert 3=VerifyClientCertIfGiven 4=RequireAndVerifyClientCert",
Value: 0,
}
QuorumLightTLSCipherSuitesFlag = cli.StringFlag{
Expand Down Expand Up @@ -1872,6 +1872,87 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
}
}

func SetQLightConfig(ctx *cli.Context, nodeCfg *node.Config, ethCfg *ethconfig.Config) {
if ctx.GlobalIsSet(QuorumLightServerFlag.Name) {
ethCfg.QuorumLightServer = ctx.GlobalBool(QuorumLightServerFlag.Name)
}

if ethCfg.QuorumLightServer {
if nodeCfg.QP2P == nil {
nodeCfg.QP2P = &p2p.Config{
ListenAddr: ":30305",
MaxPeers: 10,
NAT: nil,
NoDial: true,
NoDiscovery: true,
}
SetQP2PConfig(ctx, nodeCfg.QP2P)
}
} else {
nodeCfg.QP2P = nil
}

if ctx.GlobalIsSet(QuorumLightClientFlag.Name) {
ethCfg.QuorumLightClient = ctx.GlobalBool(QuorumLightClientFlag.Name)
}

if len(ethCfg.QuorumLightClientPSI) == 0 {
ethCfg.QuorumLightClientPSI = "private"
}
if ctx.GlobalIsSet(QuorumLightClientPSIFlag.Name) {
ethCfg.QuorumLightClientPSI = ctx.GlobalString(QuorumLightClientPSIFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientTokenFlag.Name) {
ethCfg.QuorumLightClientToken = ctx.GlobalString(QuorumLightClientTokenFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientRPCTLSFlag.Name) {
ethCfg.QuorumLightClientRPCTLS = ctx.GlobalBool(QuorumLightClientRPCTLSFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientRPCTLSCACertFlag.Name) {
ethCfg.QuorumLightClientRPCTLSCACert = ctx.GlobalString(QuorumLightClientRPCTLSCACertFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientRPCTLSCertFlag.Name) && ctx.GlobalIsSet(QuorumLightClientRPCTLSKeyFlag.Name) {
ethCfg.QuorumLightClientRPCTLSCert = ctx.GlobalString(QuorumLightClientRPCTLSCertFlag.Name)
ethCfg.QuorumLightClientRPCTLSKey = ctx.GlobalString(QuorumLightClientRPCTLSKeyFlag.Name)
} else if ctx.GlobalIsSet(QuorumLightClientRPCTLSCertFlag.Name) {
Fatalf("'%s' specified without specifying '%s'", QuorumLightClientRPCTLSCertFlag.Name, QuorumLightClientRPCTLSKeyFlag.Name)
} else if ctx.GlobalIsSet(QuorumLightClientRPCTLSKeyFlag.Name) {
Fatalf("'%s' specified without specifying '%s'", QuorumLightClientRPCTLSKeyFlag.Name, QuorumLightClientRPCTLSCertFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientServerNodeRPCFlag.Name) {
ethCfg.QuorumLightClientServerNodeRPC = ctx.GlobalString(QuorumLightClientServerNodeRPCFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientServerNodeFlag.Name) {
ethCfg.QuorumLightClientServerNode = ctx.GlobalString(QuorumLightClientServerNodeFlag.Name)
// This is already done in geth/config - before the node.New invocation (at which point the StaticNodes is already copied)
//stack.Config().P2P.StaticNodes = []*enode.Node{enode.MustParse(ethCfg.QuorumLightClientServerNode)}
}

if ethCfg.QuorumLightClient {
if ctx.GlobalBool(MiningEnabledFlag.Name) {
Fatalf("QLight clients do not support mining")
}
if len(ethCfg.QuorumLightClientServerNode) == 0 {
Fatalf("Please specify the '%s' when running a qlight client.", QuorumLightClientServerNodeFlag.Name)
}
if len(ethCfg.QuorumLightClientServerNodeRPC) == 0 {
Fatalf("Please specify the '%s' when running a qlight client.", QuorumLightClientServerNodeRPCFlag.Name)
}

nodeCfg.P2P.StaticNodes = []*enode.Node{enode.MustParse(ethCfg.QuorumLightClientServerNode)}
log.Info("The node is configured to run as a qlight client. 'maxpeers' is overridden to `1` and the P2P listener is disabled.")
nodeCfg.P2P.MaxPeers = 1
// force the qlight client node to disable the local P2P listener
nodeCfg.P2P.ListenAddr = ""
}
}

// SetEthConfig applies eth-related command line flags to the config.
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
// Avoid conflicting network flags
Expand Down Expand Up @@ -1906,6 +1987,13 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(SyncModeFlag.Name) {
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
}

// Quorum
if cfg.QuorumLightClient && cfg.SyncMode != downloader.FullSync {
Fatalf("Only the 'full' syncmode is supported for the qlight client.")
}
// End Quorum

if ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
}
Expand Down Expand Up @@ -1996,52 +2084,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
}

cfg.QuorumLightServer = false
if ctx.GlobalIsSet(QuorumLightServerFlag.Name) {
cfg.QuorumLightServer = ctx.GlobalBool(QuorumLightServerFlag.Name)
}

cfg.QuorumLightClient = false
if ctx.GlobalIsSet(QuorumLightClientFlag.Name) {
cfg.QuorumLightClient = ctx.GlobalBool(QuorumLightClientFlag.Name)
}

// TODO qlight - maybe we should panic if any of these is missing
cfg.QuorumLightClientPSI = "private"
if ctx.GlobalIsSet(QuorumLightClientPSIFlag.Name) {
cfg.QuorumLightClientPSI = ctx.GlobalString(QuorumLightClientPSIFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientTokenFlag.Name) {
cfg.QuorumLightClientToken = ctx.GlobalString(QuorumLightClientTokenFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientRPCTLSFlag.Name) {
cfg.QuorumLightClientRPCTLS = ctx.GlobalBool(QuorumLightClientRPCTLSFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientRPCTLSCACertFlag.Name) {
cfg.QuorumLightClientRPCTLSCACert = ctx.GlobalString(QuorumLightClientRPCTLSCACertFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientRPCTLSCertFlag.Name) && ctx.GlobalIsSet(QuorumLightClientRPCTLSKeyFlag.Name) {
cfg.QuorumLightClientRPCTLSCert = ctx.GlobalString(QuorumLightClientRPCTLSCertFlag.Name)
cfg.QuorumLightClientRPCTLSKey = ctx.GlobalString(QuorumLightClientRPCTLSKeyFlag.Name)
} else if ctx.GlobalIsSet(QuorumLightClientRPCTLSCertFlag.Name) {
Fatalf("'%s' specified without specifying '%s'", QuorumLightClientRPCTLSCertFlag.Name, QuorumLightClientRPCTLSKeyFlag.Name)
} else if ctx.GlobalIsSet(QuorumLightClientRPCTLSKeyFlag.Name) {
Fatalf("'%s' specified without specifying '%s'", QuorumLightClientRPCTLSKeyFlag.Name, QuorumLightClientRPCTLSCertFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientServerNodeRPCFlag.Name) {
cfg.QuorumLightClientServerNodeRPC = ctx.GlobalString(QuorumLightClientServerNodeRPCFlag.Name)
}

if ctx.GlobalIsSet(QuorumLightClientServerNodeFlag.Name) {
cfg.QuorumLightClientServerNode = ctx.GlobalString(QuorumLightClientServerNodeFlag.Name)
stack.Config().P2P.StaticNodes = append(stack.Config().P2P.StaticNodes, enode.MustParse(cfg.QuorumLightClientServerNode))
}

// set immutability threshold in config
params.SetQuorumImmutabilityThreshold(ctx.GlobalInt(QuorumImmutabilityThreshold.Name))

Expand Down
1 change: 0 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData, eth.blockchain.Config().IsQuorum))

hexNodeId := fmt.Sprintf("%x", crypto.FromECDSAPub(&stack.GetNodeKey().PublicKey)[1:]) // Quorum
// TODO qlight rebase
if eth.config.QuorumLightClient {
var (
proxyClient *rpc.Client
Expand Down

0 comments on commit 7834143

Please sign in to comment.