Skip to content

Commit 865f7ce

Browse files
author
Qi Xiao
committed
Support miner config generation
1 parent e6484e6 commit 865f7ce

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

cmd/cql/internal/generate.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939

4040
// CmdGenerate is cql generate command entity.
4141
var CmdGenerate = &Command{
42-
UsageLine: "cql generate [common params] [-source template_file] [-private existing_private_key] [dest_path]",
42+
UsageLine: "cql generate [common params] [-source template_file] [-miner] [-private existing_private_key] [dest_path]",
4343
Short: "generate a folder contains config file and private key",
4444
Long: `
4545
Generate generates private.key and config.yaml for CovenantSQL.
@@ -56,12 +56,14 @@ or input a passphrase by
5656
var (
5757
privateKeyParam string
5858
source string
59+
minerListenAddr string
5960
)
6061

6162
func init() {
6263
CmdGenerate.Run = runGenerate
6364
CmdGenerate.Flag.StringVar(&privateKeyParam, "private", "", "custom private for config generation")
6465
CmdGenerate.Flag.StringVar(&source, "source", "", "source config file template for config generation")
66+
CmdGenerate.Flag.StringVar(&minerListenAddr, "miner", "", "generate miner config with specified listen address")
6567

6668
addCommonFlags(CmdGenerate)
6769
}
@@ -218,6 +220,9 @@ func runGenerate(cmd *Command, args []string) {
218220
if source == "" {
219221
// Load testnet config
220222
rawConfig = testnet.GetTestNetConfig()
223+
if minerListenAddr != "" {
224+
testnet.SetMinerConfig(rawConfig)
225+
}
221226
} else {
222227
// Load from template file
223228
sourceConfig, err := ioutil.ReadFile(source)
@@ -241,13 +246,18 @@ func runGenerate(cmd *Command, args []string) {
241246
if rawConfig.KnownNodes == nil {
242247
rawConfig.KnownNodes = make([]proto.Node, 0, 1)
243248
}
244-
rawConfig.KnownNodes = append(rawConfig.KnownNodes, proto.Node{
249+
node := proto.Node{
245250
ID: cliNodeID,
246251
Role: proto.Client,
247252
Addr: "0.0.0.0:15151",
248253
PublicKey: publicKey,
249254
Nonce: nonce.Nonce,
250-
})
255+
}
256+
if minerListenAddr != "" {
257+
node.Role = proto.Miner
258+
node.Addr = minerListenAddr
259+
}
260+
rawConfig.KnownNodes = append(rawConfig.KnownNodes, node)
251261

252262
// Write config
253263
out, err := yaml.Marshal(rawConfig)

conf/testnet/parameters.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ const (
3030
DNSSeed:
3131
Domain: "testnet.gridb.io"
3232
BPCount: 6
33+
`
34+
// CQLMinerYAML is the config string in YAML format of the CovenantSQL TestNet for miner.
35+
CQLMinerYAML = `
36+
BillingBlockCount: 60
37+
BPPeriod: 10s
38+
BPTick: 3s
39+
SQLChainPeriod: 60s
40+
SQLChainTick: 10s
41+
SQLChainTTL: 10
42+
ChainBusPeriod: 10s
43+
MinProviderDeposit: 1000000
44+
Miner:
45+
RootDir: './data'
46+
MaxReqTimeGap: '5m'
47+
ProvideServiceInterval: '10s'
3348
`
3449
)
3550

@@ -42,3 +57,15 @@ func GetTestNetConfig() (config *conf.Config) {
4257
}
4358
return
4459
}
60+
61+
// SetMinerConfig set testnet common config for miner.
62+
func SetMinerConfig(config *conf.Config) {
63+
if config == nil {
64+
return
65+
}
66+
var err error
67+
if err = yaml.Unmarshal([]byte(CQLMinerYAML), config); err != nil {
68+
log.WithError(err).Fatal("failed to unmarshal testnet miner config")
69+
}
70+
return
71+
}

0 commit comments

Comments
 (0)