Skip to content

Commit

Permalink
Try #4765:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Aug 5, 2023
2 parents 6a4208b + 3ffa3df commit 11f70b3
Show file tree
Hide file tree
Showing 20 changed files with 2,382 additions and 6 deletions.
4 changes: 4 additions & 0 deletions cmd/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ func EnsureCLIFlags(cmd *cobra.Command, appCFG *config.Config) error {
elem = reflect.ValueOf(&appCFG.HareEligibility).Elem()
assignFields(ff, elem, name)

ff = reflect.TypeOf(appCFG.HARE3)
elem = reflect.ValueOf(&appCFG.HARE3).Elem()
assignFields(ff, elem, name)

ff = reflect.TypeOf(appCFG.Beacon)
elem = reflect.ValueOf(&appCFG.Beacon).Elem()
assignFields(ff, elem, name)
Expand Down
14 changes: 9 additions & 5 deletions common/types/malfeasance.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ func (hm *HareMetadata) Equivocation(other *HareMetadata) bool {
return hm.Layer == other.Layer && hm.Round == other.Round && hm.MsgHash != other.MsgHash
}

func (hm HareMetadata) ToBytes() []byte {
buf, err := codec.Encode(&hm)
if err != nil {
panic(err.Error())
}
return buf
}

type HareProofMsg struct {
InnerMsg HareMetadata

Expand All @@ -241,9 +249,5 @@ type HareProofMsg struct {

// SignedBytes returns the actual data being signed in a HareProofMsg.
func (m *HareProofMsg) SignedBytes() []byte {
data, err := codec.Encode(&m.InnerMsg)
if err != nil {
log.With().Fatal("failed to serialize MultiBlockProposalsMsg", log.Err(err))
}
return data
return m.InnerMsg.ToBytes()
}
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
vm "github.com/spacemeshos/go-spacemesh/genvm"
hareConfig "github.com/spacemeshos/go-spacemesh/hare/config"
eligConfig "github.com/spacemeshos/go-spacemesh/hare/eligibility/config"
"github.com/spacemeshos/go-spacemesh/hare3"
"github.com/spacemeshos/go-spacemesh/p2p"
"github.com/spacemeshos/go-spacemesh/syncer"
timeConfig "github.com/spacemeshos/go-spacemesh/timesync/config"
Expand Down Expand Up @@ -49,6 +50,7 @@ type Config struct {
P2P p2p.Config `mapstructure:"p2p"`
API grpcserver.Config `mapstructure:"api"`
HARE hareConfig.Config `mapstructure:"hare"`
HARE3 hare3.Config `mapstructure:"hare3"`
HareEligibility eligConfig.Config `mapstructure:"hare-eligibility"`
Beacon beacon.Config `mapstructure:"beacon"`
TIME timeConfig.TimeConfig `mapstructure:"time"`
Expand Down Expand Up @@ -136,6 +138,7 @@ func DefaultConfig() Config {
P2P: p2p.DefaultConfig(),
API: grpcserver.DefaultConfig(),
HARE: hareConfig.DefaultConfig(),
HARE3: hare3.DefaultConfig(),
HareEligibility: eligConfig.DefaultConfig(),
Beacon: beacon.DefaultConfig(),
TIME: timeConfig.DefaultConfig(),
Expand Down
8 changes: 8 additions & 0 deletions config/presets/fastnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ func fastnet() config.Config {
types.SetNetworkHRP(conf.NetworkHRP) // set to generate coinbase
conf.BaseConfig.OptFilterThreshold = 90

conf.HARE.Disable = 1 // hare won't run starting at this layer
conf.HARE.N = 800
conf.HARE.ExpectedLeaders = 10
conf.HARE.LimitConcurrent = 5
conf.HARE.LimitIterations = 3
conf.HARE.RoundDuration = 2 * time.Second
conf.HARE.WakeupDelta = 3 * time.Second

conf.HARE3.Enable = true
conf.HARE3.Committee = 800
conf.HARE3.Leaders = 10
conf.HARE3.PreroundDelay = 3 * time.Second
conf.HARE3.RoundDuration = 500 * time.Millisecond
conf.HARE3.IterationsLimit = 2

conf.P2P.MinPeers = 10

conf.Genesis = &config.GenesisConfig{
Expand Down
9 changes: 8 additions & 1 deletion hare/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package config

import "time"
import (
"time"

"github.com/spacemeshos/go-spacemesh/common/types"
)

// Config is the configuration of the Hare.
type Config struct {
Expand All @@ -12,6 +16,9 @@ type Config struct {
LimitConcurrent int `mapstructure:"hare-limit-concurrent"` // limit number of concurrent CPs

Hdist uint32

// If set to non-zero value will disable hare starting at that layer.
Disable types.LayerID `mapstructure:"disable"`
}

// DefaultConfig returns the default configuration for the hare.
Expand Down
4 changes: 4 additions & 0 deletions hare/hare.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ func (h *Hare) onTick(ctx context.Context, lid types.LayerID) (bool, error) {
h.With().Debug("hare exiting", log.Context(ctx), lid)
return false, nil
}
if h.config.Disable != 0 && lid >= h.config.Disable {
h.With().Debug("hare is disabled at this layer", log.Context(ctx), lid)
return false, nil
}

h.setLastLayer(lid)

Expand Down
29 changes: 29 additions & 0 deletions hare3/compat/result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package compat

import (
"context"

"go.uber.org/zap"

"github.com/spacemeshos/go-spacemesh/hare"
"github.com/spacemeshos/go-spacemesh/hare3"
)

func ReportResult(ctx context.Context, logger *zap.Logger, from <-chan hare3.ConsensusOutput, to chan<- hare.LayerOutput) {
for {
select {
case <-ctx.Done():
logger.Info("hare3 results reporter exited")
return
case out := <-from:
select {
case to <- hare.LayerOutput{
Ctx: ctx,
Layer: out.Layer,
Proposals: out.Proposals,
}:
case <-ctx.Done():
}
}
}
}
31 changes: 31 additions & 0 deletions hare3/compat/weakcoin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package compat

import (
"context"

"go.uber.org/zap"

"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/hare3"
)

type weakCoin interface {
Set(types.LayerID, bool) error
}

func ReportWeakcoin(ctx context.Context, logger *zap.Logger, from <-chan hare3.WeakCoinOutput, to weakCoin) {
for {
select {
case <-ctx.Done():
logger.Info("weak coin reporter exited")
return
case out := <-from:
if err := to.Set(out.Layer, out.Coin); err != nil {
logger.Error("failed to update weakcoin",
zap.Uint32("lid", out.Layer.Uint32()),
zap.Error(err),
)
}
}
}
}
Loading

0 comments on commit 11f70b3

Please sign in to comment.