Skip to content

Commit

Permalink
Check block proposal timestamp first to avoid invalid proposal pass p…
Browse files Browse the repository at this point in the history
…roposer check

Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Jan 18, 2019
1 parent 0f8815e commit 2f5966c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions consensus/moca/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func (consensus *Consensus) waitAndHandleProposal() (*election.Election, error)
continue
}

err = ledger.TimestampCheck(proposal.Header.Timestamp)
if err != nil {
log.Warningf("Ignore proposal that fails to pass timestamp check: %v", err)
continue
}

err := ledger.SignerCheck(proposal.Header)
if err != nil {
log.Warningf("Ignore proposal that fails to pass signer check: %v", err)
Expand Down Expand Up @@ -114,12 +120,6 @@ func (consensus *Consensus) waitAndHandleProposal() (*election.Election, error)
acceptProposal = false
}

err = ledger.TimestampCheck(proposal.Header.Timestamp)
if err != nil {
log.Warningf("Proposal fails to pass timestamp check: %v", err)
acceptProposal = false
}

err = ledger.NextBlockProposerCheck(proposal)
if err != nil {
log.Warningf("Proposal fails to pass next block proposal check: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion core/ledger/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ func TimestampCheck(timestamp int64) error {
latest := now.Add(TimestampTolerance)

if t.Before(earliest) || t.After(latest) {
return fmt.Errorf("timestamp %d exceed my tolerance [%d, %d]", timestamp, earliest.Unix(), latest.Unix())
return fmt.Errorf("timestamp %v exceed my tolerance [%v, %v]", t, earliest, latest)
}

return nil
}

Expand Down

0 comments on commit 2f5966c

Please sign in to comment.