Skip to content

Commit

Permalink
adjust nanoseconds for voteTime in state.go. add logs into VerifyCommit
Browse files Browse the repository at this point in the history
  • Loading branch information
RustNinja committed Jan 17, 2024
1 parent fe45483 commit a33c485
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 19 additions & 1 deletion consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,25 @@ func (cs *State) signVote(

func (cs *State) voteTime() time.Time {
now := cmttime.Now()
minVoteTime := now
//https://protobuf.dev/programming-guides/encoding/#varints
//if nanoseconds is greater than 268435456 proto encoding will take 1 extra byte
//so this nanoseconds adjustment is to make sure the vote time is always the same
nano := now.Nanosecond()
if nano < 268435456 {
nano = 268435456
}
newVoteTime := time.Date(
now.Year(),
now.Month(),
now.Day(),
now.Hour(),
now.Minute(),
now.Second(),
nano,
now.Location(),
)
minVoteTime := newVoteTime
now = newVoteTime
// Minimum time increment between blocks
const timeIota = time.Millisecond
// TODO: We should remove next line in case we don't vote for v in case cs.ProposalBlock == nil,
Expand Down
2 changes: 2 additions & 0 deletions types/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID,

// Validate signature.
voteSignBytes := commit.VoteSignBytes(chainID, int32(idx))
fmt.Println("voteSignBytes from VerifyCommit cometbft")
fmt.Println("voteSignBytes len", fmt.Sprintf("voteSignBytes len %v", len(voteSignBytes)))
if !val.PubKey.VerifySignature(voteSignBytes, commitSig.Signature) {
return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
}
Expand Down

0 comments on commit a33c485

Please sign in to comment.