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

Store historic header information for IBC #93

Merged
merged 5 commits into from
Aug 17, 2021

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Aug 14, 2021

Resolves #82

After #91

The historical_information.go was copied from cosmos-sdk with small modifications. Credits and big thanks to the original authors

Implements the IBC StakingKeeper interface

Not included:

  • no Validator meta data is stored with the historic information
  • no cli/ queries
    If we need any them, let's add a new issue.

@alpe alpe changed the base branch from main to 87-expose-new-func August 14, 2021 12:23
@alpe alpe force-pushed the 82-historic-validator-information branch from 133dbfb to f22295b Compare August 15, 2021 09:28
@alpe alpe force-pushed the 82-historic-validator-information branch from f22295b to 2834fbe Compare August 15, 2021 12:07
@alpe alpe marked this pull request as ready for review August 15, 2021 12:07
@alpe alpe requested a review from ethanfrey August 15, 2021 12:07
Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Looks good. Some suggestions for future improvements for tgrade 0.4

proto/confio/poe/v1beta1/poe.proto Outdated Show resolved Hide resolved
x/poe/keeper/historical_info.go Show resolved Hide resolved
x/poe/stakingadapter/keeper.go Show resolved Hide resolved
x/poe/keeper/keeper.go Show resolved Hide resolved
Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

A comment on the app.go wiring now that I made it through #91

@@ -269,7 +269,7 @@ func NewTgradeApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest

// Create IBC Keeper
app.ibcKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibchost.StoreKey], app.getSubspace(ibchost.ModuleName), stakingKeeper, scopedIBCKeeper,
appCodec, keys[ibchost.StoreKey], app.getSubspace(ibchost.ModuleName), &app.poeKeeper, scopedIBCKeeper,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah.. and now it has state once again 😄

But... how can app.poeKeeper be used on line 272 when it is set in 352? This smells funny

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A ref is parsed to the ibc keeper that is updated later. I will add a test that provides more confidence

Copy link
Contributor

Choose a reason for hiding this comment

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

A ref is passed to app.poeKeeper (probably the zero value).

Later we set app.poeKeeper = &stakingtypes.Adaptor{} or something like that, which does not update the other reference.

If you did *app.poeKeeper = staking types.Adaptor{}, then this would update the data that was pointed at by the same reference app.ibcKeeper has.

At least this is my understanding of pointers. As it is now, it points into space. This is also a bit harder to reason about when most of these are just empty structs, and return errors on all calls... when there is real state and logic, it will be most difficult

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please note app.poeKeeper is of type poekeeper.Keeper not a pointer.
When I pass the ref here it points to the empty (not nil) app.poeKeeper memory address. When the poeKeeper is instantiated, it is still the same memory address.
https://play.golang.org/p/y9VGNrLUUVC

Copy link
Contributor

Choose a reason for hiding this comment

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

I need to look into this...

Copy link
Contributor

Choose a reason for hiding this comment

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

That didn't quite convince me, so I played with it a bit more, to replicate more precisely how we use pointers: https://play.golang.org/p/xBlHLRh_ye_K

And that still matches your expected behaviour.

I guess I really don't understand how all these pointers and interfaces are implemented under the hood in Go, but your code is correct in spite of my confusion.

Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Good to show with a test, but this still doesn't convince me... let's extend the test a bit more (or link to code that shows this does indeed assert that the proper staking keeper is being called by the ibc contract

height := ibcclienttypes.Height{RevisionNumber: 1, RevisionHeight: 2}

// when
state, found := gapp.ibcKeeper.ClientKeeper.GetSelfConsensusState(ctx, height)
Copy link
Contributor

Choose a reason for hiding this comment

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

This uses the staking adaptor? Can you link to where that call happens?

Can we assert that data that we expect to be returned from such an adaptor (unbonding period?) is actually set properly? Not just that it returns "some data"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have extended the test to verify that the data returned is what was persisted before on begin block

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you. Looks convincing.

Base automatically changed from 87-expose-new-func to main August 17, 2021 10:03
Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

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

Thanks for adding the extra tests to put me at ease

height := ibcclienttypes.Height{RevisionNumber: 1, RevisionHeight: 2}

// when
state, found := gapp.ibcKeeper.ClientKeeper.GetSelfConsensusState(ctx, height)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you. Looks convincing.

@ethanfrey ethanfrey merged commit 038b10f into main Aug 17, 2021
@ethanfrey ethanfrey deleted the 82-historic-validator-information branch August 17, 2021 19:36
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.

Valset: Additional data for IBC to store
3 participants