Skip to content

Commit

Permalink
If the direction is descending, prune from start. (#2662)
Browse files Browse the repository at this point in the history
A block request contain start block, end block, direction and max size.
It could be the case that block between start and end are less than max
size. In such cases, so far we were pruning block from the end while
preparing a block response.

The correct way however would be to prune from the start, if the direction
is descending and prune from the end if the direction is ascending.

Since, we were pruning blocks the wrong way, we were preparing a
response which substrate was not expecting. And that used to result in
substrate dropping us.

This commit fixes that issue.

Fixes #2595
  • Loading branch information
kishansagathiya authored Jul 11, 2022
1 parent 8fd2188 commit 8c16d4e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dot/sync/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,14 @@ func (s *Service) handleChainByHash(ancestor, descendant common.Hash,
return nil, err
}

// If the direction is descending, prune from the start.
// if the direction is ascending it should prune from the end.
if uint(len(subchain)) > max {
subchain = subchain[:max]
if direction == network.Ascending {
subchain = subchain[:max]
} else {
subchain = subchain[uint(len(subchain))-max:]
}
}

data := make([]*types.BlockData, len(subchain))
Expand Down

0 comments on commit 8c16d4e

Please sign in to comment.