Skip to content

Commit 6e000e2

Browse files
authored
Merge pull request #452 from persistenceOne/puneet/add-halving
feat: add halving from persistence-sdk to core
2 parents e9e83e6 + a2e2ad5 commit 6e000e2

96 files changed

Lines changed: 17661 additions & 167 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ endif
102102
# Docker variables
103103
DOCKER := $(shell which docker)
104104

105-
include sims.mk
106-
107105
###############################################################################
108106
### Build ###
109107
###############################################################################
@@ -313,10 +311,29 @@ rm-testcache:
313311
### Protobuf ###
314312
###############################################################################
315313

316-
protoVer=0.14.0
314+
protoVer=0.16.0
317315
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
318316
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)
319317

318+
proto-all: proto-format proto-lint proto-gen
319+
320+
proto-gen:
321+
@echo "Generating Protobuf files"
322+
@$(protoImage) sh ./proto/scripts/protocgen.sh
323+
324+
proto-format:
325+
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;
326+
327+
proto-lint:
328+
@$(protoImage) buf lint --error-format=json
329+
330+
proto-check-breaking:
331+
@$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main
332+
333+
proto-update-deps:
334+
@echo "Updating Protobuf dependencies"
335+
$(DOCKER) run --rm -v $(CURDIR)/proto:/workspace --workdir /workspace $(protoImageName) buf mod update
336+
320337
proto-swagger-gen:
321338
@echo "Generating Protobuf Swagger"
322339
@$(protoImage) sh ./proto/scripts/proto-swagger-gen.sh
@@ -329,4 +346,4 @@ proto-clean:
329346
rm -rf tmp-swagger-gen/
330347
rm -rf tmp_deps/
331348

332-
.PHONY: proto-swagger-gen proto-clean
349+
.PHONY: proto-swagger-gen proto-clean proto-all proto-gen proto-format proto-lint proto-check-breaking proto-update-deps

app/constants/constants.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,23 @@ var (
4343
}
4444
)
4545

46+
func init() {
47+
SetUnsealedConfig()
48+
}
49+
4650
// SetConfig address/coin params at the global state
4751
func SetConfig() {
4852
cfg := sdk.GetConfig()
53+
SetUnsealedConfig()
54+
cfg.Seal()
55+
}
56+
57+
func SetUnsealedConfig() {
58+
cfg := sdk.GetConfig()
4959

5060
cfg.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
5161
cfg.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
5262
cfg.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
5363
cfg.SetCoinType(CoinType)
5464
cfg.SetPurpose(Purpose)
55-
56-
cfg.Seal()
5765
}

app/encoding.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
"github.com/cosmos/cosmos-sdk/std"
1212
"github.com/cosmos/cosmos-sdk/types/module"
1313
grouptypes "github.com/cosmos/cosmos-sdk/x/group"
14-
interchainquerytypes "github.com/persistenceOne/persistence-sdk/v6/x/interchainquery/types"
15-
"github.com/persistenceOne/persistence-sdk/v6/x/lsm/distribution"
16-
"github.com/persistenceOne/persistence-sdk/v6/x/lsm/staking"
17-
oracletypes "github.com/persistenceOne/persistence-sdk/v6/x/oracle/types"
18-
pobtypes "github.com/persistenceOne/persistence-sdk/v6/x/pob/types"
19-
liquidstakeibctypes "github.com/persistenceOne/pstake-native/v6/x/liquidstakeibc/types"
20-
lscosmostypes "github.com/persistenceOne/pstake-native/v6/x/lscosmos/types"
21-
ratesynctypes "github.com/persistenceOne/pstake-native/v6/x/ratesync/types"
14+
interchainquerytypes "github.com/persistenceOne/persistence-sdk/v7/x/interchainquery/types"
15+
liquidstakeibctypes "github.com/persistenceOne/persistence-sdk/v7/x/liquidstakeibc/types"
16+
lscosmostypes "github.com/persistenceOne/persistence-sdk/v7/x/lscosmos/types"
17+
"github.com/persistenceOne/persistence-sdk/v7/x/lsm/distribution"
18+
"github.com/persistenceOne/persistence-sdk/v7/x/lsm/staking"
19+
oracletypes "github.com/persistenceOne/persistence-sdk/v7/x/oracle/types"
20+
pobtypes "github.com/persistenceOne/persistence-sdk/v7/x/pob/types"
21+
ratesynctypes "github.com/persistenceOne/persistence-sdk/v7/x/ratesync/types"
2222

2323
"github.com/persistenceOne/persistenceCore/v16/app/params"
2424
)

app/keepers/keepers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ import (
7474
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
7575
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"
7676
ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"
77-
"github.com/persistenceOne/persistence-sdk/v6/x/halving"
78-
halvingtypes "github.com/persistenceOne/persistence-sdk/v6/x/halving/types"
79-
liquidstakekeeper "github.com/persistenceOne/pstake-native/v6/x/liquidstake/keeper"
80-
liquidstaketypes "github.com/persistenceOne/pstake-native/v6/x/liquidstake/types"
77+
"github.com/persistenceOne/persistenceCore/v16/x/halving"
78+
halvingtypes "github.com/persistenceOne/persistenceCore/v16/x/halving/types"
79+
liquidstakekeeper "github.com/persistenceOne/persistenceCore/v16/x/liquidstake/keeper"
80+
liquidstaketypes "github.com/persistenceOne/persistenceCore/v16/x/liquidstake/types"
8181
"github.com/spf13/cast"
8282

8383
"github.com/persistenceOne/persistenceCore/v16/app/constants"
@@ -366,7 +366,7 @@ func NewAppKeeper(
366366

367367
liquidStakeKeeper := liquidstakekeeper.NewKeeper(
368368
appCodec,
369-
appKeepers.keys[liquidstaketypes.StoreKey],
369+
runtime.NewKVStoreService(appKeepers.keys[liquidstaketypes.StoreKey]),
370370
appKeepers.AccountKeeper,
371371
appKeepers.BankKeeper,
372372
appKeepers.StakingKeeper,

app/keepers/keys.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
icahosttypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/host/types"
2727
ibctransfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
2828
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
29-
"github.com/persistenceOne/persistence-sdk/v6/x/halving"
30-
liquidstaketypes "github.com/persistenceOne/pstake-native/v6/x/liquidstake/types"
29+
"github.com/persistenceOne/persistenceCore/v16/x/halving"
30+
liquidstaketypes "github.com/persistenceOne/persistenceCore/v16/x/liquidstake/types"
3131
)
3232

3333
func (appKeepers *AppKeepers) GenerateKeys() {

app/modules.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ import (
5555
ibc "github.com/cosmos/ibc-go/v10/modules/core"
5656
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
5757
ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"
58-
"github.com/persistenceOne/persistence-sdk/v6/x/halving"
59-
"github.com/persistenceOne/pstake-native/v6/x/liquidstake"
60-
liquidstaketypes "github.com/persistenceOne/pstake-native/v6/x/liquidstake/types"
58+
"github.com/persistenceOne/persistenceCore/v16/x/halving"
59+
"github.com/persistenceOne/persistenceCore/v16/x/liquidstake"
60+
liquidstaketypes "github.com/persistenceOne/persistenceCore/v16/x/liquidstake/types"
6161
)
6262

6363
var ModuleAccountPermissions = map[string][]string{
@@ -138,6 +138,9 @@ func orderBeginBlockers() []string {
138138
return []string{
139139
upgradetypes.ModuleName,
140140
epochstypes.ModuleName,
141+
minttypes.ModuleName,
142+
distributiontypes.ModuleName,
143+
protocolpooltypes.ModuleName,
141144
crisistypes.ModuleName,
142145
govtypes.ModuleName,
143146
stakingtypes.ModuleName,
@@ -146,10 +149,7 @@ func orderBeginBlockers() []string {
146149
icatypes.ModuleName,
147150
authtypes.ModuleName,
148151
banktypes.ModuleName,
149-
distributiontypes.ModuleName,
150-
protocolpooltypes.ModuleName,
151152
slashingtypes.ModuleName,
152-
minttypes.ModuleName,
153153
genutiltypes.ModuleName,
154154
evidencetypes.ModuleName,
155155
authz.ModuleName,

app/test_helpers.go

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
package app
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"os"
7+
"testing"
68

79
"cosmossdk.io/log"
10+
sdkmath "cosmossdk.io/math"
811
pruningtypes "cosmossdk.io/store/pruning/types"
912
"github.com/CosmWasm/wasmd/x/wasm"
13+
abci "github.com/cometbft/cometbft/abci/types"
14+
cmttypes "github.com/cometbft/cometbft/types"
1015
dbm "github.com/cosmos/cosmos-db"
1116
bam "github.com/cosmos/cosmos-sdk/baseapp"
1217
"github.com/cosmos/cosmos-sdk/client/flags"
18+
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
1319
servertypes "github.com/cosmos/cosmos-sdk/server/types"
20+
"github.com/cosmos/cosmos-sdk/testutil/mock"
1421
"github.com/cosmos/cosmos-sdk/testutil/network"
1522
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
23+
sdk "github.com/cosmos/cosmos-sdk/types"
1624
"github.com/cosmos/cosmos-sdk/types/module/testutil"
25+
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
26+
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
27+
"github.com/persistenceOne/persistenceCore/v16/app/constants"
28+
"github.com/stretchr/testify/require"
1729
)
1830

1931
// NewTestNetworkFixture returns a new persistenceCore AppConstructor for network simulation tests.
@@ -47,3 +59,116 @@ func NewTestNetworkFixture() network.TestFixture {
4759
},
4860
}
4961
}
62+
63+
func setup(withGenesis bool, t *testing.T) (*Application, GenesisState) {
64+
db := dbm.NewMemDB()
65+
66+
appOptions := make(simtestutil.AppOptionsMap, 0)
67+
appOptions[flags.FlagHome] = t.TempDir()
68+
69+
app := NewApplication(log.NewNopLogger(), db, nil, true, appOptions, []wasm.Option{})
70+
if withGenesis {
71+
return app, app.DefaultGenesis()
72+
}
73+
return app, GenesisState{}
74+
}
75+
76+
//// NewTestAppWithCustomOptions initializes a new TestApp with custom options.
77+
//func NewTestAppWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptions) *Application {
78+
// t.Helper()
79+
//
80+
// privVal := mock.NewPV()
81+
// pubKey, err := privVal.GetPubKey()
82+
// require.NoError(t, err)
83+
// // create validator set with single validator
84+
// validator := cmttypes.NewValidator(pubKey, 1)
85+
// valSet := cmttypes.NewValidatorSet([]*cmttypes.Validator{validator})
86+
//
87+
// // generate genesis account
88+
// senderPrivKey := secp256k1.GenPrivKey()
89+
// acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
90+
// balance := banktypes.Balance{
91+
// Address: acc.GetAddress().String(),
92+
// Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))),
93+
// }
94+
//
95+
// app := NewApplication(options.Logger, options.DB, nil, true, options.AppOpts)
96+
// genesisState := app.DefaultGenesis()
97+
// genesisState, err = simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance)
98+
// require.NoError(t, err)
99+
//
100+
// if !isCheckTx {
101+
// // init chain must be called to stop deliverState from being nil
102+
// stateBytes, err := cmtjson.MarshalIndent(genesisState, "", " ")
103+
// require.NoError(t, err)
104+
//
105+
// // Initialize the chain
106+
// _, err = app.InitChain(&abci.RequestInitChain{
107+
// Validators: []abci.ValidatorUpdate{},
108+
// ConsensusParams: simtestutil.DefaultConsensusParams,
109+
// AppStateBytes: stateBytes,
110+
// })
111+
// require.NoError(t, err)
112+
// }
113+
//
114+
// return app
115+
//}
116+
117+
// Setup initializes a new TestApp. A Nop logger is set in TestApp.
118+
func Setup(t *testing.T) *Application {
119+
t.Helper()
120+
121+
privVal := mock.NewPV()
122+
pubKey, err := privVal.GetPubKey()
123+
require.NoError(t, err)
124+
125+
// create validator set with single validator
126+
validator := cmttypes.NewValidator(pubKey, 1)
127+
valSet := cmttypes.NewValidatorSet([]*cmttypes.Validator{validator})
128+
129+
// generate genesis account
130+
senderPrivKey := secp256k1.GenPrivKey()
131+
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
132+
balance := banktypes.Balance{
133+
Address: acc.GetAddress().String(),
134+
Coins: sdk.NewCoins(sdk.NewCoin(constants.BondDenom, sdkmath.NewInt(100000000000000))),
135+
}
136+
137+
app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance)
138+
139+
return app
140+
}
141+
142+
// SetupWithGenesisValSet initializes a new TestApp with a validator set and genesis accounts
143+
// that also act as delegators. For simplicity, each validator is bonded with a delegation
144+
// of one consensus engine unit in the default token of the TestApp from first genesis
145+
// account. A Nop logger is set in TestApp.
146+
func SetupWithGenesisValSet(t *testing.T, valSet *cmttypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *Application {
147+
t.Helper()
148+
149+
app, genesisState := setup(true, t)
150+
genesisState, err := simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, genAccs, balances...)
151+
require.NoError(t, err)
152+
153+
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
154+
require.NoError(t, err)
155+
156+
// init chain will set the validator set and initialize the genesis accounts
157+
_, err = app.InitChain(&abci.RequestInitChain{
158+
Validators: []abci.ValidatorUpdate{},
159+
ConsensusParams: simtestutil.DefaultConsensusParams,
160+
AppStateBytes: stateBytes,
161+
},
162+
)
163+
require.NoError(t, err)
164+
165+
require.NoError(t, err)
166+
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
167+
Height: app.LastBlockHeight() + 1,
168+
Hash: app.LastCommitID().Hash,
169+
NextValidatorsHash: valSet.Hash(),
170+
})
171+
require.NoError(t, err)
172+
173+
return app
174+
}

go.mod

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ toolchain go1.24.6
77
require (
88
cosmossdk.io/api v0.9.2
99
cosmossdk.io/client/v2 v2.0.0-beta.11
10+
cosmossdk.io/collections v1.2.1
1011
cosmossdk.io/core v0.11.3
1112
cosmossdk.io/errors v1.0.2
1213
cosmossdk.io/log v1.6.1
@@ -20,22 +21,28 @@ require (
2021
github.com/CosmWasm/wasmd v0.60.2
2122
github.com/cometbft/cometbft v0.38.19
2223
github.com/cosmos/cosmos-db v1.1.3
24+
github.com/cosmos/cosmos-proto v1.0.0-beta.5
2325
github.com/cosmos/cosmos-sdk v0.53.4
2426
github.com/cosmos/gaia/v25 v25.2.0
2527
github.com/cosmos/gogoproto v1.7.2
2628
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v10 v10.1.0
2729
github.com/cosmos/ibc-apps/modules/ibc-hooks/v10 v10.0.0-20250919123430-5596e0a03585
2830
github.com/cosmos/ibc-go/v10 v10.4.0
2931
github.com/cosmos/rosetta v0.50.12
30-
github.com/persistenceOne/persistence-sdk/v6 v6.1.0
31-
github.com/persistenceOne/pstake-native/v6 v6.0.0
32+
github.com/golang/protobuf v1.5.4
33+
github.com/gorilla/mux v1.8.1
34+
github.com/grpc-ecosystem/grpc-gateway v1.16.0
35+
github.com/persistenceOne/persistence-sdk/v7 v7.0.0-20251124115845-8e906bffc41a
3236
github.com/prometheus/client_golang v1.23.0
3337
github.com/spf13/cast v1.9.2
3438
github.com/spf13/cobra v1.10.1
3539
github.com/spf13/pflag v1.0.9
3640
github.com/spf13/viper v1.20.1
3741
github.com/stretchr/testify v1.11.1
42+
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7
43+
google.golang.org/grpc v1.75.0
3844
google.golang.org/protobuf v1.36.10
45+
gopkg.in/yaml.v2 v2.4.0
3946
)
4047

4148
require (
@@ -47,7 +54,6 @@ require (
4754
cloud.google.com/go/iam v1.5.2 // indirect
4855
cloud.google.com/go/monitoring v1.24.2 // indirect
4956
cloud.google.com/go/storage v1.50.0 // indirect
50-
cosmossdk.io/collections v1.2.1 // indirect
5157
cosmossdk.io/depinject v1.2.1 // indirect
5258
cosmossdk.io/schema v1.1.0 // indirect
5359
filippo.io/edwards25519 v1.1.0 // indirect
@@ -85,7 +91,6 @@ require (
8591
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
8692
github.com/cometbft/cometbft-db v1.0.4 // indirect
8793
github.com/cosmos/btcutil v1.0.5 // indirect
88-
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
8994
github.com/cosmos/go-bip39 v1.0.0 // indirect
9095
github.com/cosmos/gogogateway v1.2.0 // indirect
9196
github.com/cosmos/iavl v1.2.6 // indirect
@@ -122,7 +127,6 @@ require (
122127
github.com/gogo/googleapis v1.4.1 // indirect
123128
github.com/gogo/protobuf v1.3.2 // indirect
124129
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
125-
github.com/golang/protobuf v1.5.4 // indirect
126130
github.com/golang/snappy v1.0.0 // indirect
127131
github.com/google/btree v1.1.3 // indirect
128132
github.com/google/flatbuffers v25.1.24+incompatible // indirect
@@ -134,11 +138,9 @@ require (
134138
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
135139
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
136140
github.com/gorilla/handlers v1.5.2 // indirect
137-
github.com/gorilla/mux v1.8.1 // indirect
138141
github.com/gorilla/websocket v1.5.3 // indirect
139142
github.com/goware/urlx v0.3.2 // indirect
140143
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
141-
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
142144
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
143145
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
144146
github.com/hashicorp/go-getter v1.7.9 // indirect
@@ -233,10 +235,7 @@ require (
233235
golang.org/x/time v0.12.0 // indirect
234236
google.golang.org/api v0.247.0 // indirect
235237
google.golang.org/genproto v0.0.0-20250603155806-513f23925822 // indirect
236-
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
237238
google.golang.org/genproto/googleapis/rpc v0.0.0-20250818200422-3122310a409c // indirect
238-
google.golang.org/grpc v1.75.0 // indirect
239-
gopkg.in/yaml.v2 v2.4.0 // indirect
240239
gopkg.in/yaml.v3 v3.0.1 // indirect
241240
gotest.tools/v3 v3.5.2 // indirect
242241
nhooyr.io/websocket v1.8.17 // indirect

0 commit comments

Comments
 (0)