Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Increase ATX limits to 6.0 Mio #5999

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ Upgrading to this version requires going through v1.5.x first. Removed migration
ATXs. This vulnerability allows an attacker to claim rewards for a full tick amount although they should not be
eligible for them.

## Release v1.5.7

### Improvements

* [#5999](https://github.com/spacemeshos/go-spacemesh/pull/5999) Increase limits to allow up to 6.0 Mio ATXs per epoch.

## Release v1.5.6

### Improvements

* [#5943](https://github.com/spacemeshos/go-spacemesh/pull/5943) Fix timing out querying proof in 1:N in a presence of
a broken Poet.

Previously, every identity waited for the full timeout time (~20 minutes) before giving up.

## Release v1.5.5

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion common/types/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func ATXIDsToHashes(ids []ATXID) []Hash32 {

type EpochActiveSet struct {
Epoch EpochID
Set []ATXID `scale:"max=5500000"` // to be in line with `EpochData` in fetch/wire_types.go
Set []ATXID `scale:"max=6000000"` // to be in line with `EpochData` in fetch/wire_types.go
}

var MaxEpochActiveSetSize = scale.MustGetMaxElements[EpochActiveSet]("Set")
Expand Down
4 changes: 2 additions & 2 deletions common/types/activation_scale.go

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

10 changes: 5 additions & 5 deletions common/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ type InnerBlock struct {
// 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 5.5 Mio ATXs that would be a total of 5.5 Mio + 50 * 4032 = 5 701 600 slots.
// If we expect 6.0 Mio ATXs that would be a total of 6.0 Mio + 50 * 4032 = 6 201 600 slots.
// Since these are randomly distributed across the epoch, we can expect an average of n * p =
// 5 701 600 / 4032 = 1414.1 rewards in a block with a standard deviation of sqrt(n * p * (1 - p)) =
// sqrt(3 701 600 * 1/4032 * 4031/4032) = 37.6
// 6 201 600 / 4032 = 1538.1 rewards in a block with a standard deviation of sqrt(n * p * (1 - p)) =
// sqrt(3 701 600 * 1/4032 * 4031/4032) = 39.2
//
// This means that we can expect a maximum of 1414.1 + 6*37.6 = 1639.7 rewards per block with
// This means that we can expect a maximum of 1538.1 + 6*39.2 = 1773.4 rewards per block with
// > 99.9997% probability.
Rewards []AnyReward `scale:"max=1650"`
Rewards []AnyReward `scale:"max=1775"`
TxIDs []TransactionID `scale:"max=100000"`
}

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.

16 changes: 8 additions & 8 deletions fetch/wire_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type RequestMessage struct {
type ResponseMessage struct {
Hash types.Hash32
// keep in line with limit of Response.Data in `p2p/server/server.go`
Data []byte `scale:"max=183500800"` // 175 MiB > 5.5 mio ATX * 32 bytes per ID
Data []byte `scale:"max=209715200"` // 200 MiB > 6.0 mio ATX * 32 bytes per ID
}

// RequestBatch is a batch of requests and a hash of all requests as ID.
Expand Down Expand Up @@ -116,7 +116,7 @@ type MeshHashes struct {
}

type MaliciousIDs struct {
NodeIDs []types.NodeID `scale:"max=5500000"` // to be in line with `EpochData.AtxIDs` below
NodeIDs []types.NodeID `scale:"max=6000000"` // to be in line with `EpochData.AtxIDs` below
}

type EpochData struct {
Expand All @@ -128,7 +128,7 @@ type EpochData struct {
// - 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=5500000"`
AtxIDs []types.ATXID `scale:"max=6000000"`
}

// LayerData is the data response for a given layer ID.
Expand All @@ -139,14 +139,14 @@ type LayerData struct {
// 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 5.5 Mio ATXs that would be a total of 5.5 Mio + 50 * 4032 = 4 701 600 slots.
// If we expect 6.0 Mio ATXs that would be a total of 6.0 Mio + 50 * 4032 = 6 201 600 slots.
// Since these are randomly distributed across the epoch, we can expect an average of n * p =
// 5 701 600 / 4032 = 1414.1 ballots in a layer with a standard deviation of sqrt(n * p * (1 - p)) =
// sqrt(3 701 600 * 1/4032 * 4031/4032) = 37.6
// 6 201 600 / 4032 = 1538.1 ballots in a layer with a standard deviation of sqrt(n * p * (1 - p)) =
// sqrt(3 701 600 * 1/4032 * 4031/4032) = 39.2
//
// This means that we can expect a maximum of 1414.1 + 6*37.6 = 1639.7 ballots per layer with
// This means that we can expect a maximum of 1538.1 + 6*39.2 = 1773.4 ballots per layer with
// > 99.9997% probability.
Ballots []types.BallotID `scale:"max=1650"`
Ballots []types.BallotID `scale:"max=1775"`
}

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

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

10 changes: 5 additions & 5 deletions hare3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ type Value struct {
// 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 5.5 Mio ATXs that would be a total of 5.5 Mio + 50 * 4032 = 5 701 600 slots.
// If we expect 6.0 Mio ATXs that would be a total of 6.0 Mio + 50 * 4032 = 6 201 600 slots.
// Since these are randomly distributed across the epoch, we can expect an average of n * p =
// 5 701 600 / 4032 = 1414.1 eligibilities in a layer with a standard deviation of sqrt(n * p * (1 - p)) =
// sqrt(3 701 600 * 1/4032 * 4031/4032) = 37.6
// 6 201 600 / 4032 = 1538.1 eligibilities in a layer with a standard deviation of sqrt(n * p * (1 - p)) =
// sqrt(3 701 600 * 1/4032 * 4031/4032) = 39.2
//
// This means that we can expect a maximum of 1414.1 + 6*37.6 = 1639.7 eligibilities in a layer with
// This means that we can expect a maximum of 1538.1 + 6*39.2 = 1773.4 eligibilities in a layer with
// > 99.9997% probability.
Proposals []types.ProposalID `scale:"max=1650"`
Proposals []types.ProposalID `scale:"max=1775"`
// 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.

11 changes: 3 additions & 8 deletions p2p/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ func NewServerError(msg string) *ServerError {
return &ServerError{msg: msg}
}

func (*ServerError) Is(target error) bool {
_, ok := target.(*ServerError)
return ok
}

func (err *ServerError) Error() string {
return fmt.Sprintf("peer error: %s", err.msg)
}
Expand All @@ -142,7 +137,7 @@ func (err *ServerError) Error() string {
// Response is a server response.
type Response struct {
// keep in line with limit of ResponseMessage.Data in `fetch/wire_types.go`
Data []byte `scale:"max=183500800"` // 120 MiB > 3.5 mio ATX * 32 bytes per ID
Data []byte `scale:"max=209715200"` // 200 MiB > 6.0 mio ATX * 32 bytes per ID
Error string `scale:"max=1024"` // TODO(mafa): make error code instead of string
}

Expand Down Expand Up @@ -366,11 +361,11 @@ func (s *Server) StreamRequest(
)
}

serverError := errors.Is(err, &ServerError{})
var srvError *ServerError
took := time.Since(start).Seconds()
switch {
case s.metrics == nil:
case serverError:
case errors.As(err, &srvError):
s.metrics.clientServerError.Inc()
s.metrics.clientLatency.Observe(took)
case err != nil:
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.

3 changes: 2 additions & 1 deletion p2p/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func TestServer(t *testing.T) {
t.Run("ReceiveError", func(t *testing.T) {
n := srv1.NumAcceptedRequests()
_, err := client.Request(ctx, mesh.Hosts()[2].ID(), request)
require.ErrorIs(t, err, &ServerError{})
var srvErr *ServerError
require.ErrorAs(t, err, &srvErr)
require.ErrorContains(t, err, "peer error")
require.ErrorContains(t, err, testErr.Error())
require.Equal(t, n+1, srv1.NumAcceptedRequests())
Expand Down