-
Notifications
You must be signed in to change notification settings - Fork 586
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
Add revision number tests for 07-tendermint #1302
Changes from 2 commits
5e3935a
af4c7ec
3b9869f
ebc1bad
fdc261f
ab1808a
c9097b2
ec7db93
eb7540a
83907b1
fa05b4b
223eb15
a7ba8df
25cc6f7
19bc44b
5f7220e
7dd3c34
29e2f9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,55 @@ func (endpoint *Endpoint) UpdateClient() (err error) { | |
return endpoint.Chain.sendMsgs(msg) | ||
} | ||
|
||
// UpgradeChain will upgrade a chain's chainID to the next revision number. | ||
// It will also update the counterparty client. | ||
// TODO: implement actual upgrade chain functionality via scheduling an upgrade | ||
// and upgrading the client via MsgUpgradeClient | ||
// see reference https://github.com/cosmos/ibc-go/pull/1169 | ||
func (endpoint *Endpoint) UpgradeChain() error { | ||
if endpoint.Counterparty.ClientID == "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Should we use |
||
return fmt.Errorf("cannot upgrade chain if there is no counterparty client") | ||
} | ||
|
||
clientState := endpoint.Counterparty.GetClientState().(*ibctmtypes.ClientState) | ||
|
||
// increment revision number in chainID | ||
oldChainID := clientState.ChainId | ||
revisionNumber := clienttypes.ParseChainID(oldChainID) | ||
newChainID, err := clienttypes.SetRevisionNumber(oldChainID, revisionNumber+1) | ||
if err != nil { | ||
// current chainID is not in revision format | ||
newChainID = clientState.ChainId + "-1" | ||
} | ||
|
||
// update chain | ||
endpoint.Chain.ChainID = newChainID | ||
endpoint.Chain.CurrentHeader.ChainID = newChainID | ||
endpoint.Chain.NextBlock() // commit changes | ||
|
||
// update counterparty client manually | ||
clientState.ChainId = newChainID | ||
clientState.LatestHeight = clienttypes.NewHeight(revisionNumber+1, clientState.LatestHeight.GetRevisionHeight()+1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be resetting revision height here to prove that resetting height still works There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too difficult right now. Would require resetting the |
||
endpoint.Counterparty.SetClientState(clientState) | ||
|
||
consensusState := &ibctmtypes.ConsensusState{ | ||
Timestamp: endpoint.Chain.LastHeader.GetTime(), | ||
Root: commitmenttypes.NewMerkleRoot(endpoint.Chain.LastHeader.Header.GetAppHash()), | ||
NextValidatorsHash: endpoint.Chain.LastHeader.Header.NextValidatorsHash, | ||
} | ||
endpoint.Counterparty.SetConsensusState(consensusState, clientState.GetLatestHeight()) | ||
|
||
// ensure the next update isn't identical to the one set in state | ||
endpoint.Chain.Coordinator.IncrementTime() | ||
endpoint.Chain.NextBlock() | ||
|
||
if err = endpoint.Counterparty.UpdateClient(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ConnOpenInit will construct and execute a MsgConnectionOpenInit on the associated endpoint. | ||
func (endpoint *Endpoint) ConnOpenInit() error { | ||
msg := connectiontypes.NewMsgConnectionOpenInit( | ||
|
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.
nice work on these tests!