diff --git a/chain/blocksync/client.go b/chain/blocksync/client.go index 104157a82..3164d45bf 100644 --- a/chain/blocksync/client.go +++ b/chain/blocksync/client.go @@ -48,7 +48,7 @@ func NewClient( // Main logic of the client request service. The provided `Request` // is sent to the `singlePeer` if one is indicated or to all available // ones otherwise. The response is processed and validated according -// to the `Request` options. Either a `ValidatedResponse` is returned +// to the `Request` options. Either a `validatedResponse` is returned // (which can be safely accessed), or an `error` that may represent // either a response error status, a failed validation or an internal // error. @@ -66,7 +66,7 @@ func (client *BlockSync) doRequest( ctx context.Context, req *Request, singlePeer *peer.ID, -) (*ValidatedResponse, error) { +) (*validatedResponse, error) { // Validate request. if req.Length == 0 { return nil, xerrors.Errorf("invalid request of length 0") @@ -138,7 +138,7 @@ func (client *BlockSync) doRequest( // Process and validate response. Check the status and that the information // returned matches the request (and its integrity). Extract the information -// into a `ValidatedResponse` for the external-facing APIs to select what they +// into a `validatedResponse` for the external-facing APIs to select what they // want. // // We are conflating in the single error returned both status and validation @@ -148,7 +148,7 @@ func (client *BlockSync) processResponse( req *Request, res *Response, // FIXME: Add the `peer` as argument once we implement penalties. -) (*ValidatedResponse, error) { +) (*validatedResponse, error) { err := res.statusToError() if err != nil { return nil, xerrors.Errorf("status error: %s", err) @@ -175,25 +175,25 @@ func (client *BlockSync) processResponse( return nil, xerrors.Errorf("got less than requested without a proper status: %s", res.Status) } - validRes := &ValidatedResponse{} + validRes := &validatedResponse{} if options.IncludeHeaders { // Check for valid block sets and extract them into `TipSet`s. - validRes.Tipsets = make([]*types.TipSet, resLength) + validRes.tipsets = make([]*types.TipSet, resLength) for i := 0; i < resLength; i++ { - validRes.Tipsets[i], err = types.NewTipSet(res.Chain[i].Blocks) + validRes.tipsets[i], err = types.NewTipSet(res.Chain[i].Blocks) if err != nil { return nil, xerrors.Errorf("invalid tipset blocks at height (head - %d): %w", i, err) } } // Check that the returned head matches the one requested. - if !types.CidArrsEqual(validRes.Tipsets[0].Cids(), req.Head) { + if !types.CidArrsEqual(validRes.tipsets[0].Cids(), req.Head) { return nil, xerrors.Errorf("returned chain head does not match request") } // Check `TipSet` are connected (valid chain). - for i := 0; i < len(validRes.Tipsets) - 1; i++ { - if validRes.Tipsets[i].IsChildOf(validRes.Tipsets[i+1]) == false { + for i := 0; i < len(validRes.tipsets) - 1; i++ { + if validRes.tipsets[i].IsChildOf(validRes.tipsets[i+1]) == false { return nil, fmt.Errorf("tipsets are not connected at height (head - %d)/(head - %d)", i, i+1) // FIXME: Maybe give more information here, like CIDs. @@ -202,12 +202,12 @@ func (client *BlockSync) processResponse( } if options.IncludeMessages { - validRes.Messages = make([]*CompactedMessages, resLength) + validRes.messages = make([]*CompactedMessages, resLength) for i := 0; i < resLength; i++ { if res.Chain[i].Messages == nil { return nil, xerrors.Errorf("no messages included for tipset at height (head - %d): %w", i) } - validRes.Messages[i] = res.Chain[i].Messages + validRes.messages[i] = res.Chain[i].Messages } if options.IncludeHeaders { @@ -276,7 +276,7 @@ func (client *BlockSync) GetBlocks( return nil, err } - return validRes.Tipsets, nil + return validRes.tipsets, nil } func (client *BlockSync) GetFullTipSet( @@ -321,7 +321,7 @@ func (client *BlockSync) GetChainMessages( return nil, err } - return validRes.Messages, nil + return validRes.messages, nil } // Send a request to a peer. Write request in the stream and read the diff --git a/chain/blocksync/protocol.go b/chain/blocksync/protocol.go index dc9f76d26..14ae2332f 100644 --- a/chain/blocksync/protocol.go +++ b/chain/blocksync/protocol.go @@ -153,27 +153,28 @@ type CompactedMessages struct { // Response that has been validated according to the protocol // and can be safely accessed. -// FIXME: Maybe rename to verified, keep consistent naming. -type ValidatedResponse struct { - Tipsets []*types.TipSet - Messages []*CompactedMessages +type validatedResponse struct { + tipsets []*types.TipSet + // List of all messages per tipset (grouped by tipset, + // not by block, hence a single index like `tipsets`). + messages []*CompactedMessages } // Decompress messages and form full tipsets with them. The headers // need to have been requested as well. -func (res *ValidatedResponse) toFullTipSets() ([]*store.FullTipSet) { - if len(res.Tipsets) == 0 { +func (res *validatedResponse) toFullTipSets() ([]*store.FullTipSet) { + if len(res.tipsets) == 0 { // This decompression can only be done if both headers and // messages are returned in the response. // FIXME: Do we need to check the messages are present also? The validation // would seem to imply this is unnecessary, can be added just in case. return nil } - ftsList := make([]*store.FullTipSet, len(res.Tipsets)) - for tipsetIdx := range res.Tipsets { + ftsList := make([]*store.FullTipSet, len(res.tipsets)) + for tipsetIdx := range res.tipsets { fts := &store.FullTipSet{} // FIXME: We should use the `NewFullTipSet` API. - msgs := res.Messages[tipsetIdx] - for blockIdx, b := range res.Tipsets[tipsetIdx].Blocks() { + msgs := res.messages[tipsetIdx] + for blockIdx, b := range res.tipsets[tipsetIdx].Blocks() { fb := &types.FullBlock{ Header: b, }