Implement delegation removed staking hook in pse module#10
Conversation
ysv
left a comment
There was a problem hiding this comment.
@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
left a comment
There was a problem hiding this comment.
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
addedScoreis 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)orwaitAction(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
left a comment
There was a problem hiding this comment.
@ysv reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: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
Description
Reviewers checklist:
Authors checklist
This change is