From 44b52941f7a2af1c3cd69fd1324ce7454f48eb32 Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 21 Sep 2020 18:50:41 +0300 Subject: [PATCH] add option to validate messages against expected tipset --- chain/exchange/client.go | 16 ++++++++++++++++ chain/exchange/protocol.go | 13 +++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/chain/exchange/client.go b/chain/exchange/client.go index 20a130c1d..fcdcd544a 100644 --- a/chain/exchange/client.go +++ b/chain/exchange/client.go @@ -215,6 +215,22 @@ func (c *client) processResponse(req *Request, res *Response) (*validatedRespons return nil, err } } + + if options.ValidateMessages { + chain := make([]*BSTipSet, 0, resLength) + for i, resChain := range res.Chain { + next := &BSTipSet{ + Blocks: req.TipSets[i].Blocks(), + Messages: resChain.Messages, + } + chain = append(chain, next) + } + + err := c.validateCompressedIndices(chain) + if err != nil { + return nil, err + } + } } return validRes, nil diff --git a/chain/exchange/protocol.go b/chain/exchange/protocol.go index ac02cf60f..b1fe69bd2 100644 --- a/chain/exchange/protocol.go +++ b/chain/exchange/protocol.go @@ -57,6 +57,8 @@ type Request struct { // Request options, see `Options` type for more details. Compressed // in a single `uint64` to save space. Options uint64 + // Request tipsets for validation + TipSets []*types.TipSet } // `Request` processed and validated to query the tipsets needed. @@ -71,13 +73,15 @@ type validatedRequest struct { const ( Headers = 1 << iota Messages + Validate ) // Decompressed options into separate struct members for easy access // during internal processing.. type parsedOptions struct { - IncludeHeaders bool - IncludeMessages bool + IncludeHeaders bool + IncludeMessages bool + ValidateMessages bool } func (options *parsedOptions) noOptionsSet() bool { @@ -87,8 +91,9 @@ func (options *parsedOptions) noOptionsSet() bool { func parseOptions(optfield uint64) *parsedOptions { return &parsedOptions{ - IncludeHeaders: optfield&(uint64(Headers)) != 0, - IncludeMessages: optfield&(uint64(Messages)) != 0, + IncludeHeaders: optfield&(uint64(Headers)) != 0, + IncludeMessages: optfield&(uint64(Messages)) != 0, + ValidateMessages: optfield&(uint64(Validate)) != 0, } }