Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send personhood to node template #37

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

brenzi
Copy link
Member

@brenzi brenzi commented Sep 11, 2023

meaningless demo just calling template pallet do_something with a user-chosen index if has personhood

very general demonstration of trustlessly reading state from one chain and processing data and committing with an extrinsic into another chain: unlinkable XCM demo.

@brenzi
Copy link
Member Author

brenzi commented Sep 11, 2023

trouble sending an extrinsic to target B
https://gist.github.com/brenzi/530be00e9de0dc9bf16d33a3ea624025#file-gistfile1-txt-L152-L156
the encoded call is correct, but the extrinsic factory returns an empty slice which isn't handled gracefully

edit: slice wasn't empty, but inside enclave the debug rendering is null. the problem was too little funds to pay for fees

@brenzi
Copy link
Member Author

brenzi commented Sep 11, 2023

maybe try to align pallet indices in node-template with other nodes:

		System: frame_system = 0,
		Timestamp: pallet_timestamp = 3,
		Aura: pallet_aura = 23,
		Grandpa: pallet_grandpa = 25,
		Balances: pallet_balances = 10,
		TransactionPayment: pallet_transaction_payment = 11,
		Sudo: pallet_sudo = 5,
		// Include the custom logic from the pallet-template in the runtime.
		TemplateModule: pallet_template = 7,

see integritee-network/worker#1445

edit: does not fix the empty extrinsic error

@brenzi brenzi requested a review from clangenb September 11, 2023 18:05
Comment on lines +58 to +69
#[cfg(feature = "std")]
impl Display for ParentchainId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let message = match self {
ParentchainId::Integritee => "L1:Integritee",
ParentchainId::TargetA => "L1:Encointer",
ParentchainId::TargetB => "L1:NodeTemplate",
};
write!(f, "{}", message)
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like this to be upstreamed and customizeable. but it should work inside enclave too and should replace all log prefixes

Copy link
Member

Choose a reason for hiding this comment

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

Display is part of core, so it can work inside the enclave too.

I am unsure if it makes sense to replace the general log prefixes. It is not the same as in the substrate runtime, where we know that the encointer logger target is always in the runtime. Here it can be any crate in a fairly complex setup, so we should keep the crate path in in the log IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

pardon, I didn't mean the pallet log prefixes. I meant the ones where we deliberately printed TargetA/B/Integritee before.
crate path in the log is fine, but the parentchain should become part of the prefix or be therwise prepended to the log message where it makes sense

Comment on lines +788 to +802
fn print_events<R, H>(events: Vec<EventRecord<R, H>>, parentchain_id: ParentchainId)
where
R: Debug,
{
for evr in &events {
debug!("Decoded: phase = {:?}, event = {:?}", evr.phase, evr.event);
match &evr.event {
RuntimeEvent::Balances(be) => {
info!("[+] Received balances event");
debug!("{:?}", be);
match &be {
pallet_balances::Event::Transfer {
from: transactor,
to: dest,
amount: value,
} => {
debug!(" Transactor: {:?}", transactor.to_ss58check());
debug!(" Destination: {:?}", dest.to_ss58check());
debug!(" Value: {:?}", value);
},
_ => {
trace!("Ignoring unsupported balances event");
},
}
},
_ => ()
if evr.phase == ApplyExtrinsic(0) {
// not interested in intrinsics
continue
}
let re = Regex::new(r"\s[0-9a-f]*\s\(").unwrap();
let event_str = re
.replace_all(format!("{:?}", evr.event).as_str(), "(")
.replace("RuntimeEvent::", "")
.replace("Event::", "");
println!("[{}] Event: {}", parentchain_id, event_str);
Copy link
Member Author

Choose a reason for hiding this comment

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

we were lucky. no need to map it all, we can just use the debug printed event which is nicely human readable already. some string magic helps to keeps lines short

Copy link
Member

Choose a reason for hiding this comment

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

As you mention, regex is always black magic, so I would be very happy to see a function here :)

// format the event to keep the lines short
fn format_event(event: &str) -> String

// or maybe
fn format_event<'a>(event: &'a str) -> &'a str

@@ -690,7 +710,7 @@ fn init_target_parentchain<E>(
fn init_parentchain<E>(
enclave: &Arc<E>,
node_api: &ParentchainApi,
tee_account_id: &AccountId32,
tee_account_id: Option<AccountId32>,
Copy link
Member Author

Choose a reason for hiding this comment

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

the idea is: if None, that means that no extrinsics need ever to be sent to this parentchain

Copy link
Member

Choose a reason for hiding this comment

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

I think the idea is good, but it should not be documented as a PR comment ;)

Copy link
Member

Choose a reason for hiding this comment

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

Same as before, this can also be an Option<&AccountId32>.

Comment on lines +106 to +126
debug!("Existential deposit is = {:?}", existential_deposit);
let balance_transfer_fee = api
.get_fee_details(
api.balance_transfer_allow_death(
MultiAddress::Address32([0u8; 32]),
existential_deposit,
)
.encode()
.into(),
None,
)
.unwrap()
.unwrap()
.inclusion_fee
.unwrap()
.inclusion_fee();
debug!("Balance Transfer Fee is = {:?}", balance_transfer_fee);

let min_required_funds = existential_deposit
.saturating_mul(EXISTENTIAL_DEPOSIT_FACTOR_FOR_INIT_FUNDS)
.saturating_add(balance_transfer_fee.saturating_mul(100));
Copy link
Member Author

Choose a reason for hiding this comment

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

this should probably be upstreamed as it is more robust than the previous solution

Copy link
Member

Choose a reason for hiding this comment

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

I think that the .saturating_mul(EXISTENTIAL_DEPOSIT_FACTOR_FOR_INIT_FUNDS) is not a good way to determine the min_required_funds. It has no connection to any onchain metric - it is just an arbitrary value set by us. I think it is better to remove it and increase the factor for the balance_transfer_fee, i.e.:

// ensure that we can send 10_000 transfers before the account falls below the existential deposit.
let min_required_funds = existential_deposit
		.saturating_add(balance_transfer_fee.saturating_mul(10_000));

Then we have set a value for min_required_fund that we can relate to an actual onchain significance.

@brenzi
Copy link
Member Author

brenzi commented Sep 12, 2023

Resulting screencast video

Copy link
Member

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Nice, this looks good! Only some details.

error!("{}", &error_msg);
let inner_error_msg: String =
Decode::decode(&mut rpc_return_value.value.as_slice())
.expect("Failed to decode node tempölate xt issuing RPC error msg");
Copy link
Member

Choose a reason for hiding this comment

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

typo


impl IssueNodeTemplateXtCmd {
pub fn run(&self, cli: &Cli) {
//todo!();
Copy link
Member

Choose a reason for hiding this comment

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

What is this todo about?

Comment on lines +53 to +56
let rpc_params = rpc_params
.into_iter()
.map(|p| itp_utils::hex::hex_encode(p.as_slice()))
.collect();
Copy link
Member

Choose a reason for hiding this comment

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

uii, if this is necessary for our rpc api, then we have to improve it, but it indeed seems that we use a similar approach in the worker.

Comment on lines +137 to +140
trace!(
"encoded extrinsic with nonce {}: 0x{}",
nonce_value,
hex::encode(xt.clone())
Copy link
Member

Choose a reason for hiding this comment

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

I'd remove this trace as it introduces a clone

Copy link
Member Author

Choose a reason for hiding this comment

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

the idea here is to format the encoded call exactly the way it could be copy-pasted and inspected with js/apps. So I'd rather leave it as is - unless you have a way to achieve exactly the same without the clone

.expect("A previously encoded extrinsic has valid codec; qed.")
let oe = OpaqueExtrinsic::from_bytes(&xt)
.expect("A previously encoded extrinsic has valid codec; qed.");
trace!("opaque extrinsic: {:?}", oe);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the log that is empty?

Copy link
Member Author

Choose a reason for hiding this comment

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

possibly

@@ -690,7 +710,7 @@ fn init_target_parentchain<E>(
fn init_parentchain<E>(
enclave: &Arc<E>,
node_api: &ParentchainApi,
tee_account_id: &AccountId32,
tee_account_id: Option<AccountId32>,
Copy link
Member

Choose a reason for hiding this comment

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

I think the idea is good, but it should not be documented as a PR comment ;)

}
}
}

fn init_target_parentchain<E>(
enclave: &Arc<E>,
tee_account_id: &AccountId32,
tee_account_id: Option<AccountId32>,
Copy link
Member

Choose a reason for hiding this comment

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

This might be a bit too nitpicky, but as we only use ref account below, this can be an Option<&AccountId>

@@ -690,7 +710,7 @@ fn init_target_parentchain<E>(
fn init_parentchain<E>(
enclave: &Arc<E>,
node_api: &ParentchainApi,
tee_account_id: &AccountId32,
tee_account_id: Option<AccountId32>,
Copy link
Member

Choose a reason for hiding this comment

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

Same as before, this can also be an Option<&AccountId32>.

@@ -129,6 +129,7 @@ where
extrinsics.len(),
parentchain_id
);
trace!("extrinsics: {:?}", extrinsics);
Copy link
Member

Choose a reason for hiding this comment

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

I think we spam too many extrinsic logs. :)

Comment on lines +788 to +802
fn print_events<R, H>(events: Vec<EventRecord<R, H>>, parentchain_id: ParentchainId)
where
R: Debug,
{
for evr in &events {
debug!("Decoded: phase = {:?}, event = {:?}", evr.phase, evr.event);
match &evr.event {
RuntimeEvent::Balances(be) => {
info!("[+] Received balances event");
debug!("{:?}", be);
match &be {
pallet_balances::Event::Transfer {
from: transactor,
to: dest,
amount: value,
} => {
debug!(" Transactor: {:?}", transactor.to_ss58check());
debug!(" Destination: {:?}", dest.to_ss58check());
debug!(" Value: {:?}", value);
},
_ => {
trace!("Ignoring unsupported balances event");
},
}
},
_ => ()
if evr.phase == ApplyExtrinsic(0) {
// not interested in intrinsics
continue
}
let re = Regex::new(r"\s[0-9a-f]*\s\(").unwrap();
let event_str = re
.replace_all(format!("{:?}", evr.event).as_str(), "(")
.replace("RuntimeEvent::", "")
.replace("Event::", "");
println!("[{}] Event: {}", parentchain_id, event_str);
Copy link
Member

Choose a reason for hiding this comment

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

As you mention, regex is always black magic, so I would be very happy to see a function here :)

// format the event to keep the lines short
fn format_event(event: &str) -> String

// or maybe
fn format_event<'a>(event: &'a str) -> &'a str

@brenzi
Copy link
Member Author

brenzi commented Oct 4, 2023

generally, I think we should revisit your review comments when we upstream the cherries here. I'd rather not polish this PR because it is meant to just be a demo. I'd rather merge upstream into this repo to clean it up. otherwise we do work twice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants