Skip to content

Commit

Permalink
don't fetch the nonce when creating a wallet.
Browse files Browse the repository at this point in the history
  • Loading branch information
djordon committed Oct 2, 2024
1 parent 01cad73 commit d3ba8f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
13 changes: 1 addition & 12 deletions signer/src/stacks/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ use crate::storage::model::BitcoinBlockHash;
use crate::storage::DbRead;
use crate::MAX_KEYS;

use super::api::StacksInteract;

/// Stacks multisig addresses are Hash160 hashes of bitcoin Scripts (more
/// or less). The enum value below defines which Script will be used to
/// construct the address, and so implicitly describes how the multisig
Expand Down Expand Up @@ -165,16 +163,7 @@ impl SignerWallet {
let signatures_required = last_key_rotation.signatures_required;
let network_kind = ctx.config().signer.network;

// Create the wallet and properly set the nonce.
let wallet = SignerWallet::new(public_keys, signatures_required, network_kind, 0)?;
// We use the stacks-node as the source of truth for the nonce.
let account_info = ctx
.get_stacks_client()
.get_account(&wallet.address())
.await?;

wallet.set_nonce(account_info.nonce);
Ok(wallet)
SignerWallet::new(public_keys, signatures_required, network_kind, 0)
}

fn hash_mode() -> OrderIndependentMultisigHashMode {
Expand Down
34 changes: 4 additions & 30 deletions signer/src/transaction_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,15 @@ where
async fn handle_stacks_transaction_sign_request(
&mut self,
ctx: &impl Context,
request: &message::StacksTransactionSignRequest,
request: &StacksTransactionSignRequest,
bitcoin_chain_tip: &model::BitcoinBlockHash,
) -> Result<(), Error> {
self.assert_valid_stackstransaction_sign_request(ctx, request, bitcoin_chain_tip)
.await?;

let wallet = self.load_wallet(request, bitcoin_chain_tip).await?;
let wallet = SignerWallet::load(ctx, bitcoin_chain_tip).await?;
wallet.set_nonce(request.nonce);

let multi_sig = MultisigTx::new_tx(&request.contract_call, &wallet, request.tx_fee);
let txid = multi_sig.tx().txid();

Expand All @@ -408,34 +410,6 @@ where
Ok(())
}

/// Load the multi-sig wallet corresponding to the signer set defined
/// in the last key rotation.
/// TODO(255): Add a tests
async fn load_wallet(
&self,
request: &StacksTransactionSignRequest,
bitcoin_chain_tip: &model::BitcoinBlockHash,
) -> Result<SignerWallet, Error> {
let last_key_rotation = self
.storage
.get_last_key_rotation(bitcoin_chain_tip)
.await?
.ok_or(Error::MissingKeyRotation)?;

let public_keys = last_key_rotation.signer_set.as_slice();
let signatures_required = last_key_rotation.signatures_required;
let network_kind = match self.network_kind {
bitcoin::Network::Bitcoin => NetworkKind::Mainnet,
_ => NetworkKind::Testnet,
};
SignerWallet::new(
public_keys,
signatures_required,
network_kind,
request.nonce,
)
}

async fn assert_valid_stackstransaction_sign_request(
&mut self,
ctx: &impl Context,
Expand Down

0 comments on commit d3ba8f3

Please sign in to comment.