Compare commits

..

No commits in common. "568ff70ad7d2a7d57b15f502d18130b1ebec3a1d" and "8bd14a6c0025deda89ba74bb885544ba0c444d51" have entirely different histories.

5 changed files with 14 additions and 43 deletions

View File

@ -669,9 +669,7 @@ func NewApp(
evmutil.NewAppModule(app.evmutilKeeper, app.bankKeeper, app.accountKeeper), evmutil.NewAppModule(app.evmutilKeeper, app.bankKeeper, app.accountKeeper),
// nil InflationCalculationFn, use SDK's default inflation function // nil InflationCalculationFn, use SDK's default inflation function
mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper, nil, mintSubspace), mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper, nil, mintSubspace),
council.NewAppModule(app.CouncilKeeper),
ibcwasm.NewAppModule(app.ibcWasmClientKeeper), ibcwasm.NewAppModule(app.ibcWasmClientKeeper),
dasigners.NewAppModule(app.dasignersKeeper, *app.stakingKeeper),
) )
// Warning: Some begin blockers must run before others. Ensure the dependencies are understood before modifying this list. // Warning: Some begin blockers must run before others. Ensure the dependencies are understood before modifying this list.
@ -713,11 +711,9 @@ func NewApp(
paramstypes.ModuleName, paramstypes.ModuleName,
authz.ModuleName, authz.ModuleName,
evmutiltypes.ModuleName, evmutiltypes.ModuleName,
counciltypes.ModuleName,
consensusparamtypes.ModuleName, consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName, packetforwardtypes.ModuleName,
ibcwasmtypes.ModuleName, ibcwasmtypes.ModuleName,
dasignerstypes.ModuleName,
) )
// Warning: Some end blockers must run before others. Ensure the dependencies are understood before modifying this list. // Warning: Some end blockers must run before others. Ensure the dependencies are understood before modifying this list.
@ -749,11 +745,9 @@ func NewApp(
authz.ModuleName, authz.ModuleName,
evmutiltypes.ModuleName, evmutiltypes.ModuleName,
minttypes.ModuleName, minttypes.ModuleName,
counciltypes.ModuleName,
consensusparamtypes.ModuleName, consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName, packetforwardtypes.ModuleName,
ibcwasmtypes.ModuleName, ibcwasmtypes.ModuleName,
dasignerstypes.ModuleName,
) )
// Warning: Some init genesis methods must run before others. Ensure the dependencies are understood before modifying this list // Warning: Some init genesis methods must run before others. Ensure the dependencies are understood before modifying this list
@ -783,12 +777,10 @@ func NewApp(
paramstypes.ModuleName, paramstypes.ModuleName,
upgradetypes.ModuleName, upgradetypes.ModuleName,
validatorvestingtypes.ModuleName, validatorvestingtypes.ModuleName,
counciltypes.ModuleName,
consensusparamtypes.ModuleName, consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName, packetforwardtypes.ModuleName,
crisistypes.ModuleName, // runs the invariants at genesis, should run after other modules crisistypes.ModuleName, // runs the invariants at genesis, should run after other modules
ibcwasmtypes.ModuleName, ibcwasmtypes.ModuleName,
dasignerstypes.ModuleName,
) )
app.mm.RegisterInvariants(&app.crisisKeeper) app.mm.RegisterInvariants(&app.crisisKeeper)

View File

@ -12,6 +12,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -96,18 +97,18 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
type AppModule struct { type AppModule struct {
AppModuleBasic AppModuleBasic
keeper keeper.Keeper keeper keeper.Keeper
// sk stakingkeeper.Keeper sk stakingkeeper.Keeper
} }
// NewAppModule creates a new AppModule Object // NewAppModule creates a new AppModule Object
func NewAppModule( func NewAppModule(
k keeper.Keeper, k keeper.Keeper,
// sk stakingkeeper.Keeper, sk stakingkeeper.Keeper,
) AppModule { ) AppModule {
return AppModule{ return AppModule{
AppModuleBasic: AppModuleBasic{}, AppModuleBasic: AppModuleBasic{},
keeper: k, keeper: k,
// sk: sk, sk: sk,
} }
} }

View File

@ -2,7 +2,6 @@ package keeper
import ( import (
"bytes" "bytes"
"fmt"
"math/big" "math/big"
"sort" "sort"
@ -17,8 +16,7 @@ type Ballot struct {
content []byte content []byte
} }
// generateOneEpoch generate one epoch and returns true if there is a new epoch generated func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
func (k Keeper) generateOneEpoch(ctx sdk.Context) bool {
epochNumber, err := k.GetEpochNumber(ctx) epochNumber, err := k.GetEpochNumber(ctx)
if err != nil { if err != nil {
k.Logger(ctx).Error("[BeginBlock] cannot get epoch number") k.Logger(ctx).Error("[BeginBlock] cannot get epoch number")
@ -27,14 +25,12 @@ func (k Keeper) generateOneEpoch(ctx sdk.Context) bool {
params := k.GetParams(ctx) params := k.GetParams(ctx)
expectedEpoch := uint64(ctx.BlockHeight()) / params.EpochBlocks expectedEpoch := uint64(ctx.BlockHeight()) / params.EpochBlocks
if expectedEpoch == epochNumber { if expectedEpoch == epochNumber {
return false return
} }
if expectedEpoch < epochNumber { if expectedEpoch > epochNumber+1 || expectedEpoch < epochNumber {
panic("block height is not continuous") panic("block height is not continuous")
} }
expectedEpoch = epochNumber + 1
// new epoch // new epoch
k.Logger(ctx).Info(fmt.Sprintf("[BeginBlock] generating epoch %v", expectedEpoch))
registrations := []Ballot{} registrations := []Ballot{}
k.IterateRegistrations(ctx, expectedEpoch, func(account string, signature []byte) (stop bool) { k.IterateRegistrations(ctx, expectedEpoch, func(account string, signature []byte) (stop bool) {
registrations = append(registrations, Ballot{ registrations = append(registrations, Ballot{
@ -110,11 +106,4 @@ func (k Keeper) generateOneEpoch(ctx sdk.Context) bool {
// save to store // save to store
k.SetEpochQuorums(ctx, expectedEpoch, quorums) k.SetEpochQuorums(ctx, expectedEpoch, quorums)
k.SetEpochNumber(ctx, expectedEpoch) 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) {
}
} }

View File

@ -3,6 +3,7 @@ package keeper_test
import ( import (
"testing" "testing"
"github.com/0glabs/0g-chain/x/dasigners/v1"
"github.com/0glabs/0g-chain/x/dasigners/v1/keeper" "github.com/0glabs/0g-chain/x/dasigners/v1/keeper"
"github.com/0glabs/0g-chain/x/dasigners/v1/testutil" "github.com/0glabs/0g-chain/x/dasigners/v1/testutil"
"github.com/0glabs/0g-chain/x/dasigners/v1/types" "github.com/0glabs/0g-chain/x/dasigners/v1/types"
@ -18,29 +19,16 @@ type AbciTestSuite struct {
func (suite *AbciTestSuite) TestBeginBlock_NotContinuous() { func (suite *AbciTestSuite) TestBeginBlock_NotContinuous() {
// suite.App.InitializeFromGenesisStates() // suite.App.InitializeFromGenesisStates()
// dasigners.InitGenesis(suite.Ctx, suite.Keeper, *types.DefaultGenesisState()) dasigners.InitGenesis(suite.Ctx, suite.Keeper, *types.DefaultGenesisState())
params := suite.Keeper.GetParams(suite.Ctx) params := suite.Keeper.GetParams(suite.Ctx)
suite.Assert().EqualValues(params, types.DefaultGenesisState().Params) suite.Require().Panics(func() {
suite.Keeper.BeginBlock(suite.Ctx.WithBlockHeight(int64(params.EpochBlocks*2)), abci.RequestBeginBlock{})
epoch, err := suite.Keeper.GetEpochNumber(suite.Ctx)
suite.Require().NoError(err)
suite.Assert().EqualValues(epoch, 0)
suite.Assert().NotPanics(func() {
suite.Keeper.BeginBlock(suite.Ctx.WithBlockHeight(int64(params.EpochBlocks*10)), abci.RequestBeginBlock{})
})
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") }, "block height is not continuous")
} }
func (suite *AbciTestSuite) TestBeginBlock_Success() { func (suite *AbciTestSuite) TestBeginBlock_Success() {
// suite.App.InitializeFromGenesisStates() // suite.App.InitializeFromGenesisStates()
// dasigners.InitGenesis(suite.Ctx, suite.Keeper, *types.DefaultGenesisState()) dasigners.InitGenesis(suite.Ctx, suite.Keeper, *types.DefaultGenesisState())
suite.Keeper.SetParams(suite.Ctx, types.Params{ suite.Keeper.SetParams(suite.Ctx, types.Params{
TokensPerVote: 10, TokensPerVote: 10,
MaxVotesPerSigner: 200, MaxVotesPerSigner: 200,

View File

@ -7,6 +7,7 @@ import (
"testing" "testing"
"github.com/0glabs/0g-chain/crypto/bn254util" "github.com/0glabs/0g-chain/crypto/bn254util"
"github.com/0glabs/0g-chain/x/dasigners/v1"
"github.com/0glabs/0g-chain/x/dasigners/v1/keeper" "github.com/0glabs/0g-chain/x/dasigners/v1/keeper"
"github.com/0glabs/0g-chain/x/dasigners/v1/testutil" "github.com/0glabs/0g-chain/x/dasigners/v1/testutil"
"github.com/0glabs/0g-chain/x/dasigners/v1/types" "github.com/0glabs/0g-chain/x/dasigners/v1/types"
@ -311,7 +312,7 @@ func (suite *KeeperTestSuite) queryAggregatePubkeyG1(params types.Params) {
func (suite *KeeperTestSuite) Test_Keeper() { func (suite *KeeperTestSuite) Test_Keeper() {
// suite.App.InitializeFromGenesisStates() // suite.App.InitializeFromGenesisStates()
// dasigners.InitGenesis(suite.Ctx, suite.Keeper, *types.DefaultGenesisState()) dasigners.InitGenesis(suite.Ctx, suite.Keeper, *types.DefaultGenesisState())
// add delegation // add delegation
params := suite.Keeper.GetParams(suite.Ctx) params := suite.Keeper.GetParams(suite.Ctx)
suite.AddDelegation(signer1, signer1, keeper.BondedConversionRate.Mul(sdk.NewIntFromUint64(params.TokensPerVote))) suite.AddDelegation(signer1, signer1, keeper.BondedConversionRate.Mul(sdk.NewIntFromUint64(params.TokensPerVote)))