Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed May 11, 2021
1 parent d138a96 commit a2e61c2
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions dot/sync/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package sync

import (
"errors"
"math/big"

"github.com/ChainSafe/gossamer/dot/network"
Expand Down Expand Up @@ -99,24 +100,25 @@ func (s *Service) CreateBlockResponse(blockRequest *network.BlockRequestMessage)

responseData := []*types.BlockData{}

// ascending (ie child to parent)
if blockRequest.Direction == 0 {
switch blockRequest.Direction {
case 0: // ascending (ie child to parent)
for i := endHeader.Number.Int64(); i >= startHeader.Number.Int64(); i-- {
blockData, err := s.getBlockData(big.NewInt(i), blockRequest.RequestedData)
if err != nil {
return nil, err
}
responseData = append(responseData, blockData)
}
} else {
// descending (ie parent to child)
case 1: // descending (ie parent to child)
for i := startHeader.Number.Int64(); i <= endHeader.Number.Int64(); i++ {
blockData, err := s.getBlockData(big.NewInt(i), blockRequest.RequestedData)
if err != nil {
return nil, err
}
responseData = append(responseData, blockData)
}
default:
return nil, errors.New("invalid BlockRequest direction")
}

logger.Debug("sending BlockResponseMessage", "start", startHeader.Number, "end", endHeader.Number)
Expand All @@ -131,13 +133,18 @@ func (s *Service) getBlockData(num *big.Int, requestedData byte) (*types.BlockDa
return nil, err
}

blockData := new(types.BlockData)
blockData.Hash = hash
blockData.Header = optional.NewHeader(false, nil)
blockData.Body = optional.NewBody(false, nil)
blockData.Receipt = optional.NewBytes(false, nil)
blockData.MessageQueue = optional.NewBytes(false, nil)
blockData.Justification = optional.NewBytes(false, nil)
blockData := &types.BlockData{
Hash: hash,
Header: optional.NewHeader(false, nil),
Body: optional.NewBody(false, nil),
Receipt: optional.NewBytes(false, nil),
MessageQueue: optional.NewBytes(false, nil),
Justification: optional.NewBytes(false, nil),
}

if requestedData == 0 {
return blockData, nil
}

if (requestedData & network.RequestedDataHeader) == 1 {
retData, err := s.blockState.GetHeader(hash)
Expand Down

0 comments on commit a2e61c2

Please sign in to comment.