Keyset counter (#950)

* feat: refresh keysets

* fix(cdk): resolve keyset counter skipping index 0 in deterministic secret generation

- Modified Database::get_keyset_counter to return u32 instead of Option<u32>
- Added database migrations to increment existing keyset counters by 1
- Removed counter increment logic from wallet operations to use actual counter value
- Ensures deterministic secret generation starts from index 0 instead of skipping it
This commit is contained in:
thesimplekid
2025-08-13 08:54:45 +01:00
committed by GitHub
parent 69d0cf0818
commit 5d98fdf353
12 changed files with 70 additions and 18 deletions

View File

@@ -20,4 +20,5 @@ pub static MIGRATIONS: &[(&str, &str, &str)] = &[
("sqlite", "20250616144830_add_keyset_expiry.sql", include_str!(r#"./migrations/sqlite/20250616144830_add_keyset_expiry.sql"#)),
("sqlite", "20250707093445_bolt12.sql", include_str!(r#"./migrations/sqlite/20250707093445_bolt12.sql"#)),
("sqlite", "20250729111701_keyset_v2_u32.sql", include_str!(r#"./migrations/sqlite/20250729111701_keyset_v2_u32.sql"#)),
("sqlite", "20250812084621_keyset_plus_one.sql", include_str!(r#"./migrations/sqlite/20250812084621_keyset_plus_one.sql"#)),
];

View File

@@ -0,0 +1,2 @@
-- Increment keyset counter by 1 where counter > 0
UPDATE keyset SET counter = counter + 1 WHERE counter > 0;

View File

@@ -857,7 +857,7 @@ ON CONFLICT(id) DO UPDATE SET
}
#[instrument(skip(self), fields(keyset_id = %keyset_id))]
async fn get_keyset_counter(&self, keyset_id: &Id) -> Result<Option<u32>, Self::Err> {
async fn get_keyset_counter(&self, keyset_id: &Id) -> Result<u32, Self::Err> {
let conn = self.pool.get().map_err(|e| Error::Database(Box::new(e)))?;
Ok(query(
r#"
@@ -873,7 +873,8 @@ ON CONFLICT(id) DO UPDATE SET
.pluck(&*conn)
.await?
.map(|n| Ok::<_, Error>(column_as_number!(n)))
.transpose()?)
.transpose()?
.unwrap_or(0))
}
#[instrument(skip(self))]