@@ -1704,7 +1704,10 @@ impl MsgDecodable for ErrorMessage {
1704
1704
}
1705
1705
}
1706
1706
1707
- impl_writeable ! ( AcceptChannel , {
1707
+ impl_writeable_len_match ! ( AcceptChannel , {
1708
+ { AcceptChannel { shutdown_scriptpubkey: Some ( ref script) , ..} , 270 + 2 + script. len( ) } ,
1709
+ { _, 270 }
1710
+ } , {
1708
1711
temporary_channel_id,
1709
1712
dust_limit_satoshis,
1710
1713
max_htlc_value_in_flight_msat,
@@ -1722,7 +1725,7 @@ impl_writeable!(AcceptChannel, {
1722
1725
shutdown_scriptpubkey
1723
1726
} ) ;
1724
1727
1725
- impl_writeable ! ( AnnouncementSignatures , {
1728
+ impl_writeable ! ( AnnouncementSignatures , 32 + 8 + 64 * 2 , {
1726
1729
channel_id,
1727
1730
short_channel_id,
1728
1731
node_signature,
@@ -1731,6 +1734,7 @@ impl_writeable!(AnnouncementSignatures, {
1731
1734
1732
1735
impl < W : Writer > Writeable < W > for ChannelReestablish {
1733
1736
fn write ( & self , w : & mut W ) -> Result < ( ) , DecodeError > {
1737
+ w. size_hint ( if self . data_loss_protect . is_some ( ) { 32 +2 * 8 +33 +32 } else { 32 +2 * 8 } ) ;
1734
1738
self . channel_id . write ( w) ?;
1735
1739
self . next_local_commitment_number . write ( w) ?;
1736
1740
self . next_remote_commitment_number . write ( w) ?;
@@ -1763,55 +1767,68 @@ impl<R: Read> Readable<R> for ChannelReestablish{
1763
1767
}
1764
1768
}
1765
1769
1766
- impl_writeable ! ( ClosingSigned , {
1770
+ impl_writeable ! ( ClosingSigned , 32 + 8 + 64 , {
1767
1771
channel_id,
1768
1772
fee_satoshis,
1769
1773
signature
1770
1774
} ) ;
1771
1775
1772
- impl_writeable ! ( CommitmentSigned , {
1776
+ impl_writeable_len_match ! ( CommitmentSigned , {
1777
+ { CommitmentSigned { ref htlc_signatures, .. } , 32 +64 +2 +htlc_signatures. len( ) * 64 }
1778
+ } , {
1773
1779
channel_id,
1774
1780
signature,
1775
1781
htlc_signatures
1776
1782
} ) ;
1777
1783
1778
- impl_writeable ! ( DecodedOnionErrorPacket , {
1784
+ impl_writeable_len_match ! ( DecodedOnionErrorPacket , {
1785
+ { DecodedOnionErrorPacket { ref failuremsg, ref pad, .. } , 32 + 4 + failuremsg. len( ) + pad. len( ) }
1786
+ } , {
1779
1787
hmac,
1780
1788
failuremsg,
1781
1789
pad
1782
1790
} ) ;
1783
1791
1784
- impl_writeable ! ( FundingCreated , {
1792
+ impl_writeable ! ( FundingCreated , 32 + 32 + 2 + 64 , {
1785
1793
temporary_channel_id,
1786
1794
funding_txid,
1787
1795
funding_output_index,
1788
1796
signature
1789
1797
} ) ;
1790
1798
1791
- impl_writeable ! ( FundingSigned , {
1799
+ impl_writeable ! ( FundingSigned , 32 + 64 , {
1792
1800
channel_id,
1793
1801
signature
1794
1802
} ) ;
1795
1803
1796
- impl_writeable ! ( FundingLocked , {
1804
+ impl_writeable ! ( FundingLocked , 32 + 33 , {
1797
1805
channel_id,
1798
1806
next_per_commitment_point
1799
1807
} ) ;
1800
1808
1801
- impl_writeable ! ( GlobalFeatures , {
1809
+ impl_writeable_len_match ! ( GlobalFeatures , {
1810
+ { GlobalFeatures { ref flags } , flags. len( ) + 2 }
1811
+ } , {
1802
1812
flags
1803
1813
} ) ;
1804
1814
1805
- impl_writeable ! ( LocalFeatures , {
1815
+ impl_writeable_len_match ! ( LocalFeatures , {
1816
+ { LocalFeatures { ref flags } , flags. len( ) + 2 }
1817
+ } , {
1806
1818
flags
1807
1819
} ) ;
1808
1820
1809
- impl_writeable ! ( Init , {
1821
+ impl_writeable_len_match ! ( Init , {
1822
+ { Init { ref global_features, ref local_features } , global_features. flags. len( ) + local_features. flags. len( ) + 4 }
1823
+ } , {
1810
1824
global_features,
1811
1825
local_features
1812
1826
} ) ;
1813
1827
1814
- impl_writeable ! ( OpenChannel , {
1828
+ impl_writeable_len_match ! ( OpenChannel , {
1829
+ { OpenChannel { shutdown_scriptpubkey: Some ( ref script) , .. } , 319 + 2 + script. len( ) } ,
1830
+ { OpenChannel { shutdown_scriptpubkey: None , .. } , 319 }
1831
+ } , {
1815
1832
chain_hash,
1816
1833
temporary_channel_id,
1817
1834
funding_satoshis,
@@ -1833,47 +1850,54 @@ impl_writeable!(OpenChannel, {
1833
1850
shutdown_scriptpubkey
1834
1851
} ) ;
1835
1852
1836
- impl_writeable ! ( RevokeAndACK , {
1853
+ impl_writeable ! ( RevokeAndACK , 32 + 32 + 33 , {
1837
1854
channel_id,
1838
1855
per_commitment_secret,
1839
1856
next_per_commitment_point
1840
1857
} ) ;
1841
1858
1842
- impl_writeable ! ( Shutdown , {
1859
+ impl_writeable_len_match ! ( Shutdown , {
1860
+ { Shutdown { ref scriptpubkey, .. } , 32 + 2 + scriptpubkey. len( ) }
1861
+ } , {
1843
1862
channel_id,
1844
1863
scriptpubkey
1845
1864
} ) ;
1846
1865
1847
- impl_writeable ! ( UpdateFailHTLC , {
1866
+ impl_writeable_len_match ! ( UpdateFailHTLC , {
1867
+ { UpdateFailHTLC { ref reason, .. } , 32 + 10 + reason. data. len( ) }
1868
+ } , {
1848
1869
channel_id,
1849
1870
htlc_id,
1850
1871
reason
1851
1872
} ) ;
1852
1873
1853
- impl_writeable ! ( UpdateFailMalformedHTLC , {
1874
+ impl_writeable ! ( UpdateFailMalformedHTLC , 32 + 8 + 32 + 2 , {
1854
1875
channel_id,
1855
1876
htlc_id,
1856
1877
sha256_of_onion,
1857
1878
failure_code
1858
1879
} ) ;
1859
1880
1860
- impl_writeable ! ( UpdateFee , {
1881
+ impl_writeable ! ( UpdateFee , 32 + 4 , {
1861
1882
channel_id,
1862
1883
feerate_per_kw
1863
1884
} ) ;
1864
1885
1865
- impl_writeable ! ( UpdateFulfillHTLC , {
1886
+ impl_writeable ! ( UpdateFulfillHTLC , 32 + 8 + 32 , {
1866
1887
channel_id,
1867
1888
htlc_id,
1868
1889
payment_preimage
1869
1890
} ) ;
1870
1891
1871
- impl_writeable ! ( OnionErrorPacket , {
1892
+ impl_writeable_len_match ! ( OnionErrorPacket , {
1893
+ { OnionErrorPacket { ref data, .. } , 2 + data. len( ) }
1894
+ } , {
1872
1895
data
1873
1896
} ) ;
1874
1897
1875
1898
impl < W : Writer > Writeable < W > for OnionPacket {
1876
1899
fn write ( & self , w : & mut W ) -> Result < ( ) , DecodeError > {
1900
+ w. size_hint ( 1 + 33 + 20 * 65 + 32 ) ;
1877
1901
self . version . write ( w) ?;
1878
1902
match self . public_key {
1879
1903
Ok ( pubkey) => pubkey. write ( w) ?,
@@ -1900,7 +1924,7 @@ impl<R: Read> Readable<R> for OnionPacket {
1900
1924
}
1901
1925
}
1902
1926
1903
- impl_writeable ! ( UpdateAddHTLC , {
1927
+ impl_writeable ! ( UpdateAddHTLC , 32 + 8 + 8 + 32 + 4 + 1366 , {
1904
1928
channel_id,
1905
1929
htlc_id,
1906
1930
amount_msat,
@@ -1911,6 +1935,7 @@ impl_writeable!(UpdateAddHTLC, {
1911
1935
1912
1936
impl < W : Writer > Writeable < W > for OnionRealm0HopData {
1913
1937
fn write ( & self , w : & mut W ) -> Result < ( ) , DecodeError > {
1938
+ w. size_hint ( 32 ) ;
1914
1939
self . short_channel_id . write ( w) ?;
1915
1940
self . amt_to_forward . write ( w) ?;
1916
1941
self . outgoing_cltv_value . write ( w) ?;
@@ -1935,6 +1960,7 @@ impl<R: Read> Readable<R> for OnionRealm0HopData {
1935
1960
1936
1961
impl < W : Writer > Writeable < W > for OnionHopData {
1937
1962
fn write ( & self , w : & mut W ) -> Result < ( ) , DecodeError > {
1963
+ w. size_hint ( 65 ) ;
1938
1964
self . realm . write ( w) ?;
1939
1965
self . data . write ( w) ?;
1940
1966
self . hmac . write ( w) ?;
@@ -1960,6 +1986,7 @@ impl<R: Read> Readable<R> for OnionHopData {
1960
1986
1961
1987
impl < W : Writer > Writeable < W > for Ping {
1962
1988
fn write ( & self , w : & mut W ) -> Result < ( ) , DecodeError > {
1989
+ w. size_hint ( self . byteslen as usize + 4 ) ;
1963
1990
self . ponglen . write ( w) ?;
1964
1991
vec ! [ 0u8 ; self . byteslen as usize ] . write ( w) ?; // size-unchecked write
1965
1992
Ok ( ( ) )
@@ -1981,6 +2008,7 @@ impl<R: Read> Readable<R> for Ping {
1981
2008
1982
2009
impl < W : Writer > Writeable < W > for Pong {
1983
2010
fn write ( & self , w : & mut W ) -> Result < ( ) , DecodeError > {
2011
+ w. size_hint ( self . byteslen as usize + 2 ) ;
1984
2012
vec ! [ 0u8 ; self . byteslen as usize ] . write ( w) ?; // size-unchecked write
1985
2013
Ok ( ( ) )
1986
2014
}
@@ -2000,6 +2028,7 @@ impl<R: Read> Readable<R> for Pong {
2000
2028
2001
2029
impl < W : Writer > Writeable < W > for UnsignedChannelAnnouncement {
2002
2030
fn write ( & self , w : & mut W ) -> Result < ( ) , DecodeError > {
2031
+ w. size_hint ( 2 + 2 * 32 + 4 * 33 + self . features . flags . len ( ) + self . excess_data . len ( ) ) ;
2003
2032
self . features . write ( w) ?;
2004
2033
self . chain_hash . write ( w) ?;
2005
2034
self . short_channel_id . write ( w) ?;
@@ -2037,7 +2066,10 @@ impl<R: Read> Readable<R> for UnsignedChannelAnnouncement {
2037
2066
}
2038
2067
}
2039
2068
2040
- impl_writeable ! ( ChannelAnnouncement , {
2069
+ impl_writeable_len_match ! ( ChannelAnnouncement , {
2070
+ { ChannelAnnouncement { contents: UnsignedChannelAnnouncement { ref features, ref excess_data, ..} , .. } ,
2071
+ 2 + 2 * 32 + 4 * 33 + features. flags. len( ) + excess_data. len( ) + 4 * 64 }
2072
+ } , {
2041
2073
node_signature_1,
2042
2074
node_signature_2,
2043
2075
bitcoin_signature_1,
@@ -2047,6 +2079,7 @@ impl_writeable!(ChannelAnnouncement,{
2047
2079
2048
2080
impl < W : Writer > Writeable < W > for UnsignedChannelUpdate {
2049
2081
fn write ( & self , w : & mut W ) -> Result < ( ) , DecodeError > {
2082
+ w. size_hint ( 64 + self . excess_data . len ( ) ) ;
2050
2083
self . chain_hash . write ( w) ?;
2051
2084
self . short_channel_id . write ( w) ?;
2052
2085
self . timestamp . write ( w) ?;
@@ -2080,15 +2113,20 @@ impl<R: Read> Readable<R> for UnsignedChannelUpdate {
2080
2113
}
2081
2114
}
2082
2115
2083
- impl_writeable ! ( ChannelUpdate , {
2116
+ impl_writeable_len_match ! ( ChannelUpdate , {
2117
+ { ChannelUpdate { contents: UnsignedChannelUpdate { ref excess_data, ..} , .. } ,
2118
+ 64 + excess_data. len( ) + 64 }
2119
+ } , {
2084
2120
signature,
2085
2121
contents
2086
2122
} ) ;
2087
2123
2088
2124
impl < W : Writer > Writeable < W > for ErrorMessage {
2089
2125
fn write ( & self , w : & mut W ) -> Result < ( ) , DecodeError > {
2126
+ w. size_hint ( 32 + 2 + self . data . len ( ) ) ;
2090
2127
self . channel_id . write ( w) ?;
2091
- self . data . as_bytes ( ) . to_vec ( ) . write ( w) ?; // write with size prefix
2128
+ ( self . data . len ( ) as u16 ) . write ( w) ?;
2129
+ w. write_all ( self . data . as_bytes ( ) ) ?;
2092
2130
Ok ( ( ) )
2093
2131
}
2094
2132
}
@@ -2113,6 +2151,7 @@ impl<R: Read> Readable<R> for ErrorMessage {
2113
2151
2114
2152
impl < W : Writer > Writeable < W > for UnsignedNodeAnnouncement {
2115
2153
fn write ( & self , w : & mut W ) -> Result < ( ) , DecodeError > {
2154
+ w. size_hint ( 64 + 76 + self . features . flags . len ( ) + self . addresses . len ( ) * 38 + self . excess_address_data . len ( ) + self . excess_data . len ( ) ) ;
2116
2155
self . features . write ( w) ?;
2117
2156
self . timestamp . write ( w) ?;
2118
2157
self . node_id . write ( w) ?;
@@ -2279,7 +2318,10 @@ impl<R: Read> Readable<R> for UnsignedNodeAnnouncement {
2279
2318
}
2280
2319
}
2281
2320
2282
- impl_writeable ! ( NodeAnnouncement , {
2321
+ impl_writeable_len_match ! ( NodeAnnouncement , {
2322
+ { NodeAnnouncement { contents: UnsignedNodeAnnouncement { ref features, ref addresses, ref excess_address_data, ref excess_data, ..} , .. } ,
2323
+ 64 + 76 + features. flags. len( ) + addresses. len( ) * 38 + excess_address_data. len( ) + excess_data. len( ) }
2324
+ } , {
2283
2325
signature,
2284
2326
contents
2285
2327
} ) ;
0 commit comments