Skip to content

Commit

Permalink
Interpret 0 maximum block as no maximum (#2835)
Browse files Browse the repository at this point in the history
Substrate can in principle send requests with `0` maximum blocks. This
is meant to mean "no limit".

I've discovered this mismatch while investigating
#2833, however this is not
the same issue as #2833.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
tomaka and mergify[bot] authored Oct 7, 2022
1 parent 176ac12 commit f75bc7e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/network/protocol/block_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@ pub fn decode_block_request(
(Some(_), Some(_)) => return Err(DecodeBlockRequestError::ProtobufDecode),
(None, None) => return Err(DecodeBlockRequestError::MissingStartBlock),
},
desired_count: NonZeroU32::new(max_blocks.unwrap_or(u32::max_value()))
.ok_or(DecodeBlockRequestError::ZeroBlocksRequested)?,
desired_count: {
// A missing field or a `0` field are both interpreted as "no limit".
NonZeroU32::new(max_blocks.unwrap_or(u32::max_value()))
.unwrap_or(NonZeroU32::new(u32::max_value()).unwrap())
},
direction: match direction {
0 => BlocksRequestDirection::Ascending,
1 => BlocksRequestDirection::Descending,
Expand Down

0 comments on commit f75bc7e

Please sign in to comment.