Skip to content

Commit

Permalink
Merge branch 'master' of github.com:aspectron/rusty-kaspa into rk-pub-15
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Sep 26, 2024
2 parents eed7218 + 4bfa392 commit 0f6a164
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 14 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
cp target/x86_64-unknown-linux-musl/release/kaspad bin/
cp target/x86_64-unknown-linux-musl/release/rothschild bin/
cp target/x86_64-unknown-linux-musl/release/kaspa-wallet bin/
archive="bin/rusty-kaspa-${{ github.event.release.tag_name }}-linux-musl-amd64.zip"
asset_name="rusty-kaspa-${{ github.event.release.tag_name }}-linux-musl-amd64.zip"
archive="bin/rusty-kaspa-${{ github.event.release.tag_name }}-linux-amd64.zip"
asset_name="rusty-kaspa-${{ github.event.release.tag_name }}-linux-amd64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
Expand All @@ -76,12 +76,10 @@ jobs:
shell: bash
run: |
cargo build --bin kaspad --release
cargo build --bin simpa --release
cargo build --bin rothschild --release
cargo build --bin kaspa-wallet --release
mkdir bin || true
cp target/release/kaspad.exe bin/
cp target/release/simpa.exe bin/
cp target/release/rothschild.exe bin/
cp target/release/kaspa-wallet.exe bin/
archive="bin/rusty-kaspa-${{ github.event.release.tag_name }}-win64.zip"
Expand All @@ -94,12 +92,10 @@ jobs:
if: runner.os == 'macOS'
run: |
cargo build --bin kaspad --release
cargo build --bin simpa --release
cargo build --bin rothschild --release
cargo build --bin kaspa-wallet --release
mkdir bin || true
cp target/release/kaspad bin/
cp target/release/simpa bin/
cp target/release/rothschild bin/
cp target/release/kaspa-wallet bin/
archive="bin/rusty-kaspa-${{ github.event.release.tag_name }}-osx.zip"
Expand Down
76 changes: 70 additions & 6 deletions rothschild/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use kaspa_rpc_core::{api::rpc::RpcApi, notify::mode::NotificationMode, RpcUtxoEn
use kaspa_txscript::pay_to_address_script;
use parking_lot::Mutex;
use rayon::prelude::*;
use secp256k1::{rand::thread_rng, Keypair};
use secp256k1::{
rand::{thread_rng, Rng},
Keypair,
};
use tokio::time::{interval, MissedTickBehavior};

const DEFAULT_SEND_AMOUNT: u64 = 10 * SOMPI_PER_KASPA;
Expand All @@ -40,6 +43,9 @@ pub struct Args {
pub rpc_server: String,
pub threads: u8,
pub unleashed: bool,
pub addr: Option<String>,
pub priority_fee: u64,
pub randomize_fee: bool,
}

impl Args {
Expand All @@ -51,6 +57,9 @@ impl Args {
rpc_server: m.get_one::<String>("rpcserver").cloned().unwrap_or("localhost:16210".to_owned()),
threads: m.get_one::<u8>("threads").cloned().unwrap(),
unleashed: m.get_one::<bool>("unleashed").cloned().unwrap_or(false),
addr: m.get_one::<String>("addr").cloned(),
priority_fee: m.get_one::<u64>("priority-fee").cloned().unwrap_or(0),
randomize_fee: m.get_one::<bool>("randomize-fee").cloned().unwrap_or(false),
}
}
}
Expand Down Expand Up @@ -85,6 +94,25 @@ pub fn cli() -> Command {
.help("The number of threads to use for TX generation. Set to 0 to use 1 thread per core. Default is 2."),
)
.arg(Arg::new("unleashed").long("unleashed").action(ArgAction::SetTrue).hide(true).help("Allow higher TPS"))
.arg(Arg::new("addr").long("to-addr").short('a').value_name("addr").help("address to send to"))
.arg(
Arg::new("priority-fee")
.long("priority-fee")
.short('f')
.value_name("priority-fee")
.default_value("0")
.value_parser(clap::value_parser!(u64))
.help("Transaction priority fee"),
)
.arg(
Arg::new("randomize-fee")
.long("randomize-fee")
.short('r')
.value_name("randomize-fee")
.action(ArgAction::SetTrue)
.default_value("false")
.help("Randomize transaction priority fee"),
)
}

async fn new_rpc_client(subscription_context: &SubscriptionContext, address: &str) -> GrpcClient {
Expand All @@ -111,6 +139,11 @@ struct ClientPoolArg {
utxos_len: usize,
}

struct TxsFeeConfig {
priority_fee: u64,
randomize_fee: bool,
}

#[tokio::main]
async fn main() {
kaspa_core::log::init_logger(None, "");
Expand Down Expand Up @@ -150,9 +183,31 @@ async fn main() {

let kaspa_addr = Address::new(ADDRESS_PREFIX, ADDRESS_VERSION, &schnorr_key.x_only_public_key().0.serialize());

let kaspa_to_addr = args.addr.as_ref().map_or_else(|| kaspa_addr.clone(), |addr_str| Address::try_from(addr_str.clone()).unwrap());

let fee_config = TxsFeeConfig { priority_fee: args.priority_fee, randomize_fee: args.randomize_fee };

rayon::ThreadPoolBuilder::new().num_threads(args.threads as usize).build_global().unwrap();

info!("Using Rothschild with private key {} and address {}", schnorr_key.display_secret(), String::from(&kaspa_addr));
let mut log_message = format!(
"Using Rothschild with:\n\
\tprivate key: {}\n\
\tfrom address: {}",
schnorr_key.display_secret(),
String::from(&kaspa_addr)
);
if args.addr.is_some() {
log_message.push_str(&format!("\n\tto address: {}", String::from(&kaspa_to_addr)));
}
if args.priority_fee != 0 {
log_message.push_str(&format!(
"\n\tpriority fee: {} SOMPS {}",
fee_config.priority_fee,
if fee_config.randomize_fee { "[randomize]" } else { "" }
));
}
info!("{}", log_message);

let info = rpc_client.get_block_dag_info().await.unwrap();
let coinbase_maturity = match info.network.suffix {
Some(11) => TESTNET11_PARAMS.coinbase_maturity,
Expand Down Expand Up @@ -249,13 +304,14 @@ async fn main() {
let has_funds = maybe_send_tx(
txs_to_send,
&tx_sender,
kaspa_addr.clone(),
kaspa_to_addr.clone(),
&mut utxos,
&mut pending,
schnorr_key,
stats.clone(),
maximize_inputs,
&mut next_available_utxo_index,
&fee_config,
)
.await;
if !has_funds {
Expand Down Expand Up @@ -369,6 +425,7 @@ async fn maybe_send_tx(
stats: Arc<Mutex<Stats>>,
maximize_inputs: bool,
next_available_utxo_index: &mut usize,
fee_config: &TxsFeeConfig,
) -> bool {
let num_outs = if maximize_inputs { 1 } else { 2 };

Expand All @@ -377,7 +434,7 @@ async fn maybe_send_tx(
let selected_utxos_groups = (0..txs_to_send)
.map(|_| {
let (selected_utxos, selected_amount) =
select_utxos(utxos, DEFAULT_SEND_AMOUNT, num_outs, maximize_inputs, next_available_utxo_index);
select_utxos(utxos, DEFAULT_SEND_AMOUNT, num_outs, maximize_inputs, next_available_utxo_index, fee_config);
if selected_amount == 0 {
return None;
}
Expand Down Expand Up @@ -473,22 +530,29 @@ fn select_utxos(
num_outs: u64,
maximize_utxos: bool,
next_available_utxo_index: &mut usize,
fee_config: &TxsFeeConfig,
) -> (Vec<(TransactionOutpoint, UtxoEntry)>, u64) {
const MAX_UTXOS: usize = 84;
let mut selected_amount: u64 = 0;
let mut selected = Vec::new();
let mut rng = thread_rng();

while next_available_utxo_index < &mut utxos.len() {
let (outpoint, entry) = utxos[*next_available_utxo_index].clone();
selected_amount += entry.amount;
selected.push((outpoint, entry));

let fee = required_fee(selected.len(), num_outs);
let priority_fee = if fee_config.randomize_fee && fee_config.priority_fee > 0 {
rng.gen_range(0..fee_config.priority_fee)
} else {
fee_config.priority_fee
};

*next_available_utxo_index += 1;

if selected_amount >= min_amount + fee && (!maximize_utxos || selected.len() == MAX_UTXOS) {
return (selected, selected_amount - fee);
if selected_amount >= min_amount + fee + priority_fee && (!maximize_utxos || selected.len() == MAX_UTXOS) {
return (selected, selected_amount - fee - priority_fee);
}

if selected.len() > MAX_UTXOS {
Expand Down
2 changes: 1 addition & 1 deletion rpc/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ NOTE: This error usually indicates an RPC conversion error between the node and
.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, Some(batch_size))
.await?;
// bound added to the length of the accepted transaction ids, which is bounded by merged blocks
virtual_chain_batch.added = virtual_chain_batch.added[..accepted_transaction_ids.len()].to_vec();
virtual_chain_batch.added.truncate(accepted_transaction_ids.len());
accepted_transaction_ids
} else {
vec![]
Expand Down
2 changes: 1 addition & 1 deletion wallet/pskt/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ where
V: Eq + Clone,
K: Ord + Clone,
{
if lhs.len() > rhs.len() {
if lhs.len() >= rhs.len() {
if let Some((field, rhs, lhs)) =
rhs.iter().map(|(k, v)| (k, v, lhs.get(k))).find(|(_, v, rhs_v)| rhs_v.is_some_and(|rv| rv != *v))
{
Expand Down

0 comments on commit 0f6a164

Please sign in to comment.