@@ -17,8 +17,8 @@ use core::ops::Deref;
17
17
/// TLVs to encode in an intermediate onion message packet's hop data. When provided in a blinded
18
18
/// route, they are encoded into [`BlindedHop::encrypted_payload`].
19
19
pub ( crate ) struct ForwardTlvs {
20
- /// The node id of the next hop in the onion message's path.
21
- pub ( crate ) next_node_id : PublicKey ,
20
+ /// The next hop in the onion message's path.
21
+ pub ( crate ) next_hop : NextHop ,
22
22
/// Senders to a blinded path use this value to concatenate the route they find to the
23
23
/// introduction node with the blinded path.
24
24
pub ( crate ) next_blinding_override : Option < PublicKey > ,
@@ -32,11 +32,24 @@ pub(crate) struct ReceiveTlvs {
32
32
pub ( crate ) path_id : Option < [ u8 ; 32 ] > ,
33
33
}
34
34
35
+ /// The next hop to forward the onion message along its path.
36
+ pub ( crate ) enum NextHop {
37
+ /// The node id of the next hop.
38
+ NodeId ( PublicKey ) ,
39
+ /// The short channel id leading to the next hop.
40
+ ShortChannelId ( u64 ) ,
41
+ }
42
+
35
43
impl Writeable for ForwardTlvs {
36
44
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
45
+ let ( next_node_id, short_channel_id) = match self . next_hop {
46
+ NextHop :: NodeId ( pubkey) => ( Some ( pubkey) , None ) ,
47
+ NextHop :: ShortChannelId ( scid) => ( None , Some ( scid) ) ,
48
+ } ;
37
49
// TODO: write padding
38
50
encode_tlv_stream ! ( writer, {
39
- ( 4 , self . next_node_id, required) ,
51
+ ( 2 , short_channel_id, option) ,
52
+ ( 4 , next_node_id, option) ,
40
53
( 8 , self . next_blinding_override, option)
41
54
} ) ;
42
55
Ok ( ( ) )
@@ -59,9 +72,8 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
59
72
) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
60
73
let blinded_tlvs = unblinded_path. iter ( )
61
74
. skip ( 1 ) // The first node's TLVs contains the next node's pubkey
62
- . map ( |pk| {
63
- ControlTlvs :: Forward ( ForwardTlvs { next_node_id : * pk, next_blinding_override : None } )
64
- } )
75
+ . map ( |pk| ForwardTlvs { next_hop : NextHop :: NodeId ( * pk) , next_blinding_override : None } )
76
+ . map ( |tlvs| ControlTlvs :: Forward ( tlvs) )
65
77
. chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { path_id : None } ) ) ) ;
66
78
67
79
utils:: construct_blinded_hops ( secp_ctx, unblinded_path. iter ( ) , blinded_tlvs, session_priv)
@@ -78,9 +90,13 @@ pub(crate) fn advance_path_by_one<NS: Deref, T: secp256k1::Signing + secp256k1::
78
90
let mut s = Cursor :: new ( & encrypted_control_tlvs) ;
79
91
let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
80
92
match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
81
- Ok ( ChaChaPolyReadAdapter { readable : ControlTlvs :: Forward ( ForwardTlvs {
82
- mut next_node_id, next_blinding_override,
83
- } ) } ) => {
93
+ Ok ( ChaChaPolyReadAdapter {
94
+ readable : ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override } )
95
+ } ) => {
96
+ let mut next_node_id = match next_hop {
97
+ NextHop :: NodeId ( pubkey) => pubkey,
98
+ NextHop :: ShortChannelId ( _) => todo ! ( ) ,
99
+ } ;
84
100
let mut new_blinding_point = match next_blinding_override {
85
101
Some ( blinding_point) => blinding_point,
86
102
None => {
0 commit comments