Skip to content
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

Merged
merged 10 commits into from
Nov 24, 2024

Conversation

kien6034
Copy link

@kien6034 kien6034 commented Nov 2, 2024

@kien6034 kien6034 force-pushed the kien/unfork-cosmos-sdk branch from 3d39e8a to 567f5aa Compare November 2, 2024 05:22
@kien6034 kien6034 changed the title feat: base app option feat: unfork cache size hardfix Nov 2, 2024
@kien6034 kien6034 changed the title feat: unfork cache size hardfix feat: unfork cosmos sdk Nov 2, 2024
@kien6034 kien6034 marked this pull request as draft November 2, 2024 19:37
}

// Other required hook methods with empty implementations
func (h TerraStakingHooks) AfterDelegationModified(ctx sdk.Context, _ sdk.AccAddress, valAddr sdk.ValAddress) error {

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?

Copy link
Author

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)

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")

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.

Copy link
Author

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

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?

Copy link
Author

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

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.

Copy link

@StrathCole StrathCole Nov 8, 2024

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()),
)

Copy link
Author

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

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.

@@ -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)),

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).

Copy link
Author

@kien6034 kien6034 Nov 10, 2024

Choose a reason for hiding this comment

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

agree on this

@kien6034 kien6034 marked this pull request as ready for review November 11, 2024 11:40
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"

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

Copy link
Author

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?

@hoank101
Copy link

hi @kien6034 can you resolve conflict

@hoank101 hoank101 merged commit 7289b31 into feat/unfork-cosmossdk-cometbft Nov 24, 2024
@hoank101 hoank101 deleted the kien/unfork-cosmos-sdk branch November 24, 2024 11:42
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