Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@febo
Copy link
Contributor

@febo febo commented Oct 17, 2025

Problem

Currently, Pinocchio uses its own zero-copy representation of Account and AccountInfo, which saves CUs on entrypoint definitions. By using the same name to represent an AccountInfo, it is cumbersome to write code that uses both types at the same time.

These types are useful for other entrypoint definitions and they will have greater visibility if they are added to the SDK.

Solution

Add a new solana-account-view crate with two new types: Account and AccountView. The Account type has the same memory layout than the serialized account data provided by the runtime to a program entrypoint. Therefore, it can be used to represent the account data in a zero-copy fashion. The AccountView is the equivalent of an AccountInfo, wrapping an Account and providing safe borrow methods.

Note: This PR moves the code from pinocchio repository maintaining history.

febo and others added 30 commits October 18, 2025 00:43
* Use macro rules

* Update directory structure
* Add map and filter_map to Ref and RefMut

* Add unit tests

* Apply suggestions
* Add bit flag

* Remove declarative macro
* Add unchecked helper

* Fix lint

* Add inline

* Rename to checked

* Cosmetics

* Fix sol log params
* Added close and based_close

* added docs comments + wrapped up and tested both function

* cargo clippy and fmt

* added the new close and changed the name for

* fixed and tested after comments
* Fixed compiler bitching about realloc

* Added a better alterantive to the black_box

* Fixed latest comments

* deleted some line after the refactor
* [wip]: Add new scripts

* [wip]: Use matric strategy

* [wip]: Fix members parsing

* [wip]: Add CI env variables

* [wip]: Remove nothrow

* [wip]: Filter changes

* [wip]: Add audit step

* [wip]: Add semver checks

* [wip]: Refactor publish workflow

* [wip]: Refactor

* [wip]: Fix commands

* Fix formatting

* Remove detect changes step

* Review comments

* Fix lint comments

* Expand crate comment

* Ignore crate comment tests

* Add missing docs

* More missing docs

* Add missing release component

* Pin cargo-release version

* Fix merge

* Review comments
* [wip]: Add new scripts

* [wip]: Add CI env variables

* [wip]: Remove nothrow

* [wip]: Filter changes

* [wip]: Add audit step

* [wip]: Add semver checks

* [wip]: Refactor publish workflow

* [wip]: Refactor

* [wip]: Fix commands

* Fix formatting

* Remove detect changes step

* Add check methods

* Use check variant on close

* Fix merge
* [wip]: Address review comments

* [wip]: Fix pointer reference

* [wip]: Add logger buffer size tests

* Remove unused

* More logger tests

* Rename program to cpi

* Remove dynamic allocation

* Fixed signed tests

* Fix review comments

* Fix unsigned test case

* Add is_owner_by helper
* Improve fallback and docs

* Add borrow state check

* Add inline

* Review comments

* Revert doc link merge change
* Update doc comments

* Update sdk/pinocchio/src/account_info.rs

Co-authored-by: Jon C <[email protected]>

* Update sdk/pinocchio/src/account_info.rs

Co-authored-by: Jon C <[email protected]>

---------

Co-authored-by: Jon C <[email protected]>
* Add miri step

* Fix miri issues

* Install miri component
* Add resize

* Deprecate realloc
* Fix review comments

* Revert offset increment change

* Add invoke instruction helper

* Typos

* Remove new helpers

* Remove unused

* Address review comments

* Tweak inline attributes

* Use invoke signed unchecked

* Refactor inline

* Renamed to with_bounds

* Update docs

* Revert change

* Add constant length check

* Simplify accounts deserialization

* Invert borrow state logic

* Use expr instead

* Add missing import

* Address review comments

* Revert unnecessary repr

* Fix rebase

* Tweak docs

* Fix doc reference

* Fix miri errors

* More review comments
* Simplify realloc logic

* Address review comments
* Fix assign unsoundness

* Remove unsafe
* Add invoke instruction helper

* Typos

* Remove new helpers

* Remove unused

* Address review comments

* Tweak inline attributes

* Use invoke signed unchecked

* Refactor inline

* Renamed to with_bounds

* Update docs

* Revert change

* Add constant length check

* Add spellcheck step

* Tweak action

* Fix typos

* More fixes

* Yet more fixes

* Fixes

* Add j1 option

* More and more fixes

* Add missing acronym

* Fix merge

* Fix spelling

* Fix spelling
* Add comments on constants

* Improve offset comments

* Add bitmask to dictionary

* Renamed to field_at_offset
Ignore zero_init parameter
stegaBOB and others added 17 commits October 18, 2025 00:43
* make data_ptr public

* Update sdk/pinocchio/src/account_info.rs

Co-authored-by: Fernando Otero <[email protected]>

* add some tests for data ptr

* Fix spelling

---------

Co-authored-by: Fernando Otero <[email protected]>
* Add try_maps on AccountInfo Ref/RefMut

* update tests and api for try map ref
* Add pubkey_eq helper

* Fix typo

* Update pubkey comparison

* Add proptest

* Add unlikely

* Replace proptest
@febo febo force-pushed the solana-account-view branch from 2846515 to c73db50 Compare October 18, 2025 00:33
#[repr(C)]
#[cfg_attr(feature = "copy", derive(Copy))]
#[derive(Clone, Default)]
pub struct Account {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is already a public Account type defined in solana-account. We could name this one as RuntimeAccount or another name to avoid the name clash. It is not really used directly in programs, only the entrypoint uses it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A new name might be better to be safe, especially if it won't really be consumed from the outside. RuntimeAccount is pretty good, I also came up with EntrypointAccount or RuntimeSerializedAccount or OnchainAccount

@febo febo marked this pull request as ready for review October 18, 2025 09:19
@febo febo requested a review from joncinque October 18, 2025 09:19
joncinque
joncinque previously approved these changes Oct 21, 2025
Copy link
Collaborator

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Just looked at the crate definition and your comment, but it looks good! Feel free to do the rename or not

#[repr(C)]
#[cfg_attr(feature = "copy", derive(Copy))]
#[derive(Clone, Default)]
pub struct Account {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A new name might be better to be safe, especially if it won't really be consumed from the outside. RuntimeAccount is pretty good, I also came up with EntrypointAccount or RuntimeSerializedAccount or OnchainAccount

@febo febo force-pushed the solana-account-view branch from b9cc55b to e7ba5b2 Compare October 22, 2025 22:58
@febo
Copy link
Contributor Author

febo commented Oct 22, 2025

Just looked at the crate definition and your comment, but it looks good! Feel free to do the rename or not

Renamed to RuntimeAccount, which matches the crate description.

@febo febo requested a review from joncinque October 22, 2025 23:38
Copy link
Collaborator

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks great!

@febo febo merged commit c99a842 into anza-xyz:master Oct 23, 2025
26 checks passed
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.

7 participants