-
Notifications
You must be signed in to change notification settings - Fork 16
✨ System directly updates components #197
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
base: main
Are you sure you want to change the base?
Conversation
ea29cb2
to
3aee912
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
58 files reviewed, 10 comments
4df93f7
to
0fee5dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a fundamental architectural redesign of the Bolt ECS framework to address the 1024-byte limitation in component data serialization. The system transitions from a serialization-based approach to an ownership transfer pattern, allowing systems to directly modify components of any size without serialization bottlenecks.
Key changes include:
- Complete overhaul of the execution flow where component programs transfer ownership to system programs via buffer accounts
- Replacement of component data serialization with direct ownership manipulation through new
set_owner
andset_data
instructions - Introduction of buffer PDAs and enhanced CPI authentication for secure ownership transfers
Reviewed Changes
Copilot reviewed 48 out of 61 changed files in this pull request and generated 9 comments.
Show a summary per file
File | Description |
---|---|
scripts/test.sh | Deleted entire test script file |
examples/system-*/src/lib.rs | Updated system execute functions to return Result<()> instead of Result<Components> |
crates/programs/world/src/lib.rs | Major refactor implementing ownership transfer pattern with buffer accounts and new CPI instructions |
crates/programs/bolt-system/src/lib.rs | Added placeholder implementations for set_data and set_owner instructions |
crates/programs/bolt-component/src/lib.rs | Replaced update functions with set_owner and set_data instructions |
crates/bolt-lang/src/account.rs | New BoltAccount wrapper for dynamic ownership validation using const generics |
crates/bolt-lang/attribute/component-deserialize/src/lib.rs | Enhanced component deserialization with proper Anchor discriminator calculation |
clients/typescript/src/world/transactions.ts | Updated client code to include buffer accounts in all apply operations |
clients/csharp/Solana.Unity.Bolt/WorldProgram/World.cs | Added buffer PDA support and updated apply system calls |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @notdanilo for the PR. Overall, I think the implementation is a good idea.
It raises the limit from 1KB total component size per system apply to 10KB per component (limited by buffer creation), which should cover most use cases.
The only issue I see is the increased number of CPIs. To summarize, this was the previous flow:
sequenceDiagram
participant WP as World Program
participant SYS as System
participant COMP as Component
WP->>SYS: execute_system()
SYS-->>WP: return_data
WP->>COMP: set_component_data(return_data)
New flow:
sequenceDiagram
participant WP as World Program
participant COMP as Component
participant SYS as System
Note over WP: Copy component data to buffer
WP->>COMP: set_owner(system)
WP->>SYS: set_data(buffer)
WP->>SYS: execute()
Note over WP: Copy component data to buffer
WP->>SYS: set_owner(component)
WP->>COMP: set_data(buffer)
This results in 4×N + 1 CPIs (where N is the number of components) vs. N + 1 CPIs in the previous flow.
We should report a table of CU consumption with varying numbers of components (e.g., 1 to 5) to understand whether the CU increase is acceptable.
The Pinocchio reimplementation of the world program would improve this, but we should also consider alternatives if consumption increases too much, such as:
- Having components directly owned by the world program
- Using an account as a scratch pad to replace the return_data
0f83bd9
to
50355ed
Compare
50355ed
to
598678a
Compare
520e6e5
to
3645bcb
Compare
d806260
to
b0d65fa
Compare
Problem
Systems serializes and returns the components data with a limit of 1024kb so the component program can take the data and write it back.
Solution
Change the whole execution logic.
Breaking changes:
CU report:
Small bar is CPI cost
Big bar is total cost
Previous
Using Anchor CPI code
Using Solana CPI code
Greptile Summary
This PR implements a fundamental architectural redesign of the Bolt ECS framework to eliminate a critical 1024-byte limitation in component data serialization. Previously, systems would serialize component data and return it to component programs for storage, creating both size constraints and performance bottlenecks. The new execution model implements an ownership transfer pattern that allows systems to directly modify components of any size.
The core workflow changes from data serialization to ownership transfer: (1) Component programs transfer ownership of component accounts to system programs via a Buffer account, (2) System programs execute and directly modify component data in-place, (3) System programs return ownership back to component programs, and (4) World programs validate that ownership was properly restored. This eliminates the serialization step entirely while maintaining the ECS paradigm.
Key architectural changes include:
execute
functions now returnResult<()>
instead ofResult<Components>
, removing the serialization requirementset_owner
andset_data
instructions for ownership manipulation and data copying from buffer accountsFindCpiAuthPda()
for ownership transfer authorizationThe implementation spans multiple language clients (TypeScript, C#) and removes multi-component apply instructions (apply2-apply5) in favor of the new unified ownership-based approach. The BoltAccount wrapper enables dynamic ownership validation during deserialization using const generics. While this change addresses the size limitation and improves performance, it requires comprehensive client code updates to include Buffer accounts in transactions.
Confidence score: 2/5
crates/programs/bolt-system/src/lib.rs
,crates/programs/bolt-component/src/lib.rs
, andclients/csharp/Solana.Unity.Bolt/WorldProgram/World.cs
which contain empty implementations and serious bugs