Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#250 Add fail at height debug flag #251

Merged
merged 1 commit into from
Feb 13, 2019
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
19 changes: 12 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ type CyberdApp struct {
rankState *rank.RankState

latestBlockHeight int64

// debug values
failBeforeHeight int64
}

// NewBasecoinApp returns a reference to a new CyberdApp given a
Expand All @@ -91,16 +94,13 @@ type CyberdApp struct {
// registered, and finally the stores being mounted along with any necessary
// chain initialization.
func NewCyberdApp(
logger log.Logger, db dbm.DB, computeUnit rank.ComputeUnit, allowSearch bool, baseAppOptions ...func(*baseapp.BaseApp),
logger log.Logger, db dbm.DB, opts Options, baseAppOptions ...func(*baseapp.BaseApp),
) *CyberdApp {

// create and register app-level codec for TXs and accounts
cdc := MakeCodec()

dbKeys := NewCyberdAppDbKeys()

ms := store.NewMainKeeper(dbKeys.main)

var txDecoder = auth.DefaultTxDecoder(cdc)

// create your application type
Expand Down Expand Up @@ -153,8 +153,8 @@ func NewCyberdApp(
app.cidNumKeeper = keeper.NewBaseCidNumberKeeper(ms, dbKeys.cidNum, dbKeys.cidNumReverse)
app.stakingIndex = cbdbank.NewIndexedKeeper(app.bankKeeper, app.accountKeeper)
app.rankState = rank.NewRankState(
allowSearch, app.mainKeeper, app.stakingIndex,
app.linkIndexedKeeper, app.cidNumKeeper, computeUnit,
opts.AllowSearch, app.mainKeeper, app.stakingIndex,
app.linkIndexedKeeper, app.cidNumKeeper, opts.ComputeUnit,
)

// register the staking hooks
Expand Down Expand Up @@ -217,7 +217,7 @@ func NewCyberdApp(

// RANK PARAMS
app.rankState.Load(ctx, app.latestBlockHeight, app.Logger)

app.failBeforeHeight = opts.FailBeforeHeight
app.Seal()
return app
}
Expand Down Expand Up @@ -428,6 +428,11 @@ func getSignersTags(tx sdk.Tx) sdk.Tags {

func (app *CyberdApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {

if app.failBeforeHeight != 0 && req.Header.Height == app.failBeforeHeight {
app.Logger.Info("Forced panic at begin blocker", "height", app.failBeforeHeight)
os.Exit(1)
}

// mint new tokens for the previous block
mint.BeginBlocker(ctx, app.minter)
// distribute rewards for the previous block
Expand Down
12 changes: 12 additions & 0 deletions app/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app

import "github.com/cybercongress/cyberd/x/rank"

type Options struct {
// main options
ComputeUnit rank.ComputeUnit
AllowSearch bool

// debug options
FailBeforeHeight int64
}
13 changes: 11 additions & 2 deletions daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

const (
flagGpuEnabled = "compute-rank-on-gpu"
flagFailBeforeHeight = "fail-before-height"
flagSearchRpcQueryEnabled = "allow-search-rpc-query"
flagNotToSealAccPrefix = "not-to-seal-acc-prefix"
)
Expand Down Expand Up @@ -54,6 +55,7 @@ func main() {
for _, c := range rootCmd.Commands() {
if c.Use == "start" {
c.Flags().Bool(flagGpuEnabled, true, "Run cyberd with cuda calculations")
c.Flags().Int64(flagFailBeforeHeight, 0, "Forced node shutdown before specified height")
c.Flags().Bool(flagSearchRpcQueryEnabled, true, "Build index of links with ranks and allow to query search through RPC")
}
}
Expand All @@ -68,11 +70,18 @@ func main() {
func newApp(logger log.Logger, db dbm.DB, storeTracer io.Writer) abci.Application {
// todo use constant here
pruning := baseapp.SetPruning(sdk.NewPruningOptions(60*60*24, 0))

computeUnit := rank.CPU
if viper.GetBool(flagGpuEnabled) {
computeUnit = rank.GPU
}
cyberdApp := app.NewCyberdApp(logger, db, computeUnit, viper.GetBool(flagSearchRpcQueryEnabled), pruning)

opts := app.Options{
ComputeUnit: computeUnit,
AllowSearch: viper.GetBool(flagSearchRpcQueryEnabled),
FailBeforeHeight: viper.GetInt64(flagFailBeforeHeight),
}
cyberdApp := app.NewCyberdApp(logger, db, opts, pruning)
rpc.SetCyberdApp(cyberdApp)
return cyberdApp
}
Expand All @@ -81,7 +90,7 @@ func exportAppStateAndTMValidators(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool,
) (json.RawMessage, []tmtypes.GenesisValidator, error) {

capp := app.NewCyberdApp(logger, db, rank.CPU, false)
capp := app.NewCyberdApp(logger, db, app.Options{})
return capp.ExportAppStateAndValidators()
}

Expand Down