Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Predeployed accounts (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juul-Mc-Goa authored Dec 15, 2023
1 parent 32b5468 commit d488697
Show file tree
Hide file tree
Showing 34 changed files with 549 additions and 202 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/madara-commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: target/release/madara
path: |
target/release/madara
configs
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
fail-on-cache-miss: true
- name: Run setup
run: |
target/release/madara setup --chain local --from-remote
target/release/madara setup --chain local --from-local=configs
- name: Create build-spec (plain)
run: |
target/release/madara build-spec --chain local > chain-plain.json
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/rust-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jobs:
shared-key: "cache"
- uses: actions/cache@v3
with:
path: target/release/madara
path: |
target/release/madara
configs
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/starknet-js-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: target/release/madara
path: |
target/release/madara
configs
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/starknet-rpc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ jobs:
save-if: false
- uses: actions/cache@v3
with:
path: target/release/madara
path: |
target/release/madara
configs
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
Expand Down
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: add predeployed accounts to genesis state
- feat(rpc): Added starknet_simulateTransactions
- fix: Change serialization of bitvec to &[u8] in merkle tree to avoid memory
uninitialized
Expand Down
33 changes: 33 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"crates/runtime",
"crates/pallets/starknet/runtime_api/",
"crates/pallets/starknet",
"crates/primitives/genesis-config/",
"crates/primitives/digest-log",
"crates/primitives/transactions",
"crates/primitives/felt",
Expand All @@ -16,6 +17,7 @@ members = [
"crates/primitives/storage",
"crates/primitives/commitments",
"crates/primitives/chain-id",
"crates/client/genesis-data-provider",
"crates/client/db",
"crates/client/rpc-core",
"crates/client/rpc",
Expand All @@ -31,6 +33,7 @@ default-members = [
"crates/runtime",
"crates/pallets/starknet/runtime_api/",
"crates/pallets/starknet",
"crates/primitives/genesis-config/",
"crates/primitives/digest-log",
"crates/primitives/transactions",
"crates/primitives/felt",
Expand All @@ -42,6 +45,7 @@ default-members = [
"crates/primitives/storage",
"crates/primitives/commitments",
"crates/primitives/chain-id",
"crates/client/genesis-data-provider",
"crates/client/db",
"crates/client/rpc-core",
"crates/client/rpc",
Expand Down Expand Up @@ -151,6 +155,7 @@ pallet-timestamp = { default-features = false, git = "https://github.com/parityt
pallet-starknet = { path = "crates/pallets/starknet", default-features = false }
pallet-starknet-runtime-api = { path = "crates/pallets/starknet/runtime_api", default-features = false }
# Madara primtitives
mp-genesis-config = { path = "crates/primitives/genesis-config", default-features = false }
mp-digest-log = { path = "crates/primitives/digest-log", default-features = false }
mp-block = { path = "crates/primitives/block", default-features = false }
mp-fee = { path = "crates/primitives/fee", default-features = false }
Expand All @@ -165,6 +170,7 @@ mp-chain-id = { path = "crates/primitives/chain-id", default-features = false }
mp-simulations = { path = "crates/primitives/simulations", default-features = false }

# Madara client
mc-genesis-data-provider = { path = "crates/client/genesis-data-provider" }
mc-mapping-sync = { path = "crates/client/mapping-sync" }
mc-db = { path = "crates/client/db" }
mc-storage = { path = "crates/client/storage" }
Expand Down
36 changes: 36 additions & 0 deletions configs/genesis-assets/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,42 @@
"0x01d53d50d204842575c87f25161248aadb26d33c7375d0f043e2a3f1243cf874"
]
],
"predeployed_accounts": [
{
"contract_address": "0x1",
"class_hash": "0x0279d77db761fba82e0054125a6fdb5f6baa6286fa3fb73450cc44d193c2d37f",
"name": "No Validation Account",
"private_key": null
},
{
"contract_address": "0x2",
"class_hash": "0x06f0d6f6ae72e1a507ff4b65181291642889742dbf8f1a53e9ec1c595d01ba7d",
"name": "Argent Account",
"private_key": [
48, 120, 48, 48, 99, 49, 99, 102, 49, 52, 57, 48, 100, 101, 49, 51, 53,
50, 56, 54, 53, 51, 48, 49, 98, 98, 56, 55, 48, 53, 49, 52, 51, 102, 51,
101, 102, 57, 51, 56, 102, 57, 55, 102, 100, 102, 56, 57, 50, 102, 49,
48, 57, 48, 100, 99, 98, 53, 97, 99, 55, 98, 99, 100, 49, 100
]
},
{
"contract_address": "0x3",
"class_hash": "0x006280083f8c2a2db9f737320d5e3029b380e0e820fe24b8d312a6a34fdba0cd",
"name": "Openzeppelin Account",
"private_key": [
48, 120, 48, 48, 99, 49, 99, 102, 49, 52, 57, 48, 100, 101, 49, 51, 53,
50, 56, 54, 53, 51, 48, 49, 98, 98, 56, 55, 48, 53, 49, 52, 51, 102, 51,
101, 102, 57, 51, 56, 102, 57, 55, 102, 100, 102, 56, 57, 50, 102, 49,
48, 57, 48, 100, 99, 98, 53, 97, 99, 55, 98, 99, 100, 49, 100
]
},
{
"contract_address": "0x4",
"class_hash": "0x35ccefcf9d5656da623468e27e682271cd327af196785df99e7fee1436b6276",
"name": "No Validation Account (cairo 1)",
"private_key": null
}
],
"storage": [
[
[
Expand Down
4 changes: 2 additions & 2 deletions configs/index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"remote_base_path": "https://raw.githubusercontent.com/keep-starknet-strange/madara/main/configs/",
"remote_base_path": "https://raw.githubusercontent.com/Juul-Mc-Goa/madara/main/configs/",
"genesis_assets": [
{
"name": "Account.json",
Expand Down Expand Up @@ -31,7 +31,7 @@
},
{
"name": "genesis.json",
"md5": "d35a8d77f9d7d18ff48a5dac2685eb5b"
"md5": "eab09ab8efae29edbb534c077f1a8179"
},
{
"name": "NoValidateAccount.casm.json",
Expand Down
16 changes: 16 additions & 0 deletions crates/client/genesis-data-provider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "mc-genesis-data-provider"
authors.workspace = true
edition.workspace = true
repository.workspace = true
version.workspace = true

[dependencies]
anyhow = { workspace = true }
jsonrpsee = { workspace = true, default-features = true }
log = { workspace = true, default-features = true }
mp-genesis-config = { workspace = true }
pallet-starknet = { workspace = true, default-features = true }
serde = { workspace = true, default-features = true }
serde_json = { workspace = true, default-features = true }
thiserror = { workspace = true }
2 changes: 2 additions & 0 deletions crates/client/genesis-data-provider/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub const GENESIS_ASSETS_DIR: &str = "genesis-assets";
pub const GENESIS_ASSETS_FILE: &str = "genesis.json";
42 changes: 42 additions & 0 deletions crates/client/genesis-data-provider/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
mod constants;

use std::path::PathBuf;

use constants::{GENESIS_ASSETS_DIR, GENESIS_ASSETS_FILE};
use jsonrpsee::types::error::CallError;
use mp_genesis_config::GenesisData;

pub trait GenesisProvider {
type LoadGenesisDataError: std::error::Error;
fn load_genesis_data(&self) -> Result<GenesisData, LoadGenesisDataError>;
}

pub struct OnDiskGenesisConfig(pub PathBuf);

#[derive(thiserror::Error, Debug)]
pub enum LoadGenesisDataError {
#[error("File cannot be deserialized into a GenesisData struct")]
InvalidJson,
#[error("Unable to read genesis file: invalid path")]
InvalidPath,
}

impl From<LoadGenesisDataError> for jsonrpsee::core::Error {
fn from(e: LoadGenesisDataError) -> Self {
jsonrpsee::core::Error::Call(CallError::Failed(anyhow::Error::from(e)))
}
}

impl GenesisProvider for OnDiskGenesisConfig {
type LoadGenesisDataError = LoadGenesisDataError;

fn load_genesis_data(&self) -> Result<GenesisData, Self::LoadGenesisDataError> {
let genesis_path = self.0.join(GENESIS_ASSETS_DIR).join(GENESIS_ASSETS_FILE);

log::info!("Loading genesis data at: {}", genesis_path.display());

std::fs::read_to_string(genesis_path.clone()).map_or(Err(LoadGenesisDataError::InvalidPath), |s| {
serde_json::from_str::<GenesisData>(&s).map_err(|_| LoadGenesisDataError::InvalidJson)
})
}
}
2 changes: 2 additions & 0 deletions crates/client/rpc-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ jsonrpsee = { workspace = true, features = [
mp-block = { workspace = true }
mp-digest-log = { workspace = true }
mp-felt = { workspace = true }
mp-genesis-config = { workspace = true }
mp-simulations = { workspace = true }
mp-transactions = { workspace = true, features = ["serde"] }
num-bigint = { workspace = true }
pallet-starknet = { workspace = true }
serde = { workspace = true, default-features = true }
serde_json = { workspace = true }
serde_with = { workspace = true }
Expand Down
14 changes: 14 additions & 0 deletions crates/client/rpc-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod utils;

use mp_simulations::{SimulatedTransaction, SimulationFlag};
use mp_transactions::TransactionStatus;
use pallet_starknet::genesis_loader::PredeployedAccount;
use starknet_core::serde::unsigned_field_element::UfeHex;
use starknet_core::types::{
BlockHashAndNumber, BlockId, BroadcastedDeclareTransaction, BroadcastedDeployAccountTransaction,
Expand All @@ -29,6 +30,19 @@ use starknet_core::types::{
#[derive(Serialize, Deserialize)]
pub struct Felt(#[serde_as(as = "UfeHex")] pub FieldElement);

#[derive(Serialize, Deserialize)]
pub struct PredeployedAccountWithBalance {
pub account: PredeployedAccount,
pub balance: FieldElement,
}

/// Madara rpc interface for additional features.
#[rpc(server, namespace = "madara")]
pub trait MadaraRpcApi: StarknetReadRpcApi {
#[method(name = "predeployedAccounts")]
fn predeployed_accounts(&self) -> RpcResult<Vec<PredeployedAccountWithBalance>>;
}

/// Starknet write rpc interface.
#[rpc(server, namespace = "starknet")]
pub trait StarknetWriteRpcApi {
Expand Down
2 changes: 2 additions & 0 deletions crates/client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ repository = "https://github.com/keep-starknet-strange/madara"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
# Madara utils
mc-genesis-data-provider = { workspace = true }
# Madara runtime
pallet-starknet = { workspace = true, default-features = true }
pallet-starknet-runtime-api = { workspace = true, default-features = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/client/rpc/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::errors::StarknetRpcApiError;
use crate::types::{ContinuationToken, RpcEventFilter};
use crate::Starknet;

impl<A: ChainApi, B, BE, C, P, H> Starknet<A, B, BE, C, P, H>
impl<A: ChainApi, B, BE, G, C, P, H> Starknet<A, B, BE, G, C, P, H>
where
B: BlockT,
C: HeaderBackend<B> + BlockBackend<B> + StorageProvider<B, BE> + 'static,
Expand Down
Loading

0 comments on commit d488697

Please sign in to comment.