Skip to content

Commit

Permalink
Merge pull request #2579 from dusk-network/fix-key-representation
Browse files Browse the repository at this point in the history
rusk-wallet: Fix Phoenix key representation
  • Loading branch information
HDauven authored Oct 3, 2024
2 parents 8f7bd68 + 1752b16 commit d252836
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
26 changes: 15 additions & 11 deletions rusk-wallet/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::collections::BTreeSet;
use std::path::Path;

use dusk_bytes::DeserializableSlice;
use dusk_bytes::{DeserializableSlice, Serializable};
use execution_core::transfer::phoenix::NoteLeaf;
use rocksdb::{DBWithThreadMode, MultiThreaded, Options};

Expand Down Expand Up @@ -50,15 +50,15 @@ impl Cache {
// representation of the tuple (NoteHeight, Note)
pub(crate) fn insert(
&self,
pk: &PhoenixPublicKey,
pk_bs58: &str,
block_height: u64,
note_data: (Note, BlsScalar),
) -> Result<(), Error> {
let cf_name = format!("{:?}", pk);
let cf_name = pk_bs58;

let cf = self
.db
.cf_handle(&cf_name)
.cf_handle(cf_name)
.ok_or(Error::CacheDatabaseCorrupted)?;

let (note, nullifier) = note_data;
Expand All @@ -80,11 +80,11 @@ impl Cache {
// representation of the tuple (NoteHeight, Note)
pub(crate) fn insert_spent(
&self,
pk: &PhoenixPublicKey,
pk_bs58: &str,
block_height: u64,
note_data: (Note, BlsScalar),
) -> Result<(), Error> {
let cf_name = format!("spent_{:?}", pk);
let cf_name = format!("spent_{pk_bs58}");

let cf = self
.db
Expand All @@ -111,8 +111,11 @@ impl Cache {
if nullifiers.is_empty() {
return Ok(());
}
let cf_name = format!("{:?}", pk);
let spent_cf_name = format!("spent_{:?}", pk);

let pk_bs58 = bs58::encode(pk.to_bytes()).into_string();

let spent_cf_name = format!("spent_{pk_bs58}");
let cf_name = pk_bs58;

let cf = self
.db
Expand Down Expand Up @@ -157,7 +160,7 @@ impl Cache {
&self,
pk: &PhoenixPublicKey,
) -> Result<Vec<BlsScalar>, Error> {
let cf_name = format!("{:?}", pk);
let cf_name = bs58::encode(pk.to_bytes()).into_string();
let mut notes = vec![];

if let Some(cf) = self.db.cf_handle(&cf_name) {
Expand All @@ -181,7 +184,7 @@ impl Cache {
&self,
pk: &PhoenixPublicKey,
) -> Result<BTreeSet<NoteLeaf>, Error> {
let cf_name = format!("{:?}", pk);
let cf_name = bs58::encode(pk.to_bytes()).into_string();
let mut notes = BTreeSet::<NoteLeaf>::new();

if let Some(cf) = self.db.cf_handle(&cf_name) {
Expand All @@ -207,7 +210,8 @@ impl Cache {
&self,
pk: &PhoenixPublicKey,
) -> Result<Vec<(BlsScalar, NoteLeaf)>, Error> {
let cf_name = format!("spent_{:?}", pk);
let pk_bs58 = bs58::encode(pk.to_bytes()).into_string();
let cf_name = format!("spent_{pk_bs58}");
let mut notes = vec![];

if let Some(cf) = self.db.cf_handle(&cf_name) {
Expand Down
4 changes: 3 additions & 1 deletion rusk-wallet/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ impl State {
let pk: PhoenixPublicKey =
derive_phoenix_pk(store.get_seed(), i as u8);

[format!("{:?}", pk), format!("spent_{:?}", pk)]
let pk = bs58::encode(pk.to_bytes()).into_string();

[pk.clone(), format!("spent_{pk}")]
})
.collect();

Expand Down
5 changes: 3 additions & 2 deletions rusk-wallet/src/clients/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub(crate) async fn sync_db(
}

for (sk, vk, pk) in keys.iter() {
let pk_bs58 = bs58::encode(pk.to_bytes()).into_string();
for (block_height, note) in note_data.iter() {
if vk.owns(note.stealth_address()) {
let nullifier = note.gen_nullifier(sk);
Expand All @@ -95,8 +96,8 @@ pub(crate) async fn sync_db(
let note = (note.clone(), nullifier);

match spent {
true => cache.insert_spent(pk, *block_height, note),
false => cache.insert(pk, *block_height, note),
true => cache.insert_spent(&pk_bs58, *block_height, note),
false => cache.insert(&pk_bs58, *block_height, note),
}?;
}
}
Expand Down

0 comments on commit d252836

Please sign in to comment.