Skip to content

Commit 9b2c206

Browse files
Rebase ABCI Domain Types onto v0.34.20 branch.
There are two issues to fix: * The original ABCI domain types work used `chrono`; this temporarily re-adds `chrono` as a dependency, so that the changes that eliminated it can be replayed on top of this rebasing. * The original ABCI domain types work was, for some reason, mixed in with changes to the RPC test harness for 0.35 compatibility, and that may break this code. I didn't attempt to fix this, because I didn't touch the RPC tests when writing the ABCI domain types. Original concatenation of commit messages follows: Add domain types (updated) and fix integration tests for Tendermint v0.35.0 (cometbft#1022) * tendermint: add From<Infallible> for Error * Use hex for AppHash Debug formatting * Regenerate protobuf types using tools/proto-compiler. * Regenerate protos against tendermint v0.35.0-rc3. * Remove SetOption-related code in tendermint-abci. * Update imports to reflect protobuf movements. The BlockParams and ConsensusParams structs moved out of the ABCI protos. * Update tendermint-abci to reflect upstream proto changes. * p2p: treat all non-Ed25519 keys as unsupported This fixes a compile error introduced by upstream proto changes that add an Sr25519 variant. * Improve ABCI response code modeling with NonZeroU32 The previous data modeling allowed a user to construct an `Err(0)` value that would be serialized and deserialized as `Ok`. * Use the Bytes type in ABCI protos. * Add conversions between protobuf and chrono types. * tendermint: define Serde for Block in terms of RawBlock This changes the Serialize/Deserialize implementations for Block to convert to/from the proto-generated `RawBlock`, and use the derived serialization for that type. This is much cleaner and more maintainable than keeping Serde annotations for each sub-member of the data structure, because all of the serialization code is kept in one place, and there's only one validation path (the TryFrom conversion from RawBlock to Block) that applies to both kinds of serialization. * tendermint: simpler transaction modeling in Block This changes the Block type to hold the transactions as a plain `Vec<Vec<u8>>`, rather than as a custom `abci::transaction::Data` type (which is itself a wrapper for an `Option<Vec<Transaction>>`, the `Transaction` type being a wrapper for a `Vec<u8>`). This also updates the `Block` getter functions; it's not clear (to me) why they're there, since they access the public fields and aren't used anywhere else. * rpc: take over tendermint::abci The existing contents of the `tendermint::abci` module note that they're only for the purpose of implementing the RPC endpoints, not a general ABCI implementation. Moving that code from the `tendermint` crate to the `tendermint-rpc` crate decouples the RPC interface from improvements to the ABCI domain modeling. Eventually, it would be good to eliminate this code and align it with the new ABCI domain types. * tendermint: add ABCI domain types. These types mirror the generated types in tendermint_proto, but have better naming. The documentation for each request type is adapted from the ABCI Methods and Types spec document. However, the same logical request may appear three times, as a struct with the request data, as a Request variant, and as a CategoryRequest variant. To avoid duplication, this PR uses the `#[doc = include_str!(...)]` functionality stabilized in Rust 1.54 to keep common definitions of the documentation. * tendermint: eliminate &'static str errors in ABCI domain types. * Merge `abci::params::ConsensusParams` with `consensus::Params`. The code in the `abci` module had more complete documentation from the ABCI docs, so I copied it onto the existing structure. * Add hex encoding Serde attribute to Sr25519 keys. * Replace integers with `block::Height`, `vote::Power` * Replace integer with block::Round * Fix tools build by using correct imports Signed-off-by: Thane Thomson <[email protected]> * Fix clippy complaints in tools Signed-off-by: Thane Thomson <[email protected]> * Fix clippy warning Signed-off-by: Thane Thomson <[email protected]> * Fix clippy lints Signed-off-by: Thane Thomson <[email protected]> * Fix more clippy lints Signed-off-by: Thane Thomson <[email protected]> * Fix deprecation notices from ed25519 crate Signed-off-by: Thane Thomson <[email protected]> * Regenerate protos for Tendermint v0.35.0 Signed-off-by: Thane Thomson <[email protected]> * Fix raw bytes conversion in tests/docs Signed-off-by: Thane Thomson <[email protected]> * Add Tendermint v0.35.0 Docker config Signed-off-by: Thane Thomson <[email protected]> * Add Tendermint v0.35.0 Docker image for ABCI integration testing Signed-off-by: Thane Thomson <[email protected]> * Remove RPC deserialization tests The support files for these tests were manually generated some time ago. We should rather favour testing with the `kvstore_fixtures` tests, whose fixtures are automatically generated by our rpc-probe tool. Signed-off-by: Thane Thomson <[email protected]> * Reformat Docker folder readme Signed-off-by: Thane Thomson <[email protected]> * Bump version of Tendermint used in ABCI integration test Signed-off-by: Thane Thomson <[email protected]> * Bump version of Tendermint used in rpc probe Signed-off-by: Thane Thomson <[email protected]> * Bump version of Tendermint used in kvstore integration test Signed-off-by: Thane Thomson <[email protected]> * Bump version of Tendermint used in proto-compiler Signed-off-by: Thane Thomson <[email protected]> * Regenerate kvstore fixtures with rpc-probe for Tendermint v0.35.0 Signed-off-by: Thane Thomson <[email protected]> * Update kvstore integration test to accommodate newly generated fixtures Signed-off-by: Thane Thomson <[email protected]> * Update RPC tests and data structures to accommodate Tendermint v0.35.0 changes Signed-off-by: Thane Thomson <[email protected]> * Update ABCI encoding scheme to accommodate breaking change in tendermint/tendermint#5783 Signed-off-by: Thane Thomson <[email protected]> * Bump Tendermint version in GitHub Actions kvstore integration test Signed-off-by: Thane Thomson <[email protected]> * Add changelog entries to capture breaking changes Signed-off-by: Thane Thomson <[email protected]> * Change tx hash encoding from base64 to hex and update tests Signed-off-by: Thane Thomson <[email protected]> * Add changelog entry for /tx endpoint change Signed-off-by: Thane Thomson <[email protected]> Co-authored-by: Henry de Valence <[email protected]> Co-authored-by: Henry de Valence <[email protected]>
1 parent 9b9ed44 commit 9b2c206

File tree

215 files changed

+5098
-2622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+5098
-2622
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Updated integration testing to test against Tendermint v0.35.0
2+
([#862](https://github.com/informalsystems/tendermint-rs/issues/862))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `[tendermint]` Added domain types for ABCI
2+
([#862](https://github.com/informalsystems/tendermint-rs/issues/862))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `[tendermint-abci]` Changed low-level wire encoding protocol to
2+
accommodate <https://github.com/tendermint/tendermint/issues/5783>
3+
([#862](https://github.com/informalsystems/tendermint-rs/issues/862))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- `[tendermint-rpc]` The `event::Event::events` field is now represented as
2+
`Option<Vec<crate::abci::Event>>` as opposed to `Option<HashMap<String,
3+
Vec<String>>>` to accommodate breaking change in Tendermint v0.35.0
4+
subscription interface ([#862](https://github.com/informalsystems/tendermint-
5+
rs/issues/862))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `[tendermint-rpc]` The `/tx` endpoint now encodes
2+
the `hash` parameter as hexadecimal instead of base64
3+
([#862](https://github.com/informalsystems/tendermint-rs/issues/862))

abci/src/application.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tendermint_proto::abci::{
1212
ResponseApplySnapshotChunk, ResponseBeginBlock, ResponseCheckTx, ResponseCommit,
1313
ResponseDeliverTx, ResponseEcho, ResponseEndBlock, ResponseFlush, ResponseInfo,
1414
ResponseInitChain, ResponseListSnapshots, ResponseLoadSnapshotChunk, ResponseOfferSnapshot,
15-
ResponseQuery, ResponseSetOption,
15+
ResponseQuery,
1616
};
1717

1818
/// An ABCI application.
@@ -76,12 +76,6 @@ pub trait Application: Send + Clone + 'static {
7676
Default::default()
7777
}
7878

79-
/// Allows the Tendermint node to request that the application set an
80-
/// option to a particular value.
81-
fn set_option(&self, _request: RequestSetOption) -> ResponseSetOption {
82-
Default::default()
83-
}
84-
8579
/// Used during state sync to discover available snapshots on peers.
8680
fn list_snapshots(&self) -> ResponseListSnapshots {
8781
Default::default()
@@ -123,7 +117,6 @@ impl<A: Application> RequestDispatcher for A {
123117
Value::Echo(req) => response::Value::Echo(self.echo(req)),
124118
Value::Flush(_) => response::Value::Flush(self.flush()),
125119
Value::Info(req) => response::Value::Info(self.info(req)),
126-
Value::SetOption(req) => response::Value::SetOption(self.set_option(req)),
127120
Value::InitChain(req) => response::Value::InitChain(self.init_chain(req)),
128121
Value::Query(req) => response::Value::Query(self.query(req)),
129122
Value::BeginBlock(req) => response::Value::BeginBlock(self.begin_block(req)),

abci/src/application/kvstore.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ use crate::{
5050
/// // Deliver a transaction and then commit the transaction
5151
/// client
5252
/// .deliver_tx(RequestDeliverTx {
53-
/// tx: "test-key=test-value".as_bytes().to_owned(),
53+
/// tx: "test-key=test-value".into(),
5454
/// })
5555
/// .unwrap();
5656
/// client.commit().unwrap();
5757
///
5858
/// // We should be able to query for the data we just delivered above
5959
/// let res = client
6060
/// .query(RequestQuery {
61-
/// data: "test-key".as_bytes().to_owned(),
61+
/// data: "test-key".into(),
6262
/// path: "".to_string(),
6363
/// height: 0,
6464
/// prove: false,
@@ -129,25 +129,25 @@ impl Application for KeyValueStoreApp {
129129
version: "0.1.0".to_string(),
130130
app_version: 1,
131131
last_block_height,
132-
last_block_app_hash,
132+
last_block_app_hash: last_block_app_hash.into(),
133133
}
134134
}
135135

136136
fn query(&self, request: RequestQuery) -> ResponseQuery {
137-
let key = match String::from_utf8(request.data.clone()) {
137+
let key = match std::str::from_utf8(&request.data) {
138138
Ok(s) => s,
139139
Err(e) => panic!("Failed to intepret key as UTF-8: {}", e),
140140
};
141141
debug!("Attempting to get key: {}", key);
142-
match self.get(key.clone()) {
142+
match self.get(key) {
143143
Ok((height, value_opt)) => match value_opt {
144144
Some(value) => ResponseQuery {
145145
code: 0,
146146
log: "exists".to_string(),
147147
info: "".to_string(),
148148
index: 0,
149149
key: request.data,
150-
value: value.into_bytes(),
150+
value: value.into_bytes().into(),
151151
proof_ops: None,
152152
height,
153153
codespace: "".to_string(),
@@ -158,7 +158,7 @@ impl Application for KeyValueStoreApp {
158158
info: "".to_string(),
159159
index: 0,
160160
key: request.data,
161-
value: vec![],
161+
value: Default::default(),
162162
proof_ops: None,
163163
height,
164164
codespace: "".to_string(),
@@ -171,7 +171,7 @@ impl Application for KeyValueStoreApp {
171171
fn check_tx(&self, _request: RequestCheckTx) -> ResponseCheckTx {
172172
ResponseCheckTx {
173173
code: 0,
174-
data: vec![],
174+
data: Default::default(),
175175
log: "".to_string(),
176176
info: "".to_string(),
177177
gas_wanted: 1,
@@ -183,17 +183,17 @@ impl Application for KeyValueStoreApp {
183183
}
184184

185185
fn deliver_tx(&self, request: RequestDeliverTx) -> ResponseDeliverTx {
186-
let tx = String::from_utf8(request.tx).unwrap();
186+
let tx = std::str::from_utf8(&request.tx).unwrap();
187187
let tx_parts = tx.split('=').collect::<Vec<&str>>();
188188
let (key, value) = if tx_parts.len() == 2 {
189189
(tx_parts[0], tx_parts[1])
190190
} else {
191-
(tx.as_ref(), tx.as_ref())
191+
(tx, tx)
192192
};
193193
let _ = self.set(key, value).unwrap();
194194
ResponseDeliverTx {
195195
code: 0,
196-
data: vec![],
196+
data: Default::default(),
197197
log: "".to_string(),
198198
info: "".to_string(),
199199
gas_wanted: 0,
@@ -202,18 +202,18 @@ impl Application for KeyValueStoreApp {
202202
r#type: "app".to_string(),
203203
attributes: vec![
204204
EventAttribute {
205-
key: "key".as_bytes().to_owned(),
206-
value: key.as_bytes().to_owned(),
205+
key: "key".to_string(),
206+
value: key.to_string(),
207207
index: true,
208208
},
209209
EventAttribute {
210-
key: "index_key".as_bytes().to_owned(),
211-
value: "index is working".as_bytes().to_owned(),
210+
key: "index_key".to_string(),
211+
value: "index is working".to_string(),
212212
index: true,
213213
},
214214
EventAttribute {
215-
key: "noindex_key".as_bytes().to_owned(),
216-
value: "index is working".as_bytes().to_owned(),
215+
key: "noindex_key".to_string(),
216+
value: "index is working".to_string(),
217217
index: false,
218218
},
219219
],
@@ -228,7 +228,7 @@ impl Application for KeyValueStoreApp {
228228
let (height, app_hash) = channel_recv(&result_rx).unwrap();
229229
info!("Committed height {}", height);
230230
ResponseCommit {
231-
data: app_hash,
231+
data: app_hash.into(),
232232
retain_height: height - 1,
233233
}
234234
}
@@ -285,7 +285,7 @@ impl KeyValueStoreDriver {
285285
// As in the Go-based key/value store, simply encode the number of
286286
// items as the "app hash"
287287
let mut app_hash = BytesMut::with_capacity(MAX_VARINT_LENGTH);
288-
encode_varint(self.store.len() as u64, &mut app_hash);
288+
prost::encoding::encode_varint(self.store.len() as u64, &mut app_hash);
289289
self.app_hash = app_hash.to_vec();
290290
self.height += 1;
291291
channel_send(&result_tx, (self.height, self.app_hash.clone()))

abci/src/client.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ impl Client {
113113
perform!(self, Commit, RequestCommit {})
114114
}
115115

116-
/// Request that the application set an option to a particular value.
117-
pub fn set_option(&mut self, req: RequestSetOption) -> Result<ResponseSetOption, Error> {
118-
perform!(self, SetOption, req)
119-
}
120-
121116
/// Used during state sync to discover available snapshots on peers.
122117
pub fn list_snapshots(&mut self) -> Result<ResponseListSnapshots, Error> {
123118
perform!(self, ListSnapshots, RequestListSnapshots {})

abci/src/codec.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ where
130130
message.encode(&mut buf).map_err(Error::encode)?;
131131

132132
let buf = buf.freeze();
133-
encode_varint(buf.len() as u64, &mut dst);
133+
prost::encoding::encode_varint(buf.len() as u64, &mut dst);
134134
dst.put(buf);
135135
Ok(())
136136
}
@@ -142,11 +142,11 @@ where
142142
{
143143
let src_len = src.len();
144144
let mut tmp = src.clone().freeze();
145-
let encoded_len = match decode_varint(&mut tmp) {
145+
let encoded_len = match prost::encoding::decode_varint(&mut tmp) {
146146
Ok(len) => len,
147147
// We've potentially only received a partial length delimiter
148148
Err(_) if src_len <= MAX_VARINT_LENGTH => return Ok(None),
149-
Err(e) => return Err(e),
149+
Err(e) => return Err(Error::decode(e)),
150150
};
151151
let remaining = tmp.remaining() as u64;
152152
if remaining < encoded_len {
@@ -164,14 +164,3 @@ where
164164
Ok(Some(res))
165165
}
166166
}
167-
168-
// encode_varint and decode_varint will be removed once
169-
// https://github.com/tendermint/tendermint/issues/5783 lands in Tendermint.
170-
pub fn encode_varint<B: BufMut>(val: u64, mut buf: &mut B) {
171-
prost::encoding::encode_varint(val << 1, &mut buf);
172-
}
173-
174-
pub fn decode_varint<B: Buf>(mut buf: &mut B) -> Result<u64, Error> {
175-
let len = prost::encoding::decode_varint(&mut buf).map_err(Error::decode)?;
176-
Ok(len >> 1)
177-
}

abci/tests/kvstore_app.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ mod kvstore_app_integration {
2525

2626
client
2727
.deliver_tx(RequestDeliverTx {
28-
tx: "test-key=test-value".as_bytes().to_owned(),
28+
tx: "test-key=test-value".into(),
2929
})
3030
.unwrap();
3131
client.commit().unwrap();
3232

3333
let res = client
3434
.query(RequestQuery {
35-
data: "test-key".as_bytes().to_owned(),
35+
data: "test-key".into(),
3636
path: "".to_string(),
3737
height: 0,
3838
prove: false,
3939
})
4040
.unwrap();
41-
assert_eq!(res.value, "test-value".as_bytes().to_owned());
41+
assert_eq!(res.value, "test-value".as_bytes());
4242
}
4343
}

0 commit comments

Comments
 (0)