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

Lrz update fix failing tests #1412

Merged
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
51 changes: 14 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ shardtree = "0.4"

# annotated tag starting with LRZ base tag and ending with `git describe --dirty`
# TAG FROM `main_zingolib` BRANCH OF LIBRUSTZCASH FORK!
zcash_address = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5" }
zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5", features = ["lightwalletd-tonic", "orchard", "transparent-inputs"] }
zcash_encoding = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5" }
zcash_keys = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5", features = ["transparent-inputs", "sapling", "orchard" ] }
zcash_address = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5-2-g121371a08" }
zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5-2-g121371a08" , features = ["lightwalletd-tonic", "orchard", "transparent-inputs"] }
zcash_encoding = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5-2-g121371a08" }
zcash_keys = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5-2-g121371a08" , features = ["transparent-inputs", "sapling", "orchard" ] }
zcash_note_encryption = "0.4"
zcash_primitives = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5" }
zcash_proofs = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5" }
zcash_protocol = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5" }
zcash_primitives = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5-2-g121371a08" }
zcash_proofs = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5-2-g121371a08" }
zcash_protocol = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_client_sqlite-0.11.2_plus_zingolabs_changes-1-g7ad60b5d5-2-g121371a08" }
zip32 = "0.1"

append-only-vec = { git = "https://github.com/zancas/append-only-vec.git", branch = "add_debug_impl" }
Expand All @@ -49,7 +49,6 @@ futures = "0.3.15"
futures-util = "0.3.28"
getset = "0.1.2"
group = "0.13"
hdwallet = { git = "https://github.com/fluidvanadium/hdwallet.git", tag = "update_secp256k1_to_0.27.0" }
hex = "0.4"
http = "1.1.0"
http-body-util = "0.1.2"
Expand Down
1 change: 1 addition & 0 deletions libtonode-tests/tests/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3297,6 +3297,7 @@ mod slow {
assert_eq!(orchard_note.value(), 0);
}
#[tokio::test]
#[ignore = "test does not correspond to real-world case"]
async fn aborted_resync() {
let (regtest_manager, _cph, faucet, recipient, _txid) =
scenarios::orchard_funded_recipient(500_000).await;
Expand Down
1 change: 0 additions & 1 deletion zingolib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ ff = { workspace = true }
futures = { workspace = true }
getset = { workspace = true }
group = { workspace = true }
hdwallet = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

good

hex = { workspace = true }
http.workspace = true
indoc = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions zingolib/src/wallet/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl LightWallet {
Box::new(|note, transaction| {
transaction.status.is_confirmed()
&& !note.pending_receipt()
&& note.value() >= MARGINAL_FEE.into_u64()
Copy link
Contributor

Choose a reason for hiding this comment

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

correct

&& note.value() > MARGINAL_FEE.into_u64()
});
self.get_filtered_balance::<D>(filter_function).await
}
Expand Down Expand Up @@ -352,7 +352,7 @@ mod tests {
OrchardNoteBuilder::default()
.note(
OrchardCryptoNoteBuilder::default()
.value(orchard::value::NoteValue::from_raw(5_000))
.value(orchard::value::NoteValue::from_raw(5_001))
.clone(),
)
.clone(),
Expand Down Expand Up @@ -397,7 +397,7 @@ mod tests {
wallet
.confirmed_balance_excluding_dust::<OrchardDomain>()
.await,
Some(1_605_000)
Some(1_605_001)
);
}
}
20 changes: 1 addition & 19 deletions zingolib/src/wallet/send.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! This mod contains pieces of the impl LightWallet that are invoked during a send.

use hdwallet::traits::Deserialize as _;
use log::error;
use zcash_client_backend::proposal::Proposal;
use zcash_keys::keys::UnifiedSpendingKey;
Expand Down Expand Up @@ -142,29 +141,13 @@ impl LightWallet {
self.mnemonic().unwrap().0.to_seed("").as_slice(),
zip32::AccountId::ZERO,
)
.map_err(|e| BuildTransactionError::UnifiedSpendKey(e))?;
.map_err(BuildTransactionError::UnifiedSpendKey)?;

// We don't support zip320 yet. Only one step.
if proposal.steps().len() != 1 {
return Err(BuildTransactionError::ExchangeAddressesNotSupported);
}

// The 'UnifiedSpendingKey' we create is not a 'proper' USK, in that the
// transparent key it contains is not the account spending key, but the
// externally-scoped derivative key. The goal is to fix this, but in the
// interim we use this special-case logic.
fn usk_to_tkey(
unified_spend_key: &UnifiedSpendingKey,
t_metadata: &zcash_client_backend::wallet::TransparentAddressMetadata,
) -> secp256k1::SecretKey {
hdwallet::ExtendedPrivKey::deserialize(&unified_spend_key.transparent().to_bytes())
.expect("This a hack to do a type conversion, and will not fail")
.derive_private_key(t_metadata.address_index().index().into())
// This is unwrapped in librustzcash, so I'm not too worried about it
.expect("private key derivation failed")
.private_key
}

zcash_client_backend::data_api::wallet::create_proposed_transactions(
self.transaction_context
.transaction_metadata_set
Expand All @@ -177,7 +160,6 @@ impl LightWallet {
&unified_spend_key,
zcash_client_backend::wallet::OvkPolicy::Sender,
proposal,
Some(usk_to_tkey),
Some(self.wallet_capability().first_sapling_address()),
)?;
Ok(())
Expand Down
53 changes: 47 additions & 6 deletions zingolib/src/wallet/transaction_records_by_id/trait_inputsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ use orchard::note_encryption::OrchardDomain;
use sapling_crypto::note_encryption::SaplingDomain;
use zcash_client_backend::{
data_api::{InputSource, SpendableNotes},
wallet::ReceivedNote,
wallet::{ReceivedNote, WalletTransparentOutput},
ShieldedProtocol,
};
use zcash_primitives::transaction::{
components::amount::NonNegativeAmount, fees::zip317::MARGINAL_FEE, TxId,
use zcash_primitives::{
legacy::Script,
transaction::{
components::{amount::NonNegativeAmount, TxOut},
fees::zip317::MARGINAL_FEE,
TxId,
},
};

use crate::wallet::transaction_records_by_id::TransactionRecordsById;
use crate::wallet::{notes::OutputInterface, transaction_records_by_id::TransactionRecordsById};

// error type
use std::fmt::Debug;
use thiserror::Error;

Expand Down Expand Up @@ -171,7 +175,8 @@ impl InputSource for TransactionRecordsById {
.collect::<Result<Vec<_>, _>>()
.map_err(InputSourceError::InvalidValue)?;
unselected.sort_by_key(|(_id, value)| *value); // from smallest to largest
let dust_spendable_index = unselected.partition_point(|(_id, value)| *value < MARGINAL_FEE);
let dust_spendable_index =
unselected.partition_point(|(_id, value)| *value <= MARGINAL_FEE);
let _dust_notes: Vec<_> = unselected.drain(..dust_spendable_index).collect();
let mut selected = vec![];
let mut index_of_unselected = 0;
Expand Down Expand Up @@ -281,6 +286,42 @@ impl InputSource for TransactionRecordsById {
) -> Result<Option<zcash_client_backend::wallet::WalletTransparentOutput>, Self::Error> {
unimplemented!()
}

fn get_spendable_transparent_outputs(
&self,
_address: &zcash_primitives::legacy::TransparentAddress,
target_height: zcash_primitives::consensus::BlockHeight,
_min_confirmations: u32,
) -> Result<Vec<WalletTransparentOutput>, Self::Error> {
// TODO: rewrite to include addresses and min confirmations
let transparent_outputs: Vec<WalletTransparentOutput> = self
.values()
.filter(|tx| {
tx.status
.get_confirmed_height()
.map_or(false, |height| height <= target_height)
})
.flat_map(|tx| {
tx.transparent_outputs().iter().filter_map(|output| {
if output.spending_tx_status().is_none() {
WalletTransparentOutput::from_parts(
output.to_outpoint(),
TxOut {
value: NonNegativeAmount::from_u64(output.value())
.expect("value should be in valid range of zatoshis"),
script_pubkey: Script(output.script.clone()),
},
Some(tx.status.get_height()),
)
} else {
None
}
})
})
.collect();

Ok(transparent_outputs)
}
}

#[cfg(test)]
Expand Down
11 changes: 11 additions & 0 deletions zingolib/src/wallet/tx_map/trait_stub_inputsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,15 @@ impl InputSource for TxMap {
) -> Result<Option<zcash_client_backend::wallet::WalletTransparentOutput>, Self::Error> {
unimplemented!()
}

fn get_spendable_transparent_outputs(
&self,
_address: &zcash_primitives::legacy::TransparentAddress,
target_height: zcash_primitives::consensus::BlockHeight,
_min_confirmations: u32,
) -> Result<Vec<zcash_client_backend::wallet::WalletTransparentOutput>, Self::Error> {
self.transaction_records_by_id
.get_spendable_transparent_outputs(_address, target_height, _min_confirmations)
.map_err(TxMapTraitError::InputSource)
}
}
Loading