Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge e744c8e into da2fe9a
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRocketCat committed Feb 5, 2021
2 parents da2fe9a + e744c8e commit ca84ce0
Show file tree
Hide file tree
Showing 70 changed files with 837 additions and 823 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ lint: go-lint shell-lint
go-lint: check-git deps $(GOLANGCI_LINT) $(FAILLINT)
$(call require_clean_work_tree,'detected not clean master before running lint, previous job changed something?')
@echo ">> verifying modules being imported"
@$(FAILLINT) -paths "errors=github.com/pkg/errors" ./...
@$(FAILLINT) -paths "fmt.{Print,Printf,Println,Sprint}" -ignore-tests ./...
@echo ">> linting all of the Go files GOGC=${GOGC}"
@$(GOLANGCI_LINT) run
@echo ">> ensuring Copyright headers"
Expand Down
104 changes: 35 additions & 69 deletions cmd/telliot/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/tellor-io/telliot/pkg/db"
"github.com/tellor-io/telliot/pkg/logging"
"github.com/tellor-io/telliot/pkg/ops"
"github.com/tellor-io/telliot/pkg/rest"
)
Expand All @@ -36,6 +37,7 @@ type VersionCmd struct {
}

func (cmd *VersionCmd) Run() error {
//lint:ignore faillint it should print to console
fmt.Printf(versionMessage, GitTag, GitHash)
return nil
}
Expand All @@ -55,13 +57,10 @@ func (c *transferCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

logger, err := createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -87,13 +86,10 @@ func (c *approveCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

logger, err := createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand Down Expand Up @@ -122,13 +118,10 @@ func (b *balanceCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

_, err = createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, _, err := createTellorVariables(ctx, cfg)
client, contract, _, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -145,7 +138,7 @@ func (b *balanceCmd) Run() error {
return errors.Wrapf(err, "parsing argument")
}
}
return ops.Balance(ctx, client, contract.Getter, addr.addr)
return ops.Balance(ctx, logger, client, contract.Getter, addr.addr)
}

type depositCmd struct {
Expand All @@ -158,13 +151,10 @@ func (d depositCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

logger, err := createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -181,13 +171,10 @@ func (w withdrawCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

logger, err := createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -204,13 +191,10 @@ func (r requestCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

logger, err := createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -227,13 +211,10 @@ func (s statusCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

logger, err := createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -253,13 +234,10 @@ func (n newDisputeCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

_, err = createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -279,7 +257,7 @@ func (n newDisputeCmd) Run() error {
if err != nil {
return errors.Wrapf(err, "parsing argument")
}
return ops.Dispute(ctx, client, contract, account, requestID.Int, timestamp.Int, minerIndex.Int)
return ops.Dispute(ctx, logger, client, contract, account, requestID.Int, timestamp.Int, minerIndex.Int)
}

type voteCmd struct {
Expand All @@ -294,13 +272,10 @@ func (v voteCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

_, err = createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -310,7 +285,7 @@ func (v voteCmd) Run() error {
if err != nil {
return errors.Wrapf(err, "parsing argument")
}
return ops.Vote(ctx, client, contract, account, disputeID.Int, v.support)
return ops.Vote(ctx, logger, client, contract, account, disputeID.Int, v.support)
}

type showCmd struct {
Expand All @@ -323,13 +298,10 @@ func (s showCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

logger, err := createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -346,13 +318,10 @@ func (d dataserverCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

logger, err := createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -361,11 +330,11 @@ func (d dataserverCmd) Run() error {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)

DB, err := migrateAndOpenDB(cfg)
DB, err := migrateAndOpenDB(logger, cfg)
if err != nil {
return errors.Wrapf(err, "initializing database")
}
proxy, err := db.OpenLocal(cfg, DB)
proxy, err := db.OpenLocal(logger, cfg, DB)
if err != nil {
return errors.Wrapf(err, "open remote DB instance")
}
Expand All @@ -381,7 +350,7 @@ func (d dataserverCmd) Run() error {
<-ds.Ready()

http.Handle("/metrics", promhttp.Handler())
srv, err := rest.Create(ctx, proxy, cfg.DataServer.ListenHost, cfg.DataServer.ListenPort)
srv, err := rest.Create(logger, cfg, ctx, proxy, cfg.DataServer.ListenHost, cfg.DataServer.ListenPort)
if err != nil {
return errors.Wrapf(err, "creating http data server")
}
Expand Down Expand Up @@ -425,13 +394,10 @@ func (m mineCmd) Run() error {
return errors.Wrapf(err, "creating config")
}

logger, err := createLogger(cfg.Logger, cfg.LogLevel)
if err != nil {
return errors.Wrapf(err, "creating logger")
}
logger := logging.NewLogger()

ctx := context.Background()
client, contract, account, err := createTellorVariables(ctx, cfg)
client, contract, account, err := createTellorVariables(ctx, logger, cfg)
if err != nil {
return errors.Wrapf(err, "creating tellor variables")
}
Expand All @@ -452,7 +418,7 @@ func (m mineCmd) Run() error {
defer srv.Close()

var ds *ops.DataServerOps
DB, err := migrateAndOpenDB(cfg)
DB, err := migrateAndOpenDB(logger, cfg)
if err != nil {
return errors.Wrapf(err, "initializing database")
}
Expand All @@ -462,9 +428,9 @@ func (m mineCmd) Run() error {

var proxy db.DataServerProxy
if cfg.Mine.RemoteDBHost != "" {
proxy, err = db.OpenRemote(cfg, DB)
proxy, err = db.OpenRemote(logger, cfg, DB)
} else {
proxy, err = db.OpenLocal(cfg, DB)
proxy, err = db.OpenLocal(logger, cfg, DB)
}
if err != nil {
return errors.Wrapf(err, "open remote DB instance")
Expand Down
20 changes: 5 additions & 15 deletions cmd/telliot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/tellor-io/telliot/pkg/contracts"
"github.com/tellor-io/telliot/pkg/db"
"github.com/tellor-io/telliot/pkg/rpc"
"github.com/tellor-io/telliot/pkg/util"
)

func parseConfig(path string) (*config.Config, error) {
Expand All @@ -31,19 +30,10 @@ func parseConfig(path string) (*config.Config, error) {
return config.GetConfig(), nil
}

func createLogger(logConfig map[string]string, level string) (log.Logger, error) {
err := util.SetupLoggingConfig(logConfig)
if err != nil {
return nil, errors.Wrapf(err, "parsing log config")
}
logger := util.SetupLogger(level)
return logger, nil
}

func createTellorVariables(ctx context.Context, cfg *config.Config) (contracts.ETHClient, *contracts.Tellor, *rpc.Account, error) {
func createTellorVariables(ctx context.Context, logger log.Logger, cfg *config.Config) (contracts.ETHClient, *contracts.Tellor, *rpc.Account, error) {

// Create an rpc client
client, err := rpc.NewClient(os.Getenv(config.NodeURLEnvName))
client, err := rpc.NewClient(logger, cfg, os.Getenv(config.NodeURLEnvName))
if err != nil {
return nil, nil, nil, errors.Wrap(err, "create rpc client instance")
}
Expand Down Expand Up @@ -74,9 +64,9 @@ func createTellorVariables(ctx context.Context, cfg *config.Config) (contracts.E
// The DB is always deleted because the price avarages calculations
// is not calculated properly between restarts.
// TODO don't do this and just improve the price calculations.
func migrateAndOpenDB(cfg *config.Config) (db.DB, error) {
func migrateAndOpenDB(logger log.Logger, cfg *config.Config) (db.DB, error) {
// Create a db instance
DB, err := db.Open(cfg.DBFile)
DB, err := db.Open(logger, cfg, cfg.DBFile)
if err != nil {
return nil, errors.Wrapf(err, "opening DB instance")
}
Expand All @@ -94,7 +84,7 @@ func migrateAndOpenDB(cfg *config.Config) (db.DB, error) {
}
os.RemoveAll(cfg.DBFile)

DB, err = db.Open(cfg.DBFile)
DB, err = db.Open(logger, cfg, cfg.DBFile)
if err != nil {
return nil, errors.Wrapf(err, "opening DB instance")
}
Expand Down
21 changes: 8 additions & 13 deletions configs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"dbFile": "tmp/db",
"configFolder": "configs",
"envFile": ".env",
"logLevel": "info",
"Mine": {
"ListenHost": "0.0.0.0",
"ListenPort": 9090,
Expand All @@ -17,17 +16,13 @@
"ListenPort": 5000
},
"Logger": {
"config.Config": "INFO",
"db.DB": "INFO",
"rpc.client": "INFO",
"rpc.ABICodec": "INFO",
"rpc.mockClient": "INFO",
"tracker.Top50Tracker": "INFO",
"tracker.FetchDataTracker": "INFO",
"pow.MiningWorker-0:": "INFO",
"pow.MiningWorker-1:": "INFO",
"pow.MiningTasker-0:": "INFO",
"pow.MiningTasker-1:": "INFO",
"tracker.PSRTracker": "INFO"
"db": "info",
"rpc": "info",
"dataServer": "info",
"tracker": "info",
"pow:": "info",
"ops": "info",
"rest": "info",
"apiOracle": "info"
}
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ require (
github.com/prometheus/tsdb v0.10.0 // indirect
github.com/rjeczalik/notify v0.9.2 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/sirupsen/logrus v1.7.0
github.com/status-im/keycard-go v0.0.0-20190424133014-d95853db0f48 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca
github.com/tyler-smith/go-bip39 v1.0.2 // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,8 @@ github.com/shirou/gopsutil v2.20.5+incompatible h1:tYH07UPoQt0OCQdgWWMgYHy3/a9bc
github.com/shirou/gopsutil v2.20.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down

0 comments on commit ca84ce0

Please sign in to comment.