7
7
"os"
8
8
"path/filepath"
9
9
"reflect"
10
+ "time"
10
11
11
12
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
12
13
@@ -41,12 +42,15 @@ import (
41
42
42
43
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
43
44
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
45
+ "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
44
46
45
47
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
46
48
47
49
"github.com/CosmWasm/wasmd/x/wasm"
48
50
dbm "github.com/cometbft/cometbft-db"
49
51
abci "github.com/cometbft/cometbft/abci/types"
52
+ "github.com/cometbft/cometbft/crypto"
53
+ "github.com/cometbft/cometbft/libs/bytes"
50
54
tmjson "github.com/cometbft/cometbft/libs/json"
51
55
"github.com/cometbft/cometbft/libs/log"
52
56
tmos "github.com/cometbft/cometbft/libs/os"
@@ -66,12 +70,14 @@ import (
66
70
"github.com/cosmos/cosmos-sdk/server/config"
67
71
servertypes "github.com/cosmos/cosmos-sdk/server/types"
68
72
sdk "github.com/cosmos/cosmos-sdk/types"
73
+ "github.com/cosmos/cosmos-sdk/types/bech32"
69
74
"github.com/cosmos/cosmos-sdk/types/module"
70
75
"github.com/cosmos/cosmos-sdk/version"
71
76
"github.com/cosmos/cosmos-sdk/x/auth/ante"
72
77
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
73
78
"github.com/cosmos/cosmos-sdk/x/crisis"
74
79
80
+ minttypes "github.com/osmosis-labs/osmosis/v22/x/mint/types"
75
81
protorevtypes "github.com/osmosis-labs/osmosis/v22/x/protorev/types"
76
82
77
83
"github.com/osmosis-labs/osmosis/v22/app/keepers"
@@ -403,6 +409,231 @@ func NewOsmosisApp(
403
409
return app
404
410
}
405
411
412
+ // InitOsmosisAppForTestnet is broken down into two sections:
413
+ // Required Changes: Changes that, if not made, will cause the testnet to halt or panic
414
+ // Optional Changes: Changes to customize the testnet to one's liking (lower vote times, fund accounts, etc)
415
+ func InitOsmosisAppForTestnet (app * OsmosisApp , newValAddr bytes.HexBytes , newValPubKey crypto.PubKey , newOperatorAddress , upgradeToTrigger string ) * OsmosisApp {
416
+ //
417
+ // Required Changes:
418
+ //
419
+
420
+ ctx := app .BaseApp .NewUncachedContext (true , tmproto.Header {})
421
+ pubkey := & ed25519.PubKey {Key : newValPubKey .Bytes ()}
422
+ pubkeyAny , err := types .NewAnyWithValue (pubkey )
423
+ if err != nil {
424
+ tmos .Exit (err .Error ())
425
+ }
426
+
427
+ // STAKING
428
+ //
429
+
430
+ // Create Validator struct for our new validator.
431
+ _ , bz , err := bech32 .DecodeAndConvert (newOperatorAddress )
432
+ if err != nil {
433
+ tmos .Exit (err .Error ())
434
+ }
435
+ bech32Addr , err := bech32 .ConvertAndEncode ("osmovaloper" , bz )
436
+ if err != nil {
437
+ tmos .Exit (err .Error ())
438
+ }
439
+ newVal := stakingtypes.Validator {
440
+ OperatorAddress : bech32Addr ,
441
+ ConsensusPubkey : pubkeyAny ,
442
+ Jailed : false ,
443
+ Status : stakingtypes .Bonded ,
444
+ Tokens : sdk .NewInt (900000000000000 ),
445
+ DelegatorShares : sdk .MustNewDecFromStr ("10000000" ),
446
+ Description : stakingtypes.Description {
447
+ Moniker : "Testnet Validator" ,
448
+ },
449
+ Commission : stakingtypes.Commission {
450
+ CommissionRates : stakingtypes.CommissionRates {
451
+ Rate : sdk .MustNewDecFromStr ("0.05" ),
452
+ MaxRate : sdk .MustNewDecFromStr ("0.1" ),
453
+ MaxChangeRate : sdk .MustNewDecFromStr ("0.05" ),
454
+ },
455
+ },
456
+ MinSelfDelegation : sdk .OneInt (),
457
+ }
458
+
459
+ // Remove all validators from power store
460
+ stakingKey := app .GetKey (stakingtypes .ModuleName )
461
+ stakingStore := ctx .KVStore (stakingKey )
462
+ iterator := app .StakingKeeper .ValidatorsPowerStoreIterator (ctx )
463
+ for ; iterator .Valid (); iterator .Next () {
464
+ stakingStore .Delete (iterator .Key ())
465
+ }
466
+ iterator .Close ()
467
+
468
+ // Remove all valdiators from last validators store
469
+ iterator = app .StakingKeeper .LastValidatorsIterator (ctx )
470
+ for ; iterator .Valid (); iterator .Next () {
471
+ stakingStore .Delete (iterator .Key ())
472
+ }
473
+ iterator .Close ()
474
+
475
+ // Add our validator to power and last validators store
476
+ app .StakingKeeper .SetValidator (ctx , newVal )
477
+ err = app .StakingKeeper .SetValidatorByConsAddr (ctx , newVal )
478
+ if err != nil {
479
+ tmos .Exit (err .Error ())
480
+ }
481
+ app .StakingKeeper .SetValidatorByPowerIndex (ctx , newVal )
482
+ app .StakingKeeper .SetLastValidatorPower (ctx , newVal .GetOperator (), 0 )
483
+ if err := app .StakingKeeper .Hooks ().AfterValidatorCreated (ctx , newVal .GetOperator ()); err != nil {
484
+ panic (err )
485
+ }
486
+
487
+ // DISTRIBUTION
488
+ //
489
+
490
+ // Initialize records for this validator across all distribution stores
491
+ app .DistrKeeper .SetValidatorHistoricalRewards (ctx , newVal .GetOperator (), 0 , distrtypes .NewValidatorHistoricalRewards (sdk.DecCoins {}, 1 ))
492
+ app .DistrKeeper .SetValidatorCurrentRewards (ctx , newVal .GetOperator (), distrtypes .NewValidatorCurrentRewards (sdk.DecCoins {}, 1 ))
493
+ app .DistrKeeper .SetValidatorAccumulatedCommission (ctx , newVal .GetOperator (), distrtypes .InitialValidatorAccumulatedCommission ())
494
+ app .DistrKeeper .SetValidatorOutstandingRewards (ctx , newVal .GetOperator (), distrtypes.ValidatorOutstandingRewards {Rewards : sdk.DecCoins {}})
495
+
496
+ // SLASHING
497
+ //
498
+
499
+ // Set validator signing info for our new validator.
500
+ newConsAddr := sdk .ConsAddress (newValAddr .Bytes ())
501
+ newValidatorSigningInfo := slashingtypes.ValidatorSigningInfo {
502
+ Address : newConsAddr .String (),
503
+ StartHeight : app .LastBlockHeight () - 1 ,
504
+ Tombstoned : false ,
505
+ }
506
+ app .SlashingKeeper .SetValidatorSigningInfo (ctx , newConsAddr , newValidatorSigningInfo )
507
+
508
+ //
509
+ // Optional Changes:
510
+ //
511
+
512
+ // GOV
513
+ //
514
+
515
+ newExpeditedVotingPeriod := time .Minute
516
+ newVotingPeriod := time .Minute * 2
517
+
518
+ govParams := app .GovKeeper .GetParams (ctx )
519
+ govParams .ExpeditedVotingPeriod = & newExpeditedVotingPeriod
520
+ govParams .VotingPeriod = & newVotingPeriod
521
+ govParams .MinDeposit = sdk .NewCoins (sdk .NewInt64Coin ("uosmo" , 100000000 ))
522
+ govParams .ExpeditedMinDeposit = sdk .NewCoins (sdk .NewInt64Coin ("uosmo" , 150000000 ))
523
+
524
+ err = app .GovKeeper .SetParams (ctx , govParams )
525
+ if err != nil {
526
+ tmos .Exit (err .Error ())
527
+ }
528
+
529
+ // EPOCHS
530
+ //
531
+
532
+ dayEpochInfo := app .EpochsKeeper .GetEpochInfo (ctx , "day" )
533
+ dayEpochInfo .Duration = time .Hour * 6
534
+ // Prevents epochs from running back to back
535
+ dayEpochInfo .CurrentEpochStartTime = time .Now ().UTC ()
536
+ dayEpochInfo .CurrentEpochStartHeight = app .LastBlockHeight ()
537
+ app .EpochsKeeper .DeleteEpochInfo (ctx , "day" )
538
+ err = app .EpochsKeeper .AddEpochInfo (ctx , dayEpochInfo )
539
+ if err != nil {
540
+ tmos .Exit (err .Error ())
541
+ }
542
+
543
+ weekEpochInfo := app .EpochsKeeper .GetEpochInfo (ctx , "week" )
544
+ weekEpochInfo .Duration = time .Hour * 12
545
+ // Prevents epochs from running back to back
546
+ weekEpochInfo .CurrentEpochStartTime = time .Now ().UTC ()
547
+ weekEpochInfo .CurrentEpochStartHeight = app .LastBlockHeight ()
548
+ app .EpochsKeeper .DeleteEpochInfo (ctx , "week" )
549
+ err = app .EpochsKeeper .AddEpochInfo (ctx , weekEpochInfo )
550
+ if err != nil {
551
+ tmos .Exit (err .Error ())
552
+ }
553
+
554
+ // BANK
555
+ //
556
+
557
+ defaultCoins := sdk .NewCoins (
558
+ sdk .NewInt64Coin ("ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7" , 1000000000000 ), // DAI
559
+ sdk .NewInt64Coin ("uosmo" , 1000000000000 ),
560
+ sdk .NewInt64Coin ("uion" , 1000000000 ))
561
+
562
+ localOsmosisAccounts := []sdk.AccAddress {
563
+ sdk .MustAccAddressFromBech32 ("osmo12smx2wdlyttvyzvzg54y2vnqwq2qjateuf7thj" ),
564
+ sdk .MustAccAddressFromBech32 ("osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks" ),
565
+ sdk .MustAccAddressFromBech32 ("osmo18s5lynnmx37hq4wlrw9gdn68sg2uxp5rgk26vv" ),
566
+ sdk .MustAccAddressFromBech32 ("osmo1qwexv7c6sm95lwhzn9027vyu2ccneaqad4w8ka" ),
567
+ sdk .MustAccAddressFromBech32 ("osmo14hcxlnwlqtq75ttaxf674vk6mafspg8xwgnn53" ),
568
+ sdk .MustAccAddressFromBech32 ("osmo12rr534cer5c0vj53eq4y32lcwguyy7nndt0u2t" ),
569
+ sdk .MustAccAddressFromBech32 ("osmo1nt33cjd5auzh36syym6azgc8tve0jlvklnq7jq" ),
570
+ sdk .MustAccAddressFromBech32 ("osmo10qfrpash5g2vk3hppvu45x0g860czur8ff5yx0" ),
571
+ sdk .MustAccAddressFromBech32 ("osmo1f4tvsdukfwh6s9swrc24gkuz23tp8pd3e9r5fa" ),
572
+ sdk .MustAccAddressFromBech32 ("osmo1myv43sqgnj5sm4zl98ftl45af9cfzk7nhjxjqh" ),
573
+ sdk .MustAccAddressFromBech32 ("osmo14gs9zqh8m49yy9kscjqu9h72exyf295afg6kgk" ),
574
+ sdk .MustAccAddressFromBech32 ("osmo1jllfytsz4dryxhz5tl7u73v29exsf80vz52ucc" )}
575
+
576
+ // Fund localosmosis accounts
577
+ for _ , account := range localOsmosisAccounts {
578
+ err := app .BankKeeper .MintCoins (ctx , minttypes .ModuleName , defaultCoins )
579
+ if err != nil {
580
+ tmos .Exit (err .Error ())
581
+ }
582
+ err = app .BankKeeper .SendCoinsFromModuleToAccount (ctx , minttypes .ModuleName , account , defaultCoins )
583
+ if err != nil {
584
+ tmos .Exit (err .Error ())
585
+ }
586
+ }
587
+
588
+ // Fund edgenet faucet
589
+ faucetCoins := sdk .NewCoins (
590
+ sdk .NewInt64Coin ("ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7" , 1000000000000000 ), // DAI
591
+ sdk .NewInt64Coin ("uosmo" , 1000000000000000 ),
592
+ sdk .NewInt64Coin ("uion" , 1000000000000 ))
593
+ err = app .BankKeeper .MintCoins (ctx , minttypes .ModuleName , faucetCoins )
594
+ if err != nil {
595
+ tmos .Exit (err .Error ())
596
+ }
597
+ err = app .BankKeeper .SendCoinsFromModuleToAccount (ctx , minttypes .ModuleName , sdk .MustAccAddressFromBech32 ("osmo1rqgf207csps822qwmd3k2n6k6k4e99w502e79t" ), faucetCoins )
598
+ if err != nil {
599
+ tmos .Exit (err .Error ())
600
+ }
601
+
602
+ // Mars bank account
603
+ marsCoins := sdk .NewCoins (
604
+ sdk .NewInt64Coin ("uosmo" , 10000000000000 ),
605
+ sdk .NewInt64Coin ("ibc/903A61A498756EA560B85A85132D3AEE21B5DEDD41213725D22ABF276EA6945E" , 400000000000 ),
606
+ sdk .NewInt64Coin ("ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858" , 3000000000000 ),
607
+ sdk .NewInt64Coin ("ibc/C140AFD542AE77BD7DCC83F13FDD8C5E5BB8C4929785E6EC2F4C636F98F17901" , 200000000000 ),
608
+ sdk .NewInt64Coin ("ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2" , 700000000000 ),
609
+ sdk .NewInt64Coin ("ibc/D1542AA8762DB13087D8364F3EA6509FD6F009A34F00426AF9E4F9FA85CBBF1F" , 2000000000 ),
610
+ sdk .NewInt64Coin ("ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5" , 3000000000000000000 ))
611
+ err = app .BankKeeper .MintCoins (ctx , minttypes .ModuleName , marsCoins )
612
+ if err != nil {
613
+ tmos .Exit (err .Error ())
614
+ }
615
+ err = app .BankKeeper .SendCoinsFromModuleToAccount (ctx , minttypes .ModuleName , sdk .MustAccAddressFromBech32 ("osmo1ev02crc36675xd8s029qh7wg3wjtfk37jr004z" ), marsCoins )
616
+ if err != nil {
617
+ tmos .Exit (err .Error ())
618
+ }
619
+
620
+ // UPGRADE
621
+ //
622
+
623
+ if upgradeToTrigger != "" {
624
+ upgradePlan := upgradetypes.Plan {
625
+ Name : upgradeToTrigger ,
626
+ Height : app .LastBlockHeight (),
627
+ }
628
+ err = app .UpgradeKeeper .ScheduleUpgrade (ctx , upgradePlan )
629
+ if err != nil {
630
+ panic (err )
631
+ }
632
+ }
633
+
634
+ return app
635
+ }
636
+
406
637
// MakeCodecs returns the application codec and a legacy Amino codec.
407
638
func MakeCodecs () (codec.Codec , * codec.LegacyAmino ) {
408
639
config := MakeEncodingConfig ()
0 commit comments