Skip to content

Commit

Permalink
Merge pull request #4 from radixdlt/neglected
Browse files Browse the repository at this point in the history
Skipped | Failed -> Rejected.
  • Loading branch information
CyonAlexRDX authored Aug 29, 2024
2 parents a1d0cdc + 20fec99 commit 5340aec
Show file tree
Hide file tree
Showing 30 changed files with 608 additions and 314 deletions.
3 changes: 3 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
default.extend-ignore-identifiers-re = [
"[Hh][Dd][[:alnum:]]*"
]
4 changes: 4 additions & 0 deletions src/derivation/collector/key_derivation_outcome.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use crate::prelude::*;

/// A collection of all `HierarchicalDeterministicFactorInstance`
/// (Public Keys) which were derived from the referenced
/// `FactorSource`s at the specified `DerivationPath`s
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct KeyDerivationOutcome {
pub factors_by_source:
IndexMap<FactorSourceIDFromHash, IndexSet<HierarchicalDeterministicFactorInstance>>,
}

impl KeyDerivationOutcome {
pub fn new(
factors_by_source: IndexMap<
Expand Down
51 changes: 22 additions & 29 deletions src/signing/collector/signatures_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl SignaturesCollector {
Continue
}

async fn use_factor_sources(&self, factor_sources_of_kind: &FactorSourcesOfKind) -> Result<()> {
async fn sign_with_factors_of_kind(&self, factor_sources_of_kind: FactorSourcesOfKind) {
let interactor = self
.dependencies
.interactors
Expand All @@ -161,15 +161,15 @@ impl SignaturesCollector {
.map(|f| f.factor_source_id())
.collect(),
);
if !request.invalid_transactions_if_skipped.is_empty() {
if !request.invalid_transactions_if_neglected.is_empty() {
info!(
"If factors {:?} are skipped, invalid TXs: {:?}",
"If factors {:?} are neglected, invalid TXs: {:?}",
request.per_factor_source.keys(),
request.invalid_transactions_if_skipped
request.invalid_transactions_if_neglected
)
}
debug!("Dispatching parallel request to interactor: {:?}", request);
let response = interactor.sign(request).await?;
let response = interactor.sign(request).await;
debug!("Got response from parallel interactor: {:?}", response);
self.process_batch_response(response);
}
Expand All @@ -185,16 +185,17 @@ impl SignaturesCollector {
let request =
self.request_for_serial_interactor(&factor_source.factor_source_id());

if !request.invalid_transactions_if_skipped.is_empty() {
if !request.invalid_transactions_if_neglected.is_empty() {
info!(
"If factor {:?} are skipped, invalid TXs: {:?}",
request.input.factor_source_id, request.invalid_transactions_if_skipped
"If factor {:?} are neglected, invalid TXs: {:?}",
request.input.factor_source_id,
request.invalid_transactions_if_neglected
)
}

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

// Report the results back to the collector
Expand All @@ -206,17 +207,6 @@ impl SignaturesCollector {
}
}
}
Ok(())
}

async fn sign_with_factors_of_kind(&self, factor_sources_of_kind: FactorSourcesOfKind) {
let Err(e) = self.use_factor_sources(&factor_sources_of_kind).await else {
return;
};
error!("Failure using factor {:?}", e);
self.process_batch_response(SignWithFactorSourceOrSourcesOutcome::Skipped {
ids_of_skipped_factors_sources: factor_sources_of_kind.factor_source_ids(),
})
}

/// In decreasing "friction order"
Expand Down Expand Up @@ -256,7 +246,7 @@ impl SignaturesCollector {

SerialBatchSigningRequest::new(
batch_signing_request,
self.invalid_transactions_if_skipped_factor_sources(IndexSet::from_iter([
self.invalid_transactions_if_neglected_factor_sources(IndexSet::from_iter([
*factor_source_id,
]))
.into_iter()
Expand All @@ -274,27 +264,30 @@ impl SignaturesCollector {
.map(|fid| (*fid, self.input_for_interactor(fid)))
.collect::<IndexMap<FactorSourceIDFromHash, BatchTXBatchKeySigningRequest>>();

let invalid_transactions_if_skipped =
self.invalid_transactions_if_skipped_factor_sources(factor_source_ids);
let invalid_transactions_if_neglected =
self.invalid_transactions_if_neglected_factor_sources(factor_source_ids);

info!("Invalid if skipped: {:?}", invalid_transactions_if_skipped);
info!(
"Invalid if neglected: {:?}",
invalid_transactions_if_neglected
);

// Prepare the request for the interactor
ParallelBatchSigningRequest::new(per_factor_source, invalid_transactions_if_skipped)
ParallelBatchSigningRequest::new(per_factor_source, invalid_transactions_if_neglected)
}

fn invalid_transactions_if_skipped_factor_sources(
fn invalid_transactions_if_neglected_factor_sources(
&self,
factor_source_ids: IndexSet<FactorSourceIDFromHash>,
) -> IndexSet<InvalidTransactionIfSkipped> {
) -> IndexSet<InvalidTransactionIfNeglected> {
self.state
.borrow()
.petitions
.borrow()
.invalid_transactions_if_skipped_factors(factor_source_ids)
.invalid_transactions_if_neglected_factors(factor_source_ids)
}

fn process_batch_response(&self, response: SignWithFactorSourceOrSourcesOutcome) {
fn process_batch_response(&self, response: SignWithFactorsOutcome) {
let state = self.state.borrow_mut();
let petitions = state.petitions.borrow_mut();
petitions.process_batch_response(response)
Expand Down
26 changes: 26 additions & 0 deletions src/signing/collector/signing_finish_early_strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,30 @@ impl SigningFinishEarlyStrategy {
when_some_transaction_is_invalid,
}
}

pub fn r#continue() -> Self {
Self::new(
WhenAllTransactionsAreValid(SignaturesCollectingContinuation::Continue),
WhenSomeTransactionIsInvalid(SignaturesCollectingContinuation::Continue),
)
}
}

#[cfg(test)]
mod tests {
use super::*;
type Sut = SigningFinishEarlyStrategy;

#[test]
fn test_continue() {
let sut = Sut::r#continue();
assert_eq!(
sut.when_all_transactions_are_valid.0,
SignaturesCollectingContinuation::Continue
);
assert_eq!(
sut.when_some_transaction_is_invalid.0,
SignaturesCollectingContinuation::Continue
);
}
}
6 changes: 3 additions & 3 deletions src/signing/interactors/parallel_batch_signing_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ pub struct ParallelBatchSigningRequest {

/// A collection of transactions which would be invalid if the user skips
/// signing with this factor source.
pub invalid_transactions_if_skipped: IndexSet<InvalidTransactionIfSkipped>,
pub invalid_transactions_if_neglected: IndexSet<InvalidTransactionIfNeglected>,
}

impl ParallelBatchSigningRequest {
pub fn new(
per_factor_source: IndexMap<FactorSourceIDFromHash, BatchTXBatchKeySigningRequest>,
invalid_transactions_if_skipped: IndexSet<InvalidTransactionIfSkipped>,
invalid_transactions_if_neglected: IndexSet<InvalidTransactionIfNeglected>,
) -> Self {
Self {
per_factor_source,
invalid_transactions_if_skipped,
invalid_transactions_if_neglected,
}
}
}
10 changes: 5 additions & 5 deletions src/signing/interactors/serial_batch_signing_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ use crate::prelude::*;
/// A batch signing request used with a SignWithFactorSerialInteractor, containing
/// a collection of transactions to sign with multiple keys (derivation paths),
/// and a collection of transactions which would be invalid if the user skips
/// signing with this factor source.
/// signing with this factor source, or if we fail to sign.
#[derive(derive_more::Debug)]
#[debug("input: {:#?}", input)]
pub struct SerialBatchSigningRequest {
pub input: BatchTXBatchKeySigningRequest,
/// A collection of transactions which would be invalid if the user skips
/// signing with this factor source.
pub invalid_transactions_if_skipped: Vec<InvalidTransactionIfSkipped>,
/// signing with this factor source, or if we fail to sign
pub invalid_transactions_if_neglected: Vec<InvalidTransactionIfNeglected>,
}

impl SerialBatchSigningRequest {
pub fn new(
input: BatchTXBatchKeySigningRequest,
invalid_transactions_if_skipped: Vec<InvalidTransactionIfSkipped>,
invalid_transactions_if_neglected: Vec<InvalidTransactionIfNeglected>,
) -> Self {
Self {
input,
invalid_transactions_if_skipped,
invalid_transactions_if_neglected,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ use crate::prelude::*;
/// Example of a Parallel Batch Signing Driver is that for DeviceFactorSource.
#[async_trait::async_trait]
pub trait SignWithFactorParallelInteractor {
async fn sign(
&self,
request: ParallelBatchSigningRequest,
) -> Result<SignWithFactorSourceOrSourcesOutcome>;
async fn sign(&self, request: ParallelBatchSigningRequest) -> SignWithFactorsOutcome;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ use crate::prelude::*;
/// might not even even allow multiple SecurityQuestionsFactorSources to be used).
#[async_trait::async_trait]
pub trait SignWithFactorSerialInteractor {
async fn sign(
&self,
request: SerialBatchSigningRequest,
) -> Result<SignWithFactorSourceOrSourcesOutcome>;
async fn sign(&self, request: SerialBatchSigningRequest) -> SignWithFactorsOutcome;
}
Loading

0 comments on commit 5340aec

Please sign in to comment.