Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RollupParams refactor + STR 478 functional test for full node #371

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bin/datatool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ argh.workspace = true
bech32 = "0.11.0"
bitcoin = { workspace = true, features = ["std"] }
hex.workspace = true
musig2 = { workspace = true }
rand.workspace = true
secp256k1 = { workspace = true, features = ["global-context", "std"] }
serde_json.workspace = true
Expand Down
15 changes: 10 additions & 5 deletions bin/datatool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
block_credential,
buf::Buf32,
operator::OperatorPubkeys,
params::{ProofPublishMode, RollupParams},
params::{DepositTxParams, ProofPublishMode, RollupParams, TransactionParams},
vk::RollupVerifyingKey,
};
use strata_sp1_guest_builder::GUEST_CHECKPOINT_ELF_STR;
Expand Down Expand Up @@ -499,13 +499,13 @@
// TODO add in bitcoin network

RollupParams {
rollup_name: config.name,
rollup_name: config.name.clone(),

Check warning on line 502 in bin/datatool/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/main.rs#L502

Added line #L502 was not covered by tests
block_time: config.block_time_sec * 1000,
cred_rule: cr,
// TODO do we want to remove this?
horizon_l1_height: config.genesis_trigger / 2,
genesis_l1_height: config.genesis_trigger,
operator_config: strata_primitives::params::OperatorConfig::Static(opkeys),
operator_config: strata_primitives::params::OperatorConfig::Static(opkeys.clone()),

Check warning on line 508 in bin/datatool/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/main.rs#L508

Added line #L508 was not covered by tests
// TODO make configurable
evm_genesis_block_hash: Buf32(
"0x37ad61cff1367467a98cf7c54c4ac99e989f1fbb1bc1e646235e90c065c565ba"
Expand All @@ -520,8 +520,6 @@
// TODO make configurable
l1_reorg_safe_depth: 4,
target_l2_batch_size: config.epoch_slots as u64,
address_length: 20,
deposit_amount: config.deposit_sats,
rollup_vk: RollupVerifyingKey::SP1VerifyingKey(config.rollup_vk),
// TODO make configurable
dispatch_assignment_dur: 64,
Expand All @@ -532,6 +530,13 @@
// TODO make configurable
max_deposits_in_block: 16,
network: config.bitcoin_network,
tx_params: TransactionParams {
deposit: DepositTxParams {
magic_bytes: config.name.into_bytes().to_vec(),
max_address_length: 20,
deposit_amount: config.deposit_sats,
},
},

Check warning on line 539 in bin/datatool/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/datatool/src/main.rs#L533-L539

Added lines #L533 - L539 were not covered by tests
}
}

Expand Down
14 changes: 11 additions & 3 deletions bin/prover-client/src/proving_ops/btc_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use strata_primitives::{
block_credential,
buf::Buf32,
operator::OperatorPubkeys,
params::{OperatorConfig, Params, ProofPublishMode, RollupParams, SyncParams},
params::{
DepositTxParams, OperatorConfig, Params, ProofPublishMode, RollupParams, SyncParams,
TransactionParams,
},
vk::RollupVerifyingKey,
};
use tracing::debug;
Expand Down Expand Up @@ -91,8 +94,6 @@ fn gen_params_with_seed(seed: u64) -> Params {
),
l1_reorg_safe_depth: 4,
target_l2_batch_size: 64,
address_length: 20,
deposit_amount: 1_000_000_000,
rollup_vk: RollupVerifyingKey::SP1VerifyingKey(Buf32(
"0x00b01ae596b4e51843484ff71ccbd0dd1a030af70b255e6b9aad50b81d81266f"
.parse()
Expand All @@ -102,6 +103,13 @@ fn gen_params_with_seed(seed: u64) -> Params {
proof_publish_mode: ProofPublishMode::Strict,
max_deposits_in_block: 16,
network: bitcoin::Network::Regtest,
tx_params: TransactionParams {
deposit: DepositTxParams {
magic_bytes: "strata".to_string().into_bytes().to_vec(),
max_address_length: 20,
deposit_amount: 1_000_000_000,
},
},
},
run: SyncParams {
l2_blocks_fetch_limit: 1000,
Expand Down
2 changes: 1 addition & 1 deletion bin/strata-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
let sequencer_rpc = &fullnode_config.sequencer_rpc;
info!(?sequencer_rpc, "initing fullnode task");

let rpc_client = runtime.block_on(sync_client(sequencer_rpc));
let rpc_client = sync_client(sequencer_rpc);

Check warning on line 176 in bin/strata-client/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-client/src/main.rs#L176

Added line #L176 was not covered by tests
let sync_peer = RpcSyncPeer::new(rpc_client, 10);
let l2_sync_context = L2SyncContext::new(
sync_peer,
Expand Down
9 changes: 7 additions & 2 deletions bin/strata-client/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
),
l1_reorg_safe_depth: 4,
target_l2_batch_size: 64,
address_length: 20,
deposit_amount: 1_000_000_000,
rollup_vk: RollupVerifyingKey::SP1VerifyingKey(Buf32(
"0x00b01ae596b4e51843484ff71ccbd0dd1a030af70b255e6b9aad50b81d81266f"
.parse()
Expand All @@ -69,6 +67,13 @@
proof_publish_mode: ProofPublishMode::Timeout(5),
max_deposits_in_block: 16,
network: bitcoin::Network::Regtest,
tx_params: TransactionParams {
deposit: DepositTxParams {
magic_bytes: "strata".to_string().into_bytes().to_vec(),
max_address_length: 20,
deposit_amount: 1_000_000_000,
},
},

Check warning on line 76 in bin/strata-client/src/network.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-client/src/network.rs#L70-L76

Added lines #L70 - L76 were not covered by tests
}
}

Expand Down
7 changes: 3 additions & 4 deletions bin/strata-client/src/rpc_client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use jsonrpsee::{core::client::async_client::Client, ws_client::WsClientBuilder};
use jsonrpsee::http_client::{HttpClient, HttpClientBuilder};

pub async fn sync_client(url: &str) -> Client {
WsClientBuilder::default()
pub fn sync_client(url: &str) -> HttpClient {
HttpClientBuilder::default()

Check warning on line 4 in bin/strata-client/src/rpc_client.rs

View check run for this annotation

Codecov / codecov/patch

bin/strata-client/src/rpc_client.rs#L3-L4

Added lines #L3 - L4 were not covered by tests
.build(url)
.await
.expect("Failed to connect to the RPC server")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@voidash Can you make another PR with just changes related to this fix without the other param changes ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

74 changes: 31 additions & 43 deletions crates/primitives/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
/// Config for how the genesis operator table is set up.
pub operator_config: OperatorConfig,

/// Config for various transactions
pub tx_params: TransactionParams,

/// Hardcoded EL genesis info
/// TODO: move elsewhere
pub evm_genesis_block_hash: Buf32,
Expand All @@ -42,13 +45,6 @@
/// target batch size in number of l2 blocks
pub target_l2_batch_size: u64,

/// Maximum length of an EE address in a deposit.
// FIXME this should be "max address length"
pub address_length: u8,

/// Exact "at-rest" deposit amount, in sats.
pub deposit_amount: u64,

/// SP1 verifying key that is used to verify the Groth16 proof posted on Bitcoin
// FIXME which proof? should this be `checkpoint_vk`?
pub rollup_vk: RollupVerifyingKey,
Expand Down Expand Up @@ -100,14 +96,6 @@
return Err(ParamsError::ZeroProperty("target_l2_batch_size"));
}

if self.address_length == 0 {
return Err(ParamsError::ZeroProperty("max_address_length"));
}

if self.deposit_amount == 0 {
return Err(ParamsError::ZeroProperty("deposit_amount"));
}

if self.dispatch_assignment_dur == 0 {
return Err(ParamsError::ZeroProperty("dispatch_assignment_dur"));
}
Expand All @@ -129,34 +117,6 @@
}
}

/// Configuration common among deposit and deposit request transaction
#[derive(Clone, Debug, PartialEq, BorshSerialize, BorshDeserialize, Deserialize, Serialize)]
pub struct DepositTxParams {
/// Magic bytes we use to regonize a deposit with.
pub magic_bytes: Vec<u8>,

/// Maximum EE address length.
// TODO rename to be `max_addr_len`
pub address_length: u8,

/// Exact bitcoin amount in the at-rest deposit.
pub deposit_amount: u64,

/// federation address derived from operator entries
pub address: BitcoinAddress,
}

impl RollupParams {
pub fn get_deposit_params(&self, address: BitcoinAddress) -> DepositTxParams {
DepositTxParams {
magic_bytes: self.rollup_name.clone().into_bytes().to_vec(),
address_length: self.address_length,
deposit_amount: self.deposit_amount,
address,
}
}
}

/// Describes how we decide to wait for proofs for checkpoints to generate.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
Expand Down Expand Up @@ -219,6 +179,34 @@
Static(Vec<OperatorPubkeys>),
}

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]

Check warning on line 182 in crates/primitives/src/params.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/params.rs#L182

Added line #L182 was not covered by tests
#[serde(rename_all = "snake_case")]
pub struct TransactionParams {
pub deposit: DepositTxParams,
}

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, BorshSerialize, BorshDeserialize)]

Check warning on line 188 in crates/primitives/src/params.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/params.rs#L188

Added line #L188 was not covered by tests
#[serde(rename_all = "snake_case")]
pub struct DepositTxParams {
/// Magic bytes we use to regonize a deposit with.
pub magic_bytes: Vec<u8>,

/// Maximum EE address length.
pub max_address_length: u8,

/// Exact bitcoin amount in the at-rest deposit.
pub deposit_amount: u64,
}

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, BorshSerialize, BorshDeserialize)]

Check warning on line 201 in crates/primitives/src/params.rs

View check run for this annotation

Codecov / codecov/patch

crates/primitives/src/params.rs#L201

Added line #L201 was not covered by tests
#[serde(rename_all = "snake_case")]
pub struct DepositTxConfig {
/// configuration from rollup params
pub params: DepositTxParams,
/// Bitcoin address
pub addr: BitcoinAddress,
}

/// Error that can arise during params validation.
#[derive(Debug, Error)]
pub enum ParamsError {
Expand Down
27 changes: 17 additions & 10 deletions crates/test-utils/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
hashes::Hash,
Block, Transaction,
};
use strata_primitives::{buf::Buf32, l1::L1BlockManifest, params::OperatorConfig};
use strata_primitives::{
buf::Buf32,
l1::L1BlockManifest,
params::{DepositTxConfig, OperatorConfig},
};
use strata_state::l1::{
get_difficulty_adjustment_height, BtcParams, HeaderVerificationState, L1BlockId, TimestampStore,
};
use strata_tx_parser::{filter::TxFilterRule, utils::generate_taproot_address};
use strata_tx_parser::{filter::TxFilterRule, utils::derive_taproot_address};

use crate::{l2::gen_params, ArbitraryGenerator};

Expand Down Expand Up @@ -173,22 +177,25 @@
}

pub fn get_tx_filters() -> Vec<TxFilterRule> {
let config = gen_params();

let operator_config = config.rollup().operator_config.clone();
let params = gen_params();
let operator_config = params.rollup().operator_config.clone();

Check warning on line 181 in crates/test-utils/src/bitcoin.rs

View check run for this annotation

Codecov / codecov/patch

crates/test-utils/src/bitcoin.rs#L180-L181

Added lines #L180 - L181 were not covered by tests
let OperatorConfig::Static(operator_pubkeys) = operator_config;

let operator_pubkeys = operator_pubkeys
.iter()
.map(|op| *op.wallet_pk())
.collect::<Vec<Buf32>>();

let addr = generate_taproot_address(&operator_pubkeys, bitcoin::Network::Regtest)
.expect("taproot address");
let deposit_tx_params = config.rollup().get_deposit_params(addr);
let addr = derive_taproot_address(&operator_pubkeys, bitcoin::Network::Regtest).unwrap();

let deposit_tx_params = DepositTxConfig {
params: params.rollup().tx_params.deposit.clone(),
addr,
};

Check warning on line 194 in crates/test-utils/src/bitcoin.rs

View check run for this annotation

Codecov / codecov/patch

crates/test-utils/src/bitcoin.rs#L189-L194

Added lines #L189 - L194 were not covered by tests

vec![
TxFilterRule::Deposit(deposit_tx_params),
TxFilterRule::RollupInscription(config.rollup().rollup_name.clone()),
TxFilterRule::Deposit(deposit_tx_params.clone()),
TxFilterRule::DepositRequest(deposit_tx_params.clone()),
TxFilterRule::RollupInscription(params.rollup().rollup_name.clone()),

Check warning on line 199 in crates/test-utils/src/bitcoin.rs

View check run for this annotation

Codecov / codecov/patch

crates/test-utils/src/bitcoin.rs#L197-L199

Added lines #L197 - L199 were not covered by tests
]
}
14 changes: 11 additions & 3 deletions crates/test-utils/src/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use strata_primitives::{
block_credential,
buf::{Buf32, Buf64},
operator::OperatorPubkeys,
params::{OperatorConfig, Params, ProofPublishMode, RollupParams, SyncParams},
params::{
DepositTxParams, OperatorConfig, Params, ProofPublishMode, RollupParams, SyncParams,
TransactionParams,
},
vk::RollupVerifyingKey,
};
use strata_state::{
Expand Down Expand Up @@ -92,8 +95,6 @@ pub fn gen_params_with_seed(seed: u64) -> Params {
),
l1_reorg_safe_depth: 3,
target_l2_batch_size: 64,
address_length: 20,
deposit_amount: 1_000_000_000,
rollup_vk: RollupVerifyingKey::SP1VerifyingKey(Buf32(
"0x00b01ae596b4e51843484ff71ccbd0dd1a030af70b255e6b9aad50b81d81266f"
.parse()
Expand All @@ -103,6 +104,13 @@ pub fn gen_params_with_seed(seed: u64) -> Params {
proof_publish_mode: ProofPublishMode::Strict,
max_deposits_in_block: 16,
network: bitcoin::Network::Regtest,
tx_params: TransactionParams {
deposit: DepositTxParams {
magic_bytes: "strata".to_string().into_bytes().to_vec(),
max_address_length: 20,
deposit_amount: 1_000_000_000,
},
},
},
run: SyncParams {
l2_blocks_fetch_limit: 1000,
Expand Down
Loading
Loading