Skip to content

Commit

Permalink
Merge pull request #2660 from dusk-network/fix-double-stake
Browse files Browse the repository at this point in the history
rusk-wallet: fix double stake
  • Loading branch information
herr-seppia authored Oct 14, 2024
2 parents 3d52957 + 9904537 commit cc3889b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dusk-bls12_381 = { version = "=0.13.0", default-features = false }
dusk-bytes = "=0.1.7"
dusk-jubjub = { version = "=0.14.1", default-features = false }
dusk-merkle = "=0.5.3"
dusk-plonk = { version = "=0.20.0", default-features = false }
dusk-plonk = { version = "=0.20.2", default-features = false }
dusk-poseidon = "=0.40.0"
jubjub-schnorr = { version = "=0.5.0", default-features = false }

Expand Down
29 changes: 17 additions & 12 deletions rusk-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,15 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {
let mut sender_sk = self.derive_phoenix_sk(addr_idx);
let mut stake_sk = self.derive_bls_sk(addr_idx);

let nonce = state
.fetch_stake(&BlsPublicKey::from(&stake_sk))
.await?
.map(|s| s.nonce)
.unwrap_or(0)
+ 1;
let stake_pk = self.bls_pk(addr_idx)?;
let current_stake = state.fetch_stake(stake_pk).await?;
if let Some(stake) = current_stake {
if stake.amount.is_some() {
return Err(Error::AlreadyStaked);
}
}

let nonce = current_stake.map(|s| s.nonce).unwrap_or(0) + 1;

let inputs = state
.inputs(addr_idx, amt + gas.limit * gas.price)
Expand Down Expand Up @@ -696,12 +699,14 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {
let moonlight_current_nonce =
state.fetch_account(stake_pk).await?.nonce + 1;

let nonce = state
.fetch_stake(stake_pk)
.await?
.map(|s| s.nonce)
.unwrap_or(0)
+ 1;
let current_stake = state.fetch_stake(stake_pk).await?;
if let Some(stake) = current_stake {
if stake.amount.is_some() {
return Err(Error::AlreadyStaked);
}
}

let nonce = current_stake.map(|s| s.nonce).unwrap_or(0) + 1;

let stake = moonlight_stake(
&stake_sk,
Expand Down

0 comments on commit cc3889b

Please sign in to comment.