Skip to content

Commit

Permalink
Merge branch 'develop' into proper-latency
Browse files Browse the repository at this point in the history
  • Loading branch information
dshulyak committed Sep 28, 2023
2 parents 7492039 + fe23c05 commit 5fcb1aa
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 252 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ In order to enable provide following configuration:
* [#5032](https://github.com/spacemeshos/go-spacemesh/pull/5032) Ativeset data pruned from ballots.
* [#5035](https://github.com/spacemeshos/go-spacemesh/pull/5035) Fix possible nil pointer panic when node fails to persist nipost builder state.
* [#5079](https://github.com/spacemeshos/go-spacemesh/pull/5079) increase atx cache to 50 000 to reduce disk reads.
* [#5083](https://github.com/spacemeshos/go-spacemesh/pull/5083) Disable beacon protocol temporarily.

## v1.1.5

Expand Down
10 changes: 5 additions & 5 deletions activation/nipost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ func buildNIPost(tb testing.TB, postProvider *testPostManager, nipostChallenge t

epoch := layersPerEpoch * layerDuration
poetCfg := PoetConfig{
PhaseShift: epoch / 5,
CycleGap: epoch / 10,
GracePeriod: epoch / 10,
RequestTimeout: epoch / 10,
RequestRetryDelay: epoch / 100,
PhaseShift: epoch / 2,
CycleGap: epoch / 5,
GracePeriod: epoch / 5,
RequestTimeout: epoch / 5,
RequestRetryDelay: epoch / 50,
MaxRequestRetries: 10,
}

Expand Down
7 changes: 5 additions & 2 deletions beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,16 @@ func (pd *ProtocolDriver) setMetricsRegistry(registry *prometheus.Registry) {
// Start starts listening for layers and outputs.
func (pd *ProtocolDriver) Start(ctx context.Context) {
pd.startOnce.Do(func() {
pd.logger.With().Info("starting beacon protocol", log.String("config", fmt.Sprintf("%+v", pd.config)))
if pd.sync == nil {
pd.logger.Fatal("update sync state provider can't be nil")
}

pd.metricsCollector.Start(nil)

if pd.config.RoundsNumber == 0 {
pd.logger.Info("beacon protocol disabled")
return
}
pd.logger.With().Info("starting beacon protocol", log.String("config", fmt.Sprintf("%+v", pd.config)))
pd.setProposalTimeForNextEpoch()
pd.eg.Go(func() error {
pd.listenEpochs(ctx)
Expand Down
28 changes: 19 additions & 9 deletions blocks/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/events"
"github.com/spacemeshos/go-spacemesh/log"
"github.com/spacemeshos/go-spacemesh/proposals"
"github.com/spacemeshos/go-spacemesh/sql/ballots"
"github.com/spacemeshos/go-spacemesh/sql/layers"
"github.com/spacemeshos/go-spacemesh/sql/transactions"
"github.com/spacemeshos/go-spacemesh/txs"
Expand Down Expand Up @@ -225,16 +225,26 @@ func rewardInfoAndHeight(logger log.Log, cdb *datastore.CachedDB, cfg Config, pr
if atx.BaseTickHeight > max {
max = atx.BaseTickHeight
}
ballot := &p.Ballot
weightPer, err := proposals.ComputeWeightPerEligibility(cdb, ballot)
if err != nil {
logger.With().Error("failed to calculate weight per eligibility", p.ID(), log.Err(err))
return 0, nil, err
var count uint32
if p.Ballot.EpochData != nil {
count = p.Ballot.EpochData.EligibilityCount
} else {
ref, err := ballots.Get(cdb, p.RefBallot)
if err != nil {
return 0, nil, fmt.Errorf("get ballot %s: %w", p.RefBallot.String(), err)
}
if ref.EpochData == nil {
return 0, nil, fmt.Errorf("corrupted data: ref ballot %s with empty epoch data", p.RefBallot.String())
}
count = ref.EpochData.EligibilityCount
}
logger.With().Debug("weight per eligibility", p.ID(), log.Stringer("weight_per", weightPer))
actual := weightPer.Mul(weightPer, new(big.Rat).SetUint64(uint64(len(ballot.EligibilityProofs))))
if _, ok := weights[atx.ID]; !ok {
weights[atx.ID] = actual
weight := new(big.Rat).SetFrac(
new(big.Int).SetUint64(atx.GetWeight()),
new(big.Int).SetUint64(uint64(count)),
)
weight.Mul(weight, new(big.Rat).SetUint64(uint64(len(p.Ballot.EligibilityProofs))))
weights[atx.ID] = weight
atxids = append(atxids, atx.ID)
} else {
logger.With().Error("multiple proposals with the same ATX", atx.ID, p.ID())
Expand Down
2 changes: 1 addition & 1 deletion config/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func MainnetConfig() Config {
GracePeriodDuration: 10 * time.Minute,
ProposalDuration: 4 * time.Minute,
FirstVotingRoundDuration: 30 * time.Minute,
RoundsNumber: 300,
RoundsNumber: 0,
VotingRoundDuration: 4 * time.Minute,
WeakCoinRoundDuration: 4 * time.Minute,
VotesLimit: 100,
Expand Down
10 changes: 6 additions & 4 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,12 @@ func (app *App) initServices(ctx context.Context) error {
return errors.New("not synced for gossip")
}

app.host.Register(pubsub.BeaconWeakCoinProtocol, pubsub.ChainGossipHandler(syncHandler, beaconProtocol.HandleWeakCoinProposal), pubsub.WithValidatorInline(true))
app.host.Register(pubsub.BeaconProposalProtocol, pubsub.ChainGossipHandler(syncHandler, beaconProtocol.HandleProposal), pubsub.WithValidatorInline(true))
app.host.Register(pubsub.BeaconFirstVotesProtocol, pubsub.ChainGossipHandler(syncHandler, beaconProtocol.HandleFirstVotes), pubsub.WithValidatorInline(true))
app.host.Register(pubsub.BeaconFollowingVotesProtocol, pubsub.ChainGossipHandler(syncHandler, beaconProtocol.HandleFollowingVotes), pubsub.WithValidatorInline(true))
if app.Config.Beacon.RoundsNumber > 0 {
app.host.Register(pubsub.BeaconWeakCoinProtocol, pubsub.ChainGossipHandler(syncHandler, beaconProtocol.HandleWeakCoinProposal), pubsub.WithValidatorInline(true))
app.host.Register(pubsub.BeaconProposalProtocol, pubsub.ChainGossipHandler(syncHandler, beaconProtocol.HandleProposal), pubsub.WithValidatorInline(true))
app.host.Register(pubsub.BeaconFirstVotesProtocol, pubsub.ChainGossipHandler(syncHandler, beaconProtocol.HandleFirstVotes), pubsub.WithValidatorInline(true))
app.host.Register(pubsub.BeaconFollowingVotesProtocol, pubsub.ChainGossipHandler(syncHandler, beaconProtocol.HandleFollowingVotes), pubsub.WithValidatorInline(true))
}
app.host.Register(pubsub.ProposalProtocol, pubsub.ChainGossipHandler(syncHandler, proposalListener.HandleProposal))
app.host.Register(pubsub.AtxProtocol, pubsub.ChainGossipHandler(atxSyncHandler, atxHandler.HandleGossipAtx))
app.host.Register(pubsub.TxProtocol, pubsub.ChainGossipHandler(syncHandler, app.txHandler.HandleGossipTransaction))
Expand Down
2 changes: 0 additions & 2 deletions proposals/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
var (
CalcEligibleLayer = util.CalcEligibleLayer
GetNumEligibleSlots = util.GetNumEligibleSlots
// ComputeWeightPerEligibility computes the ballot weight per eligibility w.r.t the active set recorded in its reference ballot.
ComputeWeightPerEligibility = util.ComputeWeightPerEligibility
)

//go:generate scalegen -types VrfMessage
Expand Down
57 changes: 0 additions & 57 deletions proposals/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ package util
import (
"encoding/binary"
"errors"
"fmt"
"math/big"

"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/sql/activesets"
"github.com/spacemeshos/go-spacemesh/sql/ballots"
)

var (
Expand Down Expand Up @@ -41,55 +36,3 @@ func GetNumEligibleSlots(weight, minWeight, totalWeight uint64, committeeSize, l
}
return uint32(numEligible), nil
}

// ComputeWeightPerEligibility computes the ballot weight per eligibility w.r.t the active set recorded in its reference ballot.
func ComputeWeightPerEligibility(
cdb *datastore.CachedDB,
ballot *types.Ballot,
) (*big.Rat, error) {
var (
refBallot = ballot
hdr *types.ActivationTxHeader
err error
atxWeight uint64
)
if ballot.EpochData == nil {
if ballot.RefBallot == types.EmptyBallotID {
return nil, fmt.Errorf("%w: empty ref ballot but no epoch data %s", ErrBadBallotData, ballot.ID())
}
refBallot, err = ballots.Get(cdb, ballot.RefBallot)
if err != nil {
return nil, fmt.Errorf("%w: missing ref ballot %s (for %s)", err, ballot.RefBallot, ballot.ID())
}
}
if refBallot.EpochData == nil {
return nil, fmt.Errorf("epoch data is nil on ballot %d/%s", refBallot.Layer, refBallot.ID())
}
if refBallot.EpochData.EligibilityCount == 0 {
return nil, fmt.Errorf("eligibility count is 0 on ballot %d/%s", refBallot.Layer, refBallot.ID())
}
actives, err := activesets.Get(cdb, refBallot.EpochData.ActiveSetHash)
if err != nil {
return nil, fmt.Errorf("get active set %s (%s)", refBallot.EpochData.ActiveSetHash.ShortString(), refBallot.ID())
}
if len(actives.Set) == 0 {
return nil, fmt.Errorf("empty active set %s (%s)", refBallot.EpochData.ActiveSetHash.ShortString(), refBallot.ID())
}
for _, atxID := range actives.Set {
hdr, err = cdb.GetAtxHeader(atxID)
if err != nil {
return nil, fmt.Errorf("%w: missing atx %s in active set of %s (for %s)", err, atxID, refBallot.ID(), ballot.ID())
}
if atxID == ballot.AtxID {
atxWeight = hdr.GetWeight()
break
}
}
if atxWeight == 0 {
return nil, fmt.Errorf("atx id %v is not found in the active set of the reference ballot %v with atxid %v", ballot.AtxID, refBallot.ID(), refBallot.AtxID)
}
return new(big.Rat).SetFrac(
new(big.Int).SetUint64(atxWeight),
new(big.Int).SetUint64(uint64(refBallot.EpochData.EligibilityCount)),
), nil
}
172 changes: 0 additions & 172 deletions proposals/util_test.go

This file was deleted.

0 comments on commit 5fcb1aa

Please sign in to comment.