mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-20 15:05:21 +00:00
Merge pull request #64 from 0glabs/dev
Some checks failed
Continuous Integration (Commit) / lint (push) Has been cancelled
Some checks failed
Continuous Integration (Commit) / lint (push) Has been cancelled
fix missing dasigners and conuncil
This commit is contained in:
commit
83d0ab3bec
@ -669,7 +669,9 @@ 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.
|
||||||
@ -711,9 +713,11 @@ 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.
|
||||||
@ -745,9 +749,11 @@ 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
|
||||||
@ -777,10 +783,12 @@ 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)
|
||||||
|
@ -12,7 +12,6 @@ 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"
|
||||||
@ -97,18 +96,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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package keeper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
@ -16,7 +17,8 @@ type Ballot struct {
|
|||||||
content []byte
|
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)
|
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")
|
||||||
@ -25,12 +27,14 @@ func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
|
|||||||
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
|
return false
|
||||||
}
|
}
|
||||||
if expectedEpoch > epochNumber+1 || expectedEpoch < epochNumber {
|
if 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{
|
||||||
@ -106,4 +110,11 @@ func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
|
|||||||
// 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) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ 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"
|
||||||
@ -19,16 +18,29 @@ 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.Require().Panics(func() {
|
suite.Assert().EqualValues(params, types.DefaultGenesisState().Params)
|
||||||
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,
|
||||||
|
@ -7,7 +7,6 @@ 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"
|
||||||
@ -312,7 +311,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)))
|
||||||
|
Loading…
Reference in New Issue
Block a user