Skip to content

Commit

Permalink
Merge pull request #40 from centrifuge/feature/redesign-state-and-env
Browse files Browse the repository at this point in the history
Feature/redesign state and env
  • Loading branch information
mustermeiszer authored Nov 3, 2022
2 parents dd54f8b + 111ed26 commit 0c5be9c
Show file tree
Hide file tree
Showing 20 changed files with 1,477 additions and 1,239 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

10 changes: 9 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ async-trait = "0.1.52"
parking_lot = "0.12.1"
lazy_static = "1.4.0"
tracing = "0.1.3"
thiserror = "1.0"
tokio = { version = "1.15", features = ["macros"] }

# Local dependencies
fudge-companion = { path = "./src/builder/companion"}
Expand All @@ -26,6 +28,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkad
sp-storage = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
Expand Down Expand Up @@ -71,7 +74,6 @@ cumulus-relay-chain-inprocess-interface= { git = "https://github.com/paritytech/

[dev-dependencies]
polkadot-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.29" }
tokio = { version = "1.15", features = ["macros"] }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
Expand All @@ -80,3 +82,9 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/substrate",
tracing-subscriber = "0.2"
pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" }
fudge-test-runtime = {path = "./src/tests/test-parachain", default-features = true}

[features]
default = []
runtime-benchmarks = [
'frame-benchmarking/runtime-benchmarks'
]
58 changes: 37 additions & 21 deletions core/src/builder/companion/src/expand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,17 @@ pub fn expand(def: CompanionDef) -> SynResult<TokenStream> {
#(#others_names,)*
};

#(
let para = _hidden_FudgeParaChain {
id: _hidden_ParaId::from(#parachain_ids),
head: companion.#parachain_names.head(),
code: companion.#parachain_names.code(),
};
companion.#relay_chain_name.onboard_para(para).map_err(|_| ()).map(|_| ())?;

)*
{
#(
__hidden_tracing::enter_span!(sp_tracing::Level::INFO, std::stringify!(#relay_chain_name - Onboarding(#parachain_names):));
let para = _hidden_FudgeParaChain {
id: _hidden_ParaId::from(#parachain_ids),
head: companion.#parachain_names.head(),
code: companion.#parachain_names.code(),
};
companion.#relay_chain_name.onboard_para(para).map_err(|_| ()).map(|_| ())?;
)*
}

Ok(companion)
}
Expand All @@ -158,14 +160,16 @@ pub fn expand(def: CompanionDef) -> SynResult<TokenStream> {
pub fn append_extrinsic(&mut self, chain: _hidden_Chain, xt: Vec<u8>) -> Result<(), ()> {
match chain {
_hidden_Chain::Relay => {
self.#relay_chain_name.append_extrinsic(__hidden_Decode::decode(&mut xt.as_slice()).map_err(|_|())?);
Ok(())
self.#relay_chain_name.append_extrinsic(__hidden_Decode::decode(&mut xt.as_slice()).map_err(|_|())?)
.map(|_|())
.map_err(|_|())
},
_hidden_Chain::Para(id) => match id {
#(
_ if id == #parachain_ids => {
self.#parachain_names.append_extrinsic(__hidden_Decode::decode(&mut xt.as_slice()).map_err(|_|())?);
Ok(())
self.#parachain_names.append_extrinsic(__hidden_Decode::decode(&mut xt.as_slice()).map_err(|_|())?)
.map(|_|())
.map_err(|_|())
},
)*
_ => return Err(()),
Expand All @@ -175,10 +179,16 @@ pub fn expand(def: CompanionDef) -> SynResult<TokenStream> {

pub fn with_state<R>(&self, chain: _hidden_Chain, exec: impl FnOnce() -> R) -> Result<R, ()> {
match chain {
_hidden_Chain::Relay => self.#relay_chain_name.with_state(exec).map_err(|_| ()),
_hidden_Chain::Relay => {
__hidden_tracing::enter_span!(sp_tracing::Level::INFO, std::stringify!(#relay_chain_name - with_state:));
self.#relay_chain_name.with_state(exec).map_err(|_| ())
},
_hidden_Chain::Para(id) => match id {
#(
_ if id == #parachain_ids => self.#parachain_names.with_state(exec).map_err(|_| ()),
_ if id == #parachain_ids => {
__hidden_tracing::enter_span!(sp_tracing::Level::INFO, std::stringify!(#parachain_names - with_state:));
self.#parachain_names.with_state(exec).map_err(|_| ())
},
)*
_ => Err(())
}
Expand All @@ -187,10 +197,16 @@ pub fn expand(def: CompanionDef) -> SynResult<TokenStream> {

pub fn with_mut_state<R>(&mut self, chain: _hidden_Chain, exec: impl FnOnce() -> R) -> Result<R, ()> {
match chain {
_hidden_Chain::Relay => self.#relay_chain_name.with_mut_state(exec).map_err(|_| ()),
_hidden_Chain::Relay => {
__hidden_tracing::enter_span!(sp_tracing::Level::INFO, std::stringify!(#relay_chain_name - with_state:));
self.#relay_chain_name.with_mut_state(exec).map_err(|_| ())
},
_hidden_Chain::Para(id) => match id {
#(
_ if id == #parachain_ids => self.#parachain_names.with_mut_state(exec).map_err(|_| ()),
_ if id == #parachain_ids => {
__hidden_tracing::enter_span!(sp_tracing::Level::INFO, std::stringify!(#parachain_names - with_state:));
self.#parachain_names.with_mut_state(exec).map_err(|_| ())
},
)*
_ => Err(())
}
Expand All @@ -199,28 +215,28 @@ pub fn expand(def: CompanionDef) -> SynResult<TokenStream> {

pub fn evolve(&mut self) -> Result<(), ()> {
{
__hidden_tracing::enter_span!(sp_tracing::Level::TRACE, std::stringify!(#relay_chain_name - BlockBuilding:));
__hidden_tracing::enter_span!(sp_tracing::Level::INFO, std::stringify!(#relay_chain_name - BlockBuilding:));
self.#relay_chain_name.build_block().map_err(|_| ()).map(|_| ())?;
self.#relay_chain_name.import_block().map_err(|_| ()).map(|_| ())?;
}

{
#(
__hidden_tracing::enter_span!(sp_tracing::Level::TRACE, std::stringify!(#parachain_names - BlockBuilding:));
__hidden_tracing::enter_span!(sp_tracing::Level::INFO, std::stringify!(#parachain_names - BlockBuilding:));
self.#parachain_names.build_block().map_err(|_| ()).map(|_| ())?;
self.#parachain_names.import_block().map_err(|_| ()).map(|_| ())?;
)*
}

{
__hidden_tracing::enter_span!(sp_tracing::Level::TRACE, std::stringify!(#relay_chain_name - BlockBuilding:));
__hidden_tracing::enter_span!(sp_tracing::Level::INFO, std::stringify!(#relay_chain_name - BlockBuilding:));
self.#relay_chain_name.build_block().map_err(|_| ()).map(|_| ())?;
self.#relay_chain_name.import_block().map_err(|_| ()).map(|_| ())?;
}

{
#(
__hidden_tracing::enter_span!(sp_tracing::Level::TRACE, std::stringify!(#relay_chain_name - Onboarding(#parachain_names):));
__hidden_tracing::enter_span!(sp_tracing::Level::INFO, std::stringify!(#relay_chain_name - Onboarding(#parachain_names):));
let para = _hidden_FudgeParaChain {
id: _hidden_ParaId::from(#parachain_ids),
head: self.#parachain_names.head(),
Expand Down
Loading

0 comments on commit 0c5be9c

Please sign in to comment.