Skip to content

Commit 687400c

Browse files
committed
use uint64 instead of *uint64 as argument type for GetFinalizedHeader
Signed-off-by: Masanori Yoshida <masanori.yoshida@datachain.jp>
1 parent 154f54f commit 687400c

File tree

8 files changed

+25
-34
lines changed

8 files changed

+25
-34
lines changed

chains/tendermint/prover.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,8 @@ func (pr *Prover) SetupHeadersForUpdate(counterparty core.FinalityAwareChain, la
109109
}
110110

111111
// GetFinalizedHeader returns the finalized header at `height`
112-
func (pr *Prover) GetFinalizedHeader(height *uint64) (core.Header, error) {
113-
if height == nil {
114-
return pr.UpdateLightClient(0)
115-
} else {
116-
return pr.UpdateLightClient(int64(*height))
117-
}
112+
func (pr *Prover) GetFinalizedHeader(height uint64) (core.Header, error) {
113+
return pr.UpdateLightClient(int64(height))
118114
}
119115

120116
func (pr *Prover) CheckRefreshRequired(counterparty core.ChainInfoICS02Querier) (bool, error) {

chains/tendermint/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (c *Chain) QueryUnfinalizedRelayPackets(ctx core.QueryContext, counterparty
209209
}
210210

211211
var counterpartyCtx core.QueryContext
212-
if counterpartyH, err := counterparty.GetFinalizedHeader(nil); err != nil {
212+
if counterpartyH, err := counterparty.GetFinalizedHeader(0); err != nil {
213213
return nil, err
214214
} else {
215215
counterpartyCtx = core.NewQueryContext(context.TODO(), counterpartyH.GetHeight())
@@ -262,7 +262,7 @@ func (c *Chain) QueryUnfinalizedRelayAcknowledgements(ctx core.QueryContext, cou
262262
}
263263

264264
var counterpartyCtx core.QueryContext
265-
if counterpartyH, err := counterparty.GetFinalizedHeader(nil); err != nil {
265+
if counterpartyH, err := counterparty.GetFinalizedHeader(0); err != nil {
266266
return nil, err
267267
} else {
268268
counterpartyCtx = core.NewQueryContext(context.TODO(), counterpartyH.GetHeight())

cmd/tx.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"context"
5-
"math"
65
"strings"
76

87
"github.com/cosmos/cosmos-sdk/client/flags"
@@ -43,6 +42,10 @@ func createClientsCmd(ctx *config.Context) *cobra.Command {
4342
flagSrcHeight = "src-height"
4443
flagDstHeight = "dst-height"
4544
)
45+
const (
46+
defaultSrcHeight = 0
47+
defaultDstHeight = 0
48+
)
4649
cmd := &cobra.Command{
4750
Use: "clients [path-name]",
4851
Short: "create a clients between two configured chains with a configured path",
@@ -63,29 +66,21 @@ func createClientsCmd(ctx *config.Context) *cobra.Command {
6366
return err
6467
}
6568

66-
var srcHeight *uint64
67-
if h, err := cmd.Flags().GetUint64(flagSrcHeight); err != nil {
69+
srcHeight, err := cmd.Flags().GetUint64(flagSrcHeight)
70+
if err != nil {
6871
return err
69-
} else if h == math.MaxUint64 {
70-
srcHeight = nil
71-
} else {
72-
srcHeight = &h
7372
}
7473

75-
var dstHeight *uint64
76-
if h, err := cmd.Flags().GetUint64(flagDstHeight); err != nil {
74+
dstHeight, err := cmd.Flags().GetUint64(flagDstHeight)
75+
if err != nil {
7776
return err
78-
} else if h == math.MaxUint64 {
79-
dstHeight = nil
80-
} else {
81-
dstHeight = &h
8277
}
8378

8479
return core.CreateClients(c[src], c[dst], srcHeight, dstHeight)
8580
},
8681
}
87-
cmd.Flags().Uint64(flagSrcHeight, math.MaxUint64, "src header at this height is submitted to dst chain")
88-
cmd.Flags().Uint64(flagDstHeight, math.MaxUint64, "dst header at this height is submitted to src chain")
82+
cmd.Flags().Uint64(flagSrcHeight, defaultSrcHeight, "src header at this height is submitted to dst chain")
83+
cmd.Flags().Uint64(flagDstHeight, defaultDstHeight, "dst header at this height is submitted to src chain")
8984
return cmd
9085
}
9186

core/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"golang.org/x/sync/errgroup"
99
)
1010

11-
func CreateClients(src, dst *ProvableChain, srcHeight, dstHeight *uint64) error {
11+
func CreateClients(src, dst *ProvableChain, srcHeight, dstHeight uint64) error {
1212
logger := GetChainPairLogger(src, dst)
1313
defer logger.TimeTrack(time.Now(), "CreateClients")
1414
var (
@@ -118,7 +118,7 @@ func UpdateClients(src, dst *ProvableChain) error {
118118
}
119119

120120
// getHeadersForCreateClient calls UpdateLightWithHeader on the passed chains concurrently
121-
func getHeadersForCreateClient(src, dst LightClient, srcHeight, dstHeight *uint64) (srch, dsth Header, err error) {
121+
func getHeadersForCreateClient(src, dst LightClient, srcHeight, dstHeight uint64) (srch, dsth Header, err error) {
122122
var eg = new(errgroup.Group)
123123
eg.Go(func() error {
124124
srch, err = src.GetFinalizedHeader(srcHeight)

core/headers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ func (sh *syncHeaders) Updates(src, dst ChainInfoLightClient) error {
7777
return err
7878
}
7979

80-
srcHeader, err := src.GetFinalizedHeader(nil)
80+
srcHeader, err := src.GetFinalizedHeader(0)
8181
if err != nil {
8282
logger.Error("error getting latest finalized header of src", err)
8383
return err
8484
}
85-
dstHeader, err := dst.GetFinalizedHeader(nil)
85+
dstHeader, err := dst.GetFinalizedHeader(0)
8686
if err != nil {
8787
logger.Error("error getting latest finalized header of dst", err)
8888
return err

core/provers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type FinalityAware interface {
5151
// GetFinalizedHeader returns the finalized header on this chain corresponding to `height`.
5252
// If `height` is nil, this function returns the latest finalized header.
5353
// If the header at `height` isn't finalized yet, this function returns an error.
54-
GetFinalizedHeader(height *uint64) (Header, error)
54+
GetFinalizedHeader(height uint64) (Header, error)
5555
}
5656

5757
// FinalityAwareChain is FinalityAware + Chain

core/send.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func GetFinalizedMsgResult(chain ProvableChain, msgID MsgID) (MsgResult, error)
2828

2929
if err := retry.Do(func() error {
3030
// query LFH for each retry because it can proceed.
31-
lfHeader, err := chain.GetFinalizedHeader(nil)
31+
lfHeader, err := chain.GetFinalizedHeader(0)
3232
if err != nil {
3333
return fmt.Errorf("failed to get latest finalized header: %v", err)
3434
}

provers/mock/prover.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ func (pr *Prover) getDelayedLatestFinalizedHeight() (exported.Height, error) {
9090
}
9191

9292
// GetFinalizedHeader returns the finalized header at `height`
93-
func (pr *Prover) GetFinalizedHeader(height *uint64) (core.Header, error) {
93+
func (pr *Prover) GetFinalizedHeader(height uint64) (core.Header, error) {
9494
if latestFinalizedHeight, err := pr.getDelayedLatestFinalizedHeight(); err != nil {
9595
return nil, err
96-
} else if height == nil {
96+
} else if height == 0 {
9797
return pr.createMockHeader(latestFinalizedHeight)
98-
} else if *height > latestFinalizedHeight.GetRevisionHeight() {
99-
return nil, fmt.Errorf("the requested height is greater than the latest finalized height: %v > %v", *height, latestFinalizedHeight)
98+
} else if height > latestFinalizedHeight.GetRevisionHeight() {
99+
return nil, fmt.Errorf("the requested height is greater than the latest finalized height: %v > %v", height, latestFinalizedHeight)
100100
} else {
101-
ics02Height := clienttypes.NewHeight(latestFinalizedHeight.GetRevisionNumber(), *height)
101+
ics02Height := clienttypes.NewHeight(latestFinalizedHeight.GetRevisionNumber(), height)
102102
return pr.createMockHeader(ics02Height)
103103
}
104104
}

0 commit comments

Comments
 (0)