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

deleted #902

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ use crate::privval::SignableMsg;
use prost::Message as _;
use std::io::Read;
use tendermint::{chain, Proposal, Vote};
use tendermint_p2p::secret_connection::DATA_MAX_SIZE;
use tendermint_proto as proto;

// TODO(tarcieri): use `tendermint_p2p::secret_connection::DATA_MAX_SIZE`
// See informalsystems/tendermint-rs#1356
const DATA_MAX_SIZE: usize = 262144;

use crate::{
error::{Error, ErrorKind},
prelude::*,
Expand All @@ -31,12 +28,36 @@ pub enum Request {
impl Request {
/// Read a request from the given readable.
pub fn read(conn: &mut impl Read, expected_chain_id: &chain::Id) -> Result<Self, Error> {
let msg_bytes = read_msg(conn)?;

// Parse Protobuf-encoded request message
let msg = proto::privval::Message::decode_length_delimited(msg_bytes.as_ref())
.map_err(|e| format_err!(ErrorKind::ProtocolError, "malformed message packet: {}", e))?
.sum;
let mut msg_bytes: Vec<u8> = vec![];
let msg;

// fix for Sei: collect incoming bytes of Protobuf from incoming msg
loop {
let mut msg_chunk = read_msg(conn)?;
let chunk_len = msg_chunk.len();
msg_bytes.append(&mut msg_chunk);

// if we can decode it, great, break the loop
match proto::privval::Message::decode_length_delimited(msg_bytes.as_ref()) {
Ok(m) => {
msg = m.sum;
break;
}
Err(e) => {
// if chunk_len < DATA_MAX_SIZE (1024) we assume it was the end of the message and it is malformed
if chunk_len < DATA_MAX_SIZE {
return Err(format_err!(
ErrorKind::ProtocolError,
"malformed message packet: {}",
e
)
.into());
}
// otherwise, we go to start of the loop assuming next chunk(s)
// will fill the message
}
}
}

let (req, chain_id) = match msg {
Some(proto::privval::message::Sum::SignVoteRequest(
Expand Down