Skip to content

Always‐Wasm Genesis Sync

Brice Dobry edited this page Jul 15, 2024 · 1 revision

This page will document the steps needed to run a genesis sync in which Clarity-Wasm is used all the time, not epoch-gated. This provides valuable testing to confirm that it is fully backward compatible with existing chainstate.

Disable the epoch gating

In stacks-core, we can disable the epoch-gating by making the following change:

--- a/stackslib/src/chainstate/stacks/db/transactions.rs
+++ b/stackslib/src/chainstate/stacks/db/transactions.rs
@@ -1262,17 +1262,13 @@ impl StacksChainState {
                     .expect("BUG: total block cost decreased");
                 let sponsor = tx.sponsor_address().map(|a| a.to_account_principal());
 
-                // Beginning in epoch 3.0, smart contracts are compiled to Wasm
-                // and executed using the Wasm runtime.
-                if epoch_id >= StacksEpochId::Epoch30 {
-                    // Compile the contract to Wasm
-                    let mut module = compile_contract(contract_analysis.clone()).map_err(|e| {
-                        Error::ClarityError(clarity_error::Wasm(WasmError::WasmGeneratorError(
-                            e.message(),
-                        )))
-                    })?;
-                    contract_ast.wasm_module = Some(module.emit_wasm());
-                }
+                // In this branch, always compile the contract to Wasm
+                let mut module = compile_contract(contract_analysis.clone()).map_err(|e| {
+                    Error::ClarityError(clarity_error::Wasm(WasmError::WasmGeneratorError(
+                        e.message(),
+                    )))
+                })?;
+                contract_ast.wasm_module = Some(module.emit_wasm());
 
                 // execution -- if this fails due to a runtime error, then the transaction is still
                 // accepted, but the contract does not materialize (but the sender is out their fee).

This change on top of feat/clarity-wasm-develop as of today is pushed to the branch always-wasm-2024-07.

Use local paths

To avoid the challenges of pointing to the right branches across clarity-wasm and stacks-core, we can uncomment out the patches in .cargo/config.toml in both clarity-wasm and stacks-core. Note, depending on your directory structure, you may need to modify these relative paths. This simplifies the local build, but you could push the changes to both repos and modify these patches to point to the appropriate branches in both repos.

Build the stacks-node

cd stacks-core
cargo build --profile release-lite

Create a config file

We will run the stacks-node on mainnet, so we need to pass the appropriate config file. Modify the working_dir as needed to point to a directory you have created to which you would like the node to write its data.

[node]
working_dir = "/Users/brice/work/clarity-wasm/stacks-core/data"
rpc_bind = "0.0.0.0:20443"
p2p_bind = "0.0.0.0:20444"
bootstrap_node = "02196f005965cebe6ddc3901b7b1cc1aa7a88f305bb8c5893456b8f9a605923893@seed.mainnet.hiro.so:20444,02539449ad94e6e6392d8c1deb2b4e61f80ae2a18964349bc14336d8b903c46a8c@cet.stacksnodes.org:20444,02ececc8ce79b8adf813f13a0255f8ae58d4357309ba0cedd523d9f1a306fcfb79@sgt.stacksnodes.org:20444,0303144ba518fe7a0fb56a8a7d488f950307a4330f146e1e1458fc63fb33defe96@est.stacksnodes.org:20444"

[burnchain]
chain = "bitcoin"
mode = "mainnet"
peer_host = "bitcoind.stacks.co"
username = "blockstack"
password = "blockstacksystem"
rpc_port = 8332
peer_port = 8333

Running the node

target/release-lite/stacks-node start --config mainnet.toml

Note: Between reruns, be sure to clear out the data directory from any prior runs.