diff --git a/Makefile b/Makefile index 7f650f75..b69f16f5 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,9 @@ proto-gen: @cd modules/proto && \ go tool github.com/bufbuild/buf/cmd/buf generate @mv modules/github.com/rollkit/go-execution-abci/modules/rollkitmngr/types/** modules/rollkitmngr/types/ && \ - mv modules/github.com/rollkit/go-execution-abci/modules/rollkitmngr/module/* modules/rollkitmngr/module/ + mv modules/github.com/rollkit/go-execution-abci/modules/rollkitmngr/module/* modules/rollkitmngr/module/ && \ + mv modules/github.com/rollkit/go-execution-abci/modules/network/types/** modules/network/types/ && \ + mv modules/github.com/rollkit/go-execution-abci/modules/network/module/v1/* modules/network/module/v1 @rm -r modules/github.com -.PHONY: proto-gen \ No newline at end of file +.PHONY: proto-gen diff --git a/README.md b/README.md index 89914bf6..131acd86 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,11 @@ graph TD E[Mempool] <--> B F[RPC Server] --> B B --> G[Store] - + subgraph "Rollkit" A end - + subgraph "go-execution-abci" B D @@ -34,11 +34,11 @@ graph TD F G end - + subgraph "Application" C end - + style B fill:#f9f,stroke:#333,stroke-width:2px style A fill:#bbf,stroke:#333,stroke-width:1px style C fill:#bfb,stroke:#333,stroke-width:1px @@ -87,6 +87,8 @@ executor := adapter.NewABCIExecutor( logger, // Logger config, // CometBFT config appGenesis, // Application genesis + nil, // Metrics (optional) + // Optional: custom block publisher, metrics,... ) // Set up mempool for transaction handling @@ -110,26 +112,26 @@ sequenceDiagram participant Mempool participant Adapter participant ABCI App - + Client->>P2P Network: Submit Tx P2P Network->>Mempool: Gossip Tx Mempool->>Adapter: CheckTx Adapter->>ABCI App: CheckTx ABCI App-->>Adapter: Response - + Note over Adapter: Block Creation Time - + Adapter->>Adapter: GetTxs Adapter->>ABCI App: PrepareProposal ABCI App-->>Adapter: Txs - + Note over Adapter: Block Execution - + Adapter->>ABCI App: ProcessProposal ABCI App-->>Adapter: Accept/Reject Adapter->>ABCI App: FinalizeBlock ABCI App-->>Adapter: AppHash - + Adapter->>ABCI App: Commit ``` @@ -172,7 +174,7 @@ classDiagram +GetTxs() +SetFinal() } - + class Executor { <> +InitChain() @@ -180,7 +182,7 @@ classDiagram +GetTxs() +SetFinal() } - + class ABCI { <> +InitChain() @@ -189,18 +191,18 @@ classDiagram +FinalizeBlock() +Commit() } - + class Mempool { +CheckTx() +ReapMaxBytesMaxGas() } - + class Store { +Get() +Set() +Height() } - + Executor <|.. Adapter : implements Adapter o-- ABCI : uses Adapter o-- Mempool : uses diff --git a/go.mod b/go.mod index f749c349..042ce3d8 100644 --- a/go.mod +++ b/go.mod @@ -39,6 +39,7 @@ require ( golang.org/x/sync v0.15.0 google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 google.golang.org/grpc v1.73.0 + google.golang.org/protobuf v1.36.6 ) require ( @@ -336,7 +337,6 @@ require ( gonum.org/v1/gonum v0.15.1 // indirect google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a // indirect - google.golang.org/protobuf v1.36.6 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/modules/network/autocli.go b/modules/network/autocli.go new file mode 100644 index 00000000..27eefe8f --- /dev/null +++ b/modules/network/autocli.go @@ -0,0 +1,79 @@ +package network + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + + networkv1 "github.com/rollkit/go-execution-abci/modules/network/types" +) + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: networkv1.Query_serviceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Params", + Use: "params", + Short: "Query the current network parameters", + }, + { + RpcMethod: "AttestationBitmap", + Use: "attestation [height]", + Short: "Query the attestation bitmap for a specific height", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "height"}, + }, + }, + { + RpcMethod: "EpochInfo", + Use: "epoch [epoch-number]", + Short: "Query information about a specific epoch", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "epoch"}, + }, + }, + { + RpcMethod: "ValidatorIndex", + Use: "validator-index [address]", + Short: "Query the bitmap index for a validator", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "address"}, + }, + }, + { + RpcMethod: "SoftConfirmationStatus", + Use: "soft-confirmation [height]", + Short: "Query if a height is soft-confirmed", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "height"}, + }, + }, + }, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: networkv1.Msg_serviceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Attest", + Use: "attest [height] [vote-base64]", + Short: "Submit an attestation for a checkpoint height", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "height"}, + {ProtoField: "vote"}, + }, + }, + { + RpcMethod: "JoinAttesterSet", + Use: "join-attester", + Short: "Join the attester set as a validator", + }, + { + RpcMethod: "LeaveAttesterSet", + Use: "leave-attester", + Short: "Leave the attester set as a validator", + }, + }, + }, + } +} diff --git a/modules/network/client/cli/query.go b/modules/network/client/cli/query.go new file mode 100644 index 00000000..a866115e --- /dev/null +++ b/modules/network/client/cli/query.go @@ -0,0 +1,197 @@ +package cli + +import ( + "context" + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" + + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(queryRoute string) *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdQueryParams(), + CmdQueryAttestationBitmap(), + CmdQueryEpochInfo(), + CmdQueryValidatorIndex(), + CmdQuerySoftConfirmationStatus(), + ) + + return cmd +} + +// CmdQueryParams implements the params query command +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "Query the current network parameters", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// CmdQueryAttestationBitmap queries the attestation bitmap for a height +func CmdQueryAttestationBitmap() *cobra.Command { + cmd := &cobra.Command{ + Use: "attestation [height]", + Short: "Query the attestation bitmap for a specific height", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + height, err := strconv.ParseInt(args[0], 10, 64) + if err != nil { + return fmt.Errorf("invalid height: %w", err) + } + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.AttestationBitmap(context.Background(), &types.QueryAttestationBitmapRequest{ + Height: height, + }) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// CmdQueryEpochInfo queries information about an epoch +func CmdQueryEpochInfo() *cobra.Command { + cmd := &cobra.Command{ + Use: "epoch [epoch-number]", + Short: "Query information about a specific epoch", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + epoch, err := strconv.ParseUint(args[0], 10, 64) + if err != nil { + return fmt.Errorf("invalid epoch: %w", err) + } + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.EpochInfo(context.Background(), &types.QueryEpochInfoRequest{ + Epoch: epoch, + }) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// CmdQueryValidatorIndex queries the bitmap index for a validator +func CmdQueryValidatorIndex() *cobra.Command { + cmd := &cobra.Command{ + Use: "validator-index [address]", + Short: "Query the bitmap index for a validator", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.ValidatorIndex(context.Background(), &types.QueryValidatorIndexRequest{ + Address: args[0], + }) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +// CmdQuerySoftConfirmationStatus queries if a height is soft-confirmed +func CmdQuerySoftConfirmationStatus() *cobra.Command { + cmd := &cobra.Command{ + Use: "soft-confirmation [height]", + Short: "Query if a height is soft-confirmed", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + height, err := strconv.ParseInt(args[0], 10, 64) + if err != nil { + return fmt.Errorf("invalid height: %w", err) + } + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.SoftConfirmationStatus(context.Background(), &types.QuerySoftConfirmationStatusRequest{ + Height: height, + }) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/modules/network/client/cli/tx.go b/modules/network/client/cli/tx.go new file mode 100644 index 00000000..9bafb53f --- /dev/null +++ b/modules/network/client/cli/tx.go @@ -0,0 +1,126 @@ +package cli + +import ( + "fmt" + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/spf13/cobra" + + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + CmdAttest(), + CmdJoinAttesterSet(), + CmdLeaveAttesterSet(), + ) + + return cmd +} + +// CmdAttest returns a CLI command for creating a MsgAttest transaction +func CmdAttest() *cobra.Command { + cmd := &cobra.Command{ + Use: "attest [height] [vote-base64]", + Short: "Submit an attestation for a checkpoint height", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + height, err := strconv.ParseInt(args[0], 10, 64) + if err != nil { + return fmt.Errorf("invalid height: %w", err) + } + + vote := []byte(args[1]) + valAddress := sdk.ValAddress(clientCtx.GetFromAddress()).String() + msg := types.NewMsgAttest( + valAddress, + height, + vote, + ) + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +// CmdJoinAttesterSet returns a CLI command for creating a MsgJoinAttesterSet transaction +func CmdJoinAttesterSet() *cobra.Command { + cmd := &cobra.Command{ + Use: "join-attester", + Short: "Join the attester set as a validator", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + valAddress := sdk.ValAddress(clientCtx.GetFromAddress()).String() + msg := types.NewMsgJoinAttesterSet(valAddress) + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +// CmdLeaveAttesterSet returns a CLI command for creating a MsgLeaveAttesterSet transaction +func CmdLeaveAttesterSet() *cobra.Command { + cmd := &cobra.Command{ + Use: "leave-attester", + Short: "Leave the attester set as a validator", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + valAddress := sdk.ValAddress(clientCtx.GetFromAddress()).String() + msg := types.NewMsgLeaveAttesterSet(valAddress) + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/modules/network/depinject.go b/modules/network/depinject.go new file mode 100644 index 00000000..b0c99cd4 --- /dev/null +++ b/modules/network/depinject.go @@ -0,0 +1,70 @@ +package network + +import ( + "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/store" + "cosmossdk.io/depinject" + "cosmossdk.io/depinject/appconfig" + "github.com/cosmos/cosmos-sdk/codec" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/rollkit/go-execution-abci/modules/network/keeper" + modulev1 "github.com/rollkit/go-execution-abci/modules/network/module/v1" + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +var _ appmodule.AppModule = AppModule{} + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (am AppModule) IsOnePerModuleType() {} + +func init() { + appconfig.Register( + &modulev1.Module{}, + appconfig.Provide(ProvideModule), + ) +} + +type ModuleInputs struct { + depinject.In + + Config *modulev1.Module + Cdc codec.Codec + StoreService store.KVStoreService + StakingKeeper types.StakingKeeper + AccountKeeper types.AccountKeeper + BankKeeper types.BankKeeper + BlockSource types.BlockSource +} + +type ModuleOutputs struct { + depinject.Out + + NetworkKeeper keeper.Keeper + Module appmodule.AppModule +} + +func ProvideModule(in ModuleInputs) ModuleOutputs { + // default to governance authority if not provided + authority := authtypes.NewModuleAddress(govtypes.ModuleName) + if in.Config.Authority != "" { + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + } + + k := keeper.NewKeeper( + in.Cdc, + in.StoreService, + in.StakingKeeper, + in.AccountKeeper, + in.BankKeeper, + in.BlockSource, + authority.String(), + ) + m := NewAppModule( + in.Cdc, + k, + ) + + return ModuleOutputs{NetworkKeeper: k, Module: m} +} diff --git a/modules/network/genesis.go b/modules/network/genesis.go new file mode 100644 index 00000000..668aa1aa --- /dev/null +++ b/modules/network/genesis.go @@ -0,0 +1,104 @@ +package network + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/rollkit/go-execution-abci/modules/network/keeper" + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +// InitGenesis initializes the network module's state from a provided genesis state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) error { + // Set module params + if err := k.SetParams(ctx, genState.Params); err != nil { + return fmt.Errorf("set params: %s", err) + } + + // Set validator indices + for _, vi := range genState.ValidatorIndices { + if err := k.SetValidatorIndex(ctx, vi.Address, uint16(vi.Index), vi.Power); err != nil { + return err + } + // Also add to attester set + if err := k.SetAttesterSetMember(ctx, vi.Address); err != nil { + return err + } + } + + // Set attestation bitmaps + for _, ab := range genState.AttestationBitmaps { + if err := k.SetAttestationBitmap(ctx, ab.Height, ab.Bitmap); err != nil { + return err + } + // Store full attestation info using collections API + if err := k.StoredAttestationInfo.Set(ctx, ab.Height, ab); err != nil { + return err + } + + if ab.SoftConfirmed { + if err := setSoftConfirmed(ctx, k, ab.Height); err != nil { + return err + } + } + } + return nil +} + +// ExportGenesis returns the network module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + genesis := types.DefaultGenesisState() + genesis.Params = k.GetParams(ctx) + + // Export validator indices using collections API + var validatorIndices []types.ValidatorIndex + // Iterate through all validator indices + if err := k.ValidatorIndex.Walk(ctx, nil, func(addr string, index uint16) (bool, error) { + power, err := k.GetValidatorPower(ctx, index) + if err != nil { + return false, fmt.Errorf("get validator power: %w", err) + } + validatorIndices = append(validatorIndices, types.ValidatorIndex{ + Address: addr, + Index: uint32(index), + Power: power, + }) + return false, nil + }); err != nil { + panic(err) + } + genesis.ValidatorIndices = validatorIndices + + // Export attestation bitmaps using collections API + var attestationBitmaps []types.AttestationBitmap + // Iterate through all stored attestation info + if err := k.StoredAttestationInfo.Walk(ctx, nil, func(height int64, ab types.AttestationBitmap) (bool, error) { + attestationBitmaps = append(attestationBitmaps, ab) + return false, nil + }); err != nil { + panic(err) + } + genesis.AttestationBitmaps = attestationBitmaps + + return genesis +} + +// Helper function to set soft confirmed status +func setSoftConfirmed(ctx sdk.Context, k keeper.Keeper, height int64) error { + // Get the existing attestation bitmap + ab, err := k.StoredAttestationInfo.Get(ctx, height) + if err != nil { + // If there's no existing attestation bitmap, we can't set it as soft confirmed + return err + } + + // Set the SoftConfirmed field to true + ab.SoftConfirmed = true + + // Update the attestation bitmap in the collection + if err := k.StoredAttestationInfo.Set(ctx, height, ab); err != nil { + return err + } + return nil +} diff --git a/modules/network/keeper/abci.go b/modules/network/keeper/abci.go new file mode 100644 index 00000000..8fbd645a --- /dev/null +++ b/modules/network/keeper/abci.go @@ -0,0 +1,182 @@ +package keeper + +import ( + "crypto/sha256" + "encoding/base64" + "errors" + "fmt" + + // For error wrapping if needed + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +// BeginBlocker handles begin block logic for the network module +func (k Keeper) BeginBlocker(ctx sdk.Context) error { + params := k.GetParams(ctx) + + // Only process if sign mode is IBC_ONLY and we have outbound IBC packets + if params.SignMode == types.SignMode_SIGN_MODE_IBC_ONLY { + return errors.New("IBC only sign mode not yet implemented") + } + return nil +} + +// EndBlocker handles end block logic for the network module +func (k Keeper) EndBlocker(ctx sdk.Context) error { + height := ctx.BlockHeight() + params := k.GetParams(ctx) + + // Handle checkpoint heights + if k.IsCheckpointHeight(ctx, height) { + if err := k.processCheckpoint(ctx, height); err != nil { + return fmt.Errorf("processing checkpoint at height %d: %w", height, err) + } + } + + // Handle epoch end + epoch := k.GetCurrentEpoch(ctx) + nextHeight := height + 1 + nextEpoch := uint64(nextHeight) / params.EpochLength + + if epoch != nextEpoch { + if err := k.processEpochEnd(ctx, epoch); err != nil { + return fmt.Errorf("processing epoch end %d: %w", epoch, err) + } + } + return nil +} + +// processCheckpoint handles checkpoint processing +func (k Keeper) processCheckpoint(ctx sdk.Context, height int64) error { + bitmapBytes, _ := k.GetAttestationBitmap(ctx, height) + if bitmapBytes == nil { + return nil + } + + votedPower, err := k.CalculateVotedPower(ctx, bitmapBytes) + if err != nil { + return err + } + totalPower, err := k.GetTotalPower(ctx) + if err != nil { + return err + } + + validatorHash := sha256.Sum256(bitmapBytes) + + commitHash := sha256.Sum256([]byte("placeholder")) + + softConfirmed, err := k.CheckQuorum(ctx, votedPower, totalPower) + if err != nil { + return err + } + + attestationInfoToStore := types.AttestationBitmap{ + Height: height, + Bitmap: bitmapBytes, + VotedPower: votedPower, + TotalPower: totalPower, + SoftConfirmed: softConfirmed, + } + + if err := k.StoredAttestationInfo.Set(ctx, height, attestationInfoToStore); err != nil { + return fmt.Errorf("storing attestation info at height %d: %w", height, err) + } + + // Emit hashes + k.emitCheckpointHashes(ctx, height, validatorHash[:], commitHash[:], softConfirmed) + return nil +} + +func (k Keeper) processEpochEnd(ctx sdk.Context, epoch uint64) error { + params := k.GetParams(ctx) + epochBitmap := k.GetEpochBitmap(ctx, epoch) + + if epochBitmap != nil { + validators, err := k.stakingKeeper.GetLastValidators(ctx) + if err != nil { + return fmt.Errorf("getting last validators: %w", err) + } + totalBondedValidators := 0 + for _, v := range validators { + if v.IsBonded() { + totalBondedValidators++ + } + } + + if totalBondedValidators > 0 { + participated := k.bitmapHelper.PopCount(epochBitmap) + minParticipation, err := math.LegacyNewDecFromStr(params.MinParticipation) + if err != nil { + return fmt.Errorf("parsing MinParticipation parameter: %w", err) + } + participationRate := math.LegacyNewDec(int64(participated)).QuoInt64(int64(totalBondedValidators)) + if participationRate.LT(minParticipation) { + k.ejectLowParticipants(ctx, epochBitmap) + } + } + } + + if !params.EmergencyMode { + epochStartHeight := int64(epoch * params.EpochLength) + checkpointsInEpoch := 0 + softConfirmedCheckpoints := 0 + + for h := epochStartHeight; h < epochStartHeight+int64(params.EpochLength); h++ { + if h > ctx.BlockHeight() { + break + } + if k.IsCheckpointHeight(ctx, h) { + checkpointsInEpoch++ + if q, err := k.IsSoftConfirmed(ctx, h); q && err == nil { + softConfirmedCheckpoints++ + } + } + } + + if checkpointsInEpoch > 0 && softConfirmedCheckpoints == 0 { + // todo (Alex): should we really fail? + //return fmt.Errorf("no checkpoints achieved quorum in epoch: %d", epoch) + k.Logger(ctx).Info("No checkpoints achieved quorum in epoch", "epoch", epoch) + } + } + + // todo (Alex): find a way to prune only bitmaps that are not used anymore + //if err := k.PruneOldBitmaps(ctx, epoch); err != nil { + // return fmt.Errorf("pruning old data at epoch %d: %w", epoch, err) + //} + + if err := k.BuildValidatorIndexMap(ctx); err != nil { + return fmt.Errorf("rebuilding validator index map at epoch %d: %w", epoch, err) + } + return nil +} + +// ejectLowParticipants ejects validators with low participation +func (k Keeper) ejectLowParticipants(ctx sdk.Context, epochBitmap []byte) { + // TODO: Implement validator ejection logic + k.Logger(ctx).Info("Low participation detected, ejection logic not yet implemented") +} + +// emitCheckpointHashes emits checkpoint hashes +func (k Keeper) emitCheckpointHashes(ctx sdk.Context, height int64, validatorHash, commitHash []byte, softConfirmed bool) { + var softConfirmedSt string + + if softConfirmed { + softConfirmedSt = "true" + } else { + softConfirmedSt = "false" + } + ctx.EventManager().EmitEvent( + sdk.NewEvent( + "checkpoint", + sdk.NewAttribute("height", math.NewInt(height).String()), + sdk.NewAttribute("validator_hash", base64.StdEncoding.EncodeToString(validatorHash)), + sdk.NewAttribute("commit_hash", base64.StdEncoding.EncodeToString(commitHash)), + sdk.NewAttribute("soft_confirmed", softConfirmedSt), + ), + ) +} diff --git a/modules/network/keeper/bitmap.go b/modules/network/keeper/bitmap.go new file mode 100644 index 00000000..5e4a1c36 --- /dev/null +++ b/modules/network/keeper/bitmap.go @@ -0,0 +1,98 @@ +package keeper + +import ( + "math/bits" +) + +// BitmapHelper provides utility functions for bitmap operations +type BitmapHelper struct{} + +// NewBitmapHelper creates a new bitmap helper +func NewBitmapHelper() *BitmapHelper { + return &BitmapHelper{} +} + +// NewBitmap creates a new bitmap for n validators +func (bh *BitmapHelper) NewBitmap(n int) []byte { + size := (n + 7) / 8 + return make([]byte, size) +} + +// SetBit sets the bit at index to 1 +func (bh *BitmapHelper) SetBit(bitmap []byte, index int) { + if index < 0 || index >= len(bitmap)*8 { + return + } + byteIndex := index / 8 + bitIndex := uint(index % 8) + bitmap[byteIndex] |= 1 << bitIndex +} + +// IsSet checks if the bit at index is set +func (bh *BitmapHelper) IsSet(bitmap []byte, index int) bool { + if index < 0 || index >= len(bitmap)*8 { + return false + } + byteIndex := index / 8 + bitIndex := uint(index % 8) + return (bitmap[byteIndex] & (1 << bitIndex)) != 0 +} + +// PopCount returns the number of set bits +func (bh *BitmapHelper) PopCount(bitmap []byte) int { + count := 0 + for _, b := range bitmap { + count += bits.OnesCount8(b) + } + return count +} + +// OR performs bitwise OR of two bitmaps +func (bh *BitmapHelper) OR(dst, src []byte) { + minLen := len(dst) + if len(src) < minLen { + minLen = len(src) + } + for i := 0; i < minLen; i++ { + dst[i] |= src[i] + } +} + +// AND performs bitwise AND of two bitmaps +func (bh *BitmapHelper) AND(dst, src []byte) { + minLen := len(dst) + if len(src) < minLen { + minLen = len(src) + } + for i := 0; i < minLen; i++ { + dst[i] &= src[i] + } +} + +// Copy creates a copy of the bitmap +func (bh *BitmapHelper) Copy(bitmap []byte) []byte { + if bitmap == nil { + return nil + } + cp := make([]byte, len(bitmap)) + copy(cp, bitmap) + return cp +} + +// Clear sets all bits to 0 +func (bh *BitmapHelper) Clear(bitmap []byte) { + for i := range bitmap { + bitmap[i] = 0 + } +} + +// CountInRange counts set bits in a range [start, end) +func (bh *BitmapHelper) CountInRange(bitmap []byte, start, end int) int { + count := 0 + for i := start; i < end && i < len(bitmap)*8; i++ { + if bh.IsSet(bitmap, i) { + count++ + } + } + return count +} diff --git a/modules/network/keeper/grpc_query.go b/modules/network/keeper/grpc_query.go new file mode 100644 index 00000000..aade9a21 --- /dev/null +++ b/modules/network/keeper/grpc_query.go @@ -0,0 +1,187 @@ +package keeper + +import ( + "context" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +// queryServer is a wrapper around the network module's keeper providing gRPC query +// functionalities. +type queryServer struct { + keeper Keeper +} + +// NewQueryServer creates a new gRPC query server. +func NewQueryServer(k Keeper) types.QueryServer { + return &queryServer{keeper: k} +} + +var _ types.QueryServer = (*queryServer)(nil) + +// Params queries the module parameters +func (q *queryServer) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + return &types.QueryParamsResponse{Params: q.keeper.GetParams(ctx)}, nil +} + +// AttestationBitmap queries the attestation bitmap for a specific height +func (q *queryServer) AttestationBitmap(c context.Context, req *types.QueryAttestationBitmapRequest) (*types.QueryAttestationBitmapResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(c) + + bitmapBytes, _ := q.keeper.GetAttestationBitmap(ctx, req.Height) + if bitmapBytes == nil { + return nil, status.Error(codes.NotFound, "attestation bitmap not found for height") + } + + // Reconstruct attestation info using keeper methods + votedPower, err := q.keeper.CalculateVotedPower(ctx, bitmapBytes) + if err != nil { + return nil, err + } + totalPower, err := q.keeper.GetTotalPower(ctx) + if err != nil { + return nil, err + } + + // Assuming IsSoftConfirmed is a method on the Keeper + // If not, you might need to add it or compute it here using keeper.CheckQuorum + softConfirmed, err := q.keeper.IsSoftConfirmed(ctx, req.Height) + if err != nil { + return nil, err + } + + return &types.QueryAttestationBitmapResponse{ + Bitmap: &types.AttestationBitmap{ + Height: req.Height, + Bitmap: bitmapBytes, + VotedPower: votedPower, + TotalPower: totalPower, + SoftConfirmed: softConfirmed, + }, + }, nil +} + +// EpochInfo queries information about a specific epoch +func (q *queryServer) EpochInfo(c context.Context, req *types.QueryEpochInfoRequest) (*types.QueryEpochInfoResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(c) + params := q.keeper.GetParams(ctx) + + startHeight := int64(req.Epoch * params.EpochLength) + endHeight := int64((req.Epoch+1)*params.EpochLength - 1) + + epochBitmap := q.keeper.GetEpochBitmap(ctx, req.Epoch) + if epochBitmap == nil { + // Return info even if bitmap is not present, as per original logic + return &types.QueryEpochInfoResponse{ + Epoch: req.Epoch, + StartHeight: startHeight, + EndHeight: endHeight, + ParticipationBitmap: []byte{}, + ActiveValidators: 0, // Consider calculating active validators even if bitmap is nil + ParticipatingValidators: 0, + }, nil + } + + validators, err := q.keeper.stakingKeeper.GetLastValidators(ctx) + if err != nil { + return nil, err + } + activeValidators := uint64(0) + for _, v := range validators { + if v.IsBonded() { + activeValidators++ + } + } + + participatingValidators := uint64(q.keeper.bitmapHelper.PopCount(epochBitmap)) + + return &types.QueryEpochInfoResponse{ + Epoch: req.Epoch, + StartHeight: startHeight, + EndHeight: endHeight, + ParticipationBitmap: epochBitmap, + ActiveValidators: activeValidators, // TODO (Alex): we need the historic validator set instead + ParticipatingValidators: participatingValidators, + }, nil +} + +// ValidatorIndex queries the bitmap index for a validator +func (q *queryServer) ValidatorIndex(c context.Context, req *types.QueryValidatorIndexRequest) (*types.QueryValidatorIndexResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(c) + // TODO (Alex): what is the use-case for this? The valset may change every epoch. + // A request height and historic data could be useful with EpochInfo bitmap + index, found := q.keeper.GetValidatorIndex(ctx, req.Address) + if !found { + return nil, status.Error(codes.NotFound, "validator index not found") + } + + power, err := q.keeper.GetValidatorPower(ctx, index) + if err != nil { + return nil, fmt.Errorf("get validator power: %w", err) + } + + return &types.QueryValidatorIndexResponse{ + Index: &types.ValidatorIndex{ + Address: req.Address, + Index: uint32(index), + Power: power, + }, + }, nil +} + +// SoftConfirmationStatus queries if a height is soft-confirmed +func (q *queryServer) SoftConfirmationStatus(c context.Context, req *types.QuerySoftConfirmationStatusRequest) (*types.QuerySoftConfirmationStatusResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(c) + isSoftConfirmed, err := q.keeper.IsSoftConfirmed(ctx, req.Height) + if err != nil { + return nil, err + } + bitmap, err := q.keeper.GetAttestationBitmap(ctx, req.Height) + if err != nil { + return nil, err + } + totalPower, err := q.keeper.GetTotalPower(ctx) + if err != nil { + return nil, err + } + + var votedPower uint64 + if bitmap != nil { + if votedPower, err = q.keeper.CalculateVotedPower(ctx, bitmap); err != nil { + return nil, err + } + } + + return &types.QuerySoftConfirmationStatusResponse{ + IsSoftConfirmed: isSoftConfirmed, + VotedPower: votedPower, + TotalPower: totalPower, + QuorumFraction: q.keeper.GetParams(ctx).QuorumFraction, + }, nil +} diff --git a/modules/network/keeper/keeper.go b/modules/network/keeper/keeper.go new file mode 100644 index 00000000..78b46eff --- /dev/null +++ b/modules/network/keeper/keeper.go @@ -0,0 +1,375 @@ +package keeper + +import ( + "fmt" + "time" + + "cosmossdk.io/collections" + "cosmossdk.io/core/store" + "cosmossdk.io/log" + "cosmossdk.io/math" + cmbytes "github.com/cometbft/cometbft/libs/bytes" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + cmttypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +// Keeper of the network store +type Keeper struct { + cdc codec.BinaryCodec + stakingKeeper types.StakingKeeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + authority string + bitmapHelper *BitmapHelper + blockSource types.BlockSource + + // Collections for state management + ValidatorIndex collections.Map[string, uint16] + ValidatorPower collections.Map[uint16, uint64] + + //AttestationBitmap tracks attestations for a block + AttestationBitmap collections.Map[int64, []byte] + // EpochBitmap track tracks participation over a range of epochs + EpochBitmap collections.Map[uint64, []byte] + AttesterSet collections.KeySet[string] + CommitSignatures collections.Map[collections.Pair[int64, string], cmtproto.CommitSig] + StoredAttestationInfo collections.Map[int64, types.AttestationBitmap] + Params collections.Item[types.Params] +} + +// NewKeeper creates a new network Keeper instance +func NewKeeper( + cdc codec.BinaryCodec, + storeService store.KVStoreService, // Changed from sdk.StoreKey + sk types.StakingKeeper, + ak types.AccountKeeper, + bk types.BankKeeper, + blockSource types.BlockSource, + authority string, +) Keeper { + + sb := collections.NewSchemaBuilder(storeService) + keeper := Keeper{ + cdc: cdc, + stakingKeeper: sk, + accountKeeper: ak, + bankKeeper: bk, + authority: authority, + bitmapHelper: NewBitmapHelper(), + blockSource: blockSource, + + ValidatorIndex: collections.NewMap(sb, types.ValidatorIndexPrefix, "validator_index", collections.StringKey, collections.Uint16Value), + ValidatorPower: collections.NewMap(sb, types.ValidatorPowerPrefix, "validator_power", collections.Uint16Key, collections.Uint64Value), + AttestationBitmap: collections.NewMap(sb, types.AttestationBitmapPrefix, "attestation_bitmap", collections.Int64Key, collections.BytesValue), + EpochBitmap: collections.NewMap(sb, types.EpochBitmapPrefix, "epoch_bitmap", collections.Uint64Key, collections.BytesValue), + AttesterSet: collections.NewKeySet(sb, types.AttesterSetPrefix, "attester_set", collections.StringKey), + CommitSignatures: collections.NewMap(sb, types.CommitPrefix, "commits", collections.PairKeyCodec(collections.Int64Key, collections.StringKey), codec.CollValue[cmtproto.CommitSig](cdc)), + StoredAttestationInfo: collections.NewMap(sb, types.StoredAttestationInfoPrefix, "stored_attestation_info", collections.Int64Key, codec.CollValue[types.AttestationBitmap](cdc)), // Initialize new collection + Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + } + + // The schema is built implicitly when the first collection is created or can be explicitly built. + // schema, err := sb.Build() + // if err != nil { + // panic(err) + // } + // keeper.schema = schema + + return keeper +} + +// GetAuthority returns the module authority +func (k Keeper) GetAuthority() string { + return k.authority +} + +// Logger returns a module-specific logger +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", "network") +} + +// GetParams get all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + p, _ := k.Params.Get(ctx) + return p +} + +// SetParams set the params +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + return k.Params.Set(ctx, params) +} + +// SetValidatorIndex stores the validator index mapping and power +func (k Keeper) SetValidatorIndex(ctx sdk.Context, addr string, index uint16, power uint64) error { + if err := k.ValidatorIndex.Set(ctx, addr, index); err != nil { + return err + } + return k.ValidatorPower.Set(ctx, index, power) +} + +// GetValidatorIndex retrieves the validator index +func (k Keeper) GetValidatorIndex(ctx sdk.Context, addr string) (uint16, bool) { + index, err := k.ValidatorIndex.Get(ctx, addr) + if err != nil { + // For 'not found', collections.ErrNotFound can be checked specifically if needed. + return 0, false + } + return index, true +} + +// GetValidatorPower retrieves the validator power by index +func (k Keeper) GetValidatorPower(ctx sdk.Context, index uint16) (uint64, error) { + power, err := k.ValidatorPower.Get(ctx, index) + return power, err +} + +// SetAttestationBitmap stores the attestation bitmap for a height +func (k Keeper) SetAttestationBitmap(ctx sdk.Context, height int64, bitmap []byte) error { + return k.AttestationBitmap.Set(ctx, height, bitmap) +} + +// GetAttestationBitmap retrieves the attestation bitmap for a height +func (k Keeper) GetAttestationBitmap(ctx sdk.Context, height int64) ([]byte, error) { + bitmap, err := k.AttestationBitmap.Get(ctx, height) + return bitmap, err +} + +// SetEpochBitmap stores the epoch participation bitmap +func (k Keeper) SetEpochBitmap(ctx sdk.Context, epoch uint64, bitmap []byte) error { + return k.EpochBitmap.Set(ctx, epoch, bitmap) +} + +// GetEpochBitmap retrieves the epoch participation bitmap +func (k Keeper) GetEpochBitmap(ctx sdk.Context, epoch uint64) []byte { + bitmap, err := k.EpochBitmap.Get(ctx, epoch) + if err != nil { + // Consider logging err or returning (nil, error) + return nil + } + return bitmap +} + +// IsInAttesterSet checks if a validator is in the attester set +func (k Keeper) IsInAttesterSet(ctx sdk.Context, addr string) (bool, error) { + has, err := k.AttesterSet.Has(ctx, addr) + return has, err +} + +// SetAttesterSetMember adds a validator to the attester set +func (k Keeper) SetAttesterSetMember(ctx sdk.Context, addr string) error { + return k.AttesterSet.Set(ctx, addr) +} + +// RemoveAttesterSetMember removes a validator from the attester set +func (k Keeper) RemoveAttesterSetMember(ctx sdk.Context, addr string) error { + return k.AttesterSet.Remove(ctx, addr) +} + +// BuildValidatorIndexMap rebuilds the validator index mapping +func (k Keeper) BuildValidatorIndexMap(ctx sdk.Context) error { + validators, err := k.stakingKeeper.GetAllValidators(ctx) + if err != nil { + return err + } + + // Clear existing indices and powers + // The `nil` range clears all entries in the collection. + if err := k.ValidatorIndex.Clear(ctx, nil); err != nil { + k.Logger(ctx).Error("failed to clear validator index", "error", err) + return err + } + if err := k.ValidatorPower.Clear(ctx, nil); err != nil { + k.Logger(ctx).Error("failed to clear validator power", "error", err) + return err + } + + // Build new indices for bonded validators + index := uint16(0) + for _, val := range validators { + if val.IsBonded() { + power := uint64(val.GetConsensusPower(sdk.DefaultPowerReduction)) + if err := k.SetValidatorIndex(ctx, val.OperatorAddress, index, power); err != nil { + // Consider how to handle partial failures; potentially log and continue or return error. + k.Logger(ctx).Error("failed to set validator index during build", "validator", val.OperatorAddress, "error", err) + return err + } + index++ + } + } + return nil +} + +// GetCurrentEpoch returns the current epoch number +func (k Keeper) GetCurrentEpoch(ctx sdk.Context) uint64 { + return k.GetEpochForHeight(ctx, ctx.BlockHeight()) +} + +func (k Keeper) GetEpochForHeight(ctx sdk.Context, height int64) uint64 { + params := k.GetParams(ctx) + return uint64(height) / params.EpochLength +} + +// IsCheckpointHeight checks if a height is a checkpoint +func (k Keeper) IsCheckpointHeight(ctx sdk.Context, height int64) bool { + p, err := k.Params.Get(ctx) + if err != nil { + return false + } + params := p + return uint64(height)%params.EpochLength == 0 +} + +// CalculateVotedPower calculates the total voted power from a bitmap +func (k Keeper) CalculateVotedPower(ctx sdk.Context, bitmap []byte) (uint64, error) { + var votedPower uint64 + for i := 0; i < len(bitmap)*8; i++ { + if k.bitmapHelper.IsSet(bitmap, i) { + power, err := k.GetValidatorPower(ctx, uint16(i)) + if err != nil { + return 0, fmt.Errorf("get validator power: %w", err) + } + + votedPower += power + } + } + return votedPower, nil +} + +// GetTotalPower returns the total staking power +func (k Keeper) GetTotalPower(ctx sdk.Context) (uint64, error) { + n, err := k.stakingKeeper.GetLastTotalPower(ctx) + if err != nil { + return 0, err + } + return n.Uint64(), nil +} + +// CheckQuorum checks if the voted power meets quorum +func (k Keeper) CheckQuorum(ctx sdk.Context, votedPower, totalPower uint64) (bool, error) { + params := k.GetParams(ctx) + quorumFrac, err := math.LegacyNewDecFromStr(params.QuorumFraction) + if err != nil { + return false, fmt.Errorf("invalid quorum fraction: %w", err) + } + + requiredPower := math.LegacyNewDec(int64(totalPower)).Mul(quorumFrac).TruncateInt().Uint64() + return votedPower >= requiredPower, nil +} + +// IsSoftConfirmed checks if a block at a given height is soft-confirmed +// based on the attestation bitmap and quorum rules. +func (k Keeper) IsSoftConfirmed(ctx sdk.Context, height int64) (bool, error) { + bitmap, err := k.GetAttestationBitmap(ctx, height) + if err != nil { + return false, err + } + if bitmap == nil { + return false, nil // No bitmap, so cannot be soft-confirmed + } + votedPower, err := k.CalculateVotedPower(ctx, bitmap) + if err != nil { + return false, err + } + totalPower, err := k.GetTotalPower(ctx) // Assuming this gets the relevant total power for the height + if err != nil { + return false, err + } + + return k.CheckQuorum(ctx, votedPower, totalPower) +} + +// PruneOldBitmaps removes bitmaps older than PruneAfter epochs +func (k Keeper) PruneOldBitmaps(ctx sdk.Context, currentEpoch uint64) error { + params := k.GetParams(ctx) + if params.PruneAfter == 0 { // Avoid pruning if PruneAfter is zero or not set + return nil + } + if currentEpoch <= params.PruneAfter { + return nil + } + + pruneBeforeEpoch := currentEpoch - params.PruneAfter + pruneHeight := int64(pruneBeforeEpoch * params.EpochLength) // Assuming EpochLength defines blocks per epoch + + // Prune attestation bitmaps (raw bitmaps) + attestationRange := new(collections.Range[int64]).StartInclusive(0).EndExclusive(pruneHeight) + if err := k.AttestationBitmap.Clear(ctx, attestationRange); err != nil { + return fmt.Errorf("clearing attestation bitmaps before height %d: %w", pruneHeight, err) + } + // Prune stored attestation info (full AttestationBitmap objects) + storedAttestationInfoRange := new(collections.Range[int64]).StartInclusive(0).EndExclusive(pruneHeight) + if err := k.StoredAttestationInfo.Clear(ctx, storedAttestationInfoRange); err != nil { + return fmt.Errorf("clearing stored attestation info before height %d: %w", pruneHeight, err) + } + + // Prune epoch bitmaps + epochRange := new(collections.Range[uint64]).StartInclusive(0).EndExclusive(pruneBeforeEpoch) + if err := k.EpochBitmap.Clear(ctx, epochRange); err != nil { + return fmt.Errorf("clearing epoch bitmaps before epoch %d: %w", pruneBeforeEpoch, err) + } + + // TODO: Consider pruning signatures associated with pruned heights. + // This would involve iterating k.CommitsByHeight and removing entries where height < pruneHeight. + + k.Logger(ctx).Info("Pruned old bitmaps and attestation info", "prunedBeforeEpoch", pruneBeforeEpoch, "prunedBeforeHeight", pruneHeight) + return nil +} + +// SetSignature stores the vote signature for a given height and validator +func (k Keeper) SetSignature(ctx sdk.Context, height int64, validatorAddr string, consAddr []byte, timestamp time.Time, signature []byte) error { + cmtSig := cmtproto.CommitSig{ + BlockIdFlag: cmtproto.BlockIDFlagCommit, + ValidatorAddress: consAddr, + Timestamp: timestamp, + Signature: signature, + } + return k.CommitSignatures.Set(ctx, collections.Join(height, validatorAddr), cmtSig) +} + +// GetSignature retrieves the vote signature for a given height and validator +func (k Keeper) GetSignature(ctx sdk.Context, height int64, validatorAddr string) (cmtproto.CommitSig, error) { + rsp, err := k.CommitSignatures.Get(ctx, collections.Join(height, validatorAddr)) + return rsp, err +} + +// HasSignature checks if a signature exists for a given height and validator +func (k Keeper) HasSignature(ctx sdk.Context, height int64, validatorAddr string) (bool, error) { + return k.CommitSignatures.Has(ctx, collections.Join(height, validatorAddr)) +} + +func (k Keeper) GetCommits(ctx sdk.Context, height int64) (*cmttypes.Commit, error) { + header, data, err := k.blockSource.GetBlockData(ctx, uint64(height)) + if err != nil { + return nil, fmt.Errorf("failed to get block at height %d: %w", height, err) + } + _ = data + + commit := &cmttypes.Commit{ + Height: height, + Round: 0, + BlockID: cmttypes.BlockID{ + Hash: cmbytes.HexBytes(header.LastHeaderHash), + PartSetHeader: cmttypes.PartSetHeader{Total: 0, Hash: nil}, + }, + Signatures: make([]cmttypes.CommitSig, 0), + } + // add the signatures (unordered) // todo (Alex): do we need them ordered? + rng := collections.NewPrefixedPairRange[int64, string](height) + err = k.CommitSignatures.Walk(ctx, rng, func(key collections.Pair[int64, string], value cmtproto.CommitSig) (bool, error) { + var sig cmttypes.CommitSig + if err := sig.FromProto(value); err != nil { + return true, err + } + commit.Signatures = append(commit.Signatures, sig) + return false, nil + }) + if err != nil { + return nil, err + } + + return commit, nil +} diff --git a/modules/network/keeper/msg_server.go b/modules/network/keeper/msg_server.go new file mode 100644 index 00000000..647369bb --- /dev/null +++ b/modules/network/keeper/msg_server.go @@ -0,0 +1,276 @@ +package keeper + +import ( + "bytes" + "context" + "fmt" + + "cosmossdk.io/collections" + "cosmossdk.io/errors" + "cosmossdk.io/math" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + cmttypes "github.com/cometbft/cometbft/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/gogoproto/proto" + + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} + +// Attest handles MsgAttest +func (k msgServer) Attest(goCtx context.Context, msg *types.MsgAttest) (*types.MsgAttestResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if err := k.validateAttestation(ctx, msg); err != nil { + return nil, err + } + votedEpoch := k.GetEpochForHeight(ctx, msg.Height) + if k.GetCurrentEpoch(ctx) != votedEpoch+1 { // can vote only for last epoch + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "validator %s not voted for epoch %d", msg.Validator, votedEpoch) + } + + valIndexPos, found := k.GetValidatorIndex(ctx, msg.Validator) + if !found { + return nil, errors.Wrapf(sdkerrors.ErrNotFound, "validator index not found for %s", msg.Validator) + } + + if err := k.updateAttestationBitmap(ctx, msg, valIndexPos); err != nil { + return nil, errors.Wrap(err, "update attestation bitmap") + } + + vote, err := k.verifyVote(ctx, msg) + if err != nil { + return nil, err + } + + if err := k.SetSignature(ctx, msg.Height, msg.Validator, vote.ValidatorAddress, vote.Timestamp, vote.Signature); err != nil { + return nil, errors.Wrap(err, "store signature") + } + + if err := k.updateEpochBitmap(ctx, votedEpoch, valIndexPos); err != nil { + return nil, err + } + + // Emit event + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.TypeMsgAttest, + sdk.NewAttribute("validator", msg.Validator), + sdk.NewAttribute("height", math.NewInt(msg.Height).String()), + ), + ) + return &types.MsgAttestResponse{}, nil +} + +func (k msgServer) updateEpochBitmap(ctx sdk.Context, votedEpoch uint64, index uint16) error { + epochBitmap := k.GetEpochBitmap(ctx, votedEpoch) + if epochBitmap == nil { + validators, err := k.stakingKeeper.GetLastValidators(ctx) + if err != nil { + return err + } + numValidators := 0 + for _, v := range validators { + if v.IsBonded() { + numValidators++ + } + } + epochBitmap = k.bitmapHelper.NewBitmap(numValidators) + } + k.bitmapHelper.SetBit(epochBitmap, int(index)) + if err := k.SetEpochBitmap(ctx, votedEpoch, epochBitmap); err != nil { + return errors.Wrap(err, "set epoch bitmap") + } + return nil +} + +// validateAttestation validates the attestation request +func (k msgServer) validateAttestation(ctx sdk.Context, msg *types.MsgAttest) error { + if !k.IsCheckpointHeight(ctx, msg.Height) { + return errors.Wrapf(sdkerrors.ErrInvalidRequest, "height %d is not a checkpoint", msg.Height) + } + + has, err := k.IsInAttesterSet(ctx, msg.Validator) + if err != nil { + return errors.Wrapf(err, "in attester set") + } + if !has { + return errors.Wrapf(sdkerrors.ErrUnauthorized, "validator %s not in attester set", msg.Validator) + } + return nil +} + +// updateAttestationBitmap handles bitmap operations for attestation +func (k msgServer) updateAttestationBitmap(ctx sdk.Context, msg *types.MsgAttest, index uint16) error { + bitmap, err := k.GetAttestationBitmap(ctx, msg.Height) + if err != nil && !errors.IsOf(err, collections.ErrNotFound) { + return err + } + + if bitmap == nil { + validators, err := k.stakingKeeper.GetLastValidators(ctx) + if err != nil { + return err + } + numValidators := 0 + for _, v := range validators { + if v.IsBonded() { + numValidators++ + } + } + bitmap = k.bitmapHelper.NewBitmap(numValidators) + } + + if k.bitmapHelper.IsSet(bitmap, int(index)) { + return errors.Wrapf(sdkerrors.ErrInvalidRequest, "validator %s already attested for height %d", msg.Validator, msg.Height) + } + + k.bitmapHelper.SetBit(bitmap, int(index)) + + if err := k.SetAttestationBitmap(ctx, msg.Height, bitmap); err != nil { + return errors.Wrap(err, "set attestation bitmap") + } + return nil +} + +// verifyVote verifies the vote signature and block hash +func (k msgServer) verifyVote(ctx sdk.Context, msg *types.MsgAttest) (*cmtproto.Vote, error) { + var vote cmtproto.Vote + if err := proto.Unmarshal(msg.Vote, &vote); err != nil { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "unmarshal vote: %s", err) + } + + header, _, err := k.blockSource.GetBlockData(ctx, uint64(msg.Height)) + if err != nil { + return nil, errors.Wrapf(err, "block data for height %d", msg.Height) + } + if header == nil { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "block header not found for height %d", msg.Height) + } + + if !bytes.Equal(vote.BlockID.Hash, header.AppHash) { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "vote block ID hash does not match app hash for height %d", msg.Height) + } + + validator, err := k.stakingKeeper.GetValidator(ctx, vote.ValidatorAddress) + if err != nil { + return nil, errors.Wrapf(err, "get validator") + } + + pubKey, err := validator.ConsPubKey() + if err != nil { + return nil, errors.Wrapf(err, "pubkey") + } + + voteSignBytes := cmttypes.VoteSignBytes(header.ChainID(), &vote) + if !pubKey.VerifySignature(voteSignBytes, vote.Signature) { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid vote signature") + } + + return &vote, nil +} + +// JoinAttesterSet handles MsgJoinAttesterSet +func (k msgServer) JoinAttesterSet(goCtx context.Context, msg *types.MsgJoinAttesterSet) (*types.MsgJoinAttesterSetResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + valAddr, err := sdk.ValAddressFromBech32(msg.Validator) + if err != nil { + return nil, errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid validator address: %s", err) + } + + validator, err := k.stakingKeeper.GetValidator(ctx, valAddr) + if err != nil { + return nil, err + } + + if !validator.IsBonded() { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "validator must be bonded to join attester set") + } + has, err := k.IsInAttesterSet(ctx, msg.Validator) + if err != nil { + return nil, errors.Wrapf(err, "in attester set") + } + if has { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "validator already in attester set") + } + + // TODO (Alex): the valset should be updated at the end of an epoch only + if err := k.SetAttesterSetMember(ctx, msg.Validator); err != nil { + return nil, errors.Wrap(err, "set attester set member") + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.TypeMsgJoinAttesterSet, + sdk.NewAttribute("validator", msg.Validator), + ), + ) + k.Logger(ctx).Info("+++ joined attester set", "validator", msg.Validator) + return &types.MsgJoinAttesterSetResponse{}, nil +} + +// LeaveAttesterSet handles MsgLeaveAttesterSet +func (k msgServer) LeaveAttesterSet(goCtx context.Context, msg *types.MsgLeaveAttesterSet) (*types.MsgLeaveAttesterSetResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + has, err := k.IsInAttesterSet(ctx, msg.Validator) + if err != nil { + return nil, errors.Wrapf(err, "in attester set") + } + if !has { + return nil, errors.Wrapf(sdkerrors.ErrInvalidRequest, "validator not in attester set") + } + + // TODO (Alex): the valset should be updated at the end of an epoch only + if err := k.RemoveAttesterSetMember(ctx, msg.Validator); err != nil { + return nil, errors.Wrap(err, "remove attester set member") + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.TypeMsgLeaveAttesterSet, + sdk.NewAttribute("validator", msg.Validator), + ), + ) + + return &types.MsgLeaveAttesterSetResponse{}, nil +} + +// UpdateParams handles MsgUpdateParams +func (k msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if k.GetAuthority() != msg.Authority { + return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority) + } + + if err := msg.Params.Validate(); err != nil { + return nil, err + } + + if err := k.SetParams(ctx, msg.Params); err != nil { + return nil, fmt.Errorf("set params: %w", err) + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.TypeMsgUpdateParams, + sdk.NewAttribute("authority", msg.Authority), + ), + ) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/modules/network/keeper/msg_server_test.go b/modules/network/keeper/msg_server_test.go new file mode 100644 index 00000000..42c195d9 --- /dev/null +++ b/modules/network/keeper/msg_server_test.go @@ -0,0 +1,420 @@ +package keeper + +import ( + "context" + "crypto/sha256" + "maps" + "slices" + "strings" + "testing" + "time" + + "cosmossdk.io/collections" + "cosmossdk.io/log" + "cosmossdk.io/math" + storetypes "cosmossdk.io/store/types" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + cmttypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/testutil/integration" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/gogoproto/proto" + ds "github.com/ipfs/go-datastore" + kt "github.com/ipfs/go-datastore/keytransform" + "github.com/libp2p/go-libp2p/core/crypto" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + rollnode "github.com/rollkit/rollkit/node" + rstore "github.com/rollkit/rollkit/pkg/store" + rollkittypes "github.com/rollkit/rollkit/types" + + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +func TestJoinAttesterSet(t *testing.T) { + myValAddr := sdk.ValAddress("validator") + + type testCase struct { + setup func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper) + msg *types.MsgJoinAttesterSet + expErr error + expSet bool + } + + tests := map[string]testCase{ + "valid": { + setup: func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper) { + validator := stakingtypes.Validator{ + OperatorAddress: myValAddr.String(), + Status: stakingtypes.Bonded, + } + err := sk.SetValidator(ctx, validator) + require.NoError(t, err, "failed to set validator") + }, + msg: &types.MsgJoinAttesterSet{Validator: myValAddr.String()}, + expSet: true, + }, + "invalid_addr": { + setup: func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper) {}, + msg: &types.MsgJoinAttesterSet{Validator: "invalidAddr"}, + expErr: sdkerrors.ErrInvalidAddress, + }, + "val not exists": { + setup: func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper) {}, + msg: &types.MsgJoinAttesterSet{Validator: myValAddr.String()}, + expErr: sdkerrors.ErrNotFound, + }, + "val not bonded": { + setup: func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper) { + validator := stakingtypes.Validator{ + OperatorAddress: myValAddr.String(), + Status: stakingtypes.Unbonded, // Validator is not bonded + } + err := sk.SetValidator(ctx, validator) + require.NoError(t, err, "failed to set validator") + }, + msg: &types.MsgJoinAttesterSet{Validator: myValAddr.String()}, + expErr: sdkerrors.ErrInvalidRequest, + }, + "already set": { + setup: func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper) { + validator := stakingtypes.Validator{ + OperatorAddress: myValAddr.String(), + Status: stakingtypes.Bonded, + } + require.NoError(t, sk.SetValidator(ctx, validator)) + require.NoError(t, keeper.SetAttesterSetMember(ctx, myValAddr.String())) + }, + msg: &types.MsgJoinAttesterSet{Validator: myValAddr.String()}, + expErr: sdkerrors.ErrInvalidRequest, + expSet: true, + }, + //{ + // name: "failed to set attester set member", + // setup: func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper) { + // validatorAddr := sdk.ValAddress([]byte("validator5")) + // validator := stakingtypes.Validator{ + // OperatorAddress: validatorAddr.String(), + // Status: stakingtypes.Bonded, + // } + // err := sk.SetValidator(ctx, validator) + // require.NoError(t, err, "failed to set validator") + // keeper.forceError = true + // }, + // msg: &types.MsgJoinAttesterSet{ + // Validator: "validator5", + // }, + // expErr: sdkerrors.ErrInternal, + // expectResponse: false, + //}, + } + + for name, spec := range tests { + t.Run(name, func(t *testing.T) { + sk := NewMockStakingKeeper() + + cdc := moduletestutil.MakeTestEncodingConfig().Codec + + keys := storetypes.NewKVStoreKeys(types.StoreKey) + + logger := log.NewTestLogger(t) + cms := integration.CreateMultiStore(keys, logger) + authority := authtypes.NewModuleAddress("gov") + keeper := NewKeeper(cdc, runtime.NewKVStoreService(keys[types.StoreKey]), sk, nil, nil, nil, authority.String()) + server := msgServer{Keeper: keeper} + ctx := sdk.NewContext(cms, cmtproto.Header{ChainID: "test-chain", Time: time.Now().UTC(), Height: 10}, false, logger). + WithContext(t.Context()) + + spec.setup(t, ctx, &keeper, &sk) + + // when + rsp, err := server.JoinAttesterSet(ctx, spec.msg) + // then + if spec.expErr != nil { + require.ErrorIs(t, err, spec.expErr) + require.Nil(t, rsp) + exists, gotErr := keeper.AttesterSet.Has(ctx, spec.msg.Validator) + require.NoError(t, gotErr) + assert.Equal(t, exists, spec.expSet) + return + } + require.NoError(t, err) + require.NotNil(t, rsp) + exists, gotErr := keeper.AttesterSet.Has(ctx, spec.msg.Validator) + require.NoError(t, gotErr) + assert.True(t, exists) + }) + } +} + +func TestAttest(t *testing.T) { + var ( + myHash = sha256.Sum256([]byte("app_hash")) + myAppHash = myHash[:] + voteSigner = ed25519.GenPrivKey() + valAddrStr = sdk.ValAddress(voteSigner.PubKey().Address()).String() + validVote = VoteFixture(myAppHash, voteSigner) + validVoteBz = must(proto.Marshal(validVote)) + ) + + specs := map[string]struct { + setup func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper, bs rstore.Store) + msg *types.MsgAttest + expErr error + }{ + "valid attestation": { + setup: func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper, bs rstore.Store) { + validator, err := stakingtypes.NewValidator(valAddrStr, voteSigner.PubKey(), stakingtypes.Description{}) + validator.Status = stakingtypes.Bonded + require.NoError(t, err) + require.NoError(t, sk.SetValidator(ctx, validator)) + require.NoError(t, keeper.SetAttesterSetMember(ctx, valAddrStr)) + require.NoError(t, keeper.SetValidatorIndex(ctx, valAddrStr, 0, 100)) + sk.SetValidatorPubKey(valAddrStr, voteSigner.PubKey()) + + // Set up params for checkpoint height + params := types.DefaultParams() + params.EpochLength = 10 + require.NoError(t, keeper.SetParams(ctx, params)) + + signedHeader := HeaderFixture(voteSigner, myAppHash) + data := &rollkittypes.Data{Txs: rollkittypes.Txs{}} + var signature rollkittypes.Signature + require.NoError(t, bs.SaveBlockData(ctx, signedHeader, data, &signature)) + }, + msg: &types.MsgAttest{ + Validator: valAddrStr, + Height: 10, + Vote: validVoteBz, + }, + }, + //"validator not in attester set": { + // setupMock: func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper, bs rstore.Store) { + // // Set up validator but don't add to attester set + // valAddr := sdk.ValAddress("validator1") + // validator := stakingtypes.Validator{ + // OperatorAddress: valAddr.String(), + // Status: stakingtypes.Bonded, + // } + // require.NoError(t, sk.SetValidator(ctx, validator)) + // + // // Set up params for checkpoint height + // params := types.DefaultParams() + // params.EpochLength = 10 // Make height 10 a checkpoint + // require.NoError(t, keeper.SetParams(ctx, params)) + // }, + // msg: &types.MsgAttest{ + // Validator: sdk.ValAddress("validator1").String(), + // Height: 10, + // Vote: []byte("mock_vote"), + // }, + // expErr: sdkerrors.ErrUnauthorized, + //}, + //"not a checkpoint height": { + // setupMock: func(t *testing.T, ctx sdk.Context, keeper *Keeper, sk *MockStakingKeeper, bs rstore.Store) { + // // Set up validator and add to attester set + // valAddr := sdk.ValAddress("validator1") + // validator := stakingtypes.Validator{ + // OperatorAddress: valAddr.String(), + // Status: stakingtypes.Bonded, + // } + // require.NoError(t, sk.SetValidator(ctx, validator)) + // require.NoError(t, keeper.SetAttesterSetMember(ctx, valAddr.String())) + // + // // Set up params for checkpoint height + // params := types.DefaultParams() + // params.EpochLength = 10 // Make height 10 a checkpoint + // require.NoError(t, keeper.SetParams(ctx, params)) + // }, + // msg: &types.MsgAttest{ + // Validator: sdk.ValAddress("validator1").String(), + // Height: 11, // Not a checkpoint height + // Vote: []byte("mock_vote"), + // }, + // expErr: sdkerrors.ErrInvalidRequest, + //}, + } + + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + rollkitPrefixStore := kt.Wrap(ds.NewMapDatastore(), &kt.PrefixTransform{ + Prefix: ds.NewKey(rollnode.RollkitPrefix), + }) + bs := rstore.New(rollkitPrefixStore) + // Set up codec and store + cdc := moduletestutil.MakeTestEncodingConfig().Codec + keys := storetypes.NewKVStoreKeys(types.StoreKey) + + // Set up context and keeper + logger := log.NewTestLogger(t) + cms := integration.CreateMultiStore(keys, logger) + authority := authtypes.NewModuleAddress("gov") + sk := NewMockStakingKeeper() + keeper := NewKeeper(cdc, runtime.NewKVStoreService(keys[types.StoreKey]), &sk, nil, nil, bs, authority.String()) + server := NewMsgServerImpl(keeper) + + ctx := sdk.NewContext(cms, cmtproto.Header{ChainID: "test-chain", Time: time.Now().UTC(), Height: 20}, false, logger). + WithContext(t.Context()) + + // Run setup + spec.setup(t, ctx, &keeper, &sk, bs) + + // when + gotRsp, gotErr := server.Attest(ctx, spec.msg) + + // then + if spec.expErr != nil { + require.Error(t, gotErr) + require.ErrorIs(t, gotErr, spec.expErr) + // and ensure the signature is not stored + _, err := keeper.GetSignature(ctx, spec.msg.Height, valAddrStr) + assert.ErrorIs(t, err, collections.ErrNotFound) + return + } + + require.NoError(t, gotErr) + require.NotNil(t, gotRsp) + + // and attestation marked + bitmap, gotErr := keeper.GetAttestationBitmap(ctx, spec.msg.Height) + require.NoError(t, gotErr) + require.NotEmpty(t, bitmap) + require.Equal(t, byte(1), bitmap[0]) + + // and the signature was stored properly + gotSig, err := keeper.GetSignature(ctx, spec.msg.Height, valAddrStr) + require.NoError(t, err) + var vote cmtproto.Vote + require.NoError(t, proto.Unmarshal(spec.msg.Vote, &vote)) + expSig := cmtproto.CommitSig{ + BlockIdFlag: cmtproto.BlockIDFlagCommit, + ValidatorAddress: vote.ValidatorAddress, + Timestamp: vote.Timestamp, + Signature: vote.Signature, + } + assert.Equal(t, expSig, gotSig) + }) + } +} + +func HeaderFixture(signer *ed25519.PrivKey, myAppHash []byte, mutators ...func(*rollkittypes.SignedHeader)) *rollkittypes.SignedHeader { + header := rollkittypes.Header{ + BaseHeader: rollkittypes.BaseHeader{ + Height: 10, + Time: uint64(time.Now().UnixNano()), + ChainID: "testing", + }, + Version: rollkittypes.Version{Block: 1, App: 1}, + ProposerAddress: signer.PubKey().Address(), + AppHash: myAppHash, + DataHash: []byte("data_hash"), + ConsensusHash: []byte("consensus_hash"), + ValidatorHash: []byte("validator_hash"), + } + signedHeader := &rollkittypes.SignedHeader{ + Header: header, + Signature: myAppHash, + Signer: rollkittypes.Signer{PubKey: must(crypto.UnmarshalEd25519PublicKey(signer.PubKey().Bytes()))}, + } + for _, m := range mutators { + m(signedHeader) + } + return signedHeader +} + +func VoteFixture(myAppHash []byte, voteSigner *ed25519.PrivKey, mutators ...func(vote *cmtproto.Vote)) *cmtproto.Vote { + const chainID = "testing" + + vote := &cmtproto.Vote{ + Type: cmtproto.PrecommitType, + Height: 10, + Round: 0, + BlockID: cmtproto.BlockID{Hash: myAppHash, PartSetHeader: cmtproto.PartSetHeader{Total: 1, Hash: myAppHash}}, + Timestamp: time.Now(), + ValidatorAddress: voteSigner.PubKey().Address(), + ValidatorIndex: 0, + } + vote.Signature = must(voteSigner.Sign(cmttypes.VoteSignBytes(chainID, vote))) + + for _, m := range mutators { + m(vote) + } + return vote +} + +var _ types.StakingKeeper = &MockStakingKeeper{} + +type MockStakingKeeper struct { + activeSet map[string]stakingtypes.Validator + pubKeys map[string]cryptotypes.PubKey +} + +func NewMockStakingKeeper() MockStakingKeeper { + return MockStakingKeeper{ + activeSet: make(map[string]stakingtypes.Validator), + pubKeys: make(map[string]cryptotypes.PubKey), + } +} + +func (m *MockStakingKeeper) SetValidator(ctx context.Context, validator stakingtypes.Validator) error { + m.activeSet[validator.GetOperator()] = validator + return nil +} + +func (m MockStakingKeeper) GetAllValidators(ctx context.Context) (validators []stakingtypes.Validator, err error) { + return slices.SortedFunc(maps.Values(m.activeSet), func(v1 stakingtypes.Validator, v2 stakingtypes.Validator) int { + return strings.Compare(v1.OperatorAddress, v2.OperatorAddress) + }), nil +} + +func (m MockStakingKeeper) GetValidator(ctx context.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, err error) { + // First try to find the validator by address + validator, found := m.activeSet[addr.String()] + if found { + return validator, nil + } + + // If not found by address, try to find by public key address + addrStr := addr.String() + for valAddrStr, pubKey := range m.pubKeys { + if pubKey.Address().String() == addrStr { + validator, found = m.activeSet[valAddrStr] + if found { + return validator, nil + } + } + } + + return validator, sdkerrors.ErrNotFound +} + +func (m MockStakingKeeper) GetLastValidators(ctx context.Context) (validators []stakingtypes.Validator, err error) { + for _, validator := range m.activeSet { + if validator.IsBonded() { // Assuming IsBonded() identifies if a validator is in the last validators + validators = append(validators, validator) + } + } + return +} + +func (m MockStakingKeeper) GetLastTotalPower(ctx context.Context) (math.Int, error) { + return math.NewInt(int64(len(m.activeSet))), nil +} + +func (m *MockStakingKeeper) SetValidatorPubKey(valAddrStr string, key cryptotypes.PubKey) { + m.pubKeys[valAddrStr] = key +} + +func must[T any](r T, err error) T { + if err != nil { + panic(err) + } + return r +} diff --git a/modules/network/module.go b/modules/network/module.go new file mode 100644 index 00000000..aff4df5d --- /dev/null +++ b/modules/network/module.go @@ -0,0 +1,113 @@ +package network + +import ( + "context" + "encoding/json" + "fmt" + + "cosmossdk.io/core/appmodule" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" + + "github.com/rollkit/go-execution-abci/modules/network/keeper" + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +var ( + _ module.AppModuleBasic = AppModuleBasic{} + _ appmodule.AppModule = AppModule{} + _ module.HasServices = AppModule{} + _ module.HasGenesis = AppModule{} + _ appmodule.HasBeginBlocker = AppModule{} + _ appmodule.HasEndBlocker = AppModule{} +) + +type AppModuleBasic struct { + cdc codec.Codec +} + +// NewAppModule creates a new AppModule object +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: AppModuleBasic{cdc: cdc}, + keeper: keeper, + } +} + +// Name returns the network module's name +func (am AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the network module's types on the given LegacyAmino codec. +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers the module's interface types +func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + +// ValidateGenesis performs genesis state validation for the network module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genesisState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genesisState); err != nil { + return fmt.Errorf("unmarshal genesis state: %w", err) + } + return genesisState.Validate() +} + +// DefaultGenesis returns default genesis state as raw bytes. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the network module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +// InitGenesis performs genesis initialization for the staking module. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + if err := InitGenesis(ctx, am.keeper, genesisState); err != nil { + panic(fmt.Errorf("init genesis: %w", err)) + } +} +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper)) +} + +// IsAppModule implements the appmodule.AppModule interface. +func (am AppModule) IsAppModule() {} + +// RegisterServices registers module services. +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper)) +} + +func (am AppModule) EndBlock(ctx context.Context) error { + return am.keeper.EndBlocker(sdk.UnwrapSDKContext(ctx)) +} + +func (am AppModule) BeginBlock(ctx context.Context) error { + return am.keeper.BeginBlocker(sdk.UnwrapSDKContext(ctx)) +} diff --git a/modules/network/module/v1/module.pb.go b/modules/network/module/v1/module.pb.go new file mode 100644 index 00000000..fea65b08 --- /dev/null +++ b/modules/network/module/v1/module.pb.go @@ -0,0 +1,323 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: rollkitsdk/network/module/v1/module.proto + +package v1 + +import ( + _ "cosmossdk.io/depinject/appconfig/v1alpha1" + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Module is the config object for the module. +type Module struct { + // authority defines the custom module authority. If not set, defaults to the governance module. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` +} + +func (m *Module) Reset() { *m = Module{} } +func (m *Module) String() string { return proto.CompactTextString(m) } +func (*Module) ProtoMessage() {} +func (*Module) Descriptor() ([]byte, []int) { + return fileDescriptor_fc353625fec2db0a, []int{0} +} +func (m *Module) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Module) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Module.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Module) XXX_Merge(src proto.Message) { + xxx_messageInfo_Module.Merge(m, src) +} +func (m *Module) XXX_Size() int { + return m.Size() +} +func (m *Module) XXX_DiscardUnknown() { + xxx_messageInfo_Module.DiscardUnknown(m) +} + +var xxx_messageInfo_Module proto.InternalMessageInfo + +func (m *Module) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func init() { + proto.RegisterType((*Module)(nil), "rollkitsdk.network.module.v1.Module") +} + +func init() { + proto.RegisterFile("rollkitsdk/network/module/v1/module.proto", fileDescriptor_fc353625fec2db0a) +} + +var fileDescriptor_fc353625fec2db0a = []byte{ + // 211 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0xca, 0xcf, 0xc9, + 0xc9, 0xce, 0x2c, 0x29, 0x4e, 0xc9, 0xd6, 0xcf, 0x4b, 0x2d, 0x29, 0xcf, 0x2f, 0xca, 0xd6, 0xcf, + 0xcd, 0x4f, 0x29, 0xcd, 0x49, 0xd5, 0x2f, 0x33, 0x84, 0xb2, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, + 0x85, 0x64, 0x10, 0x4a, 0xf5, 0xa0, 0x4a, 0xf5, 0xa0, 0x0a, 0xca, 0x0c, 0xa5, 0x14, 0x92, 0xf3, + 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x13, 0x0b, 0x0a, 0xf4, 0xcb, 0x0c, 0x13, 0x73, 0x0a, 0x32, 0x12, + 0x51, 0xf5, 0x2b, 0xa5, 0x70, 0xb1, 0xf9, 0x82, 0xf9, 0x42, 0x32, 0x5c, 0x9c, 0x89, 0xa5, 0x25, + 0x19, 0xf9, 0x45, 0x99, 0x25, 0x95, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x08, 0x01, 0x2b, + 0x9b, 0x5d, 0x07, 0xa6, 0xdd, 0x62, 0x34, 0xe3, 0x32, 0x49, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, + 0x4b, 0xce, 0xcf, 0xd5, 0x87, 0x5a, 0xad, 0x9f, 0x9e, 0xaf, 0x9b, 0x5a, 0x91, 0x9a, 0x5c, 0x5a, + 0x92, 0x99, 0x9f, 0xa7, 0x9b, 0x98, 0x94, 0x9c, 0x09, 0xb5, 0xa2, 0x18, 0xe6, 0x78, 0xa7, 0x88, + 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, + 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xb2, 0x23, 0xc7, 0x3c, 0x44, 0x60, + 0x24, 0xb1, 0x81, 0xbd, 0x61, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x63, 0x01, 0x0d, 0x5d, 0x33, + 0x01, 0x00, 0x00, +} + +func (m *Module) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Module) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Module) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintModule(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintModule(dAtA []byte, offset int, v uint64) int { + offset -= sovModule(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Module) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovModule(uint64(l)) + } + return n +} + +func sovModule(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozModule(x uint64) (n int) { + return sovModule(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Module) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Module: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Module: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModule + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthModule + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModule + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipModule(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthModule + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipModule(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowModule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowModule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowModule + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthModule + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupModule + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthModule + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthModule = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowModule = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupModule = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/network/types/codec.go b/modules/network/types/codec.go new file mode 100644 index 00000000..a6cfbf5f --- /dev/null +++ b/modules/network/types/codec.go @@ -0,0 +1,38 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +// RegisterCodec registers the necessary types and interfaces with the codec +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgAttest{}, "network/Attest", nil) + cdc.RegisterConcrete(&MsgJoinAttesterSet{}, "network/JoinAttesterSet", nil) + cdc.RegisterConcrete(&MsgLeaveAttesterSet{}, "network/LeaveAttesterSet", nil) + cdc.RegisterConcrete(&MsgUpdateParams{}, "network/UpdateParams", nil) +} + +// RegisterInterfaces registers the module interface types +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgAttest{}, + &MsgJoinAttesterSet{}, + &MsgLeaveAttesterSet{}, + &MsgUpdateParams{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) + +func init() { + RegisterCodec(Amino) + Amino.Seal() +} diff --git a/modules/network/types/expected_keepers.go b/modules/network/types/expected_keepers.go new file mode 100644 index 00000000..a356b9aa --- /dev/null +++ b/modules/network/types/expected_keepers.go @@ -0,0 +1,34 @@ +package types + +import ( + "context" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + tyrollkittypes "github.com/rollkit/rollkit/types" +) + +// StakingKeeper defines the expected staking keeper interface +type StakingKeeper interface { + GetAllValidators(ctx context.Context) (validators []stakingtypes.Validator, err error) + GetValidator(ctx context.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, err error) + GetLastValidators(ctx context.Context) (validators []stakingtypes.Validator, err error) + GetLastTotalPower(ctx context.Context) (math.Int, error) +} + +// AccountKeeper defines the expected account keeper interface +type AccountKeeper interface { + GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI +} + +// BankKeeper defines the expected bank keeper interface +type BankKeeper interface { + SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins +} + +// BlockSource is the block store +type BlockSource interface { + GetBlockData(ctx context.Context, height uint64) (*tyrollkittypes.SignedHeader, *tyrollkittypes.Data, error) +} diff --git a/modules/network/types/genesis.go b/modules/network/types/genesis.go new file mode 100644 index 00000000..c722e021 --- /dev/null +++ b/modules/network/types/genesis.go @@ -0,0 +1,52 @@ +package types + +import ( + "fmt" + "math" +) + +// DefaultGenesisState returns the default genesis state +func DefaultGenesisState() *GenesisState { + return &GenesisState{ + Params: DefaultParams(), + ValidatorIndices: []ValidatorIndex{}, + AttestationBitmaps: []AttestationBitmap{}, + } +} + +// Validate performs basic genesis state validation +func (gs GenesisState) Validate() error { + if err := gs.Params.Validate(); err != nil { + return fmt.Errorf("invalid params: %w", err) + } + + if len(gs.ValidatorIndices) > math.MaxUint16 { + return fmt.Errorf("too many validator indices") + } + // Check for duplicate validator indices + indexMap := make(map[string]bool) + usedIndices := make(map[uint32]bool) + + for _, vi := range gs.ValidatorIndices { + if indexMap[vi.Address] { + return fmt.Errorf("duplicate validator address: %s", vi.Address) + } + if usedIndices[vi.Index] { + return fmt.Errorf("duplicate index: %d", vi.Index) + } + indexMap[vi.Address] = true + usedIndices[vi.Index] = true + } + + // Validate attestation bitmaps + for _, ab := range gs.AttestationBitmaps { + if ab.Height <= 0 { + return fmt.Errorf("invalid attestation height: %d", ab.Height) + } + if ab.VotedPower > ab.TotalPower { + return fmt.Errorf("voted power exceeds total power at height %d", ab.Height) + } + } + + return nil +} diff --git a/modules/network/types/genesis.pb.go b/modules/network/types/genesis.pb.go new file mode 100644 index 00000000..1de93571 --- /dev/null +++ b/modules/network/types/genesis.pb.go @@ -0,0 +1,457 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: rollkitsdk/network/v1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the network module's genesis state. +type GenesisState struct { + // params defines the module parameters at genesis + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + // validator_indices contains the initial validator index mappings + ValidatorIndices []ValidatorIndex `protobuf:"bytes,2,rep,name=validator_indices,json=validatorIndices,proto3" json:"validator_indices"` + // attestation_bitmaps contains historical attestation data + AttestationBitmaps []AttestationBitmap `protobuf:"bytes,3,rep,name=attestation_bitmaps,json=attestationBitmaps,proto3" json:"attestation_bitmaps"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_4576a54d81982ba5, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetValidatorIndices() []ValidatorIndex { + if m != nil { + return m.ValidatorIndices + } + return nil +} + +func (m *GenesisState) GetAttestationBitmaps() []AttestationBitmap { + if m != nil { + return m.AttestationBitmaps + } + return nil +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "rollkitsdk.network.v1.GenesisState") +} + +func init() { + proto.RegisterFile("rollkitsdk/network/v1/genesis.proto", fileDescriptor_4576a54d81982ba5) +} + +var fileDescriptor_4576a54d81982ba5 = []byte{ + // 308 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x90, 0x3f, 0x4b, 0xfb, 0x40, + 0x1c, 0xc6, 0x93, 0xf6, 0x47, 0x87, 0xf4, 0x37, 0x68, 0x54, 0x28, 0x05, 0xcf, 0xaa, 0x08, 0x59, + 0x7a, 0x47, 0xeb, 0xa6, 0x93, 0x59, 0xc4, 0x4d, 0x54, 0x44, 0x5c, 0xc2, 0x25, 0x39, 0xe2, 0x91, + 0x3f, 0x17, 0x72, 0xdf, 0xc4, 0xfa, 0x06, 0x9c, 0x7d, 0x59, 0x1d, 0x3b, 0x3a, 0x89, 0x24, 0x6f, + 0x44, 0x72, 0x3d, 0xad, 0x48, 0xbb, 0x1d, 0xf7, 0xfd, 0x3c, 0x9f, 0x07, 0x1e, 0xeb, 0xb8, 0x10, + 0x49, 0x12, 0x73, 0x90, 0x61, 0x4c, 0x32, 0x06, 0xcf, 0xa2, 0x88, 0x49, 0x35, 0x21, 0x11, 0xcb, + 0x98, 0xe4, 0x12, 0xe7, 0x85, 0x00, 0x61, 0xef, 0xad, 0x20, 0xac, 0x21, 0x5c, 0x4d, 0x86, 0xbb, + 0x91, 0x88, 0x84, 0x22, 0x48, 0xfb, 0x5a, 0xc2, 0xc3, 0xc3, 0xf5, 0x46, 0x78, 0xc9, 0x99, 0xf6, + 0x1d, 0xbd, 0x76, 0xac, 0xff, 0x97, 0xcb, 0x86, 0x5b, 0xa0, 0xc0, 0xec, 0x73, 0xab, 0x97, 0xd3, + 0x82, 0xa6, 0x72, 0x60, 0x8e, 0x4c, 0xa7, 0x3f, 0xdd, 0xc7, 0x6b, 0x1b, 0xf1, 0xb5, 0x82, 0xdc, + 0x7f, 0xf3, 0x8f, 0x03, 0xe3, 0x46, 0x47, 0xec, 0x07, 0x6b, 0xbb, 0xa2, 0x09, 0x0f, 0x29, 0x88, + 0xc2, 0xe3, 0x59, 0xc8, 0x03, 0x26, 0x07, 0x9d, 0x51, 0xd7, 0xe9, 0x4f, 0x4f, 0x36, 0x78, 0xee, + 0xbf, 0xf9, 0xab, 0x2c, 0x64, 0x33, 0xed, 0xdb, 0xaa, 0x7e, 0xfd, 0xb6, 0x12, 0xdb, 0xb3, 0x76, + 0x28, 0x00, 0x93, 0x40, 0x81, 0x8b, 0xcc, 0xf3, 0x39, 0xa4, 0x34, 0x97, 0x83, 0xae, 0x72, 0x3b, + 0x1b, 0xdc, 0x17, 0xab, 0x84, 0xab, 0x02, 0x5a, 0x6f, 0xd3, 0xbf, 0x07, 0xe9, 0xde, 0xcd, 0x6b, + 0x64, 0x2e, 0x6a, 0x64, 0x7e, 0xd6, 0xc8, 0x7c, 0x6b, 0x90, 0xb1, 0x68, 0x90, 0xf1, 0xde, 0x20, + 0xe3, 0xf1, 0x2c, 0xe2, 0xf0, 0x54, 0xfa, 0x38, 0x10, 0x29, 0xd1, 0x3d, 0x24, 0x12, 0x63, 0x36, + 0x63, 0x41, 0xd9, 0x1a, 0xc6, 0xd4, 0x0f, 0x38, 0x49, 0x45, 0x58, 0x26, 0x4c, 0xfe, 0xec, 0xac, + 0x46, 0xf6, 0x7b, 0x6a, 0xe5, 0xd3, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc8, 0x54, 0xfb, 0xbf, + 0xdc, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AttestationBitmaps) > 0 { + for iNdEx := len(m.AttestationBitmaps) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AttestationBitmaps[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.ValidatorIndices) > 0 { + for iNdEx := len(m.ValidatorIndices) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ValidatorIndices[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.ValidatorIndices) > 0 { + for _, e := range m.ValidatorIndices { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.AttestationBitmaps) > 0 { + for _, e := range m.AttestationBitmaps { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorIndices", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorIndices = append(m.ValidatorIndices, ValidatorIndex{}) + if err := m.ValidatorIndices[len(m.ValidatorIndices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AttestationBitmaps", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AttestationBitmaps = append(m.AttestationBitmaps, AttestationBitmap{}) + if err := m.AttestationBitmaps[len(m.AttestationBitmaps)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/network/types/keys.go b/modules/network/types/keys.go new file mode 100644 index 00000000..9c97e3ad --- /dev/null +++ b/modules/network/types/keys.go @@ -0,0 +1,72 @@ +package types + +import ( + "encoding/binary" + + "cosmossdk.io/collections" +) + +const ( + // ModuleName defines the module name + ModuleName = "network" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName +) + +// KVStore key prefixes +var ( + // todo (Alex): use numbers instaed of verbose keyse? + ValidatorIndexPrefix = collections.NewPrefix("validator_index") + ValidatorPowerPrefix = collections.NewPrefix("validator_power") + AttestationBitmapPrefix = collections.NewPrefix("attestation_bitmap") + EpochBitmapPrefix = collections.NewPrefix("epoch_bitmap") + AttesterSetPrefix = collections.NewPrefix("attester_set") + CommitPrefix = collections.NewPrefix("commits") + StoredAttestationInfoPrefix = collections.NewPrefix("stored_attestation_info") + ParamsKey = collections.NewPrefix("params") +) + +// GetValidatorIndexKey returns the key for validator index mapping +func GetValidatorIndexKey(addr string) []byte { + return append(ValidatorIndexPrefix, []byte(addr)...) +} + +// GetValidatorPowerKey returns the key for validator power by index +func GetValidatorPowerKey(index uint16) []byte { + bz := make([]byte, 2) + binary.BigEndian.PutUint16(bz, index) + return append(ValidatorPowerPrefix, bz...) +} + +// GetAttestationKey returns the key for attestation bitmap at height +func GetAttestationKey(height int64) []byte { + bz := make([]byte, 8) + binary.BigEndian.PutUint64(bz, uint64(height)) + return append(AttestationBitmapPrefix, bz...) +} + +// GetSignatureKey returns the key for validator signature at height +func GetSignatureKey(height int64, addr string) []byte { + bz := make([]byte, 8) + binary.BigEndian.PutUint64(bz, uint64(height)) + return append(append(CommitPrefix, bz...), []byte(addr)...) +} + +// GetEpochBitmapKey returns the key for epoch participation bitmap +func GetEpochBitmapKey(epoch uint64) []byte { + bz := make([]byte, 8) + binary.BigEndian.PutUint64(bz, epoch) + return append(EpochBitmapPrefix, bz...) +} + +// GetAttesterSetKey returns the key for attester set membership +func GetAttesterSetKey(addr string) []byte { + return append(AttesterSetPrefix, []byte(addr)...) +} diff --git a/modules/network/types/msgs.go b/modules/network/types/msgs.go new file mode 100644 index 00000000..a8c0d94d --- /dev/null +++ b/modules/network/types/msgs.go @@ -0,0 +1,196 @@ +package types + +import ( + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgAttest = "attest" +const TypeMsgJoinAttesterSet = "join_attester_set" +const TypeMsgLeaveAttesterSet = "leave_attester_set" +const TypeMsgUpdateParams = "update_params" + +var _ sdk.Msg = &MsgAttest{} +var _ sdk.Msg = &MsgJoinAttesterSet{} +var _ sdk.Msg = &MsgLeaveAttesterSet{} +var _ sdk.Msg = &MsgUpdateParams{} + +// NewMsgAttest creates a new MsgAttest instance +func NewMsgAttest(validator string, height int64, vote []byte) *MsgAttest { + return &MsgAttest{ + Validator: validator, + Height: height, + Vote: vote, + } +} + +// Route returns the message route +func (msg *MsgAttest) Route() string { + return RouterKey +} + +// Type returns the message type +func (msg *MsgAttest) Type() string { + return TypeMsgAttest +} + +// GetSigners returns the expected signers +func (msg *MsgAttest) GetSigners() []sdk.AccAddress { + addr, err := sdk.ValAddressFromBech32(msg.Validator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{sdk.AccAddress(addr)} +} + +// GetSignBytes returns the bytes for signing +func (msg *MsgAttest) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +// ValidateBasic performs basic validation +func (msg *MsgAttest) ValidateBasic() error { + _, err := sdk.ValAddressFromBech32(msg.Validator) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid validator address (%s)", err) + } + + if msg.Height <= 0 { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "height must be positive") + } + + if len(msg.Vote) == 0 { + return errors.Wrap(sdkerrors.ErrInvalidRequest, "vote cannot be empty") + } + + return nil +} + +// NewMsgJoinAttesterSet creates a new MsgJoinAttesterSet instance +func NewMsgJoinAttesterSet(validator string) *MsgJoinAttesterSet { + return &MsgJoinAttesterSet{ + Validator: validator, + } +} + +// Route returns the message route +func (msg *MsgJoinAttesterSet) Route() string { + return RouterKey +} + +// Type returns the message type +func (msg *MsgJoinAttesterSet) Type() string { + return TypeMsgJoinAttesterSet +} + +// GetSigners returns the expected signers +func (msg *MsgJoinAttesterSet) GetSigners() []sdk.AccAddress { + addr, err := sdk.ValAddressFromBech32(msg.Validator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{sdk.AccAddress(addr)} +} + +// GetSignBytes returns the bytes for signing +func (msg *MsgJoinAttesterSet) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +// ValidateBasic performs basic validation +func (msg *MsgJoinAttesterSet) ValidateBasic() error { + _, err := sdk.ValAddressFromBech32(msg.Validator) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid validator address (%s)", err) + } + + return nil +} + +// NewMsgLeaveAttesterSet creates a new MsgLeaveAttesterSet instance +func NewMsgLeaveAttesterSet(validator string) *MsgLeaveAttesterSet { + return &MsgLeaveAttesterSet{ + Validator: validator, + } +} + +// Route returns the message route +func (msg *MsgLeaveAttesterSet) Route() string { + return RouterKey +} + +// Type returns the message type +func (msg *MsgLeaveAttesterSet) Type() string { + return TypeMsgLeaveAttesterSet +} + +// GetSigners returns the expected signers +func (msg *MsgLeaveAttesterSet) GetSigners() []sdk.AccAddress { + addr, err := sdk.ValAddressFromBech32(msg.Validator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{sdk.AccAddress(addr)} +} + +// GetSignBytes returns the bytes for signing +func (msg *MsgLeaveAttesterSet) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +// ValidateBasic performs basic validation +func (msg *MsgLeaveAttesterSet) ValidateBasic() error { + _, err := sdk.ValAddressFromBech32(msg.Validator) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid validator address (%s)", err) + } + + return nil +} + +// NewMsgUpdateParams creates a new MsgUpdateParams instance +func NewMsgUpdateParams(authority string, params Params) *MsgUpdateParams { + return &MsgUpdateParams{ + Authority: authority, + Params: params, + } +} + +// Route returns the message route +func (msg *MsgUpdateParams) Route() string { + return RouterKey +} + +// Type returns the message type +func (msg *MsgUpdateParams) Type() string { + return TypeMsgUpdateParams +} + +// GetSigners returns the expected signers +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + panic(err) + } + return []sdk.AccAddress{addr} +} + +// GetSignBytes returns the bytes for signing +func (msg *MsgUpdateParams) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +// ValidateBasic performs basic validation +func (msg *MsgUpdateParams) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + return errors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid authority address (%s)", err) + } + + return msg.Params.Validate() +} diff --git a/modules/network/types/params.go b/modules/network/types/params.go new file mode 100644 index 00000000..15358e2b --- /dev/null +++ b/modules/network/types/params.go @@ -0,0 +1,186 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/math" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +var ( + KeyEpochLength = []byte("EpochLength") + KeyQuorumFraction = []byte("QuorumFraction") + KeyMinParticipation = []byte("MinParticipation") + KeyPruneAfter = []byte("PruneAfter") + KeyEmergencyMode = []byte("EmergencyMode") + KeySignMode = []byte("SignMode") +) + +// Default parameter values +var ( + DefaultEpochLength = uint64(10) // todo (Alex): what is a good default? + DefaultQuorumFraction = math.LegacyNewDecWithPrec(667, 3) // 2/3 + DefaultMinParticipation = math.LegacyNewDecWithPrec(5, 1) // 1/2 + DefaultPruneAfter = uint64(7) + DefaultEmergencyMode = false + DefaultSignMode = SignMode_SIGN_MODE_CHECKPOINT +) + +// NewParams creates a new Params instance +func NewParams( + epochLength uint64, + quorumFraction math.LegacyDec, + minParticipation math.LegacyDec, + pruneAfter uint64, + emergencyMode bool, + signMode SignMode, +) Params { + return Params{ + EpochLength: epochLength, + QuorumFraction: quorumFraction.String(), + MinParticipation: minParticipation.String(), + PruneAfter: pruneAfter, + EmergencyMode: emergencyMode, + SignMode: signMode, + } +} + +// DefaultParams returns default parameters +func DefaultParams() Params { + return NewParams( + DefaultEpochLength, + DefaultQuorumFraction, + DefaultMinParticipation, + DefaultPruneAfter, + DefaultEmergencyMode, + DefaultSignMode, + ) +} + +// ParamSetPairs implements params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyEpochLength, &p.EpochLength, validateEpochLength), + paramtypes.NewParamSetPair(KeyQuorumFraction, &p.QuorumFraction, validateQuorumFraction), + paramtypes.NewParamSetPair(KeyMinParticipation, &p.MinParticipation, validateMinParticipation), + paramtypes.NewParamSetPair(KeyPruneAfter, &p.PruneAfter, validatePruneAfter), + paramtypes.NewParamSetPair(KeyEmergencyMode, &p.EmergencyMode, validateEmergencyMode), + paramtypes.NewParamSetPair(KeySignMode, &p.SignMode, validateSignMode), + } +} + +// Validate validates the parameter set +func (p Params) Validate() error { + if err := validateEpochLength(p.EpochLength); err != nil { + return err + } + if err := validateQuorumFraction(p.QuorumFraction); err != nil { + return err + } + if err := validateMinParticipation(p.MinParticipation); err != nil { + return err + } + if err := validatePruneAfter(p.PruneAfter); err != nil { + return err + } + if err := validateEmergencyMode(p.EmergencyMode); err != nil { + return err + } + if err := validateSignMode(p.SignMode); err != nil { + return err + } + return nil +} + +func validateEpochLength(i interface{}) error { + v, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v == 0 { + return fmt.Errorf("epoch length must be positive: %d", v) + } + + return nil +} + +func validateQuorumFraction(i interface{}) error { + v, ok := i.(string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + dec, err := math.LegacyNewDecFromStr(v) + if err != nil { + return fmt.Errorf("invalid decimal string: %w", err) + } + + if dec.LTE(math.LegacyZeroDec()) || dec.GT(math.LegacyOneDec()) { + return fmt.Errorf("quorum fraction must be between 0 and 1: %s", v) + } + + return nil +} + +func validateMinParticipation(i interface{}) error { + v, ok := i.(string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + dec, err := math.LegacyNewDecFromStr(v) + if err != nil { + return fmt.Errorf("invalid decimal string: %w", err) + } + + if dec.LTE(math.LegacyZeroDec()) || dec.GT(math.LegacyOneDec()) { + return fmt.Errorf("min participation must be between 0 and 1: %s", v) + } + + return nil +} + +func validatePruneAfter(i interface{}) error { + v, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v == 0 { + return fmt.Errorf("prune after must be positive: %d", v) + } + + return nil +} + +func validateEmergencyMode(i interface{}) error { + _, ok := i.(bool) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} + +func validateSignMode(i interface{}) error { + v, ok := i.(SignMode) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v == SignMode_SIGN_MODE_UNSPECIFIED { + return fmt.Errorf("sign mode cannot be unspecified") + } + + if v < SignMode_SIGN_MODE_CHECKPOINT || v > SignMode_SIGN_MODE_IBC_ONLY { + return fmt.Errorf("invalid sign mode: %d", v) + } + + return nil +} + +// ParamKeyTable returns the parameter key table +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} diff --git a/modules/network/types/query.pb.go b/modules/network/types/query.pb.go new file mode 100644 index 00000000..0428c662 --- /dev/null +++ b/modules/network/types/query.pb.go @@ -0,0 +1,2349 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: rollkitsdk/network/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is the request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_bae17cb7b1e48f90, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_bae17cb7b1e48f90, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// QueryAttestationBitmapRequest is the request type for the Query/AttestationBitmap RPC method. +type QueryAttestationBitmapRequest struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (m *QueryAttestationBitmapRequest) Reset() { *m = QueryAttestationBitmapRequest{} } +func (m *QueryAttestationBitmapRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAttestationBitmapRequest) ProtoMessage() {} +func (*QueryAttestationBitmapRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_bae17cb7b1e48f90, []int{2} +} +func (m *QueryAttestationBitmapRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAttestationBitmapRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAttestationBitmapRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAttestationBitmapRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAttestationBitmapRequest.Merge(m, src) +} +func (m *QueryAttestationBitmapRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAttestationBitmapRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAttestationBitmapRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAttestationBitmapRequest proto.InternalMessageInfo + +func (m *QueryAttestationBitmapRequest) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +// QueryAttestationBitmapResponse is the response type for the Query/AttestationBitmap RPC method. +type QueryAttestationBitmapResponse struct { + Bitmap *AttestationBitmap `protobuf:"bytes,1,opt,name=bitmap,proto3" json:"bitmap,omitempty"` +} + +func (m *QueryAttestationBitmapResponse) Reset() { *m = QueryAttestationBitmapResponse{} } +func (m *QueryAttestationBitmapResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAttestationBitmapResponse) ProtoMessage() {} +func (*QueryAttestationBitmapResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_bae17cb7b1e48f90, []int{3} +} +func (m *QueryAttestationBitmapResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAttestationBitmapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAttestationBitmapResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAttestationBitmapResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAttestationBitmapResponse.Merge(m, src) +} +func (m *QueryAttestationBitmapResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAttestationBitmapResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAttestationBitmapResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAttestationBitmapResponse proto.InternalMessageInfo + +func (m *QueryAttestationBitmapResponse) GetBitmap() *AttestationBitmap { + if m != nil { + return m.Bitmap + } + return nil +} + +// QueryEpochInfoRequest is the request type for the Query/EpochInfo RPC method. +type QueryEpochInfoRequest struct { + Epoch uint64 `protobuf:"varint,1,opt,name=epoch,proto3" json:"epoch,omitempty"` +} + +func (m *QueryEpochInfoRequest) Reset() { *m = QueryEpochInfoRequest{} } +func (m *QueryEpochInfoRequest) String() string { return proto.CompactTextString(m) } +func (*QueryEpochInfoRequest) ProtoMessage() {} +func (*QueryEpochInfoRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_bae17cb7b1e48f90, []int{4} +} +func (m *QueryEpochInfoRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryEpochInfoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryEpochInfoRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryEpochInfoRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryEpochInfoRequest.Merge(m, src) +} +func (m *QueryEpochInfoRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryEpochInfoRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryEpochInfoRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryEpochInfoRequest proto.InternalMessageInfo + +func (m *QueryEpochInfoRequest) GetEpoch() uint64 { + if m != nil { + return m.Epoch + } + return 0 +} + +// QueryEpochInfoResponse is the response type for the Query/EpochInfo RPC method. +type QueryEpochInfoResponse struct { + Epoch uint64 `protobuf:"varint,1,opt,name=epoch,proto3" json:"epoch,omitempty"` + StartHeight int64 `protobuf:"varint,2,opt,name=start_height,json=startHeight,proto3" json:"start_height,omitempty"` + EndHeight int64 `protobuf:"varint,3,opt,name=end_height,json=endHeight,proto3" json:"end_height,omitempty"` + ParticipationBitmap []byte `protobuf:"bytes,4,opt,name=participation_bitmap,json=participationBitmap,proto3" json:"participation_bitmap,omitempty"` + ActiveValidators uint64 `protobuf:"varint,5,opt,name=active_validators,json=activeValidators,proto3" json:"active_validators,omitempty"` + ParticipatingValidators uint64 `protobuf:"varint,6,opt,name=participating_validators,json=participatingValidators,proto3" json:"participating_validators,omitempty"` +} + +func (m *QueryEpochInfoResponse) Reset() { *m = QueryEpochInfoResponse{} } +func (m *QueryEpochInfoResponse) String() string { return proto.CompactTextString(m) } +func (*QueryEpochInfoResponse) ProtoMessage() {} +func (*QueryEpochInfoResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_bae17cb7b1e48f90, []int{5} +} +func (m *QueryEpochInfoResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryEpochInfoResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryEpochInfoResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryEpochInfoResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryEpochInfoResponse.Merge(m, src) +} +func (m *QueryEpochInfoResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryEpochInfoResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryEpochInfoResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryEpochInfoResponse proto.InternalMessageInfo + +func (m *QueryEpochInfoResponse) GetEpoch() uint64 { + if m != nil { + return m.Epoch + } + return 0 +} + +func (m *QueryEpochInfoResponse) GetStartHeight() int64 { + if m != nil { + return m.StartHeight + } + return 0 +} + +func (m *QueryEpochInfoResponse) GetEndHeight() int64 { + if m != nil { + return m.EndHeight + } + return 0 +} + +func (m *QueryEpochInfoResponse) GetParticipationBitmap() []byte { + if m != nil { + return m.ParticipationBitmap + } + return nil +} + +func (m *QueryEpochInfoResponse) GetActiveValidators() uint64 { + if m != nil { + return m.ActiveValidators + } + return 0 +} + +func (m *QueryEpochInfoResponse) GetParticipatingValidators() uint64 { + if m != nil { + return m.ParticipatingValidators + } + return 0 +} + +// QueryValidatorIndexRequest is the request type for the Query/ValidatorIndex RPC method. +type QueryValidatorIndexRequest struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` +} + +func (m *QueryValidatorIndexRequest) Reset() { *m = QueryValidatorIndexRequest{} } +func (m *QueryValidatorIndexRequest) String() string { return proto.CompactTextString(m) } +func (*QueryValidatorIndexRequest) ProtoMessage() {} +func (*QueryValidatorIndexRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_bae17cb7b1e48f90, []int{6} +} +func (m *QueryValidatorIndexRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryValidatorIndexRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryValidatorIndexRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryValidatorIndexRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryValidatorIndexRequest.Merge(m, src) +} +func (m *QueryValidatorIndexRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryValidatorIndexRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryValidatorIndexRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryValidatorIndexRequest proto.InternalMessageInfo + +func (m *QueryValidatorIndexRequest) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +// QueryValidatorIndexResponse is the response type for the Query/ValidatorIndex RPC method. +type QueryValidatorIndexResponse struct { + Index *ValidatorIndex `protobuf:"bytes,1,opt,name=index,proto3" json:"index,omitempty"` +} + +func (m *QueryValidatorIndexResponse) Reset() { *m = QueryValidatorIndexResponse{} } +func (m *QueryValidatorIndexResponse) String() string { return proto.CompactTextString(m) } +func (*QueryValidatorIndexResponse) ProtoMessage() {} +func (*QueryValidatorIndexResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_bae17cb7b1e48f90, []int{7} +} +func (m *QueryValidatorIndexResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryValidatorIndexResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryValidatorIndexResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryValidatorIndexResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryValidatorIndexResponse.Merge(m, src) +} +func (m *QueryValidatorIndexResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryValidatorIndexResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryValidatorIndexResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryValidatorIndexResponse proto.InternalMessageInfo + +func (m *QueryValidatorIndexResponse) GetIndex() *ValidatorIndex { + if m != nil { + return m.Index + } + return nil +} + +// QuerySoftConfirmationStatusRequest is the request type for the Query/SoftConfirmationStatus RPC method. +type QuerySoftConfirmationStatusRequest struct { + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` +} + +func (m *QuerySoftConfirmationStatusRequest) Reset() { *m = QuerySoftConfirmationStatusRequest{} } +func (m *QuerySoftConfirmationStatusRequest) String() string { return proto.CompactTextString(m) } +func (*QuerySoftConfirmationStatusRequest) ProtoMessage() {} +func (*QuerySoftConfirmationStatusRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_bae17cb7b1e48f90, []int{8} +} +func (m *QuerySoftConfirmationStatusRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySoftConfirmationStatusRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySoftConfirmationStatusRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QuerySoftConfirmationStatusRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySoftConfirmationStatusRequest.Merge(m, src) +} +func (m *QuerySoftConfirmationStatusRequest) XXX_Size() int { + return m.Size() +} +func (m *QuerySoftConfirmationStatusRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySoftConfirmationStatusRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySoftConfirmationStatusRequest proto.InternalMessageInfo + +func (m *QuerySoftConfirmationStatusRequest) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +// QuerySoftConfirmationStatusResponse is the response type for the Query/SoftConfirmationStatus RPC method. +type QuerySoftConfirmationStatusResponse struct { + IsSoftConfirmed bool `protobuf:"varint,1,opt,name=is_soft_confirmed,json=isSoftConfirmed,proto3" json:"is_soft_confirmed,omitempty"` + VotedPower uint64 `protobuf:"varint,2,opt,name=voted_power,json=votedPower,proto3" json:"voted_power,omitempty"` + TotalPower uint64 `protobuf:"varint,3,opt,name=total_power,json=totalPower,proto3" json:"total_power,omitempty"` + QuorumFraction string `protobuf:"bytes,4,opt,name=quorum_fraction,json=quorumFraction,proto3" json:"quorum_fraction,omitempty"` +} + +func (m *QuerySoftConfirmationStatusResponse) Reset() { *m = QuerySoftConfirmationStatusResponse{} } +func (m *QuerySoftConfirmationStatusResponse) String() string { return proto.CompactTextString(m) } +func (*QuerySoftConfirmationStatusResponse) ProtoMessage() {} +func (*QuerySoftConfirmationStatusResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_bae17cb7b1e48f90, []int{9} +} +func (m *QuerySoftConfirmationStatusResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySoftConfirmationStatusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySoftConfirmationStatusResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QuerySoftConfirmationStatusResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySoftConfirmationStatusResponse.Merge(m, src) +} +func (m *QuerySoftConfirmationStatusResponse) XXX_Size() int { + return m.Size() +} +func (m *QuerySoftConfirmationStatusResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySoftConfirmationStatusResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySoftConfirmationStatusResponse proto.InternalMessageInfo + +func (m *QuerySoftConfirmationStatusResponse) GetIsSoftConfirmed() bool { + if m != nil { + return m.IsSoftConfirmed + } + return false +} + +func (m *QuerySoftConfirmationStatusResponse) GetVotedPower() uint64 { + if m != nil { + return m.VotedPower + } + return 0 +} + +func (m *QuerySoftConfirmationStatusResponse) GetTotalPower() uint64 { + if m != nil { + return m.TotalPower + } + return 0 +} + +func (m *QuerySoftConfirmationStatusResponse) GetQuorumFraction() string { + if m != nil { + return m.QuorumFraction + } + return "" +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "rollkitsdk.network.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "rollkitsdk.network.v1.QueryParamsResponse") + proto.RegisterType((*QueryAttestationBitmapRequest)(nil), "rollkitsdk.network.v1.QueryAttestationBitmapRequest") + proto.RegisterType((*QueryAttestationBitmapResponse)(nil), "rollkitsdk.network.v1.QueryAttestationBitmapResponse") + proto.RegisterType((*QueryEpochInfoRequest)(nil), "rollkitsdk.network.v1.QueryEpochInfoRequest") + proto.RegisterType((*QueryEpochInfoResponse)(nil), "rollkitsdk.network.v1.QueryEpochInfoResponse") + proto.RegisterType((*QueryValidatorIndexRequest)(nil), "rollkitsdk.network.v1.QueryValidatorIndexRequest") + proto.RegisterType((*QueryValidatorIndexResponse)(nil), "rollkitsdk.network.v1.QueryValidatorIndexResponse") + proto.RegisterType((*QuerySoftConfirmationStatusRequest)(nil), "rollkitsdk.network.v1.QuerySoftConfirmationStatusRequest") + proto.RegisterType((*QuerySoftConfirmationStatusResponse)(nil), "rollkitsdk.network.v1.QuerySoftConfirmationStatusResponse") +} + +func init() { proto.RegisterFile("rollkitsdk/network/v1/query.proto", fileDescriptor_bae17cb7b1e48f90) } + +var fileDescriptor_bae17cb7b1e48f90 = []byte{ + // 831 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x41, 0x6f, 0x1b, 0x45, + 0x14, 0xf6, 0x26, 0xb6, 0xc1, 0x2f, 0x55, 0x4b, 0xa6, 0x6e, 0xb0, 0x96, 0xc6, 0x6d, 0xb6, 0x42, + 0x75, 0x0c, 0xf6, 0xd6, 0x01, 0x8a, 0x5a, 0x38, 0x40, 0x10, 0x88, 0xde, 0xca, 0x16, 0x71, 0xe8, + 0xc5, 0x1a, 0xef, 0x8e, 0xd7, 0xa3, 0xd8, 0x3b, 0x9b, 0x9d, 0x59, 0xb7, 0x55, 0x94, 0x0b, 0x1c, + 0xb9, 0x20, 0xf5, 0x4f, 0x70, 0xe6, 0xcc, 0x9d, 0x5e, 0x90, 0x2a, 0x71, 0xe1, 0x84, 0x50, 0xc2, + 0x0f, 0x41, 0xfb, 0x66, 0xbc, 0xb1, 0x93, 0xb5, 0x69, 0x39, 0xd9, 0xf3, 0xcd, 0xf7, 0xbd, 0xf7, + 0xbd, 0x99, 0xf7, 0x66, 0x61, 0x27, 0x11, 0xe3, 0xf1, 0x01, 0x57, 0x32, 0x38, 0x70, 0x23, 0xa6, + 0x9e, 0x88, 0xe4, 0xc0, 0x9d, 0xf6, 0xdc, 0xc3, 0x94, 0x25, 0xcf, 0xba, 0x71, 0x22, 0x94, 0x20, + 0xd7, 0xce, 0x28, 0x5d, 0x43, 0xe9, 0x4e, 0x7b, 0x76, 0x3d, 0x14, 0xa1, 0x40, 0x86, 0x9b, 0xfd, + 0xd3, 0x64, 0xfb, 0x7a, 0x28, 0x44, 0x38, 0x66, 0x2e, 0x8d, 0xb9, 0x4b, 0xa3, 0x48, 0x28, 0xaa, + 0xb8, 0x88, 0xa4, 0xd9, 0x6d, 0xfb, 0x42, 0x4e, 0x84, 0x74, 0x07, 0x54, 0x32, 0x9d, 0xc3, 0x9d, + 0xf6, 0x06, 0x4c, 0xd1, 0x9e, 0x1b, 0xd3, 0x90, 0x47, 0x48, 0x36, 0xdc, 0x25, 0xce, 0xd4, 0xb3, + 0x98, 0x99, 0x70, 0x4e, 0x1d, 0xc8, 0x37, 0x59, 0x90, 0x87, 0x34, 0xa1, 0x13, 0xe9, 0xb1, 0xc3, + 0x94, 0x49, 0xe5, 0x78, 0x70, 0x75, 0x01, 0x95, 0xb1, 0x88, 0x24, 0x23, 0x9f, 0x40, 0x35, 0x46, + 0xa4, 0x61, 0xdd, 0xb4, 0x5a, 0x1b, 0x7b, 0xdb, 0xdd, 0xc2, 0xba, 0xba, 0x5a, 0xb6, 0x5f, 0x7e, + 0xf1, 0xd7, 0x8d, 0x92, 0x67, 0x24, 0xce, 0xc7, 0xb0, 0x8d, 0x31, 0x3f, 0x57, 0x8a, 0x49, 0x5d, + 0xd3, 0x3e, 0x57, 0x13, 0x1a, 0x9b, 0xa4, 0x64, 0x0b, 0xaa, 0x23, 0xc6, 0xc3, 0x91, 0xc2, 0xe8, + 0xeb, 0x9e, 0x59, 0x39, 0x03, 0x68, 0x2e, 0x13, 0x1a, 0x5f, 0x9f, 0x41, 0x75, 0x80, 0x88, 0xf1, + 0xd5, 0x5a, 0xe2, 0xeb, 0x62, 0x04, 0xa3, 0x73, 0x3a, 0x70, 0x0d, 0x73, 0x7c, 0x19, 0x0b, 0x7f, + 0xf4, 0x20, 0x1a, 0x8a, 0x99, 0xa9, 0x3a, 0x54, 0x58, 0x86, 0x61, 0xe4, 0xb2, 0xa7, 0x17, 0xce, + 0x8f, 0x6b, 0xb0, 0x75, 0x9e, 0x6f, 0xbc, 0x14, 0x0a, 0xc8, 0x0e, 0x5c, 0x92, 0x8a, 0x26, 0xaa, + 0x6f, 0x2a, 0x5c, 0xc3, 0x0a, 0x37, 0x10, 0xfb, 0x1a, 0x21, 0xb2, 0x0d, 0xc0, 0xa2, 0x60, 0x46, + 0x58, 0x47, 0x42, 0x8d, 0x45, 0x81, 0xd9, 0xee, 0x41, 0x3d, 0xa6, 0x89, 0xe2, 0x3e, 0x8f, 0xb1, + 0x80, 0xbe, 0xa9, 0xb8, 0x7c, 0xd3, 0x6a, 0x5d, 0xf2, 0xae, 0x2e, 0xec, 0xe9, 0xe2, 0xc8, 0x7b, + 0xb0, 0x49, 0x7d, 0xc5, 0xa7, 0xac, 0x3f, 0xa5, 0x63, 0x1e, 0x50, 0x25, 0x12, 0xd9, 0xa8, 0xa0, + 0xad, 0xb7, 0xf4, 0xc6, 0x77, 0x39, 0x4e, 0xee, 0x41, 0x63, 0x2e, 0x46, 0x14, 0xce, 0x6b, 0xaa, + 0xa8, 0x79, 0x7b, 0x61, 0xff, 0x4c, 0xea, 0xdc, 0x05, 0x1b, 0x0f, 0x23, 0x87, 0x1e, 0x44, 0x01, + 0x7b, 0x3a, 0x3b, 0xc1, 0x06, 0xbc, 0x41, 0x83, 0x20, 0x61, 0x52, 0x77, 0x4d, 0xcd, 0x9b, 0x2d, + 0x9d, 0xc7, 0xf0, 0x4e, 0xa1, 0x2e, 0xef, 0xb6, 0x0a, 0xcf, 0x00, 0x73, 0xa9, 0xef, 0x2e, 0xb9, + 0xd4, 0x73, 0x6a, 0xad, 0x71, 0x3e, 0x05, 0x07, 0x63, 0x3f, 0x12, 0x43, 0xf5, 0x85, 0x88, 0x86, + 0x3c, 0x99, 0xe0, 0xd1, 0x3c, 0x52, 0x54, 0xa5, 0xf2, 0xbf, 0x5a, 0xee, 0x57, 0x0b, 0x6e, 0xad, + 0x94, 0x1b, 0x8b, 0x6d, 0xd8, 0xe4, 0xb2, 0x2f, 0xc5, 0x50, 0xf5, 0x7d, 0xcd, 0x62, 0x01, 0x86, + 0x7a, 0xd3, 0xbb, 0xc2, 0xe5, 0x9c, 0x98, 0x05, 0xe4, 0x06, 0x6c, 0x4c, 0x85, 0x62, 0x41, 0x3f, + 0x16, 0x4f, 0x58, 0x82, 0x1d, 0x50, 0xf6, 0x00, 0xa1, 0x87, 0x19, 0x92, 0x11, 0x94, 0x50, 0x74, + 0x6c, 0x08, 0xeb, 0x9a, 0x80, 0x90, 0x26, 0xdc, 0x86, 0x2b, 0x87, 0xa9, 0x48, 0xd2, 0x49, 0x7f, + 0x98, 0x64, 0xf7, 0x27, 0x22, 0xbc, 0xfd, 0x9a, 0x77, 0x59, 0xc3, 0x5f, 0x19, 0x74, 0xef, 0xf7, + 0x2a, 0x54, 0xd0, 0x3e, 0xf9, 0xc1, 0x82, 0xaa, 0x9e, 0x46, 0xb2, 0xbb, 0xe4, 0xfc, 0x2e, 0x8e, + 0xbf, 0xdd, 0x7e, 0x15, 0xaa, 0x3e, 0x02, 0xc7, 0xf9, 0xfe, 0x8f, 0x7f, 0x9e, 0xaf, 0x5d, 0x27, + 0xb6, 0x6b, 0x34, 0xf3, 0x2f, 0x8d, 0x1e, 0x7d, 0xf2, 0x8b, 0x05, 0x9b, 0x17, 0x66, 0x8f, 0x7c, + 0xb8, 0x2a, 0xcb, 0xb2, 0x57, 0xc2, 0xfe, 0xe8, 0x35, 0x55, 0xc6, 0xe6, 0x1d, 0xb4, 0xd9, 0x26, + 0xad, 0x22, 0x9b, 0xf4, 0x4c, 0xe6, 0x1e, 0xe9, 0x16, 0x38, 0x26, 0xcf, 0x2d, 0xa8, 0xe5, 0xe3, + 0x4d, 0xde, 0x5f, 0x95, 0xf6, 0xfc, 0xab, 0x61, 0x77, 0x5e, 0x91, 0x6d, 0xcc, 0xed, 0xa2, 0xb9, + 0x5b, 0x64, 0xa7, 0xc8, 0x1c, 0x3e, 0x20, 0xee, 0x11, 0xfe, 0x1c, 0x93, 0x9f, 0x2d, 0xb8, 0xbc, + 0xd8, 0xf1, 0xa4, 0xb7, 0x2a, 0x59, 0xe1, 0x4c, 0xda, 0x7b, 0xaf, 0x23, 0x31, 0x26, 0x5d, 0x34, + 0xb9, 0x4b, 0x6e, 0x17, 0x99, 0xcc, 0x1f, 0x0b, 0xf7, 0xc8, 0x4c, 0xf7, 0x31, 0xf9, 0xcd, 0x82, + 0xad, 0xe2, 0xf9, 0x21, 0xf7, 0x56, 0xe5, 0x5f, 0x39, 0xb2, 0xf6, 0xfd, 0xff, 0x23, 0x35, 0x25, + 0xdc, 0xc5, 0x12, 0xee, 0x90, 0x6e, 0x51, 0x09, 0xd9, 0x14, 0x77, 0xfc, 0x39, 0x71, 0xde, 0x0a, + 0xfb, 0xdf, 0xbe, 0x38, 0x69, 0x5a, 0x2f, 0x4f, 0x9a, 0xd6, 0xdf, 0x27, 0x4d, 0xeb, 0xa7, 0xd3, + 0x66, 0xe9, 0xe5, 0x69, 0xb3, 0xf4, 0xe7, 0x69, 0xb3, 0xf4, 0xf8, 0x7e, 0xc8, 0xd5, 0x28, 0x1d, + 0x74, 0x7d, 0x31, 0xc9, 0x63, 0x86, 0xa2, 0xc3, 0x9e, 0x32, 0x3f, 0xcd, 0x62, 0x74, 0xe8, 0xc0, + 0xe7, 0xee, 0x44, 0x04, 0xe9, 0x98, 0xc9, 0x3c, 0x1b, 0x7e, 0x80, 0x07, 0x55, 0xfc, 0x02, 0x7f, + 0xf0, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe2, 0x10, 0xc6, 0x5b, 0x40, 0x08, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Params queries the module parameters + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // AttestationBitmap queries the attestation bitmap for a specific height + AttestationBitmap(ctx context.Context, in *QueryAttestationBitmapRequest, opts ...grpc.CallOption) (*QueryAttestationBitmapResponse, error) + // EpochInfo queries information about a specific epoch + EpochInfo(ctx context.Context, in *QueryEpochInfoRequest, opts ...grpc.CallOption) (*QueryEpochInfoResponse, error) + // ValidatorIndex queries the bitmap index for a validator + ValidatorIndex(ctx context.Context, in *QueryValidatorIndexRequest, opts ...grpc.CallOption) (*QueryValidatorIndexResponse, error) + // SoftConfirmationStatus queries if a height is soft-confirmed + SoftConfirmationStatus(ctx context.Context, in *QuerySoftConfirmationStatusRequest, opts ...grpc.CallOption) (*QuerySoftConfirmationStatusResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/rollkitsdk.network.v1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) AttestationBitmap(ctx context.Context, in *QueryAttestationBitmapRequest, opts ...grpc.CallOption) (*QueryAttestationBitmapResponse, error) { + out := new(QueryAttestationBitmapResponse) + err := c.cc.Invoke(ctx, "/rollkitsdk.network.v1.Query/AttestationBitmap", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) EpochInfo(ctx context.Context, in *QueryEpochInfoRequest, opts ...grpc.CallOption) (*QueryEpochInfoResponse, error) { + out := new(QueryEpochInfoResponse) + err := c.cc.Invoke(ctx, "/rollkitsdk.network.v1.Query/EpochInfo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) ValidatorIndex(ctx context.Context, in *QueryValidatorIndexRequest, opts ...grpc.CallOption) (*QueryValidatorIndexResponse, error) { + out := new(QueryValidatorIndexResponse) + err := c.cc.Invoke(ctx, "/rollkitsdk.network.v1.Query/ValidatorIndex", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) SoftConfirmationStatus(ctx context.Context, in *QuerySoftConfirmationStatusRequest, opts ...grpc.CallOption) (*QuerySoftConfirmationStatusResponse, error) { + out := new(QuerySoftConfirmationStatusResponse) + err := c.cc.Invoke(ctx, "/rollkitsdk.network.v1.Query/SoftConfirmationStatus", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Params queries the module parameters + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // AttestationBitmap queries the attestation bitmap for a specific height + AttestationBitmap(context.Context, *QueryAttestationBitmapRequest) (*QueryAttestationBitmapResponse, error) + // EpochInfo queries information about a specific epoch + EpochInfo(context.Context, *QueryEpochInfoRequest) (*QueryEpochInfoResponse, error) + // ValidatorIndex queries the bitmap index for a validator + ValidatorIndex(context.Context, *QueryValidatorIndexRequest) (*QueryValidatorIndexResponse, error) + // SoftConfirmationStatus queries if a height is soft-confirmed + SoftConfirmationStatus(context.Context, *QuerySoftConfirmationStatusRequest) (*QuerySoftConfirmationStatusResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} +func (*UnimplementedQueryServer) AttestationBitmap(ctx context.Context, req *QueryAttestationBitmapRequest) (*QueryAttestationBitmapResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AttestationBitmap not implemented") +} +func (*UnimplementedQueryServer) EpochInfo(ctx context.Context, req *QueryEpochInfoRequest) (*QueryEpochInfoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method EpochInfo not implemented") +} +func (*UnimplementedQueryServer) ValidatorIndex(ctx context.Context, req *QueryValidatorIndexRequest) (*QueryValidatorIndexResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ValidatorIndex not implemented") +} +func (*UnimplementedQueryServer) SoftConfirmationStatus(ctx context.Context, req *QuerySoftConfirmationStatusRequest) (*QuerySoftConfirmationStatusResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SoftConfirmationStatus not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollkitsdk.network.v1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_AttestationBitmap_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAttestationBitmapRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).AttestationBitmap(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollkitsdk.network.v1.Query/AttestationBitmap", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).AttestationBitmap(ctx, req.(*QueryAttestationBitmapRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_EpochInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryEpochInfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).EpochInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollkitsdk.network.v1.Query/EpochInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).EpochInfo(ctx, req.(*QueryEpochInfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_ValidatorIndex_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryValidatorIndexRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).ValidatorIndex(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollkitsdk.network.v1.Query/ValidatorIndex", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).ValidatorIndex(ctx, req.(*QueryValidatorIndexRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_SoftConfirmationStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QuerySoftConfirmationStatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).SoftConfirmationStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollkitsdk.network.v1.Query/SoftConfirmationStatus", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).SoftConfirmationStatus(ctx, req.(*QuerySoftConfirmationStatusRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var Query_serviceDesc = _Query_serviceDesc +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "rollkitsdk.network.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + { + MethodName: "AttestationBitmap", + Handler: _Query_AttestationBitmap_Handler, + }, + { + MethodName: "EpochInfo", + Handler: _Query_EpochInfo_Handler, + }, + { + MethodName: "ValidatorIndex", + Handler: _Query_ValidatorIndex_Handler, + }, + { + MethodName: "SoftConfirmationStatus", + Handler: _Query_SoftConfirmationStatus_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "rollkitsdk/network/v1/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryAttestationBitmapRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAttestationBitmapRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAttestationBitmapRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryAttestationBitmapResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAttestationBitmapResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAttestationBitmapResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Bitmap != nil { + { + size, err := m.Bitmap.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryEpochInfoRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryEpochInfoRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryEpochInfoRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Epoch != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Epoch)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryEpochInfoResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryEpochInfoResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryEpochInfoResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ParticipatingValidators != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.ParticipatingValidators)) + i-- + dAtA[i] = 0x30 + } + if m.ActiveValidators != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.ActiveValidators)) + i-- + dAtA[i] = 0x28 + } + if len(m.ParticipationBitmap) > 0 { + i -= len(m.ParticipationBitmap) + copy(dAtA[i:], m.ParticipationBitmap) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ParticipationBitmap))) + i-- + dAtA[i] = 0x22 + } + if m.EndHeight != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.EndHeight)) + i-- + dAtA[i] = 0x18 + } + if m.StartHeight != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.StartHeight)) + i-- + dAtA[i] = 0x10 + } + if m.Epoch != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Epoch)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QueryValidatorIndexRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryValidatorIndexRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryValidatorIndexRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryValidatorIndexResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryValidatorIndexResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryValidatorIndexResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Index != nil { + { + size, err := m.Index.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QuerySoftConfirmationStatusRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QuerySoftConfirmationStatusRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySoftConfirmationStatusRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *QuerySoftConfirmationStatusResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QuerySoftConfirmationStatusResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySoftConfirmationStatusResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.QuorumFraction) > 0 { + i -= len(m.QuorumFraction) + copy(dAtA[i:], m.QuorumFraction) + i = encodeVarintQuery(dAtA, i, uint64(len(m.QuorumFraction))) + i-- + dAtA[i] = 0x22 + } + if m.TotalPower != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.TotalPower)) + i-- + dAtA[i] = 0x18 + } + if m.VotedPower != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.VotedPower)) + i-- + dAtA[i] = 0x10 + } + if m.IsSoftConfirmed { + i-- + if m.IsSoftConfirmed { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryAttestationBitmapRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovQuery(uint64(m.Height)) + } + return n +} + +func (m *QueryAttestationBitmapResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Bitmap != nil { + l = m.Bitmap.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryEpochInfoRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Epoch != 0 { + n += 1 + sovQuery(uint64(m.Epoch)) + } + return n +} + +func (m *QueryEpochInfoResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Epoch != 0 { + n += 1 + sovQuery(uint64(m.Epoch)) + } + if m.StartHeight != 0 { + n += 1 + sovQuery(uint64(m.StartHeight)) + } + if m.EndHeight != 0 { + n += 1 + sovQuery(uint64(m.EndHeight)) + } + l = len(m.ParticipationBitmap) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + if m.ActiveValidators != 0 { + n += 1 + sovQuery(uint64(m.ActiveValidators)) + } + if m.ParticipatingValidators != 0 { + n += 1 + sovQuery(uint64(m.ParticipatingValidators)) + } + return n +} + +func (m *QueryValidatorIndexRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryValidatorIndexResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Index != nil { + l = m.Index.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QuerySoftConfirmationStatusRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovQuery(uint64(m.Height)) + } + return n +} + +func (m *QuerySoftConfirmationStatusResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.IsSoftConfirmed { + n += 2 + } + if m.VotedPower != 0 { + n += 1 + sovQuery(uint64(m.VotedPower)) + } + if m.TotalPower != 0 { + n += 1 + sovQuery(uint64(m.TotalPower)) + } + l = len(m.QuorumFraction) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAttestationBitmapRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAttestationBitmapRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAttestationBitmapRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAttestationBitmapResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAttestationBitmapResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAttestationBitmapResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bitmap", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Bitmap == nil { + m.Bitmap = &AttestationBitmap{} + } + if err := m.Bitmap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryEpochInfoRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryEpochInfoRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryEpochInfoRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + } + m.Epoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Epoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryEpochInfoResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryEpochInfoResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryEpochInfoResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Epoch", wireType) + } + m.Epoch = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Epoch |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartHeight", wireType) + } + m.StartHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EndHeight", wireType) + } + m.EndHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EndHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ParticipationBitmap", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ParticipationBitmap = append(m.ParticipationBitmap[:0], dAtA[iNdEx:postIndex]...) + if m.ParticipationBitmap == nil { + m.ParticipationBitmap = []byte{} + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ActiveValidators", wireType) + } + m.ActiveValidators = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ActiveValidators |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ParticipatingValidators", wireType) + } + m.ParticipatingValidators = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ParticipatingValidators |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryValidatorIndexRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryValidatorIndexRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryValidatorIndexRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryValidatorIndexResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryValidatorIndexResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryValidatorIndexResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Index == nil { + m.Index = &ValidatorIndex{} + } + if err := m.Index.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QuerySoftConfirmationStatusRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QuerySoftConfirmationStatusRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySoftConfirmationStatusRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QuerySoftConfirmationStatusResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QuerySoftConfirmationStatusResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySoftConfirmationStatusResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsSoftConfirmed", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsSoftConfirmed = bool(v != 0) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VotedPower", wireType) + } + m.VotedPower = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.VotedPower |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalPower", wireType) + } + m.TotalPower = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TotalPower |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuorumFraction", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QuorumFraction = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/network/types/query.pb.gw.go b/modules/network/types/query.pb.gw.go new file mode 100644 index 00000000..ca6c1a74 --- /dev/null +++ b/modules/network/types/query.pb.gw.go @@ -0,0 +1,557 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: rollkitsdk/network/v1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_AttestationBitmap_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAttestationBitmapRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["height"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "height") + } + + protoReq.Height, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "height", err) + } + + msg, err := client.AttestationBitmap(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_AttestationBitmap_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAttestationBitmapRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["height"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "height") + } + + protoReq.Height, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "height", err) + } + + msg, err := server.AttestationBitmap(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_EpochInfo_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryEpochInfoRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["epoch"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "epoch") + } + + protoReq.Epoch, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "epoch", err) + } + + msg, err := client.EpochInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_EpochInfo_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryEpochInfoRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["epoch"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "epoch") + } + + protoReq.Epoch, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "epoch", err) + } + + msg, err := server.EpochInfo(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_ValidatorIndex_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryValidatorIndexRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + msg, err := client.ValidatorIndex(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_ValidatorIndex_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryValidatorIndexRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") + } + + protoReq.Address, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) + } + + msg, err := server.ValidatorIndex(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_SoftConfirmationStatus_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySoftConfirmationStatusRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["height"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "height") + } + + protoReq.Height, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "height", err) + } + + msg, err := client.SoftConfirmationStatus(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_SoftConfirmationStatus_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySoftConfirmationStatusRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["height"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "height") + } + + protoReq.Height, err = runtime.Int64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "height", err) + } + + msg, err := server.SoftConfirmationStatus(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AttestationBitmap_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_AttestationBitmap_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AttestationBitmap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_EpochInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_EpochInfo_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_EpochInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ValidatorIndex_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_ValidatorIndex_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ValidatorIndex_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_SoftConfirmationStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_SoftConfirmationStatus_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_SoftConfirmationStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_AttestationBitmap_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_AttestationBitmap_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_AttestationBitmap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_EpochInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_EpochInfo_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_EpochInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_ValidatorIndex_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_ValidatorIndex_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_ValidatorIndex_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_SoftConfirmationStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_SoftConfirmationStatus_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_SoftConfirmationStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"rollkit", "network", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_AttestationBitmap_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"rollkit", "network", "v1", "attestation", "height"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_EpochInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 3}, []string{"rollkit", "network", "v1", "epoch"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_ValidatorIndex_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"rollkit", "network", "v1", "validator", "address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_SoftConfirmationStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"rollkit", "network", "v1", "soft-confirmation", "height"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_AttestationBitmap_0 = runtime.ForwardResponseMessage + + forward_Query_EpochInfo_0 = runtime.ForwardResponseMessage + + forward_Query_ValidatorIndex_0 = runtime.ForwardResponseMessage + + forward_Query_SoftConfirmationStatus_0 = runtime.ForwardResponseMessage +) diff --git a/modules/network/types/tx.pb.go b/modules/network/types/tx.pb.go new file mode 100644 index 00000000..d618154e --- /dev/null +++ b/modules/network/types/tx.pb.go @@ -0,0 +1,1636 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: rollkitsdk/network/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgAttest submits a signed vote for a checkpoint +type MsgAttest struct { + // validator is the address of the validator submitting the attestation + Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` + // height is the checkpoint height being attested + Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` + // vote is the base64-encoded canonical Comet vote + Vote []byte `protobuf:"bytes,3,opt,name=vote,proto3" json:"vote,omitempty"` +} + +func (m *MsgAttest) Reset() { *m = MsgAttest{} } +func (m *MsgAttest) String() string { return proto.CompactTextString(m) } +func (*MsgAttest) ProtoMessage() {} +func (*MsgAttest) Descriptor() ([]byte, []int) { + return fileDescriptor_cad4541892a6f0bf, []int{0} +} +func (m *MsgAttest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAttest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAttest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAttest) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAttest.Merge(m, src) +} +func (m *MsgAttest) XXX_Size() int { + return m.Size() +} +func (m *MsgAttest) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAttest.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAttest proto.InternalMessageInfo + +// MsgAttestResponse is the response type for the Attest RPC +type MsgAttestResponse struct { +} + +func (m *MsgAttestResponse) Reset() { *m = MsgAttestResponse{} } +func (m *MsgAttestResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAttestResponse) ProtoMessage() {} +func (*MsgAttestResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cad4541892a6f0bf, []int{1} +} +func (m *MsgAttestResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAttestResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAttestResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAttestResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAttestResponse.Merge(m, src) +} +func (m *MsgAttestResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAttestResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAttestResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAttestResponse proto.InternalMessageInfo + +// MsgJoinAttesterSet opts a validator into the attester set +type MsgJoinAttesterSet struct { + // validator is the address of the validator joining + Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` +} + +func (m *MsgJoinAttesterSet) Reset() { *m = MsgJoinAttesterSet{} } +func (m *MsgJoinAttesterSet) String() string { return proto.CompactTextString(m) } +func (*MsgJoinAttesterSet) ProtoMessage() {} +func (*MsgJoinAttesterSet) Descriptor() ([]byte, []int) { + return fileDescriptor_cad4541892a6f0bf, []int{2} +} +func (m *MsgJoinAttesterSet) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgJoinAttesterSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgJoinAttesterSet.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgJoinAttesterSet) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgJoinAttesterSet.Merge(m, src) +} +func (m *MsgJoinAttesterSet) XXX_Size() int { + return m.Size() +} +func (m *MsgJoinAttesterSet) XXX_DiscardUnknown() { + xxx_messageInfo_MsgJoinAttesterSet.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgJoinAttesterSet proto.InternalMessageInfo + +// MsgJoinAttesterSetResponse is the response type for the JoinAttesterSet RPC +type MsgJoinAttesterSetResponse struct { +} + +func (m *MsgJoinAttesterSetResponse) Reset() { *m = MsgJoinAttesterSetResponse{} } +func (m *MsgJoinAttesterSetResponse) String() string { return proto.CompactTextString(m) } +func (*MsgJoinAttesterSetResponse) ProtoMessage() {} +func (*MsgJoinAttesterSetResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cad4541892a6f0bf, []int{3} +} +func (m *MsgJoinAttesterSetResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgJoinAttesterSetResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgJoinAttesterSetResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgJoinAttesterSetResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgJoinAttesterSetResponse.Merge(m, src) +} +func (m *MsgJoinAttesterSetResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgJoinAttesterSetResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgJoinAttesterSetResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgJoinAttesterSetResponse proto.InternalMessageInfo + +// MsgLeaveAttesterSet opts a validator out of the attester set +type MsgLeaveAttesterSet struct { + // validator is the address of the validator leaving + Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` +} + +func (m *MsgLeaveAttesterSet) Reset() { *m = MsgLeaveAttesterSet{} } +func (m *MsgLeaveAttesterSet) String() string { return proto.CompactTextString(m) } +func (*MsgLeaveAttesterSet) ProtoMessage() {} +func (*MsgLeaveAttesterSet) Descriptor() ([]byte, []int) { + return fileDescriptor_cad4541892a6f0bf, []int{4} +} +func (m *MsgLeaveAttesterSet) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgLeaveAttesterSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgLeaveAttesterSet.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgLeaveAttesterSet) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgLeaveAttesterSet.Merge(m, src) +} +func (m *MsgLeaveAttesterSet) XXX_Size() int { + return m.Size() +} +func (m *MsgLeaveAttesterSet) XXX_DiscardUnknown() { + xxx_messageInfo_MsgLeaveAttesterSet.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgLeaveAttesterSet proto.InternalMessageInfo + +// MsgLeaveAttesterSetResponse is the response type for the LeaveAttesterSet RPC +type MsgLeaveAttesterSetResponse struct { +} + +func (m *MsgLeaveAttesterSetResponse) Reset() { *m = MsgLeaveAttesterSetResponse{} } +func (m *MsgLeaveAttesterSetResponse) String() string { return proto.CompactTextString(m) } +func (*MsgLeaveAttesterSetResponse) ProtoMessage() {} +func (*MsgLeaveAttesterSetResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cad4541892a6f0bf, []int{5} +} +func (m *MsgLeaveAttesterSetResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgLeaveAttesterSetResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgLeaveAttesterSetResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgLeaveAttesterSetResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgLeaveAttesterSetResponse.Merge(m, src) +} +func (m *MsgLeaveAttesterSetResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgLeaveAttesterSetResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgLeaveAttesterSetResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgLeaveAttesterSetResponse proto.InternalMessageInfo + +// MsgUpdateParams updates the network module parameters +type MsgUpdateParams struct { + // authority is the address that controls the module + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the module parameters to update + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_cad4541892a6f0bf, []int{6} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +// MsgUpdateParamsResponse is the response type for the UpdateParams RPC +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_cad4541892a6f0bf, []int{7} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgAttest)(nil), "rollkitsdk.network.v1.MsgAttest") + proto.RegisterType((*MsgAttestResponse)(nil), "rollkitsdk.network.v1.MsgAttestResponse") + proto.RegisterType((*MsgJoinAttesterSet)(nil), "rollkitsdk.network.v1.MsgJoinAttesterSet") + proto.RegisterType((*MsgJoinAttesterSetResponse)(nil), "rollkitsdk.network.v1.MsgJoinAttesterSetResponse") + proto.RegisterType((*MsgLeaveAttesterSet)(nil), "rollkitsdk.network.v1.MsgLeaveAttesterSet") + proto.RegisterType((*MsgLeaveAttesterSetResponse)(nil), "rollkitsdk.network.v1.MsgLeaveAttesterSetResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "rollkitsdk.network.v1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "rollkitsdk.network.v1.MsgUpdateParamsResponse") +} + +func init() { proto.RegisterFile("rollkitsdk/network/v1/tx.proto", fileDescriptor_cad4541892a6f0bf) } + +var fileDescriptor_cad4541892a6f0bf = []byte{ + // 534 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x94, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0xc7, 0x7d, 0xa4, 0x44, 0xca, 0xa3, 0x52, 0xe1, 0x5a, 0xda, 0xd4, 0x50, 0x27, 0xcd, 0x80, + 0x42, 0xa4, 0xd8, 0x4a, 0x90, 0x18, 0xca, 0x80, 0x9a, 0x11, 0x11, 0x09, 0xb9, 0x85, 0x81, 0x05, + 0x39, 0xf1, 0x71, 0xb1, 0x12, 0xfb, 0xac, 0xbb, 0x8b, 0x69, 0x37, 0xc4, 0xc4, 0xd8, 0x4f, 0x80, + 0xfa, 0x0d, 0xe8, 0xd0, 0x0f, 0xd1, 0xb1, 0xea, 0xc4, 0x84, 0x50, 0x32, 0x94, 0x8f, 0x81, 0x6a, + 0x5f, 0x1c, 0x70, 0x6b, 0x11, 0x09, 0x89, 0xed, 0xee, 0xde, 0xff, 0xfd, 0xff, 0x3f, 0xe9, 0x9e, + 0x1e, 0x18, 0x9c, 0x8d, 0x46, 0x43, 0x4f, 0x0a, 0x77, 0x68, 0x05, 0x44, 0x7e, 0x60, 0x7c, 0x68, + 0x45, 0x2d, 0x4b, 0x1e, 0x98, 0x21, 0x67, 0x92, 0xe1, 0xfb, 0xf3, 0xba, 0xa9, 0xea, 0x66, 0xd4, + 0xd2, 0x37, 0xfa, 0x4c, 0xf8, 0x4c, 0x58, 0xbe, 0xa0, 0x57, 0x72, 0x5f, 0xd0, 0x44, 0xaf, 0x6f, + 0x26, 0x85, 0x77, 0xf1, 0xcd, 0x4a, 0x2e, 0xaa, 0xb4, 0x46, 0x19, 0x65, 0xc9, 0xfb, 0xd5, 0x49, + 0xbd, 0x6e, 0xe7, 0x00, 0x1c, 0x86, 0x44, 0x35, 0xd6, 0x8e, 0x10, 0x94, 0xba, 0x82, 0xee, 0x4a, + 0x49, 0x84, 0xc4, 0xcf, 0xa1, 0x14, 0x39, 0x23, 0xcf, 0x75, 0x24, 0xe3, 0x65, 0x54, 0x45, 0xf5, + 0x52, 0x67, 0xfb, 0xe2, 0xb4, 0xb9, 0xa5, 0xb2, 0xde, 0xcc, 0x6a, 0xbb, 0xae, 0xcb, 0x89, 0x10, + 0x7b, 0x92, 0x7b, 0x01, 0xb5, 0xe7, 0x3d, 0x78, 0x1d, 0x8a, 0x03, 0xe2, 0xd1, 0x81, 0x2c, 0xdf, + 0xaa, 0xa2, 0x7a, 0xc1, 0x56, 0x37, 0x8c, 0x61, 0x29, 0x62, 0x92, 0x94, 0x0b, 0x55, 0x54, 0x5f, + 0xb6, 0xe3, 0xf3, 0xce, 0xfa, 0xe7, 0xe3, 0x8a, 0xf6, 0xf3, 0xb8, 0xa2, 0x7d, 0xba, 0x3c, 0x69, + 0xcc, 0x3d, 0x6a, 0xab, 0x70, 0x2f, 0x25, 0xb2, 0x89, 0x08, 0x59, 0x20, 0x48, 0xcd, 0x07, 0xdc, + 0x15, 0xf4, 0x05, 0xf3, 0x82, 0xa4, 0x40, 0xf8, 0x1e, 0xf9, 0x77, 0xde, 0x5c, 0x86, 0x87, 0xa0, + 0x5f, 0x8f, 0x4b, 0x61, 0x02, 0x58, 0xed, 0x0a, 0xfa, 0x92, 0x38, 0x11, 0xf9, 0x2f, 0x34, 0x5b, + 0xf0, 0xe0, 0x86, 0xbc, 0x14, 0xe7, 0x0b, 0x82, 0x95, 0xae, 0xa0, 0xaf, 0x43, 0xd7, 0x91, 0xe4, + 0x95, 0xc3, 0x1d, 0x5f, 0xe0, 0xa7, 0x50, 0x72, 0xc6, 0x72, 0xc0, 0xb8, 0x27, 0x0f, 0x15, 0x4b, + 0xf9, 0xe2, 0xb4, 0xb9, 0xa6, 0x58, 0x32, 0x08, 0xa9, 0x14, 0x3f, 0x83, 0x62, 0x18, 0x3b, 0xc4, + 0x1f, 0x78, 0xa7, 0xbd, 0x65, 0xde, 0x38, 0xa4, 0x66, 0x12, 0xd3, 0x59, 0x3a, 0xfb, 0x5e, 0xd1, + 0x6c, 0xd5, 0x92, 0xe1, 0x4f, 0x4d, 0x6b, 0x9b, 0xb0, 0x91, 0xe1, 0x9b, 0xb1, 0xb7, 0xbf, 0x16, + 0xa0, 0xd0, 0x15, 0x14, 0xef, 0x43, 0x51, 0xcd, 0x60, 0x35, 0x27, 0x31, 0x9d, 0x09, 0xbd, 0xfe, + 0x37, 0xc5, 0xcc, 0x1d, 0x33, 0x58, 0xc9, 0x8e, 0xcc, 0xe3, 0xfc, 0xe6, 0x8c, 0x54, 0x6f, 0x2d, + 0x2c, 0x4d, 0x03, 0x39, 0xdc, 0xbd, 0x36, 0x16, 0x8d, 0x7c, 0x9b, 0xac, 0x56, 0x6f, 0x2f, 0xae, + 0x4d, 0x33, 0xdf, 0xc3, 0xf2, 0x1f, 0x5f, 0xff, 0x28, 0xdf, 0xe3, 0x77, 0x9d, 0x6e, 0x2e, 0xa6, + 0x9b, 0xe5, 0xe8, 0xb7, 0x3f, 0x5e, 0x9e, 0x34, 0x50, 0x67, 0xff, 0x6c, 0x62, 0xa0, 0xf3, 0x89, + 0x81, 0x7e, 0x4c, 0x0c, 0x74, 0x34, 0x35, 0xb4, 0xf3, 0xa9, 0xa1, 0x7d, 0x9b, 0x1a, 0xda, 0xdb, + 0x1d, 0xea, 0xc9, 0xc1, 0xb8, 0x67, 0xf6, 0x99, 0x6f, 0x29, 0x6b, 0x8b, 0xb2, 0x26, 0x39, 0x20, + 0xfd, 0xb1, 0xf4, 0x58, 0xd0, 0x74, 0x7a, 0x7d, 0xcf, 0xf2, 0x99, 0x3b, 0x1e, 0x11, 0x91, 0x2e, + 0xa4, 0x78, 0x1b, 0xf5, 0x8a, 0xf1, 0x3a, 0x7a, 0xf2, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x2f, 0x15, + 0x7c, 0x0d, 0x34, 0x05, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // Attest submits a signed vote for a checkpoint + Attest(ctx context.Context, in *MsgAttest, opts ...grpc.CallOption) (*MsgAttestResponse, error) + // JoinAttesterSet opts a validator into the attester set + JoinAttesterSet(ctx context.Context, in *MsgJoinAttesterSet, opts ...grpc.CallOption) (*MsgJoinAttesterSetResponse, error) + // LeaveAttesterSet opts a validator out of the attester set + LeaveAttesterSet(ctx context.Context, in *MsgLeaveAttesterSet, opts ...grpc.CallOption) (*MsgLeaveAttesterSetResponse, error) + // UpdateParams updates the module parameters + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) Attest(ctx context.Context, in *MsgAttest, opts ...grpc.CallOption) (*MsgAttestResponse, error) { + out := new(MsgAttestResponse) + err := c.cc.Invoke(ctx, "/rollkitsdk.network.v1.Msg/Attest", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) JoinAttesterSet(ctx context.Context, in *MsgJoinAttesterSet, opts ...grpc.CallOption) (*MsgJoinAttesterSetResponse, error) { + out := new(MsgJoinAttesterSetResponse) + err := c.cc.Invoke(ctx, "/rollkitsdk.network.v1.Msg/JoinAttesterSet", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) LeaveAttesterSet(ctx context.Context, in *MsgLeaveAttesterSet, opts ...grpc.CallOption) (*MsgLeaveAttesterSetResponse, error) { + out := new(MsgLeaveAttesterSetResponse) + err := c.cc.Invoke(ctx, "/rollkitsdk.network.v1.Msg/LeaveAttesterSet", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/rollkitsdk.network.v1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // Attest submits a signed vote for a checkpoint + Attest(context.Context, *MsgAttest) (*MsgAttestResponse, error) + // JoinAttesterSet opts a validator into the attester set + JoinAttesterSet(context.Context, *MsgJoinAttesterSet) (*MsgJoinAttesterSetResponse, error) + // LeaveAttesterSet opts a validator out of the attester set + LeaveAttesterSet(context.Context, *MsgLeaveAttesterSet) (*MsgLeaveAttesterSetResponse, error) + // UpdateParams updates the module parameters + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) Attest(ctx context.Context, req *MsgAttest) (*MsgAttestResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Attest not implemented") +} +func (*UnimplementedMsgServer) JoinAttesterSet(ctx context.Context, req *MsgJoinAttesterSet) (*MsgJoinAttesterSetResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method JoinAttesterSet not implemented") +} +func (*UnimplementedMsgServer) LeaveAttesterSet(ctx context.Context, req *MsgLeaveAttesterSet) (*MsgLeaveAttesterSetResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method LeaveAttesterSet not implemented") +} +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_Attest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAttest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Attest(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollkitsdk.network.v1.Msg/Attest", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Attest(ctx, req.(*MsgAttest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_JoinAttesterSet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgJoinAttesterSet) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).JoinAttesterSet(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollkitsdk.network.v1.Msg/JoinAttesterSet", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).JoinAttesterSet(ctx, req.(*MsgJoinAttesterSet)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_LeaveAttesterSet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgLeaveAttesterSet) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).LeaveAttesterSet(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollkitsdk.network.v1.Msg/LeaveAttesterSet", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).LeaveAttesterSet(ctx, req.(*MsgLeaveAttesterSet)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/rollkitsdk.network.v1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var Msg_serviceDesc = _Msg_serviceDesc +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "rollkitsdk.network.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Attest", + Handler: _Msg_Attest_Handler, + }, + { + MethodName: "JoinAttesterSet", + Handler: _Msg_JoinAttesterSet_Handler, + }, + { + MethodName: "LeaveAttesterSet", + Handler: _Msg_LeaveAttesterSet_Handler, + }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "rollkitsdk/network/v1/tx.proto", +} + +func (m *MsgAttest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgAttest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAttest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Vote) > 0 { + i -= len(m.Vote) + copy(dAtA[i:], m.Vote) + i = encodeVarintTx(dAtA, i, uint64(len(m.Vote))) + i-- + dAtA[i] = 0x1a + } + if m.Height != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x10 + } + if len(m.Validator) > 0 { + i -= len(m.Validator) + copy(dAtA[i:], m.Validator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Validator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgAttestResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgAttestResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAttestResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgJoinAttesterSet) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgJoinAttesterSet) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgJoinAttesterSet) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Validator) > 0 { + i -= len(m.Validator) + copy(dAtA[i:], m.Validator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Validator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgJoinAttesterSetResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgJoinAttesterSetResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgJoinAttesterSetResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgLeaveAttesterSet) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgLeaveAttesterSet) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgLeaveAttesterSet) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Validator) > 0 { + i -= len(m.Validator) + copy(dAtA[i:], m.Validator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Validator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgLeaveAttesterSetResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgLeaveAttesterSetResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgLeaveAttesterSetResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgAttest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Validator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Height != 0 { + n += 1 + sovTx(uint64(m.Height)) + } + l = len(m.Vote) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgAttestResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgJoinAttesterSet) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Validator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgJoinAttesterSetResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgLeaveAttesterSet) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Validator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgLeaveAttesterSetResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgAttest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAttest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAttest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Vote", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Vote = append(m.Vote[:0], dAtA[iNdEx:postIndex]...) + if m.Vote == nil { + m.Vote = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgAttestResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAttestResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAttestResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgJoinAttesterSet) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgJoinAttesterSet: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgJoinAttesterSet: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgJoinAttesterSetResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgJoinAttesterSetResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgJoinAttesterSetResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgLeaveAttesterSet) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgLeaveAttesterSet: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgLeaveAttesterSet: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgLeaveAttesterSetResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgLeaveAttesterSetResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgLeaveAttesterSetResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/network/types/types.pb.go b/modules/network/types/types.pb.go new file mode 100644 index 00000000..eda96ff0 --- /dev/null +++ b/modules/network/types/types.pb.go @@ -0,0 +1,1154 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: rollkitsdk/network/v1/types.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/protobuf/types/known/durationpb" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// SignMode defines when validators must sign +type SignMode int32 + +const ( + // SIGN_MODE_UNSPECIFIED is invalid + SignMode_SIGN_MODE_UNSPECIFIED SignMode = 0 + // SIGN_MODE_CHECKPOINT means validators sign only at checkpoint heights + SignMode_SIGN_MODE_CHECKPOINT SignMode = 1 + // SIGN_MODE_ALL means validators sign every block + SignMode_SIGN_MODE_ALL SignMode = 2 + // SIGN_MODE_IBC_ONLY means validators sign only blocks with outbound IBC + SignMode_SIGN_MODE_IBC_ONLY SignMode = 3 +) + +var SignMode_name = map[int32]string{ + 0: "SIGN_MODE_UNSPECIFIED", + 1: "SIGN_MODE_CHECKPOINT", + 2: "SIGN_MODE_ALL", + 3: "SIGN_MODE_IBC_ONLY", +} + +var SignMode_value = map[string]int32{ + "SIGN_MODE_UNSPECIFIED": 0, + "SIGN_MODE_CHECKPOINT": 1, + "SIGN_MODE_ALL": 2, + "SIGN_MODE_IBC_ONLY": 3, +} + +func (x SignMode) String() string { + return proto.EnumName(SignMode_name, int32(x)) +} + +func (SignMode) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_6ae6db90f9054c5e, []int{0} +} + +// Params defines the parameters for the network module. +type Params struct { + // epoch_length is the number of blocks per attestation window + EpochLength uint64 `protobuf:"varint,1,opt,name=epoch_length,json=epochLength,proto3" json:"epoch_length,omitempty"` + // quorum_fraction is the voting power needed for soft-finality (e.g., "2/3") + QuorumFraction string `protobuf:"bytes,2,opt,name=quorum_fraction,json=quorumFraction,proto3" json:"quorum_fraction,omitempty"` + // min_participation is the ejection threshold inside an epoch (e.g., "1/2") + MinParticipation string `protobuf:"bytes,3,opt,name=min_participation,json=minParticipation,proto3" json:"min_participation,omitempty"` + // prune_after is the number of epochs to retain attestation bitmaps + PruneAfter uint64 `protobuf:"varint,4,opt,name=prune_after,json=pruneAfter,proto3" json:"prune_after,omitempty"` + // emergency_mode is a governance switch to bypass quorum + EmergencyMode bool `protobuf:"varint,5,opt,name=emergency_mode,json=emergencyMode,proto3" json:"emergency_mode,omitempty"` + // sign_mode determines when validators must sign + SignMode SignMode `protobuf:"varint,6,opt,name=sign_mode,json=signMode,proto3,enum=rollkitsdk.network.v1.SignMode" json:"sign_mode,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_6ae6db90f9054c5e, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetEpochLength() uint64 { + if m != nil { + return m.EpochLength + } + return 0 +} + +func (m *Params) GetQuorumFraction() string { + if m != nil { + return m.QuorumFraction + } + return "" +} + +func (m *Params) GetMinParticipation() string { + if m != nil { + return m.MinParticipation + } + return "" +} + +func (m *Params) GetPruneAfter() uint64 { + if m != nil { + return m.PruneAfter + } + return 0 +} + +func (m *Params) GetEmergencyMode() bool { + if m != nil { + return m.EmergencyMode + } + return false +} + +func (m *Params) GetSignMode() SignMode { + if m != nil { + return m.SignMode + } + return SignMode_SIGN_MODE_UNSPECIFIED +} + +// AttestationBitmap stores the bitmap and metadata for a checkpoint +type AttestationBitmap struct { + // height is the checkpoint height + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + // bitmap is the validator participation bitmap + Bitmap []byte `protobuf:"bytes,2,opt,name=bitmap,proto3" json:"bitmap,omitempty"` + // voted_power is the total voting power that attested + VotedPower uint64 `protobuf:"varint,3,opt,name=voted_power,json=votedPower,proto3" json:"voted_power,omitempty"` + // total_power is the total voting power at this height + TotalPower uint64 `protobuf:"varint,4,opt,name=total_power,json=totalPower,proto3" json:"total_power,omitempty"` + // soft_confirmed indicates if quorum was reached + SoftConfirmed bool `protobuf:"varint,5,opt,name=soft_confirmed,json=softConfirmed,proto3" json:"soft_confirmed,omitempty"` +} + +func (m *AttestationBitmap) Reset() { *m = AttestationBitmap{} } +func (m *AttestationBitmap) String() string { return proto.CompactTextString(m) } +func (*AttestationBitmap) ProtoMessage() {} +func (*AttestationBitmap) Descriptor() ([]byte, []int) { + return fileDescriptor_6ae6db90f9054c5e, []int{1} +} +func (m *AttestationBitmap) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AttestationBitmap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AttestationBitmap.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AttestationBitmap) XXX_Merge(src proto.Message) { + xxx_messageInfo_AttestationBitmap.Merge(m, src) +} +func (m *AttestationBitmap) XXX_Size() int { + return m.Size() +} +func (m *AttestationBitmap) XXX_DiscardUnknown() { + xxx_messageInfo_AttestationBitmap.DiscardUnknown(m) +} + +var xxx_messageInfo_AttestationBitmap proto.InternalMessageInfo + +func (m *AttestationBitmap) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *AttestationBitmap) GetBitmap() []byte { + if m != nil { + return m.Bitmap + } + return nil +} + +func (m *AttestationBitmap) GetVotedPower() uint64 { + if m != nil { + return m.VotedPower + } + return 0 +} + +func (m *AttestationBitmap) GetTotalPower() uint64 { + if m != nil { + return m.TotalPower + } + return 0 +} + +func (m *AttestationBitmap) GetSoftConfirmed() bool { + if m != nil { + return m.SoftConfirmed + } + return false +} + +// ValidatorIndex maps a validator address to its bitmap index +type ValidatorIndex struct { + // address is the validator operator address + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // index is the position in the bitmap + Index uint32 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` + // power is the cached voting power + Power uint64 `protobuf:"varint,3,opt,name=power,proto3" json:"power,omitempty"` +} + +func (m *ValidatorIndex) Reset() { *m = ValidatorIndex{} } +func (m *ValidatorIndex) String() string { return proto.CompactTextString(m) } +func (*ValidatorIndex) ProtoMessage() {} +func (*ValidatorIndex) Descriptor() ([]byte, []int) { + return fileDescriptor_6ae6db90f9054c5e, []int{2} +} +func (m *ValidatorIndex) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ValidatorIndex) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ValidatorIndex.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ValidatorIndex) XXX_Merge(src proto.Message) { + xxx_messageInfo_ValidatorIndex.Merge(m, src) +} +func (m *ValidatorIndex) XXX_Size() int { + return m.Size() +} +func (m *ValidatorIndex) XXX_DiscardUnknown() { + xxx_messageInfo_ValidatorIndex.DiscardUnknown(m) +} + +var xxx_messageInfo_ValidatorIndex proto.InternalMessageInfo + +func (m *ValidatorIndex) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *ValidatorIndex) GetIndex() uint32 { + if m != nil { + return m.Index + } + return 0 +} + +func (m *ValidatorIndex) GetPower() uint64 { + if m != nil { + return m.Power + } + return 0 +} + +func init() { + proto.RegisterEnum("rollkitsdk.network.v1.SignMode", SignMode_name, SignMode_value) + proto.RegisterType((*Params)(nil), "rollkitsdk.network.v1.Params") + proto.RegisterType((*AttestationBitmap)(nil), "rollkitsdk.network.v1.AttestationBitmap") + proto.RegisterType((*ValidatorIndex)(nil), "rollkitsdk.network.v1.ValidatorIndex") +} + +func init() { proto.RegisterFile("rollkitsdk/network/v1/types.proto", fileDescriptor_6ae6db90f9054c5e) } + +var fileDescriptor_6ae6db90f9054c5e = []byte{ + // 604 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x93, 0xcd, 0x4e, 0xdb, 0x40, + 0x10, 0x80, 0x63, 0x7e, 0x52, 0x58, 0x20, 0x0d, 0xab, 0x80, 0x0c, 0x07, 0x13, 0x90, 0x90, 0xa2, + 0x4a, 0x89, 0x05, 0x3d, 0x54, 0x6a, 0x7b, 0x49, 0x42, 0x68, 0xa3, 0x86, 0x10, 0x39, 0xb4, 0x52, + 0x7b, 0xb1, 0x1c, 0x7b, 0xe3, 0x6c, 0xb1, 0x77, 0xdc, 0xdd, 0x35, 0x3f, 0x6f, 0xd1, 0xb7, 0xe8, + 0xa5, 0x47, 0x1e, 0xa2, 0x47, 0xc4, 0xa9, 0xc7, 0x0a, 0x5e, 0xa4, 0xda, 0xb5, 0x43, 0x38, 0x70, + 0xdb, 0xf9, 0xe6, 0x5b, 0x7b, 0x66, 0x56, 0x83, 0x76, 0x39, 0x44, 0xd1, 0x39, 0x95, 0x22, 0x38, + 0xb7, 0x19, 0x91, 0x97, 0xc0, 0xcf, 0xed, 0x8b, 0x03, 0x5b, 0x5e, 0x27, 0x44, 0x34, 0x12, 0x0e, + 0x12, 0xf0, 0xc6, 0x4c, 0x69, 0xe4, 0x4a, 0xe3, 0xe2, 0x60, 0xbb, 0x12, 0x42, 0x08, 0xda, 0xb0, + 0xd5, 0x29, 0x93, 0xb7, 0xb7, 0x7c, 0x10, 0x31, 0x08, 0x37, 0x4b, 0x64, 0x41, 0x9e, 0xb2, 0x42, + 0x80, 0x30, 0x22, 0xb6, 0x8e, 0x46, 0xe9, 0xd8, 0x0e, 0x52, 0xee, 0x49, 0x0a, 0x2c, 0xcb, 0xef, + 0xfd, 0x9a, 0x43, 0xc5, 0x81, 0xc7, 0xbd, 0x58, 0xe0, 0x5d, 0xb4, 0x4a, 0x12, 0xf0, 0x27, 0x6e, + 0x44, 0x58, 0x28, 0x27, 0xa6, 0x51, 0x35, 0x6a, 0x0b, 0xce, 0x8a, 0x66, 0x3d, 0x8d, 0xf0, 0x1b, + 0xf4, 0xf2, 0x47, 0x0a, 0x3c, 0x8d, 0xdd, 0x31, 0xf7, 0x7c, 0xf5, 0x19, 0x73, 0xae, 0x6a, 0xd4, + 0x96, 0x5b, 0xa5, 0xbb, 0x9b, 0x3a, 0xca, 0x7f, 0x7c, 0x44, 0x7c, 0xa7, 0x94, 0x69, 0xc7, 0xb9, + 0x85, 0xdf, 0xa1, 0xf5, 0x98, 0x32, 0x37, 0xf1, 0xb8, 0xa4, 0x3e, 0x4d, 0x74, 0x05, 0xe6, 0xfc, + 0xb3, 0x57, 0xcb, 0x31, 0x65, 0x83, 0xa7, 0x1e, 0xde, 0x41, 0x2b, 0x09, 0x4f, 0x19, 0x71, 0xbd, + 0xb1, 0x24, 0xdc, 0x5c, 0xd0, 0x75, 0x21, 0x8d, 0x9a, 0x8a, 0xe0, 0x7d, 0x54, 0x22, 0x31, 0xe1, + 0x21, 0x61, 0xfe, 0xb5, 0x1b, 0x43, 0x40, 0xcc, 0xc5, 0xaa, 0x51, 0x5b, 0x72, 0xd6, 0x1e, 0xe9, + 0x09, 0x04, 0x04, 0xbf, 0x47, 0xcb, 0x82, 0x86, 0x2c, 0x33, 0x8a, 0x55, 0xa3, 0x56, 0x3a, 0xdc, + 0x69, 0x3c, 0x3b, 0xe7, 0xc6, 0x90, 0x86, 0x4c, 0xdd, 0x71, 0x96, 0x44, 0x7e, 0xda, 0xfb, 0x6d, + 0xa0, 0xf5, 0xa6, 0x94, 0x44, 0x48, 0x5d, 0x55, 0x8b, 0xca, 0xd8, 0x4b, 0xf0, 0x26, 0x2a, 0x4e, + 0x08, 0x0d, 0x27, 0x52, 0x8f, 0x6b, 0xde, 0xc9, 0x23, 0xc5, 0x47, 0xda, 0xd0, 0x03, 0x5a, 0x75, + 0xf2, 0x48, 0xf5, 0x72, 0x01, 0x92, 0x04, 0x6e, 0x02, 0x97, 0x84, 0xeb, 0x11, 0x2c, 0x38, 0x48, + 0xa3, 0x81, 0x22, 0x4a, 0x90, 0x20, 0xbd, 0x28, 0x17, 0xf2, 0x66, 0x35, 0xca, 0x84, 0x7d, 0x54, + 0x12, 0x30, 0x96, 0xae, 0x0f, 0x6c, 0x4c, 0x79, 0x4c, 0x82, 0x69, 0xb3, 0x8a, 0xb6, 0xa7, 0x70, + 0x2f, 0x41, 0xa5, 0x2f, 0x5e, 0x44, 0x03, 0x4f, 0x02, 0xef, 0xb2, 0x80, 0x5c, 0xe1, 0x43, 0xf4, + 0xc2, 0x0b, 0x02, 0x4e, 0x84, 0xd0, 0xb5, 0x2e, 0xb7, 0xcc, 0xbb, 0x9b, 0x7a, 0x25, 0x9f, 0x7c, + 0x33, 0xcb, 0x0c, 0x25, 0xa7, 0x2c, 0x74, 0xa6, 0x22, 0xae, 0xa0, 0x45, 0xaa, 0x2e, 0xeb, 0x2e, + 0xd6, 0x9c, 0x2c, 0x50, 0xf4, 0x69, 0xf9, 0x59, 0xf0, 0xea, 0x3b, 0x5a, 0x9a, 0x8e, 0x0d, 0x6f, + 0xa1, 0x8d, 0x61, 0xf7, 0x43, 0xdf, 0x3d, 0x39, 0x3d, 0xea, 0xb8, 0x9f, 0xfb, 0xc3, 0x41, 0xa7, + 0xdd, 0x3d, 0xee, 0x76, 0x8e, 0xca, 0x05, 0x6c, 0xa2, 0xca, 0x2c, 0xd5, 0xfe, 0xd8, 0x69, 0x7f, + 0x1a, 0x9c, 0x76, 0xfb, 0x67, 0x65, 0x03, 0xaf, 0xa3, 0xb5, 0x59, 0xa6, 0xd9, 0xeb, 0x95, 0xe7, + 0xf0, 0x26, 0xc2, 0x33, 0xd4, 0x6d, 0xb5, 0xdd, 0xd3, 0x7e, 0xef, 0x6b, 0x79, 0xbe, 0x75, 0xf6, + 0xe7, 0xde, 0x32, 0x6e, 0xef, 0x2d, 0xe3, 0xdf, 0xbd, 0x65, 0xfc, 0x7c, 0xb0, 0x0a, 0xb7, 0x0f, + 0x56, 0xe1, 0xef, 0x83, 0x55, 0xf8, 0xf6, 0x36, 0xa4, 0x72, 0x92, 0x8e, 0x1a, 0x3e, 0xc4, 0x76, + 0xfe, 0xb6, 0x76, 0x08, 0x75, 0x72, 0x45, 0xfc, 0x54, 0xbd, 0x5b, 0xdd, 0x1b, 0xf9, 0xd4, 0x8e, + 0x21, 0x48, 0x23, 0x22, 0x1e, 0xb7, 0x4f, 0xaf, 0xde, 0xa8, 0xa8, 0x77, 0xe2, 0xf5, 0xff, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x10, 0x23, 0x89, 0x7d, 0xa0, 0x03, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SignMode != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.SignMode)) + i-- + dAtA[i] = 0x30 + } + if m.EmergencyMode { + i-- + if m.EmergencyMode { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + if m.PruneAfter != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.PruneAfter)) + i-- + dAtA[i] = 0x20 + } + if len(m.MinParticipation) > 0 { + i -= len(m.MinParticipation) + copy(dAtA[i:], m.MinParticipation) + i = encodeVarintTypes(dAtA, i, uint64(len(m.MinParticipation))) + i-- + dAtA[i] = 0x1a + } + if len(m.QuorumFraction) > 0 { + i -= len(m.QuorumFraction) + copy(dAtA[i:], m.QuorumFraction) + i = encodeVarintTypes(dAtA, i, uint64(len(m.QuorumFraction))) + i-- + dAtA[i] = 0x12 + } + if m.EpochLength != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.EpochLength)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *AttestationBitmap) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AttestationBitmap) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AttestationBitmap) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SoftConfirmed { + i-- + if m.SoftConfirmed { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + if m.TotalPower != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.TotalPower)) + i-- + dAtA[i] = 0x20 + } + if m.VotedPower != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.VotedPower)) + i-- + dAtA[i] = 0x18 + } + if len(m.Bitmap) > 0 { + i -= len(m.Bitmap) + copy(dAtA[i:], m.Bitmap) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Bitmap))) + i-- + dAtA[i] = 0x12 + } + if m.Height != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ValidatorIndex) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ValidatorIndex) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ValidatorIndex) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Power != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Power)) + i-- + dAtA[i] = 0x18 + } + if m.Index != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x10 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.EpochLength != 0 { + n += 1 + sovTypes(uint64(m.EpochLength)) + } + l = len(m.QuorumFraction) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.MinParticipation) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.PruneAfter != 0 { + n += 1 + sovTypes(uint64(m.PruneAfter)) + } + if m.EmergencyMode { + n += 2 + } + if m.SignMode != 0 { + n += 1 + sovTypes(uint64(m.SignMode)) + } + return n +} + +func (m *AttestationBitmap) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sovTypes(uint64(m.Height)) + } + l = len(m.Bitmap) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.VotedPower != 0 { + n += 1 + sovTypes(uint64(m.VotedPower)) + } + if m.TotalPower != 0 { + n += 1 + sovTypes(uint64(m.TotalPower)) + } + if m.SoftConfirmed { + n += 2 + } + return n +} + +func (m *ValidatorIndex) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.Index != 0 { + n += 1 + sovTypes(uint64(m.Index)) + } + if m.Power != 0 { + n += 1 + sovTypes(uint64(m.Power)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochLength", wireType) + } + m.EpochLength = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EpochLength |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuorumFraction", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QuorumFraction = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinParticipation", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MinParticipation = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PruneAfter", wireType) + } + m.PruneAfter = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PruneAfter |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EmergencyMode", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.EmergencyMode = bool(v != 0) + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SignMode", wireType) + } + m.SignMode = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SignMode |= SignMode(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AttestationBitmap) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AttestationBitmap: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AttestationBitmap: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bitmap", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bitmap = append(m.Bitmap[:0], dAtA[iNdEx:postIndex]...) + if m.Bitmap == nil { + m.Bitmap = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VotedPower", wireType) + } + m.VotedPower = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.VotedPower |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TotalPower", wireType) + } + m.TotalPower = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TotalPower |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SoftConfirmed", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.SoftConfirmed = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ValidatorIndex) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValidatorIndex: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValidatorIndex: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) + } + m.Index = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Index |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Power", wireType) + } + m.Power = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Power |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/modules/proto/buf.lock b/modules/proto/buf.lock index 7eed7030..e3a7af0f 100644 --- a/modules/proto/buf.lock +++ b/modules/proto/buf.lock @@ -5,8 +5,8 @@ deps: commit: 04467658e59e44bbb22fe568206e1f70 digest: b5:8058c0aadbee8c9af67a9cefe86492c6c0b0bd5b4526b0ec820507b91fc9b0b5efbebca97331854576d2d279b0b3f5ed6a7abb0640cb640c4186532239c48fc4 - name: buf.build/cosmos/cosmos-sdk - commit: 34ac2e8322d44db08830e553ad21b93c - digest: b5:381f54c53f533c6ff074a440a4635af5ac4041eb6533c8234b5395465a209b1ecd2722a004f198bcdde77346e0eb789e56213364bf28600619b86a314719ddfb + commit: 650cd9ad7f7a468e8e19975269958658 + digest: b5:652a0cd9aa3c220bb12b558f29b30ca5c248b994420472c9c2a54eed3d33356b1307e51687c1909ea4f535a2a1e180895b8cda83b58a4697003009d17fdbc154 - name: buf.build/cosmos/gogo-proto commit: 88ef6483f90f478fb938c37dde52ece3 digest: b5:f0c69202c9bca9672dc72a9737ea9bc83744daaed2b3da77e3a95b0e53b86dee76b5a7405b993181d6c863fd64afaca0976a302f700d6c4912eb1692a1782c0a diff --git a/modules/proto/rollkitsdk/network/module/v1/module.proto b/modules/proto/rollkitsdk/network/module/v1/module.proto new file mode 100644 index 00000000..42c8bda2 --- /dev/null +++ b/modules/proto/rollkitsdk/network/module/v1/module.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package rollkitsdk.network.module.v1; + +import "cosmos/app/v1alpha1/module.proto"; + +option go_package = "github.com/rollkit/go-execution-abci/modules/network/module/v1"; + +// Module is the config object for the module. +message Module { + option (cosmos.app.v1alpha1.module) = { + go_import: "github.com/rollkit/go-execution-abci/modules/network" + }; + + // authority defines the custom module authority. If not set, defaults to the governance module. + string authority = 1; +} diff --git a/modules/proto/rollkitsdk/network/v1/genesis.proto b/modules/proto/rollkitsdk/network/v1/genesis.proto new file mode 100644 index 00000000..805ea2a5 --- /dev/null +++ b/modules/proto/rollkitsdk/network/v1/genesis.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +package rollkitsdk.network.v1; + +option go_package = "github.com/rollkit/go-execution-abci/modules/network/types"; + +import "gogoproto/gogo.proto"; +import "rollkitsdk/network/v1/types.proto"; + +// GenesisState defines the network module's genesis state. +message GenesisState { + // params defines the module parameters at genesis + Params params = 1 [(gogoproto.nullable) = false]; + + // validator_indices contains the initial validator index mappings + repeated ValidatorIndex validator_indices = 2 [(gogoproto.nullable) = false]; + + // attestation_bitmaps contains historical attestation data + repeated AttestationBitmap attestation_bitmaps = 3 [(gogoproto.nullable) = false]; +} \ No newline at end of file diff --git a/modules/proto/rollkitsdk/network/v1/query.proto b/modules/proto/rollkitsdk/network/v1/query.proto new file mode 100644 index 00000000..aeaf3321 --- /dev/null +++ b/modules/proto/rollkitsdk/network/v1/query.proto @@ -0,0 +1,95 @@ +syntax = "proto3"; + +package rollkitsdk.network.v1; + +option go_package = "github.com/rollkit/go-execution-abci/modules/network/types"; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "rollkitsdk/network/v1/types.proto"; + +// Query defines the gRPC querier service for the network module. +service Query { + // Params queries the module parameters + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/rollkit/network/v1/params"; + } + + // AttestationBitmap queries the attestation bitmap for a specific height + rpc AttestationBitmap(QueryAttestationBitmapRequest) returns (QueryAttestationBitmapResponse) { + option (google.api.http).get = "/rollkit/network/v1/attestation/{height}"; + } + + // EpochInfo queries information about a specific epoch + rpc EpochInfo(QueryEpochInfoRequest) returns (QueryEpochInfoResponse) { + option (google.api.http).get = "/rollkit/network/v1/epoch/{epoch}"; + } + + // ValidatorIndex queries the bitmap index for a validator + rpc ValidatorIndex(QueryValidatorIndexRequest) returns (QueryValidatorIndexResponse) { + option (google.api.http).get = "/rollkit/network/v1/validator/{address}"; + } + + // SoftConfirmationStatus queries if a height is soft-confirmed + rpc SoftConfirmationStatus(QuerySoftConfirmationStatusRequest) returns (QuerySoftConfirmationStatusResponse) { + option (google.api.http).get = "/rollkit/network/v1/soft-confirmation/{height}"; + } +} + +// QueryParamsRequest is the request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method. +message QueryParamsResponse { + // params holds all the parameters of this module. + Params params = 1 [(gogoproto.nullable) = false]; +} + +// QueryAttestationBitmapRequest is the request type for the Query/AttestationBitmap RPC method. +message QueryAttestationBitmapRequest { + int64 height = 1; +} + +// QueryAttestationBitmapResponse is the response type for the Query/AttestationBitmap RPC method. +message QueryAttestationBitmapResponse { + AttestationBitmap bitmap = 1; +} + +// QueryEpochInfoRequest is the request type for the Query/EpochInfo RPC method. +message QueryEpochInfoRequest { + uint64 epoch = 1; +} + +// QueryEpochInfoResponse is the response type for the Query/EpochInfo RPC method. +message QueryEpochInfoResponse { + uint64 epoch = 1; + int64 start_height = 2; + int64 end_height = 3; + bytes participation_bitmap = 4; + uint64 active_validators = 5; + uint64 participating_validators = 6; +} + +// QueryValidatorIndexRequest is the request type for the Query/ValidatorIndex RPC method. +message QueryValidatorIndexRequest { + string address = 1; +} + +// QueryValidatorIndexResponse is the response type for the Query/ValidatorIndex RPC method. +message QueryValidatorIndexResponse { + ValidatorIndex index = 1; +} + +// QuerySoftConfirmationStatusRequest is the request type for the Query/SoftConfirmationStatus RPC method. +message QuerySoftConfirmationStatusRequest { + int64 height = 1; +} + +// QuerySoftConfirmationStatusResponse is the response type for the Query/SoftConfirmationStatus RPC method. +message QuerySoftConfirmationStatusResponse { + bool is_soft_confirmed = 1; + uint64 voted_power = 2; + uint64 total_power = 3; + string quorum_fraction = 4; +} \ No newline at end of file diff --git a/modules/proto/rollkitsdk/network/v1/tx.proto b/modules/proto/rollkitsdk/network/v1/tx.proto new file mode 100644 index 00000000..f555dc8c --- /dev/null +++ b/modules/proto/rollkitsdk/network/v1/tx.proto @@ -0,0 +1,88 @@ +syntax = "proto3"; + +package rollkitsdk.network.v1; + +option go_package = "github.com/rollkit/go-execution-abci/modules/network/types"; + +import "cosmos/msg/v1/msg.proto"; +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "rollkitsdk/network/v1/types.proto"; + +// Msg defines the network module's gRPC message service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // Attest submits a signed vote for a checkpoint + rpc Attest(MsgAttest) returns (MsgAttestResponse); + + // JoinAttesterSet opts a validator into the attester set + rpc JoinAttesterSet(MsgJoinAttesterSet) returns (MsgJoinAttesterSetResponse); + + // LeaveAttesterSet opts a validator out of the attester set + rpc LeaveAttesterSet(MsgLeaveAttesterSet) returns (MsgLeaveAttesterSetResponse); + + // UpdateParams updates the module parameters + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); +} + +// MsgAttest submits a signed vote for a checkpoint +message MsgAttest { + option (cosmos.msg.v1.signer) = "validator"; + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // validator is the address of the validator submitting the attestation + string validator = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + + // height is the checkpoint height being attested + int64 height = 2; + + // vote is the base64-encoded canonical Comet vote + bytes vote = 3; +} + +// MsgAttestResponse is the response type for the Attest RPC +message MsgAttestResponse {} + +// MsgJoinAttesterSet opts a validator into the attester set +message MsgJoinAttesterSet { + option (cosmos.msg.v1.signer) = "validator"; + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // validator is the address of the validator joining + string validator = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; +} + +// MsgJoinAttesterSetResponse is the response type for the JoinAttesterSet RPC +message MsgJoinAttesterSetResponse {} + +// MsgLeaveAttesterSet opts a validator out of the attester set +message MsgLeaveAttesterSet { + option (cosmos.msg.v1.signer) = "validator"; + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // validator is the address of the validator leaving + string validator = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; +} + +// MsgLeaveAttesterSetResponse is the response type for the LeaveAttesterSet RPC +message MsgLeaveAttesterSetResponse {} + +// MsgUpdateParams updates the network module parameters +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + + // authority is the address that controls the module + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // params defines the module parameters to update + Params params = 2 [(gogoproto.nullable) = false]; +} + +// MsgUpdateParamsResponse is the response type for the UpdateParams RPC +message MsgUpdateParamsResponse {} \ No newline at end of file diff --git a/modules/proto/rollkitsdk/network/v1/types.proto b/modules/proto/rollkitsdk/network/v1/types.proto new file mode 100644 index 00000000..a09f2262 --- /dev/null +++ b/modules/proto/rollkitsdk/network/v1/types.proto @@ -0,0 +1,75 @@ +syntax = "proto3"; + +package rollkitsdk.network.v1; + +option go_package = "github.com/rollkit/go-execution-abci/modules/network/types"; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "google/protobuf/duration.proto"; + +// Params defines the parameters for the network module. +message Params { + // epoch_length is the number of blocks per attestation window + uint64 epoch_length = 1; + + // quorum_fraction is the voting power needed for soft-finality (e.g., "2/3") + string quorum_fraction = 2 [(cosmos_proto.scalar) = "cosmos.Dec"]; + + // min_participation is the ejection threshold inside an epoch (e.g., "1/2") + string min_participation = 3 [(cosmos_proto.scalar) = "cosmos.Dec"]; + + // prune_after is the number of epochs to retain attestation bitmaps + uint64 prune_after = 4; + + // emergency_mode is a governance switch to bypass quorum + bool emergency_mode = 5; + + // sign_mode determines when validators must sign + SignMode sign_mode = 6; +} + +// SignMode defines when validators must sign +enum SignMode { + // SIGN_MODE_UNSPECIFIED is invalid + SIGN_MODE_UNSPECIFIED = 0; + + // SIGN_MODE_CHECKPOINT means validators sign only at checkpoint heights + SIGN_MODE_CHECKPOINT = 1; + + // SIGN_MODE_ALL means validators sign every block + SIGN_MODE_ALL = 2; + + // SIGN_MODE_IBC_ONLY means validators sign only blocks with outbound IBC + SIGN_MODE_IBC_ONLY = 3; +} + +// AttestationBitmap stores the bitmap and metadata for a checkpoint +message AttestationBitmap { + // height is the checkpoint height + int64 height = 1; + + // bitmap is the validator participation bitmap + bytes bitmap = 2; + + // voted_power is the total voting power that attested + uint64 voted_power = 3; + + // total_power is the total voting power at this height + uint64 total_power = 4; + + // soft_confirmed indicates if quorum was reached + bool soft_confirmed = 5; +} + +// ValidatorIndex maps a validator address to its bitmap index +message ValidatorIndex { + // address is the validator operator address + string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // index is the position in the bitmap + uint32 index = 2; + + // power is the cached voting power + uint64 power = 3; +} \ No newline at end of file diff --git a/pkg/adapter/adapter.go b/pkg/adapter/adapter.go index cd80f1cc..6ed6ea88 100644 --- a/pkg/adapter/adapter.go +++ b/pkg/adapter/adapter.go @@ -2,8 +2,11 @@ package adapter import ( "context" + "crypto/sha256" + "encoding/hex" "errors" "fmt" + "strings" "time" "cosmossdk.io/log" @@ -43,6 +46,19 @@ type P2PClientInfo interface { Peers() []rollkitp2p.PeerConnection } +// BlockFilter decides if a block commit is build and published +type BlockFilter interface { + IsPublishable(ctx context.Context, height int64) bool +} + +var _ BlockFilter = BlockFilterFn(nil) + +type BlockFilterFn func(ctx context.Context, height int64) bool + +func (b BlockFilterFn) IsPublishable(ctx context.Context, height int64) bool { + return b(ctx, height) +} + // LoadGenesisDoc returns the genesis document from the provided config file. func LoadGenesisDoc(cfg *cmtcfg.Config) (*cmttypes.GenesisDoc, error) { genesisFile := cfg.GenesisFile() @@ -69,7 +85,10 @@ type Adapter struct { AppGenesis *genutiltypes.AppGenesis Logger log.Logger - Metrics *Metrics + metrics *Metrics + + blockFilter BlockFilter + stackedEvents []StackedEvent } // NewABCIExecutor creates a new Adapter instance that implements the go-execution.Executor interface. @@ -82,20 +101,15 @@ func NewABCIExecutor( logger log.Logger, cfg *cmtcfg.Config, appGenesis *genutiltypes.AppGenesis, - metrics *Metrics, + opts ...Option, ) *Adapter { - if metrics == nil { - metrics = NopMetrics() - } - // create rollkit prefix rollkitPrefixStore := kt.Wrap(store, &kt.PrefixTransform{ Prefix: ds.NewKey(rollnode.RollkitPrefix), }) rollkitStore := rstore.New(rollkitPrefixStore) abciStore := NewExecABCIStore(store) - a := &Adapter{ App: app, Store: abciStore, @@ -105,7 +119,12 @@ func NewABCIExecutor( p2pMetrics: p2pMetrics, AppGenesis: appGenesis, MempoolIDs: newMempoolIDs(), - Metrics: metrics, + metrics: NopMetrics(), + blockFilter: BlockFilterFn(func(ctx context.Context, height int64) bool { return true }), + } + + for _, opt := range opts { + opt(a) } return a @@ -132,7 +151,7 @@ func (a *Adapter) Start(ctx context.Context) error { func (a *Adapter) newTxValidator(ctx context.Context) p2p.GossipValidator { return func(m *p2p.GossipMessage) bool { - a.Metrics.TxValidationTotal.Add(1) + a.metrics.TxValidationTotal.Add(1) a.Logger.Debug("transaction received", "bytes", len(m.Data)) msgBytes := m.Data @@ -154,23 +173,23 @@ func (a *Adapter) newTxValidator(ctx context.Context) p2p.GossipValidator { SenderP2PID: corep2p.ID(m.From), }) checkTxDuration := time.Since(checkTxStart).Seconds() - a.Metrics.CheckTxDurationSeconds.Observe(checkTxDuration) + a.metrics.CheckTxDurationSeconds.Observe(checkTxDuration) switch { case errors.Is(err, mempool.ErrTxInCache): - a.Metrics.TxValidationResultTotal.With("result", "rejected_in_cache").Add(1) + a.metrics.TxValidationResultTotal.With("result", "rejected_in_cache").Add(1) return true case errors.Is(err, mempool.ErrMempoolIsFull{}): - a.Metrics.TxValidationResultTotal.With("result", "rejected_mempool_full").Add(1) + a.metrics.TxValidationResultTotal.With("result", "rejected_mempool_full").Add(1) return true case errors.Is(err, mempool.ErrTxTooLarge{}): - a.Metrics.TxValidationResultTotal.With("result", "rejected_too_large").Add(1) + a.metrics.TxValidationResultTotal.With("result", "rejected_too_large").Add(1) return false case errors.Is(err, mempool.ErrPreCheck{}): - a.Metrics.TxValidationResultTotal.With("result", "rejected_precheck").Add(1) + a.metrics.TxValidationResultTotal.With("result", "rejected_precheck").Add(1) return false case err != nil: - a.Metrics.TxValidationResultTotal.With("result", "rejected_checktx_error").Add(1) + a.metrics.TxValidationResultTotal.With("result", "rejected_checktx_error").Add(1) a.Logger.Error("CheckTx failed with unexpected error", "err", err) return false default: @@ -178,17 +197,17 @@ func (a *Adapter) newTxValidator(ctx context.Context) p2p.GossipValidator { select { case <-ctx.Done(): - a.Metrics.TxValidationResultTotal.With("result", "rejected_context_canceled").Add(1) + a.metrics.TxValidationResultTotal.With("result", "rejected_context_canceled").Add(1) return false case checkTxResp := <-checkTxResCh: if checkTxResp.Code == abci.CodeTypeOK { - a.Metrics.TxValidationResultTotal.With("result", "accepted").Add(1) + a.metrics.TxValidationResultTotal.With("result", "accepted").Add(1) return true } - a.Metrics.TxValidationResultTotal.With("result", "rejected_checktx").Add(1) + a.metrics.TxValidationResultTotal.With("result", "rejected_checktx").Add(1) return false case <-time.After(5 * time.Second): - a.Metrics.TxValidationResultTotal.With("result", "rejected_timeout").Add(1) + a.metrics.TxValidationResultTotal.With("result", "rejected_timeout").Add(1) a.Logger.Error("CheckTx response timed out") return false } @@ -199,7 +218,7 @@ func (a *Adapter) newTxValidator(ctx context.Context) p2p.GossipValidator { func (a *Adapter) InitChain(ctx context.Context, genesisTime time.Time, initialHeight uint64, chainID string) ([]byte, uint64, error) { initChainStart := time.Now() defer func() { - a.Metrics.InitChainDurationSeconds.Observe(time.Since(initChainStart).Seconds()) + a.metrics.InitChainDurationSeconds.Observe(time.Since(initChainStart).Seconds()) }() a.Logger.Info("Initializing chain", "chainID", chainID, "initialHeight", initialHeight, "genesisTime", genesisTime) @@ -239,7 +258,7 @@ func (a *Adapter) InitChain(ctx context.Context, genesisTime time.Time, initialH InitialHeight: int64(initialHeight), }) if err != nil { - return nil, 0, err + return nil, 0, fmt.Errorf("app initialize chain: %w", err) } s := &cmtstate.State{} @@ -252,7 +271,7 @@ func (a *Adapter) InitChain(ctx context.Context, genesisTime time.Time, initialH vals, err := cmttypes.PB2TM.ValidatorUpdates(res.Validators) if err != nil { - return nil, 0, err + return nil, 0, fmt.Errorf("validator updates: %w", err) } nValSet := cmttypes.NewValidatorSet(vals) @@ -287,10 +306,10 @@ func (a *Adapter) ExecuteTxs( ) ([]byte, uint64, error) { execStart := time.Now() defer func() { - a.Metrics.BlockExecutionDurationSeconds.Observe(time.Since(execStart).Seconds()) + a.metrics.BlockExecutionDurationSeconds.Observe(time.Since(execStart).Seconds()) }() a.Logger.Info("Executing block", "height", blockHeight, "num_txs", len(txs), "timestamp", timestamp) - a.Metrics.TxsExecutedPerBlock.Observe(float64(len(txs))) + a.metrics.TxsExecutedPerBlock.Observe(float64(len(txs))) s, err := a.Store.LoadState(ctx) if err != nil { @@ -346,6 +365,11 @@ func (a *Adapter) ExecuteTxs( return nil, 0, err } + for i, tx := range txs { + sum256 := sha256.Sum256(tx) + a.Logger.Info("+++ processed TX", "hash", strings.ToUpper(hex.EncodeToString(sum256[:])), "result", fbResp.TxResults[i].Code, "log", fbResp.TxResults[i].Log, "height", blockHeight) + } + s.AppHash = fbResp.AppHash s.LastBlockHeight = int64(blockHeight) @@ -358,7 +382,7 @@ func (a *Adapter) ExecuteTxs( lastHeightValsChanged := s.LastHeightValidatorsChanged if len(validatorUpdates) > 0 { - a.Metrics.ValidatorUpdatesTotal.Add(float64(len(validatorUpdates))) + a.metrics.ValidatorUpdatesTotal.Add(float64(len(validatorUpdates))) err := nValSet.UpdateWithChangeSet(validatorUpdates) if err != nil { return nil, 0, fmt.Errorf("changing validator set: %w", err) @@ -369,7 +393,7 @@ func (a *Adapter) ExecuteTxs( nValSet.IncrementProposerPriority(1) if fbResp.ConsensusParamUpdates != nil { - a.Metrics.ConsensusParamUpdatesTotal.Add(1) + a.metrics.ConsensusParamUpdatesTotal.Add(1) nextParams := s.ConsensusParams.Update(fbResp.ConsensusParamUpdates) err := nextParams.ValidateBasic() if err != nil { @@ -427,13 +451,11 @@ func (a *Adapter) ExecuteTxs( if err != nil { return nil, 0, err } - cmtTxs := make(cmttypes.Txs, len(txs)) for i := range txs { cmtTxs[i] = txs[i] } - // if blockheight is 0, we create a signed last commit. if blockHeight == 0 { lastCommit.Signatures = []cmttypes.CommitSig{ { @@ -452,15 +474,16 @@ func (a *Adapter) ExecuteTxs( PartSetHeader: cmttypes.PartSetHeader{Total: 1, Hash: block.DataHash}, } - if err := fireEvents(a.EventBus, block, currentBlockID, fbResp, validatorUpdates); err != nil { - a.Logger.Error("failed to fire events", "err", err) - } - // save the finalized block response if err := a.Store.SaveBlockResponse(ctx, blockHeight, fbResp); err != nil { return nil, 0, fmt.Errorf("failed to save block response: %w", err) } - + a.stackBlockCommitEvents(currentBlockID, block, fbResp, validatorUpdates) + if a.blockFilter.IsPublishable(ctx, int64(header.Height())) { + if err := a.publishQueuedBlockEvents(ctx, int64(header.Height())); err != nil { + return nil, 0, err + } + } a.Logger.Info("block executed successfully", "height", blockHeight, "appHash", fmt.Sprintf("%X", fbResp.AppHash)) return fbResp.AppHash, uint64(s.ConsensusParams.Block.MaxBytes), nil } @@ -583,11 +606,33 @@ func cometCommitToABCICommitInfo(commit *cmttypes.Commit) abci.CommitInfo { } } +type StackedEvent struct { + blockID cmttypes.BlockID + block *cmttypes.Block + abciResponse *abci.ResponseFinalizeBlock + validatorUpdates []*cmttypes.Validator +} + +func (a *Adapter) stackBlockCommitEvents( + blockID cmttypes.BlockID, + block *cmttypes.Block, + abciResponse *abci.ResponseFinalizeBlock, + validatorUpdates []*cmttypes.Validator, +) { + // todo (Alex): we need this persisted to recover from restart + a.stackedEvents = append(a.stackedEvents, StackedEvent{ + blockID: blockID, + block: block, + abciResponse: abciResponse, + validatorUpdates: validatorUpdates, + }) +} + // GetTxs calls PrepareProposal with the next height from the store and returns the transactions from the ABCI app func (a *Adapter) GetTxs(ctx context.Context) ([][]byte, error) { getTxsStart := time.Now() defer func() { - a.Metrics.GetTxsDurationSeconds.Observe(time.Since(getTxsStart).Seconds()) + a.metrics.GetTxsDurationSeconds.Observe(time.Since(getTxsStart).Seconds()) }() a.Logger.Debug("Getting transactions for proposal") @@ -624,12 +669,47 @@ func (a *Adapter) GetTxs(ctx context.Context) ([][]byte, error) { return nil, err } - a.Metrics.TxsProposedTotal.Add(float64(len(resp.Txs))) + a.metrics.TxsProposedTotal.Add(float64(len(resp.Txs))) return resp.Txs, nil } // SetFinal handles extra logic once the block has been finalized (posted to DA). // For a Cosmos SDK app, this is a no-op we do not need to do anything to mark the block as finalized. func (a *Adapter) SetFinal(ctx context.Context, blockHeight uint64) error { + return a.publishQueuedBlockEvents(ctx, int64(blockHeight)) +} + +func (a *Adapter) publishQueuedBlockEvents(ctx context.Context, persistedHeight int64) error { + maxPosReleased := -1 + for i, v := range a.stackedEvents { + h := v.block.Height + if h <= persistedHeight && a.blockFilter.IsPublishable(ctx, h) { + maxPosReleased = i + } + } + a.Logger.Info("processing stack for soft consensus", "count", len(a.stackedEvents), "soft_consensus", maxPosReleased != -1) + + if maxPosReleased == -1 { + return nil + } + softCommitHeight := a.stackedEvents[maxPosReleased].block.Height +outerLoop: + for i := 0; i <= maxPosReleased; i++ { + // todo (Alex): exit loop when ctx cancelled + select { + case <-ctx.Done(): + maxPosReleased = i + break outerLoop + default: + } + v := a.stackedEvents[i] + + if err := fireEvents(a.EventBus, v.block, v.blockID, v.abciResponse, v.validatorUpdates); err != nil { + return fmt.Errorf("fire events: %w", err) + } + a.Logger.Info("releasing block with soft consensus", "height", v.block.Height, "soft_consensus", softCommitHeight) + } + a.stackedEvents = a.stackedEvents[maxPosReleased+1:] + a.Logger.Info("remaining stack after soft consensus", "count", len(a.stackedEvents), "soft_consensus", softCommitHeight) return nil } diff --git a/pkg/adapter/adapter_test.go b/pkg/adapter/adapter_test.go index 0d9acd9d..741e6221 100644 --- a/pkg/adapter/adapter_test.go +++ b/pkg/adapter/adapter_test.go @@ -81,7 +81,7 @@ func TestExecuteFiresEvents(t *testing.T) { myMockApp := mockApp(myExecResult, spec.mockMutator) originStore := ds.NewMapDatastore() - adapter := NewABCIExecutor(myMockApp, originStore, nil, nil, log.NewTestLogger(t), nil, nil, NopMetrics()) + adapter := NewABCIExecutor(myMockApp, originStore, nil, nil, log.NewTestLogger(t), nil, nil) adapter.EventBus = eventBus adapter.MempoolIDs = newMempoolIDs() adapter.Mempool = &mempool.NopMempool{} diff --git a/pkg/adapter/options.go b/pkg/adapter/options.go new file mode 100644 index 00000000..e9f9aa0f --- /dev/null +++ b/pkg/adapter/options.go @@ -0,0 +1,84 @@ +package adapter + +import ( + "context" + + "cosmossdk.io/log" + abci "github.com/cometbft/cometbft/abci/types" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + + "github.com/rollkit/go-execution-abci/modules/network/types" +) + +// Option is a functional option for configuring the Adapter. +type Option func(*Adapter) + +// WithMetrics sets custom metrics for the Adapter. +func WithMetrics(m *Metrics) Option { + return func(a *Adapter) { + a.metrics = m + } +} + +// WithBlockFilter sets a custom block publisher for the Adapter. +func WithBlockFilter(publisher BlockFilter) Option { + return func(a *Adapter) { + a.blockFilter = publisher + } +} + +// WithNetworkSoftConfirmationBlockFilter creates a BlockFilter that uses the network module's SoftConfirmationStatus. +func WithNetworkSoftConfirmationBlockFilter() Option { + return func(a *Adapter) { + a.blockFilter = &NetworkSoftConfirmationBlockFilter{ + app: a.App, + logger: a.Logger, + } + } +} + +// NetworkSoftConfirmationBlockFilter is a BlockFilter implementation that uses the network module's SoftConfirmationStatus. +type NetworkSoftConfirmationBlockFilter struct { + app servertypes.ABCI + logger log.Logger +} + +// IsPublishable implements the BlockFilter interface. +func (f *NetworkSoftConfirmationBlockFilter) IsPublishable(ctx context.Context, height int64) bool { + // First check if height is valid + if height < 2 { + return false + } + + req := &types.QuerySoftConfirmationStatusRequest{ + Height: height, + } + reqData, err := req.Marshal() + if err != nil { + return false + } + + // Query soft confirmation status + softConfirmReq := &abci.RequestQuery{ + Path: "/rollkitsdk.network.v1.Query/SoftConfirmationStatus", + Data: reqData, + } + + softConfirmRes, err := f.app.Query(ctx, softConfirmReq) + if err != nil || softConfirmRes.Code != 0 { + var msg string + if softConfirmRes != nil { + msg = softConfirmRes.Log + } + f.logger.Error("query soft confirmation status", "height", height, "error", err, "log", msg) + return false + } + + softConfirmResp := &types.QuerySoftConfirmationStatusResponse{} + if err := softConfirmResp.Unmarshal(softConfirmRes.Value); err != nil { + f.logger.Error("unmarshal soft confirmation status response", "height", height, "error", err) + return false + } + f.logger.Debug("soft confirmation status", "height", height, "is_soft_confirmed", softConfirmResp.IsSoftConfirmed) + return softConfirmResp.IsSoftConfirmed +} diff --git a/server/flags.go b/server/flags.go index b650b58c..446d3165 100644 --- a/server/flags.go +++ b/server/flags.go @@ -6,6 +6,8 @@ import ( "github.com/rollkit/rollkit/pkg/config" ) +const FlagNetworkSoftConfirmation = "rollkit.network.soft-confirmation" + // AddFlags adds Rollkit specific configuration options to cobra Command. func AddFlags(cmd *cobra.Command) { def := config.DefaultConfig @@ -13,6 +15,9 @@ func AddFlags(cmd *cobra.Command) { // Add CI flag for testing cmd.Flags().Bool("ci", false, "run node for ci testing") + // Add network flags + cmd.Flags().Bool(FlagNetworkSoftConfirmation, false, "enable soft confirmation by the validator network") + // Add base flags cmd.Flags().String(config.FlagDBPath, def.DBPath, "path for the node database") cmd.Flags().String(config.FlagChainID, def.ChainID, "chain ID") diff --git a/server/start.go b/server/start.go index 2e9368f3..46e9dcfb 100644 --- a/server/start.go +++ b/server/start.go @@ -355,9 +355,14 @@ func setupNodeAndExecutor( return nil, nil, cleanupFn, err } - adapterMetrics := adapter.NopMetrics() + var opts []adapter.Option if rollkitcfg.Instrumentation.IsPrometheusEnabled() { - adapterMetrics = adapter.PrometheusMetrics(config.DefaultInstrumentationConfig().Namespace, "chain_id", cmtGenDoc.ChainID) + m := adapter.PrometheusMetrics(config.DefaultInstrumentationConfig().Namespace, "chain_id", cmtGenDoc.ChainID) + opts = append(opts, adapter.WithMetrics(m)) + } + + if srvCtx.Viper.GetBool(FlagNetworkSoftConfirmation) { + opts = append(opts, adapter.WithNetworkSoftConfirmationBlockFilter()) } executor = adapter.NewABCIExecutor( @@ -368,7 +373,7 @@ func setupNodeAndExecutor( logger, cfg, appGenesis, - adapterMetrics, + opts..., ) cmtApp := server.NewCometABCIWrapper(app)