-
Notifications
You must be signed in to change notification settings - Fork 5
Refactor serializer in Serviceability #2528
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
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 pull request refactors the Solana program to consolidate account serialization and management logic. The primary focus is removing legacy helper functions and introducing a new serializer module with standardized helpers (try_acc_create, try_acc_write, try_acc_close) for account operations. Additionally, comprehensive instruction implementation guidelines are added, and unused code is removed to improve maintainability.
- Introduced a new
serializermodule with unified account creation, writing, and closing helpers - Removed legacy
AccountTypeInfotrait implementations and replacedsize()calls withborsh::object_length() - Added
INSTRUCTION_GUIDELINES.mddocumenting best practices for implementing new instructions
Reviewed changes
Copilot reviewed 106 out of 107 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/serializer.rs |
New module providing try_acc_create, try_acc_write, and try_acc_close helper functions |
src/helper.rs |
Removed legacy account management functions, retained BGP community assignment |
src/accounts.rs |
Deleted entire file containing deprecated account management traits and functions |
src/globalstate.rs |
Removed globalstate_write and reallocation helpers, kept only minimal read logic |
src/state/*.rs |
Removed AccountTypeInfo implementations and try_serialize methods from state structs |
src/processors/**/*.rs |
Updated all processors to use new serializer helpers instead of legacy functions |
tests/*.rs |
Updated tests to use borsh::object_length() instead of .size() method |
INSTRUCTION_GUIDELINES.md |
Added comprehensive documentation for instruction implementation patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...act/programs/doublezero-telemetry/src/processors/telemetry/write_internet_latency_samples.rs
Outdated
Show resolved
Hide resolved
...tract/programs/doublezero-telemetry/src/processors/telemetry/write_device_latency_samples.rs
Outdated
Show resolved
Hide resolved
smartcontract/programs/doublezero-serviceability/src/serializer.rs
Outdated
Show resolved
Hide resolved
smartcontract/programs/doublezero-serviceability/src/state/programconfig.rs
Outdated
Show resolved
Hide resolved
smartcontract/programs/doublezero-serviceability/src/state/programconfig.rs
Outdated
Show resolved
Hide resolved
smartcontract/programs/doublezero-serviceability/src/globalstate.rs
Outdated
Show resolved
Hide resolved
b8c2d51 to
1b1636f
Compare
0f973d2 to
c677b9e
Compare
…serialize` function - Introduced a new `try_serialize` function in `serialize.rs` to handle serialization and validation for various account types. - Updated processors in the `exchange`, `link`, `location`, `multicastgroup`, and `user` modules to replace direct account writing with the new `try_serialize` function. - Ensured that all relevant structs implement the `Validate` trait to enforce validation before serialization. - Removed redundant helper functions and streamlined the code for better maintainability and readability. - Refactor account type handling and serialization across multiple modules - Removed the AccountTypeInfo trait implementation from Device, Exchange, Link, Location, MulticastGroup, User, and other related structs. - Replaced size calculations with borsh::object_length for more accurate serialization size checks. - Updated tests to reflect changes in size validation using borsh::object_length. - Consolidated account creation and writing logic into a new serializer module for better code organization. - Added comprehensive instruction implementation guidelines to ensure consistency and security in new instruction development. - Introduced a new foundation address file for better address management. - Refactor import statements for improved readability and consistency - changelog: add instruction guidelines and enforce best practices for onchain programs style: format imports and remove unnecessary blank line in initialize.rs refactor: update test command and enhance error handling for foundation allowlist fix: remove unnecessary whitespace in validation logic for GlobalState refactor: simplify assertions for writable accounts in initialize_global_state
5211a10 to
96a4fc6
Compare
This pull request makes significant improvements to the Solana program's structure, documentation, and code quality. The most important changes are the addition of comprehensive instruction implementation guidelines, major refactoring and removal of legacy account management code, and the consolidation of account serialization/creation logic into a new
serializermodule. Several processors and helpers are updated to use the new serialization helpers, and some redundant modules are removed for clarity.Documentation and Guidelines:
INSTRUCTION_GUIDELINES.mdfile to document best practices and required steps for implementing new instructions, including account parsing, validation, state mutation, error handling, and a checklist.Codebase Refactoring and Cleanup:
Account Management and Serialization:
accounts.rsandhelper.rs, such as account creation, writing, and closing logic, in favor of new, consolidated helpers. [1] [2]serializermodule for account serialization, writing, and closing, and updated relevant processors (e.g., access pass) to use these new helpers. [1] [2] [3] [4] [5]Module and Import Organization:
lib.rs, removing unused or redundant modules and ensuring only necessary modules are public.doublezero_foundationaddress module for clarity.Global State Management:
globalstate.rs, streamlining state management to rely on new helpers.These changes collectively improve maintainability, enforce best practices, and modernize the codebase for future development.
Testing Verification