Skip to content

Commit 6202c89

Browse files
authored
feat: Allow remote servers to return additional LUTs (#80)
* feat: Allow remote servers to return additional LUTs * Bump cargo versions
1 parent 74f1180 commit 6202c89

File tree

11 files changed

+101
-37
lines changed

11 files changed

+101
-37
lines changed

Cargo.lock

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ spl-token = "4.0.0"
5858
itertools = "0.13"
5959
tokio-graceful-shutdown = "0.15"
6060
solana-transaction-utils = { version = "0.4.2", path = "./solana-transaction-utils" }
61-
tuktuk-sdk = { version = "0.3.6", path = "./tuktuk-sdk" }
61+
tuktuk-sdk = { version = "0.4.0", path = "./tuktuk-sdk" }
6262
tuktuk-program = { version = "0.3.2", path = "./tuktuk-program" }
6363
solana-account-decoder = { version = "2.2.3" }
6464
solana-clock = { version = "2.2.1" }
6565
solana-transaction-status = "2.2.3"
6666
bincode = { version = "1.3.3" }
67+
async-trait = "0.1.89"
6768

6869
[profile.release]
6970
debug = true

tuktuk-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tuktuk-cli"
3-
version = "0.2.13"
3+
version = "0.2.14"
44
description = "A cli for tuktuk"
55
homepage.workspace = true
66
repository.workspace = true

tuktuk-cli/src/cmd/task.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pub enum Cmd {
123123
async fn simulate_task(client: &CliClient, task_key: Pubkey) -> Result<Option<SimulationResult>> {
124124
// Get the run instruction
125125
let run_ix_res = tuktuk_sdk::compiled_transaction::run_ix(
126+
client.as_ref(),
126127
client.as_ref(),
127128
task_key,
128129
client.payer.pubkey(),
@@ -598,6 +599,7 @@ impl TaskCmd {
598599
};
599600
for (task_key, _) in tasks {
600601
let run_ix_result = tuktuk_sdk::compiled_transaction::run_ix(
602+
client.as_ref(),
601603
client.as_ref(),
602604
task_key,
603605
client.payer.pubkey(),

tuktuk-crank-turner/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tuktuk-crank-turner"
3-
version = "0.2.24"
3+
version = "0.2.25"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true
@@ -15,6 +15,7 @@ path = "src/main.rs"
1515
[dependencies]
1616
anchor-lang = { workspace = true }
1717
anchor-client = { workspace = true, features = ["async"] }
18+
async-trait = { workspace = true }
1819
bincode = { workspace = true }
1920
solana-sdk = { workspace = true }
2021
tokio = { workspace = true }

tuktuk-crank-turner/src/cache/lookup_tables.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use solana_sdk::{
77
};
88
use tokio_graceful_shutdown::SubsystemHandle;
99
use tracing::info;
10+
use tuktuk_sdk::client::LookupTableResolver;
1011

1112
use crate::{cache::LookupTableRequest, sync};
1213

@@ -26,6 +27,18 @@ impl LookupTablesSender {
2627
}
2728
}
2829

30+
#[async_trait::async_trait]
31+
impl LookupTableResolver for LookupTablesSender {
32+
async fn resolve_lookup_tables(
33+
&self,
34+
lookup_tables: Vec<Pubkey>,
35+
) -> Result<Vec<AddressLookupTableAccount>, tuktuk_sdk::error::Error> {
36+
self.get_lookup_tables(lookup_tables).await.map_err(|_| {
37+
tuktuk_sdk::error::Error::InvalidTransaction("lookup tables channel closed")
38+
})
39+
}
40+
}
41+
2942
pub fn lookup_tables_channel() -> (LookupTablesSender, LookupTablesReceiver) {
3043
let (tx, rx) = sync::message_channel(100);
3144
(tx, rx)

tuktuk-crank-turner/src/task_processor.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ impl TimedTask {
117117

118118
let task_queue = self.get_task_queue(ctx.clone()).await?;
119119

120-
let lookup_tables = ctx
121-
.lookup_tables_client
122-
.get_lookup_tables(task_queue.lookup_tables)
123-
.await
124-
.map_err(|_| anyhow::anyhow!("lookup tables channel closed"))?;
125120
let maybe_next_available = self.get_available_task_ids(ctx.clone()).await;
126121
let next_available = match maybe_next_available {
127122
Ok(next_available) => next_available,
@@ -163,7 +158,8 @@ impl TimedTask {
163158
&self.task,
164159
payer.pubkey(),
165160
next_available,
166-
lookup_tables,
161+
task_queue.lookup_tables.clone(),
162+
ctx.rpc_client.as_ref(),
167163
)
168164
.await
169165
};

tuktuk-program/src/write_return_tasks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868
};
6969

7070
let mut total_tasks = 0;
71-
let mut has_unprocessed_tasks = true;
71+
let mut has_unprocessed_tasks: bool;
7272
for AccountWithSeeds { account, seeds } in accounts.iter() {
7373
// Store original size before any reallocation
7474
original_sizes.push(account.data_len());

tuktuk-sdk/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tuktuk-sdk"
3-
version = "0.3.6"
3+
version = "0.4.0"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true
@@ -28,12 +28,12 @@ tokio = { workspace = true }
2828
tokio-graceful-shutdown = { workspace = true }
2929
bincode = { workspace = true }
3030
itertools = { workspace = true }
31-
async-trait = { version = "0" }
3231
spl-associated-token-account = { workspace = true }
3332
spl-token = { workspace = true }
3433
tuktuk-program = { workspace = true }
3534
base64 = "0.22.1"
3635
serde_json = "1.0.135"
36+
async-trait = { workspace = true }
3737
bytemuck = "1.21.0"
3838
rand = "0.9"
3939
# For pubsub client

tuktuk-sdk/src/client.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use anchor_lang::AccountDeserialize;
44
use futures::{stream, StreamExt, TryFutureExt, TryStreamExt};
55
use itertools::Itertools;
66
pub use solana_client::nonblocking::rpc_client::RpcClient as SolanaRpcClient;
7-
use solana_sdk::{account::Account, pubkey::Pubkey};
7+
use solana_sdk::{
8+
account::Account, address_lookup_table::state::AddressLookupTable,
9+
message::AddressLookupTableAccount, pubkey::Pubkey,
10+
};
811

912
use crate::error::Error;
1013

@@ -61,6 +64,37 @@ impl GetAccount for SolanaRpcClient {
6164
}
6265
}
6366

67+
#[async_trait::async_trait]
68+
pub trait LookupTableResolver {
69+
async fn resolve_lookup_tables(
70+
&self,
71+
lookup_tables: Vec<Pubkey>,
72+
) -> Result<Vec<AddressLookupTableAccount>, Error>;
73+
}
74+
75+
#[async_trait::async_trait]
76+
impl LookupTableResolver for SolanaRpcClient {
77+
async fn resolve_lookup_tables(
78+
&self,
79+
lookup_tables: Vec<Pubkey>,
80+
) -> Result<Vec<AddressLookupTableAccount>, Error> {
81+
let accounts = self.get_multiple_accounts(&lookup_tables).await?;
82+
Ok(accounts
83+
.into_iter()
84+
.zip(lookup_tables.iter())
85+
.filter_map(|(maybe_acc, pubkey)| {
86+
maybe_acc.map(|acc| {
87+
let lut = AddressLookupTable::deserialize(&acc.data).map_err(Error::from)?;
88+
Ok(AddressLookupTableAccount {
89+
key: *pubkey,
90+
addresses: lut.addresses.to_vec(),
91+
})
92+
})
93+
})
94+
.collect::<Result<Vec<_>, Error>>()?)
95+
}
96+
}
97+
6498
#[async_trait::async_trait]
6599
impl GetAnchorAccount for SolanaRpcClient {
66100
async fn anchor_account<T: AccountDeserialize>(

0 commit comments

Comments
 (0)