Skip to content

feat: add support of address-lookup-table program #94

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sonicfromnewyoke
Copy link
Contributor

No description provided.

// - [0]: Instruction discriminator (1 byte, u8) (2 for Extend)

// LOOKUP_TABLE_MAX_ADDRESSES == u8::MAX + 1.
let mut instruction_data = [0; 8196]; // TODO: huge for stack, maybe forget about no_std and use vector
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@febo What do you think about such a huge array initialization?
Max addresses to extend is 256 x 32 + 4 for discriminator.
Otherwise I can use Vec<Pubkey>, as it's done in the original program, but we lose no_std for this.

Maybe you have other, better approaches to tackle it? Maybe use features and make 2 realizations for std and no_std ways?

Copy link
Contributor

Choose a reason for hiding this comment

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

Vec is just a wrapper for the allocation. both alloc::boxed::Box or alloc::alloc::alloc would allocate on the heap.

Copy link
Collaborator

Choose a reason for hiding this comment

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

8196 won't fit on the stack, so it needs to be less than 4096 (a bit less than that since there are other things that will go on the stack). Perhaps it would be easier if we define a trait Addresses that represents the instruction data in this case. Then we can have no_std and std implementations for it.

We can use a alloc::vec::Vec for the std variant.

// - [0]: Instruction discriminator (1 byte, u8) (2 for Extend)

// LOOKUP_TABLE_MAX_ADDRESSES == u8::MAX + 1.
let mut instruction_data = [0; 8196]; // TODO: huge for stack, maybe forget about no_std and use vector
Copy link
Contributor

Choose a reason for hiding this comment

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

Vec is just a wrapper for the allocation. both alloc::boxed::Box or alloc::alloc::alloc would allocate on the heap.

// Instruction data:
// - [0]: Instruction discriminator (1 byte, u8) (4 for Close)

let instruction_data = [4u8];
Copy link
Contributor

Choose a reason for hiding this comment

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

the size is 4 bytes

// - [0..4 ]: Instruction discriminator (1 byte, u8) (0 for Create)
// - [4..12]: Recent Slot
// - [12 ]: bump seed
let mut instruction_data = [0; 13];
Copy link
Contributor

Choose a reason for hiding this comment

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

use MaybeUninit to reduce unnecessary zeroed-out

// Instruction data:
// - [0]: Instruction discriminator (1 byte, u8) (3 for Deactivate)

let instruction_data = [3u8];
Copy link
Contributor

Choose a reason for hiding this comment

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

size is 4 bytes

// Instruction data:
// - [0]: Instruction discriminator (1 byte, u8) (1 for Freeze)

let instruction_data = [1u8];
Copy link
Contributor

Choose a reason for hiding this comment

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

size is 4 bytes

Copy link
Collaborator

@febo febo left a comment

Choose a reason for hiding this comment

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

This is a native program, so instruction discriminators have 4 bytes.

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.

3 participants