-
Notifications
You must be signed in to change notification settings - Fork 2.7k
decouple balances from some modules #1641
Conversation
|
Good to see some work has been done on this area as well. Me and my colleagues are working on #1515 which may have some overlapping with this https://github.com/xlc/substrate/tree/fee |
core/sr-primitives/src/traits.rs
Outdated
| AccountKilled, | ||
| } | ||
|
|
||
| pub trait TransferToken<AccountId> { |
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 should keep this trait as simple as possible. Many methods here are internal/private methods.
This is my take: https://github.com/paritytech/substrate/pull/1648/files#diff-cfb20bdf2f3264df022885d7fe2de6a7R147
We should agree on a name to reduce upcoming conflicts...
TransferToken or TransferAsset?
Balance or Amount?
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.
Thanks, I have very few knowledge on blockchain names. I would be a bit more in favor of Balance than Amount as it characterize the type. But I won't argue at all, frankly I'm following your choice on that.
Yes the trait is bad in the current impl
Also if it happens you need the decl_event! modification I could make it in another 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.
what kind of internal private methods were you actually thinking of ?
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 don't see why other modules will want to call increase_total_stake_by (that's increase total issuance, nothing to do with staking).
Why anyone other than balances module needs to be aware of the different between set_free_balance_creating and set_free_balance?
I see many methods needs to be exposed only because contract module needs to reimplements the same logic with its overlay account db, if we can improve and avoid this duplication some how (which I don't have a good plan), then all the read config methods should be private (e.g. creation_fee and transfer_fee)
|
Yes some methods seems private but it is because of contract specific requirements: This are the reasons:
|
|
Today I was thinking about what to expose in the trait, here some thoughts:
pub struct DefaultTokenKind;
pub struct AlternativeToken0
pub struct AlternativeToken1
pub struct AlternativeToken2
pub struct AlternativeToken3
...
decl_module! {
pub struct Module<T: Trait, M=DefaultTokenKind> for enum Call where origin: T::Origin {
}
}
/////////////////////// then used like ///////////////////////
impl staking::Trait for Runtime {
type Staking = balances::Module<Self>;
type OnRewardMinted = Treasury;
type Event = Event;
}
impl democracy::Trait for Runtime {
type Staking = balances::Module<Self, AlternativeToken0>;
type Proposal = Call;
type Event = Event;
} |
|
It would be cool to have parameterisable modules (i.e. to use the same module twice under different configurations). I think it may make sense to have |
|
It seems like it is hard to abstract away the coupling between contract module and balances module without some major refactoring work to been done on contract module to somehow avoid the duplicated balances accounts logic. A potential solution for contract - balances coupling issue is introduce a new |
88c0725 to
f3f4264
Compare
|
OK I do agree, contract could be decoupled in another PR, OverlayTransferToken is a good direction but doesn't solve everything as some are related to gas use for fees. current state of PR:
TODO:
|
f3f4264 to
0b139f7
Compare
0b139f7 to
58210f8
Compare
|
Also here are some thoughs on abstracting contracts: in the overlay I only need:
to buy gas:
to refund_gas:
to implement DefaultComputeDispatchFee
|
|
looks good apart from the minor repotting. |
16b8bce to
99140bb
Compare
|
The naming is rather funky. |
7ad326c to
ad77320
Compare
|
Yes indeed, I replaced Staking by Funding. |
ad77320 to
a9527f4
Compare
srml/support/src/traits.rs
Outdated
| /// Returns if the account was successfully updated or update has led to killing of the account. | ||
| /// | ||
| /// NOTE: This assumes that the total stake remains unchanged after this operation. | ||
| fn reward_with_no_stake_increase_creating(who: &AccountId, value: Self::Balance) -> UpdateBalanceOutcome; |
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 appears to be a synonym for increase_free_balance_creating, which has a very important caveat in its documentation missing here:
/// Adds up to `value` to the free balance of `who`. If `who` doesn't exist, it is created.
///
/// This is a sensitive function since it circumvents any fees associated with account
/// setup. Ensure it is only called by trusted code.
///
/// NOTE: This assumes that the total stake remains unchanged after this operation. If
/// you mean to actually mint value into existence, then use `reward` instead.
pub fn increase_free_balance_creating(who: &T::AccountId, value: T::Balance) -> UpdateBalanceOutcome {
Self::set_free_balance_creating(who, Self::free_balance(who) + value)
}
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 have used "reward" to mean a safe operation that doesn't need thinking about too deeply: no fees are skipped (the destination account doesn't exist, then the operation fails without introducing a potential crypto-economic flaw) and the total issued amount is increased.
I would prefer to keep it having that meaning, with the lower-level "increase_free_balance" functions having the accordingly less safe implications.
|
More naming issues. |
|
@thiolliere please take a look at my changes. if all good, feel free to merge. |
|
don't you want to make the doc of increase_free_balance_creating more warrant ? |
* decouple balances from some module by creating a new traits in support/traits * improve decl_event
related to #1514
This is a first raw implementation of a decoupling of balances from other modules.
What is done
decl_event!to be able to use some more complex generic types in events. It can now handle all type for named generics ( Name = ty ) and if it fails to handle unnamed ones then it compile with a message advising to name it.so that works
what is to be done