mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-18 21:26:20 +00:00
chore: Format and fix lints (#9336)
* make format Signed-off-by: Thane Thomson <connect@thanethomson.com> * Fix linting directives Signed-off-by: Thane Thomson <connect@thanethomson.com> * make mockery Signed-off-by: Thane Thomson <connect@thanethomson.com> * Appease CI linter Signed-off-by: Thane Thomson <connect@thanethomson.com> * Appease CI linter Signed-off-by: Thane Thomson <connect@thanethomson.com> Signed-off-by: Thane Thomson <connect@thanethomson.com>
This commit is contained in:
+1
-1
@@ -211,7 +211,7 @@ func makeBlockID(hash []byte, partSetSize uint32, partSetHash []byte) BlockID {
|
||||
|
||||
var nilBytes []byte
|
||||
|
||||
// This follows RFC-6962, i.e. `echo -n '' | sha256sum`
|
||||
// This follows RFC-6962, i.e. `echo -n ” | sha256sum`
|
||||
var emptyBytes = []byte{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8,
|
||||
0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b,
|
||||
0x78, 0x52, 0xb8, 0x55}
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ type EventBusSubscriber interface {
|
||||
|
||||
type Subscription interface {
|
||||
Out() <-chan tmpubsub.Message
|
||||
Cancelled() <-chan struct{} // nolint: misspell
|
||||
Cancelled() <-chan struct{} //nolint: misspell
|
||||
Err() error
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ func (b *EventBus) PublishEventValidatorSetUpdates(data EventDataValidatorSetUpd
|
||||
return b.Publish(EventValidatorSetUpdates, data)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------
|
||||
type NopEventBus struct{}
|
||||
|
||||
func (NopEventBus) Subscribe(
|
||||
|
||||
+3
-3
@@ -4,9 +4,9 @@ import "reflect"
|
||||
|
||||
// Go lacks a simple and safe way to see if something is a typed nil.
|
||||
// See:
|
||||
// - https://dave.cheney.net/2017/08/09/typed-nils-in-go-2
|
||||
// - https://groups.google.com/forum/#!topic/golang-nuts/wnH302gBa4I/discussion
|
||||
// - https://github.com/golang/go/issues/21538
|
||||
// - https://dave.cheney.net/2017/08/09/typed-nils-in-go-2
|
||||
// - https://groups.google.com/forum/#!topic/golang-nuts/wnH302gBa4I/discussion
|
||||
// - https://github.com/golang/go/issues/21538
|
||||
func isTypedNil(o interface{}) bool {
|
||||
rv := reflect.ValueOf(o)
|
||||
switch rv.Kind() {
|
||||
|
||||
+18
-13
@@ -411,14 +411,17 @@ func processChanges(origChanges []*Validator) (updates, removals []*Validator, e
|
||||
//
|
||||
// Inputs:
|
||||
// updates - a list of proper validator changes, i.e. they have been verified by processChanges for duplicates
|
||||
// and invalid values.
|
||||
//
|
||||
// and invalid values.
|
||||
//
|
||||
// vals - the original validator set. Note that vals is NOT modified by this function.
|
||||
// removedPower - the total voting power that will be removed after the updates are verified and applied.
|
||||
//
|
||||
// Returns:
|
||||
// tvpAfterUpdatesBeforeRemovals - the new total voting power if these updates would be applied without the removals.
|
||||
// Note that this will be < 2 * MaxTotalVotingPower in case high power validators are removed and
|
||||
// validators are added/ updated with high power values.
|
||||
//
|
||||
// Note that this will be < 2 * MaxTotalVotingPower in case high power validators are removed and
|
||||
// validators are added/ updated with high power values.
|
||||
//
|
||||
// err - non-nil if the maximum allowed total voting power would be exceeded
|
||||
func verifyUpdates(
|
||||
@@ -467,8 +470,9 @@ func numNewValidators(updates []*Validator, vals *ValidatorSet) int {
|
||||
// 'updates' parameter must be a list of unique validators to be added or updated.
|
||||
//
|
||||
// 'updatedTotalVotingPower' is the total voting power of a set where all updates would be applied but
|
||||
// not the removals. It must be < 2*MaxTotalVotingPower and may be close to this limit if close to
|
||||
// MaxTotalVotingPower will be removed. This is still safe from overflow since MaxTotalVotingPower is maxInt64/8.
|
||||
//
|
||||
// not the removals. It must be < 2*MaxTotalVotingPower and may be close to this limit if close to
|
||||
// MaxTotalVotingPower will be removed. This is still safe from overflow since MaxTotalVotingPower is maxInt64/8.
|
||||
//
|
||||
// No changes are made to the validator set 'vals'.
|
||||
func computeNewPriorities(updates []*Validator, vals *ValidatorSet, updatedTotalVotingPower int64) {
|
||||
@@ -638,14 +642,15 @@ func (vals *ValidatorSet) updateWithChangeSet(changes []*Validator, allowDeletes
|
||||
|
||||
// UpdateWithChangeSet attempts to update the validator set with 'changes'.
|
||||
// It performs the following steps:
|
||||
// - validates the changes making sure there are no duplicates and splits them in updates and deletes
|
||||
// - verifies that applying the changes will not result in errors
|
||||
// - computes the total voting power BEFORE removals to ensure that in the next steps the priorities
|
||||
// across old and newly added validators are fair
|
||||
// - computes the priorities of new validators against the final set
|
||||
// - applies the updates against the validator set
|
||||
// - applies the removals against the validator set
|
||||
// - performs scaling and centering of priority values
|
||||
// - validates the changes making sure there are no duplicates and splits them in updates and deletes
|
||||
// - verifies that applying the changes will not result in errors
|
||||
// - computes the total voting power BEFORE removals to ensure that in the next steps the priorities
|
||||
// across old and newly added validators are fair
|
||||
// - computes the priorities of new validators against the final set
|
||||
// - applies the updates against the validator set
|
||||
// - applies the removals against the validator set
|
||||
// - performs scaling and centering of priority values
|
||||
//
|
||||
// If an error is detected during verification steps, it is returned and the validator set
|
||||
// is not changed.
|
||||
func (vals *ValidatorSet) UpdateWithChangeSet(changes []*Validator) error {
|
||||
|
||||
@@ -1641,7 +1641,7 @@ func TestValidatorSetProtoBuf(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------
|
||||
// ---------------------
|
||||
// Sort validators by priority and address
|
||||
type validatorsByPriority []*Validator
|
||||
|
||||
@@ -1682,9 +1682,8 @@ func (tvals testValsByVotingPower) Swap(i, j int) {
|
||||
tvals[i], tvals[j] = tvals[j], tvals[i]
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
// -------------------------------------
|
||||
// Benchmark tests
|
||||
//
|
||||
func BenchmarkUpdates(b *testing.B) {
|
||||
const (
|
||||
n = 100
|
||||
|
||||
+32
-30
@@ -25,38 +25,38 @@ const (
|
||||
type P2PID string
|
||||
|
||||
/*
|
||||
VoteSet helps collect signatures from validators at each height+round for a
|
||||
predefined vote type.
|
||||
VoteSet helps collect signatures from validators at each height+round for a
|
||||
predefined vote type.
|
||||
|
||||
We need VoteSet to be able to keep track of conflicting votes when validators
|
||||
double-sign. Yet, we can't keep track of *all* the votes seen, as that could
|
||||
be a DoS attack vector.
|
||||
We need VoteSet to be able to keep track of conflicting votes when validators
|
||||
double-sign. Yet, we can't keep track of *all* the votes seen, as that could
|
||||
be a DoS attack vector.
|
||||
|
||||
There are two storage areas for votes.
|
||||
1. voteSet.votes
|
||||
2. voteSet.votesByBlock
|
||||
There are two storage areas for votes.
|
||||
1. voteSet.votes
|
||||
2. voteSet.votesByBlock
|
||||
|
||||
`.votes` is the "canonical" list of votes. It always has at least one vote,
|
||||
if a vote from a validator had been seen at all. Usually it keeps track of
|
||||
the first vote seen, but when a 2/3 majority is found, votes for that get
|
||||
priority and are copied over from `.votesByBlock`.
|
||||
`.votes` is the "canonical" list of votes. It always has at least one vote,
|
||||
if a vote from a validator had been seen at all. Usually it keeps track of
|
||||
the first vote seen, but when a 2/3 majority is found, votes for that get
|
||||
priority and are copied over from `.votesByBlock`.
|
||||
|
||||
`.votesByBlock` keeps track of a list of votes for a particular block. There
|
||||
are two ways a &blockVotes{} gets created in `.votesByBlock`.
|
||||
1. the first vote seen by a validator was for the particular block.
|
||||
2. a peer claims to have seen 2/3 majority for the particular block.
|
||||
`.votesByBlock` keeps track of a list of votes for a particular block. There
|
||||
are two ways a &blockVotes{} gets created in `.votesByBlock`.
|
||||
1. the first vote seen by a validator was for the particular block.
|
||||
2. a peer claims to have seen 2/3 majority for the particular block.
|
||||
|
||||
Since the first vote from a validator will always get added in `.votesByBlock`
|
||||
, all votes in `.votes` will have a corresponding entry in `.votesByBlock`.
|
||||
Since the first vote from a validator will always get added in `.votesByBlock`
|
||||
, all votes in `.votes` will have a corresponding entry in `.votesByBlock`.
|
||||
|
||||
When a &blockVotes{} in `.votesByBlock` reaches a 2/3 majority quorum, its
|
||||
votes are copied into `.votes`.
|
||||
When a &blockVotes{} in `.votesByBlock` reaches a 2/3 majority quorum, its
|
||||
votes are copied into `.votes`.
|
||||
|
||||
All this is memory bounded because conflicting votes only get added if a peer
|
||||
told us to track that block, each peer only gets to tell us 1 such block, and,
|
||||
there's only a limited number of peers.
|
||||
All this is memory bounded because conflicting votes only get added if a peer
|
||||
told us to track that block, each peer only gets to tell us 1 such block, and,
|
||||
there's only a limited number of peers.
|
||||
|
||||
NOTE: Assumes that the sum total of voting power does not exceed MaxUInt64.
|
||||
NOTE: Assumes that the sum total of voting power does not exceed MaxUInt64.
|
||||
*/
|
||||
type VoteSet struct {
|
||||
chainID string
|
||||
@@ -133,8 +133,10 @@ func (voteSet *VoteSet) Size() int {
|
||||
|
||||
// Returns added=true if vote is valid and new.
|
||||
// Otherwise returns err=ErrVote[
|
||||
// UnexpectedStep | InvalidIndex | InvalidAddress |
|
||||
// InvalidSignature | InvalidBlockHash | ConflictingVotes ]
|
||||
//
|
||||
// UnexpectedStep | InvalidIndex | InvalidAddress |
|
||||
// InvalidSignature | InvalidBlockHash | ConflictingVotes ]
|
||||
//
|
||||
// Duplicate votes return added=false, err=nil.
|
||||
// Conflicting votes return added=*, err=ErrVoteConflictingVotes.
|
||||
// NOTE: vote should not be mutated after adding.
|
||||
@@ -644,10 +646,10 @@ func (voteSet *VoteSet) MakeCommit() *Commit {
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Votes for a particular block
|
||||
There are two ways a *blockVotes gets created for a blockKey.
|
||||
1. first (non-conflicting) vote of a validator w/ blockKey (peerMaj23=false)
|
||||
2. A peer claims to have a 2/3 majority w/ blockKey (peerMaj23=true)
|
||||
Votes for a particular block
|
||||
There are two ways a *blockVotes gets created for a blockKey.
|
||||
1. first (non-conflicting) vote of a validator w/ blockKey (peerMaj23=false)
|
||||
2. A peer claims to have a 2/3 majority w/ blockKey (peerMaj23=true)
|
||||
*/
|
||||
type blockVotes struct {
|
||||
peerMaj23 bool // peer claims to have maj23
|
||||
|
||||
Reference in New Issue
Block a user