Skip to content

Commit

Permalink
Merge pull request lightningdevkit#3301 from dunxen/2024-9-fixneverty…
Browse files Browse the repository at this point in the history
…pefallback

Add an explicit_type TLV syntax for avoiding certain cases of type inference
  • Loading branch information
TheBlueMatt authored Oct 2, 2024
2 parents 4147de2 + c0d84e8 commit 605952c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ jobs:
-A clippy::unnecessary_to_owned \
-A clippy::unnecessary_unwrap \
-A clippy::unused_unit \
-A clippy::useless_conversion \
-A dependency_on_unit_never_type_fallback
-A clippy::useless_conversion
rustfmt:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ impl Readable for CommitmentTransaction {
(8, keys, required),
(10, built, required),
(12, htlcs, required_vec),
(14, _legacy_deserialization_prevention_marker, option),
(14, _legacy_deserialization_prevention_marker, (option, explicit_type: ())),
(15, channel_type_features, option),
});

Expand Down
26 changes: 26 additions & 0 deletions lightning/src/util/ser_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ macro_rules! _check_decoded_tlv_order {
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, option) => {{
// no-op
}};
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
// no-op
}};
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
_check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
}};
($last_seen_type: expr, $typ: expr, $type: expr, $field: ident, required_vec) => {{
$crate::_check_decoded_tlv_order!($last_seen_type, $typ, $type, $field, required);
}};
Expand Down Expand Up @@ -332,6 +338,12 @@ macro_rules! _check_missing_tlv {
($last_seen_type: expr, $type: expr, $field: ident, option) => {{
// no-op
}};
($last_seen_type: expr, $type: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
// no-op
}};
($last_seen_type: expr, $type: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
_check_missing_tlv!($last_seen_type, $type, $field, required);
}};
($last_seen_type: expr, $type: expr, $field: ident, optional_vec) => {{
// no-op
}};
Expand Down Expand Up @@ -372,6 +384,14 @@ macro_rules! _decode_tlv {
($outer_reader: expr, $reader: expr, $field: ident, option) => {{
$field = Some($crate::util::ser::Readable::read(&mut $reader)?);
}};
($outer_reader: expr, $reader: expr, $field: ident, (option, explicit_type: $fieldty: ty)) => {{
let _field: &Option<$fieldty> = &$field;
_decode_tlv!($outer_reader, $reader, $field, option);
}};
($outer_reader: expr, $reader: expr, $field: ident, (required, explicit_type: $fieldty: ty)) => {{
let _field: &$fieldty = &$field;
_decode_tlv!($outer_reader, $reader, $field, required);
}};
($outer_reader: expr, $reader: expr, $field: ident, optional_vec) => {{
let f: $crate::util::ser::WithoutLength<Vec<_>> = $crate::util::ser::Readable::read(&mut $reader)?;
$field = Some(f.0);
Expand Down Expand Up @@ -795,6 +815,12 @@ macro_rules! _init_tlv_field_var {
($field: ident, optional_vec) => {
let mut $field = Some(Vec::new());
};
($field: ident, (option, explicit_type: $fieldty: ty)) => {
let mut $field: Option<$fieldty> = None;
};
($field: ident, (required, explicit_type: $fieldty: ty)) => {
let mut $field = $crate::util::ser::RequiredWrapper::<$fieldty>(None);
};
($field: ident, (option, encoding: ($fieldty: ty, $encoding: ident))) => {
$crate::_init_tlv_field_var!($field, option);
};
Expand Down

0 comments on commit 605952c

Please sign in to comment.