Skip to content

Commit

Permalink
#250 Add fail at height debug flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hleb-albau authored and arturalbov committed Feb 13, 2019
1 parent d184b8c commit f18774f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
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

0 comments on commit f18774f

Please sign in to comment.