Skip to content

Commit

Permalink
Rollup refactor (#687)
Browse files Browse the repository at this point in the history
Rollup refactor
  • Loading branch information
mateuszaaa authored Feb 8, 2024
2 parents 71abd93 + fc948e4 commit e06b4d1
Show file tree
Hide file tree
Showing 20 changed files with 2,253 additions and 633 deletions.
40 changes: 37 additions & 3 deletions Cargo.lock

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

874 changes: 874 additions & 0 deletions Cargo.toml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ mangata-kusama-runtime = { path = "../runtime/mangata-kusama" }
mangata-rococo-runtime = { path = "../runtime/mangata-rococo" }
xyk-rpc = { path = "../pallets/xyk/rpc" }
xyk-runtime-api = { path = "../pallets/xyk/runtime-api" }
rolldown-runtime-api = { path = "../pallets/rolldown/runtime-api" }
rolldown-rpc = { path = "../pallets/rolldown/rpc" }
proof-of-stake-runtime-api = { path = '../pallets/proof-of-stake/runtime-api' }
proof-of-stake-rpc = { path = '../pallets/proof-of-stake/rpc' }
metamask-signature-rpc = { path = '../pallets/metamask-signature-rpc/' }
Expand Down Expand Up @@ -101,11 +103,13 @@ default = ["mangata-kusama", "mangata-rococo"]
mangata-kusama = [
"mangata-kusama-runtime/std",
"xyk-rpc/std",
"rolldown-rpc/std",
"polkadot-cli/kusama-native",
]
mangata-rococo = [
"mangata-rococo-runtime/std",
"xyk-rpc/std",
"rolldown-rpc/std",
"polkadot-cli/rococo-native",
]
runtime-benchmarks = [
Expand Down
1 change: 1 addition & 0 deletions node/src/chain_spec/mangata_kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,5 +545,6 @@ fn mangata_genesis(
.collect(),
},
vesting: Default::default(),
rolldown: Default::default(),
}
}
4 changes: 4 additions & 0 deletions node/src/chain_spec/mangata_rococo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ pub(crate) fn mangata_genesis(
},
session: mangata_rococo_runtime::SessionConfig {
keys: initial_authorities
.clone()
.into_iter()
.map(|(acc, aura)| {
(
Expand Down Expand Up @@ -545,5 +546,8 @@ pub(crate) fn mangata_genesis(
.collect(),
},
vesting: Default::default(),
rolldown: mangata_rococo_runtime::RolldownConfig {
sequencers: initial_authorities.iter().map(|(acc, _)| acc.clone()).collect(),
},
}
}
3 changes: 3 additions & 0 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ where
C::Api: xyk_rpc::XykRuntimeApi<Block, Balance, TokenId, AccountId>,
C::Api: proof_of_stake_rpc::ProofOfStakeRuntimeApi<Block, Balance, TokenId, AccountId>,
C::Api: metamask_signature_rpc::MetamaskSignatureRuntimeApi<Block>,
C::Api: rolldown_runtime_api::RolldownRuntimeApi<Block>,
C::Api: BlockBuilder<Block>,
C::Api: VerNonceApi<Block, AccountId>,
P: TransactionPool + Sync + Send + 'static,
{
use metamask_signature_rpc::MetamaskSignature;
use pallet_transaction_payment_mangata_rpc::{TransactionPayment, TransactionPaymentApiServer};
use proof_of_stake_rpc::{ProofOfStake, ProofOfStakeApiServer};
use rolldown_rpc::{Rolldown, RolldownApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
use xyk_rpc::{Xyk, XykApiServer};

Expand All @@ -81,6 +83,7 @@ where
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(Xyk::new(client.clone()).into_rpc())?;
module.merge(Rolldown::new(client.clone()).into_rpc())?;
module.merge(ProofOfStake::new(client.clone()).into_rpc())?;
module.merge(MetamaskSignature::new(client).into_rpc())?;

Expand Down
2 changes: 2 additions & 0 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub trait RuntimeApiCollection:
+ ver_api::VerNonceApi<Block, AccountId>
+ xyk_rpc::XykRuntimeApi<Block, Balance, TokenId, AccountId>
+ proof_of_stake_rpc::ProofOfStakeRuntimeApi<Block, Balance, TokenId, AccountId>
+ rolldown_runtime_api::RolldownRuntimeApi<Block>
+ metamask_signature_rpc::MetamaskSignatureRuntimeApi<Block>
{
}
Expand All @@ -127,6 +128,7 @@ impl<Api> RuntimeApiCollection for Api where
+ ver_api::VerNonceApi<Block, AccountId>
+ xyk_rpc::XykRuntimeApi<Block, Balance, TokenId, AccountId>
+ proof_of_stake_rpc::ProofOfStakeRuntimeApi<Block, Balance, TokenId, AccountId>
+ rolldown_runtime_api::RolldownRuntimeApi<Block>
+ metamask_signature_rpc::MetamaskSignatureRuntimeApi<Block>
{
}
Expand Down
8 changes: 5 additions & 3 deletions pallets/rolldown/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ version = "0.1.0"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
alloy-sol-types = { version = "0.5.0", default-features = false }
alloy-primitives = { version = "0.5.0", default-features = false }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
hex-literal = { version = "0.3.3", default-features = false }
log = { version = "0.4.14", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = {version = "1.0.101",default-features = false, features = ["derive"] }
serde_json = { version = "1.0.108", default-features = false }
# serde-json-wasm = { version = "1.0.0", default-features = false }
sha3 = { version = "0.9.1", default-features = false }
array-bytes = "6.1"

Expand All @@ -35,16 +36,17 @@ orml-tokens = { git = "https://github.com/mangata-finance/open-runtime-module-li
env_logger = "0.9.0"
lazy_static = "1.1.1"
serial_test = { version = "0.6.0", default-features = false }

mockall = "0.11.0"
sp-io = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }

orml-traits = { git = "https://github.com/mangata-finance/open-runtime-module-library", branch = "develop", default-features = false }


[features]
default = ["std"]
enable-trading = []
std = [
"alloy-sol-types/std",
"alloy-primitives/std",
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
Expand Down
40 changes: 40 additions & 0 deletions pallets/rolldown/rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
authors = ['Mangata team']
name = "rolldown-rpc"
version = "2.0.0"
edition = "2018"
description = "RPC calls for Proof of Stake"
license = "GPL-3.0-or-later"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0" }
jsonrpsee = { version = "0.16.2", features = ["server", "client", "macros"] }
serde = { version = "1.0.126", features = ["derive"], optional = true }

# Substrate packages

sp-api = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }
sp-blockchain = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }
sp-rpc = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }
sp-core = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }
sp-std = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }
sp-runtime = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }
mangata-types = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }

# local packages

rolldown-runtime-api = { version = "2.0.0", path = "../runtime-api", default-features = false }

[features]
default = ["std"]

std = [
"serde",
"sp-api/std",
"sp-core/std",
"sp-std/std",
"sp-runtime/std",
"rolldown-runtime-api/std",
"mangata-types/std",
"codec/std",
]
74 changes: 74 additions & 0 deletions pallets/rolldown/rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (C) 2021 Mangata team

use jsonrpsee::{
core::{async_trait, Error as JsonRpseeError, RpcResult},
proc_macros::rpc,
types::error::{CallError, ErrorObject},
};
use rolldown_runtime_api::RolldownRuntimeApi;
pub use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::traits::Block as BlockT;
use std::sync::Arc;

#[rpc(client, server)]
pub trait RolldownApi<BlockHash> {
/// Calculates amount of available native rewards
///
/// * `account` - user account address
/// * `liquidity_token` - liquidity token id
/// * `at` - optional block hash
#[method(name = "rolldown_pending_updates_hash")]
fn pending_updates_hash(&self, at: Option<BlockHash>) -> RpcResult<sp_core::H256>;

#[method(name = "rolldown_pending_updates")]
fn pending_updates(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
}

pub struct Rolldown<C, M> {
client: Arc<C>,
_marker: std::marker::PhantomData<M>,
}

impl<C, P> Rolldown<C, P> {
pub fn new(client: Arc<C>) -> Self {
Self { client, _marker: Default::default() }
}
}

#[async_trait]
impl<C, Block> RolldownApiServer<<Block as BlockT>::Hash> for Rolldown<C, Block>
where
Block: BlockT,
C: Send + Sync + 'static,
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block>,
C::Api: RolldownRuntimeApi<Block>,
{
fn pending_updates_hash(
&self,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<sp_core::H256> {
let api = self.client.runtime_api();
let at = at.unwrap_or(self.client.info().best_hash);
api.get_pending_updates_hash(at).map_err(|e| {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
1,
"Unable to serve the request",
Some(format!("{:?}", e)),
)))
})
}

fn pending_updates(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
let api = self.client.runtime_api();
let at = at.unwrap_or(self.client.info().best_hash);
api.get_pending_updates(at).map_err(|e| {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
1,
"Unable to serve the request",
Some(format!("{:?}", e)),
)))
})
}
}
21 changes: 21 additions & 0 deletions pallets/rolldown/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
authors = ['Mangata team']
name = "rolldown-runtime-api"
version = "2.0.0"
edition = "2018"
license = "GPL-3.0-or-later"

[dependencies]

sp-api = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }
sp-std = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }
sp-core = { git = "https://github.com/mangata-finance/polkadot-sdk", branch = "develop", default-features = false }

[features]
default = ["std"]

std = [
"sp-api/std",
"sp-std/std",
"sp-core/std",
]
10 changes: 10 additions & 0 deletions pallets/rolldown/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (C) 2021 Mangata team
#![cfg_attr(not(feature = "std"), no_std)]

use sp_std::vec::Vec;
sp_api::decl_runtime_apis! {
pub trait RolldownRuntimeApi{
fn get_pending_updates_hash() -> sp_core::H256;
fn get_pending_updates() -> Vec<u8>;
}
}
Loading

0 comments on commit e06b4d1

Please sign in to comment.