Skip to content

Commit

Permalink
Gj/on chain validation (#835)
Browse files Browse the repository at this point in the history
1. Removes the Gossip layer and introduces an aggregation layer for Thea
and OB signatures
2. All business logic moved as part of runtime for quick updation

TODO: Update the parachain port location to 8844 in Thea after testnet
testing.
  • Loading branch information
Gauthamastro authored Jul 20, 2023
2 parents 4667d0e + 305dfb7 commit af8f599
Show file tree
Hide file tree
Showing 60 changed files with 3,302 additions and 3,195 deletions.
1,462 changes: 723 additions & 739 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ members = [
"pallets/ocex",
"pallets/rewards",
"primitives/orderbook",
"primitives/bls-primitives",
"primitives/polkadex",
"primitives/thea",
"pallets/thea",
Expand All @@ -53,7 +52,6 @@ default-members = [
"pallets/ocex",
"pallets/rewards",
"primitives/orderbook",
"primitives/bls-primitives",
"primitives/polkadex",
"primitives/thea",
"pallets/thea",
Expand Down Expand Up @@ -183,3 +181,9 @@ polkadex-primitives = { path = "primitives/polkadex", default-features = false }
frame-try-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false }
try-runtime-cli = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.43", default-features = false }
xcm = { git = "https://github.com/paritytech/polkadot.git", default-features = false, branch = "release-v0.9.43" }
env_logger = { version = "0.10.0" }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
serde = { version = "1.0.171", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.102", default-features = false, features = ["alloc"] }
hash-db = { version = "0.16.0", default-features = false }
trie-db = { version = "0.27.1", default-features = false }
2 changes: 1 addition & 1 deletion check-all-ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ cargo build --features runtime-benchmarks || exit
./target/debug/polkadex-node benchmark pallet --pallet "*" --extrinsic "*" --steps 2 --repeat 1 || exit
cargo clippy -- -D warnings || exit
cargo test || exit
RUSTFLAGS="-D warnings" cargo build -p thea-message-handler || exit
RUSTFLAGS="-D warnings" cargo build -p thea-message-handler || exit
1 change: 0 additions & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ edition = "2021"
sc-executor = { workspace = true }
node-polkadex-runtime = { path = "../runtime" }
frame-benchmarking = { workspace = true }
bls-primitives = { workspace = true }
5 changes: 1 addition & 4 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
pub struct ExecutorDispatch;

impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
type ExtendHostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
bls_primitives::host_functions::bls_crypto_ext::HostFunctions,
);
type ExtendHostFunctions = (frame_benchmarking::benchmarking::HostFunctions,);

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
node_polkadex_runtime::api::dispatch(method, data)
Expand Down
4 changes: 2 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ node-polkadex-runtime = { path = "../runtime" }
rpc-assets = { path = "../rpc/assets" }
pallet-rewards-rpc = { path = "../pallets/rewards/rpc" }
polkadex-client = { path = "../client" }
orderbook-primitives = { path = "../primitives/orderbook" }
thea-primitives = { path = "../primitives/thea" }

thea = { path = "../pallets/thea" }
pallet-ocex-lmp = { path = "../pallets/ocex" }
# Substrate dependencies
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
Expand Down
54 changes: 27 additions & 27 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub(crate) fn session_keys(
babe: BabeId,
im_online: ImOnlineId,
authority_discovery: AuthorityDiscoveryId,
orderbook: orderbook_primitives::crypto::AuthorityId,
thea: thea_primitives::AuthorityId,
orderbook: pallet_ocex_lmp::sr25519::AuthorityId,
thea: thea::ecdsa::AuthorityId,
) -> SessionKeys {
SessionKeys { grandpa, babe, im_online, authority_discovery, orderbook, thea }
}
Expand All @@ -85,8 +85,8 @@ fn udon_testnet_config_genesis() -> GenesisConfig {
BabeId,
ImOnlineId,
AuthorityDiscoveryId,
orderbook_primitives::crypto::AuthorityId,
thea_primitives::AuthorityId,
pallet_ocex_lmp::sr25519::AuthorityId,
thea::ecdsa::AuthorityId,
)> = vec![];
for idx in 1..4 {
let babe = sp_core::sr25519::Pair::from_string(
Expand All @@ -111,13 +111,13 @@ fn udon_testnet_config_genesis() -> GenesisConfig {
None,
)
.unwrap();
let ob = orderbook_primitives::crypto::Pair::from_string(
let ob = sp_core::sr25519::Pair::from_string(
&(seed.to_owned() + idx.to_string().as_str() + "//orderbook"),
None,
)
.unwrap();

let thea = thea_primitives::crypto::Pair::from_string(
let thea = sp_core::ecdsa::Pair::from_string(
&(seed.to_owned() + idx.to_string().as_str() + "//thea"),
None,
)
Expand All @@ -130,8 +130,8 @@ fn udon_testnet_config_genesis() -> GenesisConfig {
BabeId::from(babe.public().into_account()),
ImOnlineId::from(imon.public().into_account()),
AuthorityDiscoveryId::from(audi.public().into_account()),
ob.public().into_account(),
thea.public().into_account(),
pallet_ocex_lmp::sr25519::AuthorityId::from(ob.public().into_account()),
thea::ecdsa::AuthorityId::from(thea.public().into_account()),
));
}

Expand Down Expand Up @@ -199,8 +199,8 @@ pub fn authority_keys_from_seed(
BabeId,
ImOnlineId,
AuthorityDiscoveryId,
orderbook_primitives::crypto::AuthorityId,
thea_primitives::AuthorityId,
pallet_ocex_lmp::sr25519::AuthorityId,
thea::ecdsa::AuthorityId,
) {
(
get_account_id_from_seed::<sr25519::Public>(&format!("{seed}//stash")),
Expand All @@ -209,8 +209,8 @@ pub fn authority_keys_from_seed(
get_from_seed::<BabeId>(seed),
get_from_seed::<ImOnlineId>(seed),
get_from_seed::<AuthorityDiscoveryId>(seed),
get_from_seed::<orderbook_primitives::crypto::AuthorityId>(seed),
get_from_seed::<thea_primitives::AuthorityId>(seed),
get_from_seed::<pallet_ocex_lmp::sr25519::AuthorityId>(seed),
get_from_seed::<thea::ecdsa::AuthorityId>(seed),
)
}

Expand Down Expand Up @@ -281,8 +281,8 @@ fn mainnet_genesis_constuctor() -> GenesisConfig {
BabeId,
ImOnlineId,
AuthorityDiscoveryId,
orderbook_primitives::crypto::AuthorityId,
thea_primitives::AuthorityId
pallet_ocex_lmp::sr25519::AuthorityId,
thea::ecdsa::AuthorityId,
)> = vec![
(
// 5Fbsd6WXDGiLTxunqeK5BATNiocfCqu9bS1yArVjCgeBLkVy
Expand All @@ -301,12 +301,12 @@ fn mainnet_genesis_constuctor() -> GenesisConfig {
// 5EynamEisSmW3kUdGC7BSXQy1oR8rD1CWLjHh2LGz8bys3sg
hex!["80f461b74b90b4913e0354569e90c7cd11ca5dbce6e8b2a6fcbbe0761b877e06"]
.unchecked_into(),
// BLS - Orderbook
hex!["a479f6b92355f700a6d95ed1080ae28730465ebda1b3711b77b0d3be88966a2fddf975cf43ca3a49c245a53b548e32680f4530248b09cbc6ead4dd553c8c993254aaa05327f63b6f9d570dbaa05ebe5ddd25096c49b254d9f063f3c1914016ab"]
.try_into().unwrap(),
// 5EynamEisSmW3kUdGC7BSXQy1oR8rD1CWLjHh2LGz8bys3sg
hex!["80f461b74b90b4913e0354569e90c7cd11ca5dbce6e8b2a6fcbbe0761b877e06"]
.unchecked_into(),
// BLS - Thea
hex!["a479f6b92355f700a6d95ed1080ae28730465ebda1b3711b77b0d3be88966a2fddf975cf43ca3a49c245a53b548e32680f4530248b09cbc6ead4dd553c8c993254aaa05327f63b6f9d570dbaa05ebe5ddd25096c49b254d9f063f3c1914016ab"]
.try_into().unwrap(),
hex!["0273c7d54e44c34534b81e51d77d150eece222487c85f138b02e5f65ef9bbf2a9c"]
.unchecked_into(),
),
(
// 5ERawXCzCWkjVq3xz1W5KGNtVx2VdefvZ62Bw1FEuZW4Vny2
Expand All @@ -325,12 +325,12 @@ fn mainnet_genesis_constuctor() -> GenesisConfig {
// 5GC5FgdZbCYkMnZ2Ez8o2zztvkdR3qn1Zymknbi97vUsk2vV
hex!["b68fae03e44288bde5c66fd89893d943baf88b8cffb33aa7f1dedf0d4a86ad3c"]
.unchecked_into(),
// BLS - Orderbook
hex!["afd525535270070659d4dcde00075735d85e58f702786ebf7d882379117db0671d9ced3d199b41f29646817863133c310dd1be65b0ff0c7e1d2b846a1c5c29a63686dc65d1be48604e2d5128c1c3a80554e1d584f05869cd15ff4c0f040a8760"]
.try_into().unwrap(),
// BLS - Thea
hex!["afd525535270070659d4dcde00075735d85e58f702786ebf7d882379117db0671d9ced3d199b41f29646817863133c310dd1be65b0ff0c7e1d2b846a1c5c29a63686dc65d1be48604e2d5128c1c3a80554e1d584f05869cd15ff4c0f040a8760"]
.try_into().unwrap(),
// 5GC5FgdZbCYkMnZ2Ez8o2zztvkdR3qn1Zymknbi97vUsk2vV
hex!["b68fae03e44288bde5c66fd89893d943baf88b8cffb33aa7f1dedf0d4a86ad3c"]
.unchecked_into(),
// ECDSA - Thea
hex!["02ec85ac1634c855abe2984050a8c8fc3a31492f60cfdd62037875be6c8dcfbb2a"]
.unchecked_into(),
),
];
let root_key = hex!["70a5f4e786b47baf52d5a34742bb8312139cfe1c747fbeb3912c197d38c53332"].into();
Expand Down Expand Up @@ -374,8 +374,8 @@ pub fn testnet_genesis(
BabeId,
ImOnlineId,
AuthorityDiscoveryId,
orderbook_primitives::crypto::AuthorityId,
thea_primitives::AuthorityId,
pallet_ocex_lmp::sr25519::AuthorityId,
thea::ecdsa::AuthorityId,
)>,
_initial_nominators: Vec<AccountId>,
development_accounts: Option<Vec<AccountId>>,
Expand Down
3 changes: 1 addition & 2 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use std::sync::Arc;

use jsonrpsee::RpcModule;
use orderbook_primitives::ObApi;
use polkadex_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index};
use rpc_assets::{PolkadexAssetHandlerRpc, PolkadexAssetHandlerRpcApiServer};
use sc_client_api::{AuxStore, BlockchainEvents};
Expand Down Expand Up @@ -111,7 +110,6 @@ where
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BabeApi<Block>,
C::Api: BlockBuilder<Block>,
C::Api: ObApi<Block>,
P: TransactionPool + 'static,
SC: SelectChain<Block> + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
Expand Down Expand Up @@ -167,5 +165,6 @@ where
io.merge(PolkadexAssetHandlerRpc::new(client.clone()).into_rpc())?;
io.merge(PolkadexRewardsRpc::new(client.clone()).into_rpc())?;
io.merge(Dev::new(client, deny_unsafe).into_rpc())?;

Ok(io)
}
22 changes: 12 additions & 10 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ pub fn new_partial(
)?;

let import_setup = (block_import, grandpa_link, babe_link);

let (rpc_extensions_builder, rpc_setup) = {
let (_, grandpa_link, _babe_link) = &import_setup;

Expand Down Expand Up @@ -302,13 +303,16 @@ pub struct NewFullBase {

/// Creates a full service from the configuration.
pub fn new_full_base(
config: Configuration,
mut config: Configuration,
disable_hardware_benchmarks: bool,
with_startup_data: impl FnOnce(
&sc_consensus_babe::BabeBlockImport<Block, FullClient, FullGrandpaBlockImport>,
&sc_consensus_babe::BabeLink<Block>,
),
) -> Result<NewFullBase, ServiceError> {
// Ensure all nodes implement offchain indexing and workers
config.offchain_worker.enabled = true;
config.offchain_worker.indexing_enabled = true;
let hwbench = (!disable_hardware_benchmarks)
.then_some(config.database.path().map(|database_path| {
let _ = std::fs::create_dir_all(database_path);
Expand Down Expand Up @@ -367,15 +371,13 @@ pub fn new_full_base(
block_announce_validator_builder: None,
warp_sync_params: Some(WarpSyncParams::WithProvider(warp_sync)),
})?;

if config.offchain_worker.enabled {
sc_service::build_offchain_workers(
&config,
task_manager.spawn_handle(),
client.clone(),
network.clone(),
);
}
// Enable offchain indexing
sc_service::build_offchain_workers(
&config,
task_manager.spawn_handle(),
client.clone(),
network.clone(),
);

let role = config.role.clone();
let force_authoring = config.force_authoring;
Expand Down
4 changes: 1 addition & 3 deletions pallets/liquidity/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ impl pallet_ocex_lmp::Config for Test {
type NativeCurrency = Balances;
type OtherAssets = Assets;
type EnclaveOrigin = EnsureRoot<AccountId>;
type Public = <Signature as sp_runtime::traits::Verify>::Signer;
type Signature = Signature;
type MsPerDay = MsPerDay;
type AuthorityId = pallet_ocex_lmp::sr25519::AuthorityId;
type WeightInfo = pallet_ocex_lmp::weights::WeightInfo<Test>;
}

Expand Down
15 changes: 12 additions & 3 deletions pallets/ocex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,41 @@ rust_decimal = { workspace = true, features = ["scale-codec"], default-features
pallet-timestamp = { workspace = true, default-features = false }
frame-benchmarking = { workspace = true, default-features = false, optional = true }
sp-core = { workspace = true, default-features = false }
sp-io = { workspace = true, default-features = false }
liquidity = { path = "../liquidity", default-features = false }
orderbook-primitives = { path = "../../primitives/orderbook", default-features = false }
sp-application-crypto = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde_json = { workspace = true, default-features = false, features = ["alloc"] }
hash-db = { workspace = true, default-features = false }
trie-db = { workspace = true, default-features = false }
sp-trie = { workspace = true, default-features = false }

[dev-dependencies]
pallet-assets = { workspace = true, features = ["std"] }
pallet-balances = { workspace = true, features = ["std"] }
sp-application-crypto = { workspace = true }
sp-keystore = { workspace = true }
sp-io = { workspace = true }
bls-primitives = { workspace = true, default-features = false }
hex = "0.4.3"

[features]
default = ["std"]
std = [
"log/std",
"serde_json/std",
"serde/std",
"sp-application-crypto/std",
"orderbook-primitives/std",
"bls-primitives/std",
"parity-scale-codec/std",
"scale-info/std",
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
"sp-std/std",
"sp-io/std",
"sp-trie/std",
"hash-db/std",
"trie-db/std",
"polkadex-primitives/std",
"rust_decimal/std",
"pallet-timestamp/std",
Expand Down
Loading

0 comments on commit af8f599

Please sign in to comment.