Skip to content

Commit

Permalink
use *uint64 as argument type for GetFinalizedHeader instead of `exp…
Browse files Browse the repository at this point in the history
…orted.Height`

Signed-off-by: Masanori Yoshida <[email protected]>
  • Loading branch information
siburu committed Nov 9, 2023
1 parent f12dcdf commit 374258c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
7 changes: 3 additions & 4 deletions chains/tendermint/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcclient "github.com/cosmos/ibc-go/v7/modules/core/client"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
tmclient "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"

Expand Down Expand Up @@ -110,11 +109,11 @@ func (pr *Prover) SetupHeadersForUpdate(counterparty core.FinalityAwareChain, la
}

// GetFinalizedHeader returns the finalized header at `height`
func (pr *Prover) GetFinalizedHeader(height exported.Height) (core.Header, error) {
if height == nil || height.IsZero() {
func (pr *Prover) GetFinalizedHeader(height *uint64) (core.Header, error) {
if height == nil {
return pr.UpdateLightClient(0)
} else {
return pr.UpdateLightClient(int64(height.GetRevisionHeight()))
return pr.UpdateLightClient(int64(*height))
}
}

Expand Down
5 changes: 2 additions & 3 deletions core/provers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)

// Prover represents a prover that supports generating a commitment proof
Expand Down Expand Up @@ -50,9 +49,9 @@ type LightClient interface {
// FinalityAware provides the capability to determine the finality of the chain
type FinalityAware interface {
// GetFinalizedHeader returns the finalized header on this chain corresponding to `height`.
// If `height` is nil or zero, this function returns the latest finalized header.
// If `height` is nil, this function returns the latest finalized header.
// If the header at `height` isn't finalized yet, this function returns an error.
GetFinalizedHeader(height exported.Height) (Header, error)
GetFinalizedHeader(height *uint64) (Header, error)
}

// FinalityAwareChain is FinalityAware + Chain
Expand Down
11 changes: 6 additions & 5 deletions provers/mock/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ func (pr *Prover) getDelayedLatestFinalizedHeight() (exported.Height, error) {
}

// GetFinalizedHeader returns the finalized header at `height`
func (pr *Prover) GetFinalizedHeader(height exported.Height) (core.Header, error) {
func (pr *Prover) GetFinalizedHeader(height *uint64) (core.Header, error) {
if latestFinalizedHeight, err := pr.getDelayedLatestFinalizedHeight(); err != nil {
return nil, err
} else if height == nil || height.IsZero() {
} else if height == nil {
return pr.createMockHeader(latestFinalizedHeight)
} else if height.GT(latestFinalizedHeight) {
return nil, fmt.Errorf("the requested height is greater than the latest finalized height: %v > %v", height, latestFinalizedHeight)
} else if *height > latestFinalizedHeight.GetRevisionHeight() {
return nil, fmt.Errorf("the requested height is greater than the latest finalized height: %v > %v", *height, latestFinalizedHeight)
} else {
return pr.createMockHeader(height)
ics02Height := clienttypes.NewHeight(latestFinalizedHeight.GetRevisionNumber(), *height)
return pr.createMockHeader(ics02Height)
}
}

Expand Down

0 comments on commit 374258c

Please sign in to comment.