Skip to content

Commit

Permalink
chore: fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f committed May 27, 2024
1 parent b6e97f5 commit 99d15b2
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 117 deletions.
2 changes: 1 addition & 1 deletion consensus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func DefaultConfig() *Config {
func (conf *Config) BasicCheck() error {
if conf.ChangeProposerTimeout <= 0 {
return ConfigError{
Reason: "timeout for change proposer must be greater than zero",
Reason: "change proposer timeout must be greater than zero",
}
}
if conf.ChangeProposerDelta <= 0 {
Expand Down
4 changes: 2 additions & 2 deletions consensus/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func TestDefaultConfigCheck(t *testing.T) {
assert.ErrorIs(t, c2.BasicCheck(), ConfigError{Reason: "change proposer delta must be greater than zero"})

c3.ChangeProposerTimeout = 0 * time.Second
assert.ErrorIs(t, c3.BasicCheck(), ConfigError{Reason: "timeout for change proposer must be greater than zero"})
assert.ErrorIs(t, c3.BasicCheck(), ConfigError{Reason: "change proposer timeout must be greater than zero"})

c4.ChangeProposerTimeout = -1 * time.Second
assert.ErrorIs(t, c4.BasicCheck(), ConfigError{Reason: "timeout for change proposer must be greater than zero"})
assert.ErrorIs(t, c4.BasicCheck(), ConfigError{Reason: "change proposer timeout must be greater than zero"})

c5.MinimumAvailabilityScore = 1.5
assert.ErrorIs(t, c5.BasicCheck(), ConfigError{Reason: "minimum availability score can't be negative or more than 1"})
Expand Down
2 changes: 1 addition & 1 deletion consensus/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (cp *changeProposer) checkJustInitZero(just vote.Just, blockHash hash.Hash)
return nil
}

func (cp *changeProposer) checkJustInitOne(just vote.Just) error {
func (*changeProposer) checkJustInitOne(just vote.Just) error {
_, ok := just.(*vote.JustInitYes)
if !ok {
return invalidJustificationError{
Expand Down
8 changes: 4 additions & 4 deletions fastconsensus/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ func (s *commitState) decide() {
s.enterNewState(s.newHeightState)
}

func (s *commitState) onAddVote(_ *vote.Vote) {
func (*commitState) onAddVote(_ *vote.Vote) {
panic("Unreachable")
}

func (s *commitState) onSetProposal(_ *proposal.Proposal) {
func (*commitState) onSetProposal(_ *proposal.Proposal) {
panic("Unreachable")
}

func (s *commitState) onTimeout(_ *ticker) {
func (*commitState) onTimeout(_ *ticker) {
panic("Unreachable")
}

func (s *commitState) name() string {
func (*commitState) name() string {
return "commit"
}
4 changes: 2 additions & 2 deletions fastconsensus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func DefaultConfig() *Config {
func (conf *Config) BasicCheck() error {
if conf.ChangeProposerTimeout <= 0 {
return ConfigError{
Reason: "timeout for change proposer can't be negative",
Reason: "change proposer timeout must be greater than zero",
}
}
if conf.ChangeProposerDelta <= 0 {
return ConfigError{
Reason: "change proposer delta can't be negative",
Reason: "change proposer delta must be greater than zero",
}
}
if conf.MinimumAvailabilityScore < 0 || conf.MinimumAvailabilityScore > 1 {
Expand Down
6 changes: 3 additions & 3 deletions fastconsensus/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ func TestDefaultConfigCheck(t *testing.T) {
assert.NoError(t, c1.BasicCheck())

c2.ChangeProposerDelta = 0 * time.Second
assert.ErrorIs(t, c2.BasicCheck(), ConfigError{Reason: "change proposer delta can't be negative"})
assert.ErrorIs(t, c2.BasicCheck(), ConfigError{Reason: "change proposer delta must be greater than zero"})

c3.ChangeProposerTimeout = 0 * time.Second
assert.ErrorIs(t, c3.BasicCheck(), ConfigError{Reason: "timeout for change proposer can't be negative"})
assert.ErrorIs(t, c3.BasicCheck(), ConfigError{Reason: "change proposer timeout must be greater than zero"})

c4.ChangeProposerTimeout = -1 * time.Second
assert.ErrorIs(t, c4.BasicCheck(), ConfigError{Reason: "timeout for change proposer can't be negative"})
assert.ErrorIs(t, c4.BasicCheck(), ConfigError{Reason: "change proposer timeout must be greater than zero"})

c5.MinimumAvailabilityScore = 1.5
assert.ErrorIs(t, c5.BasicCheck(), ConfigError{Reason: "minimum availability score can't be negative or more than 1"})
Expand Down
10 changes: 5 additions & 5 deletions fastconsensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func NewConsensus(
broadcastCh <- msg
}

return newConsensus(conf, bcState,
return makeConsensus(conf, bcState,
valKey, rewardAddr, broadcaster, mediator)
}

func newConsensus(
func makeConsensus(
conf *Config,
bcState state.Facade,
valKey *bls.ValidatorKey,
Expand Down Expand Up @@ -119,7 +119,7 @@ func (cs *consensus) Start() {
cs.lk.Lock()
defer cs.lk.Unlock()

cs.moveToNewHeight()
cs.doMoveToNewHeight()
// We have just started the consensus (possibly restarting the node).
// Therefore, let's query the votes and proposals in case we missed any.
if cs.active {
Expand Down Expand Up @@ -187,10 +187,10 @@ func (cs *consensus) MoveToNewHeight() {
cs.lk.Lock()
defer cs.lk.Unlock()

cs.moveToNewHeight()
cs.doMoveToNewHeight()
}

func (cs *consensus) moveToNewHeight() {
func (cs *consensus) doMoveToNewHeight() {
stateHeight := cs.bcState.LastBlockHeight()
if cs.height != stateHeight+1 {
cs.enterNewState(cs.newHeightState)
Expand Down
30 changes: 10 additions & 20 deletions fastconsensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func setupWithSeed(t *testing.T, seed int64) *testData {
store.MockingStore(ts), txPool, nil)
require.NoError(t, err)

instances[i] = newConsensus(testConfig(), bcState, valKey,
instances[i] = makeConsensus(testConfig(), bcState, valKey,
valKey.PublicKey().AccountAddress(), broadcasterFunc, newConcreteMediator())
}

Expand Down Expand Up @@ -252,20 +252,14 @@ func (td *testData) shouldPublishVote(t *testing.T, cons *consensus, voteType vo
return nil
}

func checkHeightRound(t *testing.T, cons *consensus, height uint32, round int16) {
func (*testData) checkHeightRound(t *testing.T, cons *consensus, height uint32, round int16) {
t.Helper()

h, r := cons.HeightRound()
assert.Equal(t, h, height)
assert.Equal(t, r, round)
}

func (td *testData) checkHeightRound(t *testing.T, cons *consensus, height uint32, round int16) {
t.Helper()

checkHeightRound(t, cons, height, round)
}

func (td *testData) addPrepareVote(cons *consensus, blockHash hash.Hash, height uint32, round int16,
valID int,
) *vote.Vote {
Expand Down Expand Up @@ -313,23 +307,19 @@ func (td *testData) addVote(cons *consensus, v *vote.Vote, valID int) *vote.Vote
return v
}

func newHeightTimeout(cons *consensus) {
func (*testData) newHeightTimeout(cons *consensus) {
cons.lk.Lock()
cons.currentState.onTimeout(&ticker{0, cons.height, cons.round, tickerTargetNewHeight})
cons.lk.Unlock()
}

func (td *testData) newHeightTimeout(cons *consensus) {
newHeightTimeout(cons)
}

func (td *testData) queryProposalTimeout(cons *consensus) {
func (*testData) queryProposalTimeout(cons *consensus) {
cons.lk.Lock()
cons.currentState.onTimeout(&ticker{0, cons.height, cons.round, tickerTargetQueryProposal})
cons.lk.Unlock()
}

func (td *testData) changeProposerTimeout(cons *consensus) {
func (*testData) changeProposerTimeout(cons *consensus) {
cons.lk.Lock()
cons.currentState.onTimeout(&ticker{0, cons.height, cons.round, tickerTargetChangeProposer})
cons.lk.Unlock()
Expand All @@ -346,7 +336,7 @@ func (td *testData) enterNewHeight(cons *consensus) {
}

// enterNextRound helps tests to enter next round safely.
func (td *testData) enterNextRound(cons *consensus) {
func (*testData) enterNextRound(cons *consensus) {
cons.lk.Lock()
cons.round++
cons.enterNewState(cons.proposeState)
Expand Down Expand Up @@ -506,9 +496,9 @@ func TestNotInCommittee(t *testing.T) {
str := store.MockingStore(td.TestSuite)

st, _ := state.LoadOrNewState(td.genDoc, []*bls.ValidatorKey{valKey}, str, td.txPool, nil)
Cons := NewConsensus(testConfig(), st, valKey, valKey.Address(), make(chan message.Message, 100),
consInst := NewConsensus(testConfig(), st, valKey, valKey.Address(), make(chan message.Message, 100),
newConcreteMediator())
cons := Cons.(*consensus)
cons := consInst.(*consensus)

td.enterNewHeight(cons)
td.newHeightTimeout(cons)
Expand Down Expand Up @@ -746,9 +736,9 @@ func TestNonActiveValidator(t *testing.T) {
td := setup(t)

valKey := td.RandValKey()
Cons := NewConsensus(testConfig(), state.MockingState(td.TestSuite),
consInst := NewConsensus(testConfig(), state.MockingState(td.TestSuite),
valKey, valKey.Address(), make(chan message.Message, 100), newConcreteMediator())
nonActiveCons := Cons.(*consensus)
nonActiveCons := consInst.(*consensus)

t.Run("non-active instances should be in new-height state", func(t *testing.T) {
nonActiveCons.MoveToNewHeight()
Expand Down
4 changes: 2 additions & 2 deletions fastconsensus/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type changeProposer struct {
*consensus
}

func (cp *changeProposer) onSetProposal(_ *proposal.Proposal) {
func (*changeProposer) onSetProposal(_ *proposal.Proposal) {
// Ignore proposal
}

Expand All @@ -23,7 +23,7 @@ func (cp *changeProposer) onTimeout(t *ticker) {
}
}

func (cp *changeProposer) cpCheckCPValue(value vote.CPValue, allowedValues ...vote.CPValue) error {
func (*changeProposer) cpCheckCPValue(value vote.CPValue, allowedValues ...vote.CPValue) error {
for _, v := range allowedValues {
if value == v {
return nil
Expand Down
2 changes: 1 addition & 1 deletion fastconsensus/cp_decide.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ func (s *cpDecideState) onAddVote(_ *vote.Vote) {
s.decide()
}

func (s *cpDecideState) name() string {
func (*cpDecideState) name() string {
return "cp:decide"
}
6 changes: 3 additions & 3 deletions fastconsensus/cp_mainvote.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ func (s *cpMainVoteState) onAddVote(_ *vote.Vote) {
s.decide()
}

func (s *cpMainVoteState) onSetProposal(_ *proposal.Proposal) {
func (*cpMainVoteState) onSetProposal(_ *proposal.Proposal) {
// Ignore proposal
}

func (s *cpMainVoteState) onTimeout(_ *ticker) {
func (*cpMainVoteState) onTimeout(_ *ticker) {
// Ignore timeouts
}

func (s *cpMainVoteState) name() string {
func (*cpMainVoteState) name() string {
return "cp:main-vote"
}
6 changes: 3 additions & 3 deletions fastconsensus/cp_prevote.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ func (s *cpPreVoteState) onAddVote(_ *vote.Vote) {
s.decide()
}

func (s *cpPreVoteState) onSetProposal(_ *proposal.Proposal) {
func (*cpPreVoteState) onSetProposal(_ *proposal.Proposal) {
}

func (s *cpPreVoteState) onTimeout(_ *ticker) {
func (*cpPreVoteState) onTimeout(_ *ticker) {
}

func (s *cpPreVoteState) name() string {
func (*cpPreVoteState) name() string {
return "cp:pre-vote"
}
4 changes: 2 additions & 2 deletions fastconsensus/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestChangeProposerAgreement1(t *testing.T) {
td.addCPMainVote(td.consP, hash.UndefHash, h, r, vote.CPValueYes, mainVote0.CPJust(), tIndexY)

td.shouldPublishVote(t, td.consP, vote.VoteTypeCPDecided, hash.UndefHash)
checkHeightRound(t, td.consP, h, r+1)
td.checkHeightRound(t, td.consP, h, r+1)
}

func TestChangeProposerAgreement0(t *testing.T) {
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestChangeProposerAgreement0(t *testing.T) {
td.shouldPublishVote(t, td.consP, vote.VoteTypeCPDecided, blockHash)
td.addPrecommitVote(td.consP, blockHash, h, r, tIndexX)
td.addPrecommitVote(td.consP, blockHash, h, r, tIndexY)
checkHeightRound(t, td.consP, h, r)
td.checkHeightRound(t, td.consP, h, r)
}

// ConsP receives all PRE-VOTE:0 votes before receiving a proposal or prepare votes.
Expand Down
4 changes: 2 additions & 2 deletions fastconsensus/height.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *newHeightState) onAddVote(_ *vote.Vote) {
}
}

func (s *newHeightState) onSetProposal(_ *proposal.Proposal) {
func (*newHeightState) onSetProposal(_ *proposal.Proposal) {
// Ignore proposal
}

Expand All @@ -55,6 +55,6 @@ func (s *newHeightState) onTimeout(t *ticker) {
}
}

func (s *newHeightState) name() string {
func (*newHeightState) name() string {
return "new-height"
}
8 changes: 4 additions & 4 deletions fastconsensus/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type Consensus interface {

Start()
MoveToNewHeight()
AddVote(vote *vote.Vote)
SetProposal(proposal *proposal.Proposal)
AddVote(vte *vote.Vote)
SetProposal(prop *proposal.Proposal)
}

type ManagerReader interface {
Expand All @@ -40,6 +40,6 @@ type Manager interface {
Start() error
Stop()
MoveToNewHeight()
AddVote(vote *vote.Vote)
SetProposal(proposal *proposal.Proposal)
AddVote(vot *vote.Vote)
SetProposal(prop *proposal.Proposal)
}
2 changes: 1 addition & 1 deletion fastconsensus/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (mgr *manager) Start() error {
}

// Stop stops the manager.
func (mgr *manager) Stop() {
func (*manager) Stop() {
}

// Instances return all consensus instances that are read-only and
Expand Down
Loading

0 comments on commit 99d15b2

Please sign in to comment.