Skip to content

Commit 4f1572f

Browse files
authored
Merge pull request #1945 from mintlayer/bridge_related_minor_changes2
Bridge-related minor changes
2 parents 4d118f3 + 51a3f3b commit 4f1572f

File tree

3 files changed

+65
-16
lines changed

3 files changed

+65
-16
lines changed

wallet/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,8 @@ tempfile.workspace = true
5353
[features]
5454
trezor = ["dep:trezor-client", "wallet-types/trezor"]
5555
enable-trezor-device-tests = []
56+
# Note: currently this is used in certain external tests (in particular, in the bridge), so we only
57+
# allow it for regtest. TODO: it's better to have some regtest-specific options for the wallet,
58+
# similar to what we have for the node.
59+
use-deterministic-signatures-in-software-signer-for-regtest = []
5660
default = ["trezor"]

wallet/src/signer/software_signer/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use itertools::Itertools;
1919

2020
use common::{
2121
chain::{
22+
config::ChainType,
2223
htlc::HtlcSecret,
2324
signature::{
2425
inputsig::{
@@ -46,7 +47,7 @@ use common::{
4647
use crypto::key::{
4748
extended::{ExtendedPrivateKey, ExtendedPublicKey},
4849
hdkd::{derivable::Derivable, u31::U31},
49-
PrivateKey, SigAuxDataProvider,
50+
PredefinedSigAuxDataProvider, PrivateKey, SigAuxDataProvider,
5051
};
5152
use randomness::make_true_rng;
5253
use wallet_storage::{
@@ -76,7 +77,22 @@ pub struct SoftwareSigner {
7677

7778
impl SoftwareSigner {
7879
pub fn new(chain_config: Arc<ChainConfig>, account_index: U31) -> Self {
79-
Self::new_with_sig_aux_data_provider(chain_config, account_index, Box::new(make_true_rng()))
80+
let use_deterministic_signer = *chain_config.chain_type() == ChainType::Regtest
81+
&& cfg!(feature = "use-deterministic-signatures-in-software-signer-for-regtest");
82+
83+
if use_deterministic_signer {
84+
Self::new_with_sig_aux_data_provider(
85+
chain_config,
86+
account_index,
87+
Box::new(PredefinedSigAuxDataProvider),
88+
)
89+
} else {
90+
Self::new_with_sig_aux_data_provider(
91+
chain_config,
92+
account_index,
93+
Box::new(make_true_rng()),
94+
)
95+
}
8096
}
8197

8298
pub fn new_with_sig_aux_data_provider(

wallet/types/src/partially_signed_transaction.rs

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ use common::{
3232
Signable, Transactable,
3333
},
3434
tokens::TokenId,
35-
ChainConfig, Destination, OrderId, PoolId, SighashInputCommitmentVersion,
36-
SignedTransaction, Transaction, TransactionCreationError, TxInput, TxOutput,
35+
AccountCommand, ChainConfig, Destination, OrderAccountCommand, OrderId, PoolId,
36+
SighashInputCommitmentVersion, SignedTransaction, Transaction, TransactionCreationError,
37+
TxInput, TxOutput,
3738
},
3839
primitives::{Amount, BlockHeight},
3940
};
@@ -160,6 +161,14 @@ impl TxAdditionalInfo {
160161
self.order_info.get(order_id)
161162
}
162163

164+
pub fn token_info_iter(&self) -> impl Iterator<Item = (&'_ TokenId, &'_ TokenAdditionalInfo)> {
165+
self.token_info.iter()
166+
}
167+
168+
pub fn pool_info_iter(&self) -> impl Iterator<Item = (&'_ PoolId, &'_ PoolAdditionalInfo)> {
169+
self.pool_info.iter()
170+
}
171+
163172
pub fn order_info_iter(&self) -> impl Iterator<Item = (&'_ OrderId, &'_ OrderAdditionalInfo)> {
164173
self.order_info.iter()
165174
}
@@ -211,31 +220,51 @@ pub struct PartiallySignedTransaction {
211220
}
212221

213222
impl PartiallySignedTransaction {
214-
pub fn new(
223+
pub fn new_unchecked(
215224
tx: Transaction,
216225
witnesses: Vec<Option<InputWitness>>,
217226
input_utxos: Vec<Option<TxOutput>>,
218227
destinations: Vec<Option<Destination>>,
219228
htlc_secrets: Option<Vec<Option<HtlcSecret>>>,
220229
additional_info: TxAdditionalInfo,
221-
) -> Result<Self, PartiallySignedTransactionError> {
230+
) -> Self {
222231
let htlc_secrets = htlc_secrets.unwrap_or_else(|| vec![None; tx.inputs().len()]);
223232

224-
let this = Self {
233+
Self {
225234
tx,
226235
witnesses,
227236
input_utxos,
228237
destinations,
229238
htlc_secrets,
230239
additional_info,
231-
};
240+
}
241+
}
232242

233-
this.ensure_consistency()?;
243+
pub fn new(
244+
tx: Transaction,
245+
witnesses: Vec<Option<InputWitness>>,
246+
input_utxos: Vec<Option<TxOutput>>,
247+
destinations: Vec<Option<Destination>>,
248+
htlc_secrets: Option<Vec<Option<HtlcSecret>>>,
249+
additional_info: TxAdditionalInfo,
250+
) -> Result<Self, PartiallySignedTransactionError> {
251+
let this = Self::new_unchecked(
252+
tx,
253+
witnesses,
254+
input_utxos,
255+
destinations,
256+
htlc_secrets,
257+
additional_info,
258+
);
234259

260+
this.ensure_consistency(Self::need_heavy_consistency_checks())?;
235261
Ok(this)
236262
}
237263

238-
pub fn ensure_consistency(&self) -> Result<(), PartiallySignedTransactionError> {
264+
pub fn ensure_consistency(
265+
&self,
266+
with_heavy_checks: bool,
267+
) -> Result<(), PartiallySignedTransactionError> {
239268
ensure!(
240269
self.tx.inputs().len() == self.witnesses.len(),
241270
PartiallySignedTransactionError::InvalidWitnessCount
@@ -256,18 +285,18 @@ impl PartiallySignedTransaction {
256285
PartiallySignedTransactionError::InvalidHtlcSecretsCount
257286
);
258287

259-
#[cfg(debug_assertions)]
260-
{
288+
if with_heavy_checks {
261289
self.ensure_additional_info_completeness()?;
262290
}
263291

264292
Ok(())
265293
}
266294

267-
#[cfg(debug_assertions)]
268-
fn ensure_additional_info_completeness(&self) -> Result<(), PartiallySignedTransactionError> {
269-
use common::chain::{AccountCommand, OrderAccountCommand};
295+
fn need_heavy_consistency_checks() -> bool {
296+
cfg!(debug_assertions)
297+
}
270298

299+
fn ensure_additional_info_completeness(&self) -> Result<(), PartiallySignedTransactionError> {
271300
let ensure_order_info_present =
272301
|order_id: &OrderId| -> Result<_, PartiallySignedTransactionError> {
273302
ensure!(
@@ -387,7 +416,7 @@ impl PartiallySignedTransaction {
387416
witnesses: Vec<Option<InputWitness>>,
388417
) -> Result<Self, PartiallySignedTransactionError> {
389418
self.witnesses = witnesses;
390-
self.ensure_consistency()?;
419+
self.ensure_consistency(Self::need_heavy_consistency_checks())?;
391420
Ok(self)
392421
}
393422

0 commit comments

Comments
 (0)