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

Decode local-TX-submission errors #495

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions examples/crawler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use pallas::{
ledger::traverse::{MultiEraBlock, MultiEraTx},
network::{
facades::NodeClient,
miniprotocols::{chainsync::NextResponse, Point},
miniprotocols::{chainsync::NextResponse, localtxsubmission::NodeErrorDecoder, Point},
},
};

Expand All @@ -28,9 +28,13 @@ async fn main() -> Result<()> {
let args = Args::parse();

// Connect to the local node over the file socket
let mut client = NodeClient::connect(args.socket_path.clone(), args.network_magic)
.await
.unwrap();
let mut client = NodeClient::connect(
args.socket_path.clone(),
args.network_magic,
NodeErrorDecoder::default(),
)
.await
.unwrap();

// Find an intersection point using the points on the command line
// The response would tell us what point we found, and what the current tip is
Expand Down
16 changes: 11 additions & 5 deletions examples/n2c-miniprotocols/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ use pallas::{
miniprotocols::{
chainsync,
localstate::queries_v16::{self, Addr, Addrs},
localtxsubmission::NodeErrorDecoder,
Point, PRE_PRODUCTION_MAGIC,
},
},
};
use tracing::info;

async fn do_localstate_query(client: &mut NodeClient) {
async fn do_localstate_query(client: &mut NodeClient<'_, NodeErrorDecoder>) {
let client = client.statequery();

client.acquire(None).await.unwrap();
Expand Down Expand Up @@ -81,7 +82,7 @@ async fn do_localstate_query(client: &mut NodeClient) {
client.send_release().await.unwrap();
}

async fn do_chainsync(client: &mut NodeClient) {
async fn do_chainsync<'a>(client: &'a mut NodeClient<'a, NodeErrorDecoder>) {
let known_points = vec![Point::Specific(
43847831u64,
hex::decode("15b9eeee849dd6386d3770b0745e0450190f7560e5159b1b3ab13b14b2684a45").unwrap(),
Expand Down Expand Up @@ -125,11 +126,16 @@ async fn main() {

// we connect to the unix socket of the local node. Make sure you have the right
// path for your environment
let mut client = NodeClient::connect(SOCKET_PATH, PRE_PRODUCTION_MAGIC)
.await
.unwrap();
let mut client = NodeClient::connect(
SOCKET_PATH,
PRE_PRODUCTION_MAGIC,
NodeErrorDecoder::default(),
)
.await
.unwrap();

// execute an arbitrary "Local State" query against the node

do_localstate_query(&mut client).await;

// execute the chainsync flow from an arbitrary point in the chain
Expand Down
1 change: 1 addition & 0 deletions pallas-codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ authors = [

[features]
default = []
half = ["minicbor/half"]

[dependencies]
hex = "0.4.3"
Expand Down
4 changes: 3 additions & 1 deletion pallas-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ authors = ["Santiago Carmuega <santiago@carmuega.me>", "Pi Lanningham <pi.lannin
byteorder = "1.4.3"
hex = "0.4.3"
itertools = "0.13.0"
pallas-codec = { version = "=0.29.0", path = "../pallas-codec" }
pallas-codec = { version = "=0.29.0", path = "../pallas-codec", features = ["half"] }
pallas-crypto = { version = "=0.29.0", path = "../pallas-crypto" }
pallas-primitives = { version = "=0.29.0", path = "../pallas-primitives" }
pallas-utxorpc = { version = "=0.29.0", path = "../pallas-utxorpc" }
rand = "0.8.5"
socket2 = "0.5.5"
thiserror = "1.0.31"
Expand Down
20 changes: 12 additions & 8 deletions pallas-network/src/facades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,17 @@ impl PeerServer {
}

/// Client of N2C Ouroboros
pub struct NodeClient {
pub struct NodeClient<'a, ErrDecoder> {
plexer: RunningPlexer,
handshake: handshake::N2CClient,
chainsync: chainsync::N2CClient,
statequery: localstate::Client,
submission: localtxsubmission::Client,
submission: localtxsubmission::Client<'a, ErrDecoder>,
monitor: txmonitor::Client,
}

impl NodeClient {
pub fn new(bearer: Bearer) -> Self {
impl<'a, ErrDecoder> NodeClient<'a, ErrDecoder> {
pub fn new(bearer: Bearer, local_tx_error_decoder: ErrDecoder) -> Self {
let mut plexer = multiplexer::Plexer::new(bearer);

let hs_channel = plexer.subscribe_client(PROTOCOL_N2C_HANDSHAKE);
Expand All @@ -307,18 +307,22 @@ impl NodeClient {
handshake: handshake::Client::new(hs_channel),
chainsync: chainsync::Client::new(cs_channel),
statequery: localstate::Client::new(sq_channel),
submission: localtxsubmission::Client::new(tx_channel),
submission: localtxsubmission::Client::new(tx_channel, local_tx_error_decoder),
monitor: txmonitor::Client::new(mo_channel),
}
}

#[cfg(unix)]
pub async fn connect(path: impl AsRef<Path>, magic: u64) -> Result<Self, Error> {
pub async fn connect(
path: impl AsRef<Path>,
magic: u64,
err_decoder: ErrDecoder,
) -> Result<Self, Error> {
let bearer = Bearer::connect_unix(path)
.await
.map_err(Error::ConnectFailure)?;

let mut client = Self::new(bearer);
let mut client = Self::new(bearer, err_decoder);

let versions = handshake::n2c::VersionTable::v10_and_above(magic);

Expand Down Expand Up @@ -413,7 +417,7 @@ impl NodeClient {
&mut self.statequery
}

pub fn submission(&mut self) -> &mut localtxsubmission::Client {
pub fn submission(&'a mut self) -> &mut localtxsubmission::Client<'a, ErrDecoder> {
&mut self.submission
}

Expand Down
Loading