Skip to content

Commit

Permalink
Merge branch 'master' into fg-chain-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
fgamundi committed May 21, 2024
2 parents a2c6504 + 2d8fc70 commit 5a0cebd
Show file tree
Hide file tree
Showing 70 changed files with 2,222 additions and 639 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ jobs:
with:
name: binaries
path: binaries
- name: Check runtime benchmarks
run: cargo check --features=runtime-benchmarks --release --all

rust-test:
runs-on: self-hosted
Expand Down
25 changes: 25 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pallet-pooled-staking = { path = "pallets/pooled-staking", default-features = fa
pallet-registrar = { path = "pallets/registrar", default-features = false }
pallet-registrar-runtime-api = { path = "pallets/registrar/rpc/runtime-api", default-features = false }
pallet-services-payment = { path = "pallets/services-payment", default-features = false }
pallet-services-payment-runtime-api = { path = "pallets/services-payment/rpc/runtime-api", default-features = false }
pallet-stream-payment = { path = "pallets/stream-payment", default-features = false }
pallet-stream-payment-runtime-api = { path = "pallets/stream-payment/rpc/runtime-api", default-features = false }
pallet-xcm-core-buyer = { path = "pallets/xcm-core-buyer", default-features = false }
Expand All @@ -73,6 +74,7 @@ flashbox-runtime = { path = "runtime/flashbox", default-features = false }
manual-xcm-rpc = { path = "client/manual-xcm" }
node-common = { path = "client/node-common" }
runtime-common = { path = "runtime/common", default-features = false }
services-payment-rpc = { path = "client/services-payment" }
stream-payment-rpc = { path = "client/stream-payment" }
tanssi-relay-encoder = { path = "runtime/relay-encoder", default-features = false }
tc-consensus = { path = "client/consensus" }
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/src/collators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ where
}

/// Attempt to claim a slot using a keystore.
pub fn claim_slot_inner<P: Pair>(
pub fn claim_slot_inner<P>(
slot: Slot,
authorities: &Vec<AuthorityId<P>>,
keystore: &KeystorePtr,
Expand Down
8 changes: 4 additions & 4 deletions client/consensus/src/collators/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,10 @@ where
// Here we lean on the property that building on an empty unincluded segment must always
// be legal. Skipping the runtime API query here allows us to seamlessly run this
// collator against chains which have not yet upgraded their runtime.
if parent_header.hash() != included_block {
if !runtime_api.can_build_upon(parent_header.hash(), included_block, slot)? {
return Ok(None);
}
if parent_header.hash() != included_block
&& !runtime_api.can_build_upon(parent_header.hash(), included_block, slot)?
{
return Ok(None);
}

slot_claim
Expand Down
16 changes: 0 additions & 16 deletions client/consensus/src/consensus_orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
//! it implements the TanssiWorker to TanssiOnSlot trait. This trait is
use {
crate::{AuthorityId, Pair, Slot},
sc_consensus_slots::{SimpleSlotWorker, SlotInfo, SlotResult},
sp_consensus::Proposer,
sp_runtime::traits::Block as BlockT,
};

Expand Down Expand Up @@ -63,17 +61,3 @@ where
pub authorities: Vec<AuthorityId<P>>,
pub min_slot_freq: Option<Slot>,
}

#[async_trait::async_trait]
pub trait TanssiSlotWorker<B: BlockT>: SimpleSlotWorker<B> {
/// Called when a new slot is triggered.
///
/// Returns a future that resolves to a [`SlotResult`] iff a block was successfully built in
/// the slot. Otherwise `None` is returned.
/// Accepts the orchestrator header as an input
async fn tanssi_on_slot(
&mut self,
slot_info: SlotInfo<B>,
aux_data: Self::AuxData,
) -> Option<SlotResult<B, <Self::Proposer as Proposer<B>>::Proof>>;
}
20 changes: 10 additions & 10 deletions client/consensus/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ sp_api::mock_impl_runtime_apis! {
}

#[derive(Clone)]
struct RelayChain(Arc<TestClient>);
struct RelayChain;

#[async_trait]
impl RelayChainInterface for RelayChain {
Expand Down Expand Up @@ -252,7 +252,7 @@ impl RelayChainInterface for RelayChain {
}

#[derive(Clone)]
struct DummySpawner(Arc<TestClient>);
struct DummySpawner;
impl SpawnNamed for DummySpawner {
fn spawn_blocking(
&self,
Expand All @@ -271,7 +271,7 @@ impl SpawnNamed for DummySpawner {
}
}

struct DummyProposer(u64, Arc<TestClient>);
struct DummyProposer(Arc<TestClient>);

// This is going to be our block verifier
// It will mimic what the Nimbus verifier does, but again, Nimbus verifier is non-public
Expand Down Expand Up @@ -354,8 +354,8 @@ impl Environment<TestBlock> for DummyFactory {
type CreateProposer = future::Ready<Result<DummyProposer, Error>>;
type Error = Error;

fn init(&mut self, parent_header: &<TestBlock as BlockT>::Header) -> Self::CreateProposer {
future::ready(Ok(DummyProposer(parent_header.number + 1, self.0.clone())))
fn init(&mut self, _parent_header: &<TestBlock as BlockT>::Header) -> Self::CreateProposer {
future::ready(Ok(DummyProposer(self.0.clone())))
}
}

Expand All @@ -373,9 +373,9 @@ impl Proposer<TestBlock> for DummyProposer {
_: Duration,
_: Option<usize>,
) -> Self::Proposal {
let r = BlockBuilderBuilder::new(&*self.1)
.on_parent_block(self.1.chain_info().best_hash)
.fetch_parent_block_number(&*self.1)
let r = BlockBuilderBuilder::new(&*self.0)
.on_parent_block(self.0.chain_info().best_hash)
.fetch_parent_block_number(&*self.0)
.unwrap()
.with_inherent_digests(digests)
.build()
Expand Down Expand Up @@ -562,8 +562,8 @@ async fn collate_returns_correct_block() {
let peer = net.peer(3);
let client = peer.client().as_client();
let environ = DummyFactory(client.clone());
let spawner = DummySpawner(client.clone());
let relay_client = RelayChain(client.clone());
let spawner = DummySpawner;
let relay_client = RelayChain;

// Build the collator
let mut collator = {
Expand Down
22 changes: 22 additions & 0 deletions client/services-payment/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "services-payment-rpc"
authors = { workspace = true }
description = "RPC interface for the Services Payment pallet"
edition = "2021"
license = "GPL-3.0-only"
version = "0.1.0"

[package.metadata.docs.rs]
targets = [ "x86_64-unknown-linux-gnu" ]

[lints]
workspace = true

[dependencies]
futures = { workspace = true }
jsonrpsee = { workspace = true }
pallet-services-payment-runtime-api = { workspace = true, features = [ "std" ] }
parity-scale-codec = { workspace = true }
sc-client-api = { workspace = true }
sp-api = { workspace = true, features = [ "std" ] }
sp-runtime = { workspace = true, features = [ "std" ] }
94 changes: 94 additions & 0 deletions client/services-payment/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.

// Tanssi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Tanssi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

//! RPC client for Services Payment pallet

pub use pallet_services_payment_runtime_api::ServicesPaymentApi as ServicesPaymentRuntimeApi;
use {
core::marker::PhantomData,
jsonrpsee::{
core::{async_trait, RpcResult},
proc_macros::rpc,
},
sc_client_api::UsageProvider,
sp_api::ProvideRuntimeApi,
sp_runtime::traits::Block as BlockT,
std::sync::Arc,
};

#[rpc(server)]
pub trait ServicesPaymentApi<Balance, ParaId> {
#[method(name = "tanssi_servicesPaymentBlockCost")]
async fn block_cost(&self, para_id: ParaId) -> RpcResult<Balance>;

#[method(name = "tanssi_servicesPaymentCollatorAssignmentCost")]
async fn collator_assignment_cost(&self, para_id: ParaId) -> RpcResult<Balance>;
}

pub struct ServicesPayment<Client, Block> {
client: Arc<Client>,
_phantom: PhantomData<Block>,
}

impl<Client, Block> ServicesPayment<Client, Block> {
pub fn new(client: Arc<Client>) -> Self {
Self {
client,
_phantom: PhantomData,
}
}
}

#[async_trait]
impl<Client, Hash, Block, Balance, ParaId> ServicesPaymentApiServer<Balance, ParaId>
for ServicesPayment<Client, Block>
where
Hash: Send + 'static,
Block: BlockT<Hash = Hash>,
Client: ProvideRuntimeApi<Block> + Sync + Send + UsageProvider<Block> + 'static,
Client::Api: ServicesPaymentRuntimeApi<Block, Balance, ParaId>,
Balance: parity_scale_codec::Codec + Send + 'static,
ParaId: parity_scale_codec::Codec + Send + 'static,
{
async fn block_cost(&self, para_id: ParaId) -> RpcResult<Balance> {
let cost = self
.client
.runtime_api()
.block_cost(self.client.usage_info().chain.best_hash, para_id)
.map_err(|e| internal_err(e))?;
Ok(cost)
}

async fn collator_assignment_cost(&self, para_id: ParaId) -> RpcResult<Balance> {
let cost = self
.client
.runtime_api()
.collator_assignment_cost(self.client.usage_info().chain.best_hash, para_id)
.map_err(|e| internal_err(e))?;
Ok(cost)
}
}

pub fn internal_err<T: ToString>(error: T) -> jsonrpsee::core::Error {
jsonrpsee::core::Error::Call(jsonrpsee::types::error::CallError::Custom(
jsonrpsee::types::error::ErrorObject::borrowed(
jsonrpsee::types::error::INTERNAL_ERROR_CODE,
&error.to_string(),
None,
)
.into_owned(),
))
}
60 changes: 0 additions & 60 deletions container-chains/nodes/frontier/src/client.rs

This file was deleted.

2 changes: 0 additions & 2 deletions container-chains/nodes/frontier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

mod chain_spec;
mod cli;
mod client;
mod command;
mod eth;
mod rpc;
mod service;

Expand Down
Loading

0 comments on commit 5a0cebd

Please sign in to comment.