Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.

Commit e545c3b

Browse files
committed
upgraded dependencies (tokio, bytes, protobuf)
rewrote the server routine to use async-await, as tokio 0.2 requires it (encoder/decoder are now in tokio_util crate; used tokio sync Mutex instead of std) added a panic hook, as otherwise the runtime may hang if internal app panics. as there's no way for apps to be signalled that connection dropped, there's an explicit panic now (so the app can restart from the committed state)
1 parent b139227 commit e545c3b

File tree

10 files changed

+3415
-2300
lines changed

10 files changed

+3415
-2300
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
_July 23, 2020_
4+
5+
## v0.7.2
6+
7+
### IMPROVEMENTS:
8+
9+
- [\#138](https://github.com/tendermint/rust-abci/pull/138): dependencies upgrades (protobuf to 2.16.2, tokio to 0.2, bytes to 0.5)
10+
311
_June 30, 2020_
412

513
## v0.7.1

Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "abci"
3-
version = "0.7.1"
3+
version = "0.7.2"
44
authors = ["Adrian Brink <adrian@brink-holdings.com>", "Jackson Lewis <st.japa6@gmail.com>", "Dave Bryson", "Tomas Tauber"]
55
edition = "2018"
66
license = "MIT/Apache-2.0"
@@ -12,14 +12,15 @@ readme = "README.md"
1212
include = ["src/**/*", "Cargo.toml"]
1313

1414
[dependencies]
15-
bytes = "0.4"
16-
protobuf = "= 2.15.1"
15+
bytes = "0.5"
16+
protobuf = "= 2.16.2"
1717
byteorder = "1.3.4"
1818
integer-encoding = "1.1.5"
1919
log = "0.4.8"
2020
env_logger = "0.7.1"
21-
tokio = { version = "0.1", default-features = false, features = ["codec", "io", "tcp", "rt-full"] }
21+
tokio = { version = "0.2", features = ["tcp", "rt-core", "io-driver", "sync"] }
22+
tokio-util = { version = "0.3.1", features = ["codec"] }
2223
futures = "0.3"
2324

2425
[build-dependencies]
25-
protobuf-codegen-pure = "= 2.15.1"
26+
protobuf-codegen-pure = "= 2.16.2"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Origin
2-
version_branch = v0.33.5
2+
version_branch = v0.33.6
33
tendermint = https://raw.githubusercontent.com/tendermint/tendermint/$(version_branch)
44

55
# Outputs

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ To use this library to build your own ABCI apps in Rust you have to include the
3333

3434
```toml
3535
[dependencies]
36-
abci = "0.7.1"
36+
abci = "0.7.2"
3737
```
3838

3939
### Development
@@ -65,6 +65,7 @@ For a real life example of an ABCI application you can checkout [Cosmos SDK](htt
6565

6666
| Tendermint | Rust-abci |
6767
| ---------- | :-------: |
68+
| 0.33.6 | 0.7.2 |
6869
| 0.33.5 | 0.7.1 |
6970
| 0.33.1 | 0.7.0 |
7071
| 0.32.9 | 0.6.5 |

src/codec.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use std::error::Error;
2-
3-
use bytes::{BufMut, BytesMut};
1+
use bytes::{buf::BufMutExt, BufMut, BytesMut};
42
use integer_encoding::VarInt;
5-
use protobuf::Message;
6-
use tokio::codec::{Decoder, Encoder};
3+
use protobuf::{Message, ProtobufError};
4+
use tokio_util::codec::{Decoder, Encoder};
75

86
use crate::messages::abci::*;
97

@@ -18,9 +16,9 @@ impl ABCICodec {
1816

1917
impl Decoder for ABCICodec {
2018
type Item = Request;
21-
type Error = Box<dyn Error>;
19+
type Error = ProtobufError;
2220

23-
fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Request>, Box<dyn Error>> {
21+
fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Request>, ProtobufError> {
2422
let length = buf.len();
2523
if length == 0 {
2624
return Ok(None);
@@ -30,16 +28,15 @@ impl Decoder for ABCICodec {
3028
return Ok(None);
3129
}
3230
let request = protobuf::parse_from_bytes(&buf[varint.1..(varint.0 as usize + varint.1)])?;
33-
buf.split_to(varint.0 as usize + varint.1);
31+
let _ = buf.split_to(varint.0 as usize + varint.1);
3432
Ok(Some(request))
3533
}
3634
}
3735

38-
impl Encoder for ABCICodec {
39-
type Item = Response;
40-
type Error = Box<dyn Error>;
36+
impl Encoder<Response> for ABCICodec {
37+
type Error = ProtobufError;
4138

42-
fn encode(&mut self, msg: Response, buf: &mut BytesMut) -> Result<(), Box<dyn Error>> {
39+
fn encode(&mut self, msg: Response, buf: &mut BytesMut) -> Result<(), ProtobufError> {
4340
let msg_len = msg.compute_size();
4441
let varint = i64::encode_var_vec(i64::from(msg_len));
4542

@@ -49,7 +46,7 @@ impl Encoder for ABCICodec {
4946
buf.reserve(needed);
5047
}
5148

52-
buf.put(&varint);
49+
buf.put(varint.as_ref());
5350
msg.write_to_writer(&mut buf.writer())?;
5451
trace!("Encode response! {:?}", &buf[..]);
5552
Ok(())
@@ -59,9 +56,10 @@ impl Encoder for ABCICodec {
5956
#[cfg(test)]
6057
mod tests {
6158
use super::*;
59+
use std::error::Error;
6260

6361
fn setup_echo_request_buf() -> Result<BytesMut, Box<dyn Error>> {
64-
let buf = &mut BytesMut::new();
62+
let mut buf = BytesMut::new();
6563

6664
let mut r = Request::new();
6765
let mut echo = RequestEcho::new();
@@ -70,16 +68,16 @@ mod tests {
7068

7169
let msg_len = r.compute_size();
7270
let varint = i64::encode_var_vec(msg_len as i64);
73-
buf.put(varint);
74-
r.write_to_writer(&mut buf.writer())?;
71+
buf.put(varint.as_ref());
72+
r.write_to_writer(&mut (&mut buf).writer())?;
7573

7674
trace!("Encode response! {:?}", &buf[..]);
7775

78-
Ok(buf.take())
76+
Ok(buf)
7977
}
8078

8179
fn setup_echo_large_request_buf() -> Result<BytesMut, Box<dyn Error>> {
82-
let buf = &mut BytesMut::new();
80+
let mut buf = BytesMut::new();
8381

8482
let mut r = Request::new();
8583
let mut echo = RequestEcho::new();
@@ -96,12 +94,12 @@ mod tests {
9694
buf.reserve(needed);
9795
}
9896

99-
buf.put(varint);
100-
r.write_to_writer(&mut buf.writer())?;
97+
buf.put(varint.as_ref());
98+
r.write_to_writer(&mut (&mut buf).writer())?;
10199

102100
trace!("Encode response! {:?}", &buf[..]);
103101

104-
Ok(buf.take())
102+
Ok(buf)
105103
}
106104

107105
#[test]

0 commit comments

Comments
 (0)