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

core: verify headers in AddHeaders() #703

Merged
merged 5 commits into from
Mar 2, 2020
Merged

core: verify headers in AddHeaders() #703

merged 5 commits into from
Mar 2, 2020

Conversation

fyrchik
Copy link
Contributor

@fyrchik fyrchik commented Feb 29, 2020

  1. Headers need to be verified on adding.
  2. Get rid of global variables in core tests.

Maybe now there is no need to verify block if it's header matches header in headerlist.

@codecov
Copy link

codecov bot commented Feb 29, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@a2b9d85). Click here to learn what that means.
The diff coverage is 78.57%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #703   +/-   ##
=========================================
  Coverage          ?   65.72%           
=========================================
  Files             ?      128           
  Lines             ?    11042           
  Branches          ?        0           
=========================================
  Hits              ?     7257           
  Misses            ?     3506           
  Partials          ?      279
Impacted Files Coverage Δ
pkg/core/blockchain.go 30.65% <78.57%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2b9d85...a3dacd3. Read the comment docs.

pkg/core/helper_test.go Outdated Show resolved Hide resolved
err = fmt.Errorf("header %v is invalid", h)
return
if verify {
if err = bc.verifyHeader(h, lastHeader); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's a good idea doing verification inside headersOp as it effectively locks bc.headerList and verification can take some substantial amount of time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have moved verification of external input upwards, and inside locked context we can only check for the validity of the first header.

pkg/core/blockchain.go Outdated Show resolved Hide resolved
pkg/core/blockchain.go Outdated Show resolved Hide resolved
pkg/core/blockchain_test.go Outdated Show resolved Hide resolved
integration/performance_test.go Outdated Show resolved Hide resolved
pkg/core/transaction/register_test.go Outdated Show resolved Hide resolved
pkg/core/util_test.go Outdated Show resolved Hide resolved
pkg/smartcontract/contract_test.go Outdated Show resolved Hide resolved
if want, have := tk.PrivateKey, acc.privateKey.String(); want != have {
t.Fatalf("expected %s got %s", want, have)
}
want, have := tk.Address, acc.Address
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need intermediate want/have here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we don't, like we didn't need it earlier. It seems more readable.

@roman-khimov roman-khimov added this to the v0.74.0 milestone Mar 2, 2020
It can lead to unnecessary race conditions and is just
a bad practice.
pkg/core/blockchain.go Outdated Show resolved Hide resolved
Headers can be malformed so public methods should verify them
before adding.
This makes tests less verbose and unifies the style
they are written in.
@roman-khimov roman-khimov merged commit 3fc0df7 into master Mar 2, 2020
@roman-khimov roman-khimov deleted the fix/tests branch March 2, 2020 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security Affects security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants