Skip to content

Commit 2051e51

Browse files
authored
Add instructions to run (#18)
1 parent 3065a53 commit 2051e51

File tree

5 files changed

+90
-39
lines changed

5 files changed

+90
-39
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@ Tuktuk's architecture allows for crankers to run a simple rust util that require
1212

1313
Creators of Task Queues set their payment per-crank turn in SOL. Crankers that run the tasks are paid out in SOL for each crank they complete. There is a minimum deposit of 1 SOL to create a task queue to discourage spam. This deposit is refunded when the task queue is closed. The intent is to minimize the number of task queues that crank turners need to watch. You should try to reuse task queues as much as possible. It is an antipattern to create a new task queue for each user, for example.
1414

15+
## Running a Crank Turner
16+
17+
Install the crank turner:
18+
19+
```
20+
cargo install tuktuk-crank-turner
21+
```
22+
23+
If you want to run a crank turner, create a config.toml file with the following:
24+
25+
```
26+
rpc_url = "https://api.mainnet-beta.solana.com"
27+
key_path = "/path/to/your/keypair.json"
28+
min_crank_fee = 10000
29+
```
30+
31+
Then run the crank turner:
32+
33+
```
34+
tuktuk-crank-turner -c config.toml
35+
```
36+
37+
You can also provider configuration via environment variables
38+
39+
```
40+
export TUKTUK__RPC_URL="https://api.mainnet-beta.solana.com"
41+
export TUKTUK__KEY_PATH="/path/to/your/keypair.json"
42+
export TUKTUK__MIN_CRANK_FEE=10000
43+
tuktuk-crank-turner
44+
```
45+
46+
### Requirements
47+
48+
You will need a good Solana RPC that doesn't have heavy rate limits (for when there are a lot of tasks queued). You should also handle restarting the process if it crashes, as this can happen if your RPC disconnects the websocket without a proper handshake.
49+
1550
## Usage
1651

1752
Install the tuktuk cli by running `cargo install tuktuk-cli`.

tuktuk-cli/src/cmd/task.rs

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,49 +76,60 @@ pub enum Cmd {
7676

7777
async fn simulate_task(client: &CliClient, task_key: Pubkey) -> Result<Option<SimulationResult>> {
7878
// Get the run instruction
79-
let run_ix = tuktuk_sdk::compiled_transaction::run_ix(
79+
let run_ix_res = tuktuk_sdk::compiled_transaction::run_ix(
8080
client.as_ref(),
8181
task_key,
8282
client.payer.pubkey(),
8383
&HashSet::new(),
8484
)
85-
.await?;
85+
.await;
8686

87-
// Create and simulate the transaction
88-
let mut updated_instructions =
89-
vec![solana_sdk::compute_budget::ComputeBudgetInstruction::set_compute_unit_limit(1900000)];
90-
updated_instructions.extend(run_ix.instructions.clone());
91-
let recent_blockhash = client.rpc_client.get_latest_blockhash().await?;
92-
let message = VersionedMessage::V0(v0::Message::try_compile(
93-
&client.payer.pubkey(),
94-
&updated_instructions,
95-
&run_ix.lookup_tables,
96-
recent_blockhash,
97-
)?);
98-
let tx = VersionedTransaction::try_new(message, &[&client.payer])?;
99-
let sim_result = client
100-
.rpc_client
101-
.simulate_transaction_with_config(
102-
&tx,
103-
RpcSimulateTransactionConfig {
104-
commitment: Some(solana_sdk::commitment_config::CommitmentConfig::confirmed()),
105-
sig_verify: true,
106-
..Default::default()
107-
},
108-
)
109-
.await;
87+
match run_ix_res {
88+
Ok(run_ix) => {
89+
// Create and simulate the transaction
90+
let mut updated_instructions = vec![
91+
solana_sdk::compute_budget::ComputeBudgetInstruction::set_compute_unit_limit(
92+
1900000,
93+
),
94+
];
95+
updated_instructions.extend(run_ix.instructions.clone());
96+
let recent_blockhash = client.rpc_client.get_latest_blockhash().await?;
97+
let message = VersionedMessage::V0(v0::Message::try_compile(
98+
&client.payer.pubkey(),
99+
&updated_instructions,
100+
&run_ix.lookup_tables,
101+
recent_blockhash,
102+
)?);
103+
let tx = VersionedTransaction::try_new(message, &[&client.payer])?;
104+
let sim_result = client
105+
.rpc_client
106+
.simulate_transaction_with_config(
107+
&tx,
108+
RpcSimulateTransactionConfig {
109+
commitment: Some(
110+
solana_sdk::commitment_config::CommitmentConfig::confirmed(),
111+
),
112+
sig_verify: true,
113+
..Default::default()
114+
},
115+
)
116+
.await;
110117

111-
match sim_result {
112-
Ok(simulated) => Ok(Some(SimulationResult {
113-
error: simulated.value.err.map(|e| e.to_string()),
114-
logs: Some(simulated.value.logs.unwrap_or_default()),
115-
compute_units: simulated.value.units_consumed,
116-
})),
117-
Err(err) => Ok(Some(SimulationResult {
118-
error: Some(err.to_string()),
119-
logs: None,
120-
compute_units: None,
121-
})),
118+
match sim_result {
119+
Ok(simulated) => Ok(Some(SimulationResult {
120+
error: simulated.value.err.map(|e| e.to_string()),
121+
logs: Some(simulated.value.logs.unwrap_or_default()),
122+
compute_units: simulated.value.units_consumed,
123+
})),
124+
Err(err) => Ok(Some(SimulationResult {
125+
error: Some(err.to_string()),
126+
logs: None,
127+
compute_units: None,
128+
})),
129+
}
130+
}
131+
Err(tuktuk_sdk::error::Error::AccountNotFound) => Ok(None),
132+
Err(e) => Err(e.into()),
122133
}
123134
}
124135

tuktuk-crank-turner/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-crank-turner"
3-
version = "0.2.10"
3+
version = "0.2.11"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true

tuktuk-crank-turner/src/settings.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Settings {
1010
#[serde(default = "default_log")]
1111
pub log: String,
1212

13+
#[serde(default = "default_max_retries")]
1314
pub max_retries: u8,
1415
pub rpc_url: String,
1516
pub key_path: String,
@@ -26,6 +27,10 @@ pub struct Settings {
2627
pub recent_attempts_window: usize,
2728
}
2829

30+
fn default_max_retries() -> u8 {
31+
5
32+
}
33+
2934
fn default_recent_attempts_window() -> usize {
3035
5
3136
}
@@ -47,7 +52,7 @@ fn default_max_sol_fee() -> u64 {
4752
}
4853

4954
fn default_log() -> String {
50-
"queue_node=debug".to_string()
55+
"info".to_string()
5156
}
5257

5358
impl Settings {

0 commit comments

Comments
 (0)