Skip to content
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

FRAME tweaks for Berkeley #772

Merged
merged 10 commits into from
Jul 26, 2023
14 changes: 9 additions & 5 deletions syllabus/6-FRAME/1-Intro_to_FRAME/Pallets_Traits_Slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ The goal is to learn by example, and show how you can use the Substrate codebase

---

## Balances Pallet & Currency Trait
## Balances Pallet & Fungible Traits

---

## Assets Pallet & Fungibles Trait
## Assets Pallet & Fungibles Traits

---

## NFT Pallet & Non-Fungibles Trait
## NFT Pallet & Non-Fungibles Traits

---

Expand All @@ -52,11 +52,15 @@ The goal is to learn by example, and show how you can use the Substrate codebase

---

## Collectives + Membership Pallet
## Conviction Voting + Referenda Pallet

(Open Governance)

---

## Democracy Pallet
## Ranked Collectives + Whitelist Pallet

(Technical Fellowship)

---

Expand Down
64 changes: 56 additions & 8 deletions syllabus/6-FRAME/2-FRAME_Basics/Calls_slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@ Here is a sentence which should help clarify their relationship, and why they ar
Here is a simple pallet call. Let's break it down.

```rust
#[pallet::call]
#[pallet::call(weight(<T as Config>::WeightInfo))]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::transfer())]
pub fn transfer(
origin: OriginFor<T>,
dest: AccountIdLookupOf<T>,
#[pallet::compact] value: T::Balance,
) -> DispatchResult {
let transactor = ensure_signed(origin)?;
let source = ensure_signed(origin)?;
let dest = T::Lookup::lookup(dest)?;
<Self as Currency<_>>::transfer( &transactor, &dest, value, ExistenceRequirement::AllowDeath)?;
<Self as fungible::Mutate<_>>::transfer(&source, &dest, value, Expendable)?;
Ok(())
}
}
Expand Down Expand Up @@ -219,13 +218,62 @@ Note that this also implies there can only be 256 calls per pallet due to the 1

## Weight

Each call must also include a `weight` attribute:
Each call must also include specify a call `weight`.

```rust
#[pallet::weight(T::WeightInfo::transfer())]
We have another lecture on Weights and Benchmarking, but the high level idea is that this weight function tells us how complex the call is, and the fees that should be charged to the user.

---

## Weight Per Call

This can be done per call:

```rust [3]
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(T::WeightInfo::transfer())]
#[pallet::call_index(0)]
pub fn transfer(
origin: OriginFor<T>,
dest: AccountIdLookupOf<T>,
#[pallet::compact] value: T::Balance,
) -> DispatchResult {
let source = ensure_signed(origin)?;
let dest = T::Lookup::lookup(dest)?;
<Self as fungible::Mutate<_>>::transfer(&source, &dest, value, Expendable)?;
Ok(())
}
}
```

We have another lecture on Weights and Benchmarking, but the high level idea is that this weight function tells us how complex the call is, and the fees that should be charged to the user.
---

## Weight for the Pallet

Or for all calls in the pallet:

```rust [1]
#[pallet::call(weight(<T as Config>::WeightInfo))]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
pub fn transfer(
origin: OriginFor<T>,
dest: AccountIdLookupOf<T>,
#[pallet::compact] value: T::Balance,
) -> DispatchResult {
let source = ensure_signed(origin)?;
let dest = T::Lookup::lookup(dest)?;
<Self as fungible::Mutate<_>>::transfer(&source, &dest, value, Expendable)?;
Ok(())
}
}
```
Comment on lines +251 to +270
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These code snippets seem rather dense for a "we'll actually cover this later" mention

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@notlesh only a single line is highlighted, which is the "weight" macro up top

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the larger code to show the difference between where the macro is located between the two options.


In this case, the weight function name is assumed to match the call name for all calls.

NOTES:

https://github.com/paritytech/substrate/pull/13932

---

Expand Down
Loading