Anwer tx-submission reqs in chain-sync examples

This commit is contained in:
Santiago Carmuega 2021-11-22 13:20:40 -03:00
parent 4d6c036e01
commit cca715cfc4
3 changed files with 13 additions and 12 deletions

View file

@ -22,3 +22,4 @@ hex = "0.4.3"
net2 = "0.2.37" net2 = "0.2.37"
env_logger = "0.9.0" env_logger = "0.9.0"
pallas-handshake = { path = "../pallas-handshake/" } pallas-handshake = { path = "../pallas-handshake/" }
pallas-txsubmission = { path = "../pallas-txsubmission/" }

View file

@ -1,5 +1,8 @@
use net2::TcpStreamExt; use net2::TcpStreamExt;
use pallas_txsubmission::NaiveProvider;
use std::net::TcpStream; use std::net::TcpStream;
use std::thread;
use std::time::Duration;
use pallas_chainsync::{Consumer, Point}; use pallas_chainsync::{Consumer, Point};
use pallas_handshake::n2c::{Client, VersionTable}; use pallas_handshake::n2c::{Client, VersionTable};
@ -16,12 +19,17 @@ fn main() {
bearer.set_nodelay(true).unwrap(); bearer.set_nodelay(true).unwrap();
bearer.set_keepalive_ms(Some(30_000u32)).unwrap(); bearer.set_keepalive_ms(Some(30_000u32)).unwrap();
let mut handles = Multiplexer::new(bearer, &vec![0, 5]).unwrap(); let mut handles = Multiplexer::new(bearer, &vec![0, 4, 5]).unwrap();
let (_, rx, tx) = handles.remove(0); let (_, rx, tx) = handles.remove(0);
let versions = VersionTable::v1_and_above(MAINNET_MAGIC); let versions = VersionTable::v1_and_above(MAINNET_MAGIC);
let last = run_agent(Client::initial(versions), rx, &tx).unwrap(); let last = run_agent(Client::initial(versions), rx, &tx).unwrap();
println!("{:?}", last); println!("last hanshake state: {:?}", last);
let (_, ts_rx, ts_tx) = handles.remove(0);
let ts = NaiveProvider::initial(vec![]);
let ts = run_agent(ts, ts_rx, &ts_tx).unwrap();
println!("last tx-submission state: {:?}", ts);
let known_points = vec![Point( let known_points = vec![Point(
43847831u64, 43847831u64,
@ -29,9 +37,7 @@ fn main() {
)]; )];
let (_, cs_rx, cs_tx) = handles.remove(0); let (_, cs_rx, cs_tx) = handles.remove(0);
let cs = Consumer::initial(known_points); let cs = Consumer::initial(known_points);
let cs = run_agent(cs, cs_rx, &cs_tx).unwrap(); let cs = run_agent(cs, cs_rx, &cs_tx).unwrap();
println!("{:?}", cs); println!("{:?}", cs);
} }

View file

@ -154,13 +154,7 @@ impl DecodePayload for Message {
Ok(Message::RollBackward(point, tip)) Ok(Message::RollBackward(point, tip))
} }
4 => { 4 => {
let points_len = d let points = Vec::<Point>::decode_payload(d)?;
.array()?
.ok_or(MachineError::UnexpectedCbor("unbounded points array"))?;
let mut points = Vec::with_capacity(points_len as usize);
for i in 0..(points_len - 1) {
points[i as usize] = Point::decode_payload(d)?;
}
Ok(Message::FindIntersect(points)) Ok(Message::FindIntersect(points))
} }
5 => { 5 => {