Skip to content

Commit 882665e

Browse files
committed
attr data len const
1 parent f4b14ad commit 882665e

File tree

7 files changed

+50
-43
lines changed

7 files changed

+50
-43
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use crate::ln::chan_utils::{
4949
ClosingTransaction, commit_tx_fee_sat,
5050
};
5151
use crate::ln::chan_utils;
52-
use crate::ln::onion_utils::HTLCFailReason;
52+
use crate::ln::onion_utils::{HTLCFailReason, ATTRIBUTION_DATA_LEN};
5353
use crate::chain::BestBlock;
5454
use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, LowerBoundedFeeEstimator, fee_for_weight};
5555
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LATENCY_GRACE_PERIOD_BLOCKS};
@@ -10062,7 +10062,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1006210062
// `::FailHTLC` variant and write the real malformed error as an optional TLV.
1006310063
malformed_htlcs.push((htlc_id, failure_code, sha256_of_onion));
1006410064

10065-
let dummy_err_packet = msgs::OnionErrorPacket { data: Vec::new(), attribution_data: [0; 940] };
10065+
let dummy_err_packet = msgs::OnionErrorPacket { data: Vec::new(), attribution_data: [0; ATTRIBUTION_DATA_LEN] };
1006610066
2u8.write(writer)?;
1006710067
htlc_id.write(writer)?;
1006810068
dummy_err_packet.write(writer)?;
@@ -10863,7 +10863,7 @@ mod tests {
1086310863
use bitcoin::transaction::{Transaction, TxOut, Version};
1086410864
use bitcoin::opcodes;
1086510865
use bitcoin::network::Network;
10866-
use crate::ln::onion_utils::INVALID_ONION_BLINDING;
10866+
use crate::ln::onion_utils::{ATTRIBUTION_DATA_LEN, INVALID_ONION_BLINDING};
1086710867
use crate::types::payment::{PaymentHash, PaymentPreimage};
1086810868
use crate::ln::channel_keys::{RevocationKey, RevocationBasepoint};
1086910869
use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
@@ -11501,7 +11501,7 @@ mod tests {
1150111501
htlc_id: 0,
1150211502
};
1150311503
let dummy_holding_cell_failed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailHTLC {
11504-
htlc_id, err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data: [0; 940] }
11504+
htlc_id, err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data: [0; ATTRIBUTION_DATA_LEN] }
1150511505
};
1150611506
let dummy_holding_cell_malformed_htlc = |htlc_id| HTLCUpdateAwaitingACK::FailMalformedHTLC {
1150711507
htlc_id, failure_code: INVALID_ONION_BLINDING, sha256_of_onion: [0; 32],

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use crate::routing::gossip::NodeId;
6060
use crate::routing::router::{BlindedTail, FixedRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
6161
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails};
6262
use crate::ln::msgs;
63-
use crate::ln::onion_utils;
63+
use crate::ln::onion_utils::{self, ATTRIBUTION_DATA_LEN};
6464
use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING};
6565
use crate::ln::msgs::{ChannelMessageHandler, CommitmentUpdate, DecodeError, LightningError};
6666
#[cfg(test)]
@@ -13125,7 +13125,7 @@ impl Writeable for HTLCForwardInfo {
1312513125
// packet so older versions have something to fail back with, but serialize the real data as
1312613126
// optional TLVs for the benefit of newer versions.
1312713127
FAIL_HTLC_VARIANT_ID.write(w)?;
13128-
let dummy_err_packet = msgs::OnionErrorPacket { data: Vec::new(), attribution_data: [0; 940] };
13128+
let dummy_err_packet = msgs::OnionErrorPacket { data: Vec::new(), attribution_data: [0; ATTRIBUTION_DATA_LEN] };
1312913129
write_tlv_fields!(w, {
1313013130
(0, htlc_id, required),
1313113131
(1, failure_code, required),
@@ -14858,7 +14858,8 @@ mod tests {
1485814858
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
1485914859
use core::sync::atomic::Ordering;
1486014860
use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
14861-
use crate::ln::types::ChannelId;
14861+
use crate::ln::onion_utils::ATTRIBUTION_DATA_LEN;
14862+
use crate::ln::types::ChannelId;
1486214863
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
1486314864
use crate::ln::channelmanager::{create_recv_pending_htlc_info, inbound_payment, ChannelConfigOverrides, HTLCForwardInfo, InterceptId, PaymentId, RecipientOnionFields};
1486414865
use crate::ln::functional_test_utils::*;
@@ -16290,7 +16291,7 @@ mod tests {
1629016291
let mut nodes = create_network(1, &node_cfg, &chanmgrs);
1629116292

1629216293
let dummy_failed_htlc = |htlc_id| {
16293-
HTLCForwardInfo::FailHTLC { htlc_id, err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data: [0; 940] } }
16294+
HTLCForwardInfo::FailHTLC { htlc_id, err_packet: msgs::OnionErrorPacket { data: vec![42], attribution_data: [0; ATTRIBUTION_DATA_LEN] } }
1629416295
};
1629516296
let dummy_malformed_htlc = |htlc_id| {
1629616297
HTLCForwardInfo::FailMalformedHTLC { htlc_id, failure_code: 0x4000, sha256_of_onion: [0; 32] }

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::chain::chaininterface::LowerBoundedFeeEstimator;
1717
use crate::chain::channelmonitor;
1818
use crate::chain::channelmonitor::{Balance, ChannelMonitorUpdateStep, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY, COUNTERPARTY_CLAIMABLE_WITHIN_BLOCKS_PINNABLE};
1919
use crate::chain::transaction::OutPoint;
20+
use crate::ln::onion_utils::ATTRIBUTION_DATA_LEN;
2021
use crate::sign::{ecdsa::EcdsaChannelSigner, EntropySource, OutputSpender, SignerProvider};
2122
use crate::events::bump_transaction::WalletSource;
2223
use crate::events::{Event, FundingInfo, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, ClosureReason, HTLCDestination, PaymentFailureReason};
@@ -7048,7 +7049,7 @@ fn test_update_fulfill_htlc_bolt2_update_fail_htlc_before_commitment() {
70487049
channel_id: chan.2,
70497050
htlc_id: 0,
70507051
reason: Vec::new(),
7051-
attribution_data: Some([0; 940])
7052+
attribution_data: Some([0; ATTRIBUTION_DATA_LEN])
70527053
};
70537054

70547055
nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_msg);

lightning/src/ln/msgs.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ pub struct UpdateFailHTLC {
766766
/// The HTLC ID
767767
pub htlc_id: u64,
768768
pub(crate) reason: Vec<u8>,
769-
pub attribution_data: Option<[u8; 940]>
769+
pub attribution_data: Option<[u8; ATTRIBUTION_DATA_LEN]>
770770
}
771771
/// An [`update_fail_malformed_htlc`] message to be sent to or received from a peer.
772772
///
@@ -1937,6 +1937,8 @@ pub use self::fuzzy_internal_msgs::*;
19371937
#[cfg(not(fuzzing))]
19381938
pub(crate) use self::fuzzy_internal_msgs::*;
19391939

1940+
use super::onion_utils::ATTRIBUTION_DATA_LEN;
1941+
19401942
/// BOLT 4 onion packet including hop data for the next peer.
19411943
#[derive(Clone, Hash, PartialEq, Eq)]
19421944
pub struct OnionPacket {
@@ -2043,7 +2045,7 @@ pub(crate) struct OnionErrorPacket {
20432045
// This really should be a constant size slice, but the spec lets these things be up to 128KB?
20442046
// (TODO) We limit it in decode to much lower...
20452047
pub(crate) data: Vec<u8>,
2046-
pub(crate) attribution_data: [u8; 940]
2048+
pub(crate) attribution_data: [u8; ATTRIBUTION_DATA_LEN]
20472049
}
20482050

20492051
impl From<&UpdateFailHTLC> for OnionErrorPacket {
@@ -3461,7 +3463,8 @@ impl_writeable_msg!(GossipTimestampFilter, {
34613463
mod tests {
34623464
use bitcoin::{Amount, Transaction, TxIn, ScriptBuf, Sequence, Witness, TxOut};
34633465
use bitcoin::hex::DisplayHex;
3464-
use crate::ln::types::ChannelId;
3466+
use crate::ln::onion_utils::ATTRIBUTION_DATA_LEN;
3467+
use crate::ln::types::ChannelId;
34653468
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
34663469
use crate::types::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
34673470
use crate::ln::msgs::{self, FinalOnionHopData, OnionErrorPacket, CommonOpenChannelFields, CommonAcceptChannelFields, OutboundTrampolinePayload, TrampolineOnionPacket, InboundOnionForwardPayload, InboundOnionReceivePayload};
@@ -4467,7 +4470,7 @@ mod tests {
44674470
channel_id: ChannelId::from_bytes([2; 32]),
44684471
htlc_id: 2316138423780173,
44694472
reason: [1; 32].to_vec(),
4470-
attribution_data: Some([0; 940])
4473+
attribution_data: Some([0; ATTRIBUTION_DATA_LEN])
44714474
};
44724475
let encoded_value = update_fail_htlc.encode();
44734476
let target_value = <Vec<u8>>::from_hex("020202020202020202020202020202020202020202020202020202020202020200083a840000034d00200101010101010101010101010101010101010101010101010101010101010101").unwrap();

lightning/src/ln/onion_route_tests.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use crate::ln::functional_test_utils::*;
4747
use crate::ln::onion_utils::{construct_trampoline_onion_keys, construct_trampoline_onion_packet};
4848

4949
use super::msgs::OnionErrorPacket;
50+
use super::onion_utils::ATTRIBUTION_DATA_LEN;
5051

5152
fn run_onion_failure_test<F1,F2>(_name: &str, test_case: u8, nodes: &Vec<Node>, route: &Route, payment_hash: &PaymentHash, payment_secret: &PaymentSecret, callback_msg: F1, callback_node: F2, expected_retryable: bool, expected_error_code: Option<u16>, expected_channel_update: Option<NetworkUpdate>, expected_short_channel_id: Option<u64>, expected_htlc_destination: Option<HTLCDestination>)
5253
where F1: for <'a> FnMut(&'a mut msgs::UpdateAddHTLC),
@@ -700,7 +701,7 @@ fn test_onion_failure() {
700701
decoded_err_packet.hmac = Hmac::from_engine(hmac).to_byte_array();
701702
let onion_error = OnionErrorPacket{
702703
data: decoded_err_packet.encode(),
703-
attribution_data: [0; 940],
704+
attribution_data: [0; ATTRIBUTION_DATA_LEN],
704705
};
705706
let failure = onion_utils::encrypt_failure_packet(
706707
&onion_keys[1].shared_secret.as_ref(), &onion_error);
@@ -729,7 +730,7 @@ fn test_onion_failure() {
729730
decoded_err_packet.hmac = Hmac::from_engine(hmac).to_byte_array();
730731
let onion_error = OnionErrorPacket{
731732
data: decoded_err_packet.encode(),
732-
attribution_data: [0; 940],
733+
attribution_data: [0; ATTRIBUTION_DATA_LEN],
733734
};
734735
let failure = onion_utils::encrypt_failure_packet(
735736
&onion_keys[0].shared_secret.as_ref(), &onion_error);
@@ -757,7 +758,7 @@ fn test_onion_failure() {
757758
decoded_err_packet.hmac = Hmac::from_engine(hmac).to_byte_array();
758759
let onion_error = OnionErrorPacket{
759760
data: decoded_err_packet.encode(),
760-
attribution_data: [0; 940],
761+
attribution_data: [0; ATTRIBUTION_DATA_LEN],
761762
};
762763
let failure = onion_utils::encrypt_failure_packet(
763764
&onion_keys[1].shared_secret.as_ref(), &onion_error);

0 commit comments

Comments
 (0)