Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub fn new_partial(
justification_import: Some(Box::new(grandpa_block_import.clone())),
client: client.clone(),
create_inherent_data_providers: move |_, ()| async move {
// XXX how can we pass a <T: Config>??
let miner = pallet_cash::internal::miner::InherentDataProvider {};
Comment on lines +103 to 104
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in principal you can depend on the gateway-runtime::Runtime struct and pass it to the generic here, that binds your node impl to a particular (set of) runtime version(s) though

let oracle = pallet_oracle::inherent::InherentDataProvider {};
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
Expand Down
29 changes: 12 additions & 17 deletions pallets/cash/src/internal/miner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{chains::ChainAccount, Call, Config, Miner, Module};
use crate::{chains::ChainAccount, core, Call, Config, Miner, Module};
use codec::{Decode, Encode};
use frame_support::{inherent::ProvideInherent, storage::StorageValue};
use sp_inherents::{InherentData, InherentIdentifier, IsFatalError};
Expand Down Expand Up @@ -39,10 +39,13 @@ impl InherentError {

/// Provide chosen miner address.
#[cfg(feature = "std")]
pub struct InherentDataProvider;
// XXX how do we even get a T here?
pub struct InherentDataProvider<T: Config> {
sentinel: std::marker::PhantomData<T>,
}

#[cfg(feature = "std")]
impl std::ops::Deref for InherentDataProvider {
impl<T: Config> std::ops::Deref for InherentDataProvider<T> {
type Target = ();

fn deref(&self) -> &Self::Target {
Expand All @@ -52,24 +55,16 @@ impl std::ops::Deref for InherentDataProvider {

#[cfg(feature = "std")]
#[async_trait::async_trait]
impl sp_inherents::InherentDataProvider for InherentDataProvider {
impl<T: Config + std::marker::Sync + std::marker::Send> sp_inherents::InherentDataProvider
for InherentDataProvider<T>
{
fn provide_inherent_data(
&self,
inherent_data: &mut InherentData,
) -> Result<(), sp_inherents::Error> {
let miner_address_str = runtime_interfaces::validator_config_interface::get_miner_address()
.ok_or(sp_inherents::Error::Application(Box::from(
"no miner address",
)))?;

let miner_address = our_std::str::from_utf8(&miner_address_str).map_err(|_| {
sp_inherents::Error::Application(Box::from("invalid miner address bytes"))
})?;

let chain_account: ChainAccount = our_std::str::FromStr::from_str(miner_address)
.map_err(|_| sp_inherents::Error::Application(Box::from("invalid miner address")))?;

inherent_data.put_data(INHERENT_IDENTIFIER, &chain_account)
let validator = core::get_current_validator::<T>()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a function accessing runtime storage I assume?
I think you'll need to introduce a runtime api that allows you to access that data (and that doesn't depend on a <T: Config>) similar to e.g. the GrandpaApi here: https://github.com/paritytech/substrate/blob/4e75f511e1357cf54c31d9e82d0cf3e39a2b8c28/bin/node/runtime/src/lib.rs#L1307

.map_err(|_| sp_inherents::Error::Application(Box::from("no miner address")))?;
inherent_data.put_data(INHERENT_IDENTIFIER, &validator.miner_address())
}

async fn try_handle_error(
Expand Down
8 changes: 7 additions & 1 deletion pallets/cash/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use types_derive::{type_alias, Types};
pub use pallet_oracle::{ticker::Ticker, types::Price};

pub use crate::{
chains::{Chain, ChainAsset, ChainBlockNumber, ChainId, Ethereum},
chains::{Chain, ChainAccount, ChainAsset, ChainBlockNumber, ChainId, Ethereum},
factor::{BigInt, BigUint, Factor},
notices::{Notice, NoticeId},
rates::{InterestRateModel, APR},
Expand Down Expand Up @@ -114,6 +114,12 @@ pub struct ValidatorKeys {
pub eth_address: <Ethereum as Chain>::Address,
}

impl ValidatorKeys {
pub fn miner_address(self) -> ChainAccount {
ChainAccount::Gate(self.substrate_id.into())
}
}

/// Type for referring to either an asset or CASH.
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, Types)]
pub enum CashOrChainAsset {
Expand Down