Skip to content

Commit

Permalink
Merge pull request #66 from bnb-chain/develop
Browse files Browse the repository at this point in the history
release: prepare release for v0.0.4
  • Loading branch information
randyahx authored Aug 11, 2023
2 parents 452aab0 + c5b802f commit ffebe78
Show file tree
Hide file tree
Showing 20 changed files with 656 additions and 109 deletions.
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Report a bug
about: Something with greenfield-challenger is not working as expected
title: ''
labels: 'type:bug'
assignees: ''
---

#### System information

Challenger version: (if getting from release page)
OS & Version: Windows/Linux/OSX
Commit hash : (if `develop`)

#### Expected behaviour


#### Actual behaviour


#### Steps to reproduce the behaviour


#### Backtrace

````
[backtrace]
````

When submitting logs: please submit them as text and not screenshots.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Request a feature
about: Report a missing feature - e.g. as a step before submitting a PR
title: ''
labels: 'type:feature'
assignees: ''
---

# Rationale

Why should this feature exist?
What are the use-cases?

# Implementation

Do you have ideas regarding the implementation of this feature?
Are you willing to implement this feature?
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: Ask a question
about: Something is unclear
title: ''
labels: 'type:docs'
assignees: ''
---

This should only be used in very rare cases e.g. if you are not 100% sure if something is a bug or asking a question that leads to improving the documentation. For general questions please use [discord](https://discord.gg/bnbchain).
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## v0.0.4
This release includes a feature and bugfix. Metrics are added in this release.

Features:
* [#61](https://github.com/bnb-chain/greenfield-challenger/pull/61) feat: add metrics

Bugfixes:
* [#64](https://github.com/bnb-chain/greenfield-challenger/pull/64) fix: attest monitor missing attested challenges

Chores:
* [#63](https://github.com/bnb-chain/greenfield-challenger/pull/63) chore: add issue template


## v0.0.3
This release includes 1 feature and 2 bugfixes.

Expand Down
41 changes: 23 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ package app
import (
"encoding/json"
"fmt"
"gorm.io/driver/mysql"
"gorm.io/gorm"

"github.com/bnb-chain/greenfield-challenger/attest"

"github.com/bnb-chain/greenfield-challenger/config"
"github.com/bnb-chain/greenfield-challenger/db/dao"
"github.com/bnb-chain/greenfield-challenger/db/model"
"github.com/bnb-chain/greenfield-challenger/executor"
"github.com/bnb-chain/greenfield-challenger/logging"
"github.com/bnb-chain/greenfield-challenger/metrics"
"github.com/bnb-chain/greenfield-challenger/monitor"
"github.com/bnb-chain/greenfield-challenger/submitter"
"github.com/bnb-chain/greenfield-challenger/verifier"
"github.com/bnb-chain/greenfield-challenger/vote"
"github.com/bnb-chain/greenfield-challenger/wiper"
"github.com/spf13/viper"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)

type App struct {
Expand All @@ -30,6 +29,7 @@ type App struct {
voteCollator *vote.VoteCollator
txSubmitter *submitter.TxSubmitter
attestMonitor *attest.AttestMonitor
metricService *metrics.MetricService
dbWiper *wiper.DBWiper
}

Expand All @@ -44,7 +44,7 @@ func NewApp(cfg *config.Config) *App {

db, err := gorm.Open(mysql.Open(dbPath), &gorm.Config{})

//only for debug purpose
// only for debug purpose
db = db.Debug()

if err != nil {
Expand All @@ -58,12 +58,13 @@ func NewApp(cfg *config.Config) *App {
dbConfig.SetMaxIdleConns(cfg.DBConfig.MaxIdleConns)
dbConfig.SetMaxOpenConns(cfg.DBConfig.MaxOpenConns)

if cfg.DBConfig.DebugMode {
err = ResetDB(db, &model.Block{}, &model.Event{}, &model.Vote{})
if err != nil {
logging.Logger.Errorf("reset db error, err=%+v", err.Error())
}
}
// For clearing database during debugging
//if cfg.DBConfig.DebugMode {
// err = ResetDB(db, &model.Block{}, &model.Event{}, &model.Vote{})
// if err != nil {
// logging.Logger.Errorf("reset db error, err=%+v", err.Error())
// }
//}

model.InitBlockTable(db)
model.InitEventTable(db)
Expand All @@ -76,23 +77,25 @@ func NewApp(cfg *config.Config) *App {

executor := executor.NewExecutor(cfg)

metricService := metrics.NewMetricService(cfg)

monitorDataHandler := monitor.NewDataHandler(daoManager)
monitor := monitor.NewMonitor(executor, monitorDataHandler)
monitor := monitor.NewMonitor(executor, monitorDataHandler, metricService)

verifierDataHandler := verifier.NewDataHandler(daoManager)
hashVerifier := verifier.NewHashVerifier(cfg, executor, cfg.GreenfieldConfig.DeduplicationInterval, verifierDataHandler)
hashVerifier := verifier.NewHashVerifier(cfg, executor, verifierDataHandler, metricService)

signer := vote.NewVoteSigner(executor.BlsPrivKey)
voteDataHandler := vote.NewDataHandler(daoManager, executor)
voteCollector := vote.NewVoteCollector(cfg, executor, voteDataHandler)
voteBroadcaster := vote.NewVoteBroadcaster(cfg, signer, executor, voteDataHandler)
voteCollator := vote.NewVoteCollator(cfg, signer, executor, voteDataHandler)
voteCollector := vote.NewVoteCollector(cfg, executor, voteDataHandler, metricService)
voteBroadcaster := vote.NewVoteBroadcaster(cfg, signer, executor, voteDataHandler, metricService)
voteCollator := vote.NewVoteCollator(cfg, signer, executor, voteDataHandler, metricService)

txDataHandler := submitter.NewDataHandler(daoManager, executor)
txSubmitter := submitter.NewTxSubmitter(cfg, executor, txDataHandler)
txSubmitter := submitter.NewTxSubmitter(cfg, executor, txDataHandler, metricService)

attestDataHandler := attest.NewDataHandler(daoManager)
attestMonitor := attest.NewAttestMonitor(executor, attestDataHandler)
attestMonitor := attest.NewAttestMonitor(executor, attestDataHandler, metricService)

dbWiper := wiper.NewDBWiper(daoManager)

Expand All @@ -105,6 +108,7 @@ func NewApp(cfg *config.Config) *App {
voteCollator: voteCollator,
attestMonitor: attestMonitor,
txSubmitter: txSubmitter,
metricService: metricService,
dbWiper: dbWiper,
}
}
Expand All @@ -119,6 +123,7 @@ func (a *App) Start() {
go a.voteBroadcaster.BroadcastVotesLoop()
go a.voteCollator.CollateVotesLoop()
go a.attestMonitor.UpdateAttestedChallengeIdLoop()
go a.metricService.Start()
a.txSubmitter.SubmitTransactionLoop()
}

Expand Down
7 changes: 6 additions & 1 deletion attest/attest_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"sync"
"time"

"github.com/bnb-chain/greenfield-challenger/metrics"

"github.com/bnb-chain/greenfield-challenger/db/model"
"github.com/bnb-chain/greenfield-challenger/executor"
"github.com/bnb-chain/greenfield-challenger/logging"
Expand All @@ -14,14 +16,16 @@ type AttestMonitor struct {
mtx sync.RWMutex
attestedChallengeIds map[uint64]bool // used to save the last attested challenge id
dataProvider DataProvider
metricService *metrics.MetricService
}

func NewAttestMonitor(executor *executor.Executor, dataProvider DataProvider) *AttestMonitor {
func NewAttestMonitor(executor *executor.Executor, dataProvider DataProvider, metricService *metrics.MetricService) *AttestMonitor {
return &AttestMonitor{
executor: executor,
mtx: sync.RWMutex{},
attestedChallengeIds: make(map[uint64]bool, 0),
dataProvider: dataProvider,
metricService: metricService,
}
}

Expand Down Expand Up @@ -78,4 +82,5 @@ func (a *AttestMonitor) updateEventStatus(challengeId uint64) {
if err != nil {
logging.Logger.Errorf("update attested event status error, err=%s", err.Error())
}
a.metricService.IncAttestedChallenges()
}
41 changes: 25 additions & 16 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
package config

import (
"cosmossdk.io/math"
"encoding/json"
"fmt"
"os"

"cosmossdk.io/math"
)

type Config struct {
GreenfieldConfig GreenfieldConfig `json:"greenfield_config"`
LogConfig LogConfig `json:"log_config"`
AlertConfig AlertConfig `json:"alert_config"`
DBConfig DBConfig `json:"db_config"`
MetricsConfig MetricsConfig `json:"metrics_config"`
}

type GreenfieldConfig struct {
KeyType string `json:"key_type"`
AWSRegion string `json:"aws_region"`
AWSSecretName string `json:"aws_secret_name"`
AWSBlsSecretName string `json:"aws_bls_secret_name"`
PrivateKey string `json:"private_key"`
BlsPrivateKey string `json:"bls_private_key"`
RPCAddrs []string `json:"rpc_addrs"`
ChainIdString string `json:"chain_id_string"`
GasLimit uint64 `json:"gas_limit"`
FeeAmount string `json:"fee_amount"`
FeeDenom string `json:"fee_denom"`
DeduplicationInterval uint64 `json:"deduplication_interval"`
KeyType string `json:"key_type"`
AWSRegion string `json:"aws_region"`
AWSSecretName string `json:"aws_secret_name"`
AWSBlsSecretName string `json:"aws_bls_secret_name"`
PrivateKey string `json:"private_key"`
BlsPrivateKey string `json:"bls_private_key"`
RPCAddrs []string `json:"rpc_addrs"`
ChainIdString string `json:"chain_id_string"`
GasLimit uint64 `json:"gas_limit"`
FeeAmount string `json:"fee_amount"`
FeeDenom string `json:"fee_denom"`
}

func (cfg *GreenfieldConfig) Validate() {
Expand Down Expand Up @@ -68,9 +69,6 @@ func (cfg *GreenfieldConfig) Validate() {
if cfg.FeeDenom == "" {
panic("fee_denom should not be empty")
}
if cfg.DeduplicationInterval == 0 {
panic("deduplication_interval should not be 0")
}
feeAmount, ok := math.NewIntFromString(cfg.FeeAmount)
if !ok {
panic("error converting fee_amount to math.Int")
Expand Down Expand Up @@ -127,10 +125,21 @@ func (cfg *DBConfig) Validate() {
}
}

type MetricsConfig struct {
Port uint16 `json:"port"`
}

func (cfg *MetricsConfig) Validate() {
if cfg.Port <= 0 || cfg.Port > 65535 {
panic("port should be within (0, 65535]")
}
}

func (cfg *Config) Validate() {
cfg.LogConfig.Validate()
cfg.DBConfig.Validate()
cfg.GreenfieldConfig.Validate()
cfg.MetricsConfig.Validate()
}

func ParseConfigFromJson(content string) *Config {
Expand Down
1 change: 1 addition & 0 deletions db/model/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
SelfAttested
Attested // Event has been submitted for tx
Duplicated
DuplicatedSlash
)

type VerifyResult int
Expand Down
13 changes: 12 additions & 1 deletion executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ func (e *Executor) QueryChallengeHeartbeatInterval() (uint64, error) {
return heartbeatInterval, nil
}

func (e *Executor) QueryChallengeSlashCoolingOffPeriod() (uint64, error) {
client := e.clients.GetClient().Client
params, err := client.ChallengeParams(context.Background(), &challengetypes.QueryParamsRequest{})
if err != nil {
logging.Logger.Errorf("query challenge params failed, err=%+v", err.Error())
return 0, err
}
logging.Logger.Infof("challenge slash cooling off period: %d", params.Params.SlashCoolingOffPeriod)
return params.Params.SlashCoolingOffPeriod, nil
}

func (e *Executor) UpdateHeartbeatIntervalLoop() {
ticker := time.NewTicker(QueryHeartbeatIntervalInterval)
for range ticker.C {
Expand Down Expand Up @@ -321,11 +332,11 @@ func (e *Executor) GetStorageProviderEndpoint(address string) (string, error) {
return "", err
}
res, err := client.GetStorageProviderInfo(context.Background(), spAddr)
logging.Logger.Infof("response res.endpoint %s", res.Endpoint)
if err != nil {
logging.Logger.Errorf("executor failed to query storage provider %s, err=%+v", address, err.Error())
return "", err
}
logging.Logger.Infof("response res.endpoint %s", res.Endpoint)

return res.Endpoint, nil
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/ory/dockertest v3.3.5+incompatible
github.com/panjf2000/ants/v2 v2.7.3
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.15.0
github.com/prysmaticlabs/prysm v0.0.0-20220124113610-e26cde5e091b
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
Expand Down Expand Up @@ -121,7 +122,6 @@ require (
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.15.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion logging/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var (
// Logger instance for quick declarative logging levels
Logger = logging.MustGetLogger("inscription-challenger")
Logger = logging.MustGetLogger("greenfield-challenger")
// log levels that are available
levels = map[string]logging.Level{
"CRITICAL": logging.CRITICAL,
Expand Down
Loading

0 comments on commit ffebe78

Please sign in to comment.