Skip to content

Commit

Permalink
Finish early mono sign when skipping factor (#342)
Browse files Browse the repository at this point in the history
* WIP

* WIP

* Skip factor source when per transaction is empty

* Fix integration tests

* Add missing extension menthods on MnemonicWithPassphrase

* Rename SigningFailure test case

* Distinguish signing failure when factor sources are skipped.

* Add to simulated user mode

* Add --locked to cargo ndk build

* Release 1.1.111

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Generated by cargo-workspaces

* Remove simulated skips from main tests
  • Loading branch information
micbakos-rdx authored Jan 20, 2025
1 parent eca2370 commit 5c4ff91
Show file tree
Hide file tree
Showing 78 changed files with 504 additions and 205 deletions.
166 changes: 83 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/app/home-cards/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "home-cards"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/key-derivation-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "key-derivation-traits"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/radix-connect-models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-connect-models"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/radix-connect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-connect"
version = "1.1.110"
version = "1.1.111"
edition = "2021"


Expand Down
2 changes: 1 addition & 1 deletion crates/app/security-center/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "security-center"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/signing-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "signing-traits"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ impl<S: Signable> SignInteractor<S> for TestSignInteractor<S> {
.clone(),
) {
SigningUserInput::Sign => {
let per_factor_outcome = IndexMap::from_iter(request
.per_factor_source
.iter()
.map(|(id, input)| {
let mut outcomes = IndexMap::<
FactorSourceIDFromHash,
FactorOutcome<S::ID>,
>::new();

for (id, input) in request.per_factor_source.clone() {
if self
.simulated_user
.simulate_skip_if_needed(IndexSet::just(id))
{
let outcome = FactorOutcome::skipped(id);
outcomes.insert(id, outcome);
} else {
let signatures = input.per_transaction
.iter()
.flat_map(|x| {
Expand All @@ -64,10 +73,12 @@ impl<S: Signable> SignInteractor<S> for TestSignInteractor<S> {
})
.collect::<IndexSet<HDSignature<S::ID>>>();

(*id, signatures)
}));
let outcome = FactorOutcome::signed(signatures)?;
outcomes.insert(id, outcome);
}
}

SignResponse::signed(per_factor_outcome)
SignResponse::new_from_outcomes(outcomes)
}

SigningUserInput::Skip => {
Expand Down
31 changes: 31 additions & 0 deletions crates/app/signing-traits/src/testing/simulated_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct SimulatedFailures {
/// Set of FactorSources which should always fail.
simulated_failures: IndexSet<FactorSourceIDFromHash>,
}

impl SimulatedFailures {
pub fn with_details(
simulated_failures: IndexSet<FactorSourceIDFromHash>,
Expand Down Expand Up @@ -82,6 +83,9 @@ pub enum SimulatedUserMode {
/// sources as possible.
Lazy(Laziness),

/// Emulation of a user, that skips specific factor sources.
Skipping(IndexSet<FactorSourceIDFromHash>),

/// Emulation of a user that dismisses (rejects) the signing process all-together.
Rejecting,
}
Expand All @@ -95,6 +99,12 @@ impl SimulatedUserMode {
pub(crate) fn lazy_sign_minimum() -> Self {
Self::Lazy(Laziness::SignMinimum)
}

pub(crate) fn skipping_specific(
factor_sources: IndexSet<FactorSourceIDFromHash>,
) -> Self {
Self::Skipping(factor_sources)
}
}

impl<S: Signable> SimulatedUser<S> {
Expand All @@ -112,6 +122,12 @@ impl<S: Signable> SimulatedUser<S> {
Self::new(SimulatedUserMode::Prudent, simulated_failures)
}

pub fn skipping_specific(
factor_sources: IndexSet<FactorSourceIDFromHash>,
) -> Self {
Self::new(SimulatedUserMode::skipping_specific(factor_sources), None)
}

pub fn lazy_always_skip_no_fail() -> Self {
Self::new(SimulatedUserMode::lazy_always_skip(), None)
}
Expand Down Expand Up @@ -185,6 +201,20 @@ impl<S: Signable> SimulatedUser<S> {
}
}

pub(crate) fn simulate_skip_if_needed(
&self,
factor_source_ids: IndexSet<FactorSourceIDFromHash>,
) -> bool {
match &self.mode {
SimulatedUserMode::Skipping(skipping_factor_source_ids) => {
factor_source_ids
.iter()
.all(|id| skipping_factor_source_ids.contains(id))
}
_ => false,
}
}

fn be_prudent<F>(&self, is_prudent: F) -> bool
where
F: Fn() -> bool,
Expand All @@ -196,6 +226,7 @@ impl<S: Signable> SimulatedUser<S> {
Laziness::SignMinimum => is_prudent(),
},
SimulatedUserMode::Rejecting => false,
SimulatedUserMode::Skipping(_) => false,
}
}
}
2 changes: 1 addition & 1 deletion crates/app/signing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "signing"
version = "1.1.110"
version = "1.1.111"
edition = "2021"


Expand Down
50 changes: 28 additions & 22 deletions crates/app/signing/src/collector/signatures_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,30 +253,33 @@ impl<S: Signable> SignaturesCollector<S> {
"Signature Collector only works with HD FactorSources.",
);

let request = self.request_for_mono_sign(
if let Some(request) = self.request_for_mono_sign(
factor_sources_of_kind.kind,
&factor_source_id,
);

let invalid_transactions = request
.invalid_transactions_if_factor_neglected(&factor_source_id);
if !invalid_transactions.is_empty() {
info!(
"If factor {:?} are neglected, invalid TXs: {:?}",
factor_source_id, invalid_transactions
)
}
) {
let invalid_transactions = request
.invalid_transactions_if_factor_neglected(
&factor_source_id,
);
if !invalid_transactions.is_empty() {
info!(
"If factor {:?} are neglected, invalid TXs: {:?}",
factor_source_id, invalid_transactions
)
}

debug!("Dispatching mono request to interactor: {:?}", request);
// Produce the results from the interactor
let response = self.dependencies.interactor.sign(request).await?;
debug!("Got response from mono interactor: {:?}", response);
debug!("Dispatching mono request to interactor: {:?}", request);
// Produce the results from the interactor
let response =
self.dependencies.interactor.sign(request).await?;
debug!("Got response from mono interactor: {:?}", response);

// Report the results back to the collector
self.process_batch_response(response);
// Report the results back to the collector
self.process_batch_response(response);

if self.continuation() == FinishEarly {
break;
if self.continuation() == FinishEarly {
break;
}
}
}

Expand Down Expand Up @@ -320,8 +323,11 @@ impl<S: Signable> SignaturesCollector<S> {
&self,
factor_source_kind: FactorSourceKind,
factor_source_id: &FactorSourceIDFromHash,
) -> SignRequest<S> {
) -> Option<SignRequest<S>> {
let per_transaction = self.per_transaction_input(factor_source_id);
if per_transaction.is_empty() {
return None;
}

let invalid_transactions_if_neglected = self
.invalid_transactions_if_neglected_factor_sources(IndexSet::just(
Expand All @@ -336,10 +342,10 @@ impl<S: Signable> SignaturesCollector<S> {
invalid_transactions_if_neglected,
);

SignRequest::new(
Some(SignRequest::new(
factor_source_kind,
IndexMap::just((*factor_source_id, per_factor_source_input)),
)
))
}

fn request_for_poly_sign(
Expand Down
2 changes: 1 addition & 1 deletion crates/common/build-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "build-info"
version = "1.1.110"
version = "1.1.111"
edition = "2021"
build = "build.rs"

Expand Down
2 changes: 1 addition & 1 deletion crates/common/bytes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bytes"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/entity-foundation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "entity-foundation"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/host-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "host-info"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/identified-vec-of/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "identified-vec-of"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/metadata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "metadata"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/network/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "network"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/numeric/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "numeric"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/short-string/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "short-string"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/assert-json/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "assert-json"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/collections/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-collections"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/error/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "error"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
3 changes: 3 additions & 0 deletions crates/core/error/src/common_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,9 @@ pub enum CommonError {

#[error("Unknown SecurityStructureID {id}")]
UnknownSecurityStructureID { id: String } = 10246,

#[error("Signing failed due to too many factor sources were neglected.")]
SigningFailedTooManyFactorSourcesNeglected = 10247,
}

impl CommonError {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/has-sample-values/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "has-sample-values"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/misc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-misc"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/prelude/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prelude"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/time-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "time-utils"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-utils"
version = "1.1.110"
version = "1.1.111"
edition = "2021"

[dependencies]
Expand Down
Loading

0 comments on commit 5c4ff91

Please sign in to comment.