mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
feat: add params event
This commit is contained in:
parent
fd1f2133b8
commit
a735de4adf
@ -2,18 +2,21 @@ package keeper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"cosmossdk.io/math"
|
"cosmossdk.io/math"
|
||||||
"github.com/cometbft/cometbft/libs/log"
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/store/prefix"
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
||||||
|
|
||||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/chaincfg"
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
"github.com/0glabs/0g-chain/x/dasigners/v1/types"
|
||||||
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var BondedConversionRate = math.NewIntFromBigInt(big.NewInt(0).Exp(big.NewInt(10), big.NewInt(chaincfg.GasDenomUnit), nil))
|
var BondedConversionRate = math.NewIntFromBigInt(big.NewInt(0).Exp(big.NewInt(10), big.NewInt(chaincfg.GasDenomUnit), nil))
|
||||||
@ -57,6 +60,17 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
|
|||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := k.cdc.MustMarshal(¶ms)
|
bz := k.cdc.MustMarshal(¶ms)
|
||||||
store.Set(types.ParamsKey, bz)
|
store.Set(types.ParamsKey, bz)
|
||||||
|
|
||||||
|
ctx.EventManager().EmitEvent(
|
||||||
|
sdk.NewEvent(
|
||||||
|
types.EventTypeUpdateParams,
|
||||||
|
sdk.NewAttribute(types.AttributeKeyBlockHeight, fmt.Sprint(ctx.BlockHeader().Height)),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyTokensPerVote, fmt.Sprint(params.TokensPerVote)),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyMaxQuorums, fmt.Sprint(params.MaxQuorums)),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyEpochBlocks, fmt.Sprint(params.EpochBlocks)),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyEncodedSlices, fmt.Sprint(params.EncodedSlices)),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) GetEpochNumber(ctx sdk.Context) (uint64, error) {
|
func (k Keeper) GetEpochNumber(ctx sdk.Context) (uint64, error) {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package keeper_test
|
package keeper_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"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"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -53,6 +55,7 @@ func (suite *MsgServerTestSuite) TestChangeParams() {
|
|||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
suite.Run(tc.name, func() {
|
suite.Run(tc.name, func() {
|
||||||
|
oldEventNum := len(suite.Ctx.EventManager().Events())
|
||||||
_, err := suite.Keeper.ChangeParams(suite.Ctx, tc.req)
|
_, err := suite.Keeper.ChangeParams(suite.Ctx, tc.req)
|
||||||
if tc.expectErr {
|
if tc.expectErr {
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
@ -61,6 +64,19 @@ func (suite *MsgServerTestSuite) TestChangeParams() {
|
|||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
params := suite.Keeper.GetParams(suite.Ctx)
|
params := suite.Keeper.GetParams(suite.Ctx)
|
||||||
suite.Require().EqualValues(*tc.req.Params, params)
|
suite.Require().EqualValues(*tc.req.Params, params)
|
||||||
|
suite.Assert().NoError(err)
|
||||||
|
|
||||||
|
events := suite.Ctx.EventManager().Events()
|
||||||
|
suite.Assert().EqualValues(len(events), oldEventNum+1)
|
||||||
|
suite.Assert().EqualValues(events[len(events)-1], sdk.NewEvent(
|
||||||
|
types.EventTypeUpdateParams,
|
||||||
|
sdk.NewAttribute(types.AttributeKeyBlockHeight, fmt.Sprint(suite.Ctx.BlockHeader().Height)),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyTokensPerVote, fmt.Sprint(params.TokensPerVote)),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyMaxQuorums, fmt.Sprint(params.MaxQuorums)),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyEpochBlocks, fmt.Sprint(params.EpochBlocks)),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyEncodedSlices, fmt.Sprint(params.EncodedSlices)),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,16 @@ package types
|
|||||||
// Module event types
|
// Module event types
|
||||||
const (
|
const (
|
||||||
EventTypeUpdateSigner = "update_signer"
|
EventTypeUpdateSigner = "update_signer"
|
||||||
|
EventTypeUpdateParams = "update_params"
|
||||||
|
|
||||||
AttributeKeySigner = "signer"
|
AttributeKeySigner = "signer"
|
||||||
AttributeKeySocket = "socket"
|
AttributeKeySocket = "socket"
|
||||||
AttributeKeyPublicKeyG1 = "pubkey_g1"
|
AttributeKeyPublicKeyG1 = "pubkey_g1"
|
||||||
AttributeKeyPublicKeyG2 = "pubkey_g2"
|
AttributeKeyPublicKeyG2 = "pubkey_g2"
|
||||||
|
AttributeKeyBlockHeight = "block_height"
|
||||||
|
AttributeKeyTokensPerVote = "tokens_per_vote"
|
||||||
|
AttributeKeyMaxVotesPerSigner = "max_votes_per_signer"
|
||||||
|
AttributeKeyMaxQuorums = "max_quorums"
|
||||||
|
AttributeKeyEpochBlocks = "epoch_blocks"
|
||||||
|
AttributeKeyEncodedSlices = "encoded_slices"
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user