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

Feat/block validation #2899

Merged
merged 11 commits into from
Jun 19, 2019
Merged

Feat/block validation #2899

merged 11 commits into from
Jun 19, 2019

Conversation

frrist
Copy link
Member

@frrist frrist commented Jun 6, 2019

What

This PR implements block validation as defined in spec.
This PR must merge after #2897

Follow On:

@frrist frrist requested review from anorth and ZenGround0 June 6, 2019 18:49
@frrist frrist force-pushed the feat/block-validation branch from db9a4b2 to 0b2bedc Compare June 6, 2019 18:56
// check that child is appropriately delayed from its parents including
// null blocks.
// TODO replace check on height when #2222 lands
limit := uint64(pmin) + uint64(dv.BlockTime().Seconds())*uint64(uint64(child.Height)-ph)
Copy link
Contributor

Choose a reason for hiding this comment

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

The outer cast to uint64 appears unnecessary.

@@ -40,3 +41,7 @@ func NewConfiguredBlockClock(blockTime time.Duration) *DefaultBlockClock {
func (bc *DefaultBlockClock) BlockTime() time.Duration {
return bc.blockTime
}

func (bc DefaultBlockClock) EpochSeconds() int64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this name seems a little unclear (could just be me). Why not Now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Missing function comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Called it EpochSeconds due to this comment: #2882 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

will add a comment as well

Copy link
Contributor

Choose a reason for hiding this comment

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

oh I see. One reason I don't like EpochSeconds is that epoch is a term with a precise meaning for the consensus protocol and it appears to be used in a different way here. This might be something @anorth didn't think of.

if uint64(blk.Height) < 0 {
return fmt.Errorf("block has negative height")
}
// TODO vlidate block signature: 1054
Copy link
Contributor

Choose a reason for hiding this comment

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

super nit: "validate"

types/tipset.go Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Jun 7, 2019

Codecov Report

Merging #2899 into master will decrease coverage by <1%.
The diff coverage is 74%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #2899   +/-   ##
======================================
- Coverage      43%     43%   -1%     
======================================
  Files         213     213           
  Lines       12680   12703   +23     
======================================
- Hits         5560    5528   -32     
- Misses       6261    6320   +59     
+ Partials      859     855    -4
Impacted Files Coverage Δ
mining/block_generate.go 71% <100%> (ø) ⬆️
node/node.go 59% <100%> (ø) ⬆️
types/tipset.go 80% <50%> (-4%) ⬇️
consensus/block_validation.go 86% <80%> (+86%) ⬆️
proofs/sectorbuilder/testing/builder.go 0% <0%> (-88%) ⬇️
proofs/sectorbuilder/testing/harness.go 0% <0%> (-58%) ⬇️
protocol/hello/hello.go 77% <0%> (-7%) ⬇️

@anorth
Copy link
Member

anorth commented Jun 12, 2019

FYI I'm not looking at this yet because it's marked draft

@frrist frrist force-pushed the feat/timestamp-block branch 3 times, most recently from b2caa77 to 3a5fe58 Compare June 12, 2019 17:25
@frrist frrist force-pushed the feat/block-validation branch from 4bff05a to f55889f Compare June 12, 2019 19:02
@frrist frrist requested a review from ingar June 12, 2019 19:05
@frrist frrist marked this pull request as ready for review June 12, 2019 19:05
@frrist frrist force-pushed the feat/timestamp-block branch 2 times, most recently from ac0d78c to acbcc58 Compare June 12, 2019 20:55
@frrist frrist force-pushed the feat/block-validation branch from f55889f to 867a70f Compare June 12, 2019 20:58
@frrist frrist force-pushed the feat/timestamp-block branch from acbcc58 to da4344d Compare June 12, 2019 21:13
@frrist frrist force-pushed the feat/block-validation branch from 867a70f to 7444af3 Compare June 12, 2019 22:48
@frrist frrist changed the base branch from feat/timestamp-block to master June 12, 2019 22:50
@frrist frrist force-pushed the feat/block-validation branch from 7444af3 to 3f39519 Compare June 12, 2019 22:57
clock/clock.go Outdated

// MockClock returns a mocked clock implementation that may be manually
// set for testing things related to time.
type MockClock struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this belong in its own file, and perhaps in its own package that has to do with testing/test helpers?

clock/clock.go Outdated

// Now returns the current value of the MockClock.
func (mc *MockClock) Now() time.Time {
mc.nowMu.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not quite sure what race condition this mutex is guarding against. Is there one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup this was a mistake, removed.

@@ -86,6 +86,7 @@ func (w *DefaultWorker) Generate(ctx context.Context,
Proof: proof,
StateRoot: newStateTreeCid,
Ticket: ticket,
Timestamp: types.Uint64(time.Now().Unix()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the point of the clock module to encapsulate access to time.Now()? Coming later?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see your "What's next" in the description. 👍

types/tipset.go Outdated
return 0, errUndefTipSet
}
min := ts.blocks[0].Timestamp
for i := 0; i < len(ts.blocks[0:]); i++ {
Copy link
Contributor

@ingar ingar Jun 14, 2019

Choose a reason for hiding this comment

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

Don't quite understand the slice here..

Was this intended to be i := 1; i < len(ts.blocks); i++?
or for block := range ts.blocks[1:]?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, yes thanks!

@frrist frrist force-pushed the feat/block-validation branch from 106e692 to 7fe4e0f Compare June 18, 2019 19:02
Copy link
Member

@anorth anorth left a comment

Choose a reason for hiding this comment

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

Minor blocking comments, but since we're planning to roll a new release for this change, I think we should put the effort into solid testing, so I'd really like those comments addressed too. Let's chat briefly to decide a plan.

clock/clock.go Outdated Show resolved Hide resolved
consensus/block_validation.go Outdated Show resolved Hide resolved
consensus/block_validation.go Outdated Show resolved Hide resolved
consensus/block_validation.go Outdated Show resolved Hide resolved
consensus/block_validation_test.go Outdated Show resolved Hide resolved
consensus/block_validation_test.go Outdated Show resolved Hide resolved
consensus/block_validation_test.go Outdated Show resolved Hide resolved
consensus/block_validation_test.go Outdated Show resolved Hide resolved
testhelpers/clock.go Outdated Show resolved Hide resolved
types/tipset_test.go Show resolved Hide resolved
@frrist frrist force-pushed the feat/block-validation branch from 6a716c3 to 0817d95 Compare June 19, 2019 01:31
// TODO replace check on height when #2222 lands
limit := uint64(pmin) + uint64(dv.BlockTime().Seconds())*(uint64(child.Height)-ph)
if uint64(child.Timestamp) < limit {
return fmt.Errorf("block %s with timestamp %d generated too far in future", child.Cid().String(), child.Timestamp)
Copy link
Member

Choose a reason for hiding this comment

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

"... too far past parent, expected timestamp < %s", ... limit)

@frrist frrist merged commit 989cb18 into master Jun 19, 2019
frrist added a commit that referenced this pull request Jun 19, 2019
* add MinTimestamp to tipset and test
* add clock package and block validation
@ZenGround0 ZenGround0 deleted the feat/block-validation branch October 29, 2019 14:48
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.

5 participants