From 89c048474b2ea9bfc33a8f8e9d367eadef3886ac Mon Sep 17 00:00:00 2001 From: zemyblue Date: Tue, 25 Oct 2022 20:53:50 +0900 Subject: [PATCH 1/5] feat: add `chCheckTxSize` configuration of Baseapp Signed-off-by: zemyblue --- baseapp/baseapp.go | 9 ++++++++- baseapp/options.go | 14 ++++++++++++-- server/config/config.go | 8 ++++++++ server/config/toml.go | 4 ++++ server/start.go | 3 +++ simapp/simd/cmd/root.go | 1 + 6 files changed, 36 insertions(+), 3 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 0e2ccbe649..356c586f24 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -16,6 +16,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/line/lbm-sdk/codec/types" + "github.com/line/lbm-sdk/server/config" "github.com/line/lbm-sdk/snapshots" "github.com/line/lbm-sdk/store" "github.com/line/lbm-sdk/store/rootmulti" @@ -75,6 +76,7 @@ type BaseApp struct { // nolint: maligned checkAccountWGs *AccountWGs chCheckTx chan *RequestCheckTxAsync + chCheckTxSize uint // chCheckTxSize is the initial size for chCheckTx // an inter-block write-through cache provided to the context during deliverState interBlockCache sdk.MultiStorePersistentCache @@ -153,13 +155,18 @@ func NewBaseApp( txDecoder: txDecoder, fauxMerkleMode: false, checkAccountWGs: NewAccountWGs(), - chCheckTx: make(chan *RequestCheckTxAsync, 10000), // TODO config channel buffer size. It might be good to set it tendermint mempool.size } for _, option := range options { option(app) } + chCheckTxSize := app.chCheckTxSize + if chCheckTxSize == 0 { + chCheckTxSize = config.DefaultChanCheckTxSize + } + app.chCheckTx = make(chan *RequestCheckTxAsync, chCheckTxSize) + if app.interBlockCache != nil { app.cms.SetInterBlockCache(app.interBlockCache) } diff --git a/baseapp/options.go b/baseapp/options.go index 14b3301ae8..ecc3e7643a 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -6,11 +6,10 @@ import ( dbm "github.com/tendermint/tm-db" - "github.com/line/lbm-sdk/store/cache" - "github.com/line/lbm-sdk/codec/types" "github.com/line/lbm-sdk/snapshots" "github.com/line/lbm-sdk/store" + "github.com/line/lbm-sdk/store/cache" sdk "github.com/line/lbm-sdk/types" ) @@ -90,6 +89,10 @@ func SetSnapshotStore(snapshotStore *snapshots.Store) func(*BaseApp) { return func(app *BaseApp) { app.SetSnapshotStore(snapshotStore) } } +func SetChanCheckTxSize(size uint) func(*BaseApp) { + return func(app *BaseApp) { app.SetChanCheckTxSize(size) } +} + func (app *BaseApp) SetName(name string) { if app.sealed { panic("SetName() on sealed BaseApp") @@ -250,6 +253,13 @@ func (app *BaseApp) SetInterfaceRegistry(registry types.InterfaceRegistry) { app.msgServiceRouter.SetInterfaceRegistry(registry) } +func (app *BaseApp) SetChanCheckTxSize(chanCheckTxSize uint) { + if app.sealed { + panic("SetChanCheckTxSize() on sealed BaseApp") + } + app.chCheckTxSize = chanCheckTxSize +} + func MetricsProvider(prometheus bool) cache.MetricsProvider { namespace := "app" if prometheus { diff --git a/server/config/config.go b/server/config/config.go index 810c46cfaf..f6d974fdc9 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -23,6 +23,9 @@ const ( // DefaultGRPCWebAddress defines the default address to bind the gRPC-web server to. DefaultGRPCWebAddress = "0.0.0.0:9091" + + // DefaultChanCheckTxSize defines the default maximum size of channel check tx in Baseapp + DefaultChanCheckTxSize = 10000 ) // BaseConfig defines the server's basic configuration @@ -85,6 +88,9 @@ type BaseConfig struct { // When true, Prometheus metrics are served under /metrics on prometheus_listen_addr in config.toml. // It works when tendermint's prometheus option (config.toml) is set to true. Prometheus bool `mapstructure:"prometheus"` + + // ChanCheckTxSize is the size of RequestCheckTxAsync of BaseApp + ChanCheckTxSize uint `mapstructure:"chan-check-tx-size"` } // APIConfig defines the API listener configuration. @@ -231,6 +237,7 @@ func DefaultConfig() *Config { PruningInterval: "0", MinRetainBlocks: 0, IndexEvents: make([]string, 0), + ChanCheckTxSize: DefaultChanCheckTxSize, }, Telemetry: telemetry.Config{ Enabled: false, @@ -294,6 +301,7 @@ func GetConfig(v *viper.Viper) Config { MinRetainBlocks: v.GetUint64("min-retain-blocks"), IAVLDisableFastNode: v.GetBool("iavl-disable-fastnode"), IAVLCacheSize: v.GetUint64("iavl-cache-size"), + ChanCheckTxSize: v.GetUint("chan-check-tx-size"), }, Telemetry: telemetry.Config{ ServiceName: v.GetString("telemetry.service-name"), diff --git a/server/config/toml.go b/server/config/toml.go index d6a4d23946..f94707a836 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -86,6 +86,10 @@ index-events = {{ .BaseConfig.IndexEvents }} # It works when tendermint's prometheus option (config.toml) is set to true. prometheus = {{ .BaseConfig.Prometheus }} +# ChanCheckTxSize is he size of RequestCheckTxAsync of BaseApp +# ChanCheckTxSize should be equals to or greater than the mempool size. +chan-check-tx-size = {{ .BaseConfig.ChanCheckTxSize }} + ############################################################################### ### Telemetry Configuration ### ############################################################################### diff --git a/server/start.go b/server/start.go index bb18d72408..624f1a0f75 100644 --- a/server/start.go +++ b/server/start.go @@ -52,6 +52,7 @@ const ( FlagTrace = "trace" FlagInvCheckPeriod = "inv-check-period" FlagPrometheus = "prometheus" + FlagChanCheckTxSize = "chan-check-tx-size" FlagPruning = "pruning" FlagPruningKeepRecent = "pruning-keep-recent" @@ -175,6 +176,8 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. cmd.Flags().Bool(FlagPrometheus, false, "Enable prometheus metric for app") + cmd.Flags().Uint(FlagChanCheckTxSize, config.DefaultChanCheckTxSize, "The maximum size of the chan-check-tx-size") + // add support for all Ostracon-specific command line options ostcmd.AddNodeFlags(cmd) return cmd diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index 7797f70f56..3bfacbdfe5 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -287,6 +287,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a baseapp.SetSnapshotStore(snapshotStore), baseapp.SetSnapshotInterval(cast.ToUint64(appOpts.Get(server.FlagStateSyncSnapshotInterval))), baseapp.SetSnapshotKeepRecent(cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent))), + baseapp.SetChanCheckTxSize(cast.ToUint(appOpts.Get(server.FlagChanCheckTxSize))), ) } From d72d41cc5448f614baa71e19d11e81e45c4859fc Mon Sep 17 00:00:00 2001 From: zemyblue Date: Tue, 25 Oct 2022 21:10:40 +0900 Subject: [PATCH 2/5] chore: add unittest Signed-off-by: zemyblue --- baseapp/baseapp_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index cec1cc826e..8e3d6587c3 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -22,6 +22,7 @@ import ( "github.com/line/lbm-sdk/codec" "github.com/line/lbm-sdk/codec/legacy" + "github.com/line/lbm-sdk/server/config" "github.com/line/lbm-sdk/snapshots" snapshottypes "github.com/line/lbm-sdk/snapshots/types" "github.com/line/lbm-sdk/store/rootmulti" @@ -542,6 +543,9 @@ func TestBaseAppOptionSeal(t *testing.T) { require.Panics(t, func() { app.SetRouter(NewRouter()) }) + require.Panics(t, func() { + app.SetChanCheckTxSize(10) + }) } func TestSetMinGasPrices(t *testing.T) { @@ -2069,3 +2073,16 @@ func TestSnapshotManager(t *testing.T) { app.SetSnapshotStore(snapshotStore) require.NotNil(t, app.SnapshotManager()) } + +func TestSetChanCheckTxSize(t *testing.T) { + logger := defaultLogger() + db := dbm.NewMemDB() + + var size = uint(100) + + app := NewBaseApp(t.Name(), logger, db, nil, SetChanCheckTxSize(size)) + require.Equal(t, int(size), cap(app.chCheckTx)) + + app = NewBaseApp(t.Name(), logger, db, nil) + require.Equal(t, config.DefaultChanCheckTxSize, cap(app.chCheckTx)) +} From fb991d0d60b6516a95fd3a9471f7bd2ab76c55b8 Mon Sep 17 00:00:00 2001 From: zemyblue Date: Tue, 25 Oct 2022 21:44:56 +0900 Subject: [PATCH 3/5] chore: update changelog Signed-off-by: zemyblue --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df0ba6f6b5..9ce716e022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (config) [\#665](https://github.com/line/lbm-sdk/pull/665) remove bech32-cache-size * (x/foundation) [\#709](https://github.com/line/lbm-sdk/pull/709) add `gov mint` for x/foundation proposal * (iavl) [\#738](https://github.com/line/lbm-sdk/pull/738) bump github.com/cosmos/iavl from v0.17.3 to v0.19.3 +* (baseapp) [\#756](https://github.com/line/lbm-sdk/pull/756) Change to create chCheckTx with the value set in app config ### Improvements From ad02b577a235a35b5d0c7756cf0e6b512a6cba69 Mon Sep 17 00:00:00 2001 From: zemyblue Date: Wed, 26 Oct 2022 11:29:35 +0900 Subject: [PATCH 4/5] chore: fix typo and add more description Signed-off-by: zemyblue --- server/config/toml.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/config/toml.go b/server/config/toml.go index f94707a836..8598dbf608 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -86,8 +86,8 @@ index-events = {{ .BaseConfig.IndexEvents }} # It works when tendermint's prometheus option (config.toml) is set to true. prometheus = {{ .BaseConfig.Prometheus }} -# ChanCheckTxSize is he size of RequestCheckTxAsync of BaseApp -# ChanCheckTxSize should be equals to or greater than the mempool size. +# ChanCheckTxSize is the size of RequestCheckTxAsync of BaseApp. +# ChanCheckTxSize should be equals to or greater than the mempool size set in config.toml of Ostracon. chan-check-tx-size = {{ .BaseConfig.ChanCheckTxSize }} ############################################################################### From f8ab4717f53130c835b438b138effb5f81b5b38c Mon Sep 17 00:00:00 2001 From: zemyblue Date: Wed, 26 Oct 2022 13:25:05 +0900 Subject: [PATCH 5/5] chore: correct ambiguous sentences Signed-off-by: zemyblue --- server/config/config.go | 2 +- server/start.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index f6d974fdc9..c37d1a3641 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -24,7 +24,7 @@ const ( // DefaultGRPCWebAddress defines the default address to bind the gRPC-web server to. DefaultGRPCWebAddress = "0.0.0.0:9091" - // DefaultChanCheckTxSize defines the default maximum size of channel check tx in Baseapp + // DefaultChanCheckTxSize defines the default size of channel check tx in Baseapp DefaultChanCheckTxSize = 10000 ) diff --git a/server/start.go b/server/start.go index 624f1a0f75..763c9507ba 100644 --- a/server/start.go +++ b/server/start.go @@ -176,7 +176,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. cmd.Flags().Bool(FlagPrometheus, false, "Enable prometheus metric for app") - cmd.Flags().Uint(FlagChanCheckTxSize, config.DefaultChanCheckTxSize, "The maximum size of the chan-check-tx-size") + cmd.Flags().Uint(FlagChanCheckTxSize, config.DefaultChanCheckTxSize, "The size of the channel check tx") // add support for all Ostracon-specific command line options ostcmd.AddNodeFlags(cmd)