This repository was archived by the owner on Oct 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Overflow checker in initialize #36
Open
girazoki
wants to merge
8
commits into
main
Choose a base branch
from
overflow_checker_in_initialize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
aa9ad0f
Add overflow checks to initialization
girazoki f02e547
Add test
girazoki ea23021
Fmt
girazoki bb6f43b
Add a further check
girazoki 605fab4
Comment fmt
girazoki e2eb006
fix test
girazoki 726550b
Add it also when summing to previous rewards
girazoki 01d141e
Clean comments
girazoki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -412,12 +412,12 @@ pub mod pallet { | |
| let incoming_rewards: BalanceOf<T> = rewards | ||
| .iter() | ||
| .fold(0u32.into(), |acc: BalanceOf<T>, (_, _, reward)| { | ||
| acc + *reward | ||
| acc.saturating_add(*reward) | ||
| }); | ||
|
|
||
| // Ensure we dont go over funds | ||
| ensure!( | ||
| current_initialized_rewards + incoming_rewards <= Self::pot(), | ||
| current_initialized_rewards.saturating_add(incoming_rewards) <= Self::pot(), | ||
| Error::<T>::BatchBeyondFundPot | ||
| ); | ||
|
|
||
|
|
@@ -470,6 +470,8 @@ pub mod pallet { | |
| claimed_reward: initial_payment, | ||
| }; | ||
|
|
||
| // It should be safe not to use saturating_add here | ||
| // as we already checked before that these rewards do not overflow existing ones | ||
| current_initialized_rewards += *reward - initial_payment; | ||
| total_contributors += 1; | ||
|
|
||
|
|
@@ -478,6 +480,8 @@ pub mod pallet { | |
| // the native account has already some rewards in, we add the new ones | ||
| AccountsPayable::<T>::insert( | ||
| native_account, | ||
| // It should be safe not to use saturating_add here | ||
|
||
| // as we already checked before that these rewards do not overflow existing ones | ||
| RewardInfo { | ||
| total_reward: inserted_reward_info.total_reward | ||
| + reward_info.total_reward, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 could consider using an
asserthere to express this. That may or may not be a good idea :)