Skip to content

feat: add official bun binding#9

Merged
twoeths merged 49 commits intomainfrom
te/consume_bun-ffi-z
May 19, 2025
Merged

feat: add official bun binding#9
twoeths merged 49 commits intomainfrom
te/consume_bun-ffi-z

Conversation

@twoeths
Copy link
Copy Markdown
Collaborator

@twoeths twoeths commented May 9, 2025

Motivation

Description

  • add home "bun" folder
  • compile zig in bun "package.json" by: "bun run build"
  • TBD

TODOs

Comment thread bun/package.json Outdated
@github-actions
Copy link
Copy Markdown

github-actions bot commented May 12, 2025

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 993e407 Previous: null Ratio
JS - unshuffleList - 16384 indices 922.25 us/op
Zig - unshuffleList - 16384 indices 608.12 us/op
JS - unshuffleList - 250000 indices 13.312 ms/op
Zig - unshuffleList - 250000 indices 8.9923 ms/op
JS - unshuffleList - 1000000 indices 52.861 ms/op
Zig - unshuffleList - 1000000 indices 35.853 ms/op
get values - 1000 335.00 ns/op
get values - naive - 1000 499.00 ns/op
set values - 1000 299.00 ns/op
set values - naive - 1000 613.00 ns/op
get values - 1000000 926.00 ns/op
get values - naive - 1000000 1.6170 us/op
set values - 1000000 930.00 ns/op
set values - naive - 1000000 2.1100 us/op
JS - computeSyncCommitteeIndices - 16384 indices 296.19 ms/op
Zig - computeSyncCommitteeIndices - 16384 indices 4.0516 ms/op
JS - computeSyncCommitteeIndices - 250000 indices 286.99 ms/op
Zig - computeSyncCommitteeIndices - 250000 indices 16.819 ms/op
JS - computeSyncCommitteeIndices - 1000000 indices 303.88 ms/op
Zig - computeSyncCommitteeIndices - 1000000 indices 31.108 ms/op

by benchmarkbot/action

Comment thread bun/src/committeeIndices.ts Outdated
Comment thread bun/src/binding.ts Outdated
Comment thread bun/src/binding.ts Outdated
};

// Load the compiled Zig shared library
const lib = await openLibrary(path.resolve("../bun"), fns);
Copy link
Copy Markdown
Member

@wemeetagain wemeetagain May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the path.resolve("../bun") is strange here. I don't think it will work when the cwd is another consumer of this package.

maybe better is path.join(import.meta.dirname, '..')

(I'm assuming the dylib would be located at something like bun/libstate-transition-utils.dylib)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified it to const lib = await openLibrary(path.resolve("."), fns); please have a look at the latest change

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@twoeths check this comment. Try something with import.meta.dirname here instead of path.resolve/cwd

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, just switched to "import.meta.dirname"

@twoeths twoeths force-pushed the te/consume_bun-ffi-z branch from 3c6482f to 6c060fc Compare May 16, 2025 04:09
@twoeths twoeths force-pushed the te/consume_bun-ffi-z branch from 2bc92dd to f28257c Compare May 17, 2025 05:36
@twoeths twoeths force-pushed the te/consume_bun-ffi-z branch from 714a29b to d848013 Compare May 17, 2025 08:14
@twoeths
Copy link
Copy Markdown
Collaborator Author

twoeths commented May 18, 2025

the publish step was tested successfully with -dry-run flag, this is the generated targetPackages
targetPackages.zip

@twoeths twoeths marked this pull request as ready for review May 18, 2025 08:07
@twoeths twoeths requested a review from wemeetagain May 18, 2025 08:08
Copy link
Copy Markdown
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@twoeths twoeths merged commit 284c90e into main May 19, 2025
14 checks passed
wemeetagain pushed a commit that referenced this pull request Nov 12, 2025
lodekeeper-z added a commit to lodekeeper-z/lodestar-z that referenced this pull request Mar 28, 2026
…, outbound API

## Gossip → Beacon Node pipeline (issue ChainSafe#9)
- Add on_validated_message callback to EthGossipAdapter
  (setMessageHandler(ctx, callback) — called for every ACCEPT-validated message)
- validateDecoded() now delivers accepted messages to the BN processing pipeline
- Beacon node wires this to enqueue blocks/attestations for import

## Gossipsub ACCEPT/REJECT feedback (issue ChainSafe#11)
- handleMessage() now accepts from_peer: ?[]const u8 parameter
- For REJECT outcomes, calls gossipsub.router.recordInvalidMessage(peer, topic)
  which increments the P4 (invalid message delivery) score counter
- pollEvents() passes msg.from to handleMessage()
- Gossipsub can now penalize peers who send invalid messages

## Outbound request API (issue ChainSafe#10)
- Add decodeResponseChunks() + freeDecodedResponseChunks() to req_resp_encoding.zig
  to parse a complete response wire buffer into []DecodedResponseChunk
- handleOutbound() now decodes the response and calls ctx.on_response callback
  if present, passing parsed chunks to the caller (sync service, etc.)
- Export new types from root.zig (DecodedResponseChunk, decodeResponseChunks,
  freeDecodedResponseChunks)

🤖 Generated with AI assistance
lodekeeper-z added a commit to lodekeeper-z/lodestar-z that referenced this pull request Mar 28, 2026
Medium issue ChainSafe#9 from REVIEW.md: two overlapping unknown-block mechanisms
existed without clear documentation of which to use when.

Add detailed module-level doc to unknown_block.zig explaining:
- UnknownBlockSync: triggered by gossip blocks with unknown parent;
  stores full block bytes; resolves by parent chain walk + recursive import
- UnknownChainSync: triggered by unknown roots from attestations/status;
  no block bytes, only roots; resolves by backwards header chain to
  fork choice, then triggers forward range sync
- The key distinction: UnknownBlockSync has the block, UnknownChainSync
  does not. They are complementary, not redundant.

🤖 Generated with AI assistance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants