Skip to content
Merged
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
4 changes: 2 additions & 2 deletions contrib/ledger-gen/run_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def first_cluster_validator(expected_shred_version, expected_genesis_hash,
vote_pubkey = await get_pubkey(vote_key, solana_source_directory)

process = await asyncio.create_subprocess_shell(
f"{solana_binary('agave-validator', solana_source_directory)} --enable-rpc-transaction-history --allow-private-addr --identity {identity_key} --ledger {ledger_path} --limit-ledger-size 100000000 --dynamic-port-range 8000-8100 --no-snapshot-fetch --no-poh-speed-test --no-os-network-limits-test --vote-account {vote_pubkey} --expected-shred-version {expected_shred_version} --expected-genesis-hash {expected_genesis_hash} --no-wait-for-vote-to-start-leader --no-incremental-snapshots --full-snapshot-interval-slots {snapshot_interval} --maximum-full-snapshots-to-retain {snapshots_to_retain} --rpc-port 8899 --gossip-port 8010 --full-rpc-api --tpu-enable-udp --log {ledger_path}/validator.log",
f"{solana_binary('agave-validator', solana_source_directory)} --enable-rpc-transaction-history --allow-private-addr --identity {identity_key} --ledger {ledger_path} --limit-ledger-size 100000000 --dynamic-port-range 8000-8100 --no-snapshot-fetch --no-poh-speed-test --no-os-network-limits-test --vote-account {vote_pubkey} --expected-shred-version {expected_shred_version} --expected-genesis-hash {expected_genesis_hash} --no-wait-for-vote-to-start-leader --no-incremental-snapshots --full-snapshot-interval-slots {snapshot_interval} --snapshot-interval-slots {snapshot_interval} --maximum-full-snapshots-to-retain {snapshots_to_retain} --rpc-port 8899 --gossip-port 8010 --full-rpc-api --tpu-enable-udp --log {ledger_path}/validator.log",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
Expand Down Expand Up @@ -180,7 +180,7 @@ async def spawn_solana_cluster(nodes, output_dir, solana_source_directory, tick_
)
stdout, _ = await process.communicate()

if os.path.exists(os.path.join(output_dir, "node-ledger-0", "snapshot", str(snapshot_interval), "state_complete")):
if os.path.exists(os.path.join(output_dir, "node-ledger-0", "snapshot", str(snapshot_interval), "state_complete")) or os.path.exists(os.path.join(output_dir, "node-ledger-0", "snapshots", str(snapshot_interval), "state_complete")):
break
await asyncio.sleep(1)

Expand Down
8 changes: 8 additions & 0 deletions contrib/ledger-gen/src/ledgers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use {
};

use crate::bpf_loader;
use crate::stake;

/// CI Link: gs://firedancer-ci-resources/v18multi-bpf-loader.tar.gz
pub fn bpf_loader_ledger(client: &RpcClient, arc_client: &Arc<RpcClient>, payer: &Keypair, program_data: &Vec<u8>, account_data: &Vec<u8>) {
Expand All @@ -29,3 +30,10 @@ pub fn bpf_loader_ledger(client: &RpcClient, arc_client: &Arc<RpcClient>, payer:
bpf_loader::close_redeploy_same_slot(&client, &arc_client, &payer, &program_data, &account_data);
bpf_loader::close_redeploy_diff_slot(&client, &arc_client, &payer, &program_data, &account_data);
}

/// CI Link: gs://firedancer-ci-resources/v203-move-stake.tar.gz
/// CI Link: gs://firedancer-ci-resources/v203-move-lamports.tar.gz
pub fn stake_ledger(client: &RpcClient, payer: &Keypair) {
// stake::move_stake(&client, &payer);
stake::move_lamports(&client, &payer);
}
4 changes: 3 additions & 1 deletion contrib/ledger-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod utils;

mod bpf_loader;
mod nonce;
mod stake;

/// Workflow for Creating Ledgers
/// * Set up all buffer accounts
Expand Down Expand Up @@ -53,5 +54,6 @@ fn main() {
let account_data = vec![0u8; 4];

// ----------------------- ONLY CHANGE BELOW THIS LINE -----------------------
ledgers::bpf_loader_ledger(&rpc_client, &arc_client, &payer, &program_data, &account_data);
// ledgers::bpf_loader_ledger(&rpc_client, &arc_client, &payer, &program_data, &account_data);
ledgers::stake_ledger(&rpc_client, &payer);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing this every time on a one-off basis, we should have a deterministic script we can run to generate all the test ledgers. Then we can just add to this in PRs. I think this file is basically that with some tweaks.

}
130 changes: 130 additions & 0 deletions contrib/ledger-gen/src/stake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
use {
solana_sdk::{
signature::{Keypair, Signer, read_keypair_file},
commitment_config::{CommitmentConfig},
feature::{self, Feature},
feature_set,
nonce::{State as NonceState},
system_instruction,
system_program,
message::Message,
transaction::Transaction,
stake::{
self,
instruction::{self as stake_instruction, LockupArgs, StakeError},
state::{
Authorized, Lockup, Meta, StakeActivationStatus, StakeAuthorize, StakeStateV2,
},
tools::{acceptable_reference_epoch_credits, eligible_for_deactivate_delinquent},
},
},
solana_client::{
rpc_client::{RpcClient},
},
solana_rpc_client_nonce_utils::{get_account_with_commitment, nonblocking},
solana_cli::{
spend_utils::{SpendAmount, resolve_spend_tx_and_check_account_balance},
}
};

use crate::instructions;
use crate::utils;

pub fn move_lamports(client: &RpcClient, payer: &Keypair) {
let from_stake_account = Keypair::new();

let authorized = Authorized {
staker: payer.pubkey(),
withdrawer: payer.pubkey(),
};

let create_from_stake_account_instruction = stake_instruction::create_account_checked(
&payer.pubkey(),
&from_stake_account.pubkey(),
&authorized,
1000000000,
);

let transaction = utils::create_message_and_sign(&create_from_stake_account_instruction, &payer, vec![&payer, &from_stake_account], client.get_latest_blockhash().unwrap());
let _ = client.send_and_confirm_transaction(&transaction).unwrap();
println!("Created From Stake Account {:?} - Slot: {:?}", from_stake_account.pubkey(), client.get_slot_with_commitment(CommitmentConfig::processed()).unwrap());

let to_stake_account = Keypair::new();

let create_to_stake_account_instruction = stake_instruction::create_account_checked(
&payer.pubkey(),
&to_stake_account.pubkey(),
&authorized,
1000000000,
);

let transaction = utils::create_message_and_sign(&create_to_stake_account_instruction, &payer, vec![&payer, &to_stake_account], client.get_latest_blockhash().unwrap());
let _ = client.send_and_confirm_transaction(&transaction).unwrap();
println!("Created To Stake Account {:?} - Slot: {:?}", to_stake_account.pubkey(), client.get_slot_with_commitment(CommitmentConfig::processed()).unwrap());

let move_lamports_instruction = vec![stake_instruction::move_lamports(
&from_stake_account.pubkey(),
&to_stake_account.pubkey(),
&payer.pubkey(),
10000000,
)];
let transaction = utils::create_message_and_sign(&move_lamports_instruction, &payer, vec![&payer], client.get_latest_blockhash().unwrap());
let _ = client.send_and_confirm_transaction(&transaction).unwrap();
println!("Moved Lamport from {:?} to {:?} - Slot: {:?}", from_stake_account.pubkey(), to_stake_account.pubkey(), client.get_slot_with_commitment(CommitmentConfig::processed()).unwrap());
}

pub fn move_stake(client: &RpcClient, payer: &Keypair) {
let from_stake_account = Keypair::new();

let authorized = Authorized {
staker: payer.pubkey(),
withdrawer: payer.pubkey(),
};

let create_from_stake_account_instructions = stake_instruction::create_account_checked(
&payer.pubkey(),
&from_stake_account.pubkey(),
&authorized,
1000000000,
);

let transaction = utils::create_message_and_sign(&create_from_stake_account_instructions, &payer, vec![&payer, &from_stake_account], client.get_latest_blockhash().unwrap());
let _ = client.send_and_confirm_transaction(&transaction).unwrap();
println!("Created From Stake Account {:?} - Slot: {:?}", from_stake_account.pubkey(), client.get_slot_with_commitment(CommitmentConfig::processed()).unwrap());

let voter = read_keypair_file("/data/kbhargava/ledgers/ledger-gen-cluster/keys-0/vote.json").unwrap();

let delegate_stake_account_instruction = vec![stake_instruction::delegate_stake(
&from_stake_account.pubkey(),
&payer.pubkey(),
&voter.pubkey(),
)];
let transaction = utils::create_message_and_sign(&delegate_stake_account_instruction, &payer, vec![&payer], client.get_latest_blockhash().unwrap());
let _ = client.send_and_confirm_transaction(&transaction).unwrap();
println!("Delegated Stake Account {:?} to {:?} - Slot: {:?}", from_stake_account.pubkey(), voter.pubkey(), client.get_slot_with_commitment(CommitmentConfig::processed()).unwrap());

let to_stake_account = Keypair::new();

let create_to_stake_account_instruction = stake_instruction::create_account_checked(
&payer.pubkey(),
&to_stake_account.pubkey(),
&authorized,
1000000000,
);

let transaction = utils::create_message_and_sign(&create_to_stake_account_instruction, &payer, vec![&payer, &to_stake_account], client.get_latest_blockhash().unwrap());
let _ = client.send_and_confirm_transaction(&transaction).unwrap();
println!("Created To Stake Account {:?} - Slot: {:?}", to_stake_account.pubkey(), client.get_slot_with_commitment(CommitmentConfig::processed()).unwrap());

utils::wait_atleast_n_slots(&client, 1000);
let move_lamports_instruction = vec![stake_instruction::move_stake(
&from_stake_account.pubkey(),
&to_stake_account.pubkey(),
&payer.pubkey(),
100000000,
)];

let transaction = utils::create_message_and_sign(&move_lamports_instruction, &payer, vec![&payer], client.get_latest_blockhash().unwrap());
let _ = client.send_and_confirm_transaction(&transaction).unwrap();
println!("Moved Stake from {:?} to {:?} - Slot: {:?}", from_stake_account.pubkey(), to_stake_account.pubkey(), client.get_slot_with_commitment(CommitmentConfig::processed()).unwrap());
}
7 changes: 7 additions & 0 deletions src/flamenco/features/fd_features_generated.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,11 @@ fd_feature_id_t const ids[] = {
/* zkhiy5oLowR7HY4zogXjCjeMXyruLqBwSWH21qcFtnv */
.name = "zk_elgamal_proof_program_enabled" },

{ .index = offsetof(fd_features_t, move_stake_and_move_lamports_ixs)>>3,
.id = {"\x61\xf9\x9e\xbb\xb5\x47\x90\x0b\xb6\x5d\x66\x44\xb8\x45\xca\x36\xc5\xaf\x9f\x6f\xe1\x6d\x73\x7e\x83\x64\xb5\x59\x1c\x46\x2b\x63"},
/* 7bTK6Jis8Xpfrs8ZoUfiMDPazTcdPcTWheZFJTA5Z6X4 */
.name = "move_stake_and_move_lamports_ixs" },

{ .index = ULONG_MAX }
};

Expand Down Expand Up @@ -1342,6 +1347,7 @@ fd_feature_id_query( ulong prefix ) {
case 0xafe148ad652172dd: return &ids[ 197 ];
case 0x91a7af96555ea309: return &ids[ 198 ];
case 0x8e1411a93085cb0e: return &ids[ 199 ];
case 0x0b9047b5bb9ef961: return &ids[ 200 ];
default: break;
}

Expand Down Expand Up @@ -1550,5 +1556,6 @@ FD_STATIC_ASSERT( offsetof( fd_features_t, simplify_alt_bn128_syscall_error_code
FD_STATIC_ASSERT( offsetof( fd_features_t, abort_on_invalid_curve )>>3==197UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, ed25519_precompile_verify_strict )>>3==198UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, zk_elgamal_proof_program_enabled )>>3==199UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, move_stake_and_move_lamports_ixs )>>3==200UL, layout );

FD_STATIC_ASSERT( sizeof( fd_features_t )>>3==FD_FEATURE_ID_CNT, layout );
3 changes: 2 additions & 1 deletion src/flamenco/features/fd_features_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/* FEATURE_ID_CNT is the number of features in ids */

#define FD_FEATURE_ID_CNT (200UL)
#define FD_FEATURE_ID_CNT (201UL)

union fd_features {

Expand Down Expand Up @@ -213,6 +213,7 @@ union fd_features {
/* 0xafe148ad652172dd */ ulong abort_on_invalid_curve;
/* 0x91a7af96555ea309 */ ulong ed25519_precompile_verify_strict;
/* 0x8e1411a93085cb0e */ ulong zk_elgamal_proof_program_enabled;
/* 0x0b9047b5bb9ef961 */ ulong move_stake_and_move_lamports_ixs;
};

};
3 changes: 2 additions & 1 deletion src/flamenco/features/feature_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,6 @@
{"name":"simplify_alt_bn128_syscall_error_codes","pubkey": "JDn5q3GBeqzvUa7z67BbmVHVdE3EbUAjvFep3weR3jxX","cleaned_up":1180,"comment":"only impl the activated path"},
{"name":"abort_on_invalid_curve","pubkey":"FuS3FPfJDKSNot99ECLXtp3rueq36hMNStJkPJwWodLh"},
{"name":"ed25519_precompile_verify_strict","pubkey":"ed9tNscbWLYBooxWA7FE2B5KHWs8A6sxfY8EzezEcoo","cleaned_up":2000,"comment":"only impl the activated path"},
{"name":"zk_elgamal_proof_program_enabled","pubkey":"zkhiy5oLowR7HY4zogXjCjeMXyruLqBwSWH21qcFtnv"}
{"name":"zk_elgamal_proof_program_enabled","pubkey":"zkhiy5oLowR7HY4zogXjCjeMXyruLqBwSWH21qcFtnv"},
{"name":"move_stake_and_move_lamports_ixs","pubkey":"7bTK6Jis8Xpfrs8ZoUfiMDPazTcdPcTWheZFJTA5Z6X4"}
]
Loading