Skip to content

Commit

Permalink
Remove subxt code generation (#186)
Browse files Browse the repository at this point in the history
* update subxt and polkadot deps

* remove subxt metadata generation from webb-rs

* update CI job and ark deps
  • Loading branch information
salman01zp authored Mar 7, 2024
1 parent 05c3441 commit 580cced
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 49,142 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Install Mold Linker
uses: rui314/setup-mold@v1
- name: Check Metadata generation
run: cargo build --features generate-substrate,generate-contracts
run: cargo build --features generate-contracts
- name: Tests
run: cargo test -p webb
- name: Rustdoc build
Expand All @@ -50,11 +50,9 @@ jobs:
os: [ubuntu-latest, macos-latest]
features:
- evm,std,scale
- substrate,std
- evm
test-features:
- evm,std,scale
- substrate,std
runs-on: ${{ matrix.os }}
# Name should be the OS name only (e.g. Linux, macOS, Windows)
# This is used to generate the badge
Expand Down
23 changes: 5 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ readme = "README.md"
keywords = ["webb", "sdk", "blockchain", "webb-tools"]

[workspace.dependencies]
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0.152", default-features = false, features = ["derive"] }
hex = { version = "0.4", default-features = false }
ethers-core = { version = "2.0.11", default-features = false }
ethers = { version = "=2.0.13", default-features = false, features = ["legacy", "abigen"] }
ethers = { version = "=2.0.13", default-features = false, features = ["legacy", "abigen" , "ethers-solc", "etherscan" ] }
thiserror = "1"

[package]
Expand All @@ -35,46 +34,34 @@ homepage = { workspace = true }
members = [".", "proposals", "proposal-derive", "bridge-proofs", "evm-test-utils", "circom-proving"]

[dependencies]
# Substrate crates.
scale = { package = "parity-scale-codec", version = "3", default-features = false, optional = true }
scale-info = { workspace = true, optional = true }
subxt = { version = "0.31.0", optional = true }
async-trait = "0.1"
rand = { version = "0.8", default-features = false, features = ["getrandom"] }
thiserror = "1.0.38"
hex = { workspace = true }
# EVM crates.
ethers = { workspace = true, optional = true, features = ["legacy", "abigen", "ethers-solc", "etherscan"] }
serde = { workspace = true }
serde_json = { version = "1", optional = true }
serde_json = { version = "^1.0.111", optional = true }

# Used by ethers (but we need it to be vendored with the lib).
openssl = { version = "0.10", features = ["vendored"], optional = true }

[dev-dependencies]
tokio = { version = "^1", features = ["macros", "rt"] }
anyhow = "^1"
sp-keyring = "26.0.0"
subxt-signer = { version = "0.31.0", features = ["subxt"] }

[build-dependencies]
prettyplease = "0.2"
serde_json = "1"
serde_json = "^1.0.111"
tempfile = "3.3"
ethers = { workspace = true, default-features = false, optional = true, features = ["legacy", "abigen", "etherscan"] }
ethers = { workspace = true, default-features = false, optional = true, features = ["legacy", "abigen", "ethers-solc", "etherscan"] }
syn = { version = "2", features = ["full", "parsing"], optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, optional = true }
subxt-metadata = { version = "0.31.0", optional = true }
subxt-codegen = { version = "0.31.0", optional = true }

[features]
default = ["substrate-runtime", "evm-runtime"]
# Main features.
substrate-runtime = ["subxt", "scale", "scale-info"]
default = ["evm-runtime"]
evm-runtime = ["ethers", "serde_json"]
# Tests
integration-tests = []
# Build
generate-contracts = ["evm-runtime", "syn"]
generate-substrate = ["subxt-codegen", "syn", "subxt-metadata", "scale"]

28 changes: 0 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,6 @@

<br />

### Downloading metadata from a Substrate node

Use the [`subxt-cli`](https://lib.rs/crates/subxt-cli) tool to download the metadata for your target runtime from a node.

1. Install:
```bash
cargo install subxt-cli
```

2. To Save the metadata of `tangle`:
Run the release build of the `tangle` node, then on another terminal run:

```bash
subxt metadata -f bytes > ./metadata/tangle-runtime.scale
```
Same goes for any future runtimes.

> Note: This defaults to querying the metadata of a locally running node on the default `http://localhost:9933/`. If querying
a different node then the `metadata` command accepts a `--url` argument.

4. Generating the rust code from the metadata:

```bash
cargo build --features generate-substrate
```

> Tip: See the [build.rs](./build.rs) file to see how everything is being generated.

### Generating EVM Contracts

Expand Down
2 changes: 1 addition & 1 deletion bridge-proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rlp = { version = "0.5", default-features = false }
tiny-keccak = { version = "2.0.0", default-features = false, features = ["keccak"] }
rlp-derive = { version = "0.1.0", default-features = false }

serde_json = { version = "1.0.83", optional = true }
serde_json = { version = "^1.0.111", optional = true }
serde = { version = "1.0.143", optional = true }
hex = "0.4.3"

Expand Down
67 changes: 0 additions & 67 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::error::Error;

#[cfg(feature = "generate-substrate")]
use subxt_codegen::TypeSubstitutes;

#[cfg(feature = "generate-contracts")]
mod evm {
use super::*;
Expand Down Expand Up @@ -246,66 +243,6 @@ mod evm {
}
}

#[cfg(feature = "generate-substrate")]
mod substrate {
use super::*;
use scale::Decode;
use subxt_codegen::CratePath;

fn parse_and_generate_runtime(
path: &str,
out: &str,
) -> Result<(), Box<dyn Error>> {
println!("cargo:rerun-if-changed=./{}", path);
let bytes = std::fs::read(path)?;

let metadata =
<subxt_metadata::Metadata as Decode>::decode(&mut &bytes[..])?;
let crate_path = CratePath::default();
// Module under which the API is generated.
let item_mod = syn::parse_quote!(
pub mod api {}
);
// Default type substitutes.
let substs = TypeSubstitutes::with_default_substitutes(&crate_path);
// Generate the Runtime API.
let generator = subxt_codegen::RuntimeGenerator::new(metadata);
let mut generated_type_derives =
subxt_codegen::DerivesRegistry::with_default_derives(&crate_path);

generated_type_derives.extend_for_all(
[
syn::parse_quote!(Eq),
syn::parse_quote!(PartialEq),
syn::parse_quote!(Clone),
]
.into_iter(),
[],
);

// Include metadata documentation in the Runtime API.
let generate_docs = true;
let runtime_api = generator.generate_runtime(
item_mod,
generated_type_derives,
substs,
crate_path,
generate_docs,
)?;
let syntax_tree = syn::parse_file(&runtime_api.to_string()).unwrap();
let formatted = prettyplease::unparse(&syntax_tree);
std::fs::write(out, formatted)?;
Ok(())
}

pub fn generate_tangle_runtime() -> Result<(), Box<dyn Error>> {
parse_and_generate_runtime(
"metadata/tangle-runtime.scale",
"src/substrate/tangle_runtime.rs",
)
}
}

fn main() -> Result<(), Box<dyn Error>> {
#[cfg(feature = "generate-contracts")]
{
Expand Down Expand Up @@ -335,9 +272,5 @@ fn main() -> Result<(), Box<dyn Error>> {
evm::build_protocol_solidity_masp_vanchor_tree()?;
evm::build_protocol_solidity_masp_vanchor()?;
}
#[cfg(feature = "generate-substrate")]
{
substrate::generate_tangle_runtime()?;
}
Ok(())
}
2 changes: 1 addition & 1 deletion evm-test-utils/src/local_evm_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use webb::evm::contract::protocol_solidity::{
treasury::TreasuryContract, treasury_handler::TreasuryHandlerContract,
};
use webb::evm::ethers;
use webb::evm::ethers::signers::{LocalWallet, Signer};
use webb::evm::ethers::signers::Signer;
use webb::evm::ethers::types::U256;
use webb_proposals::TypedChainId;

Expand Down
Binary file removed metadata/tangle-runtime.scale
Binary file not shown.
5 changes: 2 additions & 3 deletions proposals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ homepage = { workspace = true }
[dependencies]
scale-codec = { package = 'parity-scale-codec', version = '3.0.0', default-features = false, optional = true, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.1.1", default-features = false, optional = true }
frame-support = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.0", optional = true }
num-traits = { version = "0.2.15", default-features = false }
typed-builder = { version = "0.18", default-features = false, optional = true }
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
Expand All @@ -32,8 +31,8 @@ serde = { workspace = true, default-features = false, features = ["alloc"] }

[features]
default = ["std", "evm", "substrate", "scale", "ink"]
std = ["scale-codec/std", "scale-info/std", "num-traits/std", "serde/std", "hex/std", "frame-support/std", "proposal-derive/std"]
std = ["scale-codec/std", "scale-info/std", "num-traits/std", "serde/std", "hex/std", "proposal-derive/std"]
scale = ["scale-codec", "scale-info/derive"]
evm = ["serde"]
substrate = ["scale", "typed-builder", "frame-support", "serde"]
substrate = ["scale", "typed-builder", "serde"]
ink = ["scale", "typed-builder"]
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@

#[cfg(feature = "evm-runtime")]
pub mod evm;
#[cfg(feature = "substrate-runtime")]
pub mod substrate;
6 changes: 0 additions & 6 deletions src/substrate/mod.rs

This file was deleted.

Loading

0 comments on commit 580cced

Please sign in to comment.