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
Loans: ChangeGuard
trait and loans modifications
#1384
Conversation
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.
Important parts commented below:
} | ||
} | ||
|
||
pub struct ChangeGuardBridge<Change, ChangeGuardImpl>(PhantomData<(Change, ChangeGuardImpl)>); |
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 is the most essential part.
Each pallet has its own kind of change. They only know about its change. This ChangeGuardBridge
transform that pallet-specific change into a CfgChange
that the implementation of ChangeGuard
knows.
The current implementation only merges those into one enum. But we could change them into a more detailed one, appending the moment when it happens or adding a severity level that ChangeGuard
can understand.
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.
Clippy is failing but LGTM!
I've renamed the main functions of this feature to let change = Change::Loan(loan_id, LoanMutation::InterestRate(...));
let change_id = Loans::propose(origin, pool_id, change)?;
Loans::apply(origin, pool_id, change_id); But if you do not like or suggest others, please tell me. |
@lemunozm I do think these extrinsic names are a bit confusing 😅 Since the pallet name is loans, these will be |
I agree, it makes total sense what you say! 👍🏻 I'll add the suffix |
0a266a9
to
8142091
Compare
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! Gives us enough flexibility for future changes and we can channel down core changes to the pool-system and let the rest be handled by the ChangeGuard
impl
let (mut loan, _count) = Self::get_active_loan(pool_id, loan_id)?; | ||
transactional::with_transaction(|| { | ||
let result = loan.mutate_with(mutation.clone()); | ||
|
||
// We do not want to apply the mutation, | ||
// only check if there is no error in applying it | ||
TransactionOutcome::Rollback(result) | ||
})?; |
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 is new. It checks that the modification can be applied, at least when it is proposed. It doesn't mean later it can be applied or not, but at least it removes most of the bad usages for it, for example, trying to modify the interest rate in external pricing. If we don't check this, the change will be enqueued, and we will get the error weeks later.
This is not 100% reliable, because once the change can be applied, the loan could have been closed, or its state changed. i.e:
let change_id_1 = Loans::propose_loan_mutation(DCF::DiscountRate(0.2)); // ==> Ok
let change_id_2 = Loans::propose_loan_mutation(ValuationMethod::OutstandingDebt); // ==> Ok
// Time passes and both proposals become available to be applied
Loans::apply_change(change_id_2); // ==> Ok
Loans::apply_change(change_id_1); // ==> MutationError::DiscountedCashFlowExpected
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.
That's a great idea! We definitely should incorporate the same in pool-system
e15b916
to
50d0e4e
Compare
This is ready for a final review 🤓 |
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!
Description
This PR overwrites #1222 with some simplifications.
pallet-loans
. Now the implementor ofChangeGuard
, is who should allocate those mutations. This way, we extract frompallet-loans
and any futureChangeGuard
's user the need to manage mutations with its own storagepallet-loans
no longer has a dependency onCfgChange
. The runtime is who transforms theLoanMutation
type into aCfgChange
that the implementor ofChangeGuard
understand.Fixes #1207
Changes and Descriptions
ChangeGuard
trait.ChangeGuard
trait mock.pallet-loans
.pallet-loans
without the modification feature.