Skip to content

Commit

Permalink
feat: wrapper around staking msg server to create account during crea…
Browse files Browse the repository at this point in the history
…te-validator
  • Loading branch information
hacheigriega committed Dec 5, 2023
1 parent 4c4a4ab commit 0e8b4e9
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 9 deletions.
21 changes: 17 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/gogoproto/proto"
Expand Down Expand Up @@ -129,6 +128,7 @@ import (
"github.com/sedaprotocol/seda-chain/x/randomness/keeper"
randomnesskeeper "github.com/sedaprotocol/seda-chain/x/randomness/keeper"
randomnesstypes "github.com/sedaprotocol/seda-chain/x/randomness/types"
customstaking "github.com/sedaprotocol/seda-chain/x/staking"
wasmstorage "github.com/sedaprotocol/seda-chain/x/wasm-storage"
wasmstoragekeeper "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper"
wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types"
Expand Down Expand Up @@ -675,7 +675,7 @@ func NewApp(
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, nil),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, nil, app.interfaceRegistry),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, nil),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, nil),
customstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, nil),
upgrade.NewAppModule(app.UpgradeKeeper, app.AccountKeeper.AddressCodec()),
evidence.NewAppModule(app.EvidenceKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
Expand Down Expand Up @@ -867,10 +867,23 @@ func NewApp(

// Pseudorandomness beacon
app.SetPrepareProposal(
randomnesskeeper.PrepareProposalHandler(txConfig, app.RandomnessKeeper, app.AccountKeeper, app.StakingKeeper, nonceMempool),
randomnesskeeper.PrepareProposalHandler(
txConfig,
homePath,
cast.ToString(appOpts.Get("priv_validator_key_file")),
app.RandomnessKeeper,
app.AccountKeeper,
app.StakingKeeper,
nonceMempool,
),
)

app.SetProcessProposal(
randomnesskeeper.ProcessProposalHandler(txConfig, app.RandomnessKeeper, app.StakingKeeper),
randomnesskeeper.ProcessProposalHandler(
txConfig,
app.RandomnessKeeper,
app.StakingKeeper,
),
)

if loadLatest {
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/go-ethereum v1.13.4 h1:25HJnaWVg3q1O7Z62LaaI6S9wVq8QCw3K88g8wEzrcM=
github.com/ethereum/go-ethereum v1.13.4/go.mod h1:I0U5VewuuTzvBtVzKo7b3hJzDhXOUtn9mJW7SsIPB0Q=
github.com/ethereum/go-ethereum v1.13.5 h1:U6TCRciCqZRe4FPXmy1sMGxTfuk8P7u2UoinF3VbaFk=
github.com/ethereum/go-ethereum v1.13.5/go.mod h1:yMTu38GSuyxaYzQMViqNmQ1s3cE84abZexQmTgenWk0=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
Expand Down Expand Up @@ -1096,8 +1094,6 @@ github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71e
github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
github.com/sedaprotocol/vrf-go v0.0.0-20231128010622-13deb847d981 h1:YmuOnAwJZSBfBwKJrwisACb9jZ4/us8R6A06PxqbKmQ=
github.com/sedaprotocol/vrf-go v0.0.0-20231128010622-13deb847d981/go.mod h1:cub/hpbOATCymOnKPJVOhuExFhhspWaOJW2nr/yzWUs=
github.com/sedaprotocol/vrf-go v0.0.0-20231202231847-9ca3f58655e6 h1:GqAxxdvT0bteI0b0Sq3iPDMP6BGlymYjPHCOveK9KH4=
github.com/sedaprotocol/vrf-go v0.0.0-20231202231847-9ca3f58655e6/go.mod h1:cub/hpbOATCymOnKPJVOhuExFhhspWaOJW2nr/yzWUs=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
Expand Down
5 changes: 4 additions & 1 deletion x/randomness/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"os"
"path/filepath"

vrf "github.com/sedaprotocol/vrf-go"

Check failure on line 11 in x/randomness/keeper/abci.go

View workflow job for this annotation

GitHub Actions / tests

github.com/sedaprotocol/[email protected]: invalid version: git ls-remote -q origin in /home/runner/go/pkg/mod/cache/vcs/3e3eec219813a628eaea9c4e52c52e6bdcd967c706d32c1f35768464d6709f29: exit status 128:

Check failure on line 11 in x/randomness/keeper/abci.go

View workflow job for this annotation

GitHub Actions / tests

github.com/sedaprotocol/[email protected]: invalid version: git ls-remote -q origin in /home/runner/go/pkg/mod/cache/vcs/3e3eec219813a628eaea9c4e52c52e6bdcd967c706d32c1f35768464d6709f29: exit status 128:

Expand All @@ -26,6 +27,8 @@ import (

func PrepareProposalHandler(
txConfig client.TxConfig,
homePath string,
pvFile string,
keeper Keeper,
authKeeper types.AccountKeeper,
stakingKeeper types.StakingKeeper,
Expand All @@ -46,7 +49,7 @@ func PrepareProposalHandler(
alpha := append([]byte(prevSeed), timestamp...)

// prepare secret key
secretKey, err := readPrivKey("/Users/hykim/.seda-chain/config/priv_validator_key.json")
secretKey, err := readPrivKey(filepath.Join(homePath, pvFile))
if err != nil {
return nil, err
}
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions x/staking/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package staking

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

type AccountKeeper interface {
stakingtypes.AccountKeeper

NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
SetAccount(ctx context.Context, acc sdk.AccountI)
}
51 changes: 51 additions & 0 deletions x/staking/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package staking

import (
"github.com/CosmWasm/wasmd/x/wasm/exported"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

var (
_ module.AppModule = AppModule{}
)

// ----------------------------------------------------------------------------
// AppModule
// ----------------------------------------------------------------------------

// AppModule implements an application module for the staking module.
type AppModule struct {
staking.AppModule
stakingKeeper *stakingkeeper.Keeper
accountKeeper AccountKeeper
}

// NewAppModule creates a new AppModule object
func NewAppModule(
cdc codec.Codec,
keeper *keeper.Keeper,
ak AccountKeeper,
bk stakingtypes.BankKeeper,
ls exported.Subspace,

) AppModule {
am := staking.NewAppModule(cdc, keeper, ak, bk, ls)
return AppModule{
AppModule: am,
stakingKeeper: keeper,
accountKeeper: ak,
}
}

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
stakingtypes.RegisterMsgServer(cfg.MsgServer(), NewMsgServerImpl(am.stakingKeeper, am.accountKeeper))

querier := stakingkeeper.Querier{Keeper: am.stakingKeeper}
stakingtypes.RegisterQueryServer(cfg.QueryServer(), querier)
}
66 changes: 66 additions & 0 deletions x/staking/msg_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package staking

import (
"context"

errorsmod "cosmossdk.io/errors"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

var _ stakingtypes.MsgServer = msgServer{}

type msgServer struct {
stakingtypes.MsgServer
accountKeeper AccountKeeper
}

func NewMsgServerImpl(keeper *stakingkeeper.Keeper, accKeeper AccountKeeper) stakingtypes.MsgServer {
ms := &msgServer{
MsgServer: stakingkeeper.NewMsgServerImpl(keeper),
accountKeeper: accKeeper,
}
return ms
}

func (k msgServer) CreateValidator(ctx context.Context, msg *stakingtypes.MsgCreateValidator) (*stakingtypes.MsgCreateValidatorResponse, error) {
// create an account based on consensus key to send NewSeed txs when proposing blocks
pk, ok := msg.Pubkey.GetCachedValue().(cryptotypes.PubKey)
if !ok {
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidType, "Expecting cryptotypes.PubKey, got %T", pk)
}

addr := sdk.AccAddress(pk.Address().Bytes())
acc := k.accountKeeper.NewAccountWithAddress(ctx, addr)
k.accountKeeper.SetAccount(ctx, acc)

return k.MsgServer.CreateValidator(ctx, msg)
}

func (k msgServer) EditValidator(ctx context.Context, msg *stakingtypes.MsgEditValidator) (*stakingtypes.MsgEditValidatorResponse, error) {
return k.MsgServer.EditValidator(ctx, msg)
}

func (k msgServer) Delegate(ctx context.Context, msg *stakingtypes.MsgDelegate) (*stakingtypes.MsgDelegateResponse, error) {
return k.MsgServer.Delegate(ctx, msg)
}

func (k msgServer) BeginRedelegate(ctx context.Context, msg *stakingtypes.MsgBeginRedelegate) (*stakingtypes.MsgBeginRedelegateResponse, error) {
return k.MsgServer.BeginRedelegate(ctx, msg)
}

func (k msgServer) Undelegate(ctx context.Context, msg *stakingtypes.MsgUndelegate) (*stakingtypes.MsgUndelegateResponse, error) {
return k.MsgServer.Undelegate(ctx, msg)
}

func (k msgServer) CancelUnbondingDelegation(ctx context.Context, msg *stakingtypes.MsgCancelUnbondingDelegation) (*stakingtypes.MsgCancelUnbondingDelegationResponse, error) {
return k.MsgServer.CancelUnbondingDelegation(ctx, msg)
}

func (k msgServer) UpdateParams(ctx context.Context, msg *stakingtypes.MsgUpdateParams) (*stakingtypes.MsgUpdateParamsResponse, error) {
return k.MsgServer.UpdateParams(ctx, msg)
}

0 comments on commit 0e8b4e9

Please sign in to comment.