mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-31 21:27:04 +00:00
Fix linter errors thrown by lll (#3970)
* Fix long line errors in abci, crypto, and libs packages * Fix long lines in p2p and rpc packages * Fix long lines in abci, state, and tools packages * Fix long lines in behaviour and blockchain packages * Fix long lines in cmd and config packages * Begin fixing long lines in consensus package * Finish fixing long lines in consensus package * Add lll exclusion for lines containing URLs * Fix long lines in crypto package * Fix long lines in evidence package * Fix long lines in mempool and node packages * Fix long lines in libs package * Fix long lines in lite package * Fix new long line in node package * Fix long lines in p2p package * Ignore gocritic warning * Fix long lines in privval package * Fix long lines in rpc package * Fix long lines in scripts package * Fix long lines in state package * Fix long lines in tools package * Fix long lines in types package * Enable lll linter
This commit is contained in:
+2
-1
@@ -355,7 +355,8 @@ type Header struct {
|
||||
NextValidatorsHash cmn.HexBytes `json:"next_validators_hash"` // validators for the next block
|
||||
ConsensusHash cmn.HexBytes `json:"consensus_hash"` // consensus params for current block
|
||||
AppHash cmn.HexBytes `json:"app_hash"` // state after txs from the previous block
|
||||
LastResultsHash cmn.HexBytes `json:"last_results_hash"` // root hash of all results from the txs from the previous block
|
||||
// root hash of all results from the txs from the previous block
|
||||
LastResultsHash cmn.HexBytes `json:"last_results_hash"`
|
||||
|
||||
// consensus info
|
||||
EvidenceHash cmn.HexBytes `json:"evidence_hash"` // evidence included in the block
|
||||
|
||||
+6
-1
@@ -553,7 +553,12 @@ func TestSignedHeaderValidateBasic(t *testing.T) {
|
||||
Header: tc.shHeader,
|
||||
Commit: tc.shCommit,
|
||||
}
|
||||
assert.Equal(t, tc.expectErr, sh.ValidateBasic(validSignedHeader.Header.ChainID) != nil, "Validate Basic had an unexpected result")
|
||||
assert.Equal(
|
||||
t,
|
||||
tc.expectErr,
|
||||
sh.ValidateBasic(validSignedHeader.Header.ChainID) != nil,
|
||||
"Validate Basic had an unexpected result",
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+17
-3
@@ -70,13 +70,22 @@ func (b *EventBus) NumClientSubscriptions(clientID string) int {
|
||||
return b.pubsub.NumClientSubscriptions(clientID)
|
||||
}
|
||||
|
||||
func (b *EventBus) Subscribe(ctx context.Context, subscriber string, query tmpubsub.Query, outCapacity ...int) (Subscription, error) {
|
||||
func (b *EventBus) Subscribe(
|
||||
ctx context.Context,
|
||||
subscriber string,
|
||||
query tmpubsub.Query,
|
||||
outCapacity ...int,
|
||||
) (Subscription, error) {
|
||||
return b.pubsub.Subscribe(ctx, subscriber, query, outCapacity...)
|
||||
}
|
||||
|
||||
// This method can be used for a local consensus explorer and synchronous
|
||||
// testing. Do not use for for public facing / untrusted subscriptions!
|
||||
func (b *EventBus) SubscribeUnbuffered(ctx context.Context, subscriber string, query tmpubsub.Query) (Subscription, error) {
|
||||
func (b *EventBus) SubscribeUnbuffered(
|
||||
ctx context.Context,
|
||||
subscriber string,
|
||||
query tmpubsub.Query,
|
||||
) (Subscription, error) {
|
||||
return b.pubsub.SubscribeUnbuffered(ctx, subscriber, query)
|
||||
}
|
||||
|
||||
@@ -215,7 +224,12 @@ func (b *EventBus) PublishEventValidatorSetUpdates(data EventDataValidatorSetUpd
|
||||
//-----------------------------------------------------------------------------
|
||||
type NopEventBus struct{}
|
||||
|
||||
func (NopEventBus) Subscribe(ctx context.Context, subscriber string, query tmpubsub.Query, out chan<- interface{}) error {
|
||||
func (NopEventBus) Subscribe(
|
||||
ctx context.Context,
|
||||
subscriber string,
|
||||
query tmpubsub.Query,
|
||||
out chan<- interface{},
|
||||
) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+14
-3
@@ -141,17 +141,28 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string, pubKey crypto.PubKey) e
|
||||
|
||||
// Address must be the same
|
||||
if !bytes.Equal(dve.VoteA.ValidatorAddress, dve.VoteB.ValidatorAddress) {
|
||||
return fmt.Errorf("DuplicateVoteEvidence Error: Validator addresses do not match. Got %X and %X", dve.VoteA.ValidatorAddress, dve.VoteB.ValidatorAddress)
|
||||
return fmt.Errorf(
|
||||
"DuplicateVoteEvidence Error: Validator addresses do not match. Got %X and %X",
|
||||
dve.VoteA.ValidatorAddress,
|
||||
dve.VoteB.ValidatorAddress,
|
||||
)
|
||||
}
|
||||
|
||||
// Index must be the same
|
||||
if dve.VoteA.ValidatorIndex != dve.VoteB.ValidatorIndex {
|
||||
return fmt.Errorf("DuplicateVoteEvidence Error: Validator indices do not match. Got %d and %d", dve.VoteA.ValidatorIndex, dve.VoteB.ValidatorIndex)
|
||||
return fmt.Errorf(
|
||||
"DuplicateVoteEvidence Error: Validator indices do not match. Got %d and %d",
|
||||
dve.VoteA.ValidatorIndex,
|
||||
dve.VoteB.ValidatorIndex,
|
||||
)
|
||||
}
|
||||
|
||||
// BlockIDs must be different
|
||||
if dve.VoteA.BlockID.Equals(dve.VoteB.BlockID) {
|
||||
return fmt.Errorf("DuplicateVoteEvidence Error: BlockIDs are the same (%v) - not a real duplicate vote", dve.VoteA.BlockID)
|
||||
return fmt.Errorf(
|
||||
"DuplicateVoteEvidence Error: BlockIDs are the same (%v) - not a real duplicate vote",
|
||||
dve.VoteA.BlockID,
|
||||
)
|
||||
}
|
||||
|
||||
// pubkey must match address (this should already be true, sanity check)
|
||||
|
||||
+31
-5
@@ -20,13 +20,33 @@ func TestGenesisBad(t *testing.T) {
|
||||
[]byte(`{}`), // empty
|
||||
[]byte(`{"chain_id":"mychain","validators":[{}]}`), // invalid validator
|
||||
// missing pub_key type
|
||||
[]byte(`{"validators":[{"pub_key":{"value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||
[]byte(
|
||||
`{"validators":[{"pub_key":{"value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`,
|
||||
),
|
||||
// missing chain_id
|
||||
[]byte(`{"validators":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||
[]byte(
|
||||
`{"validators":[` +
|
||||
`{"pub_key":{` +
|
||||
`"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="` +
|
||||
`},"power":"10","name":""}` +
|
||||
`]}`,
|
||||
),
|
||||
// too big chain_id
|
||||
[]byte(`{"chain_id": "Lorem ipsum dolor sit amet, consectetuer adipiscing", "validators": [{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||
[]byte(
|
||||
`{"chain_id": "Lorem ipsum dolor sit amet, consectetuer adipiscing", "validators": [` +
|
||||
`{"pub_key":{` +
|
||||
`"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="` +
|
||||
`},"power":"10","name":""}` +
|
||||
`]}`,
|
||||
),
|
||||
// wrong address
|
||||
[]byte(`{"chain_id":"mychain", "validators":[{"address": "A", "pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||
[]byte(
|
||||
`{"chain_id":"mychain", "validators":[` +
|
||||
`{"address": "A", "pub_key":{` +
|
||||
`"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="` +
|
||||
`},"power":"10","name":""}` +
|
||||
`]}`,
|
||||
),
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
@@ -37,7 +57,13 @@ func TestGenesisBad(t *testing.T) {
|
||||
|
||||
func TestGenesisGood(t *testing.T) {
|
||||
// test a good one by raw json
|
||||
genDocBytes := []byte(`{"genesis_time":"0001-01-01T00:00:00Z","chain_id":"test-chain-QDKdJr","consensus_params":null,"validators":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}],"app_hash":"","app_state":{"account_owner": "Bob"}}`)
|
||||
genDocBytes := []byte(
|
||||
`{"genesis_time":"0001-01-01T00:00:00Z","chain_id":"test-chain-QDKdJr","consensus_params":null,"validators":[` +
|
||||
`{"pub_key":{` +
|
||||
`"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="` +
|
||||
`},"power":"10","name":""}` +
|
||||
`],"app_hash":"","app_state":{"account_owner": "Bob"}}`,
|
||||
)
|
||||
_, err := GenesisDocFromJSON(genDocBytes)
|
||||
assert.NoError(t, err, "expected no error for good genDoc json")
|
||||
|
||||
|
||||
+7
-1
@@ -37,7 +37,13 @@ func signAddVote(privVal PrivValidator, vote *Vote, voteSet *VoteSet) (signed bo
|
||||
return voteSet.AddVote(vote)
|
||||
}
|
||||
|
||||
func MakeVote(height int64, blockID BlockID, valSet *ValidatorSet, privVal PrivValidator, chainID string) (*Vote, error) {
|
||||
func MakeVote(
|
||||
height int64,
|
||||
blockID BlockID,
|
||||
valSet *ValidatorSet,
|
||||
privVal PrivValidator,
|
||||
chainID string,
|
||||
) (*Vote, error) {
|
||||
addr := privVal.GetPubKey().Address()
|
||||
idx, _ := valSet.GetByAddress(addr)
|
||||
vote := &Vote{
|
||||
|
||||
@@ -379,7 +379,10 @@ func processChanges(origChanges []*Validator) (updates, removals []*Validator, e
|
||||
// 'updates' should be a list of proper validator changes, i.e. they have been verified
|
||||
// by processChanges for duplicates and invalid values.
|
||||
// No changes are made to the validator set 'vals'.
|
||||
func verifyUpdates(updates []*Validator, vals *ValidatorSet) (updatedTotalVotingPower int64, numNewValidators int, err error) {
|
||||
func verifyUpdates(
|
||||
updates []*Validator,
|
||||
vals *ValidatorSet,
|
||||
) (updatedTotalVotingPower int64, numNewValidators int, err error) {
|
||||
|
||||
updatedTotalVotingPower = vals.TotalVotingPower()
|
||||
|
||||
|
||||
@@ -135,7 +135,11 @@ func TestProposerSelection1(t *testing.T) {
|
||||
proposers = append(proposers, string(val.Address))
|
||||
vset.IncrementProposerPriority(1)
|
||||
}
|
||||
expected := `foo baz foo bar foo foo baz foo bar foo foo baz foo foo bar foo baz foo foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo foo bar foo baz foo foo bar foo baz foo foo bar foo baz foo foo bar foo baz foo foo foo baz bar foo foo foo baz foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo foo bar foo baz foo foo bar foo baz foo foo bar foo baz foo foo`
|
||||
expected := `foo baz foo bar foo foo baz foo bar foo foo baz foo foo bar foo baz foo foo bar` +
|
||||
` foo foo baz foo bar foo foo baz foo bar foo foo baz foo foo bar foo baz foo foo bar` +
|
||||
` foo baz foo foo bar foo baz foo foo bar foo baz foo foo foo baz bar foo foo foo baz` +
|
||||
` foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo bar foo foo baz foo` +
|
||||
` foo bar foo baz foo foo bar foo baz foo foo bar foo baz foo foo`
|
||||
if expected != strings.Join(proposers, " ") {
|
||||
t.Errorf("Expected sequence of proposers was\n%v\nbut got \n%v", expected, strings.Join(proposers, " "))
|
||||
}
|
||||
@@ -205,13 +209,31 @@ func TestProposerSelection2(t *testing.T) {
|
||||
}
|
||||
|
||||
if propCount[0] != 40*N {
|
||||
t.Fatalf("Expected prop count for validator with 4/12 of voting power to be %d/%d. Got %d/%d", 40*N, 120*N, propCount[0], 120*N)
|
||||
t.Fatalf(
|
||||
"Expected prop count for validator with 4/12 of voting power to be %d/%d. Got %d/%d",
|
||||
40*N,
|
||||
120*N,
|
||||
propCount[0],
|
||||
120*N,
|
||||
)
|
||||
}
|
||||
if propCount[1] != 50*N {
|
||||
t.Fatalf("Expected prop count for validator with 5/12 of voting power to be %d/%d. Got %d/%d", 50*N, 120*N, propCount[1], 120*N)
|
||||
t.Fatalf(
|
||||
"Expected prop count for validator with 5/12 of voting power to be %d/%d. Got %d/%d",
|
||||
50*N,
|
||||
120*N,
|
||||
propCount[1],
|
||||
120*N,
|
||||
)
|
||||
}
|
||||
if propCount[2] != 30*N {
|
||||
t.Fatalf("Expected prop count for validator with 3/12 of voting power to be %d/%d. Got %d/%d", 30*N, 120*N, propCount[2], 120*N)
|
||||
t.Fatalf(
|
||||
"Expected prop count for validator with 3/12 of voting power to be %d/%d. Got %d/%d",
|
||||
30*N,
|
||||
120*N,
|
||||
propCount[2],
|
||||
120*N,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +269,15 @@ func TestProposerSelection3(t *testing.T) {
|
||||
computed := vset.GetProposer() // findGetProposer()
|
||||
if i != 0 {
|
||||
if !bytes.Equal(got, computed.Address) {
|
||||
t.Fatalf(fmt.Sprintf("vset.Proposer (%X) does not match computed proposer (%X) for (%d, %d)", got, computed.Address, i, j))
|
||||
t.Fatalf(
|
||||
fmt.Sprintf(
|
||||
"vset.Proposer (%X) does not match computed proposer (%X) for (%d, %d)",
|
||||
got,
|
||||
computed.Address,
|
||||
i,
|
||||
j,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,10 +361,26 @@ func TestAvgProposerPriority(t *testing.T) {
|
||||
want int64
|
||||
}{
|
||||
0: {ValidatorSet{Validators: []*Validator{{ProposerPriority: 0}, {ProposerPriority: 0}, {ProposerPriority: 0}}}, 0},
|
||||
1: {ValidatorSet{Validators: []*Validator{{ProposerPriority: math.MaxInt64}, {ProposerPriority: 0}, {ProposerPriority: 0}}}, math.MaxInt64 / 3},
|
||||
2: {ValidatorSet{Validators: []*Validator{{ProposerPriority: math.MaxInt64}, {ProposerPriority: 0}}}, math.MaxInt64 / 2},
|
||||
3: {ValidatorSet{Validators: []*Validator{{ProposerPriority: math.MaxInt64}, {ProposerPriority: math.MaxInt64}}}, math.MaxInt64},
|
||||
4: {ValidatorSet{Validators: []*Validator{{ProposerPriority: math.MinInt64}, {ProposerPriority: math.MinInt64}}}, math.MinInt64},
|
||||
1: {
|
||||
ValidatorSet{
|
||||
Validators: []*Validator{{ProposerPriority: math.MaxInt64}, {ProposerPriority: 0}, {ProposerPriority: 0}},
|
||||
}, math.MaxInt64 / 3,
|
||||
},
|
||||
2: {
|
||||
ValidatorSet{
|
||||
Validators: []*Validator{{ProposerPriority: math.MaxInt64}, {ProposerPriority: 0}},
|
||||
}, math.MaxInt64 / 2,
|
||||
},
|
||||
3: {
|
||||
ValidatorSet{
|
||||
Validators: []*Validator{{ProposerPriority: math.MaxInt64}, {ProposerPriority: math.MaxInt64}},
|
||||
}, math.MaxInt64,
|
||||
},
|
||||
4: {
|
||||
ValidatorSet{
|
||||
Validators: []*Validator{{ProposerPriority: math.MinInt64}, {ProposerPriority: math.MinInt64}},
|
||||
}, math.MinInt64,
|
||||
},
|
||||
}
|
||||
for i, tc := range tcs {
|
||||
got := tc.vs.computeAvgProposerPriority()
|
||||
|
||||
+7
-2
@@ -173,7 +173,8 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
|
||||
// Ensure that the signer has the right address.
|
||||
if !bytes.Equal(valAddr, lookupAddr) {
|
||||
return false, errors.Wrapf(ErrVoteInvalidValidatorAddress,
|
||||
"vote.ValidatorAddress (%X) does not match address (%X) for vote.ValidatorIndex (%d)\nEnsure the genesis file is correct across all validators.",
|
||||
"vote.ValidatorAddress (%X) does not match address (%X) for vote.ValidatorIndex (%d)\n"+
|
||||
"Ensure the genesis file is correct across all validators.",
|
||||
valAddr, lookupAddr, valIndex)
|
||||
}
|
||||
|
||||
@@ -214,7 +215,11 @@ func (voteSet *VoteSet) getVote(valIndex int, blockKey string) (vote *Vote, ok b
|
||||
|
||||
// Assumes signature is valid.
|
||||
// If conflicting vote exists, returns it.
|
||||
func (voteSet *VoteSet) addVerifiedVote(vote *Vote, blockKey string, votingPower int64) (added bool, conflicting *Vote) {
|
||||
func (voteSet *VoteSet) addVerifiedVote(
|
||||
vote *Vote,
|
||||
blockKey string,
|
||||
votingPower int64,
|
||||
) (added bool, conflicting *Vote) {
|
||||
valIndex := vote.ValidatorIndex
|
||||
|
||||
// Already exists in voteSet.votes?
|
||||
|
||||
@@ -12,7 +12,13 @@ import (
|
||||
)
|
||||
|
||||
// NOTE: privValidators are in order
|
||||
func randVoteSet(height int64, round int, type_ SignedMsgType, numValidators int, votingPower int64) (*VoteSet, *ValidatorSet, []PrivValidator) {
|
||||
func randVoteSet(
|
||||
height int64,
|
||||
round int,
|
||||
type_ SignedMsgType,
|
||||
numValidators int,
|
||||
votingPower int64,
|
||||
) (*VoteSet, *ValidatorSet, []PrivValidator) {
|
||||
valSet, privValidators := RandValidatorSet(numValidators, votingPower)
|
||||
return NewVoteSet("test_chain_id", height, round, type_, valSet), valSet, privValidators
|
||||
}
|
||||
|
||||
+5
-2
@@ -134,7 +134,8 @@ func TestVoteSignBytesTestVectors(t *testing.T) {
|
||||
// remaining fields:
|
||||
0x2a, // (field_number << 3) | wire_type
|
||||
0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1, // timestamp
|
||||
0x32, // (field_number << 3) | wire_type
|
||||
// (field_number << 3) | wire_type
|
||||
0x32,
|
||||
0xd, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64}, // chainID
|
||||
},
|
||||
}
|
||||
@@ -278,7 +279,9 @@ func TestVoteValidateBasic(t *testing.T) {
|
||||
{"Good Vote", func(v *Vote) {}, false},
|
||||
{"Negative Height", func(v *Vote) { v.Height = -1 }, true},
|
||||
{"Negative Round", func(v *Vote) { v.Round = -1 }, true},
|
||||
{"Invalid BlockID", func(v *Vote) { v.BlockID = BlockID{[]byte{1, 2, 3}, PartSetHeader{111, []byte("blockparts")}} }, true},
|
||||
{"Invalid BlockID", func(v *Vote) {
|
||||
v.BlockID = BlockID{[]byte{1, 2, 3}, PartSetHeader{111, []byte("blockparts")}}
|
||||
}, true},
|
||||
{"Invalid Address", func(v *Vote) { v.ValidatorAddress = make([]byte, 1) }, true},
|
||||
{"Invalid ValidatorIndex", func(v *Vote) { v.ValidatorIndex = -1 }, true},
|
||||
{"Invalid Signature", func(v *Vote) { v.Signature = nil }, true},
|
||||
|
||||
Reference in New Issue
Block a user