meshsecurity

package
v0.0.0-...-b507993 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 16 Imported by: 3

README

Mesh-security

Cosmos module implementation

Integrate the mesh security module

Prerequisites

Projects that want to integrate the meshsecurity module onto their Cosmos SDK chain must enable the following modules:

Configuring and Adding Module

  1. Add the mesh security package to the go.mod and install it.

    require (
    ...
    github.com/osmosis-labs/mesh-security
    ...
    )
    
  2. Add the following modules to app.go

    import (
    ... 
        "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity"
        meshseckeeper "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/keeper"
        meshsectypes "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types"
    ...
    )
    
  3. In app.go: Register the AppModule for the mesh security module.

    ModuleBasics = module.NewBasicManager(
      ...
      meshsecurity.AppModuleBasic{},
      ...
    )
    
  4. In app.go: Add module account permissions:

    maccPerms = map[string][]string{
      ...
      meshsectypes.ModuleName: {authtypes.Minter, authtypes.Burner}
    }
    
  5. In app.go: Add mesh security keeper.

    type App struct {
      ...
      MeshSecKeeper *meshseckeeper.Keeper
      ...
    }
    
  6. In app.go: Add mesh security store key.

    keys := sdk.NewKVStoreKeys(
      ...
      meshsectypes.StoreKey,
      ...
    )
    
  7. In app.go: Instantiate mesh security keeper

    app.MeshSecKeeper = meshseckeeper.NewKeeper(
    	app.appCodec,
    	keys[meshsectypes.StoreKey],
    	memKeys[meshsectypes.MemStoreKey],
    	app.BankKeeper,
    	app.StakingKeeper,
    	&app.WasmKeeper, // ensure this is a pointer as we instantiate the keeper a bit later
    	authtypes.NewModuleAddress(govtypes.ModuleName).String(),
    )
    
  8. In app.go: Add the mesh security module to the app manager instantiation.

    app.mm = module.NewManager(
        ...
        meshsecurity.NewAppModule(appCodec, app.MeshSecKeeper),
        ...
    )
    
  9. In app.go: Add the module as the final element to the following:

  • SetOrderBeginBlockers
  • SetOrderEndBlockers
  • SetOrderInitGenesis
    // Add mesh security to begin blocker logic
    app.moduleManager.SetOrderBeginBlockers(
      ...
      meshsectypes.ModuleName,
      ...
    )
    
    // Add mesh security to end blocker logic
    app.moduleManager.SetOrderEndBlockers(
      ...
      meshsectypes.ModuleName,
      ...
    )
    
    // Add mesh security to init genesis logic
    app.moduleManager.SetOrderInitGenesis(
      ...
      meshsectypes.ModuleName,
      ...
    )
    
  1. In app.go: Add the mesh security staking decorator to the slashing module.
    app.SlashingKeeper = slashingkeeper.NewKeeper(
    	appCodec,
    	legacyAmino,
    	keys[slashingtypes.StoreKey],
    	// decorate the sdk keeper to capture all jail/ unjail events for MS
    	meshseckeeper.NewStakingDecorator(app.StakingKeeper, app.MeshSecKeeper),
    	authtypes.NewModuleAddress(govtypes.ModuleName).String(),
    )
    
  2. In app.go: Add the mesh security hooks to the staking module.
    app.StakingKeeper.SetHooks(
    	stakingtypes.NewMultiStakingHooks(
            ...
    		// register hook to capture valset updates
    		app.MeshSecKeeper.Hooks()
    	),
    )
    
  3. In app.go: Add the mesh security hooks to the evidence module.
    evidenceKeeper := evidencekeeper.NewKeeper(
    	...
    	// decorate the SlashingKeeper to capture the tombstone event
    	meshseckeeper.CaptureTombstoneDecorator(app.MeshSecKeeper, app.SlashingKeeper, app.StakingKeeper),
    )
    
  4. In app.go: Add the mesh security wasm message handler decorator to the wasm module.
    meshMessageHandler := wasmkeeper.WithMessageHandlerDecorator(func(nested wasmkeeper.Messenger) wasmkeeper.Messenger {
    	return wasmkeeper.NewMessageHandlerChain(
    		meshseckeeper.NewIntegrityHandler(app.MeshSecKeeper),
    		nested,
    		meshseckeeper.NewDefaultCustomMsgHandler(app.MeshSecKeeper),
    	)
    })
    wasmOpts = append(wasmOpts, meshMessageHandler,
    	// add support for the mesh-security queries
    	wasmkeeper.WithQueryHandlerDecorator(meshseckeeper.NewQueryDecorator(app.MeshSecKeeper, app.SlashingKeeper)),
    )
    

Documentation

Index

Constants

View Source
const ConsensusVersion = 1

ConsensusVersion defines the module's consensus version.

Variables

This section is empty.

Functions

func EndBlocker

func EndBlocker(ctx sdk.Context, k *keeper.Keeper, h TaskExecutionResponseHandler)

EndBlocker is called after every block

Types

type AppModule

type AppModule struct {
	AppModuleBasic
	// contains filtered or unexported fields
}

AppModule implements an application module interface

func NewAppModule

func NewAppModule(cdc codec.Codec, k *keeper.Keeper) *AppModule

NewAppModule constructor with defaults

func NewAppModuleX

NewAppModuleX extended constructor

func (AppModule) BeginBlock

func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock)

BeginBlock executed before every block

func (AppModule) ConsensusVersion

func (AppModule) ConsensusVersion() uint64

ConsensusVersion implements AppModule/ConsensusVersion.

func (AppModule) EndBlock

EndBlock executed after every block. It returns no validator updates.

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage

ExportGenesis returns the exported genesis state as raw bytes for the mesh-security

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate

InitGenesis performs genesis initialization for the mesh-security module. It returns no validator updates.

func (AppModule) IsAppModule

func (am AppModule) IsAppModule()

IsAppModule implements the appmodule.AppModule interface.

func (AppModule) Name

func (AppModule) Name() string

Name returns the module's name.

func (AppModule) QuerierRoute

func (AppModule) QuerierRoute() string

QuerierRoute returns the bank module's querier route name.

func (AppModule) RegisterInvariants

func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry)

RegisterInvariants registers the module's invariants.

func (AppModule) RegisterServices

func (am AppModule) RegisterServices(cfg module.Configurator)

RegisterServices registers module services.

func (*AppModule) SetAsyncTaskRspHandler

func (am *AppModule) SetAsyncTaskRspHandler(asyncTaskRspHandler TaskExecutionResponseHandler)

SetAsyncTaskRspHandler set custom handler

type AppModuleBasic

type AppModuleBasic struct{}

AppModuleBasic defines the basic application module used by the mesh-security module.

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage

DefaultGenesis returns default genesis state as raw bytes for the mesh-security module.

func (AppModuleBasic) GetQueryCmd

func (b AppModuleBasic) GetQueryCmd() *cobra.Command

GetQueryCmd returns no root query command for the mesh-security module.

func (AppModuleBasic) GetTxCmd

func (b AppModuleBasic) GetTxCmd() *cobra.Command

GetTxCmd returns the root tx command for the mesh-security module.

func (AppModuleBasic) Name

func (AppModuleBasic) Name() string

Name returns the meshsecurity module's name.

func (AppModuleBasic) RegisterGRPCGatewayRoutes

func (b AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, serveMux *runtime.ServeMux)

func (AppModuleBasic) RegisterInterfaces

func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry)

RegisterInterfaces implements InterfaceModule

func (AppModuleBasic) RegisterLegacyAminoCodec

func (b AppModuleBasic) RegisterLegacyAminoCodec(amino *codec.LegacyAmino)

func (AppModuleBasic) ValidateGenesis

func (b AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error

ValidateGenesis performs genesis state validation for the mesh-security module.

type TaskExecutionResponseHandler

type TaskExecutionResponseHandler interface {
	Handle(ctx sdk.Context, e keeper.ExecResult)
}

TaskExecutionResponseHandler is an extension point for custom implementations

type TaskExecutionResponseHandlerFn

type TaskExecutionResponseHandlerFn func(ctx sdk.Context, e keeper.ExecResult)

TaskExecutionResponseHandlerFn helper type that implements TaskExecutionResponseHandler

func DefaultExecutionResponseHandler

func DefaultExecutionResponseHandler() TaskExecutionResponseHandlerFn

DefaultExecutionResponseHandler default implementation that panics on reschedule errors but otherwise logs only TODO: revisit, is this a good default?

func PanicOnErrorExecutionResponseHandler

func PanicOnErrorExecutionResponseHandler() TaskExecutionResponseHandlerFn

PanicOnErrorExecutionResponseHandler is an alternative TaskExecutionResponseHandler implementation that always panics on errors

func (TaskExecutionResponseHandlerFn) Handle

Directories

Path Synopsis
client
cli
Package types is a reverse proxy.
Package types is a reverse proxy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL