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
10 changes: 10 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
name = "github.com/CovenantSQL/xurls"
branch = "master"

[[override]]
name = "github.com/zserge/metric"
branch = "master"

[[override]]
name = "github.com/xtaci/smux"
branch = "master"
Expand Down
6 changes: 3 additions & 3 deletions bin/docker-entry.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/sh

echo nameserver 1.1.1.1 > /etc/resolv.conf
#echo nameserver 1.1.1.1 > /etc/resolv.conf

[ -s "${COVENANT_ALERT}" ] && [ -x "${COVENANT_ALERT}" ] && (eval "${COVENANT_ALERT}")

case "${COVENANT_ROLE}" in
miner)
exec /app/cql-minerd -config "${COVENANT_CONF}" "${@}"
exec /app/cql-minerd -config "${COVENANT_CONF}" -metric-web "${METRIC_WEB_ADDR}" "${@}"
;;
blockproducer)
exec /app/cqld -config "${COVENANT_CONF}" "${@}"
exec /app/cqld -config "${COVENANT_CONF}" -metric-web "${METRIC_WEB_ADDR}" "${@}"
;;
observer)
MAGIC_DOLLAR='$' envsubst < /etc/nginx/conf.d/servers/explorer.conf.template > /etc/nginx/conf.d/default.conf
Expand Down
9 changes: 9 additions & 0 deletions blockproducer/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ package blockproducer

import (
"context"
"expvar"
"fmt"
"math"
"os"
"sync"
"time"

mw "github.com/zserge/metric"

pi "github.com/CovenantSQL/CovenantSQL/blockproducer/interfaces"
"github.com/CovenantSQL/CovenantSQL/chainbus"
"github.com/CovenantSQL/CovenantSQL/conf"
Expand Down Expand Up @@ -80,6 +83,11 @@ type Chain struct {

// NewChain creates a new blockchain.
func NewChain(cfg *Config) (c *Chain, err error) {
// Normally, NewChain() should only be called once in app.
// So, we just check expvar without a lock
if expvar.Get("height") == nil {
expvar.Publish("height", mw.NewGauge("5m1s"))
}
return NewChainWithContext(context.Background(), cfg)
}

Expand Down Expand Up @@ -361,6 +369,7 @@ func (c *Chain) advanceNextHeight(now time.Time, d time.Duration) {
}).Warn("too much time elapsed in the new period, skip this block")
return
}
expvar.Get("height").(mw.Metric).Add(float64(c.getNextHeight()))
log.WithField("height", c.getNextHeight()).Info("producing a new block")
if err := c.produceBlock(now); err != nil {
log.WithField("now", now.Format(time.RFC3339Nano)).WithError(err).Errorln(
Expand Down
6 changes: 6 additions & 0 deletions cmd/cql-minerd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func startNodes() {
FJ(baseDir, "./bin/cqld.test"),
[]string{"-config", FJ(testWorkingDir, "./integration/node_0/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/leader.cover.out"),
"-metric-web", "0.0.0.0:13122",
},
"leader", testWorkingDir, logDir, true,
); err == nil {
Expand All @@ -98,6 +99,7 @@ func startNodes() {
FJ(baseDir, "./bin/cqld.test"),
[]string{"-config", FJ(testWorkingDir, "./integration/node_1/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/follower1.cover.out"),
"-metric-web", "0.0.0.0:13121",
},
"follower1", testWorkingDir, logDir, false,
); err == nil {
Expand All @@ -109,6 +111,7 @@ func startNodes() {
FJ(baseDir, "./bin/cqld.test"),
[]string{"-config", FJ(testWorkingDir, "./integration/node_2/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/follower2.cover.out"),
"-metric-web", "0.0.0.0:13120",
},
"follower2", testWorkingDir, logDir, false,
); err == nil {
Expand Down Expand Up @@ -149,6 +152,7 @@ func startNodes() {
FJ(baseDir, "./bin/cql-minerd.test"),
[]string{"-config", FJ(testWorkingDir, "./integration/node_miner_0/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/miner0.cover.out"),
"-metric-web", "0.0.0.0:12144",
},
"miner0", testWorkingDir, logDir, true,
); err == nil {
Expand All @@ -162,6 +166,7 @@ func startNodes() {
FJ(baseDir, "./bin/cql-minerd.test"),
[]string{"-config", FJ(testWorkingDir, "./integration/node_miner_1/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/miner1.cover.out"),
"-metric-web", "0.0.0.0:12145",
},
"miner1", testWorkingDir, logDir, false,
); err == nil {
Expand All @@ -175,6 +180,7 @@ func startNodes() {
FJ(baseDir, "./bin/cql-minerd.test"),
[]string{"-config", FJ(testWorkingDir, "./integration/node_miner_2/config.yaml"),
"-test.coverprofile", FJ(baseDir, "./cmd/cql-minerd/miner2.cover.out"),
"-metric-web", "0.0.0.0:12146",
},
"miner2", testWorkingDir, logDir, false,
); err == nil {
Expand Down
23 changes: 17 additions & 6 deletions cmd/cql-minerd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var (
configFile string
genKeyPair bool
metricLog bool
metricWeb string

// profile
cpuProfile string
Expand Down Expand Up @@ -101,12 +102,14 @@ func init() {
flag.StringVar(&cpuProfile, "cpu-profile", "", "Path to file for CPU profiling information")
flag.StringVar(&memProfile, "mem-profile", "", "Path to file for memory profiling information")
flag.StringVar(&metricGraphite, "metric-graphite-server", "", "Metric graphite server to push metrics")
flag.StringVar(&traceFile, "trace-file", "", "trace profile")
flag.StringVar(&logLevel, "log-level", "", "service log level")
flag.StringVar(&metricWeb, "metric-web", "", "Address and port to get internal metrics")

flag.StringVar(&traceFile, "trace-file", "", "Trace profile")
flag.StringVar(&logLevel, "log-level", "", "Service log level")

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "\n%s\n\n", desc)
fmt.Fprintf(os.Stderr, "Usage: %s [arguments]\n", name)
_, _ = fmt.Fprintf(os.Stderr, "\n%s\n\n", desc)
_, _ = fmt.Fprintf(os.Stderr, "Usage: %s [arguments]\n", name)
flag.PrintDefaults()
}
}
Expand Down Expand Up @@ -160,7 +163,7 @@ func main() {
}

// init profile, if cpuProfile, memProfile length is 0, nothing will be done
utils.StartProfile(cpuProfile, memProfile)
_ = utils.StartProfile(cpuProfile, memProfile)

// set generate key pair config
conf.GConf.GenerateKeyPair = genKeyPair
Expand All @@ -186,6 +189,14 @@ func main() {
}()
}

if len(metricWeb) > 0 {
err = metric.InitMetricWeb(metricWeb)
if err != nil {
log.Errorf("start metric web server on %s failed: %v", metricWeb, err)
os.Exit(-1)
}
}

// start period provide service transaction generator
go func() {
// start prometheus collector
Expand Down Expand Up @@ -218,7 +229,7 @@ func main() {
server.Serve()
}()
defer func() {
server.Listener.Close()
_ = server.Listener.Close()
server.Stop()
}()

Expand Down
32 changes: 16 additions & 16 deletions cmd/cql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,27 +208,27 @@ func usqlRegister() {

func init() {

flag.StringVar(&dsn, "dsn", "", "database url")
flag.StringVar(&command, "command", "", "run only single command (SQL or usql internal command) and exit")
flag.StringVar(&fileName, "file", "", "execute commands from file and exit")
flag.StringVar(&dsn, "dsn", "", "Database url")
flag.StringVar(&command, "command", "", "Run only single command (SQL or usql internal command) and exit")
flag.StringVar(&fileName, "file", "", "Execute commands from file and exit")
flag.BoolVar(&showVersion, "version", false, "Show version information and exit")
flag.BoolVar(&noRC, "no-rc", false, "do not read start up file")
flag.BoolVar(&noRC, "no-rc", false, "Do not read start up file")
flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false,
"Disable signature sign and verify, for testing")
flag.StringVar(&outFile, "out", "", "output file")
flag.StringVar(&configFile, "config", "config.yaml", "config file for covenantsql")
flag.StringVar(&password, "password", "", "master key password for covenantsql")
flag.BoolVar(&singleTransaction, "single-transaction", false, "execute as a single transaction (if non-interactive)")
flag.Var(&variables, "variable", "set variable")
flag.StringVar(&outFile, "out", "", "Record stdout to file")
flag.StringVar(&configFile, "config", "config.yaml", "Config file for covenantsql")
flag.StringVar(&password, "password", "", "Master key password for covenantsql")
flag.BoolVar(&singleTransaction, "single-transaction", false, "Execute as a single transaction (if non-interactive)")
flag.Var(&variables, "variable", "Set variable")

// DML flags
flag.StringVar(&createDB, "create", "", "create database, argument can be instance requirement json or simply a node count requirement")
flag.StringVar(&dropDB, "drop", "", "drop database, argument should be a database id (without covenantsql:// scheme is acceptable)")
flag.StringVar(&updatePermission, "update-perm", "", "update user's permission on specific sqlchain")
flag.StringVar(&transferToken, "transfer", "", "transfer token to target account")
flag.BoolVar(&getBalance, "get-balance", false, "get balance of current account")
flag.StringVar(&getBalanceWithTokenName, "token-balance", "", "get specific token's balance of current account, e.g. Particle, Wave, and etc.")
flag.BoolVar(&waitTxConfirmation, "wait-tx-confirm", false, "wait for transaction confirmation")
flag.StringVar(&createDB, "create", "", "Create database, argument can be instance requirement json or simply a node count requirement")
flag.StringVar(&dropDB, "drop", "", "Drop database, argument should be a database id (without covenantsql:// scheme is acceptable)")
flag.StringVar(&updatePermission, "update-perm", "", "Update user's permission on specific sqlchain")
flag.StringVar(&transferToken, "transfer", "", "Transfer token to target account")
flag.BoolVar(&getBalance, "get-balance", false, "Get balance of current account")
flag.StringVar(&getBalanceWithTokenName, "token-balance", "", "Get specific token's balance of current account, e.g. Particle, Wave, and etc.")
flag.BoolVar(&waitTxConfirmation, "wait-tx-confirm", false, "Wait for transaction confirmation")
}

func main() {
Expand Down
1 change: 0 additions & 1 deletion cmd/cqld/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ func runNode(nodeID proto.NodeID, listenAddr string) (err error) {
defer chain.Stop()

log.Info(conf.StartSucceedMessage)
//go periodicPingBlockProducer()

signalCh := make(chan os.Signal, 1)
signal.Notify(
Expand Down
Loading