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

feat(sidecar): firewall delegation #552

Draft
wants to merge 10 commits into
base: unstable
Choose a base branch
from

Conversation

thedevbirb
Copy link
Contributor

No description provided.

@thedevbirb thedevbirb force-pushed the lore/feat/firewall-delegation branch from e17add1 to ab05565 Compare December 12, 2024 10:52
Copy link
Collaborator

@merklefruit merklefruit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some initial comments; the actual request processor looks great so far but I will try it out in more detail later, also really nice seeing those tests :)

long,
env = "BOLT_SIDECAR_FIREWALL_RPC",
value_delimiter = ',',
conflicts_with("commitments_port")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
conflicts_with("commitments_port")
conflicts_with("port")

pub struct CommitmentOpts {
/// Port to listen on for incoming JSON-RPC requests of the Commitments API.
/// This port should be open on your firewall in order to receive external requests!
#[clap(long, env = "BOLT_SIDECAR_PORT", default_value = stringify!(DEFAULT_RPC_PORT))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the current logic, won't this default value always default to using the commitments server even if you don't specify it?

group = ArgGroup::new("commitments-opts").required(true)
.args(&["commitments_port", "firewall_rpc"])
)]
pub struct CommitmentOpts {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of this pattern to match on which method to use?

BOLT_SIDECAR_COMMITMENT_SERVER_PORT=8017
BOLT_SIDECAR_USE_GATEWAYS=true
BOLT_SIDECAR_GATEWAY_URLS="1, 2, 3, ..."
if use_gateways {
	// start the firewall thing
} else {
	// start the server at port
}


impl Debug for CommitmentsFirewallRecv {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("CommitmentsFirewallStream")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f.debug_struct("CommitmentsFirewallStream")
f.debug_struct("CommitmentsFirewallRecv")

}

// Reconnect on failure
// TODO: add backoff
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use the retry_with_backoff util here :)

Comment on lines +159 to +173
/// NOTE: Is there a better way to avoid this monster type?
/// SAFETY: the `poll` implementation of this struct promptly handles these responses and
/// ensures this vector doesn't grow indefinitely.
pending_commitment_responses: FuturesUnordered<
Pin<
Box<
dyn Future<
Output = Result<
Result<SignedCommitment, CommitmentError>,
oneshot::error::RecvError,
>,
> + Send,
>,
>,
>,
Copy link
Collaborator

@merklefruit merklefruit Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good start could be to extract the type alias like

type PendingCommitmentResult = impl Future<Output = Result<SignedCommitment, CommitmentError>>;

pending_commitment_responses: FuturesUnordered<PendingCommitmentResult>

or similar (if you need pin<box as well)

Also I'm pretty sure we can get rid of the oneshot channel error and handle it in the poll implementation, as it can only happen when the sender is dropped aka if everything is shutting down

while let Poll::Ready(maybe_message) = this.read_stream.poll_next_unpin(cx) {
progress = true;

match maybe_message {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall the matching going on here feels a bit heavy!
can you make the control flow more linear by using something like:

let Some(Ok(message)) = maybe_message else {
	warn!("websocket connection with {rpc_url} dropped");
	return Poll::Ready(());
};

match message {
	Message::Text(...
	Message::Close(_) ...

Comment on lines +271 to +273
Err(e) => {
error!(?e, "failed to receive commitment response");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is a oneshot::error then we don't need to match on this, as it can only happen if the sender is dropped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants