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

ShadowPortal infra #205

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update to current version of contract
cavemanloverboy committed Mar 14, 2023

Verified

This commit was signed with the committer’s verified signature.
cavemanloverboy cavemanloverboy
commit 49d4f8dd5854b50ee65d90be639fd0d8883d66ce
3 changes: 1 addition & 2 deletions plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -47,8 +47,7 @@ sha2 = "0.10.6"


[dependencies.chain-drive]
# git = "https://github.com/GenesysGo/shadow-drive-clockwork.git"
path = "../../shadow-drive-clockwork/programs/chain-drive/"
git = "https://github.com/GenesysGo/shadow-drive-clockwork.git"

[build-dependencies]
cargo_toml = "0.13.0"
7 changes: 3 additions & 4 deletions plugin/src/builders/thread_exec.rs
Original file line number Diff line number Diff line change
@@ -200,15 +200,14 @@ fn build_kickoff_ix(mut thread: Thread, signatory_pubkey: Pubkey, worker_id: u64
kickoff_ix
}

fn build_exec_ix(mut thread: Thread, signatory_pubkey: Pubkey, worker_id: u64) -> Instruction {
dbg!(&thread);
fn build_exec_ix(thread: Thread, signatory_pubkey: Pubkey, worker_id: u64) -> Instruction {
// Build the instruction.
let thread_pubkey = Thread::pubkey(thread.authority, thread.id);
let mut exec_ix = dbg!(clockwork_client::thread::instruction::thread_exec(
let mut exec_ix = clockwork_client::thread::instruction::thread_exec(
signatory_pubkey,
thread_pubkey,
Worker::pubkey(worker_id),
));
);

if let Some(next_instruction) = thread.next_instruction {
// Inject the target program account.
13 changes: 6 additions & 7 deletions plugin/src/events.rs
Original file line number Diff line number Diff line change
@@ -69,17 +69,16 @@ impl TryFrom<ReplicaAccountInfo<'_>> for AccountUpdateEvent {
}

// If the account belongs to shadow program
if dbg!(owner_pubkey).eq(dbg!(&chain_drive::ID)) && account_info.data.len() > 8 {
dbg!("found sdrive ix");
if owner_pubkey.eq(&chain_drive::ID) && account_info.data.len() > 8 {
let d = &account_info.data[..8];
if dbg!(d).eq(dbg!(&DataToBeSummoned::DISCRIMINATOR)) {
dbg!("found summon account");
if d.eq(&DataToBeSummoned::DISCRIMINATOR) {
let mut account_info = account_info;
return Ok(AccountUpdateEvent::Upload {
metadata: dbg!(DataToBeSummoned::try_deserialize(&mut account_info.data))
.map_err(|_| GeyserPluginError::AccountsUpdateError {
metadata: DataToBeSummoned::try_deserialize(&mut account_info.data).map_err(
|_| GeyserPluginError::AccountsUpdateError {
msg: "Failed to parse DataToBeSummoned account".into(),
})?,
},
)?,
});
}
}
38 changes: 35 additions & 3 deletions plugin/src/executors/tx.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ use std::{
atomic::{AtomicU64, Ordering},
Arc,
},
time::Duration,
};

use anchor_lang::{prelude::AccountMeta, InstructionData};
@@ -20,7 +21,7 @@ use log::info;
use sha2::{Digest, Sha256};
use solana_client::{
nonblocking::{rpc_client::RpcClient, tpu_client::TpuClient},
rpc_config::{RpcSendTransactionConfig, RpcSimulateTransactionConfig},
rpc_config::RpcSimulateTransactionConfig,
tpu_client::TpuClientConfig,
};
use solana_geyser_plugin_interface::geyser_plugin_interface::{
@@ -495,19 +496,44 @@ impl TxExecutor {
data: data.to_vec(),
};
let upload_ix_data = upload.data();
log::info!("upload tx is uploading to {metadata_pubkey}");
let metadata_token_account = Pubkey::find_program_address(
&[metadata_pubkey.as_ref()],
&chain_drive::ID,
)
.0;
let upload_ix = Instruction {
program_id: chain_drive::ID,
accounts: vec![
// uploader
AccountMeta::new(self.keypair.pubkey(), true),
// metadata
AccountMeta::new(metadata_pubkey, false),
// metadata token account
AccountMeta::new(metadata_token_account, false),
// shdw payout account
AccountMeta::new(chain_drive::payout_account(), false),
// thread
AccountMeta::new(
Thread::pubkey(
metadata_pubkey,
metadata_pubkey.to_bytes().to_vec(),
metadata
.unique_thread
.map(|id| id.to_le_bytes().to_vec())
.unwrap_or_else(|| {
<str as AsRef<[u8]>>::as_ref(
metadata.filename.as_ref(),
)
.to_vec()
}),
),
false,
),
// thread program
AccountMeta::new_readonly(clockwork_client::thread::ID, false),
// token program
AccountMeta::new_readonly(chain_drive::TOKEN_PROGRAM_ID, false),
// system program
AccountMeta::new_readonly(
solana_program::system_program::ID,
false,
@@ -521,7 +547,13 @@ impl TxExecutor {
&[&self.keypair],
client.get_latest_blockhash().await.expect("TODO"),
);
TPU_CLIENT.get().await.send_transaction(&transaction).await;
if let Err(e) = client.send_and_confirm_transaction(&transaction).await {
log::error!("upload failed {e:#?}");
tokio::time::sleep(Duration::from_millis(400)).await;
TPU_CLIENT.get().await.send_transaction(&transaction).await;
};
} else {
log::error!("invalid hash");
}
}
}