Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions architectures/decentralized/solana-client/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct App {
update_tui_interval: Interval,
tx_tui_state: Option<Sender<TabsData>>,
authorizer: Option<Pubkey>,
claimer: Option<Pubkey>,
metrics: Arc<ClientMetrics>,
allowlist: allowlist::AllowDynamic,
p2p: NC,
Expand All @@ -61,6 +62,7 @@ pub struct AppParams {
pub backup_clusters: Vec<Cluster>,
pub tx_tui_state: Option<Sender<TabsData>>,
pub authorizer: Option<Pubkey>,
pub claimer: Option<Pubkey>,
pub train_args: TrainArgs,
}

Expand All @@ -72,6 +74,7 @@ pub async fn build_app(
backup_clusters,
tx_tui_state,
authorizer,
claimer,
train_args: p,
}: AppParams,
) -> Result<App> {
Expand Down Expand Up @@ -151,6 +154,7 @@ pub async fn build_app(
tx_tui_state,
update_tui_interval: interval(Duration::from_millis(150)),
authorizer,
claimer,
allowlist,
metrics,
p2p,
Expand Down Expand Up @@ -238,8 +242,9 @@ impl App {
.join_run(
coordinator_instance_pubkey,
coordinator_account,
psyche_core::NodeIdentity::new(signer.to_bytes(), *p2p_identity.as_bytes()),
self.authorizer,
psyche_core::NodeIdentity::new(signer.to_bytes(), *p2p_identity.as_bytes()),
self.claimer,
)
.await?;
info!(
Expand Down Expand Up @@ -355,8 +360,9 @@ impl App {
.join_run(
coordinator_instance_pubkey,
coordinator_account,
id,
self.authorizer,
id,
self.claimer,
)
.await?;
info!(
Expand Down
5 changes: 5 additions & 0 deletions architectures/decentralized/solana-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ enum Commands {
rpc_3: String,
#[clap(long, env, default_value_t = String::from(""))]
ws_rpc_3: String,

#[clap(long, env)]
authorizer: Option<Pubkey>,
#[clap(long, env)]
claimer: Option<Pubkey>,
},
Predownload {
#[clap(flatten)]
Expand Down Expand Up @@ -171,6 +174,7 @@ async fn async_main() -> Result<()> {
rpc_3,
ws_rpc_3,
authorizer,
claimer,
} => {
psyche_client::prepare_environment();
info!(
Expand Down Expand Up @@ -254,6 +258,7 @@ async fn async_main() -> Result<()> {
cluster: cluster.into(),
backup_clusters,
authorizer,
claimer,
train_args: args,
})
.await?;
Expand Down
4 changes: 3 additions & 1 deletion architectures/decentralized/solana-common/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ impl SolanaBackend {
&self,
coordinator_instance: Pubkey,
coordinator_account: Pubkey,
id: psyche_core::NodeIdentity,
authorizer: Option<Pubkey>,
id: psyche_core::NodeIdentity,
claimer: Option<Pubkey>,
) -> Result<Signature> {
let coordinator_instance_state =
self.get_coordinator_instance(&coordinator_instance).await?;
Expand All @@ -286,6 +287,7 @@ impl SolanaBackend {
&coordinator_account,
&authorization,
id,
&claimer.unwrap_or(self.get_payer()),
);
// TODO (vbrunet) - what was the point of doing specifically a timeout here but not the other TXs ?
// We timeout the transaction at 5s max, since internally send() polls Solana until the
Expand Down
51 changes: 39 additions & 12 deletions architectures/decentralized/solana-common/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ pub fn coordinator_init_coordinator(
psyche_solana_coordinator::ID,
psyche_solana_coordinator::accounts::InitCoordinatorAccounts {
payer: *payer,
authority: *main_authority,
coordinator_instance,
coordinator_account: *coordinator_account,
system_program: system_program::ID,
},
psyche_solana_coordinator::instruction::InitCoordinator {
params: psyche_solana_coordinator::logic::InitCoordinatorParams {
main_authority: *main_authority,
join_authority: *join_authority,
run_id: run_id.to_string(),
join_authority: *join_authority,
client_version: client_version.to_string(),
},
},
Expand Down Expand Up @@ -102,6 +102,7 @@ pub fn coordinator_join_run(
coordinator_account: &Pubkey,
authorization: &Pubkey,
client_id: psyche_core::NodeIdentity,
claimer: &Pubkey,
) -> Instruction {
anchor_instruction(
psyche_solana_coordinator::ID,
Expand All @@ -112,7 +113,10 @@ pub fn coordinator_join_run(
coordinator_account: *coordinator_account,
},
psyche_solana_coordinator::instruction::JoinRun {
params: psyche_solana_coordinator::logic::JoinRunParams { client_id },
params: psyche_solana_coordinator::logic::JoinRunParams {
client_id,
claimer: *claimer,
},
},
)
}
Expand Down Expand Up @@ -219,6 +223,26 @@ pub fn coordinator_checkpoint(
)
}

pub fn coordinator_set_join_authority(
run_id: &str,
coordinator_account: &Pubkey,
main_authority: &Pubkey,
join_authority: &Pubkey,
) -> Instruction {
let coordinator_instance = psyche_solana_coordinator::find_coordinator_instance(run_id);
anchor_instruction(
psyche_solana_coordinator::ID,
psyche_solana_coordinator::accounts::OwnerCoordinatorAccounts {
authority: *main_authority,
coordinator_instance,
coordinator_account: *coordinator_account,
},
psyche_solana_coordinator::instruction::SetJoinAuthority {
join_authority: *join_authority,
},
)
}

pub fn coordinator_update_client_version(
run_id: &str,
coordinator_account: &Pubkey,
Expand Down Expand Up @@ -257,6 +281,7 @@ pub fn treasurer_run_create(
psyche_solana_treasurer::ID,
psyche_solana_treasurer::accounts::RunCreateAccounts {
payer: *payer,
authority: *main_authority,
run,
run_collateral,
collateral_mint: *collateral_mint,
Expand All @@ -270,10 +295,11 @@ pub fn treasurer_run_create(
psyche_solana_treasurer::instruction::RunCreate {
params: psyche_solana_treasurer::logic::RunCreateParams {
index: treasurer_index,
main_authority: *main_authority,
join_authority: *join_authority,
run_id: run_id.to_string(),
client_version: client_version.to_string(),
init: psyche_solana_coordinator::logic::InitCoordinatorParams {
run_id: run_id.to_string(),
join_authority: *join_authority,
client_version: client_version.to_string(),
},
},
},
)
Expand Down Expand Up @@ -314,31 +340,31 @@ pub fn treasurer_participant_create(
payer: *payer,
run,
participant,
user: *user,
system_program: system_program::ID,
},
psyche_solana_treasurer::instruction::ParticipantCreate {
params: psyche_solana_treasurer::logic::ParticipantCreateParams {},
params: psyche_solana_treasurer::logic::ParticipantCreateParams { user: *user },
},
)
}

pub fn treasurer_participant_claim(
treasurer_index: u64,
claimer: &Pubkey,
claimer_collateral: &Pubkey,
collateral_mint: &Pubkey,
coordinator_account: &Pubkey,
user: &Pubkey,
claim_earned_points: u64,
) -> Instruction {
let user_collateral = associated_token::get_associated_token_address(user, collateral_mint);
let run = psyche_solana_treasurer::find_run(treasurer_index);
let run_collateral = associated_token::get_associated_token_address(&run, collateral_mint);
let participant = psyche_solana_treasurer::find_participant(&run, user);
anchor_instruction(
psyche_solana_treasurer::ID,
psyche_solana_treasurer::accounts::ParticipantClaimAccounts {
user: *user,
user_collateral,
claimer: *claimer,
claimer_collateral: *claimer_collateral,
run,
run_collateral,
participant,
Expand All @@ -347,6 +373,7 @@ pub fn treasurer_participant_claim(
},
psyche_solana_treasurer::instruction::ParticipantClaim {
params: psyche_solana_treasurer::logic::ParticipantClaimParams {
user: *user,
claim_earned_points,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ use ts_rs::TS;
AnchorDeserialize,
Serialize,
Deserialize,
PartialEq,
TS,
)]
#[repr(C)]
#[ts(rename = "SolanaClient")]
pub struct Client {
pub id: NodeIdentity,
pub _unused: [u8; 8],
#[ts(type = "number[]")]
pub claimer: Pubkey,
pub earned: u64,
pub slashed: u64,
pub active: u64,
Expand All @@ -35,6 +37,7 @@ impl Debug for Client {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Client")
.field("id", &self.id)
.field("claimer", &self.claimer)
.field("earned", &self.earned)
.field("slashed", &self.slashed)
.field("active", &self.active)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::program_error::ProgramError;
AnchorDeserialize,
Serialize,
Deserialize,
PartialEq,
TS,
)]
#[repr(C)]
Expand All @@ -40,6 +41,7 @@ pub struct ClientsState {
AnchorDeserialize,
Serialize,
Deserialize,
PartialEq,
TS,
)]
#[repr(C)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl RunMetadata {}
Zeroable,
AnchorSerialize,
AnchorDeserialize,
PartialEq,
Serialize,
Deserialize,
TS,
Expand Down Expand Up @@ -332,7 +333,11 @@ impl CoordinatorInstanceState {
Ok(())
}

pub fn join_run(&mut self, id: NodeIdentity) -> Result<()> {
pub fn join_run(
&mut self,
id: NodeIdentity,
claimer: Pubkey,
) -> Result<()> {
let existing =
match self.clients_state.clients.iter_mut().find(|x| x.id == id) {
Some(client) => {
Expand All @@ -357,10 +362,10 @@ impl CoordinatorInstanceState {

let new_client = Client {
id,
claimer,
earned: 0,
slashed: 0,
active: self.clients_state.next_active,
_unused: Default::default(),
};

if self.clients_state.clients.push(new_client).is_err() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ mod program_error;

use anchor_lang::prelude::*;
pub use client::Client;
pub use clients_state::ClientsEpochRates;
pub use clients_state::ClientsState;
pub use instance_state::CoordinatorInstanceState;
pub use instance_state::RunMetadata;
use logic::*;
pub use program_error::ProgramError;
use psyche_coordinator::Committee;
Expand All @@ -27,8 +30,6 @@ use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;

pub use crate::instance_state::RunMetadata;

declare_id!("4SHugWqSXwKE5fqDchkJcPEqnoZE22VYKtSTVm7axbT7");

pub const SOLANA_MAX_NUM_PENDING_CLIENTS: usize = SOLANA_MAX_NUM_CLIENTS;
Expand Down Expand Up @@ -125,15 +126,15 @@ pub fn coordinator_account_from_bytes_mut(

#[account(zero_copy)]
#[repr(C)]
#[derive(Serialize, Deserialize, TS)]
#[derive(Serialize, Deserialize, PartialEq, TS)]
pub struct CoordinatorAccount {
pub version: u64,
pub state: CoordinatorInstanceState,
pub nonce: u64,
}

impl CoordinatorAccount {
pub const VERSION: u64 = 1;
pub const VERSION: u64 = 2;

pub fn space_with_discriminator() -> usize {
CoordinatorAccount::DISCRIMINATOR.len()
Expand Down Expand Up @@ -206,11 +207,21 @@ pub mod psyche_solana_coordinator {
}

account.state.client_version =
FixedString::<96>::try_from(new_version.as_str()).unwrap();
FixedString::try_from(new_version.as_str())
.map_err(|_| ProgramError::FixedStringTooLong)?;
msg!("new version: {}", account.state.client_version);
Ok(())
}

pub fn set_join_authority(
ctx: Context<OwnerCoordinatorAccounts>,
join_authority: Pubkey,
) -> Result<()> {
let account = &mut ctx.accounts.coordinator_instance;
account.join_authority = join_authority;
Ok(())
}

pub fn set_future_epoch_rates(
ctx: Context<OwnerCoordinatorAccounts>,
epoch_earning_rate_total_shared: Option<u64>,
Expand Down Expand Up @@ -327,6 +338,7 @@ pub struct OwnerCoordinatorAccounts<'info> {
pub authority: Signer<'info>,

#[account(
mut,
seeds = [
CoordinatorInstance::SEEDS_PREFIX,
bytes_from_string(&coordinator_instance.run_id)
Expand Down
Loading
Loading