-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: unfork cosmos sdk #17
feat: unfork cosmos sdk #17
Conversation
3d39e8a
to
567f5aa
Compare
} | ||
|
||
// Other required hook methods with empty implementations | ||
func (h TerraStakingHooks) AfterDelegationModified(ctx sdk.Context, _ sdk.AccAddress, valAddr sdk.ValAddress) error { |
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.
Would it make sense to modify and put the logic into the "BeforeDelegationCreated" and "BeforeDelegationSharesModified" functions using a helper function? This would allow an early exit like the current fork change does. Or is there a good reason to rather do it after?
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.
The reason why i don't use those hooks is because the hooks only provide us with this context (ctx sdk.Context, _ sdk.AccAddress, valAddr sdk.ValAddress)
, which is not-sufficient to perform the pre-check behavior like in the current forks. (we need the types.Msg...
to get the required information)
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.
Thanks for the clarification.
validatorDelegationPercent := sdk.NewDec(validatorPower).QuoInt64(totalPower.Int64()) | ||
|
||
if validatorDelegationPercent.GT(sdk.NewDecWithPrec(20, 2)) { | ||
panic("validator power is over the allowed limit") |
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.
Would it be possible to use a normal error instead of a panic here? I am not 100% sure why a panic was used in the original code, maybe you can clarify on that although you didn't write it.
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.
if subtractAccount {
if tokenSrc == types.Bonded {
panic("delegation token source cannot be bonded")
}
var sendName string
switch {
case validator.IsBonded():
sendName = types.BondedPoolName
case validator.IsUnbonding(), validator.IsUnbonded():
sendName = types.NotBondedPoolName
default:
panic("invalid validator status")
}
i think it align with the current checks logic. I think we should keep it as it is, but lets me find out if it is better to return err here
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.
Do you also need to handle the event of creating a new validator?
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.
@StrathCole the hook AfterDelegationModified
is already embedded in the internal keeper.Delegate
function, which is called by the CreateValidator
function
@@ -0,0 +1,92 @@ | |||
package staking |
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.
I am aware it is "clean" to create a full hook file. Given that only one function is used, would it make sense to create a simple hook file that inherits the distribution hooks file and in the function you alter first calls the inherited hook and then the additional code? This would remove one hook from the multihook list in the stakingkeeper.
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.
I meant like this:
type TerraStakingHooks struct {
distrkeeper.Hooks
sk stakingkeeper.Keeper
}
func NewTerraStakingHooks(sk stakingkeeper.Keeper, distrHooks distrkeeper.Hooks) *TerraStakingHooks {
return &TerraStakingHooks{
Hooks: distrHooks,
sk: sk,
}
}
func (h TerraStakingHooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
if err := h.Hooks.AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
return err
}
/* your code from the power check in here */
return nil
}
And in the app when setting up the hooks something like:
appKeepers.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(customstaking.NewTerraStakingHooks(appKeepers.StakingKeeper, appKeepers.DistrKeeper.Hooks()), appKeepers.SlashingKeeper.Hooks()),
)
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.
the distribution hooks is used for supporting rewards operation stuff, and the hook that i used already have the implementation. Imo, i think keeping it as the separate file though make the code looks "long", but will be cleaner and easier to maintain in the future
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.
My only thought was to remove the small overhead of calling all the hook functions that aren't used anyway. But it's nothing I would insist in.
app/keepers/keepers.go
Outdated
@@ -273,7 +273,7 @@ func NewAppKeepers( | |||
// register the staking hooks | |||
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks | |||
appKeepers.StakingKeeper.SetHooks( | |||
stakingtypes.NewMultiStakingHooks(appKeepers.DistrKeeper.Hooks(), appKeepers.SlashingKeeper.Hooks()), | |||
stakingtypes.NewMultiStakingHooks(appKeepers.DistrKeeper.Hooks(), appKeepers.SlashingKeeper.Hooks(), customstaking.NewTerraStakingHooks(*appKeepers.StakingKeeper)), |
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.
given the nature of the hook, it might make sense to put it first (unless you would merge it with the distrhooks anyway).
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.
agree on this
app/app.go
Outdated
"github.com/classic-terra/core/v3/app/mempool" | ||
signer_extraction "github.com/skip-mev/block-sdk/adapters/signer_extraction_adapter" | ||
"github.com/skip-mev/block-sdk/block" | ||
blockbase "github.com/skip-mev/block-sdk/block/base" |
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're having the skip-mev repo as dependencies in this PR
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.
i think because this branch is base off the feat/unfork-cosmos-sdk
that @hoank101 and @TropicalDog17 is working on rightnow.
@hoank101 @TropicalDog17 can you check this for me?
hi @kien6034 can you resolve conflict |
Closes #5