-
Notifications
You must be signed in to change notification settings - Fork 105
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
feat(runtime): Account for programs locked balance #3908
Conversation
1c00532
to
6c034ae
Compare
.map_err(|e| match e { | ||
DispatchError::Token(TokenError::BelowMinimum) => Error::<T>::InsufficientDeposit, | ||
DispatchError::Arithmetic(ArithmeticError::Overflow) => Error::<T>::Overflow, | ||
_ => unreachable!("Unexpected error: {e:?}"), |
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 cases could cause this branch?
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.
In this case only these two are possible. We just need to account for other potential DispatchError
variants to make it compile.
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.
Please no
Other variants of DispatchError
can be added and this will lead to panic, even if it is impossible now
Please make exhausted match or even better return error and panic in calling code (if absolutely unavoidable)
@@ -377,7 +383,15 @@ where | |||
ProgramStorageOf::<T>::remove_program_pages(program_id, memory_infix); | |||
|
|||
let program_account = program_id.cast(); | |||
let balance = CurrencyOf::<T>::free_balance(&program_account); | |||
|
|||
// Only `reducible_balance` is allowed to be transferred out, even if a part of the |
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.
does reducible balance include ED?
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.
Depends on Preservation
requirement. If Preservation::Expendable
is supplied then the account is allowed to die therefore the ED is included in the reducible_balance
. Otherwise it's not
// free balance includes the ED | ||
assert_eq!(CurrencyOf::<Test>::free_balance(program_account), value); | ||
|
||
// reducible balance for preserved account doesn't include the ED |
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.
program should be able to operate of the ED.
e.g.
ed = 10
program has 15, while 2 is frozen
program must be able to send 13
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.
test it pls
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.
if the idea is to always keep a program's account alive then it won't be able to touch the ED (provided we get the reducible_balance
with Preservation::Preserve
parameter. Otherwise we can pass the Preservation::Expandable
as the preservation requirement, thereby allowing the program's account to be wiped as dust in case the balance drops below the ED
Blocked by #3924 |
Implemented inside #3924 solution |
A necessary prerequisite for the staking builtin actor to be added. Being able to participate in staking for programs would mean they'll have part of their balances locked while bonding funds. This hasn't been accounted for so far - all checks of programs' funds availability have been based on their
free_balance
which can produce incorrect estimations and lead to errors in transfers.