Skip to content

Commit 50ad9c5

Browse files
committed
change block height from uint64 to int64 & lint
1 parent 224dde7 commit 50ad9c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+316
-226
lines changed

challenger/challenger.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (c *Challenger) RegisterQuerier() {
192192
})
193193
}
194194

195-
func (c *Challenger) getStartHeights(ctx context.Context, bridgeId uint64) (l1StartHeight uint64, l2StartHeight uint64, startOutputIndex uint64, err error) {
195+
func (c *Challenger) getStartHeights(ctx context.Context, bridgeId uint64) (l1StartHeight int64, l2StartHeight int64, startOutputIndex uint64, err error) {
196196
// get the bridge start height from the host
197197
l1StartHeight, err = c.host.QueryCreateBridgeHeight(ctx, bridgeId)
198198
if err != nil {
@@ -205,8 +205,8 @@ func (c *Challenger) getStartHeights(ctx context.Context, bridgeId uint64) (l1St
205205
if err != nil {
206206
return 0, 0, 0, err
207207
} else if output != nil {
208-
l1StartHeight = output.OutputProposal.L1BlockNumber
209-
l2StartHeight = output.OutputProposal.L2BlockNumber
208+
l1StartHeight = types.MustUint64ToInt64(output.OutputProposal.L1BlockNumber)
209+
l2StartHeight = types.MustUint64ToInt64(output.OutputProposal.L2BlockNumber)
210210
startOutputIndex = output.OutputIndex + 1
211211
}
212212
}

challenger/child/child.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ type Child struct {
3535

3636
eventQueue []challengertypes.ChallengeEvent
3737

38-
finalizingBlockHeight uint64
38+
finalizingBlockHeight int64
3939

4040
// status info
41-
lastUpdatedOracleL1Height uint64
42-
lastFinalizedDepositL1BlockHeight uint64
41+
lastUpdatedOracleL1Height int64
42+
lastFinalizedDepositL1BlockHeight int64
4343
lastFinalizedDepositL1Sequence uint64
4444
lastOutputTime time.Time
4545
nextOutputTime time.Time
@@ -56,7 +56,7 @@ func NewChildV1(
5656
}
5757
}
5858

59-
func (ch *Child) Initialize(ctx context.Context, startHeight uint64, startOutputIndex uint64, host hostNode, bridgeInfo opchildtypes.BridgeInfo, challenger challenger) error {
59+
func (ch *Child) Initialize(ctx context.Context, startHeight int64, startOutputIndex uint64, host hostNode, bridgeInfo opchildtypes.BridgeInfo, challenger challenger) error {
6060
_, err := ch.BaseChild.Initialize(ctx, startHeight, startOutputIndex, bridgeInfo)
6161
if err != nil {
6262
return err

challenger/child/deposit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ func (ch *Child) finalizeDepositHandler(_ context.Context, args nodetypes.EventH
2424
return nil
2525
}
2626

27-
func (ch *Child) handleFinalizeDeposit(l2BlockTime time.Time, l1BlockHeight uint64, l1Sequence uint64, from string, to string, amount sdk.Coin, baseDenom string) {
27+
func (ch *Child) handleFinalizeDeposit(l2BlockTime time.Time, l1BlockHeight int64, l1Sequence uint64, from string, to string, amount sdk.Coin, baseDenom string) {
2828
deposit := challengertypes.NewDeposit(l1Sequence, l1BlockHeight, from, to, baseDenom, amount.String(), l2BlockTime)
2929
ch.eventQueue = append(ch.eventQueue, deposit)
3030

3131
ch.Logger().Info("finalize token deposit",
32-
zap.Uint64("l1_blockHeight", l1BlockHeight),
32+
zap.Int64("l1_blockHeight", l1BlockHeight),
3333
zap.Uint64("l1_sequence", l1Sequence),
3434
zap.String("from", from),
3535
zap.String("to", to),

challenger/child/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func (ch *Child) beginBlockHandler(ctx context.Context, args nodetypes.BeginBlockArgs) (err error) {
15-
blockHeight := uint64(args.Block.Header.Height)
15+
blockHeight := args.Block.Header.Height
1616
ch.eventQueue = ch.eventQueue[:0]
1717

1818
err = ch.prepareTree(blockHeight)
@@ -28,7 +28,7 @@ func (ch *Child) beginBlockHandler(ctx context.Context, args nodetypes.BeginBloc
2828
}
2929

3030
func (ch *Child) endBlockHandler(_ context.Context, args nodetypes.EndBlockArgs) error {
31-
blockHeight := uint64(args.Block.Header.Height)
31+
blockHeight := args.Block.Header.Height
3232
batchKVs := make([]types.RawKV, 0)
3333
pendingChallenges := make([]challengertypes.Challenge, 0)
3434

@@ -109,6 +109,6 @@ func (ch *Child) txHandler(_ context.Context, args nodetypes.TxHandlerArgs) erro
109109
if !ok {
110110
return nil
111111
}
112-
ch.oracleTxHandler(args.BlockTime, msg.Sender, msg.Height, msg.Data)
112+
ch.oracleTxHandler(args.BlockTime, msg.Sender, types.MustUint64ToInt64(msg.Height), msg.Data)
113113
return nil
114114
}

challenger/child/oracle.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
"go.uber.org/zap"
99
)
1010

11-
func (ch *Child) oracleTxHandler(blockTime time.Time, sender string, l1BlockHeight uint64, oracleDataBytes comettypes.Tx) {
11+
func (ch *Child) oracleTxHandler(blockTime time.Time, sender string, l1BlockHeight int64, oracleDataBytes comettypes.Tx) {
1212
checksum := challengertypes.OracleChecksum(oracleDataBytes)
1313
oracle := challengertypes.NewOracle(l1BlockHeight, checksum, blockTime)
1414
ch.eventQueue = append(ch.eventQueue, oracle)
1515
ch.lastUpdatedOracleL1Height = l1BlockHeight
1616

1717
ch.Logger().Info("update oracle",
18-
zap.Uint64("l1_blockHeight", l1BlockHeight),
18+
zap.Int64("l1_blockHeight", l1BlockHeight),
1919
zap.String("from", sender),
2020
)
2121
}

challenger/child/status.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99

1010
type Status struct {
1111
Node nodetypes.Status `json:"node"`
12-
LastUpdatedOracleL1Height uint64 `json:"last_updated_oracle_height"`
13-
LastFinalizedDepositL1BlockHeight uint64 `json:"last_finalized_deposit_l1_block_height"`
12+
LastUpdatedOracleL1Height int64 `json:"last_updated_oracle_height"`
13+
LastFinalizedDepositL1BlockHeight int64 `json:"last_finalized_deposit_l1_block_height"`
1414
LastFinalizedDepositL1Sequence uint64 `json:"last_finalized_deposit_l1_sequence"`
1515
LastWithdrawalL2Sequence uint64 `json:"last_withdrawal_l2_sequence"`
1616
WorkingTreeIndex uint64 `json:"working_tree_index"`
1717

18-
FinalizingBlockHeight uint64 `json:"finalizing_block_height"`
18+
FinalizingBlockHeight int64 `json:"finalizing_block_height"`
1919
LastOutputSubmissionTime time.Time `json:"last_output_submission_time"`
2020
NextOutputSubmissionTime time.Time `json:"next_output_submission_time"`
2121

challenger/child/withdraw.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ func (ch *Child) handleInitiateWithdrawal(l2Sequence uint64, from string, to str
7373
return nil
7474
}
7575

76-
func (ch *Child) prepareTree(blockHeight uint64) error {
76+
func (ch *Child) prepareTree(blockHeight int64) error {
7777
if ch.InitializeTree(blockHeight) {
7878
return nil
7979
}
8080

81-
err := ch.Merkle().LoadWorkingTree(blockHeight - 1)
81+
err := ch.Merkle().LoadWorkingTree(types.MustInt64ToUint64(blockHeight - 1))
8282
if err == dbtypes.ErrNotFound {
8383
// must not happened
8484
panic(fmt.Errorf("working tree not found at height: %d, current: %d", blockHeight-1, blockHeight))
@@ -110,12 +110,12 @@ func (ch *Child) prepareOutput(ctx context.Context) error {
110110
return err
111111
} else {
112112
ch.nextOutputTime = output.OutputProposal.L1BlockTime
113-
ch.finalizingBlockHeight = output.OutputProposal.L2BlockNumber
113+
ch.finalizingBlockHeight = types.MustUint64ToInt64(output.OutputProposal.L2BlockNumber)
114114
}
115115
return nil
116116
}
117117

118-
func (ch *Child) handleTree(blockHeight uint64, blockHeader cmtproto.Header) (kvs []types.RawKV, storageRoot []byte, err error) {
118+
func (ch *Child) handleTree(blockHeight int64, blockHeader cmtproto.Header) (kvs []types.RawKV, storageRoot []byte, err error) {
119119
// panic if we passed the finalizing block height
120120
// this must not happened
121121
if ch.finalizingBlockHeight != 0 && ch.finalizingBlockHeight < blockHeight {
@@ -130,7 +130,7 @@ func (ch *Child) handleTree(blockHeight uint64, blockHeader cmtproto.Header) (kv
130130

131131
ch.Logger().Info("finalize working tree",
132132
zap.Uint64("tree_index", ch.Merkle().GetWorkingTreeIndex()),
133-
zap.Uint64("height", blockHeight),
133+
zap.Int64("height", blockHeight),
134134
zap.Uint64("num_leaves", ch.Merkle().GetWorkingTreeLeafCount()),
135135
zap.String("storage_root", base64.StdEncoding.EncodeToString(storageRoot)),
136136
)
@@ -139,15 +139,15 @@ func (ch *Child) handleTree(blockHeight uint64, blockHeader cmtproto.Header) (kv
139139
ch.lastOutputTime = blockHeader.Time
140140
}
141141

142-
err = ch.Merkle().SaveWorkingTree(blockHeight)
142+
err = ch.Merkle().SaveWorkingTree(types.MustInt64ToUint64(blockHeight))
143143
if err != nil {
144144
return nil, nil, err
145145
}
146146

147147
return kvs, storageRoot, nil
148148
}
149149

150-
func (ch *Child) handleOutput(blockTime time.Time, blockHeight uint64, version uint8, blockId []byte, outputIndex uint64, storageRoot []byte) error {
150+
func (ch *Child) handleOutput(blockTime time.Time, blockHeight int64, version uint8, blockId []byte, outputIndex uint64, storageRoot []byte) error {
151151
outputRoot := ophosttypes.GenerateOutputRoot(version, storageRoot, blockId)
152152
output := challengertypes.NewOutput(blockHeight, outputIndex, outputRoot[:], blockTime)
153153

challenger/host/deposit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (h *Host) initiateDepositHandler(_ context.Context, args nodetypes.EventHan
3838

3939
func (h *Host) handleInitiateDeposit(
4040
l1Sequence uint64,
41-
blockHeight uint64,
41+
blockHeight int64,
4242
blockTime time.Time,
4343
from string,
4444
to string,

challenger/host/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (h *Host) beginBlockHandler(_ context.Context, args nodetypes.BeginBlockArg
1515
}
1616

1717
func (h *Host) endBlockHandler(_ context.Context, args nodetypes.EndBlockArgs) error {
18-
blockHeight := uint64(args.Block.Header.Height)
18+
blockHeight := args.Block.Header.Height
1919
batchKVs := []types.RawKV{
2020
h.Node().SyncInfoToRawKV(blockHeight),
2121
}

challenger/host/host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func NewHostV1(
5555
}
5656
}
5757

58-
func (h *Host) Initialize(ctx context.Context, startHeight uint64, child childNode, bridgeInfo opchildtypes.BridgeInfo, challenger challenger) error {
58+
func (h *Host) Initialize(ctx context.Context, startHeight int64, child childNode, bridgeInfo opchildtypes.BridgeInfo, challenger challenger) error {
5959
err := h.BaseHost.Initialize(ctx, startHeight, bridgeInfo)
6060
if err != nil {
6161
return err

challenger/host/oracle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
challengertypes "github.com/initia-labs/opinit-bots/challenger/types"
99
)
1010

11-
func (h *Host) oracleTxHandler(blockHeight uint64, blockTime time.Time, oracleDataBytes comettypes.Tx) {
11+
func (h *Host) oracleTxHandler(blockHeight int64, blockTime time.Time, oracleDataBytes comettypes.Tx) {
1212
if !h.OracleEnabled() {
1313
return
1414
}

challenger/host/output.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (h *Host) proposeOutputHandler(_ context.Context, args nodetypes.EventHandl
2424
return h.handleProposeOutput(bridgeId, proposer, outputIndex, l2BlockNumber, outputRoot, args.BlockTime)
2525
}
2626

27-
func (h *Host) handleProposeOutput(bridgeId uint64, proposer string, outputIndex uint64, l2BlockNumber uint64, outputRoot []byte, blockTime time.Time) error {
27+
func (h *Host) handleProposeOutput(bridgeId uint64, proposer string, outputIndex uint64, l2BlockNumber int64, outputRoot []byte, blockTime time.Time) error {
2828
output := challengertypes.NewOutput(l2BlockNumber, outputIndex, outputRoot[:], blockTime)
2929

3030
h.lastOutputIndex = outputIndex
@@ -36,7 +36,7 @@ func (h *Host) handleProposeOutput(bridgeId uint64, proposer string, outputIndex
3636
zap.Uint64("bridge_id", bridgeId),
3737
zap.String("proposer", proposer),
3838
zap.Uint64("output_index", outputIndex),
39-
zap.Uint64("l2_block_number", l2BlockNumber),
39+
zap.Int64("l2_block_number", l2BlockNumber),
4040
zap.String("output_root", base64.StdEncoding.EncodeToString(outputRoot)),
4141
)
4242
return nil

challenger/types/challenge.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"encoding/json"
77
"fmt"
88
"time"
9+
10+
"github.com/initia-labs/opinit-bots/types"
911
)
1012

1113
type Challenge struct {
@@ -94,7 +96,7 @@ func (e EventType) String() string {
9496
type Deposit struct {
9597
EventType string `json:"event_type"`
9698
Sequence uint64 `json:"sequence"`
97-
L1BlockHeight uint64 `json:"l1_block_height"`
99+
L1BlockHeight int64 `json:"l1_block_height"`
98100
From string `json:"from"`
99101
To string `json:"to"`
100102
L1Denom string `json:"l1_denom"`
@@ -105,7 +107,7 @@ type Deposit struct {
105107

106108
var _ ChallengeEvent = &Deposit{}
107109

108-
func NewDeposit(sequence, l1BlockHeight uint64, from, to, l1Denom, amount string, time time.Time) *Deposit {
110+
func NewDeposit(sequence uint64, l1BlockHeight int64, from, to, l1Denom, amount string, time time.Time) *Deposit {
109111
d := &Deposit{
110112
Sequence: sequence,
111113
L1BlockHeight: l1BlockHeight,
@@ -169,7 +171,7 @@ func (d Deposit) IsTimeout() bool {
169171

170172
type Output struct {
171173
EventType string `json:"event_type"`
172-
L2BlockNumber uint64 `json:"l2_block_number"`
174+
L2BlockNumber int64 `json:"l2_block_number"`
173175
OutputIndex uint64 `json:"output_index"`
174176
OutputRoot []byte `json:"output_root"`
175177
Time time.Time `json:"time"`
@@ -178,7 +180,7 @@ type Output struct {
178180

179181
var _ ChallengeEvent = &Output{}
180182

181-
func NewOutput(l2BlockNumber, outputIndex uint64, outputRoot []byte, time time.Time) *Output {
183+
func NewOutput(l2BlockNumber int64, outputIndex uint64, outputRoot []byte, time time.Time) *Output {
182184
o := &Output{
183185
L2BlockNumber: l2BlockNumber,
184186
OutputIndex: outputIndex,
@@ -235,13 +237,13 @@ func (o Output) IsTimeout() bool {
235237

236238
type Oracle struct {
237239
EventType string `json:"event_type"`
238-
L1Height uint64 `json:"l1_height"`
240+
L1Height int64 `json:"l1_height"`
239241
Data []byte `json:"data"`
240242
Time time.Time `json:"time"`
241243
Timeout bool `json:"timeout"`
242244
}
243245

244-
func NewOracle(l1Height uint64, data []byte, time time.Time) *Oracle {
246+
func NewOracle(l1Height int64, data []byte, time time.Time) *Oracle {
245247
o := &Oracle{
246248
L1Height: l1Height,
247249
Data: data,
@@ -283,7 +285,7 @@ func (o Oracle) EventTime() time.Time {
283285
func (o Oracle) Id() ChallengeId {
284286
return ChallengeId{
285287
Type: EventTypeOracle,
286-
Id: o.L1Height,
288+
Id: types.MustInt64ToUint64(o.L1Height),
287289
}
288290
}
289291

challenger/types/keys.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"time"
55

66
dbtypes "github.com/initia-labs/opinit-bots/db/types"
7+
"github.com/initia-labs/opinit-bots/types"
78
"github.com/pkg/errors"
89
)
910

@@ -34,7 +35,7 @@ func PrefixedPendingChallenge(id ChallengeId) []byte {
3435
}
3536

3637
func PrefixedTimeEventTypeId(eventTime time.Time, id ChallengeId) []byte {
37-
return append(append(dbtypes.FromUint64Key(uint64(eventTime.UnixNano())), dbtypes.Splitter),
38+
return append(append(dbtypes.FromUint64Key(types.MustInt64ToUint64(eventTime.UnixNano())), dbtypes.Splitter),
3839
PrefixedEventTypeId(id.Type, id.Id)...)
3940
}
4041

client/client.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,6 @@ func New(remote, wsEndpoint string) (*HTTP, error) {
120120
return NewWithClient(remote, wsEndpoint, httpClient)
121121
}
122122

123-
// Create timeout enabled http client
124-
func NewWithTimeout(remote, wsEndpoint string, timeout uint) (*HTTP, error) {
125-
httpClient, err := jsonrpcclient.DefaultHTTPClient(remote)
126-
if err != nil {
127-
return nil, err
128-
}
129-
httpClient.Timeout = time.Duration(timeout) * time.Second
130-
return NewWithClient(remote, wsEndpoint, httpClient)
131-
}
132-
133123
// NewWithClient allows for setting a custom http client (See New).
134124
// An error is returned on invalid remote. The function panics when remote is nil.
135125
func NewWithClient(remote, wsEndpoint string, client *http.Client) (*HTTP, error) {
@@ -421,7 +411,7 @@ func (c *baseRPCClient) Block(ctx context.Context, height *int64) (*ctypes.Resul
421411
return result, nil
422412
}
423413

424-
func (c *baseRPCClient) BlockBulk(ctx context.Context, start *uint64, end *uint64) ([][]byte, error) {
414+
func (c *baseRPCClient) BlockBulk(ctx context.Context, start *int64, end *int64) ([][]byte, error) {
425415
result := new(ResultBlockBulk)
426416
params := make(map[string]interface{})
427417
if start != nil {

db/types/utils.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ func FromInt64(v int64) []byte {
1212
return []byte(fmt.Sprintf("%d", v))
1313
}
1414

15-
func ToInt64(v []byte) int64 {
15+
func ToInt64(v []byte) (int64, error) {
1616
data, err := strconv.ParseInt(string(v), 10, 64)
1717
if err != nil {
18-
// must not happen
19-
panic(err)
18+
return 0, fmt.Errorf("failed to parse uint64 from %s: %w", string(v), err)
2019
}
21-
return data
20+
return data, nil
2221
}
2322

2423
func FromUint64(v uint64) []byte {

executor/batch/batch.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type BatchSubmitter struct {
5252
homePath string
5353

5454
// status info
55-
LastBatchEndBlockNumber uint64
55+
LastBatchEndBlockNumber int64
5656
}
5757

5858
func NewBatchSubmitterV1(
@@ -96,7 +96,7 @@ func NewBatchSubmitterV1(
9696
return ch
9797
}
9898

99-
func (bs *BatchSubmitter) Initialize(ctx context.Context, startHeight uint64, host hostNode, bridgeInfo opchildtypes.BridgeInfo) error {
99+
func (bs *BatchSubmitter) Initialize(ctx context.Context, startHeight int64, host hostNode, bridgeInfo opchildtypes.BridgeInfo) error {
100100
err := bs.node.Initialize(ctx, startHeight)
101101
if err != nil {
102102
return err
@@ -113,7 +113,7 @@ func (bs *BatchSubmitter) Initialize(ctx context.Context, startHeight uint64, ho
113113
return errors.New("no batch info")
114114
}
115115
for _, batchInfo := range bs.batchInfos {
116-
if len(bs.batchInfos) == 1 || (batchInfo.Output.L2BlockNumber+1) >= bs.node.GetHeight() {
116+
if len(bs.batchInfos) == 1 || types.MustUint64ToInt64(batchInfo.Output.L2BlockNumber+1) >= bs.node.GetHeight() {
117117
break
118118
}
119119
bs.DequeueBatchInfo()
@@ -164,7 +164,7 @@ func (bs *BatchSubmitter) SetDANode(da executortypes.DANode) error {
164164
}
165165

166166
func (bs *BatchSubmitter) Start(ctx context.Context) {
167-
bs.logger.Info("batch start", zap.Uint64("height", bs.node.GetHeight()))
167+
bs.logger.Info("batch start", zap.Int64("height", bs.node.GetHeight()))
168168
bs.node.Start(ctx)
169169
}
170170

0 commit comments

Comments
 (0)