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!: custom fee distribution #485

Merged
merged 21 commits into from
Oct 28, 2021
Merged
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
- [#421](https://github.com/Pylons-tech/pylons/pull/421) Recipe execution validation and item matching logic fixed.

### Client Breaking Changes
- [#476](https://github.com/Pylons-tech/pylons/pull/476) Removes `rate` field from `*Param` proto messages.
- [#485](https://github.com/Pylons-tech/pylons/pull/485) Add fee distribution and the `x/epochs` module.
- [#476](https://github.com/Pylons-tech/pylons/pull/476) Remove `rate` field from `*Param` proto messages.

### Changes:
- [#467](https://github.com/Pylons-tech/pylons/pull/467) Remove the `/flutter/` directory. Code has been [moved](https://github.com/Pylons-tech/flutter_wallet).
Expand Down
31 changes: 31 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ import (

"github.com/Pylons-tech/pylons/docs"

epochsmodule "github.com/Pylons-tech/pylons/x/epochs"
epochsmodulekeeper "github.com/Pylons-tech/pylons/x/epochs/keeper"
epochsmoduletypes "github.com/Pylons-tech/pylons/x/epochs/types"

// this line is used by starport scaffolding # stargate/app/moduleImport
appparams "github.com/Pylons-tech/pylons/app/params"
pylonsmodule "github.com/Pylons-tech/pylons/x/pylons"
Expand Down Expand Up @@ -149,6 +153,7 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
epochsmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
pylonsmodule.AppModuleBasic{},
)
Expand Down Expand Up @@ -222,6 +227,7 @@ type App struct {
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper

EpochsKeeper epochsmodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

PylonsKeeper pylonsmodulekeeper.Keeper
Expand Down Expand Up @@ -268,6 +274,7 @@ func New(
evidencetypes.StoreKey,
ibctransfertypes.StoreKey,
capabilitytypes.StoreKey,
epochsmoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
pylonsmoduletypes.StoreKey,
)
Expand Down Expand Up @@ -389,6 +396,21 @@ func New(
app.GetSubspace(pylonsmoduletypes.ModuleName),
)

epochsKeeper := epochsmodulekeeper.NewKeeper(
appCodec,
keys[epochsmoduletypes.StoreKey],
keys[epochsmoduletypes.MemStoreKey],
)

app.EpochsKeeper = *epochsKeeper.SetHooks(
epochsmoduletypes.NewMultiEpochHooks(
// insert epoch hook receivers here
app.PylonsKeeper.Hooks(app.StakingKeeper),
),
)

epochsModule := epochsmodule.NewAppModule(appCodec, app.EpochsKeeper)

// Set node version from build configuration
pylonsmoduletypes.SetNodeVersionString(version.Version)
pylonsModule := pylonsmodule.NewAppModule(appCodec, app.PylonsKeeper, app.BankKeeper)
Expand Down Expand Up @@ -422,6 +444,7 @@ func New(
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
epochsModule,
// this line is used by starport scaffolding # stargate/app/appModule
pylonsModule,
)
Expand All @@ -431,6 +454,8 @@ func New(
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
// Note: epochs' begin should be "real" start of epochs, we keep epochs beginblock at the beginning
epochsmoduletypes.ModuleName,
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
minttypes.ModuleName,
Expand All @@ -450,6 +475,8 @@ func New(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
pylonsmoduletypes.ModuleName,
// Note: epochs' endblock should be "real" end of epochs, we keep epochs endblock at the end
epochsmoduletypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -471,6 +498,7 @@ func New(
genutiltypes.ModuleName,
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
epochsmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
pylonsmoduletypes.ModuleName,
)
Expand All @@ -495,8 +523,10 @@ func New(
params.NewAppModule(app.ParamsKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
epochsmodule.NewAppModule(appCodec, app.EpochsKeeper),

transferModule,
pylonsModule,
)

app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -679,6 +709,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(epochsmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace
paramsKeeper.Subspace(pylonsmoduletypes.ModuleName)

Expand Down
85 changes: 83 additions & 2 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,89 @@ func init() {
simapp.GetSimulatorFlags()
}

func TestFullAppSimulation(t *testing.T) {
// -Enabled=true -NumBlocks=1000 -BlockSize=200 \
// -Period=1 -Commit=true -Seed=57 -v -timeout 24h
simapp.FlagEnabledValue = true
simapp.FlagNumBlocksValue = 20
simapp.FlagBlockSizeValue = 25
simapp.FlagCommitValue = true
simapp.FlagVerboseValue = true
simapp.FlagPeriodValue = 10
simapp.FlagSeedValue = 10
fullAppSimulation(t, true)
}

func fullAppSimulation(tb testing.TB, is_testing bool) {
config, db, dir, logger, _, err := simapp.SetupSimulation("goleveldb-app-sim", "Simulation")
if err != nil {
tb.Fatalf("simulation setup failed: %s", err.Error())
}

defer func() {
db.Close()
err = os.RemoveAll(dir)
if err != nil {
tb.Fatal(err)
}
}()

// fauxMerkleModeOpt returns a BaseApp option to use a dbStoreAdapter instead of
// an IAVLStore for faster simulation speed.
fauxMerkleModeOpt := func(bapp *baseapp.BaseApp) {
if is_testing {
bapp.SetFauxMerkleMode()
}
}

cmdApp := pylons.New(
logger,
db,
nil,
true, // load latest
map[int64]bool{},
pylons.DefaultNodeHome,
simapp.FlagPeriodValue,
cosmoscmd.MakeEncodingConfig(pylons.ModuleBasics),
simapp.EmptyAppOptions{},
interBlockCacheOpt(),
fauxMerkleModeOpt)

var app *pylons.App
switch cmdApp.(type) {
case *pylons.App:
app = cmdApp.(*pylons.App)
default:
panic("imported simApp incorrectly")
}

// Run randomized simulation:
_, simParams, simErr := simulation.SimulateFromSeed(
tb,
os.Stdout,
app.BaseApp,
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
simulation2.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simapp.SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
app.AppCodec(),
)

// export state and simParams before the simulation error is checked
if err = simapp.CheckExportSimulation(app, config, simParams); err != nil {
tb.Fatal(err)
}

if simErr != nil {
tb.Fatal(simErr)
}

if config.Commit {
simapp.PrintStats(db)
}
}

// Profile with:
// /usr/local/go/bin/go test -benchmem -run=^$ github.com/cosmos/cosmos-sdk/GaiaApp -bench ^BenchmarkFullAppSimulation$ -Commit=true -cpuprofile cpu.out
func BenchmarkFullAppSimulation(b *testing.B) {
Expand Down Expand Up @@ -85,8 +168,6 @@ func interBlockCacheOpt() func(*baseapp.BaseApp) {
return baseapp.SetInterBlockCache(store.NewCommitKVStoreCacheManager())
}

//// TODO: Make another test for the fuzzer itself, which just has noOp txs
//// and doesn't depend on the application.
func TestAppStateDeterminism(t *testing.T) {
if !simapp.FlagEnabledValue {
t.Skip("skipping application simulation")
Expand Down
Loading