Skip to content

Commit 07f12e6

Browse files
fatcat22fatcat22
andauthored
upgrade proposal vote and effective (#106)
* dev: upgrade proposal vote and effective after height greater than expect height * fix test --------- Co-authored-by: fatcat22 <[email protected]>
1 parent 12168ea commit 07f12e6

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

x/params/proposal_handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ func (suite *ProposalHandlerSuite) TestCheckUpgradeVote() {
243243
}{
244244
{0, 10, false},
245245
{0, 1111, false},
246-
{10, 11, true},
247-
{10, 10, true},
246+
{10, 11, false},
247+
{10, 10, false},
248248
{10, 9, false},
249249
}
250250

x/params/upgrade_executor.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"math"
66

77
sdk "github.com/okx/okbchain/libs/cosmos-sdk/types"
8-
sdkerrors "github.com/okx/okbchain/libs/cosmos-sdk/types/errors"
98
"github.com/okx/okbchain/x/common"
109
govtypes "github.com/okx/okbchain/x/gov/types"
1110
"github.com/okx/okbchain/x/params/types"
@@ -35,6 +34,7 @@ func handleUpgradeProposal(ctx sdk.Context, k *Keeper, proposalID uint64, propos
3534
_ = storeWaitingUpgrade(ctx, k, proposal, effectiveHeight) // ignore error
3635
return nil
3736
}
37+
defer k.gk.RemoveFromWaitingProposalQueue(ctx, confirmHeight, proposalID)
3838

3939
// proposal will be confirmed right now, check if ready.
4040
cbs, ready := k.queryReadyForUpgrade(proposal.Name)
@@ -77,11 +77,8 @@ func getUpgradeProposalConfirmHeight(currentHeight uint64, proposal types.Upgrad
7777

7878
if confirmHeight < currentHeight {
7979
// if it's too late to make the proposal become effective at the height which we expected,
80-
// refuse to effective this proposal
81-
return 0, sdkerrors.New(DefaultCodespace, types.BaseParamsError,
82-
fmt.Sprintf("current height '%d' has exceed "+
83-
"the expect height '%d' of upgrade proposal '%s'",
84-
currentHeight, proposal.ExpectHeight, proposal.Name))
80+
// make the upgrade effective at next block (just like height is not specified).
81+
confirmHeight = currentHeight
8582
}
8683
return confirmHeight, nil
8784
}
@@ -146,15 +143,6 @@ func checkUpgradeValidEffectiveHeight(ctx sdk.Context, k *Keeper, effectiveHeigh
146143
return nil
147144
}
148145

149-
func checkUpgradeVote(ctx sdk.Context, proposalID uint64, proposal types.UpgradeProposal, _ govtypes.Vote) (string, sdk.Error) {
150-
curHeight := uint64(ctx.BlockHeight())
151-
152-
if proposal.ExpectHeight != 0 && proposal.ExpectHeight <= curHeight {
153-
return "", sdkerrors.New(DefaultCodespace, types.BaseParamsError,
154-
fmt.Sprintf("can not vote: current height '%d' has exceed "+
155-
"the expect height '%d' of upgrade proposal '%s'(proposal id '%d')",
156-
curHeight, proposal.ExpectHeight, proposal.Name, proposalID))
157-
}
158-
146+
func checkUpgradeVote(_ sdk.Context, _ uint64, _ types.UpgradeProposal, _ govtypes.Vote) (string, sdk.Error) {
159147
return "", nil
160148
}

x/params/upgrade_executor_test.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func TestUpgradeProposalConfirmHeight(t *testing.T) {
9797
expectConfirmHeight uint64
9898
}{
9999
{uint64(10), uint64(0), false, uint64(10)},
100-
{uint64(10), uint64(5), true, uint64(0)},
101-
{uint64(10), uint64(10), true, uint64(0)},
100+
{uint64(10), uint64(5), false, uint64(10)},
101+
{uint64(10), uint64(10), false, uint64(10)},
102102
{uint64(10), uint64(11), false, uint64(10)},
103103
{uint64(10), uint64(15), false, uint64(14)},
104104
}
@@ -259,8 +259,8 @@ func (suite *UpgradeInfoStoreSuite) TestCheckUpgradeVote() {
259259
}{
260260
{0, 10, false},
261261
{0, 1111, false},
262-
{10, 11, true},
263-
{10, 10, true},
262+
{10, 11, false},
263+
{10, 10, false},
264264
{10, 9, false},
265265
}
266266

@@ -287,19 +287,25 @@ func (suite *UpgradeInfoStoreSuite) TestHandleUpgradeProposal() {
287287
expectHitError bool
288288
}{
289289
{ // expect height is not zero but less than current height
290-
expectHeight: 10, currentHeight: 10, claimReady: false, expectPanic: false, expect1stExecuteError: true,
290+
expectHeight: 10, currentHeight: 10, claimReady: false, expectPanic: true, expect1stExecuteError: false,
291291
},
292292
{ // expect height is not zero but only greater than current height 1; and not claim ready
293-
expectHeight: 11, currentHeight: 10, claimReady: false, expectPanic: true,
293+
expectHeight: 21, currentHeight: 20, claimReady: false, expectPanic: true,
294294
},
295295
{ // expect height is not zero and greater than current height; but not claim ready
296-
expectHeight: 12, currentHeight: 10, claimReady: false, expectPanic: true, expect1stExecuteError: false,
296+
expectHeight: 32, currentHeight: 30, claimReady: false, expectPanic: true, expect1stExecuteError: false,
297297
},
298298
{ // everything's ok: expect height is not zero and greater than current height; and claim ready
299-
expectHeight: 12, currentHeight: 10, claimReady: true, expectPanic: false, expect1stExecuteError: false, expectHitError: false,
299+
expectHeight: 42, currentHeight: 40, claimReady: true, expectPanic: false, expect1stExecuteError: false, expectHitError: false,
300300
},
301301
{ // everything's ok: expect height is zero and claim ready
302-
expectHeight: 0, currentHeight: 10, claimReady: true, expectPanic: false, expect1stExecuteError: false, expectHitError: false,
302+
expectHeight: 0, currentHeight: 50, claimReady: true, expectPanic: false, expect1stExecuteError: false, expectHitError: false,
303+
},
304+
{ // everything's ok: expect height is not zero and equal to current height; and claim ready
305+
expectHeight: 60, currentHeight: 60, claimReady: true, expectPanic: false, expect1stExecuteError: false, expectHitError: false,
306+
},
307+
{ // everything's ok: expect height is not zero and less than current height; and claim ready
308+
expectHeight: 70, currentHeight: 72, claimReady: true, expectPanic: false, expect1stExecuteError: false, expectHitError: false,
303309
},
304310
}
305311

@@ -316,6 +322,9 @@ func (suite *UpgradeInfoStoreSuite) TestHandleUpgradeProposal() {
316322
if tt.expectHeight == 0 {
317323
confirmHeight = tt.currentHeight
318324
}
325+
if confirmHeight < tt.currentHeight {
326+
confirmHeight = tt.currentHeight
327+
}
319328
effectiveHeight := confirmHeight + 1
320329

321330
cbCount := 0
@@ -327,7 +336,7 @@ func (suite *UpgradeInfoStoreSuite) TestHandleUpgradeProposal() {
327336
})
328337
}
329338

330-
if tt.expectPanic && confirmHeight == tt.currentHeight {
339+
if tt.expectPanic && confirmHeight <= tt.currentHeight {
331340
suite.Panics(func() { _ = handler(ctx, proposal) })
332341
continue
333342
}
@@ -339,8 +348,7 @@ func (suite *UpgradeInfoStoreSuite) TestHandleUpgradeProposal() {
339348
continue
340349
}
341350

342-
suite.GreaterOrEqual(confirmHeight, tt.currentHeight)
343-
if confirmHeight != tt.currentHeight {
351+
if confirmHeight > tt.currentHeight {
344352
// proposal is inserted to gov waiting queue, execute it
345353
expectInfo := types.UpgradeInfo{
346354
Name: upgradeProposal.Name,

0 commit comments

Comments
 (0)