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

Finish early mono sign when skipping factor #342

Merged
merged 11 commits into from
Jan 20, 2025
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 @@
"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

Check warning on line 260 in crates/app/signing/src/collector/signatures_collector.rs

View check run for this annotation

Codecov / codecov/patch

crates/app/signing/src/collector/signatures_collector.rs#L260

Added line #L260 was not covered by tests
.invalid_transactions_if_factor_neglected(
&factor_source_id,

Check warning on line 262 in crates/app/signing/src/collector/signatures_collector.rs

View check run for this annotation

Codecov / codecov/patch

crates/app/signing/src/collector/signatures_collector.rs#L262

Added line #L262 was not covered by tests
);
if !invalid_transactions.is_empty() {

Check warning on line 264 in crates/app/signing/src/collector/signatures_collector.rs

View check run for this annotation

Codecov / codecov/patch

crates/app/signing/src/collector/signatures_collector.rs#L264

Added line #L264 was not covered by tests
info!(
"If factor {:?} are neglected, invalid TXs: {:?}",
factor_source_id, invalid_transactions

Check warning on line 267 in crates/app/signing/src/collector/signatures_collector.rs

View check run for this annotation

Codecov / codecov/patch

crates/app/signing/src/collector/signatures_collector.rs#L267

Added line #L267 was not covered by tests
)
}

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;
matiasbzurovski marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down Expand Up @@ -320,8 +323,11 @@
&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 @@
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
Loading