Skip to content

Commit

Permalink
Merge pull request #1527 from dusk-network/1520-make-committeesize-co…
Browse files Browse the repository at this point in the history
…nsistent-with-size

Use constant Committee Size

Resolves #1520
  • Loading branch information
fed-franz authored May 25, 2023
2 parents 0f80b09 + 1154dfa commit f6e64ee
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dusk_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Lint
run: rm -rf $HOME/.cache/golangci-lint || true && make lint
test:
runs-on: ubuntu-latest
runs-on: core
timeout-minutes: 10
steps:
- name: Install Go
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/didip/tollbooth v4.0.2+incompatible
github.com/drewolson/testflight v1.0.0
github.com/dusk-network/bls12_381-sign/go/cgo/bls v0.1.5
github.com/dusk-network/bls12_381-sign/go/cgo/bls v0.1.6-alpha.0
github.com/dusk-network/dusk-crypto v0.1.3
github.com/dusk-network/dusk-protobuf v0.5.2
github.com/etherlabsio/healthcheck v0.0.0-20191224061800-dd3d2fd8c3f6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ github.com/didip/tollbooth v4.0.2+incompatible h1:fVSa33JzSz0hoh2NxpwZtksAzAgd7z
github.com/didip/tollbooth v4.0.2+incompatible/go.mod h1:A9b0665CE6l1KmzpDws2++elm/CsuWBMa5Jv4WY0PEY=
github.com/drewolson/testflight v1.0.0 h1:jgA0pHcFIPnXoBmyFzrdoR2ka4UvReMDsjYc7Jcvl80=
github.com/drewolson/testflight v1.0.0/go.mod h1:t9oKuuEohRGLb80SWX+uxJHuhX98B7HnojqtW+Ryq30=
github.com/dusk-network/bls12_381-sign/go/cgo/bls v0.1.5 h1:O/KCOvH5aeQ19dPH2mynbA6ynio80CwK245RgUDMlEA=
github.com/dusk-network/bls12_381-sign/go/cgo/bls v0.1.5/go.mod h1:zaPS7YfC0Fu8DK1LEscBPPE+GnCxCW7yZ8ZCiLA5XBc=
github.com/dusk-network/bls12_381-sign/go/cgo/bls v0.1.6-alpha.0 h1:iwE/V91PY9bDmHozCGvs/J8ju4Jh//uk0nWu5W7XMQA=
github.com/dusk-network/bls12_381-sign/go/cgo/bls v0.1.6-alpha.0/go.mod h1:zaPS7YfC0Fu8DK1LEscBPPE+GnCxCW7yZ8ZCiLA5XBc=
github.com/dusk-network/bn256 v0.5.1-lattices/go.mod h1:ddVn3p/nch27uVwd+3QGreudmSKfbAVr39LvBaSUEGg=
github.com/dusk-network/dusk-crypto v0.1.3 h1:XWzB0wXuJ/6kRE7VCQ/K1Sr+OlInDyTndLRat1owfuo=
github.com/dusk-network/dusk-crypto v0.1.3/go.mod h1:XEU09/mHLIAg9cS0m/6Hu2+wvJPxybfoXYSCrveHh3U=
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ const (
// ConsensusMaxStep consensus max step number.
ConsensusMaxStep = uint8(213)

// ConsensusMaxCommitteeSize represents the maximum size of the committee in
// ConsensusCommitteeSize is the (constant) size of the committee in
// 1st_Reduction, 2th_Reduction and Agreement phases.
ConsensusMaxCommitteeSize = 64
ConsensusCommitteeSize = 64

// ConsensusMaxCommitteeSize represents the maximum size of the committee in
// Selection phase.
ConsensusSelectionMaxCommitteeSize = 1
// ConsensusSelectionCommitteeSize is the size of the committee in
// the Selection phase.
ConsensusSelectionCommitteeSize = 1

// RuskVersion is the version of the supported rusk binary.
RuskVersion = "0.6.0"
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (c *Chain) runStateTransition(tipBlk, blk block.Block) (*block.Block, error
missedIterations := blk.Header.Iteration - 1
for iteration := uint8(0); iteration < missedIterations; iteration++ {
step := iteration*3 + 1
committee := c.p.CreateVotingCommittee(tipBlk.Header.Seed, blk.Header.Height, step, config.ConsensusSelectionMaxCommitteeSize)
committee := c.p.CreateVotingCommittee(tipBlk.Header.Seed, blk.Header.Height, step, config.ConsensusSelectionCommitteeSize)
committeeKeys := committee.MemberKeys()

if len(committeeKeys) == 1 {
Expand Down
13 changes: 7 additions & 6 deletions pkg/core/consensus/agreement/agreement_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"github.com/dusk-network/bls12_381-sign/go/cgo/bls"
"github.com/dusk-network/dusk-blockchain/pkg/config"
"github.com/dusk-network/dusk-blockchain/pkg/core/consensus/header"
"github.com/dusk-network/dusk-blockchain/pkg/p2p/wire/message"
"github.com/dusk-network/dusk-blockchain/pkg/p2p/wire/topics"
Expand All @@ -32,7 +33,8 @@ func TestAccumulatorProcessing(t *testing.T) {
}

accumulatedAggros := <-accumulator.CollectedVotesChan
assert.Equal(t, 7, len(accumulatedAggros))
expectedQuorum := float64(config.ConsensusCommitteeSize * config.ConsensusQuorumThreshold)
assert.Greater(t, float64(len(accumulatedAggros)), expectedQuorum)
}

func TestAccumulatorProcessingAggregation(t *testing.T) {
Expand All @@ -48,7 +50,8 @@ func TestAccumulatorProcessingAggregation(t *testing.T) {
}

accumulatedAggros := <-accumulator.CollectedVotesChan
assert.Equal(t, 7, len(accumulatedAggros))
expectedQuorum := float64(config.ConsensusCommitteeSize * config.ConsensusQuorumThreshold)
assert.Greater(t, float64(len(accumulatedAggros)), expectedQuorum)

var err error

Expand All @@ -58,11 +61,9 @@ func TestAccumulatorProcessingAggregation(t *testing.T) {
pubs := new(sortedset.Set)

for _, a := range accumulatedAggros {
sigs = append(sigs, a.Signature())
weight := handler.VotesFor(a.State().PubKeyBLS, evs[0].State().Round, evs[0].State().Step)

for i := 0; i < weight; i++ {
pubs.Insert(a.State().PubKeyBLS)
if weight > 0 && pubs.Insert(a.State().PubKeyBLS) {
sigs = append(sigs, a.Signature())
}
}

Expand Down
10 changes: 1 addition & 9 deletions pkg/core/consensus/agreement/checkcert.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func CheckBlockCertificate(provisioners user.Provisioners, blk block.Block, seed
}

func checkBlockCertificateForStep(batchedSig []byte, bitSet uint64, round uint64, step uint8, provisioners user.Provisioners, blockHash, seed []byte) error {
size := committeeSize(provisioners.SubsetSizeAt(round))
size := config.ConsensusCommitteeSize
committee := provisioners.CreateVotingCommittee(seed, round, step, size)
subcommittee := committee.IntersectCluster(bitSet)

Expand All @@ -62,14 +62,6 @@ func checkBlockCertificateForStep(batchedSig []byte, bitSet uint64, round uint64
return header.VerifySignatures(round, step, blockHash, apk, batchedSig)
}

func committeeSize(memberAmount int) int {
if memberAmount > config.ConsensusMaxCommitteeSize {
return config.ConsensusMaxCommitteeSize
}

return memberAmount
}

func logStepVotes(msgStep uint8, msgRound uint64, msgHash []byte, h *handler, votesPerStep []*message.StepVotes, ru consensus.RoundUpdate) {
quorumTarget := h.Quorum(msgRound)

Expand Down
10 changes: 5 additions & 5 deletions pkg/core/consensus/agreement/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,29 @@ func NewHandler(keys key.Keys, p user.Provisioners, seed []byte) *handler {

// AmMember checks if we are part of the committee.
func (a *handler) AmMember(round uint64, step uint8) bool {
return a.Handler.AmMember(round, step, config.ConsensusMaxCommitteeSize)
return a.Handler.AmMember(round, step, config.ConsensusCommitteeSize)
}

// IsMember delegates the committee.Handler to check if a Provisioner is in the
// committee for a specified round and step.
func (a *handler) IsMember(pubKeyBLS []byte, round uint64, step uint8) bool {
return a.Handler.IsMember(pubKeyBLS, round, step, config.ConsensusMaxCommitteeSize)
return a.Handler.IsMember(pubKeyBLS, round, step, config.ConsensusCommitteeSize)
}

// Committee returns a VotingCommittee for a given round and step.
func (a *handler) Committee(round uint64, step uint8) user.VotingCommittee {
return a.Handler.Committee(round, step, config.ConsensusMaxCommitteeSize)
return a.Handler.Committee(round, step, config.ConsensusCommitteeSize)
}

// VotesFor delegates embedded committee.Handler to accumulate a vote for a
// given round.
func (a *handler) VotesFor(pubKeyBLS []byte, round uint64, step uint8) int {
return a.Handler.VotesFor(pubKeyBLS, round, step, config.ConsensusMaxCommitteeSize)
return a.Handler.VotesFor(pubKeyBLS, round, step, config.ConsensusCommitteeSize)
}

// Quorum returns the amount of committee members necessary to reach a quorum.
func (a *handler) Quorum(round uint64) int {
return quorum(a.CommitteeSize(round, config.ConsensusMaxCommitteeSize))
return quorum(config.ConsensusCommitteeSize)
}

func quorum(committeeSize int) int {
Expand Down
18 changes: 1 addition & 17 deletions pkg/core/consensus/committee/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ func (b *Handler) Committee(round uint64, step uint8, maxSize int) user.VotingCo
return committee
}

func (b *Handler) generateCommittees(seed []byte, round uint64, step uint8, maxSize int) {
size := b.CommitteeSize(round, maxSize)

func (b *Handler) generateCommittees(seed []byte, round uint64, step uint8, size int) {
b.lock.Lock()
defer b.lock.Unlock()

Expand All @@ -85,20 +83,6 @@ func (b *Handler) generateCommittees(seed []byte, round uint64, step uint8, maxS
}
}

// CommitteeSize returns the size of a VotingCommittee, depending on
// how many provisioners are in the set.
func (b *Handler) CommitteeSize(round uint64, maxSize int) int {
b.lock.RLock()
size := b.Provisioners.SubsetSizeAt(round)
b.lock.RUnlock()

if size > maxSize {
return maxSize
}

return size
}

// Seed returns seed value.
func (b *Handler) Seed() []byte {
b.lock.RLock()
Expand Down
3 changes: 2 additions & 1 deletion pkg/core/consensus/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/dusk-network/bls12_381-sign/go/cgo/bls"
"github.com/dusk-network/dusk-blockchain/pkg/config"
"github.com/dusk-network/dusk-blockchain/pkg/config/genesis"
"github.com/dusk-network/dusk-blockchain/pkg/core/consensus/header"
"github.com/dusk-network/dusk-blockchain/pkg/core/consensus/key"
Expand Down Expand Up @@ -99,7 +100,7 @@ func MockMember(keys key.Keys) *user.Member {
}

member.Stakes = make([]user.Stake, 1)
member.Stakes[0].Value = 500
member.Stakes[0].Value = 1000 * config.DUSK
member.Stakes[0].Eligibility = 1

return member
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/consensus/reduction/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestAggregation(t *testing.T) {
t.Run(testName, func(t *testing.T) {
// making sure that parallelism does not interfere with the test
tt := tt
// creting the require instance from this subtest
// creating the require instance from this subtest
require := require.New(t)
// setting up the helper and the aggregator
hlp := NewHelper(messageToSpawn+1, 1*time.Second)
Expand Down
14 changes: 7 additions & 7 deletions pkg/core/consensus/reduction/firststep/reduction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"testing"
"time"

"github.com/dusk-network/dusk-blockchain/pkg/p2p/wire/topics"
"github.com/dusk-network/dusk-blockchain/pkg/util/nativeutils/eventbus"
"github.com/stretchr/testify/require"

Expand All @@ -20,16 +19,17 @@ import (
"github.com/dusk-network/dusk-blockchain/pkg/core/consensus/reduction"
"github.com/dusk-network/dusk-blockchain/pkg/core/database/lite"
"github.com/dusk-network/dusk-blockchain/pkg/p2p/wire/message"
"github.com/dusk-network/dusk-blockchain/pkg/p2p/wire/topics"
crypto "github.com/dusk-network/dusk-crypto/hash"
)

// TestSendReduction tests that the reduction step completes without problems
// and produces a StepVotesMsg in case it receives enough valid Reduction messages
// It uses the reduction common test preparation.
func TestSendReduction(t *testing.T) {
hlp := reduction.NewHelper(50, time.Second)
hlp := reduction.NewHelper(10, 5*time.Second)
_, db := lite.CreateDBConnection()
step := New(nil, hlp.Emitter, hlp.ProcessCandidateVerificationRequest, 10*time.Second, db, nil)
step := New(nil, hlp.Emitter, hlp.ProcessCandidateVerificationRequest, 5*time.Second, db, nil)
scoreMsg := consensus.MockNewBlockMsg(t, nil)
// injecting the result of the Selection step
stepFn := step.Initialize(scoreMsg.Payload().(message.NewBlock))
Expand Down Expand Up @@ -73,7 +73,7 @@ func initiateTableTest(hlp *reduction.Helper, timeout time.Duration, hash []byte
// testing that the timeout remained the same after a successful run
testStep: func(t *testing.T, step consensus.Phase) {
r := step.(*Phase)
require.Equal(t, r.TimeOut, timeout)
require.Equal(t, timeout, r.TimeOut)
},
},

Expand All @@ -93,7 +93,7 @@ func initiateTableTest(hlp *reduction.Helper, timeout time.Duration, hash []byte
// testing that the timeout doubled
testStep: func(t *testing.T, step consensus.Phase) {
r := step.(*Phase)
require.Equal(t, r.TimeOut, 2*timeout)
require.Equal(t, 2*timeout, r.TimeOut)
},
},
}
Expand All @@ -102,12 +102,12 @@ func initiateTableTest(hlp *reduction.Helper, timeout time.Duration, hash []byte
func TestFirstStepReduction(t *testing.T) {
step := uint8(2)
round := uint64(1)
messageToSpawn := 50
messageToSpawn := 10

hash, err := crypto.RandEntropy(32)
require.NoError(t, err)

timeout := time.Second
timeout := 10 * time.Second
hlp := reduction.NewHelper(messageToSpawn, timeout)

table := initiateTableTest(hlp, timeout, hash, round, step)
Expand Down
10 changes: 5 additions & 5 deletions pkg/core/consensus/reduction/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ func NewHandler(keys key.Keys, p user.Provisioners, seed []byte) *Handler {

// AmMember checks if we are part of the committee.
func (b *Handler) AmMember(round uint64, step uint8) bool {
return b.Handler.AmMember(round, step, config.ConsensusMaxCommitteeSize)
return b.Handler.AmMember(round, step, config.ConsensusCommitteeSize)
}

// IsMember delegates the committee.Handler to check if a BLS public key belongs
// to a committee for the specified round and step.
func (b *Handler) IsMember(pubKeyBLS []byte, round uint64, step uint8) bool {
return b.Handler.IsMember(pubKeyBLS, round, step, config.ConsensusMaxCommitteeSize)
return b.Handler.IsMember(pubKeyBLS, round, step, config.ConsensusCommitteeSize)
}

// VotesFor delegates the committee.Handler to accumulate Votes for the
// specified BLS public key identifying a Provisioner.
func (b *Handler) VotesFor(pubKeyBLS []byte, round uint64, step uint8) int {
return b.Handler.VotesFor(pubKeyBLS, round, step, config.ConsensusMaxCommitteeSize)
return b.Handler.VotesFor(pubKeyBLS, round, step, config.ConsensusCommitteeSize)
}

// VerifySignature verifies the BLS signature of the Reduction event. Since the
Expand All @@ -67,10 +67,10 @@ func (b *Handler) VerifySignature(red message.Reduction) error {

// Quorum returns the amount of committee votes to reach a quorum.
func (b *Handler) Quorum(round uint64) int {
return int(math.Ceil(float64(b.CommitteeSize(round, config.ConsensusMaxCommitteeSize)) * config.ConsensusQuorumThreshold))
return int(math.Ceil(float64(config.ConsensusCommitteeSize) * config.ConsensusQuorumThreshold))
}

// Committee returns a VotingCommittee for a given round and step.
func (b *Handler) Committee(round uint64, step uint8) user.VotingCommittee {
return b.Handler.Committee(round, step, config.ConsensusMaxCommitteeSize)
return b.Handler.Committee(round, step, config.ConsensusCommitteeSize)
}
12 changes: 6 additions & 6 deletions pkg/core/consensus/reduction/secondstep/reduction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func verifyFn(context.Context, block.Block) error {
// It uses the recution common test preparation.
func TestSendReduction(t *testing.T) {
round := uint64(1)
messageToSpawn := 50
messageToSpawn := 10
hash, err := crypto.RandEntropy(32)
require.NoError(t, err)

timeout := time.Second

hlp := reduction.NewHelper(messageToSpawn, timeout)
secondStep := New(hlp.Emitter, verifyFn, 10*time.Second)
secondStep := New(hlp.Emitter, verifyFn, 5*time.Second)

// Generate second StepVotes
svs := message.GenVotes(hash, []byte{0, 0, 0, 0}, 1, 2, hlp.ProvisionersKeys, hlp.P)
Expand Down Expand Up @@ -83,7 +83,7 @@ func initiateTableTest(timeout time.Duration, hash []byte, round uint64, step ui
testStep: func(t *testing.T, step consensus.Phase) {
r := step.(*Phase)

require.Equal(t, r.TimeOut, timeout)
require.Equal(t, timeout, r.TimeOut)
},
},

Expand Down Expand Up @@ -126,7 +126,7 @@ func initiateTableTest(timeout time.Duration, hash []byte, round uint64, step ui
// testing that the timeout doubled
testStep: func(t *testing.T, step consensus.Phase) {
r := step.(*Phase)
require.Equal(t, r.TimeOut, 2*timeout)
require.Equal(t, 2*timeout, r.TimeOut)
},
},
}
Expand All @@ -135,12 +135,12 @@ func initiateTableTest(timeout time.Duration, hash []byte, round uint64, step ui
func TestSecondStepReduction(t *testing.T) {
step := uint8(2)
round := uint64(1)
messageToSpawn := 50
messageToSpawn := 10

hash, err := crypto.RandEntropy(32)
require.NoError(t, err)

timeout := time.Second
timeout := 10 * time.Second

table := initiateTableTest(timeout, hash, round, step)
for name, ttest := range table {
Expand Down
Loading

0 comments on commit f6e64ee

Please sign in to comment.