Skip to content

Commit

Permalink
Try #5793:
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemesh-bors[bot] authored Jul 5, 2024
2 parents 0712be8 + ce0227c commit 66a144d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
4 changes: 4 additions & 0 deletions config/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func MainnetConfig() Config {
hare3conf.Committee = 400
hare3conf.Enable = true
hare3conf.EnableLayer = 35117
hare3conf.CommitteeUpgrade = &hare3.CommitteeUpgrade{
Layer: 105_720, // July 15, 2024, 10:00:00 AM UTC
Size: 50,
}
return Config{
BaseConfig: BaseConfig{
DataDirParent: defaultDataDir,
Expand Down
35 changes: 26 additions & 9 deletions hare3/hare.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,34 @@ import (
"github.com/spacemeshos/go-spacemesh/system"
)

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 All @@ -63,6 +76,10 @@ func (cfg *Config) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
encoder.AddUint32("enabled layer", cfg.EnableLayer.Uint32())
encoder.AddUint32("disabled layer", cfg.DisableLayer.Uint32())
encoder.AddUint16("committee", cfg.Committee)
if cfg.CommitteeUpgrade != nil {
encoder.AddUint32("committee upgrade layer", cfg.CommitteeUpgrade.Layer.Uint32())
encoder.AddUint16("committee upgrade size", cfg.CommitteeUpgrade.Size)
}
encoder.AddUint16("leaders", cfg.Leaders)
encoder.AddUint8("iterations limit", cfg.IterationsLimit)
encoder.AddDuration("preround delay", cfg.PreroundDelay)
Expand Down Expand Up @@ -352,7 +369,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 hare3/hare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,3 +952,27 @@ func TestHare_AddProposal(t *testing.T) {
require.True(t, hare.IsKnown(p.Layer, p.ID()))
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))
})
}
4 changes: 2 additions & 2 deletions hare3/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
6 changes: 6 additions & 0 deletions systest/parameters/fastnet/smesher.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
}
}
},
"hare3": {
"committeeupgrade": {
"layer": 16,
"size": 15
}
},
"smeshing": {
"smeshing-verifying-opts": {
"smeshing-opts-verifying-min-workers": 1000000
Expand Down

0 comments on commit 66a144d

Please sign in to comment.