Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate reactor messages #2711

Merged
merged 26 commits into from Nov 1, 2018
Merged

validate reactor messages #2711

merged 26 commits into from Nov 1, 2018

Conversation

melekes
Copy link
Contributor

@melekes melekes commented Oct 26, 2018

Refs #2683

  • Updated all relevant documentation in docs no need(?)
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

TODO

  • validate netAddr in pex reactor
  • check signatures size

@codecov-io
Copy link

codecov-io commented Oct 26, 2018

Codecov Report

Merging #2711 into develop will decrease coverage by 0.28%.
The diff coverage is 31.37%.

@@             Coverage Diff             @@
##           develop    #2711      +/-   ##
===========================================
- Coverage    62.52%   62.23%   -0.29%     
===========================================
  Files          212      212              
  Lines        17074    17185     +111     
===========================================
+ Hits         10675    10695      +20     
- Misses        5532     5592      +60     
- Partials       867      898      +31
Impacted Files Coverage Δ
crypto/crypto.go 0% <ø> (ø) ⬆️
config/toml.go 53.19% <ø> (ø) ⬆️
p2p/pex/errors.go 0% <0%> (ø) ⬆️
p2p/pex/addrbook.go 69.24% <0%> (-0.34%) ⬇️
consensus/replay.go 56.33% <100%> (ø) ⬆️
consensus/reactor.go 66.66% <26.19%> (-4.27%) ⬇️
evidence/reactor.go 63% <33.33%> (-2.94%) ⬇️
p2p/pex/pex_reactor.go 73.05% <50%> (-1.29%) ⬇️
state/validation.go 65.81% <73.68%> (+0.18%) ⬆️
blockchain/reactor.go 35.78% <8.33%> (-3.67%) ⬇️
... and 3 more

@melekes melekes force-pushed the 2683-validate-reactor-messages branch from a12664e to ce9b642 Compare October 26, 2018 17:46
types/heartbeat.go Outdated Show resolved Hide resolved
@melekes
Copy link
Contributor Author

melekes commented Oct 26, 2018

Also we should try and offload some tasks (like checking negative integers or rather using uint's) to compiler :)

@melekes melekes changed the title [WIP] validate reactor messages validate reactor messages Oct 29, 2018
Copy link
Contributor

@ebuchman ebuchman left a comment

Choose a reason for hiding this comment

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

Woohooo!

blockchain/reactor.go Show resolved Hide resolved
blockchain/reactor.go Outdated Show resolved Hide resolved
consensus/reactor.go Show resolved Hide resolved
consensus/reactor.go Show resolved Hide resolved
consensus/reactor.go Outdated Show resolved Hide resolved
types/part_set.go Show resolved Hide resolved
}
if p.Round < 0 {
return errors.New("Negative Round")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

timestamp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how should validate it? compare it to the local time with some delta?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeh, maybe plus or minus a year? Just to eliminate the crazy outliers. The decoder will have done alot of work for us here already actually. We can punt on it for now.

const (
// MaxSignatureSize is a maximum allowed signature size for the Heartbeat,
// Proposal and Vote.
MaxSignatureSize = 64
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need this to be the math.Max of values read from the crypto package incase we introduce bigger signatures

types/vote.go Outdated Show resolved Hide resolved
}
if err := vote.BlockID.ValidateBasic(); err != nil {
return fmt.Errorf("Wrong BlockID: %v", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

timestamp and Type

@melekes melekes force-pushed the 2683-validate-reactor-messages branch from c8cf780 to 45a71b6 Compare October 30, 2018 13:13
Copy link
Contributor

@ebuchman ebuchman left a comment

Choose a reason for hiding this comment

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

Great work, thanks @melekes !

consensus/reactor.go Outdated Show resolved Hide resolved
types/evidence.go Show resolved Hide resolved
}
if p.Round < 0 {
return errors.New("Negative Round")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeh, maybe plus or minus a year? Just to eliminate the crazy outliers. The decoder will have done alot of work for us here already actually. We can punt on it for now.

@tendermint tendermint deleted a comment from ebuchman Oct 30, 2018
@@ -50,6 +50,11 @@ func (p *Proposal) ValidateBasic() error {
if p.Round < 0 {
return errors.New("Negative Round")
}
now := tmtime.Now()
oneYear := 8766 * time.Hour
Copy link
Contributor

Choose a reason for hiding this comment

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

let's make a ValidateTime(timestamp time.Time) error function for this?

if !bytes.Equal(b.EvidenceHash, b.Evidence.Hash()) {
return fmt.Errorf(
"Wrong Block.Header.EvidenceHash. Expected %v, got %v",
b.EvidenceHash,
b.Evidence.Hash(),
)
}

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also do ValidateBasic on the evidence here since otherwise the votes in the DuplicateVoteEvidence could still be nil when the block is further processed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil
for _, ev := range b.Evidence.Evidence {
if err := ev.ValidateBasic(); err != nil {
return err
}
}
return nil

Copy link
Contributor

Choose a reason for hiding this comment

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

@ebuchman @melekes This would be a quick fix. However b.Evidence is of the type EvidenceData which should also have a ValidateBasic function. That would also have to check whether EvidenceData.Evidence != nil since a nil slice could be passed which could cause another panic in a hypothetical scenario.

Copy link
Contributor

Choose a reason for hiding this comment

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

b.Evidence can't be nil since it's not a pointer. b.Evidence.Evidence could be nil because it's a slice, but here we just loop over it, so if its nil its no problem, the loop just won't run. The methods defined on EvidenceList similarly only loop over it, so if it's nil there should be no issue. Am I missing something? Or you're saying we should always ensure we have a zero-length array here and not nil ?

@melekes melekes force-pushed the 2683-validate-reactor-messages branch from b306b55 to 7f919df Compare October 30, 2018 18:03
@melekes melekes force-pushed the 2683-validate-reactor-messages branch from 916216e to e6aaed4 Compare October 31, 2018 08:49
Fix

```
grouped write of manifest, lock and vendor: failed to export github.com/tendermint/go-amino: fatal: failed to unpack tree object 6dcc6ddc143e116455c94b25c1004c99e0d0ca12
```

by running `dep ensure -update`
@ebuchman
Copy link
Contributor

Why were the test files deleted? p2p tests fail:

Successfully initialized 4 node directories
ERROR: open /go/src/github.com/tendermint/tendermint/test/p2p/data/mach0/config/node_key.json: no such file or directory
Exited with code 1

@melekes
Copy link
Contributor Author

melekes commented Oct 31, 2018

Why were the test files deleted? p2p tests fail:

we now use tendermint testnet cmd to generate them (that way we won't need to update them every time we change genesis/node_key/priv_validator files). Tests pass for me locally. I am not sure why they're failing on circle.

@melekes
Copy link
Contributor Author

melekes commented Oct 31, 2018

Done here.

@ebuchman ebuchman merged commit fb91ef7 into develop Nov 1, 2018
@ebuchman ebuchman deleted the 2683-validate-reactor-messages branch November 1, 2018 06:07
maxim-levy pushed a commit to maxim-levy/tendermint that referenced this pull request Nov 13, 2018
* 'master' of https://github.com/tendermint/tendermint: (330 commits)
  Release/v0.26.1 (tendermint#2803)
  fix amino overhead computation for Tx (tendermint#2792)
  p2p: re-check after sleeps (tendermint#2664)
  check the result of `ps.peer.Send` before calling `ps.setHasVote` (tendermint#2787)
  p2p: AddressBook requires addresses to have IDs; Do not close conn immediately after sending pex addrs in seed mode (tendermint#2797)
  test AutoFile#Size (happy path)
  [autofile/group] do not panic when checking size
  openFile creates a file if not exist => ErrNotExist is not possible
  use our logger in autofile/group
  Add tests for ValidateBasic methods (tendermint#2754)
  [docs] improve organization of ABCI docs & fix links (tendermint#2749)
  p2p: peer-id -> peer_id (tendermint#2771)
  mempool: print postCheck error (tendermint#2762)
  Fix crypto/merkle ProofOperators.Verify to check bounds on keypath pa… (tendermint#2756)
  Mempool WAL is still created by default in home directory, leads to permission errors (tendermint#2758)
  mempool: ErrPreCheck and more log info (tendermint#2724)
  Release/v0.26.0 (tendermint#2726)
  [ADR] [DRAFT] pubsub 2.0 (tendermint#2532)
  validate reactor messages (tendermint#2711)
  TMHASH is 32 bytes. Closes tendermint#1990 (tendermint#2732)
  ...
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.

None yet

5 participants