Skip to content

Commit

Permalink
Limit size of ActiveSet in ballot encoding (#5965)
Browse files Browse the repository at this point in the history
## Motivation

Don't allow a ballot to contain `ActiveSet` `ATXID`s. They are immediately discarded after receiving them but other nodes can still send ballots with a list of ATXIDs attached that is unnecessarily downloaded and decoded before being deleted.
  • Loading branch information
fasmat committed May 21, 2024
1 parent 25222c1 commit d27edfa
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 35 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ Upgrading to this version requires going through v1.5.x first. Removed migration
Ensure that your key file in `data/identities` is named `local.key` if you run a supervised node or with the change
the node will not start.

* [#5965](https://github.com/spacemeshos/go-spacemesh/pull/5965) Start considering ballots that still contain the
deprecated inlined activeset as invalid. go-spacemesh references the active set via hash since v1.3.0, and has been
pruning the data of old ballots since then as well.

## Release v1.5.4

### Improvements

* [#5963](https://github.com/spacemeshos/go-spacemesh/pull/5963) Increase supported number of ATXs to 5.5 Mio.

## Release v1.5.3

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion common/types/ballot.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type Ballot struct {
// only present in smesher's first ballot of the epoch
// this field isn't actually used any more (replaced by InnerBallot.EpochData)
// TODO (mafa): remove this field in Ballot v2
ActiveSet []ATXID `scale:"max=3500000"`
ActiveSet []ATXID `scale:"max=1"`

// the following fields are kept private and from being serialized
ballotID BallotID
Expand Down
4 changes: 2 additions & 2 deletions common/types/ballot_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 proposals/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func (h *Handler) processBallot(ctx context.Context, logger log.Log, b *types.Ba
if err != nil {
return nil, err
}
b.ActiveSet = nil
b.ActiveSet = nil // the active set is not needed anymore

t1 := time.Now()
proof, err := h.mesh.AddBallot(ctx, b)
Expand Down
11 changes: 0 additions & 11 deletions sql/ballots/ballots.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ func Has(db sql.Executor, id types.BallotID) (bool, error) {
return rows > 0, nil
}

func UpdateBlob(db sql.Executor, bid types.BallotID, blob []byte) error {
if _, err := db.Exec(`update ballots set ballot = ?2 where id = ?1;`,
func(stmt *sql.Statement) {
stmt.BindBytes(1, bid.Bytes())
stmt.BindBytes(2, blob[:])
}, nil); err != nil {
return fmt.Errorf("update blob %s: %w", bid.String(), err)
}
return nil
}

// GetBlobSizes returns the sizes of the blobs corresponding to ballots with specified
// ids. For non-existent ballots, the corresponding items are set to -1.
func GetBlobSizes(db sql.Executor, ids [][]byte) (sizes []int, err error) {
Expand Down
20 changes: 0 additions & 20 deletions sql/ballots/ballots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,6 @@ func TestAdd(t *testing.T) {
require.True(t, stored.IsMalicious())
}

func TestUpdateBlob(t *testing.T) {
db := sql.InMemory()
nodeID := types.RandomNodeID()
ballot := types.NewExistingBallot(types.BallotID{1}, types.RandomEdSignature(), nodeID, types.LayerID(0))
ballot.EpochData = &types.EpochData{
ActiveSetHash: types.RandomHash(),
}
ballot.ActiveSet = types.RandomActiveSet(199)
require.NoError(t, Add(db, &ballot))
got, err := Get(db, types.BallotID{1})
require.NoError(t, err)
require.Equal(t, ballot, *got)

ballot.ActiveSet = nil
require.NoError(t, UpdateBlob(db, types.BallotID{1}, codec.MustEncode(&ballot)))
got, err = Get(db, types.BallotID{1})
require.NoError(t, err)
require.Empty(t, got.ActiveSet)
}

func TestHas(t *testing.T) {
db := sql.InMemory()
ballot := types.NewExistingBallot(types.BallotID{1}, types.EmptyEdSignature, types.EmptyNodeID, types.LayerID(0))
Expand Down

0 comments on commit d27edfa

Please sign in to comment.