Skip to content

Commit

Permalink
go/oasis-node/cmd/debug/consim: Add --consim.memdb
Browse files Browse the repository at this point in the history
While it's possible to use the pruner to try to prevent the ABCI induced
disk usage from growing out of control, having to save/prune is rather
slow, even when backed by tmpfs.

Enabling this option will keep ABCI state in memory, dramatically
speeding up cases where only the final dump is required, especially if
a sensible configuration is used for the pruner.
  • Loading branch information
Yawning committed Apr 9, 2020
1 parent 41b800c commit c77159d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions go/consensus/tendermint/abci/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ type ApplicationConfig struct {

// OwnTxSigner is the transaction signer identity of the local node.
OwnTxSigner signature.PublicKey

// TestingMemDB forces the MemDB to be used for the state storage.
TestingMemDB bool
}

// TransactionAuthHandler is the interface for ABCI applications that handle
Expand Down
9 changes: 8 additions & 1 deletion go/consensus/tendermint/abci/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,15 @@ func (s *applicationState) metricsWorker() {
}
}

func newStateDB(cfg *ApplicationConfig) (dbm.DB, error) {
if cfg.TestingMemDB {
return dbm.NewMemDB(), nil
}
return db.New(filepath.Join(cfg.DataDir, "abci-mux-state"), false)
}

func newApplicationState(ctx context.Context, cfg *ApplicationConfig) (*applicationState, error) {
db, err := db.New(filepath.Join(cfg.DataDir, "abci-mux-state"), false)
db, err := newStateDB(cfg)
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions go/oasis-node/cmd/debug/consim/consim.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

const (
cfgNumKept = "consim.num_kept"
cfgMemDB = "consim.memdb"
cfgWorkload = "consim.workload"
cfgWorkloadSeed = "consim.workload.seed"
)
Expand Down Expand Up @@ -115,6 +116,7 @@ func doRun(cmd *cobra.Command, args []string) error {
tmChainID: tmChainID,
txAuthHandler: txAuthApp.(abci.TransactionAuthHandler),
numVersions: viper.GetInt64(cfgNumKept),
memDB: viper.GetBool(cfgMemDB),
}
mockChain, err := initMockChain(ctx, cfg)
if err != nil {
Expand Down Expand Up @@ -248,6 +250,7 @@ func Register(parentCmd *cobra.Command) {

func init() {
flagsConsim.Int64(cfgNumKept, 0, "number of versions kept (0 = all)")
flagsConsim.Bool(cfgMemDB, false, "use memory to store state")
flagsConsim.String(cfgWorkload, fileWorkloadName, "workload to execute")
flagsConsim.String(cfgWorkloadSeed, "seeeeeeeeeeeeeeeeeeeeeeeeeeeeeed", "DRBG seed for workloads")
_ = viper.BindPFlags(flagsConsim)
Expand Down
2 changes: 2 additions & 0 deletions go/oasis-node/cmd/debug/consim/mockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type mockChainCfg struct {
tmChainID string
txAuthHandler abci.TransactionAuthHandler
numVersions int64
memDB bool
}

type mockChain struct {
Expand Down Expand Up @@ -158,6 +159,7 @@ func initMockChain(ctx context.Context, cfg *mockChainCfg) (*mockChain, error) {
HaltEpochHeight: math.MaxUint64,
MinGasPrice: 0, // XXX: Should this be configurable?
OwnTxSigner: localSigner.Public(),
TestingMemDB: cfg.memDB,
}
if cfg.numVersions > 0 {
muxCfg.Pruning.Strategy = abci.PruneKeepN
Expand Down

0 comments on commit c77159d

Please sign in to comment.