Skip to content

Commit

Permalink
Esad/fix make check features (#852)
Browse files Browse the repository at this point in the history
* reorganize bitcoin-da to pass check-features

* reorganize mock-da to pass check-features

* remove sov-modules-api

* Fix compilation errors

* Fix make check-features

* Fix merge

* cargo fmt

---------

Co-authored-by: Roman Proskuryakoff <[email protected]>
  • Loading branch information
eyusufatik and kpp authored Jul 11, 2024
1 parent 2f4cd19 commit df685ea
Show file tree
Hide file tree
Showing 33 changed files with 66 additions and 59 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ serde = { version = "1.0.192", default-features = false, features = ["alloc", "d
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
sha2 = { version = "0.10.8", default-features = false }
thiserror = "1.0.50"
tracing = { version = "0.1.40", default-features = false }
tracing = { version = "0.1.40", default-features = false, features = ["attributes"] }
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json", "fmt"] }
bech32 = { version = "0.9.1", default-features = false }
derive_more = { version = "0.99.11", default-features = false }
Expand All @@ -132,7 +132,7 @@ bonsai-sdk = { version = "0.8.0" }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "7168ac5", default-features = false }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v0.2.0-beta.7", default-features = false }
reth-interfaces = { git = "https://github.com/paradigmxyz/reth", tag = "v0.2.0-beta.7", default-features = false }
reth-rpc-types = { git = "https://github.com/paradigmxyz/reth", tag = "v0.2.0-beta.7", default-features = false }
reth-rpc-types = { git = "https://github.com/paradigmxyz/reth", tag = "v0.2.0-beta.7", default-features = false, features = ["jsonrpsee-types"] }
reth-rpc-types-compat = { git = "https://github.com/paradigmxyz/reth", tag = "v0.2.0-beta.7", default-features = false }
reth-node-api = { git = "https://github.com/paradigmxyz/reth", tag = "v0.2.0-beta.7", default-features = false }
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth", tag = "v0.2.0-beta.7", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion bin/citrea/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ tracing = { workspace = true }
tracing-subscriber = { workspace = true }

[dev-dependencies]
citrea-evm = { path = "../../crates/evm", features = ["smart_contracts"] }
citrea-evm = { path = "../../crates/evm", features = ["native"] }
shared-backup-db = { path = "../../crates/shared-backup-db", features = ["test-utils"] }
sov-mock-da = { path = "../../crates/sovereign-sdk/adapters/mock-da", default-features = false }
sov-prover-storage-manager = { path = "../../crates/sovereign-sdk/full-node/sov-prover-storage-manager", features = ["test-utils"] }
Expand Down
1 change: 0 additions & 1 deletion bin/citrea/provers/risc0/guest-bitcoin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/bitcoin-da/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ rust-version = "1.66"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", default-features = false }
sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface" }

tokio = { workspace = true, features = ["full"], optional = true }
Expand Down
31 changes: 8 additions & 23 deletions crates/bitcoin-da/src/helpers/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,12 @@ use bitcoin::{
Address, Amount, Network, OutPoint, ScriptBuf, Sequence, Transaction, TxIn, TxOut, Txid,
Witness,
};
use brotli::{CompressorWriter, DecompressorWriter};
use sov_modules_api::{native_trace, native_warn};
#[cfg(feature = "native")]
use tracing::instrument;
use tracing::{instrument, trace, warn};

use crate::helpers::{BODY_TAG, PUBLICKEY_TAG, RANDOM_TAG, ROLLUP_NAME_TAG, SIGNATURE_TAG};
use crate::spec::utxo::UTXO;
use crate::REVEAL_OUTPUT_AMOUNT;

pub fn compress_blob(blob: &[u8]) -> Vec<u8> {
let mut writer = CompressorWriter::new(Vec::new(), 4096, 11, 22);
writer.write_all(blob).unwrap();
writer.into_inner()
}

pub fn decompress_blob(blob: &[u8]) -> Vec<u8> {
let mut writer = DecompressorWriter::new(Vec::new(), 4096);
writer.write_all(blob).unwrap();
writer.into_inner().expect("decompression failed")
}

// Signs a message with a private key
pub fn sign_blob_with_private_key(
blob: &[u8],
Expand Down Expand Up @@ -145,7 +130,7 @@ fn choose_utxos(
}
}

#[cfg_attr(feature = "native", instrument(level = "trace", skip(utxos), err))]
#[instrument(level = "trace", skip(utxos), err)]
fn build_commit_transaction(
prev_tx: Option<TxWithId>, // reuse outputs to add commit tx order
mut utxos: Vec<UTXO>,
Expand Down Expand Up @@ -200,9 +185,9 @@ fn build_commit_transaction(

let tx = loop {
if iteration % 10 == 0 {
native_trace!(iteration, "Trying to find commitment size");
trace!(iteration, "Trying to find commitment size");
if iteration > 100 {
native_warn!("Too many iterations choosing UTXOs");
warn!("Too many iterations choosing UTXOs");
}
}
let fee = ((last_size as f64) * fee_rate).ceil() as u64;
Expand Down Expand Up @@ -341,7 +326,7 @@ impl fmt::Debug for TxWithId {
// so tests are easier
// Creates the inscription transactions (commit and reveal)
#[allow(clippy::too_many_arguments)]
#[cfg_attr(feature = "native", instrument(level = "trace", skip_all, err))]
#[instrument(level = "trace", skip_all, err)]
pub fn create_inscription_transactions(
rollup_name: &str,
body: Vec<u8>,
Expand Down Expand Up @@ -389,9 +374,9 @@ pub fn create_inscription_transactions(
let mut nonce: i64 = 0;
loop {
if nonce % 10000 == 0 {
native_trace!(nonce, "Trying to find commit & reveal nonce");
trace!(nonce, "Trying to find commit & reveal nonce");
if nonce > 65536 {
native_warn!("Too many iterations finding nonce");
warn!("Too many iterations finding nonce");
}
}
let utxos = utxos.clone();
Expand Down Expand Up @@ -556,7 +541,7 @@ mod tests {
use bitcoin::taproot::ControlBlock;
use bitcoin::{Address, Amount, ScriptBuf, TxOut, Txid};

use crate::helpers::builders::{compress_blob, decompress_blob};
use crate::helpers::compression::{compress_blob, decompress_blob};
use crate::helpers::parsers::parse_transaction;
use crate::spec::utxo::UTXO;
use crate::REVEAL_OUTPUT_AMOUNT;
Expand Down
16 changes: 16 additions & 0 deletions crates/bitcoin-da/src/helpers/compression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::io::Write;

#[cfg(feature = "native")]
pub fn compress_blob(blob: &[u8]) -> Vec<u8> {
use brotli::CompressorWriter;
let mut writer = CompressorWriter::new(Vec::new(), 4096, 11, 22);
writer.write_all(blob).unwrap();
writer.into_inner()
}

pub fn decompress_blob(blob: &[u8]) -> Vec<u8> {
use brotli::DecompressorWriter;
let mut writer = DecompressorWriter::new(Vec::new(), 4096);
writer.write_all(blob).unwrap();
writer.into_inner().expect("decompression failed")
}
2 changes: 2 additions & 0 deletions crates/bitcoin-da/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const PUBLICKEY_TAG: &[u8] = &[3];
const RANDOM_TAG: &[u8] = &[4];
const BODY_TAG: &[u8] = &[];

#[cfg(feature = "native")]
pub mod builders;
pub mod compression;
pub mod parsers;
#[cfg(test)]
pub mod test_utils;
4 changes: 3 additions & 1 deletion crates/bitcoin-da/src/helpers/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use core::iter::Peekable;

use bitcoin::blockdata::opcodes::all::{OP_ENDIF, OP_IF};
use bitcoin::blockdata::script::{Instruction, Instructions};
use bitcoin::consensus::Decodable;
use bitcoin::hashes::{sha256d, Hash};
use bitcoin::opcodes::all::{
OP_PUSHNUM_1, OP_PUSHNUM_10, OP_PUSHNUM_11, OP_PUSHNUM_12, OP_PUSHNUM_13, OP_PUSHNUM_14,
Expand Down Expand Up @@ -184,9 +183,12 @@ fn parse_relevant_inscriptions(
})
}

#[cfg(any(feature = "native", test))]
pub fn parse_hex_transaction(
tx_hex: &str,
) -> Result<Transaction, bitcoin::consensus::encode::Error> {
use bitcoin::consensus::Decodable;

if let Ok(reader) = hex::decode(tx_hex) {
Transaction::consensus_decode(&mut &reader[..])
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitcoin-da/src/helpers/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bitcoin::string::FromHexStr;
use bitcoin::{BlockHash, CompactTarget, Transaction};
use sov_rollup_interface::da::{DaSpec, DaVerifier};

use crate::helpers::builders::decompress_blob;
use crate::helpers::compression::decompress_blob;
use crate::helpers::parsers::{parse_hex_transaction, parse_transaction};
use crate::spec::blob::BlobWithSender;
use crate::spec::header::HeaderWrapper;
Expand Down
1 change: 1 addition & 0 deletions crates/bitcoin-da/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod spec;
pub mod service;
pub mod verifier;

#[cfg(feature = "native")]
const REVEAL_OUTPUT_AMOUNT: u64 = 546;
4 changes: 2 additions & 2 deletions crates/bitcoin-da/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use tokio::sync::oneshot::channel as oneshot_channel;
use tracing::{error, info, instrument, trace};

use crate::helpers::builders::{
compress_blob, create_inscription_transactions, decompress_blob, sign_blob_with_private_key,
write_reveal_tx, TxWithId,
create_inscription_transactions, sign_blob_with_private_key, write_reveal_tx, TxWithId,
};
use crate::helpers::compression::{compress_blob, decompress_blob};
use crate::helpers::parsers::parse_transaction;
use crate::rpc::{BitcoinNode, RPCError};
use crate::spec::blob::BlobWithSender;
Expand Down
1 change: 1 addition & 0 deletions crates/bitcoin-da/src/spec/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct InclusionMultiProof {
pub coinbase_tx: TransactionWrapper,
}

#[cfg(feature = "native")]
impl InclusionMultiProof {
pub(crate) fn new(
txids: Vec<[u8; 32]>,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitcoin-da/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sov_rollup_interface::digest::Digest;
use sov_rollup_interface::zk::ValidityCondition;
use thiserror::Error;

use crate::helpers::builders::decompress_blob;
use crate::helpers::compression::decompress_blob;
use crate::helpers::parsers::parse_transaction;
use crate::spec::BitcoinSpec;

Expand Down
6 changes: 1 addition & 5 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ revm-inspectors = { workspace = true, optional = true }
secp256k1 = { workspace = true, optional = true }

[dev-dependencies]
alloy = { workspace = true, features = ["consensus", "signer-wallet", "signers", "providers"] }
alloy = { workspace = true, features = ["consensus", "providers", "signer-wallet", "signers"] }
bytes = { workspace = true }
lazy_static = "1.4.0"
rand = { workspace = true }
Expand Down Expand Up @@ -77,7 +77,3 @@ native = [
"dep:tracing",
]
serde = []
smart_contracts = [
"native",
"serde_json",
]
6 changes: 3 additions & 3 deletions crates/evm/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ pub(crate) mod call;
#[cfg(feature = "native")]
pub(crate) mod error;

#[cfg(test)]
#[cfg(all(test, feature = "native"))]
mod tests;

pub use primitive_types::RlpEvmTransaction;
use sov_state::codec::BcsCodec;

#[cfg(test)]
#[cfg(all(test, feature = "native"))]
use crate::tests::DEFAULT_CHAIN_ID;

/// Bitcoin light client contract address
Expand Down Expand Up @@ -121,7 +121,7 @@ pub struct EvmChainConfig {
pub base_fee_params: BaseFeeParams,
}

#[cfg(test)]
#[cfg(all(test, feature = "native"))]
impl Default for EvmChainConfig {
fn default() -> EvmChainConfig {
EvmChainConfig {
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/evm/system_contracts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl BitcoinLightClient {
.into()
}

#[cfg(test)]
#[cfg(all(test, feature = "native"))]
pub(crate) fn get_witness_root_by_number(block_number: u64) -> Bytes {
BitcoinLightClientContract::getWitnessRootByNumberCall {
_blockNumber: U256::from(block_number),
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sov_modules_api::WorkingSet;
use crate::evm::db_init::InitEvmDb;
use crate::evm::primitive_types::Block;
use crate::evm::{AccountInfo, EvmChainConfig};
#[cfg(test)]
#[cfg(all(test, feature = "native"))]
use crate::tests::DEFAULT_CHAIN_ID;
use crate::Evm;

Expand Down Expand Up @@ -135,7 +135,7 @@ pub struct EvmConfig {
pub difficulty: U256,
}

#[cfg(test)]
#[cfg(all(test, feature = "native"))]
impl Default for EvmConfig {
fn default() -> Self {
Self {
Expand Down Expand Up @@ -260,7 +260,7 @@ impl<C: sov_modules_api::Context> Evm<C> {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "native"))]
mod tests {
use std::collections::HashMap;
use std::str::FromStr;
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ pub use query::*;
mod signer;
#[cfg(feature = "native")]
pub use signer::DevSigner;
#[cfg(feature = "smart_contracts")]
#[cfg(feature = "native")]
pub mod smart_contracts;

#[cfg(test)]
#[cfg(all(test, feature = "native"))]
mod tests;

use evm::db::EvmDb;
Expand Down
2 changes: 1 addition & 1 deletion crates/shared-backup-db/src/postgres_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl PostgresConnector {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "test-utils"))]
mod tests {
use super::*;
use crate::tables::Tables;
Expand Down
1 change: 1 addition & 0 deletions crates/soft-confirmation-rule-enforcer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tracing = { workspace = true, optional = true }
chrono = { workspace = true, default-features = true }
lazy_static = "1.4.0"
sov-mock-da = { path = "../sovereign-sdk/adapters/mock-da", features = ["native"] }
sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", features = ["native"] }
sov-prover-storage-manager = { path = "../sovereign-sdk/full-node/sov-prover-storage-manager", features = ["test-utils"] }
tempfile = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion crates/soft-confirmation-rule-enforcer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod query;
#[cfg(feature = "native")]
pub use query::*;

#[cfg(test)]
#[cfg(all(test, feature = "native"))]
mod tests;

// "Given DA slot hasn't been used for more than N soft confirmation blocks."
Expand Down
2 changes: 1 addition & 1 deletion crates/sovereign-sdk/adapters/mock-da/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tokio-stream = { version = "0.1.14", features = ["full"], optional = true }
pin-project = { workspace = true, optional = true }
rusqlite = { version = "0.31.0", features = ["bundled"], optional = true }
serde_json = { workspace = true, optional = true }
tracing = { workspace = true }
tracing = { workspace = true, features = ["attributes"]}

sov-rollup-interface = { path = "../../rollup-interface" }

Expand Down
4 changes: 2 additions & 2 deletions crates/sovereign-sdk/adapters/mock-da/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use sov_rollup_interface::services::da::{BlobWithNotifier, DaService, SlotData};
use tokio::sync::mpsc::{unbounded_channel, UnboundedSender};
use tokio::sync::{broadcast, Mutex as AsyncMutex, MutexGuard as AsyncMutexGuard};
use tokio::time;
use tracing::{instrument, Instrument};
use tracing::instrument::Instrument;

use crate::db_connector::DbConnector;
use crate::types::{MockAddress, MockBlob, MockBlock, MockDaVerifier};
Expand Down Expand Up @@ -83,7 +83,7 @@ impl MockDaService {
}

/// Create a new [`MockDaService`] with given finality.
#[instrument(name = "MockDA")]
#[tracing::instrument(name = "MockDA")]
pub fn with_finality(
sequencer_da_address: MockAddress,
blocks_to_finality: u32,
Expand Down
2 changes: 2 additions & 0 deletions crates/sovereign-sdk/examples/demo-stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ native = [
"sov-modules-api/native",
"sov-rollup-interface/native",
"sov-modules-stf-blueprint/native",
"citrea-evm/native",
"clap",
"serde",
"serde_json",
"soft-confirmation-rule-enforcer/native",
"jsonrpsee",
"tokio",
"toml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ resolver = "2"

[dependencies]
jsonrpsee = { workspace = true, features = ["macros", "client-core", "server"], optional = true }
sov-modules-api = { path = "../../../sov-modules-api", default-features = false }
sov-modules-api = { path = "../../../sov-modules-api", default-features = false, features = ["macros"] }
sov-state = { path = "../../../sov-state" }
serde = { workspace = true, optional = true }
borsh = { workspace = true, features = ["rc"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<C: sov_modules_api::Context> ValueSetter<C> {
}
}

#[cfg(test)]
#[cfg(all(test, feature = "native"))]
mod tests {
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::Address;
Expand Down
Loading

0 comments on commit df685ea

Please sign in to comment.