Skip to content

Commit

Permalink
Backport 5619: Update size of Ballot (#5626)
Browse files Browse the repository at this point in the history
* Update size of Ballot (#5619)

## Motivation

This updates max scale collection sizes to support a network with up to 2.2 mio unique (valid) identities.

* Update CHANGELOG.md
  • Loading branch information
fasmat authored Feb 29, 2024
1 parent d540279 commit 4f5cce1
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 25 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ See [RELEASE](./RELEASE.md) for workflow instructions.
* [#5618](https://github.com/spacemeshos/go-spacemesh/pull/5618)
Add index on ATXs that makes epoch ATX requests faster

* [#5619](https://github.com/spacemeshos/go-spacemesh/pull/5619)
Updated data structures to support the network with up to 2.2 unique smesher identities.

## Release v1.3.10

### Improvements

* [#5564](https://github.com/spacemeshos/go-spacemesh/pull/5564) Use decaying tags for fetch peers. This prevents
libp2p's Connection Manager from breaking sync.

* [#5522](https://github.com/spacemeshos/go-spacemesh/pull/5522) Disable mesh aggremenet sync protocol.
* [#5522](https://github.com/spacemeshos/go-spacemesh/pull/5522) Disable mesh agreement sync protocol.

It reduces number of requests for historical activation ids.

Expand Down
3 changes: 1 addition & 2 deletions beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,7 @@ func atxThresholdFraction(kappa int, q *big.Rat, numATXs int) *big.Float {
// TODO(nkryuchkov): Consider having a generic function for probabilities.
func atxThreshold(kappa int, q *big.Rat, numATXs int) *big.Int {
const (
sigLengthBytes = 80
sigLengthBits = sigLengthBytes * 8
sigLengthBits = types.VrfSignatureSize * 8
)

fraction := atxThresholdFraction(kappa, q, numATXs)
Expand Down
2 changes: 2 additions & 0 deletions beacon/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ func ProposalFromVrf(vrf types.VrfSignature) Proposal {
type FirstVotingMessageBody struct {
EpochID types.EpochID
// number of proposals is expected to be under 100, 1000 is a safe upper bound
// This expectation holds true for any number of smeshers on the network
ValidProposals []Proposal `scale:"max=1000"`
// number of proposals is expected to be under 100, 1000 is a safe upper bound
// This expectation holds true for any number of smeshers on the network
PotentiallyValidProposals []Proposal `scale:"max=1000"`
}

Expand Down
14 changes: 11 additions & 3 deletions common/types/ballot.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ type Ballot struct {
// the proof of the smeshers eligibility to vote and propose block content in this epoch.
// Eligibilities must be produced in the ascending order.
// the proofs are vrf signatures and need not be included in the ballot's signature.
// according to protocol there are 50 per layer, the rest is safety margin
EligibilityProofs []VotingEligibility `scale:"max=500"`
//
// The number of eligibility proofs depends on the smeshers weight and the total weight of the network.
// For epoch 16 the largest smesher had 888 SUs and the total weight of the network was ~20.2 Mio SUs.
// This means that the largest smesher received 888 / 20,200,000 = 0.0044% of all eligibility slots for the epoch.
// There are 4032 layers in an epoch and 50 eligibility slots per layer, so the largest smesher received
// 0.0044% * 4032 * 50 = ~9 eligibility slots.
//
// Assuming the largest smesher won't control more than 10% of space in the network, we can assume that the
// highest number of eligibilities in a single ballot will be below 25000. (10% of 4032 * 50 = 20160)
EligibilityProofs []VotingEligibility `scale:"max=25000"`
// from the smesher's view, the set of ATXs eligible to vote and propose block content in this epoch
// only present in smesher's first ballot of the epoch
ActiveSet []ATXID `scale:"max=100000"`
ActiveSet []ATXID `scale:"max=2200000"`

// the following fields are kept private and from being serialized
ballotID BallotID
Expand Down
8 changes: 4 additions & 4 deletions common/types/ballot_scale.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions common/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,21 @@ func (b Block) Equal(other Block) bool {
type InnerBlock struct {
LayerIndex LayerID
TickHeight uint64
Rewards []AnyReward `scale:"max=500"`
TxIDs []TransactionID `scale:"max=100000"`
// Rewards are the rewards for the block.
//
// Worst case scenario is that a single smesher identity has > 99.97% of the total weight of the network.
// In this case they will get all 50 available slots in all 4032 layers of the epoch.
// Additionally every other identity on the network that successfully published an ATX will get 1 slot.
//
// If we expect 2.2 Mio ATXs that would be a total of 2.2 Mio + 50 * 4032 = 2,401,600 slots.
// Since these are randomly distributed across the epoch, we can expect an average of n * p =
// 2,401,600 / 4032 = 595.7 rewards in a block with a standard deviation of sqrt(n * p * (1 - p)) =
// sqrt(2,401,600 * 1/4032 * 4031/4032) = 24.4
//
// This means that we can expect a maximum of 595.7 + 6*24.4 = 743 rewards per block with
// > 99.9997% probability.
Rewards []AnyReward `scale:"max=800"`
TxIDs []TransactionID `scale:"max=100000"`
}

// RatNum represents a rational number with the numerator and denominator.
Expand Down
4 changes: 2 additions & 2 deletions common/types/block_scale.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 22 additions & 3 deletions fetch/wire_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type RequestMessage struct {
// ResponseMessage is sent to the node as a response.
type ResponseMessage struct {
Hash types.Hash32
Data []byte `scale:"max=89128960"` // limit to 85 MiB
Data []byte `scale:"max=89128960"` // limit to 85 MiB - keep in line with Response.Data in `p2p/server/server.go`
}

// RequestBatch is a batch of requests and a hash of all requests as ID.
Expand Down Expand Up @@ -107,13 +107,32 @@ type MaliciousIDs struct {
type EpochData struct {
// to be in line with `EpochActiveSet` in common/types/activation.go
// and DefaultConfig in datastore/store.go
// also double-check the size of `ResponseMessage` above
//
// When changing this value also check
// - the size of `ResponseMessage` above
// - the fields `EligibilityProofs` and `ActiveSet` in the type `Ballot` in common/types/ballot.go
// - the size of `Rewards` in the type `InnerBlock` in common/types/block.go
// - the size of `Ballots` in the type `LayerData` below
// - the size of `Proposals` in the type `Value` in hare3/types.go
AtxIDs []types.ATXID `scale:"max=2200000"`
}

// LayerData is the data response for a given layer ID.
type LayerData struct {
Ballots []types.BallotID `scale:"max=500"` // expected are 50 proposals per layer + safety margin
// Ballots contains the ballots for the given layer.
//
// Worst case scenario is that a single smesher identity has > 99.97% of the total weight of the network.
// In this case they will get all 50 available slots in all 4032 layers of the epoch.
// Additionally every other identity on the network that successfully published an ATX will get 1 slot.
//
// If we expect 2.2 Mio ATXs that would be a total of 2.2 Mio + 50 * 4032 = 2,401,600 slots.
// Since these are randomly distributed across the epoch, we can expect an average of n * p =
// 2,401,600 / 4032 = 595.7 ballots in a layer with a standard deviation of sqrt(n * p * (1 - p)) =
// sqrt(2,401,600 * 1/4032 * 4031/4032) = 24.4
//
// This means that we can expect a maximum of 595.7 + 6*24.4 = 743 ballots per layer with
// > 99.9997% probability.
Ballots []types.BallotID `scale:"max=800"`
}

type OpinionRequest struct {
Expand Down
4 changes: 2 additions & 2 deletions fetch/wire_types_scale.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion hare3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,19 @@ func (ir IterRound) Absolute() uint32 {

type Value struct {
// Proposals is set in messages for preround and propose rounds.
Proposals []types.ProposalID `scale:"max=500"`
//
// Worst case scenario is that a single smesher identity has > 99.97% of the total weight of the network.
// In this case they will get all 50 available slots in all 4032 layers of the epoch.
// Additionally every other identity on the network that successfully published an ATX will get 1 slot.
//
// If we expect 2.2 Mio ATXs that would be a total of 2.2 Mio + 50 * 4032 = 2,401,600 slots.
// Since these are randomly distributed across the epoch, we can expect an average of n * p =
// 2,401,600 / 4032 = 595.7 eligibilities in a layer with a standard deviation of sqrt(n * p * (1 - p)) =
// sqrt(2,401,600 * 1/4032 * 4031/4032) = 24.4
//
// This means that we can expect a maximum of 595.7 + 6*24.4 = 743 eligibilities in a layer with
// > 99.9997% probability.
Proposals []types.ProposalID `scale:"max=800"`
// Reference is set in messages for commit and notify rounds.
Reference *types.Hash32
}
Expand Down
4 changes: 2 additions & 2 deletions hare3/types_scale.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type Handler func(context.Context, []byte) ([]byte, error)

// Response is a server response.
type Response struct {
Data []byte `scale:"max=62914560"` // 60 MiB
Data []byte `scale:"max=89128960"` // 85 MiB
Error string `scale:"max=1024"` // TODO(mafa): make error code instead of string
}

Expand Down
4 changes: 2 additions & 2 deletions p2p/server/server_scale.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4f5cce1

Please sign in to comment.