diff --git a/client/pkiclient/katzenmint_integration_test.go b/client/pkiclient/katzenmint_integration_test.go index 8b2df4f..5818b7c 100644 --- a/client/pkiclient/katzenmint_integration_test.go +++ b/client/pkiclient/katzenmint_integration_test.go @@ -28,6 +28,8 @@ var ( abciClient *local.Local ) +const testDBCacheSize = 100 + func newDiscardLogger() (logger log.Logger) { logger = log.NewTMLogger(log.NewSyncWriter(ioutil.Discard)) return @@ -150,7 +152,7 @@ func TestMain(m *testing.M) { kcfg := kconf.DefaultConfig() db := dbm.NewMemDB() logger := newDiscardLogger() - app := kpki.NewKatzenmintApplication(kcfg, db, logger) + app := kpki.NewKatzenmintApplication(kcfg, db, testDBCacheSize, logger) node := rpctest.StartTendermint(app, rpctest.SuppressStdout) abciClient = local.New(node) diff --git a/katzenmint/app.go b/katzenmint/app.go index f939a50..8b7fe69 100644 --- a/katzenmint/app.go +++ b/katzenmint/app.go @@ -31,8 +31,8 @@ type KatzenmintApplication struct { logger log.Logger } -func NewKatzenmintApplication(kConfig *config.Config, db dbm.DB, logger log.Logger) *KatzenmintApplication { - state := NewKatzenmintState(kConfig, db) +func NewKatzenmintApplication(kConfig *config.Config, db dbm.DB, dbCacheSize int, logger log.Logger) *KatzenmintApplication { + state := NewKatzenmintState(kConfig, db, dbCacheSize) return &KatzenmintApplication{ state: state, logger: logger, diff --git a/katzenmint/app_test.go b/katzenmint/app_test.go index 6a34500..7539f0c 100644 --- a/katzenmint/app_test.go +++ b/katzenmint/app_test.go @@ -37,7 +37,7 @@ func TestGetEpoch(t *testing.T) { db := dbm.NewMemDB() defer db.Close() logger := newDiscardLogger() - app := NewKatzenmintApplication(kConfig, db, logger) + app := NewKatzenmintApplication(kConfig, db, testDBCacheSize, logger) m := mock.ABCIApp{ App: app, } @@ -76,7 +76,7 @@ func TestAddAuthority(t *testing.T) { db := dbm.NewMemDB() defer db.Close() logger := newDiscardLogger() - app := NewKatzenmintApplication(kConfig, db, logger) + app := NewKatzenmintApplication(kConfig, db, testDBCacheSize, logger) m := mock.ABCIApp{ App: app, } @@ -133,7 +133,7 @@ func TestPostDescriptorAndCommit(t *testing.T) { db := dbm.NewMemDB() defer db.Close() logger := newDiscardLogger() - app := NewKatzenmintApplication(kConfig, db, logger) + app := NewKatzenmintApplication(kConfig, db, testDBCacheSize, logger) m := mock.ABCIApp{ App: app, } diff --git a/katzenmint/cmd/katzenmint/run.go b/katzenmint/cmd/katzenmint/run.go index 5bb7cd6..ef07540 100644 --- a/katzenmint/cmd/katzenmint/run.go +++ b/katzenmint/cmd/katzenmint/run.go @@ -32,7 +32,8 @@ var ( Short: "Run katzenmint PKI node", RunE: runNode, } - configFile string + configFile string + dbCacheSize int ) func readTendermintConfig(tConfigFile string) (config *cfg.Config, err error) { @@ -105,6 +106,7 @@ func newTendermint(app abci.Application, config *cfg.Config, logger log.Logger) func init() { rootCmd.PersistentFlags().StringVar(&configFile, "config", "katzenmint.toml", "Path to katzenmint.toml") + runCmd.Flags().IntVar(&dbCacheSize, "dbcachesize", 100, "Cache size for katzenmint db") rootCmd.AddCommand(runCmd) rootCmd.AddCommand(registerValidatorCmd) } @@ -134,7 +136,7 @@ func runNode(cmd *cobra.Command, args []string) error { return fmt.Errorf("failed to parse log level: %+v", err) } - app := katzenmint.NewKatzenmintApplication(kConfig, db, logger) + app := katzenmint.NewKatzenmintApplication(kConfig, db, dbCacheSize, logger) defer app.Close() node, err := newTendermint(app, config, logger) diff --git a/katzenmint/state.go b/katzenmint/state.go index 7e18992..1454a3e 100644 --- a/katzenmint/state.go +++ b/katzenmint/state.go @@ -69,8 +69,8 @@ type KatzenmintState struct { * Load & Save State * *****************************************/ -func NewKatzenmintState(kConfig *config.Config, db dbm.DB) *KatzenmintState { - tree, err := iavl.NewMutableTree(db, 100) +func NewKatzenmintState(kConfig *config.Config, db dbm.DB, dbCacheSize int) *KatzenmintState { + tree, err := iavl.NewMutableTree(db, dbCacheSize) if err != nil { panic(fmt.Errorf("error creating iavl tree")) } diff --git a/katzenmint/state_test.go b/katzenmint/state_test.go index f85ffca..ea84e52 100644 --- a/katzenmint/state_test.go +++ b/katzenmint/state_test.go @@ -20,6 +20,7 @@ import ( ) const testEpoch = GenesisEpoch +const testDBCacheSize = 100 var kConfig *config.Config @@ -33,7 +34,7 @@ func TestNewStateBasic(t *testing.T) { // create katzenmint state db := dbm.NewMemDB() defer db.Close() - state := NewKatzenmintState(kConfig, db) + state := NewKatzenmintState(kConfig, db, testDBCacheSize) // advance block height require.Equal(int64(0), state.blockHeight) @@ -42,7 +43,7 @@ func TestNewStateBasic(t *testing.T) { require.Equal(int64(1), state.blockHeight) // test that basic state info can be rebuilt - state = NewKatzenmintState(kConfig, db) + state = NewKatzenmintState(kConfig, db, testDBCacheSize) require.Equal(int64(1), state.blockHeight) require.Equal(GenesisEpoch, state.currentEpoch) require.Equal(int64(0), state.epochStartHeight) @@ -54,7 +55,7 @@ func TestUpdateDescriptor(t *testing.T) { // create katzenmint state db := dbm.NewMemDB() defer db.Close() - state := NewKatzenmintState(kConfig, db) + state := NewKatzenmintState(kConfig, db, testDBCacheSize) // create test descriptor desc, rawDesc, _ := testutil.CreateTestDescriptor(require, 1, pki.LayerProvider, testEpoch) @@ -87,7 +88,7 @@ func TestUpdateAuthority(t *testing.T) { // create katzenmint state db := dbm.NewMemDB() defer db.Close() - state := NewKatzenmintState(kConfig, db) + state := NewKatzenmintState(kConfig, db, testDBCacheSize) // create authority k, err := eddsa.NewKeypair(rand.Reader) @@ -138,7 +139,7 @@ func TestDocumentGenerationUponCommit(t *testing.T) { // create katzenmint state db := dbm.NewMemDB() defer db.Close() - state := NewKatzenmintState(kConfig, db) + state := NewKatzenmintState(kConfig, db, testDBCacheSize) epoch := state.currentEpoch // create descriptorosts of providers @@ -220,7 +221,7 @@ func TestDocumentGenerationUponCommit(t *testing.T) { } // test the document can be reloaded - newState := NewKatzenmintState(kConfig, db) + newState := NewKatzenmintState(kConfig, db, testDBCacheSize) if newState.prevDocument == nil { t.Fatalf("The pki document should be reloaded\n") } diff --git a/server/server_shutdown_test.go b/server/server_shutdown_test.go index 247d3a6..2f490dc 100644 --- a/server/server_shutdown_test.go +++ b/server/server_shutdown_test.go @@ -45,6 +45,8 @@ var ( abciClient *local.Local ) +const testDBCacheSize = 100 + func newDiscardLogger() (logger tmlog.Logger) { logger = tmlog.NewTMLogger(tmlog.NewSyncWriter(ioutil.Discard)) return @@ -155,7 +157,7 @@ func TestMain(m *testing.M) { // start katzenmint node in the background to test against db := dbm.NewMemDB() logger := newDiscardLogger() - app := kpki.NewKatzenmintApplication(kconf.DefaultConfig(), db, logger) + app := kpki.NewKatzenmintApplication(kconf.DefaultConfig(), db, testDBCacheSize, logger) node := rpctest.StartTendermint(app, rpctest.SuppressStdout) abciClient = local.New(node)