Skip to content

Backport Thunder 0.12.1, bump version for release 0.12.1 #11

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

Merged
merged 4 commits into from
May 1, 2025
Merged
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
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Ash Manning <[email protected]>"]
edition = "2024"
license-file = "LICENSE.txt"
publish = false
version = "0.12.0"
version = "0.12.1"

[workspace.dependencies]
anyhow = "1.0.72"
Expand Down
9 changes: 8 additions & 1 deletion app/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use clap::{Arg, Parser};
use plain_bitassets::types::{Network, THIS_SIDECHAIN};
use url::{Host, Url};

use crate::util::saturating_pred_level;

const fn ipv4_socket_addr(ipv4_octets: [u8; 4], port: u16) -> SocketAddr {
let [a, b, c, d] = ipv4_octets;
let ipv4 = Ipv4Addr::new(a, b, c, d);
Expand Down Expand Up @@ -179,12 +181,17 @@ impl Cli {
}
}
};
let log_level = if self.headless {
self.log_level
} else {
saturating_pred_level(self.log_level)
};
Ok(Config {
datadir: self.datadir.0,
file_log_level: self.file_log_level,
headless: self.headless,
log_dir,
log_level: self.log_level,
log_level,
mainchain_grpc_url,
mnemonic_seed_phrase_path: self.mnemonic_seed_phrase_path,
net_addr: self.net_addr,
Expand Down
11 changes: 1 addition & 10 deletions app/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@ mod rpc_server;
mod util;

use line_buffer::{LineBuffer, LineBufferWriter};
use util::saturating_pred_level;

/// Saturating predecessor of a log level
fn saturating_pred_level(log_level: tracing::Level) -> tracing::Level {
match log_level {
tracing::Level::TRACE => tracing::Level::DEBUG,
tracing::Level::DEBUG => tracing::Level::INFO,
tracing::Level::INFO => tracing::Level::WARN,
tracing::Level::WARN => tracing::Level::ERROR,
tracing::Level::ERROR => tracing::Level::ERROR,
}
}
/// The empty string target `""` can be used to set a default level.
fn targets_directive_str<'a, Targets>(targets: Targets) -> String
where
Expand Down
11 changes: 11 additions & 0 deletions app/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,14 @@ where
Self(Some(Self::promise(stream)))
}
}

/// Saturating predecessor of a log level
pub fn saturating_pred_level(log_level: tracing::Level) -> tracing::Level {
match log_level {
tracing::Level::TRACE => tracing::Level::DEBUG,
tracing::Level::DEBUG => tracing::Level::INFO,
tracing::Level::INFO => tracing::Level::WARN,
tracing::Level::WARN => tracing::Level::ERROR,
tracing::Level::ERROR => tracing::Level::ERROR,
}
}
15 changes: 15 additions & 0 deletions lib/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{

mod peer;

pub(crate) use peer::error::mailbox::Error as PeerConnectionMailboxError;
use peer::{
Connection, ConnectionContext as PeerConnectionCtxt,
ConnectionHandle as PeerConnectionHandle,
Expand Down Expand Up @@ -266,6 +267,20 @@ impl Net {
}
}

/// Apply the provided function to the peer connection handle,
/// if it exists.
pub fn try_with_active_peer_connection<F, T>(
&self,
addr: SocketAddr,
f: F,
) -> Option<T>
where
F: FnMut(&PeerConnectionHandle) -> T,
{
let active_peers_read = self.active_peers.read();
active_peers_read.get(&addr).map(f)
}

// TODO: This should have more context.
// Last received message, connection state, etc.
pub fn get_active_peers(&self) -> Vec<Peer> {
Expand Down
9 changes: 6 additions & 3 deletions lib/net/peer/channel_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ use async_lock::{Semaphore, SemaphoreGuardArc};
use futures::{FutureExt as _, Stream, StreamExt as _, future::Either, stream};
use tokio::task::AbortHandle;

use crate::net::peer::{
Connection, PeerResponseItem, error, join_set,
message::{Heartbeat, Request},
use crate::{
net::peer::{
Connection, PeerResponseItem, error,
message::{Heartbeat, Request},
},
util::join_set,
};

/// Type tags for channel limiters
Expand Down
2 changes: 1 addition & 1 deletion lib/net/peer/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub(in crate::net::peer) mod request_queue {
}
}

pub(in crate::net::peer) mod mailbox {
pub mod mailbox {
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Heartbeat timeout")]
Expand Down
94 changes: 0 additions & 94 deletions lib/net/peer/join_set.rs

This file was deleted.

22 changes: 19 additions & 3 deletions lib/net/peer/mailbox.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//! Mailbox for a peer connection task

use std::sync::{
Arc,
atomic::{self, AtomicBool},
};

use futures::{
Stream, StreamExt as _, TryFutureExt as _, channel::mpsc, stream,
};
Expand Down Expand Up @@ -65,9 +70,12 @@ pub struct Receiver {
}

impl Receiver {
/// `received_msg_successfully` is set to `True` if a valid message is
/// received successfully.
pub fn into_stream(
self,
connection: Connection,
received_msg_successfully: &Arc<AtomicBool>,
) -> impl Stream<Item = MailboxItem> + Unpin {
let (peer_response_tx, peer_response_rx) = mpsc::unbounded();
let internal_message_stream =
Expand All @@ -81,10 +89,14 @@ impl Receiver {
.map(|err| MailboxItem::Error(err.into()));
let peer_request_stream = stream::try_unfold((), move |()| {
let conn = connection.clone();
let received_msg_successfully = received_msg_successfully.clone();
let fut = async move {
let item = timeout(
Connection::HEARTBEAT_TIMEOUT_INTERVAL,
conn.receive_request(),
conn.receive_request().inspect_ok(|_| {
received_msg_successfully
.store(true, atomic::Ordering::SeqCst);
}),
)
.map_err(|_| Error::HeartbeatTimeout)
.await??;
Expand All @@ -96,8 +108,12 @@ impl Receiver {
Ok(peer_request) => MailboxItem::PeerRequest(peer_request),
Err(err) => MailboxItem::Error(err),
});
let peer_response_stream =
peer_response_rx.map(MailboxItem::PeerResponse);
let peer_response_stream = peer_response_rx.map(|resp| {
if resp.response.is_ok() {
received_msg_successfully.store(true, atomic::Ordering::SeqCst);
}
MailboxItem::PeerResponse(resp)
});
stream::select_all([
internal_message_stream.boxed(),
heartbeat_stream.boxed(),
Expand Down
4 changes: 2 additions & 2 deletions lib/net/peer/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ pub struct GetHeadersRequest {
impl GetHeadersRequest {
/// Limit bytes to read in a response to a request
pub const fn read_response_limit(&self) -> NonZeroUsize {
// 1KB limit per header
// 2KB limit per header
const READ_HEADER_LIMIT: NonZeroUsize =
NonZeroUsize::new(1024).unwrap();
NonZeroUsize::new(2048).unwrap();
let expected_headers = self.height.expect(
"GetHeaders height should always be Some in an outbound request",
) as usize
Expand Down
Loading
Loading