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

broadcast insistor #1645

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
ad676b7
Merge branch 'darkside_eviction_simulator' into worktree_broadcast_in…
fluidvanadium Jan 8, 2025
6eee1a0
set up insistor loop
fluidvanadium Jan 8, 2025
90a11c8
moved it
fluidvanadium Jan 8, 2025
a45e857
re-arranged complete_and_broadcast result (a list of txids now record…
fluidvanadium Jan 8, 2025
b435258
added a hook to grab the replacement txids
fluidvanadium Jan 8, 2025
d4cfb61
get_send_result now matches sibling functions
fluidvanadium Jan 8, 2025
b30bac3
working through changing the broadcast_created_transactions return va…
fluidvanadium Jan 8, 2025
9ac9a18
ee
fluidvanadium Jan 8, 2025
58e81de
thanks clippy
fluidvanadium Jan 8, 2025
eb66268
add send_result to with_assertions
fluidvanadium Jan 8, 2025
bdb85b5
added error handling
fluidvanadium Jan 8, 2025
69f913f
get_send_result now matches sibling functions
fluidvanadium Jan 8, 2025
02c2951
remove naive insistor function
fluidvanadium Jan 8, 2025
96cfbc4
sibling naming
fluidvanadium Jan 8, 2025
2e92164
assertions and comments
fluidvanadium Jan 9, 2025
0bb3d1d
Merge branch 'worktree_add_sync_result_to_test_framework' into worktr…
fluidvanadium Jan 9, 2025
acf9cbe
varname
fluidvanadium Jan 9, 2025
1eec094
helperized reidentify_tx
fluidvanadium Jan 9, 2025
d9d5e14
refactored txid_comparison
fluidvanadium Jan 9, 2025
8f5d2e2
refactor
fluidvanadium Jan 9, 2025
1e45bcc
some refactors
fluidvanadium Jan 10, 2025
fa97de8
re-ordered methods
fluidvanadium Jan 10, 2025
a544ee0
and re-ordered errors
fluidvanadium Jan 10, 2025
58ef079
refactored get_latest_block_height
fluidvanadium Jan 10, 2025
f863717
refactored broadcast_created_transactions to take a reference
fluidvanadium Jan 10, 2025
b8fac84
remove unused import
fluidvanadium Jan 10, 2025
cf4b1c4
rescue prelimary loop from git
fluidvanadium Jan 10, 2025
6723940
stopped using a no-longer helpful helper
fluidvanadium Jan 13, 2025
8f06f49
added parameters to start_broadcast_loop
fluidvanadium Jan 13, 2025
0602066
fill broadcast loop, part 1
fluidvanadium Jan 13, 2025
d0dd7e7
filled broadcast loop, part 2
fluidvanadium Jan 15, 2025
e2c3a4a
added get_record and GetRecordError
fluidvanadium Jan 15, 2025
3d5d695
filled broadcast loop, part 3
fluidvanadium Jan 15, 2025
223c891
filled broadcast loop, part 4
fluidvanadium Jan 15, 2025
d44cc6a
SendProgress tweak
fluidvanadium Jan 15, 2025
bd45082
filled broadcast loop, part 5
fluidvanadium Jan 15, 2025
c956d55
simplified a return type and removed a check
fluidvanadium Jan 15, 2025
7aca557
dbg printlns
fluidvanadium Jan 15, 2025
be65509
clarified when the broadcast loop ends
fluidvanadium Jan 15, 2025
e51399c
refactor for clarity
fluidvanadium Jan 15, 2025
ba80b4f
debug wip
fluidvanadium Jan 25, 2025
44c6bbc
added simple_send test
fluidvanadium Jan 25, 2025
70441bb
new helper
fluidvanadium Jan 26, 2025
572f5c1
improved transmission flow
fluidvanadium Jan 27, 2025
bec327a
cleanup: distinguish broadcast (multiple) from transmit (single messa…
fluidvanadium Jan 27, 2025
6782fc5
clip
fluidvanadium Jan 27, 2025
6a05f55
error PartialEq
fluidvanadium Jan 27, 2025
c90b256
place initial send before beginning confirmation loop
fluidvanadium Jan 28, 2025
72b0f94
added simple_send_darkside and adjusting darkside rules
fluidvanadium Feb 2, 2025
237250f
improved darkside logic
fluidvanadium Feb 2, 2025
c642ba5
comment
fluidvanadium Feb 2, 2025
8e88527
provisional improvement to darkside chain_generic setup
fluidvanadium Feb 2, 2025
b3f5d39
made a compromise to test conditions
fluidvanadium Feb 2, 2025
9887764
carefully refactoring
fluidvanadium Feb 2, 2025
57016a2
carefully refactored
fluidvanadium Feb 2, 2025
eb7b58a
improved send_result info
fluidvanadium Feb 2, 2025
17bc98a
disable darkside mempool testing
fluidvanadium Feb 2, 2025
616214d
helperized send_result comparison. I see here that send_result needs …
fluidvanadium Feb 2, 2025
26ec506
update glorygoddess test wallet
fluidvanadium Feb 3, 2025
cd5d2e8
fixed txid choice and also fixed final expect
fluidvanadium Feb 3, 2025
5d3802e
opened SendProgress function. Mobile developer confirms its not curre…
fluidvanadium Feb 3, 2025
cb14aa0
move initial broadcast up a level and added comment
fluidvanadium Feb 3, 2025
a808b12
Merge remote-tracking branch 'labs/dev' into worktree_broadcast_insistor
fluidvanadium Feb 3, 2025
c99c2d7
unfold glory_goddess_send_to_self
fluidvanadium Feb 3, 2025
425346e
add server_uri to LiveChain ConductChain struct
fluidvanadium Feb 3, 2025
38b53f0
comments and used test chain to successfully run a glory_goddess_send
fluidvanadium Feb 3, 2025
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
17 changes: 11 additions & 6 deletions darkside-tests/src/chain_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ use zingolib::testutils::int_to_shieldedprotocol;

use crate::utils::scenarios::DarksideEnvironment;

#[tokio::test]
async fn simple_send_darkside() {
fixtures::simple_send::<DarksideEnvironment>(10_000, false).await;
}

proptest! {
#![proptest_config(proptest::test_runner::Config::with_cases(4))]
#[test]
Expand Down Expand Up @@ -50,12 +55,14 @@ pub(crate) mod conduct_chain {
/// doesnt use the full extent of DarksideEnvironment, preferring to rely on server truths when ever possible.
impl ConductChain for DarksideEnvironment {
async fn setup() -> Self {
let elf = DarksideEnvironment::new(None).await;
let mut elf = DarksideEnvironment::new(None).await;
elf.stage_transaction(ABANDON_TO_DARKSIDE_SAP_10_000_000_ZAT)
.await;
elf.darkside_connector
.stage_blocks_create(1, 1, 0)
.stage_blocks_create(2, 1, 0)
.await
.unwrap();
elf.darkside_connector.apply_staged(1).await.unwrap();
elf.darkside_connector.apply_staged(2).await.unwrap();
elf
}

Expand All @@ -65,8 +72,6 @@ pub(crate) mod conduct_chain {
}

async fn create_faucet(&mut self) -> LightClient {
self.stage_transaction(ABANDON_TO_DARKSIDE_SAP_10_000_000_ZAT)
.await;
let zingo_config = self
.client_builder
.make_unique_data_dir_and_load_config(self.regtest_network);
Expand All @@ -87,7 +92,7 @@ pub(crate) mod conduct_chain {

async fn bump_chain(&mut self) {
let height_before =
zingolib::grpc_connector::get_latest_block(self.lightserver_uri().unwrap())
zingolib::grpc_connector::get_latest_block(&self.lightserver_uri().unwrap())
.await
.unwrap()
.height;
Expand Down
14 changes: 7 additions & 7 deletions darkside-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use testvectors::seeds::DARKSIDE_SEED;
use tokio::time::sleep;
use zcash_client_backend::PoolType::Shielded;
use zcash_client_backend::ShieldedProtocol::Orchard;
use zcash_primitives::consensus::BlockHeight;
use zingo_status::confirmation_status::ConfirmationStatus;
use zingolib::config::RegtestNetwork;
use zingolib::get_base_address_macro;
Expand All @@ -18,6 +17,7 @@ use zingolib::lightclient::LightClient;
use zingolib::lightclient::PoolBalances;
use zingolib::testutils;
use zingolib::testutils::chain_generics::conduct_chain::ConductChain;
use zingolib::testutils::chain_generics::with_assertions::validate_send_result;
use zingolib::testutils::scenarios::setup::ClientBuilder;
use zingolib::wallet::notes::query::OutputQuery;

Expand Down Expand Up @@ -276,15 +276,15 @@ async fn transaction_disappears_before_mempool() {

// a modified zingolib::testutils::chain_generics::with_assertions::follow_proposal block
{
let txids = validate_send_result(&primary, txids).await.unwrap();

let sender = &primary;
let proposal = &proposal;

let server_height_at_send = BlockHeight::from(
grpc_connector::get_latest_block(environment.lightserver_uri().unwrap())
let server_height_at_send =
crate::grpc_connector::get_latest_block_height(&environment.lightserver_uri().unwrap())
.await
.unwrap()
.height as u32,
);
.unwrap();

// check that each record has the expected fee and status, returning the fee
let (sender_recorded_fees, (sender_recorded_outputs, sender_recorded_statuses)): (
Expand Down Expand Up @@ -362,7 +362,7 @@ async fn transaction_disappears_before_mempool() {
for status in sender_confirmed_statuses {
assert_eq!(
status,
ConfirmationStatus::Transmitted(server_height_at_send + 1)
ConfirmationStatus::Confirmed(server_height_at_send + 1)
);
}
}
Expand Down
8 changes: 8 additions & 0 deletions libtonode-tests/tests/chain_generics.proptest-regressions
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 64d91b23be1001070c6f03675388fb561aa34ca6cd9cac36b6f4850675789787 # shrinks to send_value = 0, sender_protocol = 1, receiver_pool = 0
cc 0ad075771292fafd9cc5ae2a40401290d91e1829f4ad9e8e7fd636f7fd00db6e # shrinks to send_value = 0, change_value = 3383, sender_protocol = 1, receiver_pool = 1
6 changes: 6 additions & 0 deletions libtonode-tests/tests/chain_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ use zingolib::testutils::{
int_to_pooltype, int_to_shieldedprotocol,
};

#[tokio::test]
async fn simple_send_libtonode() {
fixtures::simple_send::<LibtonodeEnvironment>(10_000, true).await;
}

proptest::proptest! {
#![proptest_config(proptest::test_runner::Config::with_cases(4))]
#[ignore = "hangs"]
Expand All @@ -21,6 +26,7 @@ proptest::proptest! {
}
}

// extra mod. to be removed, and tests coalesced
mod chain_generics {
use zcash_client_backend::PoolType::Shielded;
use zcash_client_backend::PoolType::Transparent;
Expand Down
35 changes: 35 additions & 0 deletions zingolib/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//! This is a mod for data structs that will be used across all sections of zingolib.

use zcash_primitives::transaction::TxId;

use crate::utils::conversion::TxIdFromHexEncodedStrError;
pub mod proposal;
pub mod witness_trees;

Expand Down Expand Up @@ -66,3 +70,34 @@ pub mod receivers {
TransactionRequest::new(payments)
}
}

#[allow(missing_docs)] // error types document themselves
#[derive(Clone, Debug, thiserror::Error, PartialEq)]
pub enum TxIdComparisonError {
#[error("Server returned TxId [{0}] which fails to decode with error: [{1:?}].")]
InvalidTxId(String, TxIdFromHexEncodedStrError),
/// please note that this error contains two arguments of the same type. Its possible to cause bugs by interpreting them in the opposite order.
#[error("Server returned TxId: [{0:?}], which does not match expected [{1:?}].")]
InconsistentTxId(TxId, TxId),
}

pub(crate) fn txid_comparison(
reported_string_txid: String,
original_txid: &TxId,
) -> Result<TxId, TxIdComparisonError> {
match crate::utils::conversion::txid_from_hex_encoded_str(reported_string_txid.as_str()) {
Ok(reported_txid) => {
if *original_txid != reported_txid {
{
Err(TxIdComparisonError::InconsistentTxId(
reported_txid,
*original_txid,
))
}
} else {
Ok(reported_txid)
}
}
Err(e) => Err(TxIdComparisonError::InvalidTxId(reported_string_txid, e)),
}
}
9 changes: 8 additions & 1 deletion zingolib/src/grpc_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub async fn get_trees(uri: http::Uri, height: u64) -> Result<TreeState, String>
}

/// get_latest_block GRPC call
pub async fn get_latest_block(uri: http::Uri) -> Result<BlockId, String> {
pub async fn get_latest_block(uri: &http::Uri) -> Result<BlockId, String> {
let client = Arc::new(GrpcConnector::new(uri.clone()));
let mut client = client
.get_client()
Expand All @@ -341,6 +341,13 @@ pub async fn get_latest_block(uri: http::Uri) -> Result<BlockId, String> {
Ok(response.into_inner())
}

/// ask LightWalletD server for latest block height
pub async fn get_latest_block_height(uri: &http::Uri) -> Result<BlockHeight, String> {
Ok(BlockHeight::from_u32(
get_latest_block(uri).await?.height as u32,
))
}

/// TODO: Add Doc Comment Here!
pub async fn send_transaction(
uri: http::Uri,
Expand Down
29 changes: 14 additions & 15 deletions zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,22 @@ pub struct LightWalletSendProgress {
impl LightWalletSendProgress {
/// TODO: Add Doc Comment Here!
pub fn to_json(&self) -> JsonValue {
let last_result = self.progress.last_result.clone();
let tx_ids: Vec<String> = match &last_result {
Some(r) => {
let mut binding = r.clone().unwrap();
let binding = binding.as_array_mut();
let tx_json_values: Vec<String> = binding
.unwrap()
.iter()
.map(|x| x.as_str().unwrap().to_string())
.collect();
tx_json_values
}
None => vec![],
let opt_last_result = self.progress.last_result.clone();

let (tx_ids, error): (Vec<String>, Option<String>) = match &opt_last_result {
Some(last_result) => match last_result {
Ok(txids) => (
txids
.iter()
.map(|txid| txid.to_string())
.collect::<Vec<String>>(),
None,
),
Err(e) => (vec![], Some(e.to_string())),
},
None => (vec![], None),
};

let error: Option<String> = last_result.and_then(|result| result.err());

object! {
"id" => self.progress.id,
"sending" => self.progress.is_send_in_progress,
Expand Down
Loading