Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

[ABO-237] Affiliate Pallet #392

Merged
merged 6 commits into from
Feb 2, 2024
Merged

[ABO-237] Affiliate Pallet #392

merged 6 commits into from
Feb 2, 2024

Conversation

DidacSF
Copy link
Contributor

@DidacSF DidacSF commented Jan 18, 2024

Description

See here for details.

Type of changes

  • build: Changes that affect the build system or external dependencies (eg, Cargo, Docker)
  • ci: Changes to CI configuration
  • docs: Changes to documentation only
  • feat: Changes to add a new feature
  • fix: Changes to fix a bug
  • refactor: Changes that do not alter functionality
  • style: Changes to format the code
  • test: Changes to add missing tests or correct existing tests

Checklist

  • Tests for the changes have been added
  • Necessary documentation is added (if appropriate)
  • Formatted with cargo fmt --all
  • Linted with cargo clippy --all-features --all-targets
  • Tested with cargo test --workspace --all-features --all-targets

Copy link

codecov bot commented Jan 18, 2024

Codecov Report

Attention: 24 lines in your changes are missing coverage. Please review.

Comparison is base (4b7235e) 77.27% compared to head (433f69c) 77.12%.

Files Patch % Lines
pallets/ajuna-affiliate/src/lib.rs 69.23% 24 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #392      +/-   ##
===========================================
- Coverage    77.27%   77.12%   -0.15%     
===========================================
  Files           36       37       +1     
  Lines         4189     4267      +78     
===========================================
+ Hits          3237     3291      +54     
- Misses         952      976      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@darkfriend77 darkfriend77 left a comment

Choose a reason for hiding this comment

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

besides the naming, which I think needs to be more precise, it's good.

/// Stores the affiliated accounts from the perspectives of the affiliatee
#[pallet::storage]
#[pallet::getter(fn affiliatees)]
pub type Affiliatees<T: Config> =
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use more common names.

LinkedAccounts

Copy link
Contributor

Choose a reason for hiding this comment

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

I like that Affiliatees implies a direction, while LinkedAccounts does not. However, I do agree that the names are quite confusing, and even if Affiliatee has a notion of direction, it is undefined by the terminology who earns the rewards. If possible, we should find a term that defines both or add this extra part in the documentation.

Haha, this reminds me again that there are only two hard software problems: 1. cache invalidation, 2. variable naming.

Copy link
Contributor

@clangenb clangenb Jan 24, 2024

Choose a reason for hiding this comment

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

How about we name them: Downline and Upline accounts? I think this solves both of our issues:

  • It is directional
  • It uses the common affiliate marketing terms

So:

  • Affiliatees -> DownlineAccounts
  • Affiliators: can stay the same; these are accounts, which have downline accounts
  • Affiliatables: As @darkfriend77 suggests, I think it is unneded too.

Then do some renaming based on this suggestion.

pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Show resolved Hide resolved
/// There is no account set as the organizer
OrganizerNotSet,
/// An account cannot affiliate itself
CannotAffiliateSelf,
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, would replace in general Affiliate with Link

pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Nice, good job keeping the code fairly simple! I really think we have mostly on issue to solve: naming. Even though the naming is correct, it was really hard for me to keep track of which Aff* does what. I think I have added a good terminology suggestion in one of the comments, which we can refine.

Cargo.toml Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/README.md Outdated Show resolved Hide resolved
@@ -118,7 +118,7 @@ impl<T: Config> AvatarCombinator<T> {
})
.transpose()?;

Ok((leader_output, other_output.into_iter().chain(additional_output.into_iter()).collect()))
Ok((leader_output, other_output.into_iter().chain(additional_output).collect()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Another thing, I am quite picky with: feature PRs should not implement other unrelated fixes. Especially for me who is new to the code base, this makes my life easier. :)

pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
/// Stores the affiliated accounts from the perspectives of the affiliatee
#[pallet::storage]
#[pallet::getter(fn affiliatees)]
pub type Affiliatees<T: Config> =
Copy link
Contributor

@clangenb clangenb Jan 24, 2024

Choose a reason for hiding this comment

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

How about we name them: Downline and Upline accounts? I think this solves both of our issues:

  • It is directional
  • It uses the common affiliate marketing terms

So:

  • Affiliatees -> DownlineAccounts
  • Affiliators: can stay the same; these are accounts, which have downline accounts
  • Affiliatables: As @darkfriend77 suggests, I think it is unneded too.

Then do some renaming based on this suggestion.

pallets/ajuna-affiliate/src/tests.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/tests.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/tests.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/traits.rs Outdated Show resolved Hide resolved
@DidacSF DidacSF marked this pull request as ready for review January 24, 2024 15:44
Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Very nice cleanup, thanks for removing the unrelated changes! I just noted a few details, but nothing major.

pallets/ajuna-affiliate/src/traits.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/tests.rs Show resolved Hide resolved
pallets/ajuna-affiliate/src/tests.rs Show resolved Hide resolved
pallets/ajuna-affiliate/src/tests.rs Show resolved Hide resolved
@DidacSF DidacSF requested a review from clangenb January 25, 2024 12:10
Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Nice, I am happy that you liked my suggestions!

pallets/ajuna-affiliate/src/tests.rs Outdated Show resolved Hide resolved
@DidacSF DidacSF requested a review from clangenb January 26, 2024 14:53
Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Nothing really to add, current state looks good. 👍

pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
pallets/ajuna-affiliate/src/lib.rs Outdated Show resolved Hide resolved
@DidacSF DidacSF requested a review from clangenb January 30, 2024 10:40
Copy link
Contributor

@clangenb clangenb left a comment

Choose a reason for hiding this comment

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

Nice, codewise nothing to add, I just have one fundamental question. :)

Comment on lines +57 to +60
type RuleIdentifier: Parameter + MaxEncodedLen;

/// The rule type at runtime.
type RuntimeRule: Parameter + MaxEncodedLen;
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, exactly, this is how I meant it. I have been thinking some more about a trait bound we could introduce here, like ExecuteRule. However, as this pallet has no predefined hooks, meaning the pallet that uses the affiliate pallet can decide when to use this it won't be needed.

However, then that pallet needs to invoke the execution of the rule itself, then the question is, why do we even store the rule here? It is not needed, the invoking pallet already knows, which rule it wants to execute. Then this pallet, would actually only need to handle affiliate relations and no rules at all, and the other pallet simply wants to check if an account is an affiliator or not.

Alternatively, if we really and this to be generic, then maybe the RuleId does not correspond to the extrinsic enum variant. This would allow some runtime to even have two pallets, one that wants to add affiliate relations, and another one that would want to execute the rule. In this case, we'd need to store the rule here, but we'd need to have a trait bound so that the other pallet could execute the rule, if it finds one.

This is probably one more fundamental thing we have to discuss in the brainstorming session tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I get what you mean, it really is something that we should discuss in the meeting

@darkfriend77 darkfriend77 merged commit 8152444 into develop Feb 2, 2024
13 checks passed
@darkfriend77 darkfriend77 deleted the ds/AB0-237 branch February 2, 2024 14:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants