Skip to content

Commit 6d172f2

Browse files
committed
add UTC to all time.Unix interface
1 parent 6194495 commit 6d172f2

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

challenger/types/keys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ func ParseChallenge(key []byte) (time.Time, ChallengeId, error) {
7171
typeBz := key[cursor : cursor+1]
7272
cursor += 1 + 1 // u8 + splitter
7373
idBz := key[cursor:]
74-
return time.Unix(0, types.MustUint64ToInt64(dbtypes.ToUint64Key(timeBz))), ChallengeId{Type: EventType(typeBz[0]), Id: dbtypes.ToUint64Key(idBz)}, nil
74+
return time.Unix(0, types.MustUint64ToInt64(dbtypes.ToUint64Key(timeBz))).UTC(), ChallengeId{Type: EventType(typeBz[0]), Id: dbtypes.ToUint64Key(idBz)}, nil
7575
}

executor/batchsubmitter/batch_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestPrepareBatch(t *testing.T) {
7474
existingLocalBatchInfo: executortypes.LocalBatchInfo{
7575
Start: 1,
7676
End: 100,
77-
LastSubmissionTime: time.Unix(0, 10000),
77+
LastSubmissionTime: time.Unix(0, 10000).UTC(),
7878
BatchSize: 100,
7979
},
8080
batchInfoQueue: []ophosttypes.BatchInfoWithOutput{
@@ -89,7 +89,7 @@ func TestPrepareBatch(t *testing.T) {
8989
expectedLocalBatchInfo: executortypes.LocalBatchInfo{
9090
Start: 101,
9191
End: 0,
92-
LastSubmissionTime: time.Unix(0, 10000),
92+
LastSubmissionTime: time.Unix(0, 10000).UTC(),
9393
BatchSize: 0,
9494
},
9595
expectedChanges: []types.KV{},
@@ -546,7 +546,7 @@ func TestCheckBatch(t *testing.T) {
546546
name: "block time >= last submission time + 2/3 interval, block height == latest height",
547547
localBatchInfo: &executortypes.LocalBatchInfo{
548548
Start: 1,
549-
LastSubmissionTime: time.Unix(0, 0),
549+
LastSubmissionTime: time.Unix(0, 0).UTC(),
550550
},
551551
batchConfig: executortypes.BatchConfig{
552552
MaxChunks: 100,
@@ -555,7 +555,7 @@ func TestCheckBatch(t *testing.T) {
555555
},
556556
blockHeight: 10,
557557
latestHeight: 10,
558-
blockTime: time.Unix(0, 10001),
558+
blockTime: time.Unix(0, 10001).UTC(),
559559
expected: true,
560560
},
561561
{
@@ -571,14 +571,14 @@ func TestCheckBatch(t *testing.T) {
571571
},
572572
blockHeight: 10,
573573
latestHeight: 20,
574-
blockTime: time.Unix(0, 10001),
574+
blockTime: time.Unix(0, 10001).UTC(),
575575
expected: false,
576576
},
577577
{
578578
name: "block time < last submission time + 2/3 interval, block height == latest height",
579579
localBatchInfo: &executortypes.LocalBatchInfo{
580580
Start: 1,
581-
LastSubmissionTime: time.Unix(0, 10000),
581+
LastSubmissionTime: time.Unix(0, 10000).UTC(),
582582
},
583583
batchConfig: executortypes.BatchConfig{
584584
MaxChunks: 100,
@@ -587,14 +587,14 @@ func TestCheckBatch(t *testing.T) {
587587
},
588588
blockHeight: 10,
589589
latestHeight: 10,
590-
blockTime: time.Unix(0, 10001),
590+
blockTime: time.Unix(0, 10001).UTC(),
591591
expected: false,
592592
},
593593
{
594594
name: "block time > last submission time + max submission time, block height == latest height",
595595
localBatchInfo: &executortypes.LocalBatchInfo{
596596
Start: 1,
597-
LastSubmissionTime: time.Unix(0, 0),
597+
LastSubmissionTime: time.Unix(0, 0).UTC(),
598598
},
599599
batchConfig: executortypes.BatchConfig{
600600
MaxChunks: 100,
@@ -603,14 +603,14 @@ func TestCheckBatch(t *testing.T) {
603603
},
604604
blockHeight: 10,
605605
latestHeight: 10,
606-
blockTime: time.Unix(0, 1000*1000*1000+1),
606+
blockTime: time.Unix(0, 1000*1000*1000+1).UTC(),
607607
expected: true,
608608
},
609609
{
610610
name: "block time > last submission time + max submission time, block height != latest height",
611611
localBatchInfo: &executortypes.LocalBatchInfo{
612612
Start: 1,
613-
LastSubmissionTime: time.Unix(0, 0),
613+
LastSubmissionTime: time.Unix(0, 0).UTC(),
614614
},
615615
batchConfig: executortypes.BatchConfig{
616616
MaxChunks: 100,
@@ -619,14 +619,14 @@ func TestCheckBatch(t *testing.T) {
619619
},
620620
blockHeight: 10,
621621
latestHeight: 20,
622-
blockTime: time.Unix(0, 1000*1000*1000+1),
622+
blockTime: time.Unix(0, 1000*1000*1000+1).UTC(),
623623
expected: false,
624624
},
625625
{
626626
name: "block time < last submission time + max submission time, block height == latest height",
627627
localBatchInfo: &executortypes.LocalBatchInfo{
628628
Start: 1,
629-
LastSubmissionTime: time.Unix(0, 0),
629+
LastSubmissionTime: time.Unix(0, 0).UTC(),
630630
},
631631
batchConfig: executortypes.BatchConfig{
632632
MaxChunks: 100,
@@ -635,14 +635,14 @@ func TestCheckBatch(t *testing.T) {
635635
},
636636
blockHeight: 10,
637637
latestHeight: 10,
638-
blockTime: time.Unix(0, 1000*1000*1000),
638+
blockTime: time.Unix(0, 1000*1000*1000).UTC(),
639639
expected: true,
640640
},
641641
{
642642
name: "batch size >= (max chunks - 1) * max chunk size",
643643
localBatchInfo: &executortypes.LocalBatchInfo{
644644
Start: 1,
645-
LastSubmissionTime: time.Unix(0, 0),
645+
LastSubmissionTime: time.Unix(0, 0).UTC(),
646646
BatchSize: 1000,
647647
},
648648
batchConfig: executortypes.BatchConfig{
@@ -652,7 +652,7 @@ func TestCheckBatch(t *testing.T) {
652652
},
653653
blockHeight: 10,
654654
latestHeight: 20,
655-
blockTime: time.Unix(0, 500),
655+
blockTime: time.Unix(0, 500).UTC(),
656656
expected: true,
657657
},
658658
{
@@ -669,7 +669,7 @@ func TestCheckBatch(t *testing.T) {
669669
},
670670
blockHeight: 10,
671671
latestHeight: 20,
672-
blockTime: time.Unix(0, 500),
672+
blockTime: time.Unix(0, 500).UTC(),
673673
expected: false,
674674
},
675675
}

executor/batchsubmitter/handler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestRawBlockHandler(t *testing.T) {
106106
pbb := &cmtproto.Block{
107107
Header: cmtproto.Header{
108108
Height: 1,
109-
Time: time.Unix(0, 10),
109+
Time: time.Unix(0, 10).UTC(),
110110
},
111111
Data: cmtproto.Data{
112112
Txs: [][]byte{},
@@ -127,7 +127,7 @@ func TestRawBlockHandler(t *testing.T) {
127127
err = SaveLocalBatchInfo(batchDB, executortypes.LocalBatchInfo{
128128
Start: 1,
129129
End: 0,
130-
LastSubmissionTime: time.Unix(0, 0),
130+
LastSubmissionTime: time.Unix(0, 0).UTC(),
131131
})
132132
require.NoError(t, err)
133133

@@ -147,7 +147,7 @@ func TestRawBlockHandler(t *testing.T) {
147147
require.Equal(t, executortypes.LocalBatchInfo{
148148
Start: 1,
149149
End: 0,
150-
LastSubmissionTime: time.Unix(0, 0),
150+
LastSubmissionTime: time.Unix(0, 0).UTC(),
151151
BatchSize: localBatchInfo.BatchSize,
152152
}, localBatchInfo)
153153

@@ -156,7 +156,7 @@ func TestRawBlockHandler(t *testing.T) {
156156
pbb = &cmtproto.Block{
157157
Header: cmtproto.Header{
158158
Height: 2,
159-
Time: time.Unix(0, 110),
159+
Time: time.Unix(0, 110).UTC(),
160160
},
161161
Data: cmtproto.Data{
162162
Txs: [][]byte{},

executor/child/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func TestEndBlockHandler(t *testing.T) {
221221

222222
childdb := basedb.WithPrefix([]byte("test_child"))
223223
childNode := node.NewTestNode(nodetypes.NodeConfig{}, childdb, nil, nil, nil, nil)
224-
stage := childdb.NewStage().(*db.Stage)
224+
stage := childdb.NewStage().(db.Stage)
225225
mk, err := merkle.NewMerkle(ophosttypes.GenerateNodeHash)
226226
require.NoError(t, err)
227227
err = mk.PrepareWorkingTree(merkletypes.TreeInfo{

executor/child/withdraw_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestInitiateWithdrawalHandler(t *testing.T) {
8888
},
8989
eventHandlerArgs: nodetypes.EventHandlerArgs{
9090
BlockHeight: 11,
91-
BlockTime: time.Unix(0, 10000),
91+
BlockTime: time.Unix(0, 10000).UTC(),
9292
Tx: []byte("txbytes"), // EA58654919E6F3E08370DE723D8DA223F1DFE78DD28D0A23E6F18BFA0815BB99
9393
EventAttributes: InitiateWithdrawalEvents("from", "to", "denom", "uinit", sdk.NewInt64Coin("uinit", 10000), 1),
9494
},
@@ -137,7 +137,7 @@ func TestInitiateWithdrawalHandler(t *testing.T) {
137137
},
138138
eventHandlerArgs: nodetypes.EventHandlerArgs{
139139
BlockHeight: 11,
140-
BlockTime: time.Unix(0, 10000),
140+
BlockTime: time.Unix(0, 10000).UTC(),
141141
Tx: []byte("txbytes"),
142142
EventAttributes: InitiateWithdrawalEvents("from", "to", "denom", "uinit", sdk.NewInt64Coin("uinit", 10000), 101),
143143
},
@@ -188,7 +188,7 @@ func TestInitiateWithdrawalHandler(t *testing.T) {
188188
},
189189
eventHandlerArgs: nodetypes.EventHandlerArgs{
190190
BlockHeight: 10,
191-
BlockTime: time.Unix(0, 10000),
191+
BlockTime: time.Unix(0, 10000).UTC(),
192192
Tx: []byte("txbytes"),
193193
EventAttributes: InitiateWithdrawalEvents("from", "to", "denom", "uinit", sdk.NewInt64Coin("uinit", 10000), 101),
194194
},
@@ -258,7 +258,7 @@ func TestInitiateWithdrawalHandler(t *testing.T) {
258258
err = mk.PrepareWorkingTree(tc.lastWorkingTree)
259259
require.NoError(t, err)
260260

261-
stage := childdb.NewStage().(*db.Stage)
261+
stage := childdb.NewStage().(db.Stage)
262262
ch := Child{
263263
BaseChild: childprovider.NewTestBaseChild(0, childNode, mk, bridgeInfo, nil, nodetypes.NodeConfig{}),
264264
stage: stage,
@@ -529,7 +529,7 @@ func TestPrepareOutput(t *testing.T) {
529529
},
530530
hostOutputs: map[uint64]ophosttypes.Output{
531531
1: {
532-
L1BlockTime: time.Unix(0, 10000),
532+
L1BlockTime: time.Unix(0, 10000).UTC(),
533533
L2BlockNumber: 10,
534534
},
535535
},
@@ -542,7 +542,7 @@ func TestPrepareOutput(t *testing.T) {
542542
Done: false,
543543
},
544544
expected: func() (lastOutputTime time.Time, nextOutputTime time.Time, finalizingBlockHeight int64) {
545-
return time.Unix(0, 10000), time.Unix(0, 10200), 0
545+
return time.Unix(0, 10000).UTC(), time.Unix(0, 10200).UTC(), 0
546546
},
547547
err: false,
548548
},
@@ -613,7 +613,7 @@ func TestHandleTree(t *testing.T) {
613613
blockHeight: 5,
614614
latestHeight: 5,
615615
blockHeader: cmtproto.Header{
616-
Time: time.Unix(0, 10100),
616+
Time: time.Unix(0, 10100).UTC(),
617617
},
618618
lastWorkingTree: merkletypes.TreeInfo{
619619
Version: 4,
@@ -624,12 +624,12 @@ func TestHandleTree(t *testing.T) {
624624
Done: false,
625625
},
626626
lastOutputTime: time.Time{},
627-
nextOutputTime: time.Unix(0, 10000),
627+
nextOutputTime: time.Unix(0, 10000).UTC(),
628628
finalizingBlockHeight: 0,
629629

630630
expected: func() (storageRoot []byte, lastOutputTime time.Time, nextOutputTime time.Time, finalizingBlockHeight int64) {
631631
return []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
632-
time.Unix(0, 10100), time.Unix(0, 10300), 0
632+
time.Unix(0, 10100).UTC(), time.Unix(0, 10300).UTC(), 0
633633
},
634634
expectedStage: []types.KV{
635635
{
@@ -645,7 +645,7 @@ func TestHandleTree(t *testing.T) {
645645
blockHeight: 5,
646646
latestHeight: 5,
647647
blockHeader: cmtproto.Header{
648-
Time: time.Unix(0, 10100),
648+
Time: time.Unix(0, 10100).UTC(),
649649
},
650650
lastWorkingTree: merkletypes.TreeInfo{
651651
Version: 4,
@@ -659,12 +659,12 @@ func TestHandleTree(t *testing.T) {
659659
Done: false,
660660
},
661661
lastOutputTime: time.Time{},
662-
nextOutputTime: time.Unix(0, 10000),
662+
nextOutputTime: time.Unix(0, 10000).UTC(),
663663
finalizingBlockHeight: 0,
664664

665665
expected: func() (storageRoot []byte, lastOutputTime time.Time, nextOutputTime time.Time, finalizingBlockHeight int64) {
666666
return []byte{0x50, 0x26, 0x55, 0x2e, 0x7b, 0x21, 0xca, 0xb5, 0x27, 0xe4, 0x16, 0x9e, 0x66, 0x46, 0x02, 0xb8, 0x5d, 0x03, 0x67, 0x0b, 0xb5, 0x57, 0xe3, 0x29, 0x18, 0xd9, 0x33, 0xe3, 0xd5, 0x92, 0x5c, 0x7e},
667-
time.Unix(0, 10100), time.Unix(0, 10300), 0
667+
time.Unix(0, 10100).UTC(), time.Unix(0, 10300).UTC(), 0
668668
},
669669
expectedStage: []types.KV{
670670
{
@@ -684,7 +684,7 @@ func TestHandleTree(t *testing.T) {
684684
blockHeight: 5,
685685
latestHeight: 5,
686686
blockHeader: cmtproto.Header{
687-
Time: time.Unix(0, 10100),
687+
Time: time.Unix(0, 10100).UTC(),
688688
},
689689
lastWorkingTree: merkletypes.TreeInfo{
690690
Version: 4,
@@ -698,12 +698,12 @@ func TestHandleTree(t *testing.T) {
698698
Done: false,
699699
},
700700
lastOutputTime: time.Time{},
701-
nextOutputTime: time.Unix(0, 10000),
701+
nextOutputTime: time.Unix(0, 10000).UTC(),
702702
finalizingBlockHeight: 0,
703703

704704
expected: func() (storageRoot []byte, lastOutputTime time.Time, nextOutputTime time.Time, finalizingBlockHeight int64) {
705705
return []byte{0xff, 0xd4, 0x7a, 0x71, 0xf6, 0x3a, 0x8a, 0x50, 0x09, 0x56, 0xef, 0x34, 0xb1, 0xfa, 0xbb, 0xd4, 0x2f, 0x07, 0xc8, 0x5e, 0x77, 0xf7, 0xad, 0x21, 0x27, 0x01, 0xe0, 0x64, 0xda, 0xbd, 0xf6, 0xa3},
706-
time.Unix(0, 10100), time.Unix(0, 10300), 0
706+
time.Unix(0, 10100).UTC(), time.Unix(0, 10300).UTC(), 0
707707
},
708708
expectedStage: []types.KV{
709709
{
@@ -735,7 +735,7 @@ func TestHandleTree(t *testing.T) {
735735
blockHeight: 10,
736736
latestHeight: 10,
737737
blockHeader: cmtproto.Header{
738-
Time: time.Unix(0, 10100),
738+
Time: time.Unix(0, 10100).UTC(),
739739
},
740740
lastWorkingTree: merkletypes.TreeInfo{
741741
Version: 9,
@@ -757,7 +757,7 @@ func TestHandleTree(t *testing.T) {
757757
blockHeight: 5,
758758
latestHeight: 5,
759759
blockHeader: cmtproto.Header{
760-
Time: time.Unix(0, 9900),
760+
Time: time.Unix(0, 9900).UTC(),
761761
},
762762
lastWorkingTree: merkletypes.TreeInfo{
763763
Version: 4,
@@ -771,7 +771,7 @@ func TestHandleTree(t *testing.T) {
771771
Done: false,
772772
},
773773
lastOutputTime: time.Time{},
774-
nextOutputTime: time.Unix(0, 10000),
774+
nextOutputTime: time.Unix(0, 10000).UTC(),
775775
finalizingBlockHeight: 0,
776776

777777
expected: nil,
@@ -789,7 +789,7 @@ func TestHandleTree(t *testing.T) {
789789
blockHeight: 5,
790790
latestHeight: 6,
791791
blockHeader: cmtproto.Header{
792-
Time: time.Unix(0, 9900),
792+
Time: time.Unix(0, 9900).UTC(),
793793
},
794794
lastWorkingTree: merkletypes.TreeInfo{
795795
Version: 4,
@@ -803,7 +803,7 @@ func TestHandleTree(t *testing.T) {
803803
Done: false,
804804
},
805805
lastOutputTime: time.Time{},
806-
nextOutputTime: time.Unix(0, 10000),
806+
nextOutputTime: time.Unix(0, 10000).UTC(),
807807
finalizingBlockHeight: 0,
808808

809809
expected: nil,
@@ -831,7 +831,7 @@ func TestHandleTree(t *testing.T) {
831831
err = mk.PrepareWorkingTree(tc.lastWorkingTree)
832832
require.NoError(t, err)
833833

834-
stage := childdb.NewStage().(*db.Stage)
834+
stage := childdb.NewStage().(db.Stage)
835835
ch := Child{
836836
BaseChild: childprovider.NewTestBaseChild(0, childNode, mk, bridgeInfo, nil, nodetypes.NodeConfig{}),
837837
stage: stage,

node/broadcaster/broadcaster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (b *Broadcaster) loadPendingTxs(ctx types.Context, stage types.BasicDB, las
146146
return nil
147147
}
148148

149-
pendingTxTime := time.Unix(0, pendingTxs[0].Timestamp)
149+
pendingTxTime := time.Unix(0, pendingTxs[0].Timestamp).UTC()
150150
// if we have pending txs, wait until timeout
151151
if timeoutTime := pendingTxTime.Add(b.cfg.TxTimeout); lastBlockTime.Before(timeoutTime) {
152152
waitingTime := timeoutTime.Sub(lastBlockTime)

node/broadcaster/process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (b *Broadcaster) CheckPendingTx(ctx types.Context, pendingTx btypes.Pending
3131
if txerr != nil && IsTxNotFoundErr(txerr, pendingTx.TxHash) {
3232
// if the tx is not found, it means the tx is not processed yet
3333
// or the tx is not indexed by the node in rare cases.
34-
pendingTxTime := time.Unix(0, pendingTx.Timestamp)
34+
pendingTxTime := time.Unix(0, pendingTx.Timestamp).UTC()
3535

3636
lastHeader, err := b.rpcClient.Header(ctx, nil)
3737
if err != nil {

0 commit comments

Comments
 (0)