Skip to content

Commit f4c98e4

Browse files
hard-netthard-nettantstalepresh
authored
v023 (#285)
* add binary * patch: replace cosmos-sdk, bump cometbft * dev: prep for v022 upgrade * remove binary * dev: add custom export cli command * dev: update ed25519 library used in-place-testnet * bump: add debug mod instructions * logs: update replace docs * fix testnet issues * docs * readd v021 upgradeHandler for in-place-testnet * add historical custom upgrade patch logic * dev: remove unnecessary x/account feegrant query * dev: bumps to upggradeHandler logs & tests * dev: bump export custom * dev: return err instead of panic, require no error in tests * add default replace, bump docker alpine version * go mod tidy * wip: retain broken validator in testnet for patch assertion * wip: retain validator in staking store * tests: 1 log file printed for debugging v022 upgradeHandler, added upgradeHandler logic to in-place-testnet * dev: access appKeepers from top level app * test: add unbonded control validator to unit tests * spellcheck * cosmos-sdk@v0.53, implement x/protocol-pool * register protocol pool in our app modules basic manager * 4444 * ict: impl x/protocolpool tests * protocol-pool test * uncomment tests * init protocolpool keeper prior to distribution keeper * saftey * proto tools bump * add msg service option * remove binary * add x/smart-account easy to read specs * fix: add cosmos.msg.v1.service to protos * fix: remove external community pool support * remove v022 logs * tests: v023 unit tests * ict: go mod tidy * ict: fantoken basic tests * ict: fix test addr * tidy: go mod tidy * wip: set resolveDenom to false, remove v022 custom patch from init-from-mainnet * fix: set feepool to reflect updated balance --------- Co-authored-by: hard-nett <hardnettt@proton.me> Co-authored-by: antstalepresh <brchen327@gmail.com>
1 parent cf7a58c commit f4c98e4

File tree

29 files changed

+1536
-199
lines changed

29 files changed

+1536
-199
lines changed

app/app.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import (
7575

7676
v021 "github.com/bitsongofficial/go-bitsong/app/upgrades/v021"
7777
v022 "github.com/bitsongofficial/go-bitsong/app/upgrades/v022"
78+
v023 "github.com/bitsongofficial/go-bitsong/app/upgrades/v023"
7879
// unnamed import of statik for swagger UI support
7980
// _ "github.com/bitsongofficial/go-bitsong/swagger/statik"
8081
)
@@ -96,7 +97,7 @@ var (
9697
Upgrades = []upgrades.Upgrade{
9798
// v010.Upgrade, v011.Upgrade, v013.Upgrade, v014.Upgrade,
9899
// v015.Upgrade, v016.Upgrade, v018.Upgrade, v020.Upgrade,
99-
v021.Upgrade, v022.Upgrade,
100+
v021.Upgrade, v022.Upgrade, v023.Upgrade,
100101
}
101102
)
102103

@@ -682,11 +683,6 @@ func InitBitsongAppForTestnet(app *BitsongApp, newValAddr bytes.HexBytes, newVal
682683
}
683684
fmt.Printf("retainedValDels: %v\n", retainedValDels)
684685

685-
// run patch logic prior to resett app state. simulates upgradehandler logic
686-
err = v022.CustomV022PatchLogic(ctx, &app.AppKeepers, true)
687-
if err != nil {
688-
panic(err)
689-
}
690686
// Create Validator struct for our new validator.
691687
_, bz, err := bech32.DecodeAndConvert(newOperatorAddress)
692688
if err != nil {

app/keepers/keepers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func NewAppKeepers(
292292
appKeepers.DistrKeeper = distrkeeper.NewKeeper(
293293
appCodec,
294294
runtime.NewKVStoreService(appKeepers.keys[distrtypes.StoreKey]), appKeepers.AccountKeeper, appKeepers.BankKeeper,
295-
stakingKeeper, authtypes.FeeCollectorName, govModAddress, distrkeeper.WithExternalCommunityPool(appKeepers.ProtocolPoolKeeper),
295+
stakingKeeper, authtypes.FeeCollectorName, govModAddress, // distrkeeper.WithExternalCommunityPool(appKeepers.ProtocolPoolKeeper),
296296
)
297297

298298
appKeepers.SlashingKeeper = slashingkeeper.NewKeeper(

app/upgrades/v023/constants.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package v023
2+
3+
import (
4+
store "cosmossdk.io/store/types"
5+
"github.com/bitsongofficial/go-bitsong/app/upgrades"
6+
)
7+
8+
const (
9+
UpgradeName = "v023"
10+
)
11+
12+
var Upgrade = upgrades.Upgrade{
13+
UpgradeName: UpgradeName,
14+
CreateUpgradeHandler: CreateV023UpgradeHandler,
15+
StoreUpgrades: store.StoreUpgrades{Added: []string{}, Deleted: []string{}},
16+
}

app/upgrades/v023/upgrades.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package v023
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
upgradetypes "cosmossdk.io/x/upgrade/types"
8+
sdk "github.com/cosmos/cosmos-sdk/types"
9+
"github.com/cosmos/cosmos-sdk/x/bank/types"
10+
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
11+
protocolpooltypes "github.com/cosmos/cosmos-sdk/x/protocolpool/types"
12+
13+
"github.com/bitsongofficial/go-bitsong/app/keepers"
14+
"github.com/bitsongofficial/go-bitsong/app/upgrades"
15+
16+
"github.com/cosmos/cosmos-sdk/types/module"
17+
)
18+
19+
func CreateV023UpgradeHandler(mm *module.Manager, configurator module.Configurator, bpm upgrades.BaseAppParamManager, k *keepers.AppKeepers) upgradetypes.UpgradeHandler {
20+
return func(context context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
21+
22+
sdkCtx := sdk.UnwrapSDKContext(context)
23+
logger := sdkCtx.Logger().With("upgrade", UpgradeName)
24+
25+
// Run migrations first
26+
logger.Info(fmt.Sprintf("pre migrate version map: %v", vm))
27+
versionMap, err := mm.RunMigrations(sdkCtx, configurator, vm)
28+
if err != nil {
29+
return nil, err
30+
}
31+
32+
// apply logic patch
33+
err = CustomV023PatchLogic(sdkCtx, k)
34+
if err != nil {
35+
return nil, err
36+
}
37+
logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap))
38+
return versionMap, err
39+
}
40+
}
41+
42+
// transfer all funds from protocolpool module account to distirbution module account
43+
func CustomV023PatchLogic(ctx sdk.Context, k *keepers.AppKeepers) error {
44+
45+
// perform patch on both of the accounts the module uses, just to be safe
46+
protocolPoolAddr := protocolpooltypes.ModuleName
47+
protocolPoolEscrowAddr := protocolpooltypes.ProtocolPoolEscrowAccount
48+
49+
targetModule := distributiontypes.ModuleName
50+
51+
if err := transferModuleBalance(ctx, k, protocolPoolAddr, targetModule); err != nil {
52+
return err
53+
}
54+
55+
if err := transferModuleBalance(ctx, k, protocolPoolEscrowAddr, targetModule); err != nil {
56+
return err
57+
}
58+
59+
return nil
60+
}
61+
62+
func transferModuleBalance(ctx sdk.Context, k *keepers.AppKeepers, moduleName, targetModule string) error {
63+
moduleAddr := k.AccountKeeper.GetModuleAddress(moduleName)
64+
balances, err := k.BankKeeper.AllBalances(ctx, types.NewQueryAllBalancesRequest(moduleAddr, nil, false))
65+
if err != nil {
66+
return err
67+
}
68+
69+
// no need to call bankkeeper if module has no balance
70+
if balances.Balances.Len() == 0 {
71+
return nil
72+
}
73+
// send tokens from module to module
74+
err = k.BankKeeper.SendCoinsFromModuleToModule(ctx, moduleName, targetModule, balances.Balances)
75+
if err != nil {
76+
return err
77+
}
78+
// now we need to update the feepool value (mimics logic used in fundCommunityPool, but we must reimplement due to sending tokens from module to module)
79+
feePool, err := k.DistrKeeper.FeePool.Get(ctx)
80+
if err != nil {
81+
return err
82+
}
83+
feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(balances.Balances...)...)
84+
return k.DistrKeeper.FeePool.Set(ctx, feePool)
85+
}

app/upgrades/v023/upgrades_test.go

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package v023_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
"time"
7+
8+
"cosmossdk.io/core/appmodule"
9+
"cosmossdk.io/core/header"
10+
"cosmossdk.io/math"
11+
"cosmossdk.io/x/upgrade"
12+
upgradetypes "cosmossdk.io/x/upgrade/types"
13+
apptesting "github.com/bitsongofficial/go-bitsong/app/testing"
14+
v023 "github.com/bitsongofficial/go-bitsong/app/upgrades/v023"
15+
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
16+
"github.com/cosmos/cosmos-sdk/types"
17+
18+
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
19+
protocolpooltypes "github.com/cosmos/cosmos-sdk/x/protocolpool/types"
20+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
21+
22+
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
23+
24+
"github.com/stretchr/testify/suite"
25+
)
26+
27+
const dummyUpgradeHeight = 5
28+
29+
var testDescription = stakingtypes.NewDescription("test_moniker", "test_identity", "test_website", "test_security_contact", "test_details")
30+
31+
type UpgradeTestSuite struct {
32+
apptesting.KeeperTestHelper
33+
preModule appmodule.HasPreBlocker
34+
}
35+
36+
func (s *UpgradeTestSuite) SetupTest() {
37+
s.Setup()
38+
s.preModule = upgrade.NewAppModule(s.App.UpgradeKeeper, addresscodec.NewBech32Codec("bitsong"))
39+
}
40+
41+
func TestUpgradeTestSuite(t *testing.T) {
42+
suite.Run(t, new(UpgradeTestSuite))
43+
}
44+
45+
func (s *UpgradeTestSuite) TestUpgrade() {
46+
coin := types.NewCoin("ft12345", math.NewInt(12345))
47+
communityPoolFunds := types.NewCoins(types.NewCoin("ubtsg", math.NewInt(69420)), types.NewCoin("ftfantoken", math.NewInt(1234567890)))
48+
protocolpoolEscrow := protocolpooltypes.ProtocolPoolEscrowAccount
49+
protocolpool := protocolpooltypes.ModuleName
50+
distributionModule := distrtypes.ModuleName
51+
52+
upgradeSetup := func() {
53+
s.Ctx = s.Ctx.WithBlockHeight(dummyUpgradeHeight - 2)
54+
s.FundAcc(s.TestAccs[0], types.NewCoins(coin))
55+
56+
// fund protocolpool_escrow (cannot use protocolpool fund-community-pool since we have disbabled external community pool, so we just seed with balance to module account)
57+
s.App.BankKeeper.MintCoins(s.Ctx, minttypes.ModuleName, communityPoolFunds)
58+
s.App.BankKeeper.SendCoinsFromModuleToModule(s.Ctx, minttypes.ModuleName, protocolpoolEscrow, communityPoolFunds)
59+
60+
}
61+
62+
postUpgrade := func() {
63+
s.Ctx = s.Ctx.WithBlockHeight(dummyUpgradeHeight + 1)
64+
65+
// assert protocolpool & protocolpool_escrow are empty
66+
protocolPoolBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, s.App.AccountKeeper.GetModuleAddress(protocolpool))
67+
protocolPoolEscrowBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, s.App.AccountKeeper.GetModuleAddress(protocolpoolEscrow))
68+
distrModuleBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, s.App.AccountKeeper.GetModuleAddress(distributionModule))
69+
70+
fmt.Printf("distrModuleBalance: %v\n", distrModuleBalance)
71+
fmt.Printf("protocolPoolBalance: %v\n", protocolPoolBalance)
72+
fmt.Printf("protocolPoolEscrowBalance: %v\n", protocolPoolEscrowBalance)
73+
74+
s.Require().Equal(protocolPoolBalance.Empty(), true)
75+
s.Require().Equal(protocolPoolEscrowBalance.Empty(), true)
76+
77+
// assert fund community pool does not error
78+
err := s.App.DistrKeeper.FundCommunityPool(s.Ctx, types.NewCoins(coin), s.TestAccs[0])
79+
s.Require().NoError(err)
80+
81+
// check for funded token in distribution module balance
82+
distrModuleBalance = s.App.BankKeeper.GetAllBalances(s.Ctx, s.App.AccountKeeper.GetModuleAddress(distributionModule))
83+
amountOf := distrModuleBalance.AmountOf(coin.Denom)
84+
s.Require().Equal(amountOf, coin.Amount)
85+
86+
// assert we are unblocking fund communityu pool requests
87+
s.Require().Equal(s.App.DistrKeeper.HasExternalCommunityPool(), false)
88+
89+
}
90+
91+
testCases := []struct {
92+
name string
93+
pre_upgrade func()
94+
upgrade func()
95+
post_upgrade func()
96+
}{
97+
{
98+
"test: protocol-pool patch",
99+
func() {
100+
upgradeSetup()
101+
},
102+
func() {
103+
dummyUpgrade(s)
104+
s.Require().NotPanics(func() {
105+
_, err := s.preModule.PreBlock(s.Ctx)
106+
s.Require().NoError(err)
107+
})
108+
109+
},
110+
func() {
111+
s.Ctx = s.Ctx.WithBlockHeight(dummyUpgradeHeight + 1)
112+
postUpgrade()
113+
},
114+
},
115+
}
116+
117+
for _, tc := range testCases {
118+
s.Run(fmt.Sprintf("Case %s", tc.name), func() {
119+
s.SetupTest() // reset
120+
tc.pre_upgrade()
121+
tc.upgrade()
122+
tc.post_upgrade()
123+
})
124+
}
125+
}
126+
127+
func dummyUpgrade(s *UpgradeTestSuite) {
128+
s.Ctx = s.Ctx.WithBlockHeight(dummyUpgradeHeight - 1)
129+
plan := upgradetypes.Plan{Name: v023.UpgradeName, Height: dummyUpgradeHeight}
130+
err := s.App.UpgradeKeeper.ScheduleUpgrade(s.Ctx, plan)
131+
s.Require().NoError(err)
132+
_, err = s.App.UpgradeKeeper.GetUpgradePlan(s.Ctx)
133+
s.Require().NoError(err)
134+
135+
s.Ctx = s.Ctx.WithHeaderInfo(header.Info{Height: dummyUpgradeHeight, Time: s.Ctx.BlockTime().Add(time.Second)}).WithBlockHeight(dummyUpgradeHeight)
136+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ require (
1515
cosmossdk.io/x/feegrant v0.1.1
1616
cosmossdk.io/x/tx v0.14.0
1717
cosmossdk.io/x/upgrade v0.1.4
18-
github.com/CosmWasm/wasmd v0.53.2
19-
github.com/CosmWasm/wasmvm/v2 v2.1.5
18+
github.com/CosmWasm/wasmd v0.53.3
19+
github.com/CosmWasm/wasmvm/v2 v2.1.6
2020
github.com/cometbft/cometbft v0.38.17
2121
github.com/cosmos/cosmos-db v1.1.1
2222
github.com/cosmos/cosmos-proto v1.0.0-beta.5

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,10 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25
657657
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
658658
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
659659
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
660-
github.com/CosmWasm/wasmd v0.53.2 h1:c3MQjeQq+r+Zj2rPeW+c9kJmTevuNnZOIkiiCP/3bg4=
661-
github.com/CosmWasm/wasmd v0.53.2/go.mod h1:gP10E56tuToU5rsZR7vZLBL5ssW2mie6KN/WrQLG7/I=
662-
github.com/CosmWasm/wasmvm/v2 v2.1.5 h1:cYI1Ook1IAA5DFA0IVvDQQboorNHZPAZ7emBBHFmXSQ=
663-
github.com/CosmWasm/wasmvm/v2 v2.1.5/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg=
660+
github.com/CosmWasm/wasmd v0.53.3 h1:kZkkSM2hf0Le7iJPLLNm0QTi2j+wiuLMMn7SyOqBiYw=
661+
github.com/CosmWasm/wasmd v0.53.3/go.mod h1:gP10E56tuToU5rsZR7vZLBL5ssW2mie6KN/WrQLG7/I=
662+
github.com/CosmWasm/wasmvm/v2 v2.1.6 h1:TBJovKsc2PdLngXJx9Cozo4SnxaC/z6SJLZrxw9wv+M=
663+
github.com/CosmWasm/wasmvm/v2 v2.1.6/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg=
664664
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
665665
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
666666
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=

proto/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ once installed, in the root of your project
2424
```sh
2525
# requires buf to be installed: https://buf.build/docs/installation/
2626
cd ../proto
27-
buf mod update
27+
buf dep update
2828
cd ..
2929
buf generate
3030
```

proto/bitsong/cadence/v1/tx.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import "cosmos_proto/cosmos.proto";
1111
import "amino/amino.proto";
1212

1313
// Msg defines the Msg service.
14-
service Msg {
14+
service Msg {
15+
option (cosmos.msg.v1.service) = true;
1516

1617
// RegisterCadenceContract defines the endpoint for
1718
// registering a new cadence contract .
@@ -43,6 +44,7 @@ service Msg {
4344

4445
// MsgRegisterCadenceContract is the Msg/RegisterCadenceContract request type.
4546
message MsgRegisterCadenceContract {
47+
option (cosmos.msg.v1.signer) = "sender_address";
4648
// The address of the sender.
4749
string sender_address = 1;
4850
// The address of the contract to register.
@@ -55,6 +57,7 @@ message MsgRegisterCadenceContractResponse {}
5557

5658
// MsgUnregisterCadenceContract is the Msg/UnregisterCadenceContract request type.
5759
message MsgUnregisterCadenceContract {
60+
option (cosmos.msg.v1.signer) = "sender_address";
5861
// The address of the sender.
5962
string sender_address = 1;
6063
// The address of the contract to unregister.
@@ -67,6 +70,7 @@ message MsgUnregisterCadenceContractResponse {}
6770

6871
// MsgUnjailCadenceContract is the Msg/UnjailCadenceContract request type.
6972
message MsgUnjailCadenceContract {
73+
option (cosmos.msg.v1.signer) = "sender_address";
7074
// The address of the sender.
7175
string sender_address = 1;
7276
// The address of the contract to unjail.

0 commit comments

Comments
 (0)