-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: master
Are you sure you want to change the base?
Conversation
trouble sending an extrinsic to target B edit: slice wasn't empty, but inside enclave the debug rendering is null. the problem was too little funds to pay for fees |
maybe try to align pallet indices in node-template with other nodes:
see integritee-network/worker#1445 edit: does not fix the empty extrinsic error |
#[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) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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>
.
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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Resulting screencast video |
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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!(); |
There was a problem hiding this comment.
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?
let rpc_params = rpc_params | ||
.into_iter() | ||
.map(|p| itp_utils::hex::hex_encode(p.as_slice())) | ||
.collect(); |
There was a problem hiding this comment.
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.
trace!( | ||
"encoded extrinsic with nonce {}: 0x{}", | ||
nonce_value, | ||
hex::encode(xt.clone()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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>, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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. :)
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); |
There was a problem hiding this comment.
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
Co-authored-by: clangenb <[email protected]>
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 |
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.