Skip to content
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

lang: remove the state and interface attributes #2285

Merged
merged 26 commits into from Dec 22, 2022

Conversation

Aursen
Copy link
Contributor

@Aursen Aursen commented Nov 25, 2022

TODO:

  • Fix the client
  • Fix all examples
  • Check unnecessary code snippets
  • Remove interface attribute
  • Clean the doc

@vercel
Copy link

vercel bot commented Nov 25, 2022

@Aursen is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@Aursen
Copy link
Contributor Author

Aursen commented Nov 25, 2022

@Henry-E for the basic 4 example, do I use init-if-needed with a pda?

@Henry-E
Copy link
Contributor

Henry-E commented Nov 25, 2022

personally i would prefer to not include init_if_needed in any of the basic examples

@Aursen Aursen changed the title WIP: Remove the state attribute WIP: Remove the state and interface of the attributes Dec 9, 2022
@Aursen
Copy link
Contributor Author

Aursen commented Dec 21, 2022

  • Examples:
    • deleted the interface
    • deleted misc2
    • disabled lockup
    • updated misc to work stateless
    • updated basic4 to work stateless
    • updated version of tic-tac-toe anchor
  • Client:
    • removed state and RequestNamespace
    • updated instructions function to remove unused account metas
  • Lang:
    • removed cpi_state and state accounts
    • removed state count generation (i.e.: codegen/program/accounts.rs)
    • removed state and ctor sighash and ctor args generation (ie: codegen/program/common.rs)
    • suppression of the generation of state_cpi_methods (ie : codegen/program/cpi.rs)
    • removed the generation of ctor, state, interface arms (ie : codegen/program/dispatch.rs)
    • removed ctor, state and interface handlers (ie : codegen/program/handlers.rs)
    • removed ctor and state variants in instructions (ie : codegen/program/instruction.rs)
    • removed the state in the idl
    • removed state parser
  • TS:
    • delete state.ts
    • update borsh (remove encodeState, state method map and update parseIxLayout)

@Aursen Aursen changed the title WIP: Remove the state and interface of the attributes lang: remove the state and interface attributes Dec 21, 2022
@Henry-E Henry-E self-requested a review December 21, 2022 11:25
lang/src/lib.rs Outdated
// Calculates the size of an account, which may be larger than the deserialized
// data in it. This trait is currently only used for `#[state]` accounts.
// data in it. This trait is currently unused.
// TODO: Uses it maybe to calculate the size of an account.
Copy link
Contributor

Choose a reason for hiding this comment

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

minor english maybe use it calculate ...

The key with making a trait that automatically calculates size is that it doesn't have a high runtime cost. It really ought to be closer to a constant, although need to account for variable sized elements.

@Henry-E
Copy link
Contributor

Henry-E commented Dec 21, 2022

Looks really nice, thanks for such a great effort!

Some loose thoughts,

  • is it possible to keep the interface trait without state? Maybe we can just remove the interface test example which uses state but leave the interface attribute in the code just for people that really want it and mark it as deprecated.
  • references to the account types ProgramState and CpiState and also the constraint state should probably also be removed from the syn/.
    • If you want, I can do this part but I would need you to first rebase your PR to the current master so that I can safely pull and update it (the rebasing part is actually the most time consuming/annoying, probably more annoying than finding and deleting the account + constraint references)

Another question as well to check before we merge for my own sanity

  • In the non-example parts of the anchor code, e.g. lang/ was state relatively self contained or where there any places where you had to modify the workings of any traits/functions/impls in order to get it to compile?

@Aursen
Copy link
Contributor Author

Aursen commented Dec 21, 2022

Concerning the state and the interface the two are extremely linked because the interface does not call the global function in the dispatcher. And the interface in the idl was in the state category, so I concluded that if the program had no state, the interface was not usable. It is better for this kind of practice to make a client from the idl as anchor-gen or mannually.

Program state is used by the idl internally, from what I remember.

For the account size, I may delete it because I'm going to do a derive macro for it.

Then for all that is constraint it is true that I did not touch it, because of memories there is no constraint related to the state.

No everything is relatively contained concerning the state, I just had to modify a TS function for the instructions. And the same in the client.

And for the rest I will do it

@Aursen Aursen marked this pull request as ready for review December 21, 2022 16:32
@Henry-E
Copy link
Contributor

Henry-E commented Dec 21, 2022

Cool, I will play around with this locally tomorrow morning and try to merge.

@Henry-E Henry-E merged commit 38bbb21 into coral-xyz:master Dec 22, 2022
@Henry-E
Copy link
Contributor

Henry-E commented Dec 22, 2022

Thanks for all your hard work on this!

@Aursen Aursen deleted the clean-accounts branch December 23, 2022 11:42
dovahcrow pushed a commit to dovahcrow/anchor that referenced this pull request Jan 13, 2023
michaeldjeffrey added a commit to helium/oracles that referenced this pull request Mar 11, 2024
maplant added a commit to helium/oracles that referenced this pull request Apr 9, 2024
* remove unused structopt

* cleanup anchor-lang dep

anchor-lang is re-exported through anchor-client.
and was unused in some projects.

* update anchor-lang 0.26 -> 0.27

RequestNamespace was removed
coral-xyz/anchor#2285

* update anchor-lang 0.27 -> 0.28

We don't use async feature in achor-lang, which means we get the blocking version of RequestBuilder. It needs a handle to the runtime to block with.

also ran `cargo update -p helium-anchor-gen` to get generated types to implement updated traits.

* update anchor-lang 0.28 -> 0.29

no code changes required

---------

Co-authored-by: Matthew Plant <maplant@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants