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

Implement soft batch save for full nodes #289

Merged
merged 8 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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 examples/demo-rollup/bitcoin_rollup_config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sequencer_public_key = "0000000000000000000000000000000000000000000000000000000000000000"
min_soft_confirmations_per_commitment = 1000
include_tx_body = false

[da]
node_url = "http://localhost:38332"
Expand Down
4 changes: 3 additions & 1 deletion examples/demo-rollup/celestia_rollup_config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include_tx_body = false

[da]
# The JWT used to authenticate with the celestia light client. Instructions for generating this token can be found in the README
celestia_rpc_auth_token = "MY.SECRET.TOKEN"
Expand All @@ -23,4 +25,4 @@ bind_host = "127.0.0.1"
bind_port = 12345

[prover_service]
aggregated_proof_block_jump = 1
aggregated_proof_block_jump = 1
1 change: 1 addition & 0 deletions examples/demo-rollup/mock_dockerized_rollup_config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sequencer_public_key = "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21"
include_tx_body = false

[da]
sender_address = "0000000000000000000000000000000000000000000000000000000000000000"
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/mock_rollup_config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sequencer_public_key = "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21"
include_tx_body = false

[da]
sender_address = "0000000000000000000000000000000000000000000000000000000000000000"
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/mocknet_rollup_config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sequencer_public_key = "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21"
min_soft_confirmations_per_commitment = 1000
include_tx_body = false

[da]
sender_address = "0000000000000000000000000000000000000000000000000000000000000000"
Expand Down
106 changes: 106 additions & 0 deletions examples/demo-rollup/tests/e2e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async fn initialize_test(
NodeMode::SequencerNode,
None,
config.seq_min_soft_confirmations,
true,
)
.await;
});
Expand All @@ -75,6 +76,7 @@ async fn initialize_test(
NodeMode::FullNode(seq_port),
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand All @@ -91,6 +93,101 @@ async fn initialize_test(
)
}

#[tokio::test]
async fn test_soft_batch_save() -> Result<(), anyhow::Error> {
let config = TestConfig::default();

let (seq_port_tx, seq_port_rx) = tokio::sync::oneshot::channel();

let seq_task = tokio::spawn(async move {
start_rollup(
seq_port_tx,
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
BasicKernelGenesisPaths {
chain_state: "../test-data/genesis/integration-tests/chain_state.json".into(),
},
RollupProverConfig::Execute,
NodeMode::SequencerNode,
None,
config.seq_min_soft_confirmations,
true,
)
.await;
});

let seq_port = seq_port_rx.await.unwrap();
let seq_test_client = init_test_rollup(seq_port).await;

let (full_node_port_tx, full_node_port_rx) = tokio::sync::oneshot::channel();

let full_node_task = tokio::spawn(async move {
start_rollup(
full_node_port_tx,
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
BasicKernelGenesisPaths {
chain_state: "../test-data/genesis/integration-tests/chain_state.json".into(),
},
RollupProverConfig::Execute,
NodeMode::FullNode(seq_port),
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});

let full_node_port = full_node_port_rx.await.unwrap();
let full_node_test_client = make_test_client(full_node_port).await;

let _ = execute_blocks(&seq_test_client, &full_node_test_client).await;

sleep(Duration::from_secs(10)).await;

let (full_node_port_tx_2, full_node_port_rx_2) = tokio::sync::oneshot::channel();

let full_node_task_2 = tokio::spawn(async move {
start_rollup(
full_node_port_tx_2,
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
BasicKernelGenesisPaths {
chain_state: "../test-data/genesis/integration-tests/chain_state.json".into(),
},
RollupProverConfig::Execute,
NodeMode::FullNode(full_node_port),
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
false,
)
.await;
});

let full_node_port_2 = full_node_port_rx_2.await.unwrap();
let full_node_test_client_2 = make_test_client(full_node_port_2).await;

sleep(Duration::from_secs(10)).await;

let seq_block = seq_test_client
.eth_get_block_by_number(Some(BlockNumberOrTag::Latest))
.await;
let full_node_block = full_node_test_client
.eth_get_block_by_number(Some(BlockNumberOrTag::Latest))
.await;
let full_node_block_2 = full_node_test_client_2
.eth_get_block_by_number(Some(BlockNumberOrTag::Latest))
.await;

assert_eq!(seq_block.state_root, full_node_block.state_root);
assert_eq!(full_node_block.state_root, full_node_block_2.state_root);
assert_eq!(seq_block.hash, full_node_block.hash);
assert_eq!(full_node_block.hash, full_node_block_2.hash);

seq_task.abort();
full_node_task.abort();
full_node_task_2.abort();

Ok(())
}

#[tokio::test]
async fn test_full_node_send_tx() -> Result<(), anyhow::Error> {
// sov_demo_rollup::initialize_logging();
Expand Down Expand Up @@ -142,6 +239,7 @@ async fn test_delayed_sync_ten_blocks() -> Result<(), anyhow::Error> {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down Expand Up @@ -172,6 +270,7 @@ async fn test_delayed_sync_ten_blocks() -> Result<(), anyhow::Error> {
NodeMode::FullNode(seq_port),
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down Expand Up @@ -233,6 +332,7 @@ async fn test_close_and_reopen_full_node() -> Result<(), anyhow::Error> {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand All @@ -253,6 +353,7 @@ async fn test_close_and_reopen_full_node() -> Result<(), anyhow::Error> {
NodeMode::FullNode(seq_port),
Some("demo_data_test_close_and_reopen_full_node"),
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down Expand Up @@ -332,6 +433,7 @@ async fn test_close_and_reopen_full_node() -> Result<(), anyhow::Error> {
NodeMode::FullNode(seq_port),
Some("demo_data_test_close_and_reopen_full_node_copy"),
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down Expand Up @@ -384,6 +486,7 @@ async fn test_get_transaction_by_hash() -> Result<(), anyhow::Error> {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand All @@ -403,6 +506,7 @@ async fn test_get_transaction_by_hash() -> Result<(), anyhow::Error> {
NodeMode::FullNode(seq_port),
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down Expand Up @@ -636,6 +740,7 @@ async fn test_reopen_sequencer() -> Result<(), anyhow::Error> {
NodeMode::SequencerNode,
Some("demo_data_test_reopen_sequencer"),
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down Expand Up @@ -679,6 +784,7 @@ async fn test_reopen_sequencer() -> Result<(), anyhow::Error> {
NodeMode::SequencerNode,
Some("demo_data_test_reopen_sequencer_copy"),
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/tests/evm/archival_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async fn test_archival_state() -> Result<(), anyhow::Error> {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/tests/evm/gas_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async fn test_gas_price_increase() -> Result<(), anyhow::Error> {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down
3 changes: 3 additions & 0 deletions examples/demo-rollup/tests/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async fn web3_rpc_tests() -> Result<(), anyhow::Error> {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down Expand Up @@ -80,6 +81,7 @@ async fn evm_tx_tests() -> Result<(), anyhow::Error> {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down Expand Up @@ -114,6 +116,7 @@ async fn test_eth_get_logs() -> Result<(), anyhow::Error> {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/tests/evm/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async fn tracing_tests() -> Result<(), Box<dyn std::error::Error>> {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/tests/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async fn initialize_test() -> (JoinHandle<()>, Box<TestClient>) {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/tests/sequencer_commitments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async fn sequencer_sends_commitments_to_da_layer() {
NodeMode::SequencerNode,
None,
4,
true,
)
.await;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async fn too_many_l2_block_per_l1_block() {
NodeMode::SequencerNode,
None,
DEFAULT_MIN_SOFT_CONFIRMATIONS_PER_COMMITMENT,
true,
)
.await;
});
Expand Down
3 changes: 3 additions & 0 deletions examples/demo-rollup/tests/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum NodeMode {
Prover(SocketAddr),
}

#[allow(clippy::too_many_arguments)]
pub async fn start_rollup(
rpc_reporting_channel: oneshot::Sender<SocketAddr>,
rt_genesis_paths: GenesisPaths,
Expand All @@ -35,6 +36,7 @@ pub async fn start_rollup(
node_mode: NodeMode,
db_path: Option<&str>,
min_soft_confirmations_per_commitment: u64,
include_tx_body: bool,
) {
let mut path = db_path.map(Path::new);
let mut temp_dir: Option<tempfile::TempDir> = None;
Expand Down Expand Up @@ -73,6 +75,7 @@ pub async fn start_rollup(
}
NodeMode::SequencerNode => None,
},
include_tx_body,
};

let sequencer_config = SequencerConfig {
Expand Down
3 changes: 1 addition & 2 deletions full-node/chainway-sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ where

self.state_root = next_state_root;

self.ledger_db
.commit_soft_batch(soft_batch_receipt, false)?;
self.ledger_db.commit_soft_batch(soft_batch_receipt, true)?;

self.mempool
.remove_transactions(self.db_provider.last_block_tx_hashes());
Expand Down
4 changes: 2 additions & 2 deletions full-node/db/sov-db/src/ledger_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl LedgerDB {
pub fn commit_soft_batch<B: Serialize, T: Serialize, DS: DaSpec>(
&self,
batch_receipt: SoftBatchReceipt<B, T, DS>,
ignore_tx_body: bool,
include_tx_body: bool,
) -> Result<(), anyhow::Error> {
// Create a scope to ensure that the lock is released before we commit to the db
let mut current_item_numbers = {
Expand Down Expand Up @@ -284,7 +284,7 @@ impl LedgerDB {

// Rollup full nodes don't need to store the tx body as they already store evm body
// Sequencer full nodes need to store the tx body as they are the only ones that have it
if ignore_tx_body {
if !include_tx_body {
tx_to_store.body = None;
}

Expand Down
4 changes: 4 additions & 0 deletions full-node/sov-stf-runner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub struct RollupConfig<DaServiceConfig> {
pub sequencer_public_key: Vec<u8>,
/// Prover service configuration.
pub prover_service: ProverServiceConfig,
/// Saves sequencer soft batches if set to true
pub include_tx_body: bool,
}

/// Reads toml file as a specific type.
Expand Down Expand Up @@ -97,6 +99,7 @@ mod tests {
fn test_correct_config() {
let config = r#"
sequencer_public_key = "0000000000000000000000000000000000000000000000000000000000000000"
include_tx_body = true
[da]
celestia_rpc_auth_token = "SECRET_RPC_TOKEN"
celestia_rpc_address = "http://localhost:11111/"
Expand Down Expand Up @@ -143,6 +146,7 @@ mod tests {
prover_service: ProverServiceConfig {
aggregated_proof_block_jump: 22,
},
include_tx_body: true,
};
assert_eq!(config, expected);
}
Expand Down
Loading
Loading