Skip to content

Commit

Permalink
use param max block proposers to pick authority
Browse files Browse the repository at this point in the history
  • Loading branch information
libotony committed Aug 16, 2022
1 parent e1a61bd commit 4128c09
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
8 changes: 4 additions & 4 deletions builtin/authority/authority_test.go
Expand Up @@ -40,13 +40,13 @@ func TestAuthority(t *testing.T) {
{M(aut.Get(p1)), M(true, p1, thor.Bytes32{}, true, nil)},
{M(aut.Add(p2, p2, thor.Bytes32{})), M(true, nil)},
{M(aut.Add(p3, p3, thor.Bytes32{})), M(true, nil)},
{M(aut.Candidates(big.NewInt(10), thor.MaxBlockProposers)), M(
{M(aut.Candidates(big.NewInt(10), thor.InitialMaxBlockProposers)), M(
[]*Candidate{{p1, p1, thor.Bytes32{}, true}, {p2, p2, thor.Bytes32{}, true}, {p3, p3, thor.Bytes32{}, true}}, nil,
)},
{M(aut.Candidates(big.NewInt(20), thor.MaxBlockProposers)), M(
{M(aut.Candidates(big.NewInt(20), thor.InitialMaxBlockProposers)), M(
[]*Candidate{{p2, p2, thor.Bytes32{}, true}, {p3, p3, thor.Bytes32{}, true}}, nil,
)},
{M(aut.Candidates(big.NewInt(30), thor.MaxBlockProposers)), M(
{M(aut.Candidates(big.NewInt(30), thor.InitialMaxBlockProposers)), M(
[]*Candidate{{p3, p3, thor.Bytes32{}, true}}, nil,
)},
{M(aut.Candidates(big.NewInt(10), 2)), M(
Expand All @@ -59,7 +59,7 @@ func TestAuthority(t *testing.T) {
{M(aut.Get(p1)), M(true, p1, thor.Bytes32{}, true, nil)},
{M(aut.Revoke(p1)), M(true, nil)},
{M(aut.Get(p1)), M(false, p1, thor.Bytes32{}, false, nil)},
{M(aut.Candidates(&big.Int{}, thor.MaxBlockProposers)), M(
{M(aut.Candidates(&big.Int{}, thor.InitialMaxBlockProposers)), M(
[]*Candidate{{p2, p2, thor.Bytes32{}, true}, {p3, p3, thor.Bytes32{}, true}}, nil,
)},
}
Expand Down
13 changes: 12 additions & 1 deletion packer/packer.go
Expand Up @@ -62,7 +62,18 @@ func (p *Packer) Schedule(parent *chain.BlockSummary, nowTimestamp uint64) (flow
if err != nil {
return nil, err
}
candidates, err := authority.Candidates(endorsement, thor.MaxBlockProposers)

mbp, err := builtin.Params.Native(state).Get(thor.KeyMaxBlockProposers)
if err != nil {
return nil, err
}

maxBlockProposers := mbp.Uint64()
if maxBlockProposers == 0 || maxBlockProposers > thor.InitialMaxBlockProposers {
maxBlockProposers = thor.InitialMaxBlockProposers
}

candidates, err := authority.Candidates(endorsement, maxBlockProposers)
if err != nil {
return nil, err
}
Expand Down
11 changes: 10 additions & 1 deletion poa/candidates.go
Expand Up @@ -53,8 +53,17 @@ func (c *Candidates) Pick(state *state.State) ([]Proposer, error) {
return nil, err
}

mbp, err := builtin.Params.Native(state).Get(thor.KeyMaxBlockProposers)
if err != nil {
return nil, err
}
maxBlockProposers := mbp.Uint64()
if maxBlockProposers == 0 || maxBlockProposers > thor.InitialMaxBlockProposers {
maxBlockProposers = thor.InitialMaxBlockProposers
}

satisfied = make([]int, 0, len(c.list))
for i := 0; i < len(c.list) && uint64(len(satisfied)) < thor.MaxBlockProposers; i++ {
for i := 0; i < len(c.list) && uint64(len(satisfied)) < maxBlockProposers; i++ {
bal, err := state.GetBalance(c.list[i].Endorsor)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion poa/sched.go
Expand Up @@ -112,7 +112,7 @@ func (s *SchedulerV1) Updates(newBlockTime uint64) (updates []Proposer, score ui
toDeactivate := make(map[thor.Address]Proposer)

t := newBlockTime - thor.BlockInterval
for i := uint64(0); i < thor.MaxBlockProposers && t > s.parentBlockTime; i++ {
for i := uint64(0); i < thor.InitialMaxBlockProposers && t > s.parentBlockTime; i++ {
p := s.whoseTurn(t)
if p.Address != s.proposer.Address {
toDeactivate[p.Address] = p
Expand Down

0 comments on commit 4128c09

Please sign in to comment.