diff --git a/app/app.go b/app/app.go index d0073057..22b78f2a 100644 --- a/app/app.go +++ b/app/app.go @@ -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" @@ -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" @@ -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), @@ -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 { diff --git a/go.sum b/go.sum index 9c3263df..e00c7027 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/x/randomness/keeper/abci.go b/x/randomness/keeper/abci.go index 2228b57d..356d1bfc 100644 --- a/x/randomness/keeper/abci.go +++ b/x/randomness/keeper/abci.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "fmt" "os" + "path/filepath" vrf "github.com/sedaprotocol/vrf-go" @@ -26,6 +27,8 @@ import ( func PrepareProposalHandler( txConfig client.TxConfig, + homePath string, + pvFile string, keeper Keeper, authKeeper types.AccountKeeper, stakingKeeper types.StakingKeeper, @@ -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 } diff --git a/x/randomness/types/expected_keeper.go b/x/randomness/types/expected_keepers.go similarity index 100% rename from x/randomness/types/expected_keeper.go rename to x/randomness/types/expected_keepers.go diff --git a/x/staking/expected_keepers.go b/x/staking/expected_keepers.go new file mode 100644 index 00000000..34dded8d --- /dev/null +++ b/x/staking/expected_keepers.go @@ -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) +} diff --git a/x/staking/module.go b/x/staking/module.go new file mode 100644 index 00000000..7a0c8847 --- /dev/null +++ b/x/staking/module.go @@ -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) +} diff --git a/x/staking/msg_server.go b/x/staking/msg_server.go new file mode 100644 index 00000000..ae8b2965 --- /dev/null +++ b/x/staking/msg_server.go @@ -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) +}