Skip to content

Commit

Permalink
consensus/core: fix lint failed
Browse files Browse the repository at this point in the history
  • Loading branch information
markya0616 committed Feb 26, 2018
1 parent 28fa7d2 commit 262ae3f
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 43 deletions.
2 changes: 1 addition & 1 deletion consensus/istanbul/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (sb *backend) Verify(proposal istanbul.Proposal) (time.Duration, error) {

// Sign implements istanbul.Backend.Sign
func (sb *backend) Sign(data []byte) ([]byte, error) {
hashData := crypto.Keccak256([]byte(data))
hashData := crypto.Keccak256(data)
return crypto.Sign(hashData, sb.privateKey)
}

Expand Down
7 changes: 2 additions & 5 deletions consensus/istanbul/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,8 @@ func TestCommit(t *testing.T) {
for _, test := range testCases {
expBlock := test.expectedBlock()
go func() {
select {
case result := <-backend.commitCh:
commitCh <- result
return
}
result := <-backend.commitCh
commitCh <- result
}()

backend.proposedBlockHash = expBlock.Hash()
Expand Down
2 changes: 1 addition & 1 deletion consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var (
// errEmptyCommittedSeals is returned if the field of committed seals is zero.
errEmptyCommittedSeals = errors.New("zero committed seals")
// errMismatchTxhashes is returned if the TxHash in header is mismatch.
errMismatchTxhashes = errors.New("mismatch transcations hashes")
errMismatchTxhashes = errors.New("mismatch transactions hashes")
)
var (
defaultDifficulty = big.NewInt(1)
Expand Down
30 changes: 12 additions & 18 deletions consensus/istanbul/backend/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,12 @@ func TestSealStopChannel(t *testing.T) {
stop := make(chan struct{}, 1)
eventSub := engine.EventMux().Subscribe(istanbul.RequestEvent{})
eventLoop := func() {
select {
case ev := <-eventSub.Chan():
_, ok := ev.Data.(istanbul.RequestEvent)
if !ok {
t.Errorf("unexpected event comes: %v", reflect.TypeOf(ev.Data))
}
stop <- struct{}{}
ev := <-eventSub.Chan()
_, ok := ev.Data.(istanbul.RequestEvent)
if !ok {
t.Errorf("unexpected event comes: %v", reflect.TypeOf(ev.Data))
}
stop <- struct{}{}
eventSub.Unsubscribe()
}
go eventLoop()
Expand All @@ -189,14 +187,12 @@ func TestSealCommittedOtherHash(t *testing.T) {
otherBlock := makeBlockWithoutSeal(chain, engine, block)
eventSub := engine.EventMux().Subscribe(istanbul.RequestEvent{})
eventLoop := func() {
select {
case ev := <-eventSub.Chan():
_, ok := ev.Data.(istanbul.RequestEvent)
if !ok {
t.Errorf("unexpected event comes: %v", reflect.TypeOf(ev.Data))
}
engine.Commit(otherBlock, [][]byte{})
ev := <-eventSub.Chan()
_, ok := ev.Data.(istanbul.RequestEvent)
if !ok {
t.Errorf("unexpected event comes: %v", reflect.TypeOf(ev.Data))
}
engine.Commit(otherBlock, [][]byte{})
eventSub.Unsubscribe()
}
go eventLoop()
Expand All @@ -208,10 +204,8 @@ func TestSealCommittedOtherHash(t *testing.T) {

const timeoutDura = 2 * time.Second
timeout := time.NewTimer(timeoutDura)
select {
case <-timeout.C:
// wait 2 seconds to ensure we cannot get any blocks from Istanbul
}
<-timeout.C
// wait 2 seconds to ensure we cannot get any blocks from Istanbul
}

func TestSealCommitted(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions consensus/istanbul/backend/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
// Tally up the new vote from the validator
var authorize bool
switch {
case bytes.Compare(header.Nonce[:], nonceAuthVote) == 0:
case bytes.Equal(header.Nonce[:], nonceAuthVote):
authorize = true
case bytes.Compare(header.Nonce[:], nonceDropVote) == 0:
case bytes.Equal(header.Nonce[:], nonceDropVote):
authorize = false
default:
return nil, errInvalidVote
Expand Down
2 changes: 1 addition & 1 deletion consensus/istanbul/backend/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func TestSaveAndLoad(t *testing.T) {
},
},
Tally: map[common.Address]Tally{
common.StringToAddress("1234567893"): Tally{
common.StringToAddress("1234567893"): {
Authorize: false,
Votes: 20,
},
Expand Down
8 changes: 4 additions & 4 deletions consensus/istanbul/core/backlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,19 @@ func TestProcessBacklog(t *testing.T) {
subjectPayload, _ := Encode(subject)

msgs := []*message{
&message{
{
Code: msgPreprepare,
Msg: prepreparePayload,
},
&message{
{
Code: msgPrepare,
Msg: subjectPayload,
},
&message{
{
Code: msgCommit,
Msg: subjectPayload,
},
&message{
{
Code: msgRoundChange,
Msg: subjectPayload,
},
Expand Down
2 changes: 1 addition & 1 deletion consensus/istanbul/core/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ OUTER:
committedSeals := v0.committedMsgs[0].committedSeals
for _, validator := range r0.valSet.List() {
for _, seal := range committedSeals {
if bytes.Compare(validator.Address().Bytes(), seal[:common.AddressLength]) == 0 {
if bytes.Equal(validator.Address().Bytes(), seal[:common.AddressLength]) {
signedCount++
break
}
Expand Down
8 changes: 2 additions & 6 deletions consensus/istanbul/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,12 @@ func TestNewRequest(t *testing.T) {
request1 := makeBlock(1)
sys.backends[0].NewRequest(request1)

select {
case <-time.After(1 * time.Second):
}
<-time.After(1 * time.Second)

request2 := makeBlock(2)
sys.backends[0].NewRequest(request2)

select {
case <-time.After(1 * time.Second):
}
<-time.After(1 * time.Second)

for _, backend := range sys.backends {
if len(backend.committedMsgs) != 2 {
Expand Down
4 changes: 2 additions & 2 deletions consensus/istanbul/core/roundchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ func (c *core) handleRoundChange(msg *message, src istanbul.Validator) error {
// Once we received f+1 ROUND CHANGE messages, those messages form a weak certificate.
// If our round number is smaller than the certificate's round number, we would
// try to catch up the round number.
if c.waitingForRoundChange && num == int(c.valSet.F()+1) {
if c.waitingForRoundChange && num == c.valSet.F()+1 {
if cv.Round.Cmp(roundView.Round) < 0 {
c.sendRoundChange(roundView.Round)
}
return nil
} else if num == int(2*c.valSet.F()+1) && (c.waitingForRoundChange || cv.Round.Cmp(roundView.Round) < 0) {
} else if num == 2*c.valSet.F()+1 && (c.waitingForRoundChange || cv.Round.Cmp(roundView.Round) < 0) {
// We've received 2f+1 ROUND CHANGE messages, start a new round immediately.
c.startNewRound(roundView.Round)
return nil
Expand Down
2 changes: 1 addition & 1 deletion consensus/istanbul/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func RLPHash(v interface{}) (h common.Hash) {
// GetSignatureAddress gets the signer address from the signature
func GetSignatureAddress(data []byte, sig []byte) (common.Address, error) {
// 1. Keccak data
hashData := crypto.Keccak256([]byte(data))
hashData := crypto.Keccak256(data)
// 2. Recover public key
pubkey, err := crypto.SigToPub(hashData, sig)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/genesis_alloc.go

Large diffs are not rendered by default.

0 comments on commit 262ae3f

Please sign in to comment.