Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(consensus): add cometInfo to consensus #20615

Merged
merged 13 commits into from
Jun 13, 2024
1,312 changes: 328 additions & 984 deletions api/cosmos/consensus/v1/consensus.pulsar.go

Large diffs are not rendered by default.

1,420 changes: 1,354 additions & 66 deletions api/cosmos/consensus/v1/tx.pulsar.go

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions api/cosmos/consensus/v1/tx_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions x/consensus/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"google.golang.org/grpc/status"

"cosmossdk.io/collections"
coreapp "cosmossdk.io/core/app"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/event"
"cosmossdk.io/x/consensus/exported"
Expand All @@ -25,6 +26,8 @@

authority string
ParamsStore collections.Item[cmtproto.ConsensusParams]
// storage of the last comet info
cometInfo collections.Item[types.CometInfo]
}

var _ exported.ConsensusParamSetter = Keeper{}.ParamsStore
Expand All @@ -35,6 +38,7 @@
Environment: env,
authority: authority,
ParamsStore: collections.NewItem(sb, collections.NewPrefix("Consensus"), "params", codec.CollValue[cmtproto.ConsensusParams](cdc)),
cometInfo: collections.NewItem(sb, collections.NewPrefix("CometInfo"), "comet_info", codec.CollValue[types.CometInfo](cdc)),
}
}

Expand Down Expand Up @@ -99,3 +103,22 @@

return &types.MsgUpdateParamsResponse{}, nil
}

func (k Keeper) CometInfo(ctx context.Context, msg *types.MsgCometInfo) (*types.MsgCometInfoResponse, error) {
if coreapp.ConsensusIdentity != msg.Authority {

Check failure on line 108 in x/consensus/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / dependency-review

invalid operation: coreapp.ConsensusIdentity != msg.Authority (mismatched types []byte and string)

Check failure on line 108 in x/consensus/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid operation: coreapp.ConsensusIdentity != msg.Authority (mismatched types []byte and string)

Check failure on line 108 in x/consensus/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid operation: coreapp.ConsensusIdentity != msg.Authority (mismatched types []byte and string)

Check failure on line 108 in x/consensus/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid operation: coreapp.ConsensusIdentity != msg.Authority (mismatched types []byte and string)
return nil, fmt.Errorf("invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority)
}

cometInfo := types.CometInfo{
Evidence: msg.Evidence,
ValidatorsHash: msg.ValidatorsHash,
ProposerAddress: msg.ProposerAddress,
LastCommit: msg.LastCommit,
}

if err := k.cometInfo.Set(ctx, cometInfo); err != nil {
return nil, err
}

return &types.MsgCometInfoResponse{}, nil
}
26 changes: 8 additions & 18 deletions x/consensus/proto/cosmos/consensus/v1/consensus.proto
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
// Since: cosmos-sdk 0.51
// Since: cosmos-sdk 0.52
syntax = "proto3";
package cosmos.consensus.v1;

import "cometbft/types/v1/params.proto";
import "cometbft/abci/v1/types.proto";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The import path cometbft/abci/v1/types.proto in consensus.proto is incorrect or the file is missing from the repository. Please verify the correct path or ensure that the required file is added to the repository.

  • File: x/consensus/proto/cosmos/consensus/v1/consensus.proto
  • Line: 5
Analysis chain

Ensure the import path is correctly specified and accessible.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the import path for types.proto in the consensus.proto file.

# Test: Search for the import path in the repository. Expect: Path exists.
fd --type file 'types.proto' | grep 'cometbft/abci/v1'

Length of output: 52



Script:

#!/bin/bash
# Description: Search for types.proto in the entire repository to determine its location.

# Test: Search for the types.proto file in the repository. Expect: Path exists.
fd --type file 'types.proto'

Length of output: 221



Script:

#!/bin/bash
# Description: Search for directories or files related to cometbft in the repository.

# Test: Search for any directories or files related to cometbft. Expect: Path exists.
fd --type d 'cometbft' || fd --type f 'cometbft'

Length of output: 42

option go_package = "cosmossdk.io/x/consensus/types";

// ConsensusMsgParams is the Msg/Params request type. This is a consensus message that is sent from cometbft.
message ConsensusMsgParams {
// params defines the x/consensus parameters to be passed from comet.
//
// NOTE: All parameters must be supplied.
cometbft.types.v1.VersionParams version = 1;
cometbft.types.v1.BlockParams block = 2;
cometbft.types.v1.EvidenceParams evidence = 3;
cometbft.types.v1.ValidatorParams validator = 4;
cometbft.types.v1.ABCIParams abci = 5 [deprecated = true];
cometbft.types.v1.SynchronyParams synchrony = 6;
cometbft.types.v1.FeatureParams feature = 7;
// CometInfo defines the structure of the x/consensus module's comet info.
message CometInfo {
repeated cometbft.abci.v1.Misbehavior evidence = 1;
bytes validators_hash = 2;
bytes proposer_address = 3;
cometbft.abci.v1.CommitInfo last_commit = 4;
}

// ConsensusMsgParamsResponse defines the response structure for executing a
// ConsensusMsgParams message.
message ConsensusMsgParamsResponse {}
28 changes: 19 additions & 9 deletions x/consensus/proto/cosmos/consensus/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@ service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cosmos/consensus/v1/params";
}

rpc CometInfo(QueryCometInfoRequest) returns (QueryCometInfoResponse):
}

// QueryParamsRequest defines the request type for querying x/consensus parameters.
message QueryParamsRequest {}
// QueryCometInfoRequest defines the request type for querying x/consensus comet info.
message QueryCometInfoRequest {}

// QueryParamsResponse defines the response type for querying x/consensus parameters.
message QueryParamsResponse {
// params are the tendermint consensus params stored in the consensus module.
// Please note that `params.version` is not populated in this response, it is
// tracked separately in the x/upgrade module.
cometbft.types.v1.ConsensusParams params = 1;
}
// QueryCometInfoResponse defines the response type for querying x/consensus comet info.
message QueryCometInfoResponse {
// comet_info is the comet info of the x/consensus module.
CometInfo comet_info = 1;

// QueryParamsRequest defines the request type for querying x/consensus parameters.
message QueryParamsRequest {}

// QueryParamsResponse defines the response type for querying x/consensus parameters.
message QueryParamsResponse {
// params are the tendermint consensus params stored in the consensus module.
// Please note that `params.version` is not populated in this response, it is
// tracked separately in the x/upgrade module.
cometbft.types.v1.ConsensusParams params = 1;
}
27 changes: 27 additions & 0 deletions x/consensus/proto/cosmos/consensus/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "cometbft/types/v1/params.proto";
import "cometbft/abci/v1/types.proto";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The types.proto file is not located in the cometbft/abci/v1/ directory as specified in the import statement. Instead, the types.proto files are found in different directories, none of which match the expected path. This indicates that the import path in tx.proto is incorrect and needs to be updated to reflect the correct location of the required types.proto.

  • File: x/consensus/proto/cosmos/consensus/v1/tx.proto
  • Line: 9
  • Current Import: import "cometbft/abci/v1/types.proto";

Please update the import path to the correct location based on the actual file structure.

Analysis chain

Ensure the import path for types.proto is correctly specified and accessible.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the import path for types.proto in the tx.proto file.

# Test: Search for the import path in the repository. Expect: Path exists.
fd --type file 'types.proto' | grep 'cometbft/abci/v1'

Length of output: 52



Script:

#!/bin/bash
# Description: Verify the existence of types.proto in the repository and identify its correct path.

# Test: Search for any occurrences of types.proto in the repository.
fd --type file 'types.proto'

Length of output: 221



Script:

#!/bin/bash
# Description: Verify the content of the identified types.proto files to check for the correct import path.

# Test: Display the content of the identified types.proto files.
cat proto/cosmos/base/tendermint/v1beta1/types.proto
cat x/circuit/proto/cosmos/circuit/v1/types.proto
cat x/group/proto/cosmos/group/v1/types.proto
cat x/protocolpool/proto/cosmos/protocolpool/v1/types.proto

Length of output: 19813


option go_package = "cosmossdk.io/x/consensus/types";

Expand All @@ -18,6 +19,8 @@ service Msg {
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) {
option (cosmos_proto.method_added_in) = "cosmos-sdk 0.47";
}

rpc CometInfo(MsgCometInfo) returns (MsgCometInfoResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
Expand Down Expand Up @@ -46,3 +49,27 @@ message MsgUpdateParams {
// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
message MsgUpdateParamsResponse {}

// MsgCometInfo is the Msg/CometInfo request type.
message MsgCometInfo {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "cosmos-sdk/x/consensus/MsgCometInfo";

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// evidence is the misbehaviour evidence to submit.
repeated cometbft.abci.v1.Misbehavior evidence = 2;

// validators_hash is the hash of the current validator set.
bytes validators_hash = 3;

// proposer_address is the address of the current proposer.
bytes proposer_address = 4;

// last_commit is the last commit info.
cometbft.abci.v1.CommitInfo last_commit = 5;
}

// MsgCometInfoResponse defines the response
message MsgCometInfoResponse {}
Loading
Loading