Skip to content

Commit 8245521

Browse files
committed
Downgrade cometbft-rs to use v0_38 protos
Most chains haven't updated to CometBFT v1 yet. In PR #976, @melekes was prospectively exploring what it would take to support multiple versions concurrently, but for now this seems like the safest default.
1 parent 96c732f commit 8245521

File tree

7 files changed

+127
-113
lines changed

7 files changed

+127
-113
lines changed

src/commands/ledger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Runnable for InitCommand {
5555
let registry = chain::REGISTRY.get();
5656
let chain = registry.get_chain(&chain_id).unwrap();
5757

58-
let vote = proto::types::v1::Vote {
58+
let vote = proto::types::v1beta1::Vote {
5959
height: self.height.unwrap(),
6060
round: self.round.unwrap() as i32,
6161
r#type: ConsensusMsgType::Proposal.into(),

src/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod unix;
1010

1111
/// Connections to a validator
1212
pub trait Connection:
13-
ReadMsg<proto::privval::v1::Message> + WriteMsg<proto::privval::v1::Message> + Sync + Send
13+
ReadMsg<proto::privval::v1beta1::Message> + WriteMsg<proto::privval::v1beta1::Message> + Sync + Send
1414
{
1515
}
1616

src/keyring/signature.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ impl From<Signature> for cometbft::Signature {
4242
}
4343

4444
// TODO(tarcieri): vendor the `SignedRawBytes*` protos
45-
// impl From<Signature> for proto::privval::v1::SignedRawBytesResponse {
45+
// impl From<Signature> for proto::privval::v1beta1::SignedRawBytesResponse {
4646
// fn from(sig: Signature) -> Self {
47-
// proto::privval::v1::SignedRawBytesResponse {
47+
// proto::privval::v1beta1::SignedRawBytesResponse {
4848
// signature: sig.to_vec(),
4949
// error: None,
5050
// }

src/privval.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl ConsensusMsg {
5454

5555
match self {
5656
Self::Proposal(proposal) => {
57-
let canonical = proto::types::v1::CanonicalProposal {
57+
let canonical = proto::types::v1beta1::CanonicalProposal {
5858
chain_id: chain_id.to_string(),
5959
r#type: ConsensusMsgType::Proposal.into(),
6060
height: proposal.height.into(),
@@ -70,7 +70,7 @@ impl ConsensusMsg {
7070
canonical.encode_length_delimited(&mut bytes)?;
7171
}
7272
Self::Vote(vote) => {
73-
let canonical = proto::types::v1::CanonicalVote {
73+
let canonical = proto::types::v1beta1::CanonicalVote {
7474
r#type: vote.vote_type.into(),
7575
height: vote.height.into(),
7676
round: vote.round.value().into(),
@@ -94,7 +94,7 @@ impl ConsensusMsg {
9494
// Only sign extension if it's a precommit for a non-nil block.
9595
// Note that extension can be empty.
9696
(vote::Type::Precommit, Some(_)) => {
97-
let canonical = proto::types::v1::CanonicalVoteExtension {
97+
let canonical = proto::v0_38::types::CanonicalVoteExtension {
9898
extension: v.extension.clone(),
9999
height: v.height.into(),
100100
round: v.round.value().into(),
@@ -171,18 +171,18 @@ impl From<Vote> for ConsensusMsg {
171171
}
172172
}
173173

174-
impl TryFrom<proto::types::v1::Proposal> for ConsensusMsg {
174+
impl TryFrom<proto::types::v1beta1::Proposal> for ConsensusMsg {
175175
type Error = Error;
176176

177-
fn try_from(proposal: proto::types::v1::Proposal) -> Result<Self, Self::Error> {
177+
fn try_from(proposal: proto::types::v1beta1::Proposal) -> Result<Self, Self::Error> {
178178
Proposal::try_from(proposal).map(Self::Proposal)
179179
}
180180
}
181181

182-
impl TryFrom<proto::types::v1::Vote> for ConsensusMsg {
182+
impl TryFrom<proto::types::v1beta1::Vote> for ConsensusMsg {
183183
type Error = Error;
184184

185-
fn try_from(vote: proto::types::v1::Vote) -> Result<Self, Self::Error> {
185+
fn try_from(vote: proto::types::v1beta1::Vote) -> Result<Self, Self::Error> {
186186
Vote::try_from(vote).map(Self::Vote)
187187
}
188188
}
@@ -225,24 +225,24 @@ impl From<ConsensusMsgType> for SignedMsgCode {
225225
}
226226
}
227227

228-
impl From<ConsensusMsgType> for proto::types::v1::SignedMsgType {
229-
fn from(msg_type: ConsensusMsgType) -> proto::types::v1::SignedMsgType {
228+
impl From<ConsensusMsgType> for proto::types::v1beta1::SignedMsgType {
229+
fn from(msg_type: ConsensusMsgType) -> proto::types::v1beta1::SignedMsgType {
230230
match msg_type {
231-
ConsensusMsgType::Unknown => proto::types::v1::SignedMsgType::Unknown,
232-
ConsensusMsgType::Prevote => proto::types::v1::SignedMsgType::Prevote,
233-
ConsensusMsgType::Precommit => proto::types::v1::SignedMsgType::Precommit,
234-
ConsensusMsgType::Proposal => proto::types::v1::SignedMsgType::Proposal,
231+
ConsensusMsgType::Unknown => proto::types::v1beta1::SignedMsgType::Unknown,
232+
ConsensusMsgType::Prevote => proto::types::v1beta1::SignedMsgType::Prevote,
233+
ConsensusMsgType::Precommit => proto::types::v1beta1::SignedMsgType::Precommit,
234+
ConsensusMsgType::Proposal => proto::types::v1beta1::SignedMsgType::Proposal,
235235
}
236236
}
237237
}
238238

239-
impl From<proto::types::v1::SignedMsgType> for ConsensusMsgType {
240-
fn from(proto: proto::types::v1::SignedMsgType) -> ConsensusMsgType {
239+
impl From<proto::types::v1beta1::SignedMsgType> for ConsensusMsgType {
240+
fn from(proto: proto::types::v1beta1::SignedMsgType) -> ConsensusMsgType {
241241
match proto {
242-
proto::types::v1::SignedMsgType::Unknown => Self::Unknown,
243-
proto::types::v1::SignedMsgType::Prevote => Self::Prevote,
244-
proto::types::v1::SignedMsgType::Precommit => Self::Precommit,
245-
proto::types::v1::SignedMsgType::Proposal => Self::Proposal,
242+
proto::types::v1beta1::SignedMsgType::Unknown => Self::Unknown,
243+
proto::types::v1beta1::SignedMsgType::Prevote => Self::Prevote,
244+
proto::types::v1beta1::SignedMsgType::Precommit => Self::Precommit,
245+
proto::types::v1beta1::SignedMsgType::Proposal => Self::Proposal,
246246
}
247247
}
248248
}
@@ -260,7 +260,7 @@ impl TryFrom<SignedMsgCode> for ConsensusMsgType {
260260
type Error = Error;
261261

262262
fn try_from(code: SignedMsgCode) -> Result<Self, Self::Error> {
263-
proto::types::v1::SignedMsgType::try_from(code)
263+
proto::types::v1beta1::SignedMsgType::try_from(code)
264264
.map(Into::into)
265265
.map_err(|e| Error::parse(e.to_string()))
266266
}
@@ -285,7 +285,7 @@ mod tests {
285285
}
286286

287287
fn example_proposal() -> Proposal {
288-
proto::types::v1::Proposal {
288+
proto::types::v1beta1::Proposal {
289289
r#type: ConsensusMsgType::Proposal.into(),
290290
height: 12345,
291291
round: 1,
@@ -299,14 +299,14 @@ mod tests {
299299
}
300300

301301
fn example_vote() -> Vote {
302-
proto::types::v1::Vote {
302+
proto::types::v1beta1::Vote {
303303
r#type: 0x01,
304304
height: 500001,
305305
round: 2,
306306
timestamp: Some(example_timestamp()),
307-
block_id: Some(proto::types::v1::BlockId {
307+
block_id: Some(proto::types::v1beta1::BlockId {
308308
hash: b"some hash00000000000000000000000".to_vec(),
309-
part_set_header: Some(proto::types::v1::PartSetHeader {
309+
part_set_header: Some(proto::types::v1beta1::PartSetHeader {
310310
total: 1000000,
311311
hash: b"parts_hash0000000000000000000000".to_vec(),
312312
}),
@@ -317,8 +317,8 @@ mod tests {
317317
],
318318
validator_index: 56789,
319319
signature: vec![],
320-
extension: vec![],
321-
extension_signature: vec![],
320+
//extension: vec![],
321+
//extension_signature: vec![],
322322
}
323323
.try_into()
324324
.unwrap()

src/rpc.rs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum Request {
2020
SignProposal(Proposal),
2121
/// Sign the given vote
2222
SignVote((Vote, bool)), // skip_extension_signing
23-
// SignRawBytes(proto::privval::v1::SignRawBytesRequest), TODO(tarcieri): vendor protos
23+
// SignRawBytes(proto::privval::v1beta1::SignRawBytesRequest), TODO(tarcieri): vendor protos
2424
ShowPublicKey,
2525
PingRequest,
2626
}
@@ -34,31 +34,31 @@ impl Request {
3434
let msg = conn.read_msg()?;
3535

3636
let (req, chain_id) = match msg.sum {
37-
Some(proto::privval::v1::message::Sum::SignVoteRequest(
38-
proto::privval::v1::SignVoteRequest {
37+
Some(proto::privval::v1beta1::message::Sum::SignVoteRequest(
38+
proto::privval::v1beta1::SignVoteRequest {
3939
vote: Some(vote),
4040
chain_id,
41-
skip_extension_signing,
41+
//skip_extension_signing,
4242
},
4343
)) => (
44-
Request::SignVote((vote.try_into()?, skip_extension_signing)),
44+
Request::SignVote((vote.try_into()?, false)), //skip_extension_signing)),
4545
chain_id,
4646
),
47-
Some(proto::privval::v1::message::Sum::SignProposalRequest(
48-
proto::privval::v1::SignProposalRequest {
47+
Some(proto::privval::v1beta1::message::Sum::SignProposalRequest(
48+
proto::privval::v1beta1::SignProposalRequest {
4949
proposal: Some(proposal),
5050
chain_id,
5151
},
5252
)) => (Request::SignProposal(proposal.try_into()?), chain_id),
5353
// TODO(tarcieri): vendor protos
54-
// Some(proto::privval::v1::message::Sum::SignRawBytesRequest(req)) => {
54+
// Some(proto::privval::v1beta1::message::Sum::SignRawBytesRequest(req)) => {
5555
// let chain_id = req.chain_id.clone();
5656
// (Request::SignRawBytes(req), chain_id)
5757
// }
58-
Some(proto::privval::v1::message::Sum::PubKeyRequest(req)) => {
58+
Some(proto::privval::v1beta1::message::Sum::PubKeyRequest(req)) => {
5959
(Request::ShowPublicKey, req.chain_id)
6060
}
61-
Some(proto::privval::v1::message::Sum::PingRequest(_)) => {
61+
Some(proto::privval::v1beta1::message::Sum::PingRequest(_)) => {
6262
return Ok(Request::PingRequest);
6363
}
6464
_ => fail!(ErrorKind::ProtocolError, "invalid RPC message: {:?}", msg),
@@ -94,47 +94,51 @@ impl Request {
9494
/// RPC responses from the KMS
9595
#[derive(Debug)]
9696
pub enum Response {
97-
SignedVote(proto::privval::v1::SignedVoteResponse),
98-
SignedProposal(proto::privval::v1::SignedProposalResponse),
99-
// SignedRawBytes(proto::privval::v1::SignedRawBytesResponse), TODO(tarcieri): vendor protos
100-
Ping(proto::privval::v1::PingResponse),
101-
PublicKey(proto::privval::v1::PubKeyResponse),
97+
SignedVote(proto::privval::v1beta1::SignedVoteResponse),
98+
SignedProposal(proto::privval::v1beta1::SignedProposalResponse),
99+
// SignedRawBytes(proto::privval::v1beta1::SignedRawBytesResponse), TODO(tarcieri): vendor protos
100+
Ping(proto::privval::v1beta1::PingResponse),
101+
PublicKey(proto::privval::v1beta1::PubKeyResponse),
102102
}
103103

104104
impl Response {
105-
/// Convert into a `privval::v1::Message` proto.
106-
pub fn to_proto(self) -> proto::privval::v1::Message {
105+
/// Convert into a `privval::v1beta1::Message` proto.
106+
pub fn to_proto(self) -> proto::privval::v1beta1::Message {
107107
let sum = match self {
108108
Response::SignedVote(resp) => {
109-
proto::privval::v1::message::Sum::SignedVoteResponse(resp)
109+
proto::privval::v1beta1::message::Sum::SignedVoteResponse(resp)
110110
}
111111
Response::SignedProposal(resp) => {
112-
proto::privval::v1::message::Sum::SignedProposalResponse(resp)
112+
proto::privval::v1beta1::message::Sum::SignedProposalResponse(resp)
113113
}
114114
// TODO(tarcieri): vendor protos
115115
// Response::SignedRawBytes(resp) => {
116-
// proto::privval::v1::message::Sum::SignedRawBytesResponse(resp)
116+
// proto::privval::v1beta1::message::Sum::SignedRawBytesResponse(resp)
117117
// }
118-
Response::Ping(resp) => proto::privval::v1::message::Sum::PingResponse(resp),
119-
Response::PublicKey(resp) => proto::privval::v1::message::Sum::PubKeyResponse(resp),
118+
Response::Ping(resp) => proto::privval::v1beta1::message::Sum::PingResponse(resp),
119+
Response::PublicKey(resp) => {
120+
proto::privval::v1beta1::message::Sum::PubKeyResponse(resp)
121+
}
120122
};
121123

122-
proto::privval::v1::Message { sum: Some(sum) }
124+
proto::privval::v1beta1::Message { sum: Some(sum) }
123125
}
124126

125127
/// Construct an error response for a given [`ConsensusMsg`].
126-
pub fn error(msg: ConsensusMsg, error: proto::privval::v1::RemoteSignerError) -> Response {
128+
pub fn error(msg: ConsensusMsg, error: proto::privval::v1beta1::RemoteSignerError) -> Response {
127129
match msg {
128130
ConsensusMsg::Proposal(_) => {
129-
Response::SignedProposal(proto::privval::v1::SignedProposalResponse {
131+
Response::SignedProposal(proto::privval::v1beta1::SignedProposalResponse {
130132
proposal: None,
131133
error: Some(error),
132134
})
133135
}
134-
ConsensusMsg::Vote(_) => Response::SignedVote(proto::privval::v1::SignedVoteResponse {
135-
vote: None,
136-
error: Some(error),
137-
}),
136+
ConsensusMsg::Vote(_) => {
137+
Response::SignedVote(proto::privval::v1beta1::SignedVoteResponse {
138+
vote: None,
139+
error: Some(error),
140+
})
141+
}
138142
}
139143
}
140144
}
@@ -143,13 +147,13 @@ impl From<ConsensusMsg> for Response {
143147
fn from(msg: ConsensusMsg) -> Response {
144148
match msg {
145149
ConsensusMsg::Proposal(proposal) => {
146-
Response::SignedProposal(proto::privval::v1::SignedProposalResponse {
150+
Response::SignedProposal(proto::privval::v1beta1::SignedProposalResponse {
147151
proposal: Some(proposal.into()),
148152
error: None,
149153
})
150154
}
151155
ConsensusMsg::Vote(vote) => {
152-
Response::SignedVote(proto::privval::v1::SignedVoteResponse {
156+
Response::SignedVote(proto::privval::v1beta1::SignedVoteResponse {
153157
vote: Some(vote.into()),
154158
error: None,
155159
})

src/session.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl Session {
117117
// Request::SignRawBytes(req) => self.sign_raw(req)?,
118118

119119
// non-signable requests:
120-
Request::PingRequest => Response::Ping(proto::privval::v1::PingResponse {}),
120+
Request::PingRequest => Response::Ping(proto::privval::v1beta1::PingResponse {}),
121121
Request::ShowPublicKey => self.get_public_key()?,
122122
};
123123

@@ -181,7 +181,7 @@ impl Session {
181181
// /// Sign a raw (non-consensus) message.
182182
// fn sign_raw(
183183
// &mut self,
184-
// req: proto::privval::v1::SignRawBytesRequest,
184+
// req: proto::privval::v1beta1::SignRawBytesRequest,
185185
// ) -> Result<Response, Error> {
186186
// /// Domain separation prefix to prevent confusion with consensus message signatures.
187187
// const PREFIX: &[u8] = b"COMET::RAW_BYTES::SIGN";
@@ -248,7 +248,7 @@ impl Session {
248248
&mut self,
249249
chain: &Chain,
250250
signable_msg: &ConsensusMsg,
251-
) -> Result<Option<proto::privval::v1::RemoteSignerError>, Error> {
251+
) -> Result<Option<proto::privval::v1beta1::RemoteSignerError>, Error> {
252252
let msg_type = signable_msg.msg_type();
253253
let request_state = signable_msg.consensus_state();
254254
let mut chain_state = chain.state.lock().unwrap();
@@ -291,11 +291,12 @@ impl Session {
291291
CometbftKey::ConsensusKey(pk) => pk,
292292
};
293293

294-
Ok(Response::PublicKey(proto::privval::v1::PubKeyResponse {
295-
pub_key_bytes: pub_key.to_bytes(),
296-
pub_key_type: pub_key.type_str().to_owned(),
297-
error: None,
298-
}))
294+
Ok(Response::PublicKey(
295+
proto::privval::v1beta1::PubKeyResponse {
296+
pub_key: Some(pub_key.into()),
297+
error: None,
298+
},
299+
))
299300
}
300301

301302
/// Write an INFO logline about a signing request
@@ -322,11 +323,11 @@ impl Session {
322323
}
323324

324325
/// Double signing handler.
325-
fn double_sign(consensus_state: consensus::State) -> proto::privval::v1::RemoteSignerError {
326+
fn double_sign(consensus_state: consensus::State) -> proto::privval::v1beta1::RemoteSignerError {
326327
/// Double signing error code.
327328
const DOUBLE_SIGN_ERROR: i32 = 2;
328329

329-
proto::privval::v1::RemoteSignerError {
330+
proto::privval::v1beta1::RemoteSignerError {
330331
code: DOUBLE_SIGN_ERROR,
331332
description: format!(
332333
"double signing requested at height: {}",

0 commit comments

Comments
 (0)