From fd1f2133b8728ed0e29e84781f00ecf44655358a Mon Sep 17 00:00:00 2001 From: MiniFrenchBread <103425574+MiniFrenchBread@users.noreply.github.com> Date: Tue, 13 Aug 2024 15:42:27 +0800 Subject: [PATCH] feat: remove epoch and block height hard check --- x/dasigners/v1/keeper/abci.go | 26 ++++++++------------------ x/dasigners/v1/keeper/abci_test.go | 6 +----- x/dasigners/v1/types/errors.go | 1 + x/dasigners/v1/types/params.go | 3 +++ 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/x/dasigners/v1/keeper/abci.go b/x/dasigners/v1/keeper/abci.go index 32d41d89..4c4f3f92 100644 --- a/x/dasigners/v1/keeper/abci.go +++ b/x/dasigners/v1/keeper/abci.go @@ -17,22 +17,17 @@ type Ballot struct { content []byte } -// generateOneEpoch generate one epoch and returns true if there is a new epoch generated -func (k Keeper) generateOneEpoch(ctx sdk.Context) bool { +func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { + params := k.GetParams(ctx) + if uint64(ctx.BlockHeight())%params.EpochBlocks != 0 { + return + } epochNumber, err := k.GetEpochNumber(ctx) if err != nil { k.Logger(ctx).Error("[BeginBlock] cannot get epoch number") panic(err) } - params := k.GetParams(ctx) - expectedEpoch := uint64(ctx.BlockHeight()) / params.EpochBlocks - if expectedEpoch == epochNumber { - return false - } - if expectedEpoch < epochNumber { - panic("block height is not continuous") - } - expectedEpoch = epochNumber + 1 + expectedEpoch := epochNumber + 1 // new epoch k.Logger(ctx).Info(fmt.Sprintf("[BeginBlock] generating epoch %v", expectedEpoch)) registrations := []Ballot{} @@ -110,11 +105,6 @@ func (k Keeper) generateOneEpoch(ctx sdk.Context) bool { // save to store k.SetEpochQuorums(ctx, expectedEpoch, quorums) k.SetEpochNumber(ctx, expectedEpoch) - k.Logger(ctx).Info(fmt.Sprintf("[BeginBlock] epoch %v generated, with %v quorums", expectedEpoch, len(quorums.Quorums))) - return true -} - -func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { - for k.generateOneEpoch(ctx) { - } + k.Logger(ctx).Info(fmt.Sprintf("[BeginBlock] epoch %v generated at block height %v, with %v quorums", expectedEpoch, ctx.BlockHeight(), len(quorums.Quorums))) + return } diff --git a/x/dasigners/v1/keeper/abci_test.go b/x/dasigners/v1/keeper/abci_test.go index 424abe9c..ea1bf997 100644 --- a/x/dasigners/v1/keeper/abci_test.go +++ b/x/dasigners/v1/keeper/abci_test.go @@ -31,11 +31,7 @@ func (suite *AbciTestSuite) TestBeginBlock_NotContinuous() { }) epoch, err = suite.Keeper.GetEpochNumber(suite.Ctx) suite.Require().NoError(err) - suite.Assert().EqualValues(epoch, 10) - - suite.Assert().Panics(func() { - suite.Keeper.BeginBlock(suite.Ctx.WithBlockHeight(int64(params.EpochBlocks*9)), abci.RequestBeginBlock{}) - }, "block height is not continuous") + suite.Assert().EqualValues(epoch, 1) } func (suite *AbciTestSuite) TestBeginBlock_Success() { diff --git a/x/dasigners/v1/types/errors.go b/x/dasigners/v1/types/errors.go index 0a421941..4e33a1a8 100644 --- a/x/dasigners/v1/types/errors.go +++ b/x/dasigners/v1/types/errors.go @@ -12,4 +12,5 @@ var ( ErrQuorumBitmapLengthMismatch = errorsmod.Register(ModuleName, 7, "quorum bitmap length mismatch") ErrInsufficientBonded = errorsmod.Register(ModuleName, 8, "insufficient bonded amount") ErrRowIndexOutOfBound = errorsmod.Register(ModuleName, 9, "row index out of bound") + ErrInvalidEpochBlocks = errorsmod.Register(ModuleName, 10, "invalid epoch blocks") ) diff --git a/x/dasigners/v1/types/params.go b/x/dasigners/v1/types/params.go index a8c6fd96..ecb5a0f4 100644 --- a/x/dasigners/v1/types/params.go +++ b/x/dasigners/v1/types/params.go @@ -1,5 +1,8 @@ package types func (p *Params) Validate() error { + if p.EpochBlocks == 0 { + return ErrInvalidEpochBlocks + } return nil }