Skip to content

Commit

Permalink
Refactor light client handling, remove reliance on histroical info (#416
Browse files Browse the repository at this point in the history
)

* use light client not chain to get trusted headers

* refactor light client handling

Remove SyncHeaders entirely. Reduce light client API. We can update off chain light clients. Then we can get creation or update headers to handle on chain light clients. No other functions necessary

* continue fixing cmd and self review suggestions

* fix build

* update error message and add todo

* fix lgtm

* use uint64 in latest height return

* fix lint

* more self review fixes

* apply @AdityaSripal review suggestions

* fix lint

* add - 1 notes cc @fedekunze

* add more -1 notes

* fix golang ci
  • Loading branch information
colin-axner authored Feb 10, 2021
1 parent 1e98674 commit 872dc2e
Show file tree
Hide file tree
Showing 17 changed files with 373 additions and 532 deletions.
4 changes: 2 additions & 2 deletions cmd/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ $ %s l u ibc-1`, appName, appName)),
return err
}

ah, err := chain.UpdateLightWithHeader()
lightBlock, err := chain.UpdateLightClient()
if err != nil {
return err
}
fmt.Printf("Updated light client for %s from height %d -> height %d\n",
args[0], bh.Header.Height, ah.Header.Height)
args[0], bh.Header.Height, lightBlock.Header.Height)
return nil
},
}
Expand Down
31 changes: 5 additions & 26 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ $ %s q txs ibc-0 "message.action=transfer"`, appName, appName)),
return err
}

h, err := chain.UpdateLightWithHeader()
_, err = chain.UpdateLightClient()
if err != nil {
return err
}
Expand All @@ -149,7 +149,7 @@ $ %s q txs ibc-0 "message.action=transfer"`, appName, appName)),
return err
}

txs, err := chain.QueryTxs(relayer.MustGetHeight(h.GetHeight()), int(offset), int(limit), events)
txs, err := chain.QueryTxs(chain.MustGetLatestLightHeight(), int(offset), int(limit), events)
if err != nil {
return err
}
Expand Down Expand Up @@ -291,7 +291,7 @@ $ %s q hdr ibc-1`, appName, appName, appName)),

switch len(args) {
case 1:
header, err = chain.QueryLatestHeader()
header, err = chain.GetLightSignedHeaderAtHeight(0)
if err != nil {
return err
}
Expand All @@ -302,17 +302,6 @@ $ %s q hdr ibc-1`, appName, appName, appName)),
return err
}

if height == 0 {
height, err = chain.QueryLatestHeight()
if err != nil {
return err
}

if height == -1 {
return relayer.ErrLightNotInitialized
}
}

header, err = chain.QueryHeaderAtHeight(height)
if err != nil {
return err
Expand Down Expand Up @@ -775,17 +764,12 @@ $ %s q pkts demo-path`, appName, appName, appName)),
return err
}

sh, err := relayer.NewSyncHeaders(c[src], c[dst])
if err != nil {
return err
}

strategy, err := path.GetStrategy()
if err != nil {
return err
}

sp, err := strategy.UnrelayedSequences(c[src], c[dst], sh)
sp, err := strategy.UnrelayedSequences(c[src], c[dst])
if err != nil {
return err
}
Expand Down Expand Up @@ -831,17 +815,12 @@ $ %s q acks demo-path`, appName, appName)),
return err
}

sh, err := relayer.NewSyncHeaders(c[src], c[dst])
if err != nil {
return err
}

strategy, err := path.GetStrategy()
if err != nil {
return err
}

sp, err := strategy.UnrelayedAcknowledgements(c[src], c[dst], sh)
sp, err := strategy.UnrelayedAcknowledgements(c[src], c[dst])
if err != nil {
return err
}
Expand Down
69 changes: 16 additions & 53 deletions cmd/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ $ %s tx raw uc ibc-0 ibc-1 ibconeclient`, appName, appName)),
return err
}

dstHeader, err := chains[dst].UpdateLightWithHeader()
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dstHeader)
updateHeader, err := chains[src].GetIBCUpdateHeader(chains[dst])
if err != nil {
return err
}
Expand All @@ -98,7 +93,7 @@ $ %s tx raw clnt ibc-1 ibc-0 ibconeclient`, appName, appName)),
return err
}

dstHeader, err := chains[dst].UpdateLightWithHeader()
dstHeader, err := chains[src].GetIBCCreateClientHeader(chains[dst])
if err != nil {
return err
}
Expand Down Expand Up @@ -186,16 +181,11 @@ $ %s tx raw conn-try ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn2`,
return err
}

_, dsth, err := relayer.UpdatesWithHeaders(chains[src], chains[dst])
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dsth)
updateHeader, err := chains[src].GetIBCUpdateHeader(chains[dst])
if err != nil {
return err
}
openTry, err := chains[src].ConnTry(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1)
openTry, err := chains[src].ConnTry(chains[dst])
if err != nil {
return err
}
Expand Down Expand Up @@ -234,17 +224,12 @@ $ %s tx raw conn-ack ibc-0 ibc-1 ibconeclient ibczeroclient ibcconn1 ibcconn2`,
return err
}

_, dsth, err := relayer.UpdatesWithHeaders(chains[src], chains[dst])
updateHeader, err := chains[src].GetIBCUpdateHeader(chains[dst])
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dsth)
if err != nil {
return err
}

openAck, err := chains[src].ConnAck(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1)
openAck, err := chains[src].ConnAck(chains[dst])
if err != nil {
return err
}
Expand Down Expand Up @@ -283,22 +268,18 @@ $ %s tx raw conn-confirm ibc-0 ibc-1 ibczeroclient ibconeclient ibcconn1 ibcconn
return err
}

_, dsth, err := relayer.UpdatesWithHeaders(chains[src], chains[dst])
updateHeader, err := chains[src].GetIBCUpdateHeader(chains[dst])
if err != nil {
return err
}

// NOTE: We query connection at height - 1 because of the way tendermint returns
// proofs the commit for height n is contained in the header of height n + 1
dstState, err := chains[dst].QueryConnection(dsth.Header.Height - 1)
dstState, err := chains[dst].QueryConnection(int64(chains[dst].MustGetLatestLightHeight()) - 1)
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dsth)
if err != nil {
return err
}
txs := []sdk.Msg{
chains[src].ConnConfirm(dstState),
chains[src].UpdateClient(updateHeader),
Expand Down Expand Up @@ -408,17 +389,12 @@ $ %s tx raw chan-try ibc-0 ibc-1 ibczeroclient ibcconn0 ibcchan1 ibcchan2 transf
return err
}

dstHeader, err := chains[dst].UpdateLightWithHeader()
updateHeader, err := chains[src].GetIBCUpdateHeader(chains[dst])
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dstHeader)
if err != nil {
return err
}

openTry, err := chains[src].ChanTry(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1)
openTry, err := chains[src].ChanTry(chains[dst])
if err != nil {
return err
}
Expand Down Expand Up @@ -459,17 +435,12 @@ $ %s tx raw chan-ack ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 transfer transf
return err
}

dstHeader, err := chains[dst].UpdateLightWithHeader()
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dstHeader)
updateHeader, err := chains[src].GetIBCUpdateHeader(chains[dst])
if err != nil {
return err
}

openAck, err := chains[src].ChanAck(chains[dst], updateHeader.GetHeight().GetRevisionHeight()-1)
openAck, err := chains[src].ChanAck(chains[dst])
if err != nil {
return err
}
Expand Down Expand Up @@ -509,20 +480,16 @@ $ %s tx raw chan-confirm ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 transfer tr
return err
}

dstHeader, err := chains[dst].UpdateLightWithHeader()
updateHeader, err := chains[src].GetIBCUpdateHeader(chains[dst])
if err != nil {
return err
}

dstChanState, err := chains[dst].QueryChannel(dstHeader.Header.Height - 1)
dstChanState, err := chains[dst].QueryChannel(int64(chains[dst].MustGetLatestLightHeight()) - 1)
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dstHeader)
if err != nil {
return err
}
txs := []sdk.Msg{
chains[src].UpdateClient(updateHeader),
chains[src].ChanConfirm(dstChanState),
Expand Down Expand Up @@ -624,20 +591,16 @@ $ %s tx raw chan-close-confirm ibc-0 ibc-1 ibczeroclient ibcchan1 ibcchan2 trans
return err
}

dstHeader, err := chains[dst].UpdateLightWithHeader()
updateHeader, err := chains[src].GetIBCUpdateHeader(chains[dst])
if err != nil {
return err
}

dstChanState, err := chains[dst].QueryChannel(dstHeader.Header.Height - 1)
dstChanState, err := chains[dst].QueryChannel(int64(chains[dst].MustGetLatestLightHeight()) - 1)
if err != nil {
return err
}

updateHeader, err := relayer.InjectTrustedFields(chains[dst], chains[src], dstHeader)
if err != nil {
return err
}
txs := []sdk.Msg{
chains[src].UpdateClient(updateHeader),
chains[src].ChanCloseConfirm(dstChanState),
Expand Down
18 changes: 4 additions & 14 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,22 +385,17 @@ $ %s tx relay demo-path`, appName, appName, appName, appName)),
return err
}

sh, err := relayer.NewSyncHeaders(c[src], c[dst])
if err != nil {
return err
}

strategy, err := GetStrategyWithOptions(cmd, config.Paths.MustGet(args[0]).MustGetStrategy())
if err != nil {
return err
}

sp, err := strategy.UnrelayedSequences(c[src], c[dst], sh)
sp, err := strategy.UnrelayedSequences(c[src], c[dst])
if err != nil {
return err
}

if err = strategy.RelayPackets(c[src], c[dst], sp, sh); err != nil {
if err = strategy.RelayPackets(c[src], c[dst], sp); err != nil {
return err
}

Expand Down Expand Up @@ -430,24 +425,19 @@ $ %s tx acks demo-path -l 3 -s 6`, appName, appName)),
return err
}

sh, err := relayer.NewSyncHeaders(c[src], c[dst])
if err != nil {
return err
}

strategy, err := GetStrategyWithOptions(cmd, config.Paths.MustGet(args[0]).MustGetStrategy())
if err != nil {
return err
}

// sp.Src contains all sequences acked on SRC but acknowledgement not processed on DST
// sp.Dst contains all sequences acked on DST but acknowledgement not processed on SRC
sp, err := strategy.UnrelayedAcknowledgements(c[src], c[dst], sh)
sp, err := strategy.UnrelayedAcknowledgements(c[src], c[dst])
if err != nil {
return err
}

if err = strategy.RelayAcknowledgements(c[src], c[dst], sp, sh); err != nil {
if err = strategy.RelayAcknowledgements(c[src], c[dst], sp); err != nil {
return err
}

Expand Down
8 changes: 2 additions & 6 deletions relayer/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,14 +683,10 @@ func (c *Chain) GenerateConnHandshakeProof(height uint64) (clientState ibcexport
// UpgradeChain submits and upgrade proposal using a zero'd out client state with an updated unbonding period.
func (c *Chain) UpgradeChain(dst *Chain, plan *upgradetypes.Plan, deposit sdk.Coin,
unbondingPeriod time.Duration) error {
sh, err := NewSyncHeaders(c, dst)
if err != nil {
return err
}
if err := sh.Updates(c, dst); err != nil {
if _, _, err := UpdateLightClients(c, dst); err != nil {
return err
}
height := int64(sh.GetHeight(dst.ChainID))
height := int64(dst.MustGetLatestLightHeight())

clientStateRes, err := dst.QueryClientState(height)
if err != nil {
Expand Down
Loading

0 comments on commit 872dc2e

Please sign in to comment.