-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: require secp256k1 pubkey registration for unjail
- Loading branch information
1 parent
a3d0bba
commit 49d2cc9
Showing
7 changed files
with
156 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package slashing | ||
|
||
import ( | ||
addresscodec "cosmossdk.io/core/address" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
cdctypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/cosmos/cosmos-sdk/x/slashing" | ||
"github.com/cosmos/cosmos-sdk/x/slashing/exported" | ||
"github.com/cosmos/cosmos-sdk/x/slashing/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/slashing/types" | ||
) | ||
|
||
var ( | ||
_ module.AppModule = AppModule{} | ||
) | ||
|
||
// ---------------------------------------------------------------------------- | ||
// AppModule | ||
// ---------------------------------------------------------------------------- | ||
|
||
// AppModule implements an application module for the slashing module. | ||
type AppModule struct { | ||
slashing.AppModule | ||
|
||
keeper keeper.Keeper | ||
pubKeyKeeper PubKeyKeeper | ||
validatorAddressCodec addresscodec.Codec | ||
} | ||
|
||
// NewAppModule creates a new AppModule object. | ||
func NewAppModule( | ||
cdc codec.Codec, | ||
keeper keeper.Keeper, | ||
ak types.AccountKeeper, | ||
bk types.BankKeeper, | ||
sk types.StakingKeeper, | ||
ss exported.Subspace, | ||
registry cdctypes.InterfaceRegistry, | ||
pk PubKeyKeeper, | ||
valAddrCdc addresscodec.Codec, | ||
) AppModule { | ||
baseAppModule := slashing.NewAppModule(cdc, keeper, ak, bk, sk, ss, registry) | ||
return AppModule{ | ||
AppModule: baseAppModule, | ||
keeper: keeper, | ||
pubKeyKeeper: pk, | ||
validatorAddressCodec: valAddrCdc, | ||
} | ||
} | ||
|
||
// RegisterServices registers module services. | ||
func (am AppModule) RegisterServices(cfg module.Configurator) { | ||
sdkMsgServer := keeper.NewMsgServerImpl(am.keeper) | ||
msgServer := NewMsgServerImpl(sdkMsgServer, am.pubKeyKeeper, am.validatorAddressCodec) | ||
types.RegisterMsgServer(cfg.MsgServer(), msgServer) | ||
types.RegisterQueryServer(cfg.QueryServer(), am.keeper) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package slashing | ||
|
||
import ( | ||
"context" | ||
|
||
addresscodec "cosmossdk.io/core/address" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/slashing/types" | ||
"github.com/sedaprotocol/seda-chain/app/utils" | ||
) | ||
|
||
var _ types.MsgServer = msgServer{} | ||
|
||
type msgServer struct { | ||
types.MsgServer | ||
pubKeyKeeper PubKeyKeeper | ||
validatorAddressCodec addresscodec.Codec | ||
} | ||
|
||
type PubKeyKeeper interface { | ||
HasRegisteredKey(ctx context.Context, validatorAddr sdk.ValAddress, index utils.SEDAKeyIndex) (bool, error) | ||
} | ||
|
||
func NewMsgServerImpl(sdkMsgServer types.MsgServer, pubKeyKeeper PubKeyKeeper, valAddrCdc addresscodec.Codec) types.MsgServer { | ||
ms := &msgServer{ | ||
MsgServer: sdkMsgServer, | ||
pubKeyKeeper: pubKeyKeeper, | ||
validatorAddressCodec: valAddrCdc, | ||
} | ||
return ms | ||
} | ||
|
||
// Unjail overrides the default Unjail method to add an additional | ||
// check for registration of required public keys. | ||
func (m msgServer) Unjail(ctx context.Context, req *types.MsgUnjail) (*types.MsgUnjailResponse, error) { | ||
valAddr, err := m.validatorAddressCodec.StringToBytes(req.ValidatorAddr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
registered, err := m.pubKeyKeeper.HasRegisteredKey(ctx, valAddr, utils.SEDAKeyIndexSecp256k1) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !registered { | ||
return nil, sdkerrors.ErrInvalidRequest.Wrap("validator has not registered required SEDA keys") | ||
} | ||
|
||
return m.MsgServer.Unjail(ctx, req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters