Skip to content

Commit

Permalink
Lint fix tendermint#7 + Test Passing
Browse files Browse the repository at this point in the history
  • Loading branch information
iammadab committed Jul 31, 2021
1 parent 69d1b14 commit d06dc1c
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 65 deletions.
6 changes: 3 additions & 3 deletions abci/example/kvstore/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func RandValidatorSetUpdate(cnt int) types.ValidatorSetUpdate {
panic(err)
}
return types.ValidatorSetUpdate{
ValidatorUpdates: res,
ThresholdPublicKey: thresholdPublicKeyABCI,
QuorumHash: crypto.RandQuorumHash(),
ValidatorUpdates: res,
ThresholdPublicKey: thresholdPublicKeyABCI,
QuorumHash: crypto.RandQuorumHash(),
}
}

Expand Down
47 changes: 22 additions & 25 deletions abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ func (app *PersistentKVStoreApplication) DeliverTx(req types.RequestDeliverTx) t
// otherwise, update the key-value store
return app.app.DeliverTx(req)
}

// otherwise, update the key-value store
return app.app.DeliverTx(req)
}

func (app *PersistentKVStoreApplication) CheckTx(req types.RequestCheckTx) types.ResponseCheckTx {
Expand Down Expand Up @@ -205,28 +202,28 @@ func (app *PersistentKVStoreApplication) ValidatorSet() (validatorSet types.Vali
}
for ; itr.Valid(); itr.Next() {
key := itr.Key()
switch{
case isValidatorTx(key):
validator := new(types.ValidatorUpdate)
err := types.ReadMessage(bytes.NewBuffer(itr.Value()), validator)
if err != nil {
panic(err)
}
validatorSet.ValidatorUpdates = append(validatorSet.ValidatorUpdates, *validator)
case isThresholdPublicKeyTx(key):
thresholdPublicKeyMessage := new(types.ThresholdPublicKeyUpdate)
err := types.ReadMessage(bytes.NewBuffer(itr.Value()), thresholdPublicKeyMessage)
if err != nil {
panic(err)
}
validatorSet.ThresholdPublicKey = thresholdPublicKeyMessage.GetThresholdPublicKey()
case isQuorumHashTx(key):
quorumHashMessage := new(types.QuorumHashUpdate)
err := types.ReadMessage(bytes.NewBuffer(itr.Value()), quorumHashMessage)
if err != nil {
panic(err)
}
validatorSet.QuorumHash = quorumHashMessage.GetQuorumHash()
switch {
case isValidatorTx(key):
validator := new(types.ValidatorUpdate)
err := types.ReadMessage(bytes.NewBuffer(itr.Value()), validator)
if err != nil {
panic(err)
}
validatorSet.ValidatorUpdates = append(validatorSet.ValidatorUpdates, *validator)
case isThresholdPublicKeyTx(key):
thresholdPublicKeyMessage := new(types.ThresholdPublicKeyUpdate)
err := types.ReadMessage(bytes.NewBuffer(itr.Value()), thresholdPublicKeyMessage)
if err != nil {
panic(err)
}
validatorSet.ThresholdPublicKey = thresholdPublicKeyMessage.GetThresholdPublicKey()
case isQuorumHashTx(key):
quorumHashMessage := new(types.QuorumHashUpdate)
err := types.ReadMessage(bytes.NewBuffer(itr.Value()), quorumHashMessage)
if err != nil {
panic(err)
}
validatorSet.QuorumHash = quorumHashMessage.GetQuorumHash()
}
}
if err = itr.Error(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ OUTER_LOOP:
// If height matches, then send LastCommit, Prevotes, Precommits.
if rs.Height == prs.Height {
heightLogger := logger.With("height", prs.Height)
if wasValidator == false {
if !wasValidator {
// If there are lastCommits to send...
if prs.Step == cstypes.RoundStepNewHeight && prs.Height+1 == rs.Height && prs.HasCommit == false {
if ps.SendCommit(rs.LastCommit) {
Expand All @@ -748,7 +748,7 @@ OUTER_LOOP:

// Special catchup logic.
// If peer is lagging by height 1, send LastCommit if we haven't already.
if prs.Height != 0 && rs.Height == prs.Height+1 && prs.HasCommit == false && wasValidator == false {
if prs.Height != 0 && rs.Height == prs.Height+1 && !prs.HasCommit && !wasValidator {
if ps.SendCommit(rs.LastCommit) {
logger.Debug("Sending LastCommit for catch up", "height", prs.Height)
continue OUTER_LOOP
Expand Down
7 changes: 4 additions & 3 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,10 @@ func TestSimulateValidatorsChange(t *testing.T) {

proposerPubKey2, err = vss[proposerIndex].GetPubKey(validatorsAtProposalHeight.QuorumHash)

if !bytes.Equal(proposerPubKey2.Bytes(), proposerPubKey.Bytes()) {
//t.Fatal("wrong proposer pubKey", err)
}
/*
if !bytes.Equal(proposerPubKey2.Bytes(), proposerPubKey.Bytes()) {
//t.Fatal("wrong proposer pubKey", err)
}*/

css[0].Logger.Debug("signed proposal", "height", proposal.Height, "round", proposal.Round,
"proposer", proposerProTxHash.ShortString(), "signature", p.Signature, "pubkey", proposerPubKey.Bytes(), "quorum type",
Expand Down
4 changes: 2 additions & 2 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ func (cs *State) tryAddCommit(commit *types.Commit, peerID p2p.ID) (bool, error)

// First lets verify that the commit is what we are expecting
verified, err := cs.verifyCommit(commit, peerID, false)
if verified == false || err != nil {
if !verified || err != nil {
return verified, err
}

Expand Down Expand Up @@ -2317,7 +2317,7 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID) (added bool, err error
}

// Ignore vote if we do not have public keys to verify votes
if cs.Validators.HasPublicKeys == false {
if !cs.Validators.HasPublicKeys {
added = false
cs.Logger.Debug("vote received on non-validator, ignoring it", "vote_height", vote.Height,
"cs_height", cs.Height, "peer", peerID)
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/height_vote_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (hvs *HeightVoteSet) addRound(round int32) {
panic("addRound() for an existing round")
}
// log.Debug("addRound(round)", "round", round)
if hvs.valSet.HasPublicKeys == true {
if hvs.valSet.HasPublicKeys {
prevotes := types.NewVoteSet(hvs.chainID, hvs.height, round, tmproto.PrevoteType, hvs.valSet)
precommits := types.NewVoteSet(hvs.chainID, hvs.height, round, tmproto.PrecommitType, hvs.valSet)
hvs.roundVoteSets[round] = RoundVoteSet{
Expand Down
6 changes: 3 additions & 3 deletions crypto/bls12381/bls12381.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ func CreatePrivLLMQDataOnProTxHashesDefaultThresholdUsingSeedSource(proTxHashes
}

func CreatePrivLLMQDataOnProTxHashes(
proTxHashes []crypto.ProTxHash,
threshold int,
) ([]crypto.ProTxHash, []crypto.PrivKey, crypto.PubKey) {
proTxHashes []crypto.ProTxHash,
threshold int,
) ([]crypto.ProTxHash, []crypto.PrivKey, crypto.PubKey) {
return CreatePrivLLMQDataOnProTxHashesUsingSeed(proTxHashes, threshold, 0)
}

Expand Down
4 changes: 2 additions & 2 deletions crypto/quorum.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
bls "github.com/dashpay/bls-signatures/go-bindings"
)

func SignID(llmqType btcjson.LLMQType, quorumHash QuorumHash, requestId []byte, messageHash []byte) []byte {
func SignID(llmqType btcjson.LLMQType, quorumHash QuorumHash, requestID []byte, messageHash []byte) []byte {
var blsQuorumHash bls.Hash
copy(blsQuorumHash[:], quorumHash.Bytes())

var blsRequestID bls.Hash
copy(blsRequestID[:], requestId)
copy(blsRequestID[:], requestID)

var blsMessageHash bls.Hash
copy(blsMessageHash[:], messageHash)
Expand Down
4 changes: 2 additions & 2 deletions evidence/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func VerifyDuplicateVote(e *types.DuplicateVoteEvidence, chainID string, valSet
return fmt.Errorf("verifying VoteA: %s", types.ErrVoteInvalidBlockSignature.Error())
}
if !pubKey.VerifySignatureDigest(
types.VoteBlockSignId(chainID, vb, valSet.QuorumType, valSet.QuorumHash),
e.VoteB.BlockSignature,
types.VoteBlockSignId(chainID, vb, valSet.QuorumType, valSet.QuorumHash),
e.VoteB.BlockSignature,
) {
return fmt.Errorf("verifying VoteB: %s", types.ErrVoteInvalidStateSignature.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion libs/cli/flags/log_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func ParseLogLevel(lvl string, logger log.Logger, defaultLogLevelValue string) (
default:
return nil,
fmt.Errorf(
"expected either \"info\", \"debug\", \"p2p_debug\", \"error\" or \"none\" log level, given %s (pair %s, list %s)",
"expected either \"info\", \"debug\", \"p2p_debug\", \"error\" or \"none\" log level, given %s (pair %s, list %s)",
level,
item,
list)
Expand Down
4 changes: 2 additions & 2 deletions libs/log/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func AllowLevel(lvl string) (Option, error) {
return AllowNone(), nil
default:
return nil, fmt.Errorf(
"expected either \"info\", \"debug\", \"p2p_debug\", \"error\" or \"none\" level, given %s",
lvl,
"expected either \"info\", \"debug\", \"p2p_debug\", \"error\" or \"none\" level, given %s",
lvl,
)
}
}
Expand Down
7 changes: 5 additions & 2 deletions light/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,11 @@ func (c *Client) restoreTrustedLightBlock() error {

// initialize fetches the last light block from
// primary provider.
/*
func (c *Client) initialize(ctx context.Context) error {
return c.initializeAtHeight(ctx, 0) //
}
*/

// initializeAtHeight fetches a light block at given height from
// primary provider.
Expand Down Expand Up @@ -615,6 +617,7 @@ func (c *Client) Cleanup() error {

// cleanupAfter deletes all headers & validator sets after +height+. It also
// resets latestTrustedBlock to the latest header.
/*
func (c *Client) cleanupAfter(height int64) error {
prevHeight := c.latestTrustedBlock.Height
Expand Down Expand Up @@ -642,7 +645,7 @@ func (c *Client) cleanupAfter(height int64) error {
}
return nil
}
}*/

func (c *Client) updateTrustedLightBlock(l *types.LightBlock) error {
c.logger.Debug("updating trusted light block", "light_block", l)
Expand Down Expand Up @@ -695,7 +698,7 @@ func (c *Client) lightBlockFromPrimaryAtHeight(ctx context.Context, height int64
if c.latestTrustedBlock != nil && l.Height < c.latestTrustedBlock.Height {
return c.findNewPrimary(ctx, false)
}
return l, nil
return l, nil

case provider.ErrNoResponse, provider.ErrLightBlockNotFound, provider.ErrHeightTooHigh:
// we find a new witness to replace the primary
Expand Down
2 changes: 2 additions & 0 deletions light/proxy/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,15 @@ func makeTxSearchFunc(c *lrpc.Client) rpcTxSearchFunc {
}
}

/*
type rpcBlockSearchFunc func(
ctx *rpctypes.Context,
query string,
prove bool,
page, perPage *int,
orderBy string,
) (*ctypes.ResultBlockSearch, error)
*/

/*
func makeBlockSearchFunc(c *lrpc.Client) rpcBlockSearchFunc {
Expand Down
6 changes: 3 additions & 3 deletions p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ func (p *peer) String() string {
if mConnString == "MConn{pipe}" {
mConnString = ""
} else {
mConnString += " "
mConnString += " "
}

if proTxHash != nil {
return fmt.Sprintf("Peer{%sproTxHash:%v}", mConnString, proTxHash.ShortString())
}
return fmt.Sprintf("Peer{%speerId:%v}", mConnString, p.ID())
}
return fmt.Sprintf("Peer{%speerId:%v}", mConnString, p.ID())

}

Expand Down
12 changes: 6 additions & 6 deletions privval/dash_core_signer_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (sc *DashCoreSignerClient) GetPubKey(quorumHash crypto.QuorumHash) (crypto.
}

if len(decodedPublicKeyShare) != bls12381.PubKeySize {
if found == true {
if found {
// We found it, we should have a public key share
return nil, fmt.Errorf("no public key share found")
} else {
Expand Down Expand Up @@ -244,13 +244,13 @@ func (sc *DashCoreSignerClient) SignVote(chainID string, quorumType btcjson.LLMQ
//
// fmt.Printf("core block signID %s our block sign Id %s\n", blockResponse.SignHash, hex.EncodeToString(signID))
//
//pubKey, err := sc.GetPubKey(quorumHash)
//verified := pubKey.VerifySignatureDigest(signID, blockDecodedSignature)
//if verified {
// pubKey, err := sc.GetPubKey(quorumHash)
// verified := pubKey.VerifySignatureDigest(signID, blockDecodedSignature)
// if verified {
// fmt.Printf("Verified core signing with public key %v\n", pubKey)
//} else {
// } else {
// fmt.Printf("Unable to verify signature %v\n", pubKey)
//}
// }

stateResponse, err := sc.dashCoreRpcClient.QuorumSign(sc.defaultQuorumType, stateRequestId, stateMessageHash, quorumHash)

Expand Down
2 changes: 1 addition & 1 deletion rpc/client/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func WaitForOneEvent(c EventsClient, evtTyp string, timeout time.Duration) (type

select {
case event := <-eventCh:
return event.Data.(types.TMEventData), nil
return event.Data, nil
case <-ctx.Done():
return nil, errors.New("timed out waiting for event")
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/pkg/mockcoreserver/expect.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func BodyShouldBeSame(v interface{}) ExpectFunc {
return err
}
req.Body = ioutil.NopCloser(bytes.NewBuffer(buf))
if bytes.Compare(body, buf) != 0 {
if !bytes.Equal(body, buf) {
return fmt.Errorf("the request body retried by URL %s is not equal\nexpected: %s\nactual: %s", req.URL.String(), buf, body)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/pkg/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func LoadTestnet(file string) (*Testnet, error) {
isPartOfQuorum = true
}
}
if isPartOfQuorum == false {
if !isPartOfQuorum {
if node.PrivvalKeys == nil {
node.PrivvalKeys = make(map[string]crypto.QuorumKeys)
}
Expand Down
6 changes: 3 additions & 3 deletions test/maverick/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1539,11 +1539,11 @@ func createAndStartPrivValidatorRPCClient(
return nil, fmt.Errorf("can't get proTxHash when starting private validator rpc client: %w", err)
}

//const (
// const (
// retries = 50 // 50 * 100ms = 5s total
// timeout = 100 * time.Millisecond
//)
//pvscWithRetries := privval.NewRetrySignerClient(pvsc, retries, timeout)
// )
// pvscWithRetries := privval.NewRetrySignerClient(pvsc, retries, timeout)

return pvsc, nil
}
Expand Down
2 changes: 1 addition & 1 deletion types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (p *Proposal) ValidateBasic() error {
// See BlockID#String.
func (p *Proposal) String() string {
if p == nil {
return fmt.Sprintf("Proposal{nil}")
return "Proposal{nil}"
}
return fmt.Sprintf("Proposal{%v/%v (%v, %v) %X @ %s}",
p.Height,
Expand Down
3 changes: 2 additions & 1 deletion types/validator_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ func TestAveragingInIncrementProposerPriority(t *testing.T) {
{ProTxHash: []byte("c"), ProposerPriority: 1}}},
// this should average twice but the average should be 0 after the first iteration
// (voting power is 0 -> no changes)
11, 1 / 3},
// 1/3 -> 0
11, 0},
2: {ValidatorSet{
Validators: []*Validator{
{ProTxHash: []byte("a"), ProposerPriority: 100},
Expand Down

0 comments on commit d06dc1c

Please sign in to comment.