Skip to content

Commit

Permalink
Merge pull request #158 from hashcloak/feature/add-cache-size
Browse files Browse the repository at this point in the history
katzenmint: add dbcachesize parameter
  • Loading branch information
sc0Vu authored Oct 25, 2022
2 parents 1a69f13 + 8b19b11 commit c613320
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
4 changes: 3 additions & 1 deletion client/pkiclient/katzenmint_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var (
abciClient *local.Local
)

const testDBCacheSize = 100

func newDiscardLogger() (logger log.Logger) {
logger = log.NewTMLogger(log.NewSyncWriter(ioutil.Discard))
return
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions katzenmint/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions katzenmint/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
6 changes: 4 additions & 2 deletions katzenmint/cmd/katzenmint/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions katzenmint/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down
13 changes: 7 additions & 6 deletions katzenmint/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
)

const testEpoch = GenesisEpoch
const testDBCacheSize = 100

var kConfig *config.Config

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 3 additions & 1 deletion server/server_shutdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var (
abciClient *local.Local
)

const testDBCacheSize = 100

func newDiscardLogger() (logger tmlog.Logger) {
logger = tmlog.NewTMLogger(tmlog.NewSyncWriter(ioutil.Discard))
return
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c613320

Please sign in to comment.