Skip to content

Commit

Permalink
chore(storage): remove base64_felts_to_index_prefixed_base32_felts
Browse files Browse the repository at this point in the history
…scalar function
  • Loading branch information
kkovaacs committed Jan 22, 2024
1 parent ce71db7 commit 601bd9d
Showing 1 changed file with 0 additions and 62 deletions.
62 changes: 0 additions & 62 deletions crates/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::sync::Arc;
pub use connection::*;

use pathfinder_common::{BlockHash, BlockNumber};
use rusqlite::functions::FunctionFlags;

use anyhow::Context;
use r2d2::Pool;
Expand Down Expand Up @@ -218,21 +217,6 @@ fn setup_connection(
true,
)?;

connection.create_scalar_function(
"base64_felts_to_index_prefixed_base32_felts",
1,
FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
move |ctx| {
assert_eq!(ctx.len(), 1, "called with unexpected number of arguments");
let base64_felts = ctx
.get_raw(0)
.as_str()
.map_err(|e| rusqlite::Error::UserFunctionError(e.into()))?;

Ok(base64_felts_to_index_prefixed_base32_felts(base64_felts))
},
)?;

match journal_mode {
JournalMode::Rollback => {
// According to the documentation FULL is the recommended setting for rollback mode.
Expand All @@ -247,24 +231,6 @@ fn setup_connection(
Ok(())
}

fn base64_felts_to_index_prefixed_base32_felts(base64_felts: &str) -> String {
let strings = base64_felts
.split(' ')
// Convert only the first 256 elements so that the index fits into one u8
// we will use as a prefix byte.
.take(connection::EVENT_KEY_FILTER_LIMIT)
.enumerate()
.map(|(index, key)| {
let mut buf: [u8; 33] = [0u8; 33];
buf[0] = index as u8;
base64::decode_config_slice(key, base64::STANDARD, &mut buf[1..]).unwrap();
data_encoding::BASE32_NOPAD.encode(&buf)
})
.collect::<Vec<_>>();

strings.join(" ")
}

/// Migrates the database to the latest version. This __MUST__ be called
/// at the beginning of the application.
fn migrate_database(connection: &mut rusqlite::Connection) -> anyhow::Result<()> {
Expand Down Expand Up @@ -365,9 +331,6 @@ fn schema_version(connection: &rusqlite::Connection) -> anyhow::Result<usize> {

#[cfg(test)]
mod tests {
use pathfinder_common::felt;
use pathfinder_crypto::Felt;

use super::*;

#[test]
Expand Down Expand Up @@ -442,31 +405,6 @@ mod tests {
.unwrap_err();
}

#[test]
fn felts_to_index_prefixed_base32_strings() {
let input: String = [felt!("0x901823"), felt!("0x901823"), felt!("0x901825")]
.iter()
.map(|f| base64::encode(f.as_be_bytes()))
.collect::<Vec<_>>()
.join(" ");
assert_eq!(
super::base64_felts_to_index_prefixed_base32_felts(&input),
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASAMCG AEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASAMCG AIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASAMCK".to_owned()
);
}

#[test]
fn felts_to_index_prefixed_base32_strings_encodes_the_first_256_felts() {
let input = [Felt::ZERO; 257]
.iter()
.map(|f| base64::encode(f.as_be_bytes()))
.collect::<Vec<_>>()
.join(" ");
let output = super::base64_felts_to_index_prefixed_base32_felts(&input);

assert_eq!(output.split(' ').count(), 256);
}

#[test]
fn rpc_test_db_is_migrated() {
let mut source_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Expand Down

0 comments on commit 601bd9d

Please sign in to comment.