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

feat: L3 support #437

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8949443
feat : l3 support init
ocdbytes Dec 18, 2024
abc808e
code : refactor
ocdbytes Dec 18, 2024
a49e209
feat : added tests for starknet client
ocdbytes Dec 20, 2024
0d6168e
changelog update
ocdbytes Dec 20, 2024
76bc944
Merge branch 'main' into l3-support
ocdbytes Dec 20, 2024
75229a4
fix : lint
ocdbytes Dec 20, 2024
661cd33
feat: added update state worker test for starknet client
ocdbytes Dec 20, 2024
62fb337
feat : added messaging implementation for l2 client & resolved commen…
ocdbytes Dec 26, 2024
d4aa988
feat : updated l2 messaging implementation
ocdbytes Dec 27, 2024
a4314be
feat : updated l2 messaging implementation
ocdbytes Dec 27, 2024
9dea223
feat : updated messaging logic
ocdbytes Dec 27, 2024
fafd2c3
clients refactoring done
ocdbytes Jan 6, 2025
aa7834e
refactor : tests
ocdbytes Jan 6, 2025
6c1ff95
fix : tests
ocdbytes Jan 7, 2025
26c9319
feat : updated streams and added tests for streams
ocdbytes Jan 14, 2025
2a19391
fix : changed event params in messaging contract
ocdbytes Jan 14, 2025
8abf999
refactor : removed external devnet.yaml file
ocdbytes Jan 14, 2025
749df1c
feat : removed expects
ocdbytes Jan 14, 2025
b63cf61
refactor crates structure
ocdbytes Jan 14, 2025
c837570
merge main
ocdbytes Jan 14, 2025
1d4d3a4
resolved comments
ocdbytes Jan 15, 2025
fffd9dd
refactor
ocdbytes Jan 17, 2025
71c5524
feat : added automock tests and resolved comments
ocdbytes Jan 21, 2025
62d1df3
merge : main
ocdbytes Jan 21, 2025
79ef5ab
refactor
ocdbytes Jan 21, 2025
8657da3
refactor code and comments resolved
ocdbytes Jan 22, 2025
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
9 changes: 9 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ jobs:
with:
version: nightly

# TODO : For now madara binary is stored in aws s3 bucket :
# After the proper release binaries are implemented
# We can directly use that and we can remove this
# temporary AWS implementation
- name: Download madara binary for l2 client testing
run: |
curl -L https://madara-test-binary.s3.us-west-1.amazonaws.com/madara-linux -o ./test-artifacts/madara
chmod +x ./test-artifacts/madara

- name: Build and run tests
env:
ETH_FORK_URL: ${{ secrets.ETH_FORK_URL }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/rust-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ jobs:
while ! nc -z localhost 8545; do
sleep 1
done
# TODO : For now madara binary is stored in aws s3 bucket :
# After the proper release binaries are implemented
# We can directly use that and we can remove this
# temporary AWS implementation
- name: Download madara binary for l2 client testing
run: |
curl -L https://madara-test-binary.s3.us-west-1.amazonaws.com/madara-linux -o ./test-artifacts/madara
chmod +x ./test-artifacts/madara

- name: Run unit tests
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ tmp/
# Running madara with make and docker compose
.secrets
image.tar.gz

# madara test artifacts for testing l2 clients for appchains
test-artifacts/madara
apoorvsadana marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- feat : l3 support
- fix: devnet accounts getting deployed in sequencer mode
- fix(rpc): fix BroadcastedDeclareTxn V3 in starknet-types-rpc
- fix: oracle need condition
Expand Down
101 changes: 55 additions & 46 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [
"crates/client/db",
"crates/client/exec",
"crates/client/sync",
"crates/client/eth",
"crates/client/settlement_client",
"crates/client/rpc",
"crates/client/gateway/client",
"crates/client/gateway/server",
Expand Down Expand Up @@ -33,7 +33,7 @@ default-members = [
"crates/client/db",
"crates/client/exec",
"crates/client/sync",
"crates/client/eth",
"crates/client/settlement_client",
"crates/client/gateway/client",
"crates/client/gateway/server",
"crates/client/rpc",
Expand Down Expand Up @@ -127,7 +127,7 @@ mc-rpc = { path = "crates/client/rpc" }
mc-gateway-client = { path = "crates/client/gateway/client" }
mc-gateway-server = { path = "crates/client/gateway/server" }
mc-sync = { path = "crates/client/sync" }
mc-eth = { path = "crates/client/eth" }
mc-settlement-client = { path = "crates/client/settlement_client" }
mc-mempool = { path = "crates/client/mempool" }
mc-block-production = { path = "crates/client/block_production" }
mc-block-import = { path = "crates/client/block_import" }
Expand Down
2 changes: 1 addition & 1 deletion cairo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
These contracts are used for the genesis block in devnet mode. For real world use, the [madara bootstrapper] is used instead.
We use [OpenZeppelin] contracts.

[OpenZeppelin]: https://docs.openzeppelin.com
[openzeppelin]: https://docs.openzeppelin.com
[madara bootstrapper]: https://github.com/madara-alliance/madara-bootstrapper
38 changes: 0 additions & 38 deletions crates/client/eth/src/sync.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
description = "This crate is responsible to handle l1 communication"
name = "mc-eth"
name = "mc-settlement-client"
authors.workspace = true
edition.workspace = true
license.workspace = true
Expand Down Expand Up @@ -35,13 +35,19 @@ starknet_api.workspace = true
# Other
alloy.workspace = true
anyhow.workspace = true
assert_matches = "1.5.0"
bigdecimal.workspace = true
bitvec.workspace = true
futures = { workspace = true, default-features = true }

regex = "1.10.5"
serde = { workspace = true, default-features = true }
serde_json = "1"
starknet-accounts = "0.11.0"
Mohiiit marked this conversation as resolved.
Show resolved Hide resolved
starknet-contract = "0.11.0"
starknet-core = { workspace = true }
starknet-providers = { workspace = true }
starknet-signers = { workspace = true }
apoorvsadana marked this conversation as resolved.
Show resolved Hide resolved
thiserror.workspace = true
time = "0.3.36"
tokio = { workspace = true, features = [
Expand All @@ -54,6 +60,7 @@ url.workspace = true


#Instrumentation
async-trait = { workspace = true }
opentelemetry = { workspace = true, features = ["metrics", "logs"] }
opentelemetry-appender-tracing = { workspace = true, default-features = false }
opentelemetry-otlp = { workspace = true, features = [
Expand Down
File renamed without changes.
94 changes: 94 additions & 0 deletions crates/client/settlement_client/src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use crate::eth::StarknetCoreContract::StarknetCoreContractInstance;
use crate::gas_price::L1BlockMetrics;
use crate::state_update::StateUpdate;
use alloy::contract::Event;
use alloy::primitives::FixedBytes;
use alloy::providers::RootProvider;
use alloy::sol_types::SolEvent;
use alloy::transports::http::{Client, Http};
use async_trait::async_trait;
use mc_db::MadaraBackend;
use mp_utils::service::ServiceContext;
use starknet_types_core::felt::Felt;
use std::sync::Arc;

pub enum ClientType {
ETH,
STARKNET,
}

pub enum CoreContractInstance {
Ethereum(StarknetCoreContractInstance<Http<Client>, RootProvider<Http<Client>>>),
Starknet(Felt),
}

impl CoreContractInstance {
#[allow(clippy::type_complexity)]
pub fn event_filter<T: SolEvent>(&self) -> anyhow::Result<Event<Http<Client>, &RootProvider<Http<Client>>, T>> {
match self {
CoreContractInstance::Ethereum(contract) => Ok(contract.event_filter()),
CoreContractInstance::Starknet(_) => Err(anyhow::anyhow!("Starknet doesn't support event filters")),
apoorvsadana marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

#[async_trait]
pub trait ClientTrait: Send + Sync {
// Provider type used by the implementation
type Provider;
apoorvsadana marked this conversation as resolved.
Show resolved Hide resolved
// Configuration type used for initialization
type Config;

// Basic getter functions
fn get_l1_block_metrics(&self) -> &L1BlockMetrics;
fn get_core_contract_instance(&self) -> CoreContractInstance;
fn get_client_type(&self) -> ClientType;

// Create a new instance of the client
async fn new(config: Self::Config) -> anyhow::Result<Self>
where
Self: Sized;

// Get the latest block number
async fn get_latest_block_number(&self) -> anyhow::Result<u64>;

// Get the block number of the last occurrence of a specific event
async fn get_last_event_block_number(&self) -> anyhow::Result<u64>;

// Get the last verified block number
async fn get_last_verified_block_number(&self) -> anyhow::Result<u64>;

// Get the last state root
// - change this to Felt in implementation
// - write tests for conversion to Felt from <native-type>
async fn get_last_state_root(&self) -> anyhow::Result<Felt>;
Mohiiit marked this conversation as resolved.
Show resolved Hide resolved

// Get the last verified block hash
async fn get_last_verified_block_hash(&self) -> anyhow::Result<Felt>;

// Get initial state from client
async fn get_initial_state(&self) -> anyhow::Result<StateUpdate>;
async fn listen_for_update_state_events(
&self,
backend: Arc<MadaraBackend>,
ctx: ServiceContext,
) -> anyhow::Result<()>;

// get gas prices
async fn get_eth_gas_prices(&self) -> anyhow::Result<(u128, u128)>;
apoorvsadana marked this conversation as resolved.
Show resolved Hide resolved

/// Get cancellation status of an L1 to L2 message
///
/// This function query the core contract to know if a L1->L2 message has been cancelled
/// # Arguments
///
/// - msg_hash : Hash of L1 to L2 message
///
/// # Return
///
/// - A felt representing a timestamp :
/// - 0 if the message has not been cancelled
/// - timestamp of the cancellation if it has been cancelled
/// - An Error if the call fail
async fn get_l1_to_l2_message_cancellations(&self, msg_hash: FixedBytes<32>) -> anyhow::Result<Felt>;
}
Loading
Loading