Skip to content

Commit

Permalink
Merge pull request #64 from 0glabs/dev
Browse files Browse the repository at this point in the history
fix missing dasigners and conuncil
  • Loading branch information
0g-wh authored Aug 10, 2024
2 parents ff9195c + 568ff70 commit 83d0ab3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
8 changes: 8 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@ func NewApp(
evmutil.NewAppModule(app.evmutilKeeper, app.bankKeeper, app.accountKeeper),
// nil InflationCalculationFn, use SDK's default inflation function
mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper, nil, mintSubspace),
council.NewAppModule(app.CouncilKeeper),
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.
Expand Down Expand Up @@ -711,9 +713,11 @@ func NewApp(
paramstypes.ModuleName,
authz.ModuleName,
evmutiltypes.ModuleName,
counciltypes.ModuleName,
consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName,
ibcwasmtypes.ModuleName,
dasignerstypes.ModuleName,
)

// Warning: Some end blockers must run before others. Ensure the dependencies are understood before modifying this list.
Expand Down Expand Up @@ -745,9 +749,11 @@ func NewApp(
authz.ModuleName,
evmutiltypes.ModuleName,
minttypes.ModuleName,
counciltypes.ModuleName,
consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName,
ibcwasmtypes.ModuleName,
dasignerstypes.ModuleName,
)

// Warning: Some init genesis methods must run before others. Ensure the dependencies are understood before modifying this list
Expand Down Expand Up @@ -777,10 +783,12 @@ func NewApp(
paramstypes.ModuleName,
upgradetypes.ModuleName,
validatorvestingtypes.ModuleName,
counciltypes.ModuleName,
consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName,
crisistypes.ModuleName, // runs the invariants at genesis, should run after other modules
ibcwasmtypes.ModuleName,
dasignerstypes.ModuleName,
)

app.mm.RegisterInvariants(&app.crisisKeeper)
Expand Down
7 changes: 3 additions & 4 deletions x/council/v1/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -97,18 +96,18 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
type AppModule struct {
AppModuleBasic
keeper keeper.Keeper
sk stakingkeeper.Keeper
// sk stakingkeeper.Keeper
}

// NewAppModule creates a new AppModule Object
func NewAppModule(
k keeper.Keeper,
sk stakingkeeper.Keeper,
// sk stakingkeeper.Keeper,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
keeper: k,
sk: sk,
// sk: sk,
}
}

Expand Down
17 changes: 14 additions & 3 deletions x/dasigners/v1/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"bytes"
"fmt"
"math/big"
"sort"

Expand All @@ -16,7 +17,8 @@ type Ballot struct {
content []byte
}

func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
// generateOneEpoch generate one epoch and returns true if there is a new epoch generated
func (k Keeper) generateOneEpoch(ctx sdk.Context) bool {
epochNumber, err := k.GetEpochNumber(ctx)
if err != nil {
k.Logger(ctx).Error("[BeginBlock] cannot get epoch number")
Expand All @@ -25,12 +27,14 @@ func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
params := k.GetParams(ctx)
expectedEpoch := uint64(ctx.BlockHeight()) / params.EpochBlocks
if expectedEpoch == epochNumber {
return
return false
}
if expectedEpoch > epochNumber+1 || expectedEpoch < epochNumber {
if expectedEpoch < epochNumber {
panic("block height is not continuous")
}
expectedEpoch = epochNumber + 1
// new epoch
k.Logger(ctx).Info(fmt.Sprintf("[BeginBlock] generating epoch %v", expectedEpoch))
registrations := []Ballot{}
k.IterateRegistrations(ctx, expectedEpoch, func(account string, signature []byte) (stop bool) {
registrations = append(registrations, Ballot{
Expand Down Expand Up @@ -106,4 +110,11 @@ func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
// 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) {
}
}
22 changes: 17 additions & 5 deletions x/dasigners/v1/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper_test
import (
"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/testutil"
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
Expand All @@ -19,16 +18,29 @@ type AbciTestSuite struct {

func (suite *AbciTestSuite) TestBeginBlock_NotContinuous() {
// 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)
suite.Require().Panics(func() {
suite.Keeper.BeginBlock(suite.Ctx.WithBlockHeight(int64(params.EpochBlocks*2)), abci.RequestBeginBlock{})
suite.Assert().EqualValues(params, types.DefaultGenesisState().Params)

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")
}

func (suite *AbciTestSuite) TestBeginBlock_Success() {
// 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{
TokensPerVote: 10,
MaxVotesPerSigner: 200,
Expand Down
3 changes: 1 addition & 2 deletions x/dasigners/v1/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"

"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/testutil"
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
Expand Down Expand Up @@ -312,7 +311,7 @@ func (suite *KeeperTestSuite) queryAggregatePubkeyG1(params types.Params) {

func (suite *KeeperTestSuite) Test_Keeper() {
// suite.App.InitializeFromGenesisStates()
dasigners.InitGenesis(suite.Ctx, suite.Keeper, *types.DefaultGenesisState())
// dasigners.InitGenesis(suite.Ctx, suite.Keeper, *types.DefaultGenesisState())
// add delegation
params := suite.Keeper.GetParams(suite.Ctx)
suite.AddDelegation(signer1, signer1, keeper.BondedConversionRate.Mul(sdk.NewIntFromUint64(params.TokensPerVote)))
Expand Down

0 comments on commit 83d0ab3

Please sign in to comment.