Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change to create chCheckTx with the value set in app config. #756

Merged
merged 5 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
17 changes: 17 additions & 0 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
}
14 changes: 12 additions & 2 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 size of channel check tx in Baseapp
DefaultChanCheckTxSize = 10000
)

// BaseConfig defines the server's basic configuration
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -231,6 +237,7 @@ func DefaultConfig() *Config {
PruningInterval: "0",
MinRetainBlocks: 0,
IndexEvents: make([]string, 0),
ChanCheckTxSize: DefaultChanCheckTxSize,
},
Telemetry: telemetry.Config{
Enabled: false,
Expand Down Expand Up @@ -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"),
Expand Down
4 changes: 4 additions & 0 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 }}

###############################################################################
### Telemetry Configuration ###
###############################################################################
Expand Down
3 changes: 3 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
FlagTrace = "trace"
FlagInvCheckPeriod = "inv-check-period"
FlagPrometheus = "prometheus"
FlagChanCheckTxSize = "chan-check-tx-size"

FlagPruning = "pruning"
FlagPruningKeepRecent = "pruning-keep-recent"
Expand Down Expand Up @@ -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 size of the channel check tx")

// add support for all Ostracon-specific command line options
ostcmd.AddNodeFlags(cmd)
return cmd
Expand Down
1 change: 1 addition & 0 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
)
}

Expand Down