style: apply fmt to entire workspace
This commit is contained in:
parent
b55ee1799f
commit
eef3f7afeb
23 changed files with 111 additions and 67 deletions
|
|
@ -1,5 +1,5 @@
|
|||
mod model;
|
||||
mod framework;
|
||||
mod model;
|
||||
|
||||
pub use framework::*;
|
||||
pub use model::*;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ impl<'b, const N: usize> minicbor::Decode<'b> for SkipCbor<N> {
|
|||
impl<const N: usize> minicbor::Encode for SkipCbor<N> {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_e: &mut minicbor::Encoder<W>,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ use net2::TcpStreamExt;
|
|||
use pallas_machines::primitives::Point;
|
||||
use std::net::TcpStream;
|
||||
|
||||
use pallas_blockfetch::BlockFetchClient;
|
||||
use pallas_handshake::{MAINNET_MAGIC, n2n::{Client, VersionTable}};
|
||||
use pallas_blockfetch::{BatchClient, NoopObserver};
|
||||
use pallas_handshake::{
|
||||
n2n::{Client, VersionTable},
|
||||
MAINNET_MAGIC,
|
||||
};
|
||||
use pallas_machines::run_agent;
|
||||
use pallas_multiplexer::Multiplexer;
|
||||
|
||||
|
|
@ -37,7 +40,7 @@ fn main() {
|
|||
);
|
||||
|
||||
let mut bf_channel = muxer.use_channel(3);
|
||||
let bf = BlockFetchClient::initial(range);
|
||||
let bf = BatchClient::initial(range, NoopObserver {});
|
||||
let bf_last = run_agent(bf, &mut bf_channel);
|
||||
println!("{:?}", bf_last);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,18 +94,25 @@ pub trait Observer {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NoopObserver {}
|
||||
|
||||
impl Observer for NoopObserver {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BatchClient<O> where O: Observer {
|
||||
pub struct BatchClient<O>
|
||||
where
|
||||
O: Observer,
|
||||
{
|
||||
pub state: State,
|
||||
pub range: (Point, Point),
|
||||
pub observer: O,
|
||||
}
|
||||
|
||||
impl<O> BatchClient<O> where O: Observer {
|
||||
impl<O> BatchClient<O>
|
||||
where
|
||||
O: Observer,
|
||||
{
|
||||
pub fn initial(range: (Point, Point), observer: O) -> Self {
|
||||
Self {
|
||||
state: State::Idle,
|
||||
|
|
@ -128,7 +135,10 @@ impl<O> BatchClient<O> where O: Observer {
|
|||
}
|
||||
}
|
||||
|
||||
impl<O> Agent for BatchClient<O> where O: Observer {
|
||||
impl<O> Agent for BatchClient<O>
|
||||
where
|
||||
O: Observer,
|
||||
{
|
||||
type Message = Message;
|
||||
|
||||
fn is_done(&self) -> bool {
|
||||
|
|
@ -176,13 +186,19 @@ impl<O> Agent for BatchClient<O> where O: Observer {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OnDemandClient<O> where O: Observer {
|
||||
pub struct OnDemandClient<O>
|
||||
where
|
||||
O: Observer,
|
||||
{
|
||||
pub state: State,
|
||||
pub requests: Receiver<Point>,
|
||||
pub observer: O,
|
||||
}
|
||||
|
||||
impl<O> OnDemandClient<O> where O: Observer {
|
||||
impl<O> OnDemandClient<O>
|
||||
where
|
||||
O: Observer,
|
||||
{
|
||||
pub fn initial(requests: Receiver<Point>, observer: O) -> Self {
|
||||
Self {
|
||||
state: State::Idle,
|
||||
|
|
@ -207,7 +223,10 @@ impl<O> OnDemandClient<O> where O: Observer {
|
|||
}
|
||||
}
|
||||
|
||||
impl<O> Agent for OnDemandClient<O> where O: Observer {
|
||||
impl<O> Agent for OnDemandClient<O>
|
||||
where
|
||||
O: Observer,
|
||||
{
|
||||
type Message = Message;
|
||||
|
||||
// we're never done because we react to external work requests.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
use pallas_chainsync::{ClientConsumer, NoopObserver};
|
||||
use pallas_handshake::{MAINNET_MAGIC, n2c::{Client, VersionTable}};
|
||||
use pallas_handshake::{
|
||||
n2c::{Client, VersionTable},
|
||||
MAINNET_MAGIC,
|
||||
};
|
||||
use pallas_machines::primitives::Point;
|
||||
use pallas_machines::run_agent;
|
||||
use pallas_multiplexer::Multiplexer;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,20 @@ use pallas_machines::{
|
|||
use crate::{BlockBody, Message, State, Tip, WrappedHeader};
|
||||
|
||||
/// An observer of chain-sync events sent by the state-machine
|
||||
pub trait Observer<C> where C: Debug {
|
||||
fn on_block(&self, cursor: &Option<Point>, content: &C) -> Result<(), Box<dyn std::error::Error>> {
|
||||
log::debug!("asked to save block content {:?} at cursor {:?}", content, cursor);
|
||||
pub trait Observer<C>
|
||||
where
|
||||
C: Debug,
|
||||
{
|
||||
fn on_block(
|
||||
&self,
|
||||
cursor: &Option<Point>,
|
||||
content: &C,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
log::debug!(
|
||||
"asked to save block content {:?} at cursor {:?}",
|
||||
content,
|
||||
cursor
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ fn main() {
|
|||
env_logger::init();
|
||||
|
||||
//let bearer = TcpStream::connect("localhost:6000").unwrap();
|
||||
let bearer =
|
||||
TcpStream::connect("relays-new.cardano-mainnet.iohk.io:3001").unwrap();
|
||||
let bearer = TcpStream::connect("relays-new.cardano-mainnet.iohk.io:3001").unwrap();
|
||||
|
||||
bearer.set_nodelay(true).unwrap();
|
||||
bearer.set_keepalive_ms(Some(30_000u32)).unwrap();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
use core::panic;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use pallas_machines::{Agent, CodecError, DecodePayload, EncodePayload, MachineOutput, PayloadDecoder, PayloadEncoder};
|
||||
use pallas_machines::{
|
||||
Agent, CodecError, DecodePayload, EncodePayload, MachineOutput, PayloadDecoder, PayloadEncoder,
|
||||
};
|
||||
|
||||
use crate::common::{NetworkMagic, RefuseReason, VersionNumber};
|
||||
|
||||
|
|
@ -39,11 +41,9 @@ impl VersionTable {
|
|||
}
|
||||
|
||||
pub fn only_v10(network_magic: u64) -> VersionTable {
|
||||
let values = vec![
|
||||
(PROTOCOL_V10, VersionData(network_magic)),
|
||||
]
|
||||
.into_iter()
|
||||
.collect::<HashMap<u64, VersionData>>();
|
||||
let values = vec![(PROTOCOL_V10, VersionData(network_magic))]
|
||||
.into_iter()
|
||||
.collect::<HashMap<u64, VersionData>>();
|
||||
|
||||
VersionTable { values }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
use core::panic;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use pallas_machines::{Agent, CodecError, DecodePayload, EncodePayload, MachineOutput, PayloadDecoder, PayloadEncoder};
|
||||
use pallas_machines::{
|
||||
Agent, CodecError, DecodePayload, EncodePayload, MachineOutput, PayloadDecoder, PayloadEncoder,
|
||||
};
|
||||
|
||||
use crate::common::{RefuseReason, VersionNumber};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
use minicbor::data::Cbor;
|
||||
use pallas_localstate::queries::RequestV10;
|
||||
use pallas_localstate::{OneShotClient, queries::QueryV10};
|
||||
use pallas_handshake::n2c::{Client, VersionTable};
|
||||
use pallas_handshake::{MAINNET_MAGIC};
|
||||
use pallas_machines::{DecodePayload, EncodePayload, run_agent};
|
||||
use pallas_handshake::MAINNET_MAGIC;
|
||||
use pallas_localstate::queries::RequestV10;
|
||||
use pallas_localstate::{queries::QueryV10, OneShotClient};
|
||||
use pallas_machines::run_agent;
|
||||
use pallas_multiplexer::Multiplexer;
|
||||
use std::os::unix::net::UnixStream;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ impl DecodePayload for AcquireFailure {
|
|||
match code {
|
||||
0 => Ok(AcquireFailure::PointTooOld),
|
||||
1 => Ok(AcquireFailure::PointNotInChain),
|
||||
_ => Err(Box::new(CodecError::UnexpectedCbor("can't infer acquire failure from variant id"))),
|
||||
_ => Err(Box::new(CodecError::UnexpectedCbor(
|
||||
"can't infer acquire failure from variant id",
|
||||
))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
pub mod queries;
|
||||
mod codec;
|
||||
pub mod queries;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use log::debug;
|
||||
|
||||
use pallas_machines::{Agent, DecodePayload, EncodePayload, MachineError, MachineOutput, Transition, primitives::Point};
|
||||
use pallas_machines::{
|
||||
primitives::Point, Agent, DecodePayload, EncodePayload, MachineError, MachineOutput, Transition,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum State {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use minicbor::{Decoder, data::Cbor};
|
||||
use pallas_machines::{DecodePayload, EncodePayload, PayloadDecoder, primitives::Point};
|
||||
use minicbor::{data::Cbor, Decoder};
|
||||
use pallas_machines::{primitives::Point, DecodePayload, EncodePayload, PayloadDecoder};
|
||||
|
||||
use super::Query;
|
||||
|
||||
|
|
@ -20,10 +20,8 @@ impl EncodePayload for RequestV10 {
|
|||
e: &mut pallas_machines::PayloadEncoder,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match self {
|
||||
Self::BlockQuery(block_query) => {
|
||||
e.u16(0)?;
|
||||
e.array(0)?;
|
||||
Ok(())
|
||||
Self::BlockQuery(..) => {
|
||||
todo!()
|
||||
}
|
||||
Self::GetSystemStart => {
|
||||
e.u16(1)?;
|
||||
|
|
@ -43,7 +41,7 @@ impl EncodePayload for RequestV10 {
|
|||
|
||||
impl DecodePayload for RequestV10 {
|
||||
fn decode_payload(
|
||||
d: &mut pallas_machines::PayloadDecoder,
|
||||
_d: &mut pallas_machines::PayloadDecoder,
|
||||
) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
|
|
@ -55,7 +53,7 @@ pub struct GenericResponse(Vec<u8>);
|
|||
impl EncodePayload for GenericResponse {
|
||||
fn encode_payload(
|
||||
&self,
|
||||
e: &mut pallas_machines::PayloadEncoder,
|
||||
_e: &mut pallas_machines::PayloadEncoder,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use super::primitives::*;
|
||||
use super::payloads::*;
|
||||
use super::primitives::*;
|
||||
|
||||
impl EncodePayload for Point {
|
||||
fn encode_payload(&self, e: &mut PayloadEncoder) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
mod codec;
|
||||
mod payloads;
|
||||
pub mod primitives;
|
||||
mod codec;
|
||||
|
||||
use log::{debug, trace};
|
||||
use pallas_multiplexer::{Channel, Payload};
|
||||
use std::borrow::Borrow;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::sync::mpsc::{Sender};
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub use payloads::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ use super::*;
|
|||
|
||||
use log::{debug, warn};
|
||||
use minicbor::{Decoder, Encoder};
|
||||
use std::{ops::{Deref, DerefMut}, sync::mpsc::Receiver};
|
||||
use pallas_multiplexer::Payload;
|
||||
use std::{
|
||||
ops::{Deref, DerefMut},
|
||||
sync::mpsc::Receiver,
|
||||
};
|
||||
|
||||
pub struct PayloadEncoder<'a>(Encoder<&'a mut Vec<u8>>);
|
||||
|
||||
|
|
@ -22,7 +25,10 @@ impl<'a> DerefMut for PayloadEncoder<'a> {
|
|||
}
|
||||
|
||||
impl<'a> PayloadEncoder<'a> {
|
||||
pub fn encode_payload<T: EncodePayload>(&mut self, t: &T)->Result<(), Box<dyn std::error::Error>> {
|
||||
pub fn encode_payload<T: EncodePayload>(
|
||||
&mut self,
|
||||
t: &T,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
t.encode_payload(self)
|
||||
}
|
||||
}
|
||||
|
|
@ -95,7 +101,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub trait DecodePayload: Sized {
|
||||
fn decode_payload(d: &mut PayloadDecoder) -> Result<Self, Box<dyn std::error::Error>>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{net::TcpListener, os::unix::net::UnixListener, thread, time::Duration};
|
||||
use std::{os::unix::net::UnixListener, thread, time::Duration};
|
||||
|
||||
use pallas_multiplexer::{Channel, Multiplexer};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{net::TcpStream, os::unix::net::UnixStream, thread, time::Duration};
|
||||
use std::{os::unix::net::UnixStream, thread, time::Duration};
|
||||
|
||||
use pallas_multiplexer::{Channel, Multiplexer};
|
||||
|
||||
|
|
@ -20,9 +20,7 @@ fn main() {
|
|||
loop {
|
||||
let payload = vec![1; 65545];
|
||||
tx.send(payload).unwrap();
|
||||
thread::sleep(Duration::from_millis(
|
||||
50u64 + (protocol as u64 * 10u64),
|
||||
));
|
||||
thread::sleep(Duration::from_millis(50u64 + (protocol as u64 * 10u64)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
mod bearers;
|
||||
|
||||
use std::{collections::HashMap, io::{Read, Write}, sync::mpsc::{self, Receiver, Sender, TryRecvError}, thread::{self, JoinHandle}, time::{Duration, Instant}};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
io::{Read, Write},
|
||||
sync::mpsc::{self, Receiver, Sender, TryRecvError},
|
||||
thread::{self, JoinHandle},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use log::{debug, error, trace, warn};
|
||||
|
||||
|
|
@ -115,7 +121,10 @@ pub struct Multiplexer {
|
|||
}
|
||||
|
||||
impl Multiplexer {
|
||||
pub fn setup<TBearer>(bearer: TBearer, protocols: &[u16]) -> Result<Multiplexer, Box<dyn std::error::Error>>
|
||||
pub fn setup<TBearer>(
|
||||
bearer: TBearer,
|
||||
protocols: &[u16],
|
||||
) -> Result<Multiplexer, Box<dyn std::error::Error>>
|
||||
where
|
||||
TBearer: Bearer + 'static,
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use net2::TcpStreamExt;
|
||||
use std::net::TcpStream;
|
||||
|
||||
use pallas_txsubmission::{NaiveProvider};
|
||||
use pallas_handshake::n2c::{Client, VersionTable};
|
||||
use pallas_handshake::MAINNET_MAGIC;
|
||||
use pallas_machines::run_agent;
|
||||
use pallas_multiplexer::Multiplexer;
|
||||
use pallas_txsubmission::NaiveProvider;
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
|
|
@ -23,7 +23,6 @@ fn main() {
|
|||
let last = run_agent(Client::initial(versions), &mut hs_channel).unwrap();
|
||||
println!("{:?}", last);
|
||||
|
||||
|
||||
let mut ts_channel = muxer.use_channel(4);
|
||||
let ts = NaiveProvider::initial(vec![]);
|
||||
let ts = run_agent(ts, &mut ts_channel).unwrap();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ use std::fmt::Debug;
|
|||
use itertools::Itertools;
|
||||
use log::debug;
|
||||
|
||||
use pallas_machines::{Agent, CodecError, DecodePayload, EncodePayload, MachineError, MachineOutput, PayloadDecoder, PayloadEncoder, Transition};
|
||||
use pallas_machines::{
|
||||
Agent, CodecError, DecodePayload, EncodePayload, MachineError, MachineOutput, PayloadDecoder,
|
||||
PayloadEncoder, Transition,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum State {
|
||||
|
|
@ -238,14 +241,8 @@ impl NaiveProvider {
|
|||
})
|
||||
}
|
||||
|
||||
fn on_txs_request(
|
||||
self,
|
||||
requested_txs: Vec<TxId>,
|
||||
) -> Transition<Self> {
|
||||
debug!(
|
||||
"new txs request {:?}",
|
||||
requested_txs,
|
||||
);
|
||||
fn on_txs_request(self, requested_txs: Vec<TxId>) -> Transition<Self> {
|
||||
debug!("new txs request {:?}", requested_txs,);
|
||||
|
||||
Ok(Self {
|
||||
state: State::Idle,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
|
||||
#[doc(inline)]
|
||||
pub use pallas_alonzo as alonzo;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#[doc(inline)]
|
||||
pub use pallas_multiplexer as multiplexer;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue