Compare commits

...

3 Commits

Author SHA1 Message Date
0g-wh
568ff70ad7
Merge pull request #63 from Solovyov1796/local-dev
Some checks failed
Continuous Integration (Commit) / lint (push) Has been cancelled
add conuncil back
2024-08-10 10:25:04 +08:00
MiniFrenchBread
1355bd6ab1
fix: missing designers (#62)
* fix: add dasigners back

* test: remove manually initialize genesis

* feat: generate all missing epochs on begin block; only panic on smaller block height

* chore: add logs, fix EpochBlocks
2024-08-10 10:24:11 +08:00
Solovyov1796
ceb4d774ff add conuncil back 2024-08-10 10:18:21 +08:00
5 changed files with 43 additions and 14 deletions

View File

@ -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.
@ -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.
@ -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
@ -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)

View File

@ -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"
@ -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,
}
}

View File

@ -2,6 +2,7 @@ package keeper
import (
"bytes"
"fmt"
"math/big"
"sort"
@ -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")
@ -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{
@ -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) {
}
}

View File

@ -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"
@ -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,

View File

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