Skip to content

Commit a4f0da8

Browse files
committed
Merge branch master-feed into master-tss
2 parents 71f0b90 + 0e76e27 commit a4f0da8

File tree

141 files changed

+14504
-4287
lines changed

Some content is hidden

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

141 files changed

+14504
-4287
lines changed

app/app.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ import (
134134
oracleclient "github.com/bandprotocol/chain/v2/x/oracle/client"
135135
oraclekeeper "github.com/bandprotocol/chain/v2/x/oracle/keeper"
136136
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
137+
"github.com/bandprotocol/chain/v2/x/restake"
138+
restakekeeper "github.com/bandprotocol/chain/v2/x/restake/keeper"
139+
restaketypes "github.com/bandprotocol/chain/v2/x/restake/types"
137140
"github.com/bandprotocol/chain/v2/x/rollingseed"
138141
rollingseedkeeper "github.com/bandprotocol/chain/v2/x/rollingseed/keeper"
139142
rollingseedtypes "github.com/bandprotocol/chain/v2/x/rollingseed/types"
@@ -195,6 +198,7 @@ var (
195198
),
196199
feeds.AppModuleBasic{},
197200
globalfee.AppModule{},
201+
restake.AppModuleBasic{},
198202
)
199203
// module account permissions
200204
maccPerms = map[string][]string{
@@ -207,6 +211,7 @@ var (
207211
govtypes.ModuleName: {authtypes.Burner},
208212
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
209213
bandtsstypes.ModuleName: nil,
214+
restaketypes.ModuleName: nil,
210215
}
211216

212217
Upgrades = []upgrades.Upgrade{v2_6.Upgrade}
@@ -312,6 +317,7 @@ func NewBandApp(
312317
bandtsstypes.StoreKey,
313318
feedstypes.StoreKey,
314319
globalfeetypes.StoreKey,
320+
restaketypes.StoreKey,
315321
)
316322
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
317323
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
@@ -440,6 +446,14 @@ func NewBandApp(
440446
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
441447
)
442448

449+
app.RestakeKeeper = restakekeeper.NewKeeper(
450+
appCodec,
451+
keys[restaketypes.StoreKey],
452+
app.AccountKeeper,
453+
app.BankKeeper,
454+
app.StakingKeeper,
455+
)
456+
443457
// create IBC Keeper
444458
app.IBCKeeper = ibckeeper.NewKeeper(
445459
appCodec,
@@ -588,6 +602,8 @@ func NewBandApp(
588602
keys[feedstypes.StoreKey],
589603
app.OracleKeeper,
590604
app.StakingKeeper,
605+
app.RestakeKeeper,
606+
app.AuthzKeeper,
591607
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
592608
)
593609

@@ -607,7 +623,7 @@ func NewBandApp(
607623
stakingtypes.NewMultiStakingHooks(
608624
app.DistrKeeper.Hooks(),
609625
app.SlashingKeeper.Hooks(),
610-
app.FeedsKeeper.Hooks(),
626+
app.RestakeKeeper.Hooks(),
611627
),
612628
)
613629

@@ -705,6 +721,7 @@ func NewBandApp(
705721
bandtssModule,
706722
feeds.NewAppModule(appCodec, app.FeedsKeeper),
707723
globalfee.NewAppModule(app.GlobalfeeKeeper),
724+
restake.NewAppModule(appCodec, &app.RestakeKeeper),
708725
)
709726

710727
// NOTE: Oracle module must occur before distr as it takes some fee to distribute to active oracle validators.
@@ -720,6 +737,7 @@ func NewBandApp(
720737
tsstypes.ModuleName,
721738
bandtsstypes.ModuleName,
722739
feedstypes.ModuleName,
740+
restaketypes.ModuleName,
723741
distrtypes.ModuleName,
724742
slashingtypes.ModuleName,
725743
evidencetypes.ModuleName,
@@ -750,6 +768,7 @@ func NewBandApp(
750768
tsstypes.ModuleName,
751769
bandtsstypes.ModuleName,
752770
feedstypes.ModuleName,
771+
restaketypes.ModuleName,
753772
ibctransfertypes.ModuleName,
754773
ibcexported.ModuleName,
755774
icatypes.ModuleName,
@@ -805,6 +824,7 @@ func NewBandApp(
805824
bandtsstypes.ModuleName,
806825
feedstypes.ModuleName,
807826
globalfeetypes.ModuleName,
827+
restaketypes.ModuleName,
808828
)
809829

810830
app.mm.RegisterInvariants(app.CrisisKeeper)

app/genesis.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import (
4545
globalfeetypes "github.com/bandprotocol/chain/v2/x/globalfee/types"
4646
"github.com/bandprotocol/chain/v2/x/oracle"
4747
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
48+
"github.com/bandprotocol/chain/v2/x/restake"
49+
restaketypes "github.com/bandprotocol/chain/v2/x/restake/types"
4850
"github.com/bandprotocol/chain/v2/x/rollingseed"
4951
rollingseedtypes "github.com/bandprotocol/chain/v2/x/rollingseed/types"
5052
"github.com/bandprotocol/chain/v2/x/tss"
@@ -119,5 +121,6 @@ func NewDefaultGenesisState() GenesisState {
119121
bandtsstypes.ModuleName: bandtss.AppModuleBasic{}.DefaultGenesis(cdc),
120122
feedstypes.ModuleName: feeds.AppModuleBasic{}.DefaultGenesis(cdc),
121123
globalfeetypes.ModuleName: cdc.MustMarshalJSON(globalfeeGenesis),
124+
restaketypes.ModuleName: restake.AppModuleBasic{}.DefaultGenesis(cdc),
122125
}
123126
}

app/keepers/keepers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
feedskeeper "github.com/bandprotocol/chain/v2/x/feeds/keeper"
2626
globalfeekeeper "github.com/bandprotocol/chain/v2/x/globalfee/keeper"
2727
oraclekeeper "github.com/bandprotocol/chain/v2/x/oracle/keeper"
28+
restakekeeper "github.com/bandprotocol/chain/v2/x/restake/keeper"
2829
rollingseedKeeper "github.com/bandprotocol/chain/v2/x/rollingseed/keeper"
2930
tsskeeper "github.com/bandprotocol/chain/v2/x/tss/keeper"
3031
)
@@ -57,6 +58,7 @@ type AppKeepers struct {
5758
FeedsKeeper feedskeeper.Keeper
5859
ConsensusParamsKeeper consensusparamkeeper.Keeper
5960
GlobalfeeKeeper globalfeekeeper.Keeper
61+
RestakeKeeper restakekeeper.Keeper
6062

6163
// make scoped keepers public for test purposes
6264
ScopedIBCKeeper capabilitykeeper.ScopedKeeper

benchmark/feeds_bench_test.go

Lines changed: 97 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package benchmark
33
import (
44
"fmt"
55
"math/rand"
6+
"sort"
67
"testing"
78

89
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -15,8 +16,41 @@ import (
1516
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
1617
)
1718

18-
// benchmark test for delivering MsgSubmitPrices
19-
func BenchmarkSubmitPricesDeliver(b *testing.B) {
19+
var (
20+
ValidValidator = sdk.ValAddress("1000000001")
21+
ValidValidator2 = sdk.ValAddress("1000000002")
22+
)
23+
24+
func BenchmarkSortMap(b *testing.B) {
25+
b.ResetTimer()
26+
b.StopTimer()
27+
ba := InitializeBenchmarkApp(b, -1)
28+
expValPrices := generateValidatorPrices(300, ValidValidator.String(), ba.Ctx.BlockTime().Unix())
29+
valPricesMap := make(map[string]types.ValidatorPrice)
30+
for _, valPrice := range expValPrices {
31+
valPricesMap[valPrice.SignalID] = valPrice
32+
}
33+
for i := 0; i < b.N; i++ {
34+
for j := 0; j < 2000; j++ {
35+
b.StartTimer()
36+
keys := make([]string, len(valPricesMap))
37+
k := int(0)
38+
for key := range valPricesMap {
39+
keys[k] = key
40+
k++
41+
}
42+
sort.Strings(keys)
43+
valPrices := make([]types.ValidatorPrice, len(valPricesMap))
44+
for idx, key := range keys {
45+
valPrices[idx] = valPricesMap[key]
46+
}
47+
b.StopTimer()
48+
}
49+
}
50+
}
51+
52+
// benchmark test for delivering MsgSubmitSignalPrices
53+
func BenchmarkSubmitSignalPricesDeliver(b *testing.B) {
2054
b.ResetTimer()
2155
b.StopTimer()
2256

@@ -31,15 +65,18 @@ func BenchmarkSubmitPricesDeliver(b *testing.B) {
3165
err = setupFeeds(ba)
3266
require.NoError(b, err)
3367

68+
err = setupValidatorPriceList(ba, vals)
69+
require.NoError(b, err)
70+
3471
ba.CallBeginBlock()
3572

3673
txs := []sdk.Tx{}
3774
for _, val := range vals {
3875
tx := GenSequenceOfTxs(
3976
ba.TxConfig,
40-
GenMsgSubmitPrices(
77+
GenMsgSubmitSignalPrices(
4178
val,
42-
ba.FeedsKeeper.GetSupportedFeeds(ba.Ctx).Feeds,
79+
ba.FeedsKeeper.GetCurrentFeeds(ba.Ctx).Feeds,
4380
ba.Ctx.BlockTime().Unix(),
4481
),
4582
val,
@@ -98,42 +135,70 @@ func BenchmarkFeedsEndBlock(b *testing.B) {
98135
}
99136

100137
func setupFeeds(ba *BenchmarkApp) error {
101-
numFeeds := ba.FeedsKeeper.GetParams(ba.Ctx).MaxSupportedFeeds
138+
numFeeds := ba.FeedsKeeper.GetParams(ba.Ctx).MaxCurrentFeeds
102139

103140
ba.CallBeginBlock()
104141

105142
feeds := []types.Feed{}
106-
for i := int64(0); i < numFeeds; i++ {
143+
for i := uint64(0); i < numFeeds; i++ {
107144
feeds = append(feeds, types.Feed{
108-
SignalID: fmt.Sprintf("signal.%d", i),
109-
Interval: 60,
110-
DeviationInThousandth: 5,
145+
SignalID: fmt.Sprintf("signal.%d", i),
146+
Interval: 60,
111147
})
112148
}
113-
ba.FeedsKeeper.SetSupportedFeeds(ba.Ctx, feeds)
149+
ba.FeedsKeeper.SetCurrentFeeds(ba.Ctx, feeds)
150+
151+
ba.CallEndBlock()
152+
ba.Commit()
153+
154+
return nil
155+
}
156+
157+
func setupValidatorPriceList(ba *BenchmarkApp, vals []*Account) error {
158+
sfs := ba.FeedsKeeper.GetCurrentFeeds(ba.Ctx)
114159

160+
ba.CallBeginBlock()
161+
for valIdx, val := range vals {
162+
valPrices := []types.ValidatorPrice{}
163+
for _, feed := range sfs.Feeds {
164+
valPrices = append(valPrices, types.ValidatorPrice{
165+
PriceStatus: types.PriceStatusAvailable,
166+
Validator: val.ValAddress.String(),
167+
SignalID: feed.SignalID,
168+
Price: (10000 + uint64(valIdx)) * 10e9,
169+
Timestamp: ba.Ctx.BlockTime().Unix() - 40,
170+
})
171+
}
172+
err := ba.FeedsKeeper.SetValidatorPriceList(ba.Ctx, val.ValAddress, valPrices)
173+
if err != nil {
174+
return err
175+
}
176+
}
115177
ba.CallEndBlock()
116178
ba.Commit()
117179

118180
return nil
119181
}
120182

121183
func setupValidatorPrices(ba *BenchmarkApp, vals []*Account) error {
122-
sfs := ba.FeedsKeeper.GetSupportedFeeds(ba.Ctx)
184+
sfs := ba.FeedsKeeper.GetCurrentFeeds(ba.Ctx)
123185

124186
ba.CallBeginBlock()
125-
for _, feed := range sfs.Feeds {
126-
for valIdx, val := range vals {
127-
err := ba.FeedsKeeper.SetValidatorPrice(ba.Ctx, types.ValidatorPrice{
187+
for valIdx, val := range vals {
188+
valPrices := []types.ValidatorPrice{}
189+
for _, feed := range sfs.Feeds {
190+
valPrices = append(valPrices, types.ValidatorPrice{
128191
PriceStatus: types.PriceStatusAvailable,
129192
Validator: val.ValAddress.String(),
130193
SignalID: feed.SignalID,
131194
Price: (10000 + uint64(valIdx)) * 10e9,
132195
Timestamp: ba.Ctx.BlockTime().Unix(),
133196
})
134-
if err != nil {
135-
return err
136-
}
197+
}
198+
199+
err := ba.FeedsKeeper.SetValidatorPriceList(ba.Ctx, val.ValAddress, valPrices)
200+
if err != nil {
201+
return err
137202
}
138203
}
139204
ba.CallEndBlock()
@@ -213,3 +278,18 @@ func generateValidators(ba *BenchmarkApp, num int) ([]*Account, error) {
213278

214279
return accs, nil
215280
}
281+
282+
// generateValidatorPrices generates a slice of ValidatorPrice with the specified number of elements.
283+
func generateValidatorPrices(numElements int, validatorAddress string, timestamp int64) []types.ValidatorPrice {
284+
prices := make([]types.ValidatorPrice, numElements)
285+
286+
for i := 0; i < numElements; i++ {
287+
prices[i] = types.ValidatorPrice{
288+
Validator: validatorAddress,
289+
SignalID: fmt.Sprintf("CS:BAND%d-USD", i),
290+
Price: 1e10,
291+
Timestamp: timestamp,
292+
}
293+
}
294+
return prices
295+
}

benchmark/helper_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ func GenMsgRequestData(
7575
return []sdk.Msg{&msg}
7676
}
7777

78-
func GenMsgSubmitPrices(
78+
func GenMsgSubmitSignalPrices(
7979
sender *Account,
8080
feeds []feedstypes.Feed,
8181
timestamp int64,
8282
) []sdk.Msg {
83-
prices := []feedstypes.SubmitPrice{}
83+
prices := make([]feedstypes.SignalPrice, 0, len(feeds))
8484
for _, feed := range feeds {
85-
prices = append(prices, feedstypes.SubmitPrice{
85+
prices = append(prices, feedstypes.SignalPrice{
8686
PriceStatus: feedstypes.PriceStatusAvailable,
8787
SignalID: feed.SignalID,
8888
Price: 60000,
8989
})
9090
}
9191

92-
msg := feedstypes.NewMsgSubmitPrices(sender.ValAddress.String(), timestamp, prices)
92+
msg := feedstypes.NewMsgSubmitSignalPrices(sender.ValAddress.String(), timestamp, prices)
9393

9494
return []sdk.Msg{msg}
9595
}

grogu/cmd/config.go renamed to cmd/grogu/cmd/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import (
66
)
77

88
func ConfigCmd() *cobra.Command {
9-
cmd := &cobra.Command{
9+
return &cobra.Command{
1010
Use: "config [key] [value]",
1111
Aliases: []string{"c"},
12-
Short: "Set grogu configuration environment",
12+
Short: "Set Grogu's configuration environment",
1313
Args: cobra.ExactArgs(2),
1414
RunE: func(cmd *cobra.Command, args []string) error {
1515
viper.Set(args[0], args[1])
1616
return viper.WriteConfig()
1717
},
1818
}
19-
return cmd
2019
}

0 commit comments

Comments
 (0)