Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/docker-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ miner)
blockproducer)
exec /app/cqld -config "${COVENANT_CONF}" -metric-web "${METRIC_WEB_ADDR}" "${@}"
;;
observer)
exec /app/cql explorer -config "${COVENANT_CONF}" "${COVENANTSQL_OBSERVER_ADDR}" "${@}"
explorer)
exec /app/cql explorer -config "${COVENANT_CONF}" "${@}" "${COVENANTSQL_OBSERVER_ADDR}"
;;
adapter)
exec /app/cql adapter -config "${COVENANT_CONF}" "${COVENANTSQL_ADAPTER_ADDR}" "${@}"
exec /app/cql adapter -config "${COVENANT_CONF}" "${@}" "${COVENANTSQL_ADAPTER_ADDR}"
;;
mysql-adapter)
exec /app/cql-mysql-adapter -config "${COVENANT_CONF}" "${@}"
Expand Down
62 changes: 37 additions & 25 deletions cmd/cql/internal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (

// CmdGenerate is cql generate command entity.
var CmdGenerate = &Command{
UsageLine: "cql generate [common params] [-source template_file] [-miner] [-private existing_private_key] [dest_path]",
UsageLine: "cql generate [common params] [-source template_file] [-miner listen_addr] [-private existing_private_key] [dest_path]",
Short: "generate a folder contains config file and private key",
Long: `
Generate generates private.key and config.yaml for CovenantSQL.
Expand Down Expand Up @@ -153,6 +153,42 @@ func runGenerate(cmd *Command, args []string) {
}
}

var port string
if minerListenAddr != "" {
minerListenAddrSplit := strings.Split(minerListenAddr, ":")
if len(minerListenAddrSplit) != 2 {
ConsoleLog.Error("-miner only accepts listen address in ip:port format. e.g. 127.0.0.1:7458")
SetExitStatus(1)
return
}
port = minerListenAddrSplit[1]
}

var rawConfig *conf.Config

if source == "" {
// Load testnet config
rawConfig = testnet.GetTestNetConfig()
if minerListenAddr != "" {
testnet.SetMinerConfig(rawConfig)
rawConfig.ListenAddr = "0.0.0.0:" + port
}
} else {
// Load from template file
sourceConfig, err := ioutil.ReadFile(source)
if err != nil {
ConsoleLog.WithError(err).Error("read config template failed")
SetExitStatus(1)
return
}
rawConfig = &conf.Config{}
if err = yaml.Unmarshal(sourceConfig, rawConfig); err != nil {
ConsoleLog.WithError(err).Error("load config template failed")
SetExitStatus(1)
return
}
}

var fileinfo os.FileInfo
if fileinfo, err = os.Stat(workingRoot); err == nil {
if fileinfo.IsDir() {
Expand Down Expand Up @@ -222,30 +258,6 @@ func runGenerate(cmd *Command, args []string) {

fmt.Println("Generating config file...")

var rawConfig *conf.Config

if source == "" {
// Load testnet config
rawConfig = testnet.GetTestNetConfig()
if minerListenAddr != "" {
testnet.SetMinerConfig(rawConfig)
}
} else {
// Load from template file
sourceConfig, err := ioutil.ReadFile(source)
if err != nil {
ConsoleLog.WithError(err).Error("read config template failed")
SetExitStatus(1)
return
}
rawConfig = &conf.Config{}
if err = yaml.Unmarshal(sourceConfig, rawConfig); err != nil {
ConsoleLog.WithError(err).Error("load config template failed")
SetExitStatus(1)
return
}
}

// Add client config
rawConfig.PrivateKeyFile = privateKeyFileName
rawConfig.WalletAddress = walletAddr
Expand Down
14 changes: 11 additions & 3 deletions cmd/cql/internal/idminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"math"
"math/rand"
"runtime"
"sync"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -130,13 +131,16 @@ func nonceGen(publicKey *asymmetric.PublicKey) *mine.NonceInfo {
cpuCount := runtime.NumCPU()
ConsoleLog.Infof("cpu: %#v\n", cpuCount)
stopCh := make(chan struct{})
nonceCh := make(chan mine.NonceInfo)
nonceCh := make(chan mine.NonceInfo, cpuCount)
progressCh := make(chan int, 100)
var wg sync.WaitGroup

rand.Seed(time.Now().UnixNano())
step := 256 / cpuCount
for i := 0; i < cpuCount; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
startBit := i * step
position := startBit / 64
shift := uint(startBit % 64)
Expand All @@ -155,7 +159,7 @@ func nonceGen(publicKey *asymmetric.PublicKey) *mine.NonceInfo {
for j := start; ; j.Inc() {
select {
case <-stopCh:
break
return
default:
currentHash := mine.HashBlock(publicKeyBytes, j)
currentDifficulty := currentHash.Difficulty()
Expand All @@ -167,13 +171,16 @@ func nonceGen(publicKey *asymmetric.PublicKey) *mine.NonceInfo {
Hash: currentHash,
}
nonceCh <- nonce
return
}
}
}
}(i)
}

wg.Add(1)
go func() {
defer wg.Done()
var count, current int

ticker := time.NewTicker(1 * time.Second)
Expand All @@ -182,7 +189,7 @@ func nonceGen(publicKey *asymmetric.PublicKey) *mine.NonceInfo {
for {
select {
case <-stopCh:
break
return
case mined := <-progressCh:
if mined > current {
current = mined
Expand All @@ -197,6 +204,7 @@ func nonceGen(publicKey *asymmetric.PublicKey) *mine.NonceInfo {

nonce := <-nonceCh
close(stopCh)
wg.Wait()
fmt.Printf("\n")

// verify result
Expand Down
3 changes: 1 addition & 2 deletions conf/testnet/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ import (
const (
// CQLConfigYAML is the config string in YAML format of the CovenantSQL TestNet.
CQLConfigYAML = `
SQLChainPeriod: 60s
DNSSeed:
Domain: "testnet.gridb.io"
BPCount: 6
`
// CQLMinerYAML is the config string in YAML format of the CovenantSQL TestNet for miner.
CQLMinerYAML = `
ListenAddr: 0.0.0.0:4661
BillingBlockCount: 60
BPPeriod: 10s
BPTick: 3s
SQLChainPeriod: 60s
SQLChainTick: 10s
SQLChainTTL: 10
ChainBusPeriod: 10s
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,18 @@ services:
options:
max-size: '1m'
max-file: '10'
covenantsql_observer:
covenantsql_explorer:
image: covenantsql/covenantsql:latest
container_name: covenantsql_observer
container_name: covenantsql_explorer
restart: always
ports:
- '11108:4663'
environment:
COVENANT_ROLE: observer
COVENANT_CONF: ./node_observer/config.yaml
COVENANT_ROLE: explorer
COVENANT_CONF: ./node_explorer/config.yaml
COVENANTSQL_OBSERVER_ADDR: 0.0.0.0:4663
volumes:
- ./test/service/node_observer/:/app/node_observer/
- ./test/service/node_explorer/:/app/node_explorer/
networks:
default:
ipv4_address: 172.254.1.9
Expand Down
9 changes: 1 addition & 8 deletions test/service/node_adapter/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,5 @@ KnownNodes:
Role: Client
Adapter:
ListenAddr: 0.0.0.0:4661
CertificatePath: ./server.test.covenantsql.io.pem
PrivateKeyPath: ./server.test.covenantsql.io-key.pem
VerifyCertificate: true
ClientCAPath: ./rootCA.pem
AdminCerts:
- ./admin.test.covenantsql.io.pem
WriteCerts:
- ./write.test.covenantsql.io.pem
VerifyCertificate: false
StorageDriver: covenantsql
51 changes: 0 additions & 51 deletions test/service/node_c/admin.test.covenantsql.io-key.pem

This file was deleted.

33 changes: 0 additions & 33 deletions test/service/node_c/admin.test.covenantsql.io.pem

This file was deleted.

51 changes: 0 additions & 51 deletions test/service/node_c/read.test.covenantsql.io-key.pem

This file was deleted.

33 changes: 0 additions & 33 deletions test/service/node_c/read.test.covenantsql.io.pem

This file was deleted.

Loading