mirror of
https://github.com/0glabs/0g-chain.git
synced 2025-01-12 16:25:17 +00:00
feat: remove epoch and block height hard check
This commit is contained in:
parent
3017ed9919
commit
fd1f2133b8
@ -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
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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")
|
||||
)
|
||||
|
@ -1,5 +1,8 @@
|
||||
package types
|
||||
|
||||
func (p *Params) Validate() error {
|
||||
if p.EpochBlocks == 0 {
|
||||
return ErrInvalidEpochBlocks
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user