Skip to content

Commit

Permalink
fix typo proposer
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Feb 28, 2023
1 parent 89a6065 commit da7cfc8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 41 deletions.
5 changes: 2 additions & 3 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ func NewConsensus(
}
return addrs, nil
}
// TODO implement proposorsByEpochFunc
proposorsByEpochFunc := delegatesByEpochFunc
proposersByEpochFunc := delegatesByEpochFunc
bd := rolldpos.NewRollDPoSBuilder().
SetAddr(cfg.Chain.ProducerAddress().String()).
SetPriKey(cfg.Chain.ProducerPrivateKey()).
Expand All @@ -142,7 +141,7 @@ func NewConsensus(
SetClock(clock).
SetBroadcast(ops.broadcastHandler).
SetDelegatesByEpochFunc(delegatesByEpochFunc).
SetProposorsByEpochFunc(proposorsByEpochFunc).
SetProposersByEpochFunc(proposersByEpochFunc).
RegisterProtocol(ops.rp)
// TODO: explorer dependency deleted here at #1085, need to revive by migrating to api
cs.scheme, err = bd.Build()
Expand Down
12 changes: 6 additions & 6 deletions consensus/scheme/rolldpos/rolldpos.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ type (
// TODO: explorer dependency deleted at #1085, need to add api params
rp *rolldpos.Protocol
delegatesByEpochFunc NodesSelectionByEpochFunc
proposorsByEpochFunc NodesSelectionByEpochFunc
proposersByEpochFunc NodesSelectionByEpochFunc
}
)

Expand Down Expand Up @@ -399,11 +399,11 @@ func (b *Builder) SetDelegatesByEpochFunc(
return b
}

// SetProposorsByEpochFunc sets proposorsByEpochFunc
func (b *Builder) SetProposorsByEpochFunc(
proposorsByEpochFunc NodesSelectionByEpochFunc,
// SetProposersByEpochFunc sets proposersByEpochFunc
func (b *Builder) SetProposersByEpochFunc(
proposersByEpochFunc NodesSelectionByEpochFunc,
) *Builder {
b.proposorsByEpochFunc = proposorsByEpochFunc
b.proposersByEpochFunc = proposersByEpochFunc
return b
}

Expand Down Expand Up @@ -436,7 +436,7 @@ func (b *Builder) Build() (*RollDPoS, error) {
b.rp,
b.broadcastHandler,
b.delegatesByEpochFunc,
b.proposorsByEpochFunc,
b.proposersByEpochFunc,
b.encodedAddr,
b.priKey,
b.clock,
Expand Down
14 changes: 7 additions & 7 deletions consensus/scheme/rolldpos/rolldpos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestNewRollDPoS(t *testing.T) {
return nil
}).
SetDelegatesByEpochFunc(delegatesByEpoch).
SetProposorsByEpochFunc(delegatesByEpoch).
SetProposersByEpochFunc(delegatesByEpoch).
RegisterProtocol(rp).
Build()
assert.NoError(t, err)
Expand All @@ -100,7 +100,7 @@ func TestNewRollDPoS(t *testing.T) {
}).
SetClock(clock.NewMock()).
SetDelegatesByEpochFunc(delegatesByEpoch).
SetProposorsByEpochFunc(delegatesByEpoch).
SetProposersByEpochFunc(delegatesByEpoch).
RegisterProtocol(rp).
Build()
assert.NoError(t, err)
Expand All @@ -121,7 +121,7 @@ func TestNewRollDPoS(t *testing.T) {
}).
SetClock(clock.NewMock()).
SetDelegatesByEpochFunc(delegatesByEpoch).
SetProposorsByEpochFunc(delegatesByEpoch).
SetProposersByEpochFunc(delegatesByEpoch).
RegisterProtocol(rp).
Build()
assert.NoError(t, err)
Expand All @@ -137,7 +137,7 @@ func TestNewRollDPoS(t *testing.T) {
return nil
}).
SetDelegatesByEpochFunc(delegatesByEpoch).
SetProposorsByEpochFunc(delegatesByEpoch).
SetProposersByEpochFunc(delegatesByEpoch).
RegisterProtocol(rp).
Build()
assert.Error(t, err)
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestValidateBlockFooter(t *testing.T) {
return nil
}).
SetDelegatesByEpochFunc(delegatesByEpoch).
SetProposorsByEpochFunc(delegatesByEpoch).
SetProposersByEpochFunc(delegatesByEpoch).
SetClock(clock).
RegisterProtocol(rp).
Build()
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestRollDPoS_Metrics(t *testing.T) {
}).
SetClock(clock).
SetDelegatesByEpochFunc(delegatesByEpoch).
SetProposorsByEpochFunc(delegatesByEpoch).
SetProposersByEpochFunc(delegatesByEpoch).
RegisterProtocol(rp).
Build()
require.NoError(t, err)
Expand Down Expand Up @@ -487,7 +487,7 @@ func TestRollDPoSConsensus(t *testing.T) {
SetChainManager(NewChainManager(chain)).
SetBroadcast(p2p.Broadcast).
SetDelegatesByEpochFunc(delegatesByEpochFunc).
SetProposorsByEpochFunc(delegatesByEpochFunc).
SetProposersByEpochFunc(delegatesByEpochFunc).
RegisterProtocol(rp).
Build()
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions consensus/scheme/rolldpos/rolldposctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewRollDPoSCtx(
rp *rolldpos.Protocol,
broadcastHandler scheme.Broadcast,
delegatesByEpochFunc NodesSelectionByEpochFunc,
proposorsByEpochFunc NodesSelectionByEpochFunc,
proposersByEpochFunc NodesSelectionByEpochFunc,
encodedAddr string,
priKey crypto.PrivateKey,
clock clock.Clock,
Expand All @@ -133,8 +133,8 @@ func NewRollDPoSCtx(
if delegatesByEpochFunc == nil {
return nil, errors.New("delegates by epoch function cannot be nil")
}
if proposorsByEpochFunc == nil {
return nil, errors.New("proposors by epoch function cannot be nil")
if proposersByEpochFunc == nil {
return nil, errors.New("proposers by epoch function cannot be nil")
}
if cfg.AcceptBlockTTL(0)+cfg.AcceptProposalEndorsementTTL(0)+cfg.AcceptLockEndorsementTTL(0)+cfg.CommitTTL(0) > cfg.BlockInterval(0) {
return nil, errors.Errorf(
Expand All @@ -152,7 +152,7 @@ func NewRollDPoSCtx(
}
roundCalc := &roundCalculator{
delegatesByEpochFunc: delegatesByEpochFunc,
proposorsByEpochFunc: proposorsByEpochFunc,
proposersByEpochFunc: proposersByEpochFunc,
chain: chain,
rp: rp,
timeBasedRotation: timeBasedRotation,
Expand Down
36 changes: 18 additions & 18 deletions consensus/scheme/rolldpos/roundcalculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type roundCalculator struct {
timeBasedRotation bool
rp *rolldpos.Protocol
delegatesByEpochFunc NodesSelectionByEpochFunc
proposorsByEpochFunc NodesSelectionByEpochFunc
proposersByEpochFunc NodesSelectionByEpochFunc
beringHeight uint64
}

Expand All @@ -30,7 +30,7 @@ func (c *roundCalculator) UpdateRound(round *roundCtx, height uint64, blockInter
epochNum := round.EpochNum()
epochStartHeight := round.EpochStartHeight()
delegates := round.Delegates()
proposors := round.Proposors()
proposers := round.Proposers()
switch {
case height < round.Height():
return nil, errors.New("cannot update to a lower height")
Expand All @@ -47,7 +47,7 @@ func (c *roundCalculator) UpdateRound(round *roundCtx, height uint64, blockInter
if delegates, err = c.Delegates(height); err != nil {
return nil, err
}
if proposors, err = c.Proposors(height); err != nil {
if proposers, err = c.Proposers(height); err != nil {
return nil, err
}
}
Expand All @@ -56,7 +56,7 @@ func (c *roundCalculator) UpdateRound(round *roundCtx, height uint64, blockInter
if err != nil {
return nil, err
}
proposer, err := c.calculateProposer(height, roundNum, proposors)
proposer, err := c.calculateProposer(height, roundNum, proposers)
if err != nil {
return nil, err
}
Expand All @@ -82,7 +82,7 @@ func (c *roundCalculator) UpdateRound(round *roundCtx, height uint64, blockInter
epochStartHeight: epochStartHeight,
nextEpochStartHeight: c.rp.GetEpochHeight(epochNum + 1),
delegates: delegates,
proposors: proposors,
proposers: proposers,

height: height,
roundNum: roundNum,
Expand Down Expand Up @@ -183,10 +183,10 @@ func (c *roundCalculator) Delegates(height uint64) ([]string, error) {
return c.delegatesByEpochFunc(epochNum)
}

// Delegates returns list of proposors at given height
func (c *roundCalculator) Proposors(height uint64) ([]string, error) {
// Proposers returns list of candidate proposers at given height
func (c *roundCalculator) Proposers(height uint64) ([]string, error) {
epochNum := c.rp.GetEpochNum(height)
return c.proposorsByEpochFunc(epochNum)
return c.proposersByEpochFunc(epochNum)
}

// NewRoundWithToleration starts new round with tolerated over time
Expand Down Expand Up @@ -219,7 +219,7 @@ func (c *roundCalculator) newRound(
) (round *roundCtx, err error) {
epochNum := uint64(0)
epochStartHeight := uint64(0)
var delegates, proposors []string
var delegates, proposers []string
var roundNum uint32
var proposer string
var roundStartTime time.Time
Expand All @@ -229,13 +229,13 @@ func (c *roundCalculator) newRound(
if delegates, err = c.Delegates(height); err != nil {
return
}
if proposors, err = c.Proposors(height); err != nil {
if proposers, err = c.Proposers(height); err != nil {
return
}
if roundNum, roundStartTime, err = c.roundInfo(height, blockInterval, now, toleratedOvertime); err != nil {
return
}
if proposer, err = c.calculateProposer(height, roundNum, proposors); err != nil {
if proposer, err = c.calculateProposer(height, roundNum, proposers); err != nil {
return
}
}
Expand All @@ -249,7 +249,7 @@ func (c *roundCalculator) newRound(
epochStartHeight: epochStartHeight,
nextEpochStartHeight: c.rp.GetEpochHeight(epochNum + 1),
delegates: delegates,
proposors: proposors,
proposers: proposers,

height: height,
roundNum: roundNum,
Expand All @@ -268,18 +268,18 @@ func (c *roundCalculator) newRound(
func (c *roundCalculator) calculateProposer(
height uint64,
round uint32,
proposors []string,
proposers []string,
) (proposer string, err error) {
// TODO use number of proposors
numProposors := c.rp.NumDelegates()
if numProposors != uint64(len(proposors)) {
err = errors.New("invalid proposor list")
// TODO use number of proposers
numProposers := c.rp.NumDelegates()
if numProposers != uint64(len(proposers)) {
err = errors.New("invalid proposer list")
return
}
idx := height
if c.timeBasedRotation {
idx += uint64(round)
}
proposer = proposors[idx%numProposors]
proposer = proposers[idx%numProposers]
return
}
6 changes: 3 additions & 3 deletions consensus/scheme/rolldpos/roundctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type roundCtx struct {
epochStartHeight uint64
nextEpochStartHeight uint64
delegates []string
proposors []string
proposers []string

height uint64
roundNum uint32
Expand Down Expand Up @@ -95,8 +95,8 @@ func (ctx *roundCtx) Delegates() []string {
return ctx.delegates
}

func (ctx *roundCtx) Proposors() []string {
return ctx.proposors
func (ctx *roundCtx) Proposers() []string {
return ctx.proposers
}

func (ctx *roundCtx) IsDelegate(addr string) bool {
Expand Down

0 comments on commit da7cfc8

Please sign in to comment.