-
Notifications
You must be signed in to change notification settings - Fork 38
Conversation
* Init commit * Small fixes * Chain extension & precompile modifications * TODO handling * Traces, improved gas tracking, fixed issues * Doc to placeholder weight * Doc & typos * Change base * Fix UT * Update TODOs, cleanup * Fix contract issues
* Remove chain-extension-trait package * Dapps Staking CE optimizations * Dapps Staking CE optimizations * Rename dapps-staking CE in general way * Derive Default for chain extension structs * Implement Default trait for CEs * Fix typo
4d6aefe
to
902fcbf
Compare
5d72e25
to
957f0e6
Compare
// TODO: correct weight calculation directly from pallet! | ||
let weight = Weight::from_ref_time(1_000_000_000); | ||
env.charge_weight(weight)?; | ||
// We need to immediately charge for the worst case scenario. Gas equals Weight in pallet-contracts context. |
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 was confused at first by this because it seems so familiar lol 😅
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 believe gas charging should be rewritten for new weighs, including comments. Let’s do it in XVMv3
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 meant to say that the reason this code looked so familiar is that I was the author. In the PR that added weight handling. xD
But it was like 2 months ago so I've forgotten about it.
This handling should be fine - some stuff needs to be benchmarked but that won't change the current weights too much.
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.
Fixed
@@ -117,7 +117,9 @@ fn cannot_register_candidate_if_too_many() { | |||
|
|||
// reset desired candidates: | |||
<crate::DesiredCandidates<Test>>::put(1); | |||
assert_ok!(CollatorSelection::register_as_candidate(RuntimeOrigin::signed(4))); | |||
assert_ok!(CollatorSelection::register_as_candidate( |
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.
Why are unrelated files changed by the formatter? Are you using different settings?
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 guess it’s new astar-frame formatting settings
frame/pallet-xvm/src/evm.rs
Outdated
error: XvmError::ExecutionError(Vec::default()), // TODO: make error mapping make more sense | ||
consumed_weight: 42u64, // TODO: res.actual_weight.map(|x| x.ref_time()).unwrap_or(context.max_weight), |
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 should go with worst case scenario here and specify consumed_weight: context.max_weight
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.
Yes, but it not works with new weighs, so, I just hack it to make it works.
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.
Can you please explain more? What doesn't work?
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 believe problem here is different types for Weight
and context types. We should rework it using new substrate weight system.
Ok(Default::default()) | ||
Ok(XvmCallOk { | ||
output: Default::default(), // TODO: Fill output vec with response from the call | ||
consumed_weight: 42u64, // TODO: res.actual_weight.map(|x| x.ref_time()).unwrap_or(context.max_weight), |
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.
You should extract correct consumed_weight
from the res
.
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.
Yes, but next time
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.
Why next time?
Weights should be handled properly in v2, right?
And it's a very minor fix. I guess same question as above, but why is the "correct" code commented out?
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.
Unfortunately this code no more works correctly, it assumes that weight is a number, but it is struct now.
I just want merge this PR because it takes so long time and proper weighting isn’t the main aim of this PR.
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 see - however, the struct that was introduced was simply a wrapper around the old u64 value.
That was the initial step, the next one being adding the PoV size.
For this particular case, in the PR, all you need to do is this:
consumed_weight: res.actual_weight.map(|x| x.ref_time()).unwrap_or(context.max_weight.ref_time())
Just add .ref_time()
to the max_weight
.
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.
Not that simple but fixed
frame/pallet-xvm/src/wasm.rs
Outdated
error: XvmError::ExecutionError(Vec::default()), // TODO: make error mapping make more sense | ||
consumed_weight: 42u64, //TODO: e.post_info.actual_weight.ref_time().unwrap_or(gas_limit), |
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 comment as for EVM counter-part, we should use context.max_weight
here.
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.
Fixed
frame/pallet-xvm/src/wasm.rs
Outdated
Ok(XvmCallOk { | ||
output: Default::default(), // TODO: Fill in with output from the call | ||
consumed_weight: 42u64, //TODO: e.post_info.actual_weight.ref_time().unwrap_or(gas_limit), |
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.
Correct consumed weight can be extracted from the res
.
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.
For sure
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.
Fixed
|
||
// TODO: rethink this? How do we get valid env in chain extension? Need to know which data to encode. | ||
// gas limit, taking into account used gas so far? | ||
let _origin_address = env.ext().address().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 think you can delete these 2 unused values.
_origin_address
will only be used in a case of an enum where contract can chose to use caller() or address()
_value
will be used only when calling payable function will work
Minimum allowed line rate is |
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.
LGTM!
Pull Request Summary
This PR containts XVM v2 prototype.
Feature list:
Check list