Skip to content

feat: emit compact PiecesAddedV2 events - #300

Open
Kubuxu wants to merge 3 commits into
mainfrom
issue-295-compact-pieces-added
Open

feat: emit compact PiecesAddedV2 events#300
Kubuxu wants to merge 3 commits into
mainfrom
issue-295-compact-pieces-added

Conversation

@Kubuxu

@Kubuxu Kubuxu commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Closes #295

Summary

Adds a compact, ABI-decodable event for piece additions:

struct PackedCid {
    bytes32 header;
    bytes32 root;
}

event PiecesAddedV2(
    uint256 indexed setId,
    uint256 firstPieceId,
    PackedCid[] pieceCids
);

Piece IDs derive from firstPieceId + arrayIndex. CIDs are reconstructed by stripping the leading zero padding from header and appending root.

Events are limited to 125 pieces. Larger calls emit multiple events with adjusted firstPieceId values.

BREAKING (!!): event consumers must upgrade

The legacy PiecesAdded event remains in the contract ABI but is no longer emitted. New additions emit only PiecesAddedV2.

Indexers and all other event consumers must support PiecesAddedV2 before the contract rollout.

Historical PiecesAdded logs remain decodable. The addPieces function ABI and listener callbacks are unchanged.

Size

Encoding 64 pieces Maximum pieces/event
Existing PiecesAdded 12,480 bytes 41
PiecesAddedV2 4,256 bytes 125

A 125-piece event consumes 8,160 bytes, below FEVM’s 8,192-byte limit.

Gas

Measured with this PR applied, using the prior batch sizes of 41 pieces with one metadata pair and 61 pieces without metadata as baselines.

Metadata per piece Starting pieces Prior batch: gas/piece Largest batch: gas/piece Change
One pair 0 41: 71.003M 135: 59.633M −16.0%
One pair 1,024 41: 71.664M 135: 59.961M −16.3%
None 0 61: 10.063M 225: 6.505M −35.4%
None 1,024 61: 10.455M 225: 6.877M −34.2%

Dependency

Relies on #292 enforcing canonical PieceCIDv2 encodings so splitting a CID into header and root preserves it exactly.

Validation

  • Packed CID and 125/126-piece batching coverage
  • Full suite: 224 passed
  • Contract size checks pass

@FilOzzy FilOzzy added this to FOC Aug 14, 2026
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Aug 14, 2026
@Kubuxu
Kubuxu requested a review from rvagg August 14, 2026 23:08
@Kubuxu Kubuxu linked an issue Aug 14, 2026 that may be closed by this pull request
@Kubuxu Kubuxu added this to the August Contract Release milestone Aug 14, 2026
@Kubuxu Kubuxu self-assigned this Aug 14, 2026
@Kubuxu Kubuxu moved this from 📌 Triage to ⌨️ In Progress in FOC Aug 14, 2026
Base automatically changed from feat/optimized-add-pieces-2 to main August 14, 2026 23:42
Kubuxu added 3 commits August 15, 2026 01:44
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
@Kubuxu Kubuxu moved this from ⌨️ In Progress to 🔎 Awaiting review in FOC Aug 14, 2026
@Kubuxu
Kubuxu force-pushed the issue-295-compact-pieces-added branch from 4f3fe9e to b043537 Compare August 14, 2026 23:47
@Kubuxu
Kubuxu marked this pull request as ready for review August 14, 2026 23:48
@Kubuxu
Kubuxu requested a review from wjmelements as a code owner August 14, 2026 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Awaiting review
Status: No status

Development

Successfully merging this pull request may close these issues.

Proposal: compact PiecesAddedV2 event

2 participants