Skip to content

Instantly share code, notes, and snippets.

@cordt-sei
Created December 23, 2024 21:42
Show Gist options
  • Save cordt-sei/9057959f00c02b912125916c8ec3e6d5 to your computer and use it in GitHub Desktop.
Save cordt-sei/9057959f00c02b912125916c8ec3e6d5 to your computer and use it in GitHub Desktop.
commit 5bff2163b81a0ef5d7ef99adaaab5ebe8dae013d
Author: Adam Tucker <[email protected]>
Date: Fri May 24 14:16:37 2024 -0600
feat: sdk v0.50.x upgrade (#8274)
* initial push
* delete
* tidy
* add replace
* proto
* excludes
* update go mods
* fix
* initial pass through modules
* checkpoint
* checkpoint
* another round
* fork update with fixes
* fork bumps
* more fixes
* move to cosmosdb
* signModeHandler fix
* more fixes
* store fixes
* checkpoint
* checkpoint
* more event fixes
* GetSigners fix for tests
* get signers fixes
* smart account fixes
* fixes
* checkpoint
* txfees completion
* more errors
* rosetta import
* address simulation
* smart account get sign bytes
* disable streaming service
* some test fixes
* as signer proto
* fix some tests
* fix superfluid test
* more fixes
* fix gamm keeper test with note
* fix authz serialization
* fix validate basic test
* incentives test fix
* fix lockup test
* begin and end block fixes
* fix epochs tests
* fix all upgrade tests
* fix txfees test
* fix e2e init test
* more fixes
* updated ibctesting overrides. Removed unnecessary receiver length check test (now checked on ibc sends). Rate limit tests pass
* smart account integration test fixes
* SetAccount no longer needed. Done internally.
* more set account issues
* gas checks are not needed when using selected authenticators. That was a legacy check
* fix accounts and codec
* using codec with proper "osmo" prefix. The default test codec uses "cosmos" and there's no way to override it
* fix ibc-hooks tests
* streaming fixes
* upgrade handler
* tidy
* golang bump 1.22
* prevent circular dep
* update osmoutils
* tidy
* remove local replaces for testing
* set up module.go
* fix dockerfile for local work
* module changes
* fix e2e
* more ci fixes
* fix simulator
* lints
* remove wrap
* lints
* lints
* clean up the TODOs
* more todo clean ups
* comments
* comments
* move test outside of osmoutils
* clean up go mods
* fix errors for GetDelegation
* return error instead of panic
* chore: fix build
* fix weird error check
* ignore words
* more spelling fixes
* final spelling errors
* Revert "more spelling fixes"
This reverts commit 5c8698ba6d82978a0ea0d33fe443cfb5d9a01dc1.
* redo spelling check
---------
Co-authored-by: Nicolas Lara <[email protected]>
Co-authored-by: PaddyMc <[email protected]>
diff --git a/app/app.go b/app/app.go
--- a/app/app.go
+++ b/app/app.go
@@ -557,154 +624,195 @@
}
reflectionSvc, err := runtimeservices.NewReflectionService()
if err != nil {
panic(err)
}
cachedReflectionService = reflectionSvc
return reflectionSvc
}
// InitOsmosisAppForTestnet is broken down into two sections:
// Required Changes: Changes that, if not made, will cause the testnet to halt or panic
// Optional Changes: Changes to customize the testnet to one's liking (lower vote times, fund accounts, etc)
func InitOsmosisAppForTestnet(app *OsmosisApp, newValAddr bytes.HexBytes, newValPubKey crypto.PubKey, newOperatorAddress, upgradeToTrigger string) *OsmosisApp {
//
// Required Changes:
//
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
pubkey := &ed25519.PubKey{Key: newValPubKey.Bytes()}
pubkeyAny, err := types.NewAnyWithValue(pubkey)
if err != nil {
tmos.Exit(err.Error())
}
// STAKING
//
// Create Validator struct for our new validator.
_, bz, err := bech32.DecodeAndConvert(newOperatorAddress)
if err != nil {
tmos.Exit(err.Error())
}
bech32Addr, err := bech32.ConvertAndEncode("osmovaloper", bz)
if err != nil {
tmos.Exit(err.Error())
}
newVal := stakingtypes.Validator{
OperatorAddress: bech32Addr,
ConsensusPubkey: pubkeyAny,
Jailed: false,
Status: stakingtypes.Bonded,
- Tokens: sdk.NewInt(900000000000000),
- DelegatorShares: sdk.MustNewDecFromStr("10000000"),
+ Tokens: osmomath.NewInt(900000000000000),
+ DelegatorShares: osmomath.MustNewDecFromStr("10000000"),
Description: stakingtypes.Description{
Moniker: "Testnet Validator",
},
Commission: stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates{
- Rate: sdk.MustNewDecFromStr("0.05"),
- MaxRate: sdk.MustNewDecFromStr("0.1"),
- MaxChangeRate: sdk.MustNewDecFromStr("0.05"),
+ Rate: osmomath.MustNewDecFromStr("0.05"),
+ MaxRate: osmomath.MustNewDecFromStr("0.1"),
+ MaxChangeRate: osmomath.MustNewDecFromStr("0.05"),
},
},
- MinSelfDelegation: sdk.OneInt(),
+ MinSelfDelegation: osmomath.OneInt(),
}
// Remove all validators from power store
stakingKey := app.GetKey(stakingtypes.ModuleName)
stakingStore := ctx.KVStore(stakingKey)
- iterator := app.StakingKeeper.ValidatorsPowerStoreIterator(ctx)
+ iterator, err := app.StakingKeeper.ValidatorsPowerStoreIterator(ctx)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Remove all valdiators from last validators store
- iterator = app.StakingKeeper.LastValidatorsIterator(ctx)
+ iterator, err = app.StakingKeeper.LastValidatorsIterator(ctx)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Remove all validators from validators store
- iterator = sdk.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorsKey)
+ iterator = storetypes.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorsKey)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Remove all validators from unbonding queue
- iterator = sdk.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorQueueKey)
+ iterator = storetypes.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorQueueKey)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Add our validator to power and last validators store
- app.StakingKeeper.SetValidator(ctx, newVal)
+ err = app.StakingKeeper.SetValidator(ctx, newVal)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
err = app.StakingKeeper.SetValidatorByConsAddr(ctx, newVal)
if err != nil {
tmos.Exit(err.Error())
}
- app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)
- app.StakingKeeper.SetLastValidatorPower(ctx, newVal.GetOperator(), 0)
- if err := app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, newVal.GetOperator()); err != nil {
+ err = app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+ valAddr, err := sdk.ValAddressFromBech32(newVal.GetOperator())
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+ err = app.StakingKeeper.SetLastValidatorPower(ctx, valAddr, 0)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+ if err := app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, valAddr); err != nil {
panic(err)
}
// DISTRIBUTION
//
// Initialize records for this validator across all distribution stores
- app.DistrKeeper.SetValidatorHistoricalRewards(ctx, newVal.GetOperator(), 0, distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
- app.DistrKeeper.SetValidatorCurrentRewards(ctx, newVal.GetOperator(), distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1))
- app.DistrKeeper.SetValidatorAccumulatedCommission(ctx, newVal.GetOperator(), distrtypes.InitialValidatorAccumulatedCommission())
- app.DistrKeeper.SetValidatorOutstandingRewards(ctx, newVal.GetOperator(), distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}})
+ valAddr, err = sdk.ValAddressFromBech32(newVal.GetOperator())
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+ err = app.DistrKeeper.SetValidatorHistoricalRewards(ctx, valAddr, 0, distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+ err = app.DistrKeeper.SetValidatorCurrentRewards(ctx, valAddr, distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1))
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+ err = app.DistrKeeper.SetValidatorAccumulatedCommission(ctx, valAddr, distrtypes.InitialValidatorAccumulatedCommission())
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+ err = app.DistrKeeper.SetValidatorOutstandingRewards(ctx, valAddr, distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}})
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
// SLASHING
//
// Set validator signing info for our new validator.
newConsAddr := sdk.ConsAddress(newValAddr.Bytes())
newValidatorSigningInfo := slashingtypes.ValidatorSigningInfo{
Address: newConsAddr.String(),
StartHeight: app.LastBlockHeight() - 1,
Tombstoned: false,
}
- app.SlashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newValidatorSigningInfo)
+ err = app.SlashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newValidatorSigningInfo)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
//
// Optional Changes:
//
// GOV
//
newExpeditedVotingPeriod := time.Minute
newVotingPeriod := time.Minute * 2
- govParams := app.GovKeeper.GetParams(ctx)
+ govParams, err := app.GovKeeper.Params.Get(ctx)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
govParams.ExpeditedVotingPeriod = &newExpeditedVotingPeriod
govParams.VotingPeriod = &newVotingPeriod
govParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(appparams.BaseCoinUnit, 100000000))
govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewInt64Coin(appparams.BaseCoinUnit, 150000000))
- err = app.GovKeeper.SetParams(ctx, govParams)
+ err = app.GovKeeper.Params.Set(ctx, govParams)
if err != nil {
tmos.Exit(err.Error())
}
// EPOCHS
//
dayEpochInfo := app.EpochsKeeper.GetEpochInfo(ctx, "day")
dayEpochInfo.Duration = time.Hour * 6
// Prevents epochs from running back to back
dayEpochInfo.CurrentEpochStartTime = time.Now().UTC()
// If you want epoch to run a minute after starting the chain, uncomment the line below and comment the line above
// dayEpochInfo.CurrentEpochStartTime = time.Now().UTC().Add(-dayEpochInfo.Duration).Add(time.Minute)
dayEpochInfo.CurrentEpochStartHeight = app.LastBlockHeight()
app.EpochsKeeper.DeleteEpochInfo(ctx, "day")
err = app.EpochsKeeper.AddEpochInfo(ctx, dayEpochInfo)
if err != nil {
tmos.Exit(err.Error())
commit 77c22c00911a4a3538683d8cb01d6755569134b6
Author: Adam Tucker <[email protected]>
Date: Tue Apr 30 22:27:57 2024 -0600
chore: don't use hardcoded "uosmo" string (#8145)
* check denoms for gauge creation
* changelog
* extract logic
* use uosmo var
* initial push of test fixes
* fix lint
* tidy
* tidy
* add comments
* add test cases
diff --git a/app/app.go b/app/app.go
--- a/app/app.go
+++ b/app/app.go
@@ -554,154 +556,154 @@
}
reflectionSvc, err := runtimeservices.NewReflectionService()
if err != nil {
panic(err)
}
cachedReflectionService = reflectionSvc
return reflectionSvc
}
// InitOsmosisAppForTestnet is broken down into two sections:
// Required Changes: Changes that, if not made, will cause the testnet to halt or panic
// Optional Changes: Changes to customize the testnet to one's liking (lower vote times, fund accounts, etc)
func InitOsmosisAppForTestnet(app *OsmosisApp, newValAddr bytes.HexBytes, newValPubKey crypto.PubKey, newOperatorAddress, upgradeToTrigger string) *OsmosisApp {
//
// Required Changes:
//
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
pubkey := &ed25519.PubKey{Key: newValPubKey.Bytes()}
pubkeyAny, err := types.NewAnyWithValue(pubkey)
if err != nil {
tmos.Exit(err.Error())
}
// STAKING
//
// Create Validator struct for our new validator.
_, bz, err := bech32.DecodeAndConvert(newOperatorAddress)
if err != nil {
tmos.Exit(err.Error())
}
bech32Addr, err := bech32.ConvertAndEncode("osmovaloper", bz)
if err != nil {
tmos.Exit(err.Error())
}
newVal := stakingtypes.Validator{
OperatorAddress: bech32Addr,
ConsensusPubkey: pubkeyAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: sdk.NewInt(900000000000000),
DelegatorShares: sdk.MustNewDecFromStr("10000000"),
Description: stakingtypes.Description{
Moniker: "Testnet Validator",
},
Commission: stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates{
Rate: sdk.MustNewDecFromStr("0.05"),
MaxRate: sdk.MustNewDecFromStr("0.1"),
MaxChangeRate: sdk.MustNewDecFromStr("0.05"),
},
},
MinSelfDelegation: sdk.OneInt(),
}
// Remove all validators from power store
stakingKey := app.GetKey(stakingtypes.ModuleName)
stakingStore := ctx.KVStore(stakingKey)
iterator := app.StakingKeeper.ValidatorsPowerStoreIterator(ctx)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Remove all valdiators from last validators store
iterator = app.StakingKeeper.LastValidatorsIterator(ctx)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Remove all validators from validators store
iterator = sdk.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorsKey)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Remove all validators from unbonding queue
iterator = sdk.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorQueueKey)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Add our validator to power and last validators store
app.StakingKeeper.SetValidator(ctx, newVal)
err = app.StakingKeeper.SetValidatorByConsAddr(ctx, newVal)
if err != nil {
tmos.Exit(err.Error())
}
app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)
app.StakingKeeper.SetLastValidatorPower(ctx, newVal.GetOperator(), 0)
if err := app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, newVal.GetOperator()); err != nil {
panic(err)
}
// DISTRIBUTION
//
// Initialize records for this validator across all distribution stores
app.DistrKeeper.SetValidatorHistoricalRewards(ctx, newVal.GetOperator(), 0, distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
app.DistrKeeper.SetValidatorCurrentRewards(ctx, newVal.GetOperator(), distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1))
app.DistrKeeper.SetValidatorAccumulatedCommission(ctx, newVal.GetOperator(), distrtypes.InitialValidatorAccumulatedCommission())
app.DistrKeeper.SetValidatorOutstandingRewards(ctx, newVal.GetOperator(), distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}})
// SLASHING
//
// Set validator signing info for our new validator.
newConsAddr := sdk.ConsAddress(newValAddr.Bytes())
newValidatorSigningInfo := slashingtypes.ValidatorSigningInfo{
Address: newConsAddr.String(),
StartHeight: app.LastBlockHeight() - 1,
Tombstoned: false,
}
app.SlashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newValidatorSigningInfo)
//
// Optional Changes:
//
// GOV
//
newExpeditedVotingPeriod := time.Minute
newVotingPeriod := time.Minute * 2
govParams := app.GovKeeper.GetParams(ctx)
govParams.ExpeditedVotingPeriod = &newExpeditedVotingPeriod
govParams.VotingPeriod = &newVotingPeriod
- govParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin("uosmo", 100000000))
- govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewInt64Coin("uosmo", 150000000))
+ govParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(appparams.BaseCoinUnit, 100000000))
+ govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewInt64Coin(appparams.BaseCoinUnit, 150000000))
err = app.GovKeeper.SetParams(ctx, govParams)
if err != nil {
tmos.Exit(err.Error())
}
// EPOCHS
//
dayEpochInfo := app.EpochsKeeper.GetEpochInfo(ctx, "day")
dayEpochInfo.Duration = time.Hour * 6
// Prevents epochs from running back to back
dayEpochInfo.CurrentEpochStartTime = time.Now().UTC()
// If you want epoch to run a minute after starting the chain, uncomment the line below and comment the line above
// dayEpochInfo.CurrentEpochStartTime = time.Now().UTC().Add(-dayEpochInfo.Duration).Add(time.Minute)
dayEpochInfo.CurrentEpochStartHeight = app.LastBlockHeight()
app.EpochsKeeper.DeleteEpochInfo(ctx, "day")
err = app.EpochsKeeper.AddEpochInfo(ctx, dayEpochInfo)
if err != nil {
tmos.Exit(err.Error())
commit e9b6ebead04fe346d9a5ae9acef79b8b65ccb22c
Author: Dev Ojha <[email protected]>
Date: Tue Apr 2 05:21:41 2024 +0200
Speedup go test Reset logic (#7902)
* Slight speedup to go tests
* Introduce caching for the reflection service
* Speedup some more generic setup logic for all tests
diff --git a/app/app.go b/app/app.go
--- a/app/app.go
+++ b/app/app.go
@@ -476,145 +479,154 @@
+ }
+ reflectionSvc, err := runtimeservices.NewReflectionService()
+ if err != nil {
+ panic(err)
+ }
+ cachedReflectionService = reflectionSvc
+ return reflectionSvc
+}
+
// InitOsmosisAppForTestnet is broken down into two sections:
// Required Changes: Changes that, if not made, will cause the testnet to halt or panic
// Optional Changes: Changes to customize the testnet to one's liking (lower vote times, fund accounts, etc)
func InitOsmosisAppForTestnet(app *OsmosisApp, newValAddr bytes.HexBytes, newValPubKey crypto.PubKey, newOperatorAddress, upgradeToTrigger string) *OsmosisApp {
//
// Required Changes:
//
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
pubkey := &ed25519.PubKey{Key: newValPubKey.Bytes()}
pubkeyAny, err := types.NewAnyWithValue(pubkey)
if err != nil {
tmos.Exit(err.Error())
}
// STAKING
//
// Create Validator struct for our new validator.
_, bz, err := bech32.DecodeAndConvert(newOperatorAddress)
if err != nil {
tmos.Exit(err.Error())
}
bech32Addr, err := bech32.ConvertAndEncode("osmovaloper", bz)
if err != nil {
tmos.Exit(err.Error())
}
newVal := stakingtypes.Validator{
OperatorAddress: bech32Addr,
ConsensusPubkey: pubkeyAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: sdk.NewInt(900000000000000),
DelegatorShares: sdk.MustNewDecFromStr("10000000"),
Description: stakingtypes.Description{
Moniker: "Testnet Validator",
},
Commission: stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates{
Rate: sdk.MustNewDecFromStr("0.05"),
MaxRate: sdk.MustNewDecFromStr("0.1"),
MaxChangeRate: sdk.MustNewDecFromStr("0.05"),
},
},
MinSelfDelegation: sdk.OneInt(),
}
// Remove all validators from power store
stakingKey := app.GetKey(stakingtypes.ModuleName)
stakingStore := ctx.KVStore(stakingKey)
iterator := app.StakingKeeper.ValidatorsPowerStoreIterator(ctx)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Remove all valdiators from last validators store
iterator = app.StakingKeeper.LastValidatorsIterator(ctx)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Remove all validators from validators store
iterator = sdk.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorsKey)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Remove all validators from unbonding queue
iterator = sdk.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorQueueKey)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Add our validator to power and last validators store
app.StakingKeeper.SetValidator(ctx, newVal)
err = app.StakingKeeper.SetValidatorByConsAddr(ctx, newVal)
if err != nil {
tmos.Exit(err.Error())
}
app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)
app.StakingKeeper.SetLastValidatorPower(ctx, newVal.GetOperator(), 0)
if err := app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, newVal.GetOperator()); err != nil {
panic(err)
}
// DISTRIBUTION
//
// Initialize records for this validator across all distribution stores
app.DistrKeeper.SetValidatorHistoricalRewards(ctx, newVal.GetOperator(), 0, distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
app.DistrKeeper.SetValidatorCurrentRewards(ctx, newVal.GetOperator(), distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1))
app.DistrKeeper.SetValidatorAccumulatedCommission(ctx, newVal.GetOperator(), distrtypes.InitialValidatorAccumulatedCommission())
app.DistrKeeper.SetValidatorOutstandingRewards(ctx, newVal.GetOperator(), distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}})
// SLASHING
//
// Set validator signing info for our new validator.
newConsAddr := sdk.ConsAddress(newValAddr.Bytes())
newValidatorSigningInfo := slashingtypes.ValidatorSigningInfo{
Address: newConsAddr.String(),
StartHeight: app.LastBlockHeight() - 1,
Tombstoned: false,
}
app.SlashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newValidatorSigningInfo)
//
// Optional Changes:
//
// GOV
//
newExpeditedVotingPeriod := time.Minute
newVotingPeriod := time.Minute * 2
govParams := app.GovKeeper.GetParams(ctx)
govParams.ExpeditedVotingPeriod = &newExpeditedVotingPeriod
govParams.VotingPeriod = &newVotingPeriod
govParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin("uosmo", 100000000))
govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewInt64Coin("uosmo", 150000000))
err = app.GovKeeper.SetParams(ctx, govParams)
if err != nil {
tmos.Exit(err.Error())
}
// EPOCHS
//
dayEpochInfo := app.EpochsKeeper.GetEpochInfo(ctx, "day")
dayEpochInfo.Duration = time.Hour * 6
// Prevents epochs from running back to back
dayEpochInfo.CurrentEpochStartTime = time.Now().UTC()
// If you want epoch to run a minute after starting the chain, uncomment the line below and comment the line above
// dayEpochInfo.CurrentEpochStartTime = time.Now().UTC().Add(-dayEpochInfo.Duration).Add(time.Minute)
dayEpochInfo.CurrentEpochStartHeight = app.LastBlockHeight()
app.EpochsKeeper.DeleteEpochInfo(ctx, "day")
err = app.EpochsKeeper.AddEpochInfo(ctx, dayEpochInfo)
if err != nil {
tmos.Exit(err.Error())
commit 236d7f733f5914431863a1df9a023bdf38de84ba
Author: Adam Tucker <[email protected]>
Date: Mon Feb 12 10:30:16 2024 -0600
remove all vals from testnet state (#7454)
diff --git a/app/app.go b/app/app.go
--- a/app/app.go
+++ b/app/app.go
@@ -413,129 +413,145 @@
// InitOsmosisAppForTestnet is broken down into two sections:
// Required Changes: Changes that, if not made, will cause the testnet to halt or panic
// Optional Changes: Changes to customize the testnet to one's liking (lower vote times, fund accounts, etc)
func InitOsmosisAppForTestnet(app *OsmosisApp, newValAddr bytes.HexBytes, newValPubKey crypto.PubKey, newOperatorAddress, upgradeToTrigger string) *OsmosisApp {
//
// Required Changes:
//
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
pubkey := &ed25519.PubKey{Key: newValPubKey.Bytes()}
pubkeyAny, err := types.NewAnyWithValue(pubkey)
if err != nil {
tmos.Exit(err.Error())
}
// STAKING
//
// Create Validator struct for our new validator.
_, bz, err := bech32.DecodeAndConvert(newOperatorAddress)
if err != nil {
tmos.Exit(err.Error())
}
bech32Addr, err := bech32.ConvertAndEncode("osmovaloper", bz)
if err != nil {
tmos.Exit(err.Error())
}
newVal := stakingtypes.Validator{
OperatorAddress: bech32Addr,
ConsensusPubkey: pubkeyAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: sdk.NewInt(900000000000000),
DelegatorShares: sdk.MustNewDecFromStr("10000000"),
Description: stakingtypes.Description{
Moniker: "Testnet Validator",
},
Commission: stakingtypes.Commission{
CommissionRates: stakingtypes.CommissionRates{
Rate: sdk.MustNewDecFromStr("0.05"),
MaxRate: sdk.MustNewDecFromStr("0.1"),
MaxChangeRate: sdk.MustNewDecFromStr("0.05"),
},
},
MinSelfDelegation: sdk.OneInt(),
}
// Remove all validators from power store
stakingKey := app.GetKey(stakingtypes.ModuleName)
stakingStore := ctx.KVStore(stakingKey)
iterator := app.StakingKeeper.ValidatorsPowerStoreIterator(ctx)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
// Remove all valdiators from last validators store
iterator = app.StakingKeeper.LastValidatorsIterator(ctx)
for ; iterator.Valid(); iterator.Next() {
stakingStore.Delete(iterator.Key())
}
iterator.Close()
+ // Remove all validators from validators store
+ iterator = sdk.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorsKey)
+ for ; iterator.Valid(); iterator.Next() {
+ stakingStore.Delete(iterator.Key())
+ }
+ iterator.Close()
+
+ // Remove all validators from unbonding queue
+ iterator = sdk.KVStorePrefixIterator(stakingStore, stakingtypes.ValidatorQueueKey)
+ for ; iterator.Valid(); iterator.Next() {
+ stakingStore.Delete(iterator.Key())
+ }
+ iterator.Close()
+
// Add our validator to power and last validators store
app.StakingKeeper.SetValidator(ctx, newVal)
err = app.StakingKeeper.SetValidatorByConsAddr(ctx, newVal)
if err != nil {
tmos.Exit(err.Error())
}
app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)
app.StakingKeeper.SetLastValidatorPower(ctx, newVal.GetOperator(), 0)
if err := app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, newVal.GetOperator()); err != nil {
panic(err)
}
// DISTRIBUTION
//
// Initialize records for this validator across all distribution stores
app.DistrKeeper.SetValidatorHistoricalRewards(ctx, newVal.GetOperator(), 0, distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
app.DistrKeeper.SetValidatorCurrentRewards(ctx, newVal.GetOperator(), distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1))
app.DistrKeeper.SetValidatorAccumulatedCommission(ctx, newVal.GetOperator(), distrtypes.InitialValidatorAccumulatedCommission())
app.DistrKeeper.SetValidatorOutstandingRewards(ctx, newVal.GetOperator(), distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}})
// SLASHING
//
// Set validator signing info for our new validator.
newConsAddr := sdk.ConsAddress(newValAddr.Bytes())
newValidatorSigningInfo := slashingtypes.ValidatorSigningInfo{
Address: newConsAddr.String(),
StartHeight: app.LastBlockHeight() - 1,
Tombstoned: false,
}
app.SlashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newValidatorSigningInfo)
//
// Optional Changes:
//
// GOV
//
newExpeditedVotingPeriod := time.Minute
newVotingPeriod := time.Minute * 2
govParams := app.GovKeeper.GetParams(ctx)
govParams.ExpeditedVotingPeriod = &newExpeditedVotingPeriod
govParams.VotingPeriod = &newVotingPeriod
govParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin("uosmo", 100000000))
govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewInt64Coin("uosmo", 150000000))
err = app.GovKeeper.SetParams(ctx, govParams)
if err != nil {
tmos.Exit(err.Error())
}
// EPOCHS
//
dayEpochInfo := app.EpochsKeeper.GetEpochInfo(ctx, "day")
dayEpochInfo.Duration = time.Hour * 6
// Prevents epochs from running back to back
dayEpochInfo.CurrentEpochStartTime = time.Now().UTC()
+ // If you want epoch to run a minute after starting the chain, uncomment the line below and comment the line above
+ // dayEpochInfo.CurrentEpochStartTime = time.Now().UTC().Add(-dayEpochInfo.Duration).Add(time.Minute)
dayEpochInfo.CurrentEpochStartHeight = app.LastBlockHeight()
app.EpochsKeeper.DeleteEpochInfo(ctx, "day")
err = app.EpochsKeeper.AddEpochInfo(ctx, dayEpochInfo)
if err != nil {
tmos.Exit(err.Error())
commit 0b326547e1205cde1fd0ece9d51722a1b960166b
Author: Adam Tucker <[email protected]>
Date: Tue Feb 6 14:07:02 2024 -0600
feat: in-place testnet creator (#7374)
* plug in testnetify
* fix import
* utilize appOpts
* add upgrade trigger
* update sdk fork tag
* add changelog
diff --git a/app/app.go b/app/app.go
--- a/app/app.go
+++ b/app/app.go
@@ -407,0 +413,129 @@
+// InitOsmosisAppForTestnet is broken down into two sections:
+// Required Changes: Changes that, if not made, will cause the testnet to halt or panic
+// Optional Changes: Changes to customize the testnet to one's liking (lower vote times, fund accounts, etc)
+func InitOsmosisAppForTestnet(app *OsmosisApp, newValAddr bytes.HexBytes, newValPubKey crypto.PubKey, newOperatorAddress, upgradeToTrigger string) *OsmosisApp {
+ //
+ // Required Changes:
+ //
+
+ ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
+ pubkey := &ed25519.PubKey{Key: newValPubKey.Bytes()}
+ pubkeyAny, err := types.NewAnyWithValue(pubkey)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+
+ // STAKING
+ //
+
+ // Create Validator struct for our new validator.
+ _, bz, err := bech32.DecodeAndConvert(newOperatorAddress)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+ bech32Addr, err := bech32.ConvertAndEncode("osmovaloper", bz)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+ newVal := stakingtypes.Validator{
+ OperatorAddress: bech32Addr,
+ ConsensusPubkey: pubkeyAny,
+ Jailed: false,
+ Status: stakingtypes.Bonded,
+ Tokens: sdk.NewInt(900000000000000),
+ DelegatorShares: sdk.MustNewDecFromStr("10000000"),
+ Description: stakingtypes.Description{
+ Moniker: "Testnet Validator",
+ },
+ Commission: stakingtypes.Commission{
+ CommissionRates: stakingtypes.CommissionRates{
+ Rate: sdk.MustNewDecFromStr("0.05"),
+ MaxRate: sdk.MustNewDecFromStr("0.1"),
+ MaxChangeRate: sdk.MustNewDecFromStr("0.05"),
+ },
+ },
+ MinSelfDelegation: sdk.OneInt(),
+ }
+
+ // Remove all validators from power store
+ stakingKey := app.GetKey(stakingtypes.ModuleName)
+ stakingStore := ctx.KVStore(stakingKey)
+ iterator := app.StakingKeeper.ValidatorsPowerStoreIterator(ctx)
+ for ; iterator.Valid(); iterator.Next() {
+ stakingStore.Delete(iterator.Key())
+ }
+ iterator.Close()
+
+ // Remove all valdiators from last validators store
+ iterator = app.StakingKeeper.LastValidatorsIterator(ctx)
+ for ; iterator.Valid(); iterator.Next() {
+ stakingStore.Delete(iterator.Key())
+ }
+ iterator.Close()
+
+ // Add our validator to power and last validators store
+ app.StakingKeeper.SetValidator(ctx, newVal)
+ err = app.StakingKeeper.SetValidatorByConsAddr(ctx, newVal)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+ app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)
+ app.StakingKeeper.SetLastValidatorPower(ctx, newVal.GetOperator(), 0)
+ if err := app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, newVal.GetOperator()); err != nil {
+ panic(err)
+ }
+
+ // DISTRIBUTION
+ //
+
+ // Initialize records for this validator across all distribution stores
+ app.DistrKeeper.SetValidatorHistoricalRewards(ctx, newVal.GetOperator(), 0, distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
+ app.DistrKeeper.SetValidatorCurrentRewards(ctx, newVal.GetOperator(), distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1))
+ app.DistrKeeper.SetValidatorAccumulatedCommission(ctx, newVal.GetOperator(), distrtypes.InitialValidatorAccumulatedCommission())
+ app.DistrKeeper.SetValidatorOutstandingRewards(ctx, newVal.GetOperator(), distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}})
+
+ // SLASHING
+ //
+
+ // Set validator signing info for our new validator.
+ newConsAddr := sdk.ConsAddress(newValAddr.Bytes())
+ newValidatorSigningInfo := slashingtypes.ValidatorSigningInfo{
+ Address: newConsAddr.String(),
+ StartHeight: app.LastBlockHeight() - 1,
+ Tombstoned: false,
+ }
+ app.SlashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newValidatorSigningInfo)
+
+ //
+ // Optional Changes:
+ //
+
+ // GOV
+ //
+
+ newExpeditedVotingPeriod := time.Minute
+ newVotingPeriod := time.Minute * 2
+
+ govParams := app.GovKeeper.GetParams(ctx)
+ govParams.ExpeditedVotingPeriod = &newExpeditedVotingPeriod
+ govParams.VotingPeriod = &newVotingPeriod
+ govParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin("uosmo", 100000000))
+ govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewInt64Coin("uosmo", 150000000))
+
+ err = app.GovKeeper.SetParams(ctx, govParams)
+ if err != nil {
+ tmos.Exit(err.Error())
+ }
+
+ // EPOCHS
+ //
+
+ dayEpochInfo := app.EpochsKeeper.GetEpochInfo(ctx, "day")
+ dayEpochInfo.Duration = time.Hour * 6
+ // Prevents epochs from running back to back
+ dayEpochInfo.CurrentEpochStartTime = time.Now().UTC()
+ dayEpochInfo.CurrentEpochStartHeight = app.LastBlockHeight()
+ app.EpochsKeeper.DeleteEpochInfo(ctx, "day")
+ err = app.EpochsKeeper.AddEpochInfo(ctx, dayEpochInfo)
+ if err != nil {
+ tmos.Exit(err.Error())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment