From 844a303b5b7b0edc4f73ee81b64cf8d108e924a8 Mon Sep 17 00:00:00 2001 From: Stanislaw Drozd Date: Thu, 15 Jul 2021 13:22:50 +0000 Subject: [PATCH] Revert "Solitaire: Extend Peel to support CPI re-wrapping" Revert submission 693 Reason for revert: Moving away from CPI abstraction Reverted Changes: I8c252e137:bridge, token_bridge: Use Many I6a721e8a8:Solitaire: Add an explicit Many type for nested... Ibdc94b4c6:Solitaire: Serialize CPI accounts as an AccountMet... Iefa59f5d4:Solitaire: Extend Peel to support CPI re-wrapping Change-Id: Iab567aea6dca5be1a7bf7efd4b86e0be05d2753c --- solana/bridge/agent/Cargo.toml | 2 +- solana/bridge/program/src/vaa.rs | 6 +-- solana/solitaire/program/src/lib.rs | 3 -- solana/solitaire/program/src/macros.rs | 4 -- .../solitaire/program/src/processors/peel.rs | 34 ------------- solana/solitaire/rocksalt/src/lib.rs | 48 ++----------------- 6 files changed, 7 insertions(+), 90 deletions(-) diff --git a/solana/bridge/agent/Cargo.toml b/solana/bridge/agent/Cargo.toml index 2316ac26..747bbe9a 100644 --- a/solana/bridge/agent/Cargo.toml +++ b/solana/bridge/agent/Cargo.toml @@ -14,7 +14,7 @@ solana-program = "=1.7.0" solana-sdk = "=1.7.0" solitaire = { path = "../../solitaire/program" } solitaire-client = {path = "../../solitaire/client" } -bridge = { path = "../program", features = ["client"] } +bridge = { path = "../program", features = ["no-entrypoint", "client"] } primitive-types = { version = "0.7.2" } hex = "0.4.2" thiserror = "1.0.20" diff --git a/solana/bridge/program/src/vaa.rs b/solana/bridge/program/src/vaa.rs index ae489349..931657fe 100644 --- a/solana/bridge/program/src/vaa.rs +++ b/solana/bridge/program/src/vaa.rs @@ -17,7 +17,7 @@ use byteorder::{ BigEndian, ReadBytesExt, }; -use solana_program::{instruction::AccountMeta, pubkey::Pubkey}; +use solana_program::pubkey::Pubkey; use solitaire::{ processors::seeded::Seeded, trace, @@ -102,10 +102,6 @@ impl<'a, 'b: 'a, 'c, T: DeserializePayload> Peel<'a, 'b, 'c> for PayloadMessage< fn persist(&self, program_id: &Pubkey) -> Result<()> { Data::persist(&self.0, program_id) } - - fn to_partial_cpi_meta(&self) -> Vec { - Data::to_partial_cpi_meta(&self.0) - } } impl<'b, T: DeserializePayload> Deref for PayloadMessage<'b, T> { diff --git a/solana/solitaire/program/src/lib.rs b/solana/solitaire/program/src/lib.rs index 01a400e7..a4b0b3ae 100644 --- a/solana/solitaire/program/src/lib.rs +++ b/solana/solitaire/program/src/lib.rs @@ -123,7 +123,4 @@ pub trait FromAccounts<'a, 'b: 'a, 'c> { fn from(_: &'a Pubkey, _: &'c mut Iter<'a, AccountInfo<'b>>, _: &'a T) -> Result where Self: Sized; - - /// Converts the accounts back to vector form to facilitate CPI calls. - fn to_cpi_metas(&self) -> Vec; } diff --git a/solana/solitaire/program/src/macros.rs b/solana/solitaire/program/src/macros.rs index 1c7e76d9..0c04e022 100644 --- a/solana/solitaire/program/src/macros.rs +++ b/solana/solitaire/program/src/macros.rs @@ -155,10 +155,6 @@ macro_rules! data_wrapper { ) -> solitaire::Result<()> { Data::<'_, $embed, { $state }>::persist(self, program_id) } - - fn to_partial_cpi_meta(&self) -> Vec { - self.0.to_partial_cpi_meta() - } } impl<'b> solitaire::processors::seeded::Owned for $name<'b> { diff --git a/solana/solitaire/program/src/processors/peel.rs b/solana/solitaire/program/src/processors/peel.rs index 9f4fbe25..e36473b6 100644 --- a/solana/solitaire/program/src/processors/peel.rs +++ b/solana/solitaire/program/src/processors/peel.rs @@ -6,7 +6,6 @@ use borsh::BorshDeserialize; use solana_program::{ - instruction::AccountMeta, pubkey::Pubkey, system_program, sysvar::{ @@ -39,9 +38,6 @@ pub trait Peel<'a, 'b: 'a, 'c> { fn deps() -> Vec; fn persist(&self, program_id: &Pubkey) -> Result<()>; - - /// Special method for turning the type back into AccountMeta for CPI use cases. - fn to_partial_cpi_meta(&self) -> Vec; } /// Peel a Derived Key @@ -64,10 +60,6 @@ impl<'a, 'b: 'a, 'c, T: Peel<'a, 'b, 'c>, const Seed: &'static str> Peel<'a, 'b, fn persist(&self, program_id: &Pubkey) -> Result<()> { T::persist(self, program_id) } - - fn to_partial_cpi_meta(&self) -> Vec { - self.0.to_partial_cpi_meta() - } } /// Peel a Mutable key. @@ -106,10 +98,6 @@ impl<'a, 'b: 'a, 'c, T: Peel<'a, 'b, 'c>> Peel<'a, 'b, 'c> for Signer { fn persist(&self, program_id: &Pubkey) -> Result<()> { T::persist(self, program_id) } - - fn to_partial_cpi_meta(&self) -> Vec { - self.0.to_partial_cpi_meta() - } } /// Expicitly depend upon the System account. @@ -128,10 +116,6 @@ impl<'a, 'b: 'a, 'c, T: Peel<'a, 'b, 'c>> Peel<'a, 'b, 'c> for System { fn persist(&self, program_id: &Pubkey) -> Result<()> { T::persist(self, program_id) } - - fn to_partial_cpi_meta(&self) -> Vec { - self.0.to_partial_cpi_meta() - } } /// Peel a Sysvar @@ -156,10 +140,6 @@ where fn persist(&self, _program_id: &Pubkey) -> Result<()> { Ok(()) } - - fn to_partial_cpi_meta(&self) -> Vec { - self.to_partial_cpi_meta() - } } /// This is our structural recursion base case, the trait system will stop generating new nested @@ -178,16 +158,6 @@ impl<'a, 'b: 'a, 'c> Peel<'a, 'b, 'c> for Info<'b> { fn persist(&self, _program_id: &Pubkey) -> Result<()> { Ok(()) } - - fn to_partial_cpi_meta(&self) -> Vec { - let meta = if self.is_writable { - AccountMeta::new(self.key.clone(), self.is_signer) - } else { - AccountMeta::new_readonly(self.key.clone(), self.is_signer) - }; - - vec![meta] - } } /// This is our structural recursion base case, the trait system will stop generating new nested @@ -267,8 +237,4 @@ impl< Ok(()) } - - fn to_partial_cpi_meta(&self) -> Vec { - self.0.to_partial_cpi_meta() - } } diff --git a/solana/solitaire/rocksalt/src/lib.rs b/solana/solitaire/rocksalt/src/lib.rs index 5fc26911..413c65e8 100644 --- a/solana/solitaire/rocksalt/src/lib.rs +++ b/solana/solitaire/rocksalt/src/lib.rs @@ -27,7 +27,6 @@ use syn::{ parse_quote, spanned::Spanned, Data, - DataStruct, DeriveInput, Fields, GenericParam, @@ -107,8 +106,7 @@ pub fn derive_from_accounts(input: TokenStream) -> TokenStream { } let (combined_impl_g, _, _) = combined_generics.split_for_impl(); - let from_method = generate_from(&name, &input.data); - let to_cpi_metas_method = generate_to_cpi_metas(&name, &input.data); + let from_method = generate_fields(&name, &input.data); let persist_method = generate_persist(&name, &input.data); let deps_method = generate_deps_fields(&name, &input.data); let expanded = quote! { @@ -117,12 +115,8 @@ pub fn derive_from_accounts(input: TokenStream) -> TokenStream { fn from(pid: &'a solana_program::pubkey::Pubkey, iter: &'c mut std::slice::Iter<'a, solana_program::account_info::AccountInfo<'b>>, data: &'a DataType) -> solitaire::Result { #from_method } - fn to_cpi_metas(&self) -> Vec { - #to_cpi_metas_method - } } - /// Macro generated implementation of Peel by Solitaire. impl #combined_impl_g solitaire::Peel<'a, 'b, 'c> for #name #type_g { fn peel(ctx: &'c mut Context<'a, 'b, 'c, I>) -> solitaire::Result where Self: Sized { let v: #name #type_g = FromAccounts::from(ctx.this, ctx.iter, ctx.data)?; @@ -140,10 +134,6 @@ pub fn derive_from_accounts(input: TokenStream) -> TokenStream { fn persist(&self, program_id: &solana_program::pubkey::Pubkey) -> solitaire::Result<()> { solitaire::Persist::persist(self, program_id) } - - fn to_partial_cpi_meta(&self) -> Vec { - self.to_cpi_metas() - } } /// Macro generated implementation of Persist by Solitaire. @@ -159,7 +149,7 @@ pub fn derive_from_accounts(input: TokenStream) -> TokenStream { } /// This function does the heavy lifting of generating the field parsers. -fn generate_from(name: &syn::Ident, data: &Data) -> TokenStream2 { +fn generate_fields(name: &syn::Ident, data: &Data) -> TokenStream2 { match *data { // We only care about structures. Data::Struct(ref data) => { @@ -214,37 +204,6 @@ fn generate_from(name: &syn::Ident, data: &Data) -> TokenStream2 { } } -fn generate_to_cpi_metas(name: &syn::Ident, data: &Data) -> TokenStream2 { - if let Data::Struct(DataStruct { - fields: Fields::Named(fields), - .. - }) = data - { - let v_appends = fields.named.iter().map(|f| { - // Field name, to assign to. - let field_name = &f.ident; - let ty = &f.ty; - - quote! { - v.append(&mut self.#field_name.to_partial_cpi_meta()); - } - }); - - let names = fields.named.iter().map(|f| { - let name = &f.ident; - quote!(#name) - }); - - quote! { - let mut v = Vec::new(); - #(#v_appends;)* - v - } - } else { - unimplemented!() - } -} - /// This function does the heavy lifting of generating the field parsers. fn generate_deps_fields(name: &syn::Ident, data: &Data) -> TokenStream2 { match *data { @@ -293,6 +252,9 @@ fn generate_persist(name: &syn::Ident, data: &Data) -> TokenStream2 { match data.fields { // For now, we only care about struct { a: T } forms, not struct(T); Fields::Named(ref fields) => { + // For each field, generate an expression that parses an account info field + // from the Solana accounts list. This relies on Verify::verify to do most of + // the work. let recurse = fields.named.iter().map(|f| { // Field name, to assign to. let name = &f.ident;