-
Notifications
You must be signed in to change notification settings - Fork 467
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
Feat/block validation #2899
Conversation
db9a4b2
to
0b2bedc
Compare
consensus/block_validation.go
Outdated
// 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) |
There was a problem hiding this comment.
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.
plumbing/clock/clock.go
Outdated
@@ -40,3 +41,7 @@ func NewConfiguredBlockClock(blockTime time.Duration) *DefaultBlockClock { | |||
func (bc *DefaultBlockClock) BlockTime() time.Duration { | |||
return bc.blockTime | |||
} | |||
|
|||
func (bc DefaultBlockClock) EpochSeconds() int64 { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing function comment
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
consensus/block_validation.go
Outdated
if uint64(blk.Height) < 0 { | ||
return fmt.Errorf("block has negative height") | ||
} | ||
// TODO vlidate block signature: 1054 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: "validate"
Codecov Report
@@ 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
|
FYI I'm not looking at this yet because it's marked draft |
b2caa77
to
3a5fe58
Compare
4bff05a
to
f55889f
Compare
ac0d78c
to
acbcc58
Compare
f55889f
to
867a70f
Compare
acbcc58
to
da4344d
Compare
867a70f
to
7444af3
Compare
7444af3
to
3f39519
Compare
clock/clock.go
Outdated
|
||
// MockClock returns a mocked clock implementation that may be manually | ||
// set for testing things related to time. | ||
type MockClock struct { |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
mining/block_generate.go
Outdated
@@ -86,6 +86,7 @@ func (w *DefaultWorker) Generate(ctx context.Context, | |||
Proof: proof, | |||
StateRoot: newStateTreeCid, | |||
Ticket: ticket, | |||
Timestamp: types.Uint64(time.Now().Unix()), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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++ { |
There was a problem hiding this comment.
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:]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, yes thanks!
106e692
to
7fe4e0f
Compare
There was a problem hiding this 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.
6a716c3
to
0817d95
Compare
consensus/block_validation.go
Outdated
// 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) |
There was a problem hiding this comment.
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)
* add MinTimestamp to tipset and test * add clock package and block validation
What
This PR implements block validation as defined in spec.
This PR must merge after #2897
Follow On: