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: Compatibility between the voteweighted package and ICS consumer keeper #315

Merged
merged 12 commits into from
Apr 15, 2024

Conversation

Eric-Warehime
Copy link
Collaborator

Adds compat types so that ICS chains can use slinky.

It uses validator power instead of bonded tokens in the stake-weighted median computation.

It uses the most recent version of ics v5.0.0-alpha1.

Copy link

codecov bot commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 51.72414% with 14 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (main@f06be79). Click here to learn what that means.

Files Patch % Lines
pkg/math/voteweighted/ccv_compat.go 51.72% 13 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #315   +/-   ##
=======================================
  Coverage        ?   56.79%           
=======================================
  Files           ?      228           
  Lines           ?    10790           
  Branches        ?        0           
=======================================
  Hits            ?     6128           
  Misses          ?     4149           
  Partials        ?      513           

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

Copy link

@NeverHappened NeverHappened left a comment

Choose a reason for hiding this comment

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

Seems nice! Two requests:

  • there is no way to create CCVConsumerCompatKeeper now, because ccvKeeper is a private field. Can you add a constructor to it please?
  • can you also implement another ValidatorStore as well for CCVConsumerCompatKeeper? (it's used in another place)
type ValidatorStore interface {
	GetPubKeyByConsAddr(context.Context, sdk.ConsAddress) (cmtprotocrypto.PublicKey, error)
}

I implemented it like this (seems to be working):

func (c ConsumerValidatorStore) GetPubKeyByConsAddr(ctx context.Context, consAddr sdk.ConsAddress) (cmtprotocrypto.PublicKey, error) {
	sdkCtx := sdk.UnwrapSDKContext(ctx)
	val, found := c.k.GetCCValidator(sdkCtx, consAddr)
	if !found {
		// TODO
		return cmtprotocrypto.PublicKey{}, fmt.Errorf("not found CCValidator for address = TODO: ")
	}

	consPubKey, err := val.ConsPubKey()
	if err != nil {
		// TODO
		return cmtprotocrypto.PublicKey{}, fmt.Errorf("TODO")
	}
	tmPubKey, err := cryptocodec.ToCmtProtoPublicKey(consPubKey)
	if err != nil {
		// TODO
		return cmtprotocrypto.PublicKey{}, err
	}

	return tmPubKey, nil
}

// TotalBondedTokens iterates through all CCVs and returns the sum of all validator power.
func (c CCVConsumerCompatKeeper) TotalBondedTokens(ctx context.Context) (math.Int, error) {
total := math.NewInt(0)
sdkCtx, ok := ctx.(sdk.Context)

Choose a reason for hiding this comment

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

how about using sdkCtx := sdk.UnwrapSDKContext(ctx)?

@Eric-Warehime Eric-Warehime marked this pull request as ready for review April 11, 2024 01:12
Copy link
Contributor

@nivasan1 nivasan1 left a comment

Choose a reason for hiding this comment

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

lgtm

@Eric-Warehime Eric-Warehime merged commit eaac82a into main Apr 15, 2024
15 checks passed
@Eric-Warehime Eric-Warehime deleted the eric/ics-compat branch April 15, 2024 16:25
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.

4 participants