Skip to content

Commit

Permalink
Konradstaniec/testnet parameters (#364)
Browse files Browse the repository at this point in the history
- Upgrades parameters in upgrade for testnet launch

---------

Co-authored-by: Filippos Malandrakis <[email protected]>
  • Loading branch information
KonradStaniec and filippos47 authored Dec 20, 2024
1 parent 40f890d commit 2135919
Show file tree
Hide file tree
Showing 10 changed files with 6,940 additions and 18 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ and module account vars in appparams
- [#351](https://github.com/babylonlabs-io/babylon/pull/351) docs: Add state
transition docs.
- [#358](https://github.com/babylonlabs-io/babylon/pull/358) Remove unused deps in `.proto` files
- [#364](https://github.com/babylonlabs-io/babylon/pull/364) Add testnet upgrade data

### Bug fixes

- [#324](https://github.com/babylonlabs-io/babylon/pull/324) Fix decrementing
jailed fp counter
- [#352](https://github.com/babylonlabs-io/babylon/pull/352) Fix: withdrawal cli
- [#352](https://github.com/babylonlabs-io/babylon/pull/352) Fix: withdrawal cli
for rewards

### State Machine Breaking
Expand Down
2 changes: 1 addition & 1 deletion app/include_upgrade_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ func init() {
NewBtcHeadersStr: mainnet.NewBtcHeadersStr,
TokensDistributionStr: mainnet.TokensDistributionStr,
AllowedStakingTxHashesStr: mainnet.AllowedStakingTxHashesStr,
})}
}, nil)}
}
2 changes: 1 addition & 1 deletion app/include_upgrade_testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ func init() {
NewBtcHeadersStr: testnet.NewBtcHeadersStr,
TokensDistributionStr: testnet.TokensDistributionStr,
AllowedStakingTxHashesStr: testnet.AllowedStakingTxHashesStr,
})}
}, testnet.TestnetParamUpgrade)}
}
6,740 changes: 6,739 additions & 1 deletion app/upgrades/v1/testnet/btc_headers.go

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions app/upgrades/v1/testnet/btcstaking_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,32 @@ const BtcStakingParamsStr = `[
"delegation_creation_base_gas_fee": 1000,
"allow_list_expiration_height": 26120,
"btc_activation_height": 220637
},
{
"covenant_pks": [
"fa9d882d45f4060bdb8042183828cd87544f1ea997380e586cab77d5fd698737",
"0aee0509b16db71c999238a4827db945526859b13c95487ab46725357c9a9f25",
"17921cf156ccb4e73d428f996ed11b245313e37e27c978ac4d2cc21eca4672e4",
"113c3a32a9d320b72190a04a020a0db3976ef36972673258e9a38a364f3dc3b0",
"79a71ffd71c503ef2e2f91bccfc8fcda7946f4653cef0d9f3dde20795ef3b9f0",
"3bb93dfc8b61887d771f3630e9a63e97cbafcfcc78556a474df83a31a0ef899c",
"d21faf78c6751a0d38e6bd8028b907ff07e9a869a43fc837d6b3f8dff6119a36",
"40afaf47c4ffa56de86410d8e47baa2bb6f04b604f4ea24323737ddc3fe092df",
"f5199efae3f28bb82476163a7e458c7ad445d9bffb0682d10d3bdb2cb41f8e8e"
],
"covenant_quorum": 6,
"min_staking_value_sat": 50000,
"max_staking_value_sat": 35000000000,
"min_staking_time_blocks": 10000,
"max_staking_time_blocks": 64000,
"slashing_pk_script": "ABRb4SYk0IorQkCV18ByIcM0UNFL8Q==",
"min_slashing_tx_fee_sat": 5000,
"slashing_rate": "0.05",
"unbonding_time_blocks": 1008,
"unbonding_fee_sat": 2000,
"min_commission_rate": "0.03",
"delegation_creation_base_gas_fee": 1095000,
"allow_list_expiration_height": 26124,
"btc_activation_height": 227174
}
]`
14 changes: 7 additions & 7 deletions app/upgrades/v1/testnet/finality_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ package testnet
// had an update and it is possible to overwrite during the upgrade.
// The finality activation height is when the FPs need to have their
// programs ready to start sending finality signatures and it is defined
// to be 48 hours after the upgrade, the upgrade will happen close to
// block 200 and 48 hours of blocks with 10 seconds block time gives 17280
// to be 24 hours after the upgrade, the upgrade will happen close to
// block 200 and 24 hours of blocks with 10 seconds block time gives 8640
// blocks. In this case the finality activation block heigth will be set
// as 17480 = 17280 (48hrs worth of blocks) + ~200 (blocks of TGE).
// as 8844 = 8640 (24hrs worth of blocks) + ~200 (blocks of TGE).
const FinalityParamStr = `{
"max_active_finality_providers": 100,
"signed_blocks_window": 100,
"signed_blocks_window": 10000,
"finality_sig_timeout": 3,
"min_signed_per_window": "0.1",
"min_signed_per_window": "0.05",
"min_pub_rand": 500,
"jail_duration": "86400s",
"finality_activation_height": 17480
"jail_duration": "3600s",
"finality_activation_height": 8844
}`
2 changes: 1 addition & 1 deletion app/upgrades/v1/testnet/incentive.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package testnet

const IncentiveParamStr = `{
"btc_staking_portion": "0.6"
"btc_staking_portion": "0.3"
}`
111 changes: 111 additions & 0 deletions app/upgrades/v1/testnet/testnet_params_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package testnet

import (
"encoding/hex"
"fmt"
"time"

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
"github.com/babylonlabs-io/babylon/app/keepers"
appparams "github.com/babylonlabs-io/babylon/app/params"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
// Governance params
TestnetVotingPeriod = 24 * time.Hour
TestnetExpeditedVotingPeriod = 12 * time.Hour
// 10 BBN
TestnetMinDeposit = sdk.NewCoin(appparams.DefaultBondDenom, math.NewInt(10000000))
// 20 BBN
TestnetExpeditedMinDeposit = sdk.NewCoin(appparams.DefaultBondDenom, math.NewInt(20000000))
// Consensus params
TestnetBlockGasLimit = int64(250000000)
// Staking params
TestnetMinCommissionRate, _ = sdkmath.LegacyNewDecFromStr("0.03")
// Distribution params
TestnetCommunityTax, _ = sdkmath.LegacyNewDecFromStr("0.001")
// BTC checkpoint params
TestnetBTCCheckpointTag = hex.EncodeToString([]byte("bbt5"))
// Additional allow address to BTC light client
TestnetReporterAllowAddress = "bbn1cferwuxd95mdnyh4qnptahmzym0xt9sp9asqnw"
)

// TestnetParamUpgrade make updates to specific params of specific modules
func TestnetParamUpgrade(ctx sdk.Context, k *keepers.AppKeepers) error {
// update gov params
govParams, err := k.GovKeeper.Params.Get(ctx)
if err != nil {
return fmt.Errorf("failed to get gov params: %w", err)
}

govParams.VotingPeriod = &TestnetVotingPeriod
govParams.ExpeditedVotingPeriod = &TestnetExpeditedVotingPeriod
govParams.MinDeposit = []sdk.Coin{
TestnetMinDeposit,
}
govParams.ExpeditedMinDeposit = []sdk.Coin{
TestnetExpeditedMinDeposit,
}

if err := k.GovKeeper.Params.Set(ctx, govParams); err != nil {
return fmt.Errorf("failed to set gov params: %w", err)
}

// update consensus params
consensusParams, err := k.ConsensusParamsKeeper.ParamsStore.Get(ctx)
if err != nil {
return fmt.Errorf("failed to get consensus params: %w", err)
}

consensusParams.Block.MaxGas = TestnetBlockGasLimit

if err := k.ConsensusParamsKeeper.ParamsStore.Set(ctx, consensusParams); err != nil {
return fmt.Errorf("failed to set consensus params: %w", err)
}

// update staking params
stakingParams, err := k.StakingKeeper.GetParams(ctx)
if err != nil {
return fmt.Errorf("failed to get staking params: %w", err)
}

stakingParams.MinCommissionRate = TestnetMinCommissionRate

if err := k.StakingKeeper.SetParams(ctx, stakingParams); err != nil {
return fmt.Errorf("failed to set staking params: %w", err)
}

// update distribution params
distributionParams, err := k.DistrKeeper.Params.Get(ctx)
if err != nil {
return fmt.Errorf("failed to get distribution params: %w", err)
}

distributionParams.CommunityTax = TestnetCommunityTax

if err := k.DistrKeeper.Params.Set(ctx, distributionParams); err != nil {
return fmt.Errorf("failed to set distribution params: %w", err)
}

// update btc checkpoint tag
btcCheckpointParams := k.BtcCheckpointKeeper.GetParams(ctx)

btcCheckpointParams.CheckpointTag = TestnetBTCCheckpointTag

if err := k.BtcCheckpointKeeper.SetParams(ctx, btcCheckpointParams); err != nil {
return fmt.Errorf("failed to set btc checkpoint params: %w", err)
}

// btc light client allow address
btcLCParams := k.BTCLightClientKeeper.GetParams(ctx)

btcLCParams.InsertHeadersAllowList = append(btcLCParams.InsertHeadersAllowList, TestnetReporterAllowAddress)

if err := k.BTCLightClientKeeper.SetParams(ctx, btcLCParams); err != nil {
return fmt.Errorf("failed to set btc light client params: %w", err)
}

return nil
}
16 changes: 13 additions & 3 deletions app/upgrades/v1/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ import (
minttypes "github.com/babylonlabs-io/babylon/x/mint/types"
)

type ParamUpgradeFn func(ctx sdk.Context, k *keepers.AppKeepers) error

const (
ZoneConciergeStoreKey = "zoneconcierge"
UpgradeName = "v1"
)

func CreateUpgrade(upgradeDataStr UpgradeDataString) upgrades.Upgrade {
func CreateUpgrade(upgradeDataStr UpgradeDataString, parmUpgradeFn ParamUpgradeFn) upgrades.Upgrade {
return upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler(upgradeDataStr),
CreateUpgradeHandler: CreateUpgradeHandler(upgradeDataStr, parmUpgradeFn),
// Upgrade necessary for deletions of `zoneconcierge`
StoreUpgrades: store.StoreUpgrades{
Deleted: []string{ZoneConciergeStoreKey},
Expand All @@ -58,7 +60,7 @@ func CreateUpgrade(upgradeDataStr UpgradeDataString) upgrades.Upgrade {
}

// CreateUpgradeHandler upgrade handler for launch.
func CreateUpgradeHandler(upgradeDataStr UpgradeDataString) upgrades.UpgradeHandlerCreator {
func CreateUpgradeHandler(upgradeDataStr UpgradeDataString, parmUpgradeFn ParamUpgradeFn) upgrades.UpgradeHandlerCreator {
return func(mm *module.Manager, cfg module.Configurator, keepers *keepers.AppKeepers) upgradetypes.UpgradeHandler {
return func(context context.Context, _plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(context)
Expand Down Expand Up @@ -110,6 +112,14 @@ func CreateUpgradeHandler(upgradeDataStr UpgradeDataString) upgrades.UpgradeHand
return nil, fmt.Errorf("failed to upgrade inserting additional data: %w", err)
}

// if there is hardcoded upgrade for parameters, run it
if parmUpgradeFn != nil {
err = parmUpgradeFn(ctx, keepers)
if err != nil {
return nil, fmt.Errorf("failed to upgrade parameters: %w", err)
}
}

return migrations, nil
}
}
Expand Down
41 changes: 38 additions & 3 deletions app/upgrades/v1/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1_test
import (
_ "embed"
"fmt"
"slices"
"testing"
"time"

Expand Down Expand Up @@ -92,13 +93,15 @@ func (s *UpgradeTestSuite) TestUpgrade() {
testCases := []struct {
msg string
upgradeDataStr v1.UpgradeDataString
upgradeParams v1.ParamUpgradeFn
preUpgrade func()
upgrade func()
postUpgrade func()
}{
{
"Test launch software upgrade v1 mainnet",
UpgradeV1DataMainnet,
nil,
s.PreUpgrade,
s.Upgrade,
func() {
Expand Down Expand Up @@ -138,6 +141,7 @@ func (s *UpgradeTestSuite) TestUpgrade() {
{
"Test launch software upgrade v1 testnet",
UpgradeV1DataTestnet,
testnetdata.TestnetParamUpgrade,
s.PreUpgrade,
s.Upgrade,
func() {
Expand All @@ -152,13 +156,44 @@ func (s *UpgradeTestSuite) TestUpgrade() {
s.NoError(err)
s.EqualValues(resp.CodeID, 1)
s.Equal(stakingWasmChecksum[:], wasmvmtypes.Checksum(resp.Checksum))

// check that the gov params were updated
govParams, err := s.app.GovKeeper.Params.Get(s.ctx)
s.NoError(err)
s.EqualValues(testnetdata.TestnetVotingPeriod, *govParams.VotingPeriod)
s.EqualValues(testnetdata.TestnetExpeditedVotingPeriod, *govParams.ExpeditedVotingPeriod)
s.EqualValues([]sdk.Coin{testnetdata.TestnetMinDeposit}, govParams.MinDeposit)
s.EqualValues([]sdk.Coin{testnetdata.TestnetExpeditedMinDeposit}, govParams.ExpeditedMinDeposit)

// check that the consensus params were updated
consensusParams, err := s.app.ConsensusParamsKeeper.ParamsStore.Get(s.ctx)
s.NoError(err)
s.EqualValues(testnetdata.TestnetBlockGasLimit, consensusParams.Block.MaxGas)

// check that the staking params were updated
stakingParams, err := s.app.StakingKeeper.GetParams(s.ctx)
s.NoError(err)
s.EqualValues(testnetdata.TestnetMinCommissionRate, stakingParams.MinCommissionRate)

// check that the distribution params were updated
distributionParams, err := s.app.DistrKeeper.Params.Get(s.ctx)
s.NoError(err)
s.EqualValues(testnetdata.TestnetCommunityTax, distributionParams.CommunityTax)

// check that the btc checkpoint params were updated
btcCheckpointParams := s.app.BtcCheckpointKeeper.GetParams(s.ctx)
s.EqualValues(testnetdata.TestnetBTCCheckpointTag, btcCheckpointParams.CheckpointTag)

// check that the btc light client params were updated
btcLCParams := s.app.BTCLightClientKeeper.GetParams(s.ctx)
s.True(slices.Contains(btcLCParams.InsertHeadersAllowList, testnetdata.TestnetReporterAllowAddress))
},
},
}

for _, tc := range testCases {
s.Run(fmt.Sprintf("Case %s", tc.msg), func() {
s.SetupTest(tc.upgradeDataStr) // reset
s.SetupTest(tc.upgradeDataStr, tc.upgradeParams) // reset

tc.preUpgrade()
tc.upgrade()
Expand All @@ -167,11 +202,11 @@ func (s *UpgradeTestSuite) TestUpgrade() {
}
}

func (s *UpgradeTestSuite) SetupTest(upgradeDataStr v1.UpgradeDataString) {
func (s *UpgradeTestSuite) SetupTest(upgradeDataStr v1.UpgradeDataString, upgradeParams v1.ParamUpgradeFn) {
s.upgradeDataStr = upgradeDataStr

// add the upgrade plan
app.Upgrades = []upgrades.Upgrade{v1.CreateUpgrade(upgradeDataStr)}
app.Upgrades = []upgrades.Upgrade{v1.CreateUpgrade(upgradeDataStr, upgradeParams)}

// set up app
s.app = app.SetupWithBitcoinConf(s.T(), false, bbn.BtcSignet)
Expand Down

0 comments on commit 2135919

Please sign in to comment.