Skip to content

Commit

Permalink
reinstate CommitteeUpgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
acud committed Jul 31, 2024
1 parent 3fcb975 commit 6d3ef2e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
31 changes: 22 additions & 9 deletions hare4/hare.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,34 @@ var (
fetchFullTimeout = 5 * time.Second
)

type CommitteeUpgrade struct {
Layer types.LayerID
Size uint16
}

type Config struct {
Enable bool `mapstructure:"enable"`
EnableLayer types.LayerID `mapstructure:"enable-layer"`
DisableLayer types.LayerID `mapstructure:"disable-layer"`
Committee uint16 `mapstructure:"committee"`
Leaders uint16 `mapstructure:"leaders"`
IterationsLimit uint8 `mapstructure:"iterations-limit"`
PreroundDelay time.Duration `mapstructure:"preround-delay"`
RoundDuration time.Duration `mapstructure:"round-duration"`
Enable bool `mapstructure:"enable"`
EnableLayer types.LayerID `mapstructure:"enable-layer"`
DisableLayer types.LayerID `mapstructure:"disable-layer"`
Committee uint16 `mapstructure:"committee"`
CommitteeUpgrade *CommitteeUpgrade
Leaders uint16 `mapstructure:"leaders"`
IterationsLimit uint8 `mapstructure:"iterations-limit"`
PreroundDelay time.Duration `mapstructure:"preround-delay"`
RoundDuration time.Duration `mapstructure:"round-duration"`
// LogStats if true will log iteration statistics with INFO level at the start of the next iteration.
// This requires additional computation and should be used for debugging only.
LogStats bool `mapstructure:"log-stats"`
ProtocolName string `mapstructure:"protocolname"`
}

func (cfg *Config) CommitteeFor(layer types.LayerID) uint16 {
if cfg.CommitteeUpgrade != nil && layer >= cfg.CommitteeUpgrade.Layer {
return cfg.CommitteeUpgrade.Size
}
return cfg.Committee
}

func (cfg *Config) Validate(zdist time.Duration) error {
terminates := cfg.roundStart(IterRound{Iter: cfg.IterationsLimit, Round: hardlock})
if terminates > zdist {
Expand Down Expand Up @@ -574,7 +587,7 @@ func (h *Hare) onLayer(layer types.LayerID) {
beacon: beacon,
signers: maps.Values(h.signers),
vrfs: make([]*types.HareEligibility, len(h.signers)),
proto: newProtocol(h.config.Committee/2 + 1),
proto: newProtocol(h.config.CommitteeFor(layer)/2 + 1),
}
h.sessions[layer] = s.proto
h.mu.Unlock()
Expand Down
24 changes: 24 additions & 0 deletions hare4/hare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,30 @@ func TestHare_AddProposal(t *testing.T) {
require.ErrorIs(t, hare.OnProposal(p), store.ErrProposalExists)
}

func TestHareConfig_CommitteeUpgrade(t *testing.T) {
t.Parallel()
t.Run("no upgrade", func(t *testing.T) {
cfg := Config{
Committee: 400,
}
require.Equal(t, cfg.Committee, cfg.CommitteeFor(0))
require.Equal(t, cfg.Committee, cfg.CommitteeFor(100))
})
t.Run("upgrade", func(t *testing.T) {
cfg := Config{
Committee: 400,
CommitteeUpgrade: &CommitteeUpgrade{
Layer: 16,
Size: 50,
},
}
require.EqualValues(t, cfg.Committee, cfg.CommitteeFor(0))
require.EqualValues(t, cfg.Committee, cfg.CommitteeFor(15))
require.EqualValues(t, 50, cfg.CommitteeFor(16))
require.EqualValues(t, 50, cfg.CommitteeFor(100))
})
}

// TestHare_ReconstructForward tests that a message
// could be reconstructed on a downstream peer that
// receives a gossipsub message from a forwarding node
Expand Down
4 changes: 2 additions & 2 deletions hare4/legacy_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (lg *legacyOracle) validate(msg *Message) grade {
if msg.Eligibility.Count == 0 {
return grade0
}
committee := int(lg.config.Committee)
committee := int(lg.config.CommitteeFor(msg.Layer))
if msg.Round == propose {
committee = int(lg.config.Leaders)
}
Expand All @@ -50,7 +50,7 @@ func (lg *legacyOracle) active(
ir IterRound,
) *types.HareEligibility {
vrf := eligibility.GenVRF(context.Background(), signer.VRFSigner(), beacon, layer, ir.Absolute())
committee := int(lg.config.Committee)
committee := int(lg.config.CommitteeFor(layer))
if ir.Round == propose {
committee = int(lg.config.Leaders)
}
Expand Down

0 comments on commit 6d3ef2e

Please sign in to comment.