add option to validate messages against expected tipset

This commit is contained in:
vyzo 2020-09-21 18:50:41 +03:00
parent 58a85f378c
commit 44b52941f7
2 changed files with 25 additions and 4 deletions

View File

@ -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

View File

@ -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,6 +73,7 @@ type validatedRequest struct {
const (
Headers = 1 << iota
Messages
Validate
)
// Decompressed options into separate struct members for easy access
@ -78,6 +81,7 @@ const (
type parsedOptions struct {
IncludeHeaders bool
IncludeMessages bool
ValidateMessages bool
}
func (options *parsedOptions) noOptionsSet() bool {
@ -89,6 +93,7 @@ func parseOptions(optfield uint64) *parsedOptions {
return &parsedOptions{
IncludeHeaders: optfield&(uint64(Headers)) != 0,
IncludeMessages: optfield&(uint64(Messages)) != 0,
ValidateMessages: optfield&(uint64(Validate)) != 0,
}
}