Skip to content

Commit

Permalink
Merge pull request #1715 from eqlabs/krisztian/remove-casm-compiler-v…
Browse files Browse the repository at this point in the history
…ersion

fix(compiler,storage): remove CASM compiler version info
  • Loading branch information
kkovaacs authored Jan 31, 2024
2 parents 2306dbf + 4a41ef2 commit 70e8ed1
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 171 deletions.
7 changes: 0 additions & 7 deletions crates/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,3 @@ serde_json = { workspace = true, features = [

[dev-dependencies]
starknet-gateway-test-fixtures = { path = "../gateway-test-fixtures" }

[build-dependencies]
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = [
"arbitrary_precision",
"raw_value",
] }
61 changes: 0 additions & 61 deletions crates/compiler/build.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use std::borrow::Cow;
use anyhow::Context;
use pathfinder_common::StarknetVersion;

pub const COMPILER_VERSION: &str = env!("SIERRA_CASM_COMPILER_VERSION");

/// Compile a Sierra class definition into CASM.
///
/// The class representation expected by the compiler doesn't match the representation used
Expand Down
1 change: 0 additions & 1 deletion crates/pathfinder/src/state/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ async fn consumer(mut events: Receiver<SyncEvent>, context: ConsumerContext) ->
&sierra_definition,
&casm_hash,
&casm_definition,
pathfinder_compiler::COMPILER_VERSION,
)
.context("Inserting sierra class")?;
tx.commit().context("Committing database transaction")
Expand Down
Binary file modified crates/rpc/fixtures/mainnet.sqlite
Binary file not shown.
3 changes: 1 addition & 2 deletions crates/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ pub mod test_utils {
&sierra_class_definition,
&casm_hash_bytes!(b"non-existent"),
&[],
"compiler version 123",
)
.unwrap();
db_txn
Expand Down Expand Up @@ -741,7 +740,7 @@ pub mod test_utils {
}

for (sierra, casm) in state_update_copy.declared_sierra_classes {
tx.insert_sierra_class(&sierra, b"sierra def", &casm, b"casm def", "test version")
tx.insert_sierra_class(&sierra, b"sierra def", &casm, b"casm def")
.unwrap();
}

Expand Down
20 changes: 4 additions & 16 deletions crates/rpc/src/v05/method/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,8 @@ mod tests {

let mut connection = context.storage.connection().unwrap();
let tx = connection.transaction().unwrap();
tx.insert_sierra_class(
&sierra_hash,
sierra_definition,
&casm_hash,
casm_definition,
"2.0.2",
)
.unwrap();
tx.insert_sierra_class(&sierra_hash, sierra_definition, &casm_hash, casm_definition)
.unwrap();
tx.commit().unwrap();

drop(connection);
Expand Down Expand Up @@ -431,14 +425,8 @@ mod tests {
let mut connection = context.storage.connection().unwrap();
let tx = connection.transaction().unwrap();

tx.insert_sierra_class(
&sierra_hash,
sierra_definition,
&casm_hash,
casm_definition,
"2.0.0",
)
.unwrap();
tx.insert_sierra_class(&sierra_hash, sierra_definition, &casm_hash, casm_definition)
.unwrap();

let header = BlockHeader::builder()
.with_number(block_number)
Expand Down
1 change: 0 additions & 1 deletion crates/rpc/src/v05/method/estimate_message_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ mod tests {
CAIRO_1_1_0_BALANCE_SIERRA_JSON,
&casm_hash!("0x0484c163658bcce5f9916f486171ac60143a92897533aa7ff7ac800b16c63311"),
CAIRO_1_1_0_BALANCE_CASM_JSON,
"cairo-lang-starknet 1.1.0",
)
.expect("insert class");

Expand Down
2 changes: 0 additions & 2 deletions crates/rpc/src/v05/method/trace_block_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ pub(crate) mod tests {
fixtures::SIERRA_DEFINITION,
&fixtures::CASM_HASH,
fixtures::CASM_DEFINITION,
"compiler version",
)?;

let next_block_header = BlockHeader::builder()
Expand Down Expand Up @@ -425,7 +424,6 @@ pub(crate) mod tests {
fixtures::SIERRA_DEFINITION,
&fixtures::CASM_HASH,
fixtures::CASM_DEFINITION,
"compiler version",
)?;

let dummy_receipt: Receipt = Receipt {
Expand Down
1 change: 0 additions & 1 deletion crates/rpc/src/v06/method/estimate_message_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ mod tests {
CAIRO_1_1_0_BALANCE_SIERRA_JSON,
&casm_hash!("0x0484c163658bcce5f9916f486171ac60143a92897533aa7ff7ac800b16c63311"),
CAIRO_1_1_0_BALANCE_CASM_JSON,
"cairo-lang-starknet 1.1.0",
)
.expect("insert class");

Expand Down
2 changes: 0 additions & 2 deletions crates/rpc/src/v06/method/trace_block_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ pub(crate) mod tests {
fixtures::SIERRA_DEFINITION,
&fixtures::CASM_HASH,
fixtures::CASM_DEFINITION,
"compiler version",
)?;

let next_block_header = BlockHeader::builder()
Expand Down Expand Up @@ -445,7 +444,6 @@ pub(crate) mod tests {
fixtures::SIERRA_DEFINITION,
&fixtures::CASM_HASH,
fixtures::CASM_DEFINITION,
"compiler version",
)?;

let dummy_receipt: Receipt = Receipt {
Expand Down
2 changes: 0 additions & 2 deletions crates/storage/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,13 @@ impl<'inner> Transaction<'inner> {
sierra_definition: &[u8],
casm_hash: &CasmHash,
casm_definition: &[u8],
compiler_version: &str,
) -> anyhow::Result<()> {
class::insert_sierra_class(
self,
sierra_hash,
sierra_definition,
casm_hash,
casm_definition,
compiler_version,
)
}

Expand Down
77 changes: 5 additions & 72 deletions crates/storage/src/connection/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub(super) fn insert_sierra_class(
sierra_definition: &[u8],
casm_hash: &CasmHash,
casm_definition: &[u8],
compiler_version: &str,
) -> anyhow::Result<()> {
let mut compressor = zstd::bulk::Compressor::new(10).context("Creating zstd compressor")?;
let sierra_definition = compressor
Expand All @@ -19,9 +18,6 @@ pub(super) fn insert_sierra_class(
.compress(casm_definition)
.context("Compressing casm definition")?;

let version_id = intern_compiler_version(transaction, compiler_version)
.context("Interning compiler version")?;

transaction
.inner()
.execute(
Expand All @@ -34,14 +30,13 @@ pub(super) fn insert_sierra_class(
.inner()
.execute(
r"INSERT OR REPLACE INTO casm_definitions
(hash, definition, compiled_class_hash, compiler_version_id)
(hash, definition, compiled_class_hash)
VALUES
(:hash, :definition, :compiled_class_hash, :compiler_version_id)",
(:hash, :definition, :compiled_class_hash)",
named_params! {
":hash": sierra_hash,
":definition": &casm_definition,
":compiled_class_hash": casm_hash,
":compiler_version_id": &version_id,
},
)
.context("Inserting casm definition")?;
Expand Down Expand Up @@ -70,40 +65,6 @@ pub(super) fn insert_cairo_class(
Ok(())
}

fn intern_compiler_version(
transaction: &Transaction<'_>,
compiler_version: &str,
) -> anyhow::Result<i64> {
let id: Option<i64> = transaction
.inner()
.query_row(
"SELECT id FROM casm_compiler_versions WHERE version = ?",
[compiler_version],
|r| Ok(r.get_unwrap(0)),
)
.optional()
.context("Querying for an existing casm compiler version")?;

let id = if let Some(id) = id {
id
} else {
// sqlite "autoincrement" for integer primary keys works like this: we leave it out of
// the insert, even though it's not null, it will get max(id)+1 assigned, which we can
// read back with last_insert_rowid

transaction
.inner()
.query_row(
"INSERT INTO casm_compiler_versions(version) VALUES (?) RETURNING id",
[compiler_version],
|row| row.get(0),
)
.context("Inserting unique casm_compiler_version")?
};

Ok(id)
}

/// Returns whether or not the given class definitions exist.
pub(super) fn classes_exist(
transaction: &Transaction<'_>,
Expand Down Expand Up @@ -520,29 +481,6 @@ mod tests {
assert_eq!(result, expected);
}

#[test]
fn compiler_version_interning() {
let mut connection = Storage::in_memory().unwrap().connection().unwrap();
let transaction = connection.transaction().unwrap();

let alpha = intern_compiler_version(&transaction, "alpha").unwrap();
let alpha_again = intern_compiler_version(&transaction, "alpha").unwrap();
assert_eq!(alpha, alpha_again);

let beta = intern_compiler_version(&transaction, "beta").unwrap();
assert_ne!(alpha, beta);

let beta_again = intern_compiler_version(&transaction, "beta").unwrap();
assert_eq!(beta, beta_again);

for i in 0..10 {
intern_compiler_version(&transaction, i.to_string().as_str()).unwrap();
}

let alpha_again2 = intern_compiler_version(&transaction, "alpha").unwrap();
assert_eq!(alpha, alpha_again2);
}

#[test]
fn insert_cairo() {
let mut connection = Storage::in_memory().unwrap().connection().unwrap();
Expand All @@ -567,22 +505,20 @@ mod tests {
let casm_hash = casm_hash_bytes!(b"casm hash");
let sierra_definition = b"example sierra program";
let casm_definition = b"compiled sierra program";
let version = "compiler version";

insert_sierra_class(
&tx,
&sierra_hash,
sierra_definition,
&casm_hash,
casm_definition,
version,
)
.unwrap();

let casm_result = tx
.inner().query_row(
.inner()
.query_row(
r"SELECT * FROM casm_definitions
JOIN casm_compiler_versions ON casm_definitions.compiler_version_id = casm_compiler_versions.id
WHERE hash = ?",
params![&sierra_hash],
|row| {
Expand All @@ -592,16 +528,13 @@ mod tests {
let casm_definition = row.get_blob("definition").unwrap().to_vec();
let casm_definition = zstd::decode_all(casm_definition.as_slice()).unwrap();

let version: String = row.get("version").unwrap();

Ok((casm_hash, casm_definition, version))
Ok((casm_hash, casm_definition))
},
)
.unwrap();

assert_eq!(casm_result.0, casm_hash);
assert_eq!(casm_result.1, casm_definition);
assert_eq!(casm_result.2, version);

let definition = class_definition(&tx, ClassHash(sierra_hash.0))
.unwrap()
Expand Down
1 change: 0 additions & 1 deletion crates/storage/src/connection/state_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ mod tests {
b"sierra definition",
&casm_hash,
b"casm definition",
"compiler version",
)
.unwrap();

Expand Down
1 change: 0 additions & 1 deletion crates/storage/src/fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub fn with_n_blocks_and_rng<R: Rng>(
sierra_definition,
casm_hash,
casm_definition,
"1.0.alpha6",
)
.unwrap()
},
Expand Down
2 changes: 2 additions & 0 deletions crates/storage/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod revision_0044;
mod revision_0045;
mod revision_0046;
mod revision_0047;
mod revision_0048;

pub(crate) use base::base_schema;

Expand All @@ -22,6 +23,7 @@ pub fn migrations() -> &'static [MigrationFn] {
revision_0045::migrate,
revision_0046::migrate,
revision_0047::migrate,
revision_0048::migrate,
]
}

Expand Down
Loading

0 comments on commit 70e8ed1

Please sign in to comment.