Skip to content

Implement delegation removed staking hook in pse module#10

Merged
miladz68 merged 4 commits into
masterfrom
milad/pse-unbdoning-snapshot
Nov 3, 2025
Merged

Implement delegation removed staking hook in pse module#10
miladz68 merged 4 commits into
masterfrom
milad/pse-unbdoning-snapshot

Conversation

@miladz68

@miladz68 miladz68 commented Oct 30, 2025

Copy link
Copy Markdown
Contributor

Description

Reviewers checklist:

  • Try to write more meaningful comments with clear actions to be taken.
  • Nit-picking should be unblocking. Focus on core issues.

Authors checklist

  • Provide a concise and meaningful description
  • Review the code yourself first, before making the PR.
  • Annotate your PR in places that require explanation.
  • Think and try to split the PR to smaller PR if it is big.

This change is Reviewable

@miladz68 miladz68 requested a review from a team as a code owner October 30, 2025 08:54

@ysv ysv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ysv reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @miladz68)


x/pse/keeper/hooks.go line 52 at r1 (raw file):

	}

	delegationScore, err := calculateAddedScore(ctx, h.k, valAddr, delegationTimeEntry)

nit: maybe addedScore is better name to keep it consistent with BeforeDelegationRemoved


x/pse/keeper/hooks_test.go line 19 at r1 (raw file):

func TestKeeper_Hooks(t *testing.T) {
	cases := []struct {

nice, very smart DSL for these tests 👍


x/pse/keeper/hooks_test.go line 27 at r1 (raw file):

			actions: []func(*runEnv){
				func(r *runEnv) { delegateAction(r, r.delegators[0], r.validators[0], 11) },
				func(r *runEnv) { waitAction(r, time.Second*8) },

one potentially nice to have case is to include time rounding.

Smth like:
waitAction(time.Second + time.Millisecond) or waitAction(5*time.Second - time.Millisecond)

not blocking


x/pse/keeper/hooks_test.go line 59 at r1 (raw file):

				func(r *runEnv) { waitAction(r, time.Second*5) },
				func(r *runEnv) { delegateAction(r, r.delegators[0], r.validators[0], 1) },
				func(r *runEnv) { delegateAction(r, r.delegators[0], r.validators[1], 1) },

I see these 2 delegateActions of 1ucore on a few unit tests right before assertion but they don't have any effect without waitAction.
Did you keep them on purpose to show this ?

Code quote:

				func(r *runEnv) { delegateAction(r, r.delegators[0], r.validators[0], 1) },
				func(r *runEnv) { delegateAction(r, r.delegators[0], r.validators[1], 1) },

@miladz68 miladz68 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ysv)


x/pse/keeper/hooks.go line 52 at r1 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

nit: maybe addedScore is better name to keep it consistent with BeforeDelegationRemoved

Done.


x/pse/keeper/hooks_test.go line 27 at r1 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

one potentially nice to have case is to include time rounding.

Smth like:
waitAction(time.Second + time.Millisecond) or waitAction(5*time.Second - time.Millisecond)

not blocking

added both scenarios


x/pse/keeper/hooks_test.go line 59 at r1 (raw file):

Previously, ysv (Yaroslav Savchuk) wrote…

I see these 2 delegateActions of 1ucore on a few unit tests right before assertion but they don't have any effect without waitAction.
Did you keep them on purpose to show this ?

actually they are effective when they come after the wait action. The small delegation invokes the hook and it forces the previous delegation to be multiplied by the wait duration which leads to increase of the score.

@ysv ysv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ysv reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @miladz68)


x/pse/keeper/hooks_test.go line 59 at r1 (raw file):

Previously, miladz68 (milad) wrote…

actually they are effective when they come after the wait action. The small delegation invokes the hook and it forces the previous delegation to be multiplied by the wait duration which leads to increase of the score.

I see what you mean. Because you assert AccountScoreSnapshot not AccountScore
Then it is fine, maybe worth adding comment in a single place for this

@miladz68 miladz68 merged commit 9258d27 into master Nov 3, 2025
15 of 16 checks passed
@miladz68 miladz68 deleted the milad/pse-unbdoning-snapshot branch November 3, 2025 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants