Skip to content

Commit f86dadc

Browse files
committed
feat: Add Send Sync to traits
1 parent e49ab3b commit f86dadc

File tree

6 files changed

+66
-65
lines changed

6 files changed

+66
-65
lines changed

.github/workflows/check.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ jobs:
103103
# https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html which allows an
104104
# API be documented as only available in some specific platforms.
105105
#
106-
107-
runs-on: ubuntu-latest
106+
runs-on: ${{ vars.RUNNER }}
108107
name: doc
109108
steps:
110109
- uses: actions/checkout@v5
@@ -114,17 +113,11 @@ jobs:
114113
with:
115114
cache-on-failure: "true"
116115
cache-all-crates: "true"
117-
cache-workspace-crates: "true"
118-
workspaces: |
119-
. -> target
120-
# Specifies what to use as the backend providing cache
121-
# Can be set to "github", "buildjet", or "warpbuild"
122-
# default: "github"
123-
cache-bin: "true"
124116
- name: Install rust
125117
uses: dtolnay/rust-toolchain@nightly
126118
- name: Install cargo-docs-rs
127-
uses: dtolnay/install@cargo-docs-rs
119+
run: |
120+
cargo +nightly install cargo-docs-rs
128121
- name: cargo docs-rs
129122
run: |
130123
./scripts/docsrs.sh
@@ -191,4 +184,4 @@ jobs:
191184
TEST_PRIVATE_KEY: ${{ secrets.TEST_PRIVATE_KEY }}
192185
RPC_URL: ${{ secrets.RPC_URL }}
193186
run: |
194-
cargo run -p circle-cctp -- bridge 0x626189bcDE2392ea088Ea0BD32336994CA9a0DCc
187+
cargo run -p circle-cctp -- burn 0x626189bcDE2392ea088Ea0BD32336994CA9a0DCc

encoders/circle-message-transmitter-v2-encoder/src/helpers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use {
22
crate::{accounts::MessageSent, types::ReclaimEventAccountParams},
33
solana_account::Account,
4+
solana_client::nonblocking::rpc_client::RpcClient,
45
solana_pubkey::Pubkey,
56
solana_rpc_client_api::client_error::Result as ClientResult,
67
std::{
@@ -13,15 +14,15 @@ pub const TOKEN_MINTER_PROGRAM_ID: Pubkey =
1314
solana_pubkey::pubkey!("CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe");
1415

1516
#[async_trait::async_trait]
16-
pub trait ReclaimAccountRpcState {
17+
pub trait ReclaimAccountRpcState: Send + Sync {
1718
async fn get_reclaim_accounts(&self, owner: &Pubkey) -> ClientResult<Vec<(Pubkey, Account)>>;
1819
async fn get_reclaim_account_signature(&self, account: &Pubkey)
1920
-> ClientResult<Option<String>>;
2021
}
2122

2223
/// The fee account is owned by Circle and is used to pay for CCTP fees.
2324
#[async_trait::async_trait]
24-
pub trait FeeRecipientFetcher {
25+
pub trait FeeRecipientFetcher: Send + Sync {
2526
async fn get_fee_recipient_token_account(
2627
&self,
2728
circle_usdc_address: &Pubkey,

encoders/circle-message-transmitter-v2-encoder/src/helpers/reclaim_event_account_helpers.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use {
99
rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig},
1010
},
1111
solana_pubkey::Pubkey,
12-
solana_rpc_client::nonblocking::rpc_client::RpcClient,
1312
};
1413

1514
// https://github.com/circlefin/solana-cctp-contracts/blob/03f7dec786eb9affa68688954f62917edeed2e35/programs/v2/message-transmitter-v2/src/state.rs#L56
@@ -60,11 +59,14 @@ impl<T: AsRef<RpcClient> + Send + Sync> ReclaimAccountRpcState for T {
6059
}
6160
}
6261

62+
#[tracing::instrument(level = "info", skip(rpc))]
6363
pub async fn find_claimable_accounts<T: ReclaimAccountRpcState>(
6464
owner: &Pubkey,
6565
rpc: &T,
6666
) -> ClientResult<ReclaimAccountStatus> {
67+
tracing::debug!("calling RPC for reclaim accounts");
6768
let accounts = rpc.get_reclaim_accounts(owner).await?;
69+
tracing::debug!("found {} accounts", accounts.len());
6870
let mut claimable = ReclaimAccountStatus::new(*owner);
6971
let now = std::time::SystemTime::now()
7072
.duration_since(std::time::UNIX_EPOCH)

examples/circle-cctp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ solana-rpc-client = { workspace = true }
2323
solana-rpc-client-api = { workspace = true }
2424
solana-signer = { workspace = true }
2525
solana-system-interface = { workspace = true }
26-
soly = { git = "https://github.com/CarteraMesh/soly.git", branch = "main" }
26+
soly = { version = "0.1.1-rc.1" }
2727
spl-memo = { workspace = true }
2828
spl-token = { workspace = true }
2929
tokio = { workspace = true, features = ["full"] }

examples/circle-cctp/src/command.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use clap::{Args, Parser, Subcommand};
1+
use {
2+
clap::{Args, Parser, Subcommand},
3+
std::fmt::Debug,
4+
};
25

36
#[derive(Parser)]
47
#[command(name = "circle-cctp")]
@@ -8,7 +11,7 @@ pub struct Cli {
811
}
912

1013
#[derive(Args)]
11-
pub struct BridgeArgs {
14+
pub struct BurnArgs {
1215
#[arg(long, default_value = "10")]
1316
pub amount: u64,
1417
#[arg(long, default_value = "6")]
@@ -18,9 +21,19 @@ pub struct BridgeArgs {
1821
pub destination: String,
1922
}
2023

24+
impl Debug for BurnArgs {
25+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26+
write!(
27+
f,
28+
"[amount={},dest={},chain={}]",
29+
self.amount, self.destination, self.destination_chain
30+
)
31+
}
32+
}
33+
2134
#[derive(Subcommand)]
2235
pub enum Commands {
23-
Bridge(BridgeArgs),
36+
Burn(BurnArgs),
2437
Reclaim,
2538
Recv { tx_hash: String },
2639
}

examples/circle-cctp/src/main.rs

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use {
2-
crate::command::BridgeArgs,
2+
crate::command::BurnArgs,
33
alloy_primitives::Address,
44
anyhow::{Ok, Result},
55
clap::Parser,
66
nitrogen_circle_message_transmitter_v2_encoder::{
77
ID as MESSAGE_TRANSMITTER_PROGRAM_ID,
88
helpers::{receive_message_helpers, reclaim_event_account_helpers},
9-
instructions::reclaim_event_account,
10-
types::ReclaimEventAccountParams,
119
},
1210
nitrogen_circle_token_messenger_minter_v2_encoder::{
1311
ID as TOKEN_MINTER_PROGRAM_ID,
@@ -25,8 +23,8 @@ use {
2523
BlockHashCacheProvider,
2624
LookupTableCacheProvider,
2725
SimpleCacheProvider,
28-
SolanaRpcProvider,
29-
TraceNativeProvider,
26+
SolanaRpcProviderNative,
27+
TraceRpcNativeProvider,
3028
TransactionBuilder,
3129
},
3230
std::{env, time::Duration},
@@ -50,10 +48,7 @@ async fn fetch_attestation(
5048
attestation::get_attestation_with_retry(sig, chain).await
5149
}
5250

53-
async fn reclaim<T: SolanaRpcProvider + AsRef<RpcClient> + Send + Sync>(
54-
rpc: &T,
55-
owner: Keypair,
56-
) -> Result<()> {
51+
async fn reclaim<T: SolanaRpcProviderNative>(rpc: &T, owner: Keypair) -> Result<()> {
5752
let reclaim_accounts =
5853
reclaim_event_account_helpers::find_claimable_accounts(&owner.pubkey(), rpc).await?;
5954
info!("reclaim accounts {reclaim_accounts}");
@@ -74,20 +69,9 @@ async fn reclaim<T: SolanaRpcProvider + AsRef<RpcClient> + Send + Sync>(
7469
tracing::warn!("Skipping account with no signature");
7570
continue;
7671
}
77-
let sig = account.signature.unwrap_or_default();
72+
let sig = account.signature.clone().unwrap();
7873
let (attest, message) = fetch_attestation(sig, None).await?;
79-
let reclaim_account = reclaim_event_account(
80-
ReclaimEventAccountParams::builder()
81-
.attestation(attest)
82-
.destination_message(message)
83-
.build(),
84-
);
85-
let reclaim_tx = TransactionBuilder::from(
86-
reclaim_account
87-
.accounts(owner.pubkey(), account.address)
88-
.instruction(),
89-
);
90-
74+
let reclaim_tx: TransactionBuilder = account.instruction((attest, message)).into();
9175
let reclaim_tx = match (units, fee) {
9276
(Some(units), Some(fee)) => {
9377
reclaim_tx.prepend_compute_budget_instructions(units, fee)?
@@ -155,12 +139,14 @@ fn get_keypair() -> Result<Keypair> {
155139
}
156140

157141
#[allow(unused_variables)]
158-
async fn evm_sol(args: BridgeArgs, owner: Keypair, rpc: TraceNativeProvider) -> Result<()> {
142+
async fn evm_sol<T: SolanaRpcProviderNative>(args: BurnArgs, owner: Keypair, rpc: T) -> Result<()> {
159143
info!("TBD sending to sol");
160144
Ok(())
161145
}
162146

163-
async fn sol_evm(args: BridgeArgs, owner: Keypair, rpc: TraceNativeProvider) -> Result<()> {
147+
async fn sol_evm<T: SolanaRpcProviderNative>(args: BurnArgs, owner: Keypair, rpc: T) -> Result<()> {
148+
let span = tracing::info_span!("sol_evm", args =? args);
149+
let _g = span.enter();
164150
info!("burning...");
165151
let message_sent_event_account = Keypair::new();
166152
let evm_addr: Address = Address::parse_checksummed(args.destination, None)?;
@@ -211,6 +197,30 @@ async fn sol_evm(args: BridgeArgs, owner: Keypair, rpc: TraceNativeProvider) ->
211197
Ok(())
212198
}
213199

200+
fn cached_rpc(rpc: RpcClient) -> impl SolanaRpcProviderNative {
201+
let rpc: TraceRpcNativeProvider = rpc.into();
202+
let hash_cache = BlockHashCacheProvider::new(rpc.clone(), Duration::from_secs(30));
203+
let lookup_cache = LookupTableCacheProvider::builder()
204+
.inner(rpc.clone())
205+
.lookup_cache(
206+
soly::Cache::builder()
207+
.time_to_live(Duration::from_secs(86400))
208+
.build(),
209+
)
210+
.negative_cache(
211+
soly::Cache::builder()
212+
.time_to_live(Duration::from_secs(600))
213+
.build(),
214+
)
215+
.build();
216+
217+
SimpleCacheProvider::builder()
218+
.inner(rpc.clone())
219+
.blockhash_cache(hash_cache.into())
220+
.lookup_cache(lookup_cache.into())
221+
.build()
222+
}
223+
214224
#[allow(clippy::expect_fun_call)]
215225
#[tokio::main]
216226
pub async fn main() -> Result<()> {
@@ -228,37 +238,19 @@ pub async fn main() -> Result<()> {
228238

229239
let url = env::var("RPC_URL").expect("RPC_URL is not set");
230240
info!("using RPC {url}");
231-
let rpc: TraceNativeProvider =
232-
RpcClient::new_with_commitment(url, CommitmentConfig::finalized()).into();
241+
let rpc = cached_rpc(RpcClient::new_with_commitment(
242+
url,
243+
CommitmentConfig::finalized(),
244+
));
233245
match cli.command {
234-
command::Commands::Bridge(args) => {
246+
command::Commands::Burn(args) => {
235247
if !args.to_sol {
236248
sol_evm(args, owner, rpc).await
237249
} else {
238250
evm_sol(args, owner, rpc).await
239251
}
240252
}
241253
command::Commands::Reclaim => {
242-
let hash_cache = BlockHashCacheProvider::new(rpc.clone(), Duration::from_secs(30));
243-
let lookup_cache = LookupTableCacheProvider::builder()
244-
.inner(rpc.clone())
245-
.lookup_cache(
246-
soly::Cache::builder()
247-
.time_to_live(Duration::from_secs(86400))
248-
.build(),
249-
)
250-
.negative_cache(
251-
soly::Cache::builder()
252-
.time_to_live(Duration::from_secs(600))
253-
.build(),
254-
)
255-
.build();
256-
257-
let rpc = SimpleCacheProvider::builder()
258-
.inner(rpc.clone())
259-
.blockhash_cache(hash_cache.into())
260-
.lookup_cache(lookup_cache.into())
261-
.build();
262254
reclaim(&rpc, owner).await?;
263255
Ok(())
264256
}

0 commit comments

Comments
 (0)