From e0a63096d18ea29d508cc0397624d7c4255140a0 Mon Sep 17 00:00:00 2001 From: junkai121 Date: Mon, 29 Aug 2022 21:49:28 +0800 Subject: [PATCH] Resolve genesis import/export on distributor module --- RELEASE.md | 3 +- proto/kira/distributor/genesis.proto | 2 + scripts/commands/governance/upgrade-plan.sh | 9 +- types/constants.go | 2 +- x/distributor/module.go | 9 ++ x/distributor/types/genesis.pb.go | 102 +++++++++++++++----- 6 files changed, 96 insertions(+), 31 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index ddf97fcc..5552a094 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,4 +1,3 @@ Features: -- Implement slash proposal and execution process for multistaking pool -- Implement delegation/undelegation changes on slashed pool +- Resolve genesis import/export on distributor module diff --git a/proto/kira/distributor/genesis.proto b/proto/kira/distributor/genesis.proto index b194b7d5..657a2fa0 100644 --- a/proto/kira/distributor/genesis.proto +++ b/proto/kira/distributor/genesis.proto @@ -26,6 +26,8 @@ message GenesisState { int64 snap_period = 3; // validator historical votes repeated ValidatorVote validator_votes = 4 [(gogoproto.nullable) = false]; + // previous proposer + string previous_proposer = 5; } // https://www.notion.so/kira-network/KIP-73-Fee-Reward-Distributor-v1-32b3d1dc90024befa7bb9680c6a425cd diff --git a/scripts/commands/governance/upgrade-plan.sh b/scripts/commands/governance/upgrade-plan.sh index f99d40e1..97840b35 100644 --- a/scripts/commands/governance/upgrade-plan.sh +++ b/scripts/commands/governance/upgrade-plan.sh @@ -30,15 +30,16 @@ sekaid query customgov proposals sekaid start --home=$HOME/.sekaid # propose second upgrade plan -sekaid tx upgrade proposal-set-plan --name="upgrade2" --instate-upgrade=true --skip-handler=false --resources="[{\"id\":\"infra\",\"git\":\"https://aaa/bbb.com\"}]" --min-upgrade-time=$(($(date -u +%s) + 200)) --old-chain-id=1 --new-chain-id=1 --rollback-memo=1 --max-enrollment-duration=1 --upgrade-memo="upgrade2 test" --from=validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes +sekaid tx upgrade proposal-set-plan --name="upgrade6" --instate-upgrade=false --skip-handler=true --resources="[{\"id\":\"infra\",\"git\":\"https://aaa/bbb.com\"}]" --min-upgrade-time=$(($(date -u +%s) + 200)) --old-chain-id=testing --new-chain-id=testing --rollback-memo=1 --max-enrollment-duration=1 --upgrade-memo="upgrade2 test" --from=validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes -sekaid tx upgrade proposal-set-plan --name="upgrade3" --instate-upgrade=true --skip-handler=false --resources="[{\"id\":\"infra\",\"git\":\"https://aaa/bbb.com\"}]" --min-upgrade-time=$(($(date -u +%s) + 200)) --old-chain-id=1 --new-chain-id=1 --rollback-memo=1 --max-enrollment-duration=1 --upgrade-memo="upgrade3 test" --from=validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes +sekaid tx upgrade proposal-set-plan --name="upgrade3" --instate-upgrade=true --skip-handler=false --resources="[{\"id\":\"infra\",\"git\":\"https://aaa/bbb.com\"}]" --min-upgrade-time=$(($(date -u +%s) + 200)) --old-chain-id=testing --new-chain-id=testing --rollback-memo=1 --max-enrollment-duration=1 --upgrade-memo="upgrade3 test" --from=validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes -sekaid tx upgrade proposal-set-plan --name="upgrade4" --instate-upgrade=true --skip-handler=true --resources="[{\"id\":\"infra\",\"git\":\"https://aaa/bbb.com\"}]" --min-upgrade-time=$(($(date -u +%s) + 200)) --old-chain-id=1 --new-chain-id=1 --rollback-memo=1 --max-enrollment-duration=1 --upgrade-memo="upgrade4 test" --from=validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes +sekaid tx upgrade proposal-set-plan --name="upgrade4" --instate-upgrade=true --skip-handler=true --resources="[{\"id\":\"infra\",\"git\":\"https://aaa/bbb.com\"}]" --min-upgrade-time=$(($(date -u +%s) + 200)) --old-chain-id=testing --new-chain-id=testing --rollback-memo=1 --max-enrollment-duration=1 --upgrade-memo="upgrade4 test" --from=validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes -sekaid tx upgrade proposal-set-plan --name="upgrade5" --instate-upgrade=false --skip-handler=false --resources="[{\"id\":\"infra\",\"git\":\"https://aaa/bbb.com\"}]" --min-upgrade-time=$(($(date -u +%s) + 200)) --old-chain-id=1 --new-chain-id=1 --rollback-memo=1 --max-enrollment-duration=1 --upgrade-memo="upgrade5 test" --from=validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes +sekaid tx upgrade proposal-set-plan --name="upgrade5" --instate-upgrade=false --skip-handler=false --resources="[{\"id\":\"infra\",\"git\":\"https://aaa/bbb.com\"}]" --min-upgrade-time=$(($(date -u +%s) + 200)) --old-chain-id=testing --new-chain-id=testing --rollback-memo=1 --max-enrollment-duration=1 --upgrade-memo="upgrade5 test" --from=validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes sekaid tx upgrade proposal-cancel-plan --name="cancel-upgrade4" --from=validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes +sekaid tx customgov proposal vote 1 1 --from validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes sekaid tx customgov proposal vote 2 1 --from validator --keyring-backend=test --home=$HOME/.sekaid --chain-id=testing --fees=100ukex --yes sekaid query customgov proposals diff --git a/types/constants.go b/types/constants.go index 3463a6db..254219b4 100644 --- a/types/constants.go +++ b/types/constants.go @@ -3,6 +3,6 @@ package types const ( // we set page iteration limit for safety PageIterationLimit = 512 - SekaiVersion = "v0.3.0" + SekaiVersion = "v0.3.0.21" CosmosVersion = "v0.45.1" ) diff --git a/x/distributor/module.go b/x/distributor/module.go index 71ddacca..d27e8955 100644 --- a/x/distributor/module.go +++ b/x/distributor/module.go @@ -108,6 +108,14 @@ func (am AppModule) InitGenesis( am.distributorKeeper.SetValidatorVote(ctx, consAddr, vote.Height) } + if genesisState.PreviousProposer != "" { + consAddr, err := sdk.ConsAddressFromBech32(genesisState.PreviousProposer) + if err != nil { + panic(err) + } + am.distributorKeeper.SetPreviousProposerConsAddr(ctx, consAddr) + } + return nil } @@ -117,6 +125,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw genesisState.FeesTreasury = am.distributorKeeper.GetFeesTreasury(ctx) genesisState.SnapPeriod = am.distributorKeeper.GetSnapPeriod(ctx) genesisState.ValidatorVotes = am.distributorKeeper.GetAllValidatorVotes(ctx) + genesisState.PreviousProposer = am.distributorKeeper.GetPreviousProposerConsAddr(ctx).String() return cdc.MustMarshalJSON(&genesisState) } diff --git a/x/distributor/types/genesis.pb.go b/x/distributor/types/genesis.pb.go index fe64d052..dbf055e5 100644 --- a/x/distributor/types/genesis.pb.go +++ b/x/distributor/types/genesis.pb.go @@ -86,6 +86,8 @@ type GenesisState struct { SnapPeriod int64 `protobuf:"varint,3,opt,name=snap_period,json=snapPeriod,proto3" json:"snap_period,omitempty"` // validator historical votes ValidatorVotes []ValidatorVote `protobuf:"bytes,4,rep,name=validator_votes,json=validatorVotes,proto3" json:"validator_votes"` + // previous proposer + PreviousProposer string `protobuf:"bytes,5,opt,name=previous_proposer,json=previousProposer,proto3" json:"previous_proposer,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -135,6 +137,13 @@ func (m *GenesisState) GetValidatorVotes() []ValidatorVote { return nil } +func (m *GenesisState) GetPreviousProposer() string { + if m != nil { + return m.PreviousProposer + } + return "" +} + func init() { proto.RegisterType((*ValidatorVote)(nil), "kira.distributor.ValidatorVote") proto.RegisterType((*GenesisState)(nil), "kira.distributor.GenesisState") @@ -143,30 +152,32 @@ func init() { func init() { proto.RegisterFile("kira/distributor/genesis.proto", fileDescriptor_e815530f0f0e0b78) } var fileDescriptor_e815530f0f0e0b78 = []byte{ - // 361 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0x4f, 0x6b, 0xe2, 0x40, - 0x18, 0xc6, 0x13, 0x23, 0xb2, 0x8e, 0x7f, 0x76, 0x09, 0xcb, 0x12, 0x76, 0x21, 0x09, 0x5e, 0x36, - 0x17, 0x33, 0xb0, 0xfb, 0x09, 0xaa, 0x05, 0x0f, 0x85, 0x52, 0x52, 0xf1, 0xd0, 0x4b, 0x18, 0x33, - 0x6f, 0xe3, 0xa0, 0xe6, 0x0d, 0x33, 0xa3, 0xd4, 0x6f, 0xd1, 0x2f, 0xd2, 0xef, 0xe1, 0xd1, 0x63, - 0xe9, 0x41, 0x8a, 0x7e, 0x91, 0x92, 0xa8, 0xa0, 0x3d, 0xf6, 0x94, 0xcc, 0xf3, 0x0c, 0xbf, 0x79, - 0x9f, 0xe7, 0x25, 0xee, 0x54, 0x48, 0x46, 0xb9, 0x50, 0x5a, 0x8a, 0xf1, 0x42, 0xa3, 0xa4, 0x29, - 0x64, 0xa0, 0x84, 0x0a, 0x73, 0x89, 0x1a, 0xed, 0x1f, 0x85, 0x1f, 0x9e, 0xf9, 0xbf, 0x7f, 0xa6, - 0x98, 0x62, 0x69, 0xd2, 0xe2, 0xef, 0x70, 0xaf, 0x73, 0x4d, 0x5a, 0x23, 0x36, 0x13, 0x9c, 0x69, - 0x94, 0x23, 0xd4, 0x60, 0xff, 0x21, 0xf5, 0x04, 0x33, 0x15, 0x33, 0xce, 0xa5, 0x63, 0xfa, 0x66, - 0x50, 0x8f, 0xbe, 0x15, 0xc2, 0x15, 0xe7, 0xd2, 0xfe, 0x45, 0x6a, 0x13, 0x10, 0xe9, 0x44, 0x3b, - 0x15, 0xdf, 0x0c, 0xac, 0xe8, 0x78, 0xea, 0xbc, 0x54, 0x48, 0x73, 0x70, 0x78, 0xff, 0x5e, 0x33, - 0x0d, 0xf6, 0x90, 0xb4, 0x1e, 0x01, 0x54, 0xac, 0x25, 0x30, 0xb5, 0x90, 0x2b, 0xc7, 0xf4, 0xad, - 0xa0, 0xde, 0xa3, 0xeb, 0xad, 0x67, 0xbc, 0x6d, 0xbd, 0xbf, 0xa9, 0xd0, 0x93, 0xc5, 0x38, 0x4c, - 0x70, 0x4e, 0x13, 0x54, 0x73, 0x54, 0xc7, 0x4f, 0x57, 0xf1, 0x29, 0xd5, 0xab, 0x1c, 0x54, 0xd8, - 0x47, 0x91, 0x45, 0xcd, 0x82, 0x32, 0x3c, 0x42, 0xec, 0x11, 0x69, 0x97, 0xd4, 0x04, 0x67, 0x33, - 0x48, 0x34, 0x70, 0xa7, 0xf2, 0x35, 0x6c, 0x39, 0x5c, 0xff, 0x44, 0xb1, 0x3d, 0xd2, 0x50, 0x19, - 0xcb, 0xe3, 0x1c, 0xa4, 0x40, 0xee, 0x58, 0x65, 0x36, 0x52, 0x48, 0x77, 0xa5, 0x62, 0xdf, 0x92, - 0xef, 0xcb, 0x53, 0x4b, 0xf1, 0x12, 0x35, 0x28, 0xa7, 0xea, 0x5b, 0x41, 0xe3, 0x9f, 0x17, 0x7e, - 0xee, 0x39, 0xbc, 0xa8, 0xb3, 0x57, 0x2d, 0x46, 0x8b, 0xda, 0xcb, 0x73, 0x51, 0xf5, 0x06, 0xeb, - 0x9d, 0x6b, 0x6e, 0x76, 0xae, 0xf9, 0xbe, 0x73, 0xcd, 0xe7, 0xbd, 0x6b, 0x6c, 0xf6, 0xae, 0xf1, - 0xba, 0x77, 0x8d, 0x87, 0xee, 0x59, 0x84, 0x1b, 0x21, 0x59, 0x1f, 0x25, 0x50, 0x05, 0x53, 0x26, - 0xe8, 0xd3, 0xc5, 0xba, 0xcb, 0x34, 0xe3, 0x5a, 0xb9, 0xc5, 0xff, 0x1f, 0x01, 0x00, 0x00, 0xff, - 0xff, 0x3c, 0xa6, 0xbb, 0x18, 0x0f, 0x02, 0x00, 0x00, + // 385 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0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00, 0x00, 0xff, 0xff, 0xe3, 0x6d, 0xce, 0xc6, 0x3c, 0x02, 0x00, + 0x00, } func (m *ValidatorVote) Marshal() (dAtA []byte, err error) { @@ -224,6 +235,13 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.PreviousProposer) > 0 { + i -= len(m.PreviousProposer) + copy(dAtA[i:], m.PreviousProposer) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.PreviousProposer))) + i-- + dAtA[i] = 0x2a + } if len(m.ValidatorVotes) > 0 { for iNdEx := len(m.ValidatorVotes) - 1; iNdEx >= 0; iNdEx-- { { @@ -328,6 +346,10 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + l = len(m.PreviousProposer) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } return n } @@ -592,6 +614,38 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PreviousProposer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PreviousProposer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:])