Skip to content

Commit 313f344

Browse files
committed
De-macro return_malformed_err
It does not need to be a macro, so we convert it into a simple lambda.
1 parent a293d21 commit 313f344

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

lightning/src/ln/onion_payment.rs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -464,27 +464,23 @@ where
464464
NS::Target: NodeSigner,
465465
L::Target: Logger,
466466
{
467-
macro_rules! return_malformed_err {
468-
($msg: expr, $err_code: expr) => {
469-
{
470-
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
471-
let (sha256_of_onion, failure_code) = if msg.blinding_point.is_some() {
472-
([0; 32], INVALID_ONION_BLINDING)
473-
} else {
474-
(Sha256::hash(&msg.onion_routing_packet.hop_data).to_byte_array(), $err_code)
475-
};
476-
return Err(HTLCFailureMsg::Malformed(msgs::UpdateFailMalformedHTLC {
477-
channel_id: msg.channel_id,
478-
htlc_id: msg.htlc_id,
479-
sha256_of_onion,
480-
failure_code,
481-
}));
482-
}
483-
}
484-
}
467+
let encode_malformed_error = |message: &str, err_code: u16| {
468+
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", message);
469+
let (sha256_of_onion, failure_code) = if msg.blinding_point.is_some() {
470+
([0; 32], INVALID_ONION_BLINDING)
471+
} else {
472+
(Sha256::hash(&msg.onion_routing_packet.hop_data).to_byte_array(), err_code)
473+
};
474+
return Err(HTLCFailureMsg::Malformed(msgs::UpdateFailMalformedHTLC {
475+
channel_id: msg.channel_id,
476+
htlc_id: msg.htlc_id,
477+
sha256_of_onion,
478+
failure_code,
479+
}));
480+
};
485481

486482
if let Err(_) = msg.onion_routing_packet.public_key {
487-
return_malformed_err!("invalid ephemeral pubkey", 0x8000 | 0x4000 | 6);
483+
return encode_malformed_error("invalid ephemeral pubkey", 0x8000 | 0x4000 | 6);
488484
}
489485

490486
if msg.onion_routing_packet.version != 0 {
@@ -494,12 +490,12 @@ where
494490
//receiving node would have to brute force to figure out which version was put in the
495491
//packet by the node that send us the message, in the case of hashing the hop_data, the
496492
//node knows the HMAC matched, so they already know what is there...
497-
return_malformed_err!("Unknown onion packet version", 0x8000 | 0x4000 | 4);
493+
return encode_malformed_error("Unknown onion packet version", 0x8000 | 0x4000 | 4);
498494
}
499495

500496
let encode_relay_error = |message: &str, err_code: u16, shared_secret: [u8; 32], trampoline_shared_secret: Option<[u8; 32]>, data: &[u8]| {
501497
if msg.blinding_point.is_some() {
502-
return_malformed_err!(message, INVALID_ONION_BLINDING)
498+
return encode_malformed_error(message, INVALID_ONION_BLINDING)
503499
}
504500

505501
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", message);
@@ -518,7 +514,7 @@ where
518514
) {
519515
Ok(res) => res,
520516
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, err_code }) => {
521-
return_malformed_err!(err_msg, err_code);
517+
return encode_malformed_error(err_msg, err_code);
522518
},
523519
Err(onion_utils::OnionDecodeErr::Relay { err_msg, err_code, shared_secret, trampoline_shared_secret }) => {
524520
return encode_relay_error(err_msg, err_code, shared_secret.secret_bytes(), trampoline_shared_secret.map(|tss| tss.secret_bytes()), &[0; 0]);

0 commit comments

Comments
 (0)