Skip to content

Commit 3166830

Browse files
authored
Merge branch 'main' into improve-logs
2 parents 86909c9 + e7b02e6 commit 3166830

File tree

14 files changed

+736
-213
lines changed

14 files changed

+736
-213
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,5 @@ s3
105105
# python virtual env
106106
.venv
107107

108-
sequencer_venv/
108+
sequencer_venv/
109+
sequencer_requirements.txt

Makefile

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Targets:
1414

1515
[ SETUP ]
1616

17+
- setup-cairo Setup Cairo 0 environment for building
1718
- setup-l2 Setup orchestrator with L2 layer
1819
- setup-l2-localstack Setup orchestrator with L2 layer and Localstack
1920
- setup-l3 Setup orchestrator with L3 layer
@@ -69,6 +70,11 @@ Targets:
6970
- clean-db Perform clean and remove local database
7071
- fclean Perform clean-db and remove local images
7172

73+
[ BUILDING ]
74+
75+
- build-madara Build Madara with Cairo 0 environment setup
76+
- build-orchestrator Build Orchestrator with Cairo 0 environment setup
77+
7278
[ CODE QUALITY ]
7379

7480
Runs various code quality checks including formatting and linting.
@@ -103,6 +109,8 @@ DOCKER_TAG := madara:latest
103109
DOCKER_IMAGE := ghcr.io/madara-alliance/$(DOCKER_TAG)
104110
DOCKER_GZ := image.tar.gz
105111
ARTIFACTS := ./build-artifacts
112+
VENV := sequencer_venv
113+
VENV_ACTIVATE := . $(VENV)/bin/activate
106114

107115
# Configuration for E2E bridge tests
108116
CARGO_TARGET_DIR ?= target
@@ -195,9 +203,48 @@ artifacts:
195203
@git submodule update --init --recursive
196204
./scripts/artifacts.sh
197205

206+
.PHONY: setup-cairo
207+
setup-cairo:
208+
@echo -e "$(DIM)Setting up Cairo 0 environment...$(RESET)"
209+
@if [ ! -d "$(VENV)" ]; then \
210+
echo -e "$(INFO)Creating Python virtual environment...$(RESET)"; \
211+
python3 -m venv $(VENV); \
212+
else \
213+
echo -e "$(PASS)✅ Virtual environment already exists$(RESET)"; \
214+
fi
215+
@echo -e "$(INFO)Installing Cairo 0 dependencies...$(RESET)"
216+
@if [ ! -f sequencer_requirements.txt ]; then \
217+
CARGO_HOME=$${CARGO_HOME:-$$HOME/.cargo}; \
218+
GIT_CHECKOUTS=$$(readlink -f "$$CARGO_HOME/git" 2>/dev/null || echo "$$CARGO_HOME/git"); \
219+
SEQUENCER_REV=$$(grep -A 2 'name = "blockifier"' Cargo.lock | grep 'sequencer?rev=' | sed -E 's/.*rev=([a-f0-9]+).*/\1/' | cut -c1-7); \
220+
REQUIREMENTS_PATH=$$(find "$$GIT_CHECKOUTS/checkouts" -type f -path "*/sequencer*/$$SEQUENCER_REV*/scripts/requirements.txt" 2>/dev/null | head -n 1); \
221+
if [ -n "$$REQUIREMENTS_PATH" ]; then \
222+
sed 's/numpy==2.0.2/numpy<2.0/' "$$REQUIREMENTS_PATH" > sequencer_requirements.txt; \
223+
echo -e "$(INFO)Found requirements.txt at: $$REQUIREMENTS_PATH$(RESET)"; \
224+
else \
225+
echo -e "$(WARN)⚠️ WARNING: Could not find requirements.txt from sequencer checkout$(RESET)"; \
226+
echo -e "$(INFO)Creating basic requirements with cairo-lang...$(RESET)"; \
227+
echo "cairo-lang==0.14.0.1" > sequencer_requirements.txt; \
228+
echo "numpy<2.0" >> sequencer_requirements.txt; \
229+
fi; \
230+
fi
231+
@$(VENV_ACTIVATE) && pip install --upgrade pip > /dev/null 2>&1 && pip install -r sequencer_requirements.txt > /dev/null 2>&1
232+
@$(VENV_ACTIVATE) && cairo-compile --version > /dev/null 2>&1 && echo -e "$(PASS)✅ Cairo 0 environment ready (cairo-compile $$($(VENV_ACTIVATE) && cairo-compile --version 2>&1))$(RESET)" || (echo -e "$(WARN)❌ Cairo setup failed$(RESET)" && exit 1)
233+
234+
.PHONY: build-madara
235+
build-madara:
236+
@echo -e "$(DIM)Building Madara with Cairo 0 environment...$(RESET)"
237+
@$(VENV_ACTIVATE) && cargo build --manifest-path madara/Cargo.toml --bin madara --release
238+
@echo -e "$(PASS)✅ Build complete!$(RESET)"
239+
240+
.PHONY: build-orchestrator
241+
build-orchestrator: setup-cairo
242+
@echo -e "$(DIM)Building Orchestrator with Cairo 0 environment...$(RESET)"
243+
@$(VENV_ACTIVATE) && cargo build --bin orchestrator --release
244+
@echo -e "$(PASS)✅ Build complete!$(RESET)"
198245

199246
.PHONY: check
200-
check:
247+
check: setup-cairo
201248
@echo -e "$(DIM)Running code quality checks...$(RESET)"
202249
@echo -e "$(INFO)Running prettier check...$(RESET)"
203250
@npm install
@@ -206,20 +253,23 @@ check:
206253
@cargo fmt -- --check
207254
@echo -e "$(INFO)Running taplo fmt check...$(RESET)"
208255
@taplo fmt --config=./taplo/taplo.toml --check
209-
@echo -e "$(INFO)Running cargo clippy workspace checks...$(RESET)"
256+
@echo "Running cargo clippy..."
210257
@cargo clippy --workspace --no-deps -- -D warnings
211-
@echo -e "$(INFO)Running cargo clippy workspace tests...$(RESET)"
212258
@cargo clippy --workspace --tests --no-deps -- -D warnings
213-
@echo -e "$(INFO)Running cargo clippy with testing features...$(RESET)"
214-
@cargo clippy --workspace --exclude madara --features testing --no-deps -- -D warnings
215-
@echo -e "$(INFO)Running cargo clippy with testing features and tests...$(RESET)"
216-
@cargo clippy --workspace --exclude madara --features testing --tests --no-deps -- -D warnings
259+
@# TODO(mehul 14/11/2025, hotfix): This is a temporary fix to ensure that the madara is linted.
260+
@# Madara does not belong to the toplevel workspace, so we need to lint it separately.
261+
@# Remove this once we add madara back to toplevel workspace.
262+
@echo "Running cargo clippy for madara..."
263+
@cd madara && \
264+
cargo clippy --workspace --no-deps -- -D warnings && \
265+
cargo clippy --workspace --tests --no-deps -- -D warnings && \
266+
cd ..
217267
@echo -e "$(INFO)Running markdownlint check...$(RESET)"
218268
@npx markdownlint -c .markdownlint.json -q -p .markdownlintignore .
219269
@echo -e "$(PASS)All code quality checks passed!$(RESET)"
220270

221271
.PHONY: fmt
222-
fmt:
272+
fmt: setup-cairo
223273
@echo -e "$(DIM)Running code formatters...$(RESET)"
224274
@echo -e "$(INFO)Running taplo formatter...$(RESET)"
225275
@npm install
@@ -421,10 +471,10 @@ test: test-e2e test-orchestrator
421471
@echo -e "$(PASS)All tests completed!$(RESET)"
422472

423473
.PHONY: pre-push
424-
pre-push:
474+
pre-push: setup-cairo
425475
@echo -e "$(DIM)Running pre-push checks...$(RESET)"
426476
@echo -e "$(INFO)Running code quality checks...$(RESET)"
427-
@$(MAKE) --silent check
477+
@$(VENV_ACTIVATE) && $(MAKE) --silent check
428478
@echo -e "$(PASS)Pre-push checks completed successfully!$(RESET)"
429479

430480
.PHONY: git-hook

configs/args/config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
},
108108
"block_production_params": {
109109
"block_production_disabled": false,
110-
"close_preconfirmed_block_upon_restart": false,
111110
"devnet_contracts": 10
112111
},
113112
"chain_config_override": {

madara/crates/client/block_production/src/executor/thread.rs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
33
use crate::util::{create_execution_context, BatchToExecute, BlockExecutionContext, ExecutionStats};
44
use anyhow::Context;
5-
use blockifier::{blockifier::transaction_executor::TransactionExecutor, state::state_api::State};
5+
use blockifier::blockifier::transaction_executor::TransactionExecutor;
66
use futures::future::OptionFuture;
77
use mc_db::MadaraBackend;
8-
use mc_exec::{execution::TxInfo, LayeredStateAdapter, MadaraBackendExecutionExt};
8+
use mc_exec::{execution::TxInfo, LayeredStateAdapter};
99
use mp_convert::{Felt, ToFelt};
1010
use starknet_api::contract_class::ContractClass;
1111
use starknet_api::core::ClassHash;
@@ -220,29 +220,14 @@ impl ExecutorThread {
220220
previous_l2_gas_used,
221221
)?;
222222

223-
// Create the TransactionExecution, but reuse the layered_state_adapter.
224-
let mut executor =
225-
self.backend.new_executor_for_block_production(state.state_adaptor, exec_ctx.to_blockifier()?)?;
226-
227-
// Prepare the block_n-10 state diff entry on the 0x1 contract.
228-
if let Some((block_n_min_10, block_hash_n_min_10)) =
229-
self.wait_for_hash_of_block_min_10(exec_ctx.block_number)?
230-
{
231-
let contract_address = 1u64.into();
232-
let key = block_n_min_10.into();
233-
executor
234-
.block_state
235-
.as_mut()
236-
.expect("Blockifier block context has been taken")
237-
.set_storage_at(contract_address, key, block_hash_n_min_10)
238-
.context("Cannot set storage value in cache")?;
223+
// Create the TransactionExecutor with block_n-10 handling, reusing the layered_state_adapter.
224+
let executor = crate::util::create_executor_with_block_n_min_10(
225+
&self.backend,
226+
&exec_ctx,
227+
state.state_adaptor,
228+
|block_n| self.wait_for_hash_of_block_min_10(block_n),
229+
)?;
239230

240-
tracing::debug!(
241-
"State diff inserted {:#x} {:#x} => {block_hash_n_min_10:#x}",
242-
contract_address.to_felt(),
243-
key.to_felt()
244-
);
245-
}
246231
Ok(ExecutorStateExecuting {
247232
exec_ctx,
248233
executor,
@@ -433,7 +418,11 @@ impl ExecutorThread {
433418
);
434419
let block_exec_summary = execution_state.executor.finalize()?;
435420

436-
if self.replies_sender.blocking_send(super::ExecutorMessage::EndBlock(Box::new(block_exec_summary))).is_err() {
421+
if self
422+
.replies_sender
423+
.blocking_send(super::ExecutorMessage::EndBlock(Box::new(block_exec_summary)))
424+
.is_err()
425+
{
437426
// Receiver closed
438427
break Ok(());
439428
}

0 commit comments

Comments
 (0)