Skip to content

light: correctly handle contexts#6687

Merged
cmwaters merged 8 commits intomasterfrom
callum/light-contexts
Jul 9, 2021
Merged

light: correctly handle contexts#6687
cmwaters merged 8 commits intomasterfrom
callum/light-contexts

Conversation

@cmwaters
Copy link
Copy Markdown
Contributor

@cmwaters cmwaters commented Jul 9, 2021

This is the update to master for #6685 which fixes incorrect handling of contexts within the light client.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 9, 2021

Codecov Report

Merging #6687 (03ac98d) into master (007eeb9) will decrease coverage by 5.09%.
The diff coverage is 17.31%.

@@            Coverage Diff             @@
##           master    #6687      +/-   ##
==========================================
- Coverage   65.99%   60.89%   -5.10%     
==========================================
  Files         234      297      +63     
  Lines       20269    28229    +7960     
==========================================
+ Hits        13376    17191    +3815     
- Misses       5825     9304    +3479     
- Partials     1068     1734     +666     
Impacted Files Coverage Δ
abci/client/grpc_client.go 0.00% <0.00%> (ø)
abci/client/local_client.go 0.00% <0.00%> (ø)
abci/types/application.go 0.00% <0.00%> (ø)
abci/types/pubkey.go 0.00% <0.00%> (ø)
abci/types/result.go 23.07% <0.00%> (ø)
abci/types/util.go 0.00% <0.00%> (ø)
cmd/tendermint/commands/gen_node_key.go 0.00% <ø> (ø)
cmd/tendermint/commands/gen_validator.go 18.18% <ø> (+18.18%) ⬆️
cmd/tendermint/commands/init.go 3.27% <ø> (+3.27%) ⬆️
cmd/tendermint/commands/light.go 24.27% <ø> (ø)
... and 429 more

errNoSnapshots = errors.New("no suitable snapshots found")
// errDeadlineExceeded is returned by Sync() when the timeout for retrieving
// tendermint state or the commit is exceeded
errDeadlineExceeded = errors.New("deadline to retrieve state and commit exceeded")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This already is an error value in the standard library, can we just use that one?

Copy link
Copy Markdown
Contributor Author

@cmwaters cmwaters Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I made a separate error is what happens if someone uses a deadline in the parent context. If it gets triggered we have (AFAIK and context is relatively new to me so I don't know too much) no idea whether the deadline was from the parent context or the sub context we use for retrieving the state and commit information. If it is a parent context deadline then we should stop completely. If it is a sub context deadline, we should drop the snapshot but try again with another snapshot. Does that make sense?

Copy link
Copy Markdown
Contributor

@williambanfield williambanfield Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this used on line 287 and 295 of this file. In either of those cases, the parent or the child could have timed out and we sill return this error. We still can't tell which one timed out when we percolate this error up but perhaps I'm not totally understanding?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok good catch. I think I've added the adequate clause to distinguish between parent context errors and child context errors

state, err := s.stateProvider.State(pctx, snapshot.Height)
if err != nil {
if err == context.DeadlineExceeded {
return sm.State{}, nil, errDeadlineExceeded
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we wrap the error that we return using the %w format directive. I'm not sure there's a need for this extra case. The caller can use error.Is(err, Context.DeadlineExceeded).

@cmwaters cmwaters requested a review from williambanfield July 9, 2021 15:18
errNoSnapshots = errors.New("no suitable snapshots found")
// errStateCommitTimeout is returned by Sync() when the timeout for retrieving
// tendermint state or the commit is exceeded
errStateCommitTimeout = errors.New("timed out trying to retrieve state and commit")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants