Skip to content

Commit e88bcb5

Browse files
committed
Consensus params migration
1 parent 9b91bdc commit e88bcb5

2 files changed

Lines changed: 77 additions & 241 deletions

File tree

app/traces/transfer.pb.go

Lines changed: 2 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -80,73 +80,12 @@ func (m *DenomTrace) GetBaseDenom() string {
8080
return ""
8181
}
8282

83-
// Params defines the set of IBC transfer parameters.
84-
// NOTE: To prevent a single token from being transferred, set the
85-
// TransfersEnabled parameter to true and then set the bank module's SendEnabled
86-
// parameter for the denomination to false.
87-
type Params struct {
88-
// send_enabled enables or disables all cross-chain token transfers from this
89-
// chain.
90-
SendEnabled bool `protobuf:"varint,1,opt,name=send_enabled,json=sendEnabled,proto3" json:"send_enabled,omitempty"`
91-
// receive_enabled enables or disables all cross-chain token transfers to this
92-
// chain.
93-
ReceiveEnabled bool `protobuf:"varint,2,opt,name=receive_enabled,json=receiveEnabled,proto3" json:"receive_enabled,omitempty"`
94-
}
95-
96-
func (m *Params) Reset() { *m = Params{} }
97-
func (m *Params) String() string { return proto.CompactTextString(m) }
98-
func (*Params) ProtoMessage() {}
99-
func (*Params) Descriptor() ([]byte, []int) {
100-
return fileDescriptor_5041673e96e97901, []int{1}
101-
}
102-
func (m *Params) XXX_Unmarshal(b []byte) error {
103-
return m.Unmarshal(b)
104-
}
105-
func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
106-
if deterministic {
107-
return xxx_messageInfo_Params.Marshal(b, m, deterministic)
108-
} else {
109-
b = b[:cap(b)]
110-
n, err := m.MarshalToSizedBuffer(b)
111-
if err != nil {
112-
return nil, err
113-
}
114-
return b[:n], nil
115-
}
116-
}
117-
func (m *Params) XXX_Merge(src proto.Message) {
118-
xxx_messageInfo_Params.Merge(m, src)
119-
}
120-
func (m *Params) XXX_Size() int {
121-
return m.Size()
122-
}
123-
func (m *Params) XXX_DiscardUnknown() {
124-
xxx_messageInfo_Params.DiscardUnknown(m)
125-
}
126-
127-
var xxx_messageInfo_Params proto.InternalMessageInfo
128-
129-
func (m *Params) GetSendEnabled() bool {
130-
if m != nil {
131-
return m.SendEnabled
132-
}
133-
return false
134-
}
135-
136-
func (m *Params) GetReceiveEnabled() bool {
137-
if m != nil {
138-
return m.ReceiveEnabled
139-
}
140-
return false
141-
}
142-
14383
func init() {
144-
proto.RegisterType((*DenomTrace)(nil), "ibc.applications.transfer.v1.DenomTrace")
145-
proto.RegisterType((*Params)(nil), "ibc.applications.transfer.v1.Params")
84+
//proto.RegisterType((*DenomTrace)(nil), "ibc.applications.transfer.v1.DenomTrace")
14685
}
14786

14887
func init() {
149-
proto.RegisterFile("ibc/applications/transfer/v1/transfer.proto", fileDescriptor_5041673e96e97901)
88+
//proto.RegisterFile("ibc/applications/transfer/v1/transfer.proto", fileDescriptor_5041673e96e97901)
15089
}
15190

15291
var fileDescriptor_5041673e96e97901 = []byte{
@@ -206,49 +145,6 @@ func (m *DenomTrace) MarshalToSizedBuffer(dAtA []byte) (int, error) {
206145
return len(dAtA) - i, nil
207146
}
208147

209-
func (m *Params) Marshal() (dAtA []byte, err error) {
210-
size := m.Size()
211-
dAtA = make([]byte, size)
212-
n, err := m.MarshalToSizedBuffer(dAtA[:size])
213-
if err != nil {
214-
return nil, err
215-
}
216-
return dAtA[:n], nil
217-
}
218-
219-
func (m *Params) MarshalTo(dAtA []byte) (int, error) {
220-
size := m.Size()
221-
return m.MarshalToSizedBuffer(dAtA[:size])
222-
}
223-
224-
func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) {
225-
i := len(dAtA)
226-
_ = i
227-
var l int
228-
_ = l
229-
if m.ReceiveEnabled {
230-
i--
231-
if m.ReceiveEnabled {
232-
dAtA[i] = 1
233-
} else {
234-
dAtA[i] = 0
235-
}
236-
i--
237-
dAtA[i] = 0x10
238-
}
239-
if m.SendEnabled {
240-
i--
241-
if m.SendEnabled {
242-
dAtA[i] = 1
243-
} else {
244-
dAtA[i] = 0
245-
}
246-
i--
247-
dAtA[i] = 0x8
248-
}
249-
return len(dAtA) - i, nil
250-
}
251-
252148
func encodeVarintTransfer(dAtA []byte, offset int, v uint64) int {
253149
offset -= sovTransfer(v)
254150
base := offset
@@ -277,21 +173,6 @@ func (m *DenomTrace) Size() (n int) {
277173
return n
278174
}
279175

280-
func (m *Params) Size() (n int) {
281-
if m == nil {
282-
return 0
283-
}
284-
var l int
285-
_ = l
286-
if m.SendEnabled {
287-
n += 2
288-
}
289-
if m.ReceiveEnabled {
290-
n += 2
291-
}
292-
return n
293-
}
294-
295176
func sovTransfer(x uint64) (n int) {
296177
return (math_bits.Len64(x|1) + 6) / 7
297178
}
@@ -412,96 +293,7 @@ func (m *DenomTrace) Unmarshal(dAtA []byte) error {
412293
}
413294
return nil
414295
}
415-
func (m *Params) Unmarshal(dAtA []byte) error {
416-
l := len(dAtA)
417-
iNdEx := 0
418-
for iNdEx < l {
419-
preIndex := iNdEx
420-
var wire uint64
421-
for shift := uint(0); ; shift += 7 {
422-
if shift >= 64 {
423-
return ErrIntOverflowTransfer
424-
}
425-
if iNdEx >= l {
426-
return io.ErrUnexpectedEOF
427-
}
428-
b := dAtA[iNdEx]
429-
iNdEx++
430-
wire |= uint64(b&0x7F) << shift
431-
if b < 0x80 {
432-
break
433-
}
434-
}
435-
fieldNum := int32(wire >> 3)
436-
wireType := int(wire & 0x7)
437-
if wireType == 4 {
438-
return fmt.Errorf("proto: Params: wiretype end group for non-group")
439-
}
440-
if fieldNum <= 0 {
441-
return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire)
442-
}
443-
switch fieldNum {
444-
case 1:
445-
if wireType != 0 {
446-
return fmt.Errorf("proto: wrong wireType = %d for field SendEnabled", wireType)
447-
}
448-
var v int
449-
for shift := uint(0); ; shift += 7 {
450-
if shift >= 64 {
451-
return ErrIntOverflowTransfer
452-
}
453-
if iNdEx >= l {
454-
return io.ErrUnexpectedEOF
455-
}
456-
b := dAtA[iNdEx]
457-
iNdEx++
458-
v |= int(b&0x7F) << shift
459-
if b < 0x80 {
460-
break
461-
}
462-
}
463-
m.SendEnabled = bool(v != 0)
464-
case 2:
465-
if wireType != 0 {
466-
return fmt.Errorf("proto: wrong wireType = %d for field ReceiveEnabled", wireType)
467-
}
468-
var v int
469-
for shift := uint(0); ; shift += 7 {
470-
if shift >= 64 {
471-
return ErrIntOverflowTransfer
472-
}
473-
if iNdEx >= l {
474-
return io.ErrUnexpectedEOF
475-
}
476-
b := dAtA[iNdEx]
477-
iNdEx++
478-
v |= int(b&0x7F) << shift
479-
if b < 0x80 {
480-
break
481-
}
482-
}
483-
m.ReceiveEnabled = bool(v != 0)
484-
default:
485-
iNdEx = preIndex
486-
skippy, err := skipTransfer(dAtA[iNdEx:])
487-
if err != nil {
488-
return err
489-
}
490-
if (skippy < 0) || (iNdEx+skippy) < 0 {
491-
return ErrInvalidLengthTransfer
492-
}
493-
if (iNdEx + skippy) > l {
494-
return io.ErrUnexpectedEOF
495-
}
496-
iNdEx += skippy
497-
}
498-
}
499296

500-
if iNdEx > l {
501-
return io.ErrUnexpectedEOF
502-
}
503-
return nil
504-
}
505297
func skipTransfer(dAtA []byte) (n int, err error) {
506298
l := len(dAtA)
507299
iNdEx := 0

app/upgrades.go

Lines changed: 75 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package app
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
7+
"strconv"
8+
"strings"
69
"time"
710

811
storetypes "cosmossdk.io/store/types"
@@ -19,6 +22,7 @@ import (
1922
epochstypes "github.com/cosmos/cosmos-sdk/x/epochs/types"
2023
"github.com/cosmos/cosmos-sdk/x/group"
2124
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
25+
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
2226
protocolpooltypes "github.com/cosmos/cosmos-sdk/x/protocolpool/types"
2327
icacontrollertypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/types"
2428
icatypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/types"
@@ -106,40 +110,11 @@ func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
106110
}
107111
}
108112

109-
cparams := app.BaseApp.GetConsensusParams(sdkCtx)
110-
if err := app.BaseApp.StoreConsensusParams(sdkCtx, cparams); err != nil {
113+
err = migrateConsensusParamsFromParamsStore(app, sdkCtx)
114+
if err != nil {
111115
return nil, err
112116
}
113117

114-
// Bootstrap consensus params if empty
115-
if _, err := app.ConsensusParamsKeeper.ParamsStore.Get(sdkCtx); err != nil {
116-
// Use sane defaults (adjust if your chain needs different limits)
117-
cp := tmproto.ConsensusParams{
118-
Block: &tmproto.BlockParams{
119-
MaxBytes: 22020096, // ~21MB like most Cosmos chains
120-
MaxGas: -1, // unlimited; set your real value if needed
121-
},
122-
Evidence: &tmproto.EvidenceParams{
123-
MaxAgeNumBlocks: 302400, // ~3 weeks at 6s blocks
124-
MaxAgeDuration: 504 * time.Hour, // 3 weeks
125-
MaxBytes: 1048576, // 1MB evidence
126-
},
127-
Validator: &tmproto.ValidatorParams{
128-
PubKeyTypes: []string{"ed25519"},
129-
},
130-
Version: &tmproto.VersionParams{
131-
App: 0,
132-
},
133-
// Abci left nil (CometBFT will use defaults)
134-
}
135-
if err := app.ConsensusParamsKeeper.ParamsStore.Set(sdkCtx, cp); err != nil {
136-
panic(err)
137-
}
138-
if err := app.BaseApp.StoreConsensusParams(sdkCtx, cp); err != nil {
139-
return nil, err
140-
}
141-
}
142-
143118
// If you must pin any module "from" versions, adjust fromVM here.
144119
return app.mm.RunMigrations(ctx, cfg, fromVM)
145120
},
@@ -167,3 +142,72 @@ func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
167142
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &v053StoreUpgrades))
168143
}
169144
}
145+
146+
func migrateConsensusParamsFromParamsStore(app *App, ctx sdk.Context) error {
147+
paramsStore := ctx.KVStore(app.GetKey(paramstypes.StoreKey))
148+
149+
// BlockParams
150+
var blockParams tmproto.BlockParams
151+
if bz := paramsStore.Get([]byte("baseapp/BlockParams")); len(bz) > 0 {
152+
// these are plain numbers; codec JSON is fine
153+
if err := app.AppCodec().UnmarshalJSON(bz, &blockParams); err != nil {
154+
return err
155+
}
156+
}
157+
158+
// --- EvidenceParams (strings; duration in ns) ---
159+
var epRaw struct {
160+
MaxAgeNumBlocks string `json:"max_age_num_blocks"`
161+
MaxAgeDuration string `json:"max_age_duration"` // ns as string
162+
MaxBytes string `json:"max_bytes"`
163+
}
164+
if err := json.Unmarshal(paramsStore.Get([]byte("baseapp/EvidenceParams")), &epRaw); err != nil {
165+
return err
166+
}
167+
blocks, err := parseI64(epRaw.MaxAgeNumBlocks)
168+
if err != nil {
169+
return err
170+
}
171+
durNs, err := parseI64(epRaw.MaxAgeDuration)
172+
if err != nil {
173+
return err
174+
}
175+
evMaxBytes, err := parseI64(epRaw.MaxBytes)
176+
if err != nil {
177+
return err
178+
}
179+
evidenceParams := tmproto.EvidenceParams{
180+
MaxAgeNumBlocks: blocks,
181+
MaxAgeDuration: time.Duration(durNs), // ns → time.Duration
182+
MaxBytes: evMaxBytes,
183+
}
184+
185+
// ValidatorParams
186+
var validatorParams tmproto.ValidatorParams
187+
if bz := paramsStore.Get([]byte("baseapp/ValidatorParams")); len(bz) > 0 {
188+
if err := app.AppCodec().UnmarshalJSON(bz, &validatorParams); err != nil {
189+
return err
190+
}
191+
}
192+
193+
cp := tmproto.ConsensusParams{
194+
Block: &blockParams,
195+
Evidence: &evidenceParams,
196+
Validator: &validatorParams,
197+
Version: &tmproto.VersionParams{App: 0},
198+
}
199+
200+
// Write to x/consensus so it’s persisted in app state
201+
if err := app.ConsensusParamsKeeper.ParamsStore.Set(ctx, cp); err != nil {
202+
return err
203+
}
204+
// Also write to BaseApp so CometBFT uses it immediately
205+
if err := app.BaseApp.StoreConsensusParams(ctx, cp); err != nil {
206+
return err
207+
}
208+
return nil
209+
}
210+
211+
func parseI64(s string) (int64, error) {
212+
return strconv.ParseInt(strings.TrimSpace(s), 10, 64)
213+
}

0 commit comments

Comments
 (0)