Skip to content

Commit

Permalink
Merge branch 'main' into foundation_invariant
Browse files Browse the repository at this point in the history
  • Loading branch information
0Tech authored Oct 26, 2022
2 parents 99950d8 + eb1b5e2 commit 98ec5d5
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 15 deletions.
3 changes: 3 additions & 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
* (x/foundation) [\#758](https://github.com/line/lbm-sdk/pull/758) add invariants to x/foundation

### Improvements
Expand Down Expand Up @@ -121,6 +122,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/foundation) [\#730](https://github.com/line/lbm-sdk/pull/730) prune stale x/foundation proposals at voting period end
* (cli) [\#734](https://github.com/line/lbm-sdk/pull/734) add restrictions on the number of args in the CLIs
* (client) [\#737](https://github.com/line/lbm-sdk/pull/737) check multisig key list to prevent unexpected key deletion
* (simapp) [\#752](https://github.com/line/lbm-sdk/pull/752) add x/distribution's module account into blockedAddr

### Breaking Changes
* (proto) [\#564](https://github.com/line/lbm-sdk/pull/564) change gRPC path to original cosmos path
Expand All @@ -146,3 +148,4 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (docs) [\#490](https://github.com/line/lbm-sdk/pull/490) update documents on x/consortium
* (docs) [\#602](https://github.com/line/lbm-sdk/pull/602) update outdated events in specs
* (docs) [\#721](https://github.com/line/lbm-sdk/pull/721) update x/foundation specification
* (docs) [\#748](https://github.com/line/lbm-sdk/pull/748) add `GovMint` to x/foundation specification
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ require (
github.com/regen-network/cosmos-proto v0.3.1
github.com/rs/zerolog v1.28.0
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,8 @@ github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tL
github.com/spf13/cobra v1.3.0/go.mod h1:BrRVncBjOJa/eUcVVm9CE+oC6as8k+VYr4NY7WCi9V4=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI=
github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
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
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ var (

// module accounts that are allowed to receive tokens
allowedReceivingModAcc = map[string]bool{
distrtypes.ModuleName: true,
// govtypes.ModuleName: true, // TODO: uncomment it when authority is ready
}
)

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
2 changes: 1 addition & 1 deletion x/bank/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (suite *IntegrationTestSuite) TestExportGenesis() {

func (suite *IntegrationTestSuite) getTestBalancesAndSupply() ([]types.Balance, sdk.Coins) {
addr2, _ := sdk.AccAddressFromBech32("link1f9xjhxm0plzrh9cskf4qee4pc2xwp0n0p662v8")
addr1, _ := sdk.AccAddressFromBech32("link1jv65s3grqf6v6jl3dp4t6c9t9rk99cd8j3y7jh") // distribution module address
addr1, _ := sdk.AccAddressFromBech32("link1t5u0jfg3ljsjrh2m9e47d4ny2hea7eehndz0n9")
addr1Balance := sdk.Coins{sdk.NewInt64Coin("testcoin3", 10)}
addr2Balance := sdk.Coins{sdk.NewInt64Coin("testcoin1", 32), sdk.NewInt64Coin("testcoin2", 34)}

Expand Down
12 changes: 6 additions & 6 deletions x/bank/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ func (suite *SimTestSuite) TestSimulateModuleAccountMsgSend() {
r = rand.New(s)

operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "")
suite.Require().NoError(err)
suite.Require().Error(err)

var msg types.MsgSend
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)

suite.Require().True(operationMsg.OK)
suite.Require().Empty(operationMsg.Comment)
suite.Require().False(operationMsg.OK)
suite.Require().Equal(operationMsg.Comment, "invalid transfers")
suite.Require().Equal(types.TypeMsgSend, msg.Type())
suite.Require().Equal(types.ModuleName, msg.Route())
suite.Require().Len(futureOperations, 0)
Expand All @@ -173,13 +173,13 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() {
op := simulation.SimulateMsgMultiSendToModuleAccount(suite.app.AccountKeeper, suite.app.BankKeeper, mAccCount)

operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "")
suite.Require().NoError(err)
suite.Require().Error(err)

var msg types.MsgMultiSend
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)

suite.Require().True(operationMsg.OK) // sending tokens to a module account should fail
suite.Require().Empty(operationMsg.Comment)
suite.Require().False(operationMsg.OK) // sending tokens to a module account should fail
suite.Require().Equal(operationMsg.Comment, "invalid transfers")
suite.Require().Equal(types.TypeMsgMultiSend, msg.Type())
suite.Require().Equal(types.ModuleName, msg.Route())
suite.Require().Len(futureOperations, 0)
Expand Down
29 changes: 28 additions & 1 deletion x/foundation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ back these foundation-specific functionalities.
* [Msg/Revoke](#msgrevoke)
* [Msg/FundTreasury](#msgfundtreasury)
* [Msg/WithdrawFromTreasury](#msgwithdrawfromtreasury)
* [Msg/GovMint](#msggovmint)
* [Events](#events)
* [EventUpdateFoundationParams](#eventupdatefoundationparams)
* [EventUpdateDecisionPolicy](#eventupdatedecisionpolicy)
Expand All @@ -44,6 +45,7 @@ back these foundation-specific functionalities.
* [EventRevoke](#eventrevoke)
* [EventFundTreasury](#eventfundedtreasury)
* [EventWithdrawFromTreasury](#eventwithdrawedfromtreasury)
* [EventGovMint](#eventgovmint)
* [Client](#client)
* [CLI](#cli)
* [gRPC](#grpc)
Expand Down Expand Up @@ -262,6 +264,12 @@ sending the message `Msg/WithdrawFromTreasury`.
value again (irreversible), which means you must set it to a non-zero value in
the genesis to make it work.

## GovMint

When the chain is first started, it may be necessary to mint a large amount of
coins at most once for initial validators or for specific purposes. Newly minted
coins are transferred to the treasury pool.

# State

## Params
Expand Down Expand Up @@ -476,7 +484,7 @@ Anyone can fund treasury with `MsgFundTreasury`.

+++ https://github.com/line/lbm-sdk/blob/392277a33519d289154e8da27f05f9a6788ab076/proto/lbm/foundation/v1/tx.proto#L76-L81

## Msg/WithdrawFromTresury
## Msg/WithdrawFromTreasury

The foundation can withdraw coins from the treasury with
`MsgWithdrawFromTreasury`.
Expand All @@ -489,6 +497,17 @@ The message handling should fail if:
* the address which receives the coins has no authorization of
`ReceiveFromTreasuryAuthorization`.

## Msg/GovMint

Massive minting is possible through 'MsgGovMint' up to 1 time after the chain is started.

+++ https://github.com/line/lbm-sdk/blob/66988a235a0e01f7a1ee76d719d585ff35f0d176/proto/lbm/foundation/v1/tx.proto#L221-L225

The message handling should fail if:

* the authority is not the module's authority.
* The remaining left count is 0.

# Events

## EventUpdateFoundationParams
Expand Down Expand Up @@ -598,6 +617,14 @@ the treasury.
| to | {toAddress} |
| amount | {amount} |

## EventGovMint

`EventGovMint` is an event emitted when coins are minted.

| Attribute Key | Attribute Value |
|---------------|-----------------|
| amount | {amount} |

# Client

## CLI
Expand Down

0 comments on commit 98ec5d5

Please sign in to comment.