Skip to content

Commit c74991d

Browse files
committed
use TimestampedUnixBig instead of TimestampedBig
1 parent 7b5d0e2 commit c74991d

File tree

7 files changed

+84
-86
lines changed

7 files changed

+84
-86
lines changed

pkg/loop/internal/pb/ccipocr3/chainaccessor.pb.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/loop/internal/pb/ccipocr3/chainaccessor.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ message GetFeeQuoterTokenUpdatesRequest {
372372
}
373373

374374
message GetFeeQuoterTokenUpdatesResponse {
375-
map<string, TimestampedBig> token_updates = 1; // key is UnknownEncodedAddress
375+
map<string, TimestampedUnixBig> token_updates = 1; // key is UnknownEncodedAddress
376376
}
377377

378378
// Helper message types

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/chainaccessor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func (c *chainAccessorClient) GetFeedPricesUSD(ctx context.Context, tokens []cci
317317
return pbToTokenPriceMap(resp.Prices), nil
318318
}
319319

320-
func (c *chainAccessorClient) GetFeeQuoterTokenUpdates(ctx context.Context, tokens []ccipocr3.UnknownEncodedAddress, chain ccipocr3.ChainSelector) (map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig, error) {
320+
func (c *chainAccessorClient) GetFeeQuoterTokenUpdates(ctx context.Context, tokens []ccipocr3.UnknownEncodedAddress, chain ccipocr3.ChainSelector) (map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig, error) {
321321
var tokenStrs []string
322322
for _, token := range tokens {
323323
tokenStrs = append(tokenStrs, string(token))
@@ -330,7 +330,7 @@ func (c *chainAccessorClient) GetFeeQuoterTokenUpdates(ctx context.Context, toke
330330
if err != nil {
331331
return nil, err
332332
}
333-
return pbToTokenUpdates(resp.TokenUpdates), nil
333+
return pbToTokenUpdatesUnix(resp.TokenUpdates), nil
334334
}
335335

336336
// Server implementation
@@ -657,6 +657,6 @@ func (s *chainAccessorServer) GetFeeQuoterTokenUpdates(ctx context.Context, req
657657
}
658658

659659
return &ccipocr3pb.GetFeeQuoterTokenUpdatesResponse{
660-
TokenUpdates: tokenUpdatesToPb(updates),
660+
TokenUpdates: tokenUpdatesUnixToPb(updates),
661661
}, nil
662662
}

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/convert.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package ccipocr3
33
import (
44
"fmt"
55
"math/big"
6-
"time"
7-
8-
"google.golang.org/protobuf/types/known/timestamppb"
96

107
ccipocr3pb "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb/ccipocr3"
118
"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
@@ -790,9 +787,9 @@ func pbToMessageTokenIDMap(pbTokens map[string]*ccipocr3pb.RampTokenAmount) (map
790787

791788
tokenID := ccipocr3.NewMessageTokenID(ccipocr3.SeqNum(seqNr), index)
792789
result[tokenID] = ccipocr3.RampTokenAmount{
793-
SourcePoolAddress: ccipocr3.UnknownAddress(pbAmount.SourcePoolAddress),
794-
DestTokenAddress: ccipocr3.UnknownAddress(pbAmount.DestTokenAddress),
795-
ExtraData: ccipocr3.Bytes(pbAmount.ExtraData),
790+
SourcePoolAddress: pbAmount.SourcePoolAddress,
791+
DestTokenAddress: pbAmount.DestTokenAddress,
792+
ExtraData: pbAmount.ExtraData,
796793
Amount: pbToBigIntPreservingZero(pbAmount.Amount),
797794
}
798795
}
@@ -845,33 +842,35 @@ func messagesByTokenIDToPb(messages map[ccipocr3.MessageTokenID]ccipocr3.Bytes)
845842
return result
846843
}
847844

848-
func pbToTokenUpdates(pbUpdates map[string]*ccipocr3pb.TimestampedBig) map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig {
845+
func pbToTokenUpdatesUnix(pbUpdates map[string]*ccipocr3pb.TimestampedUnixBig) map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig {
849846
if pbUpdates == nil {
850847
return nil
851848
}
852-
result := make(map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig)
849+
result := make(map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig)
853850
for token, pbUpdate := range pbUpdates {
854-
var timestamp time.Time
855-
if pbUpdate.Timestamp != nil {
856-
timestamp = pbUpdate.Timestamp.AsTime()
851+
var value *big.Int
852+
if pbUpdate.Value != nil && len(pbUpdate.Value.Value) > 0 {
853+
value = new(big.Int).SetBytes(pbUpdate.Value.Value)
854+
} else {
855+
value = big.NewInt(0)
857856
}
858-
result[ccipocr3.UnknownEncodedAddress(token)] = ccipocr3.TimestampedBig{
859-
Timestamp: timestamp,
860-
Value: pbToBigIntPreservingZero(pbUpdate.Value),
857+
result[ccipocr3.UnknownEncodedAddress(token)] = ccipocr3.TimestampedUnixBig{
858+
Timestamp: pbUpdate.Timestamp,
859+
Value: value,
861860
}
862861
}
863862
return result
864863
}
865864

866-
func tokenUpdatesToPb(updates map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig) map[string]*ccipocr3pb.TimestampedBig {
865+
func tokenUpdatesUnixToPb(updates map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig) map[string]*ccipocr3pb.TimestampedUnixBig {
867866
if updates == nil {
868867
return nil
869868
}
870-
result := make(map[string]*ccipocr3pb.TimestampedBig)
869+
result := make(map[string]*ccipocr3pb.TimestampedUnixBig)
871870
for token, update := range updates {
872-
result[string(token)] = &ccipocr3pb.TimestampedBig{
873-
Timestamp: timestamppb.New(update.Timestamp),
874-
Value: intToPbBigInt(update.Value.Int),
871+
result[string(token)] = &ccipocr3pb.TimestampedUnixBig{
872+
Timestamp: update.Timestamp,
873+
Value: intToPbBigInt(update.Value),
875874
}
876875
}
877876
return result

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/convert_test.go

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -951,52 +951,52 @@ func TestMessagesByTokenIDErrorHandling(t *testing.T) {
951951
})
952952
}
953953

954-
// TestTokenUpdatesConversion tests the token updates conversion functions
955-
func TestTokenUpdatesConversion(t *testing.T) {
954+
// TestTokenUpdatesUnixConversion tests the TimestampedUnixBig token updates conversion functions
955+
func TestTokenUpdatesUnixConversion(t *testing.T) {
956956
testTime := time.Date(2024, 1, 15, 12, 0, 0, 0, time.UTC)
957957

958958
testCases := []struct {
959959
name string
960-
updates map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig
960+
updates map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig
961961
}{
962962
{
963-
name: "Token updates with multiple tokens",
964-
updates: map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig{
963+
name: "Unix token updates with multiple tokens",
964+
updates: map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig{
965965
ccipocr3.UnknownEncodedAddress("token1"): {
966-
Timestamp: testTime,
967-
Value: ccipocr3.NewBigInt(big.NewInt(1500000)),
966+
Timestamp: uint32(testTime.Unix()),
967+
Value: big.NewInt(1500000),
968968
},
969969
ccipocr3.UnknownEncodedAddress("token2"): {
970-
Timestamp: testTime.Add(time.Hour),
971-
Value: ccipocr3.NewBigInt(big.NewInt(2500000)),
970+
Timestamp: uint32(testTime.Add(time.Hour).Unix()),
971+
Value: big.NewInt(2500000),
972972
},
973973
ccipocr3.UnknownEncodedAddress("token3"): {
974-
Timestamp: testTime.Add(2 * time.Hour),
975-
Value: ccipocr3.NewBigInt(big.NewInt(750000)),
974+
Timestamp: uint32(testTime.Add(2 * time.Hour).Unix()),
975+
Value: big.NewInt(750000),
976976
},
977977
},
978978
},
979979
{
980-
name: "Empty token updates",
981-
updates: map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig{},
980+
name: "Empty unix token updates",
981+
updates: map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig{},
982982
},
983983
{
984-
name: "Token update with zero value",
985-
updates: map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig{
984+
name: "Unix token update with zero value",
985+
updates: map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig{
986986
ccipocr3.UnknownEncodedAddress("zero-token"): {
987-
Timestamp: testTime,
988-
Value: ccipocr3.NewBigInt(big.NewInt(0)),
987+
Timestamp: uint32(testTime.Unix()),
988+
Value: big.NewInt(0),
989989
},
990990
},
991991
},
992992
{
993-
name: "Token update with large value",
994-
updates: map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig{
993+
name: "Unix token update with large value",
994+
updates: map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig{
995995
ccipocr3.UnknownEncodedAddress("large-token"): {
996-
Timestamp: testTime,
997-
Value: func() ccipocr3.BigInt {
996+
Timestamp: uint32(testTime.Unix()),
997+
Value: func() *big.Int {
998998
val, _ := new(big.Int).SetString("999999999999999999999999999999", 10)
999-
return ccipocr3.NewBigInt(val)
999+
return val
10001000
}(),
10011001
},
10021002
},
@@ -1006,7 +1006,7 @@ func TestTokenUpdatesConversion(t *testing.T) {
10061006
for _, tc := range testCases {
10071007
t.Run(tc.name, func(t *testing.T) {
10081008
// Convert Go -> Protobuf
1009-
pbMap := tokenUpdatesToPb(tc.updates)
1009+
pbMap := tokenUpdatesUnixToPb(tc.updates)
10101010

10111011
if tc.updates == nil {
10121012
assert.Nil(t, pbMap)
@@ -1021,63 +1021,62 @@ func TestTokenUpdatesConversion(t *testing.T) {
10211021
pbUpdate, exists := pbMap[string(token)]
10221022
require.True(t, exists, "token %s should exist in protobuf map", string(token))
10231023
require.NotNil(t, pbUpdate)
1024-
require.NotNil(t, pbUpdate.Timestamp)
10251024
require.NotNil(t, pbUpdate.Value)
10261025

1027-
assert.Equal(t, update.Timestamp.Unix(), pbUpdate.Timestamp.AsTime().Unix())
1028-
assert.Equal(t, update.Value.Int.Bytes(), pbUpdate.Value.Value)
1026+
assert.Equal(t, update.Timestamp, pbUpdate.Timestamp)
1027+
assert.Equal(t, update.Value.Bytes(), pbUpdate.Value.Value)
10291028
}
10301029

10311030
// Convert Protobuf -> Go (round-trip)
1032-
convertedMap := pbToTokenUpdates(pbMap)
1031+
convertedMap := pbToTokenUpdatesUnix(pbMap)
10331032

10341033
// Verify round-trip conversion
10351034
assert.Equal(t, len(tc.updates), len(convertedMap))
10361035
for token, originalUpdate := range tc.updates {
10371036
convertedUpdate, exists := convertedMap[token]
10381037
require.True(t, exists, "token %s should exist in converted map", string(token))
10391038

1040-
// Compare timestamps (allowing for some precision loss in conversion)
1041-
assert.Equal(t, originalUpdate.Timestamp.Unix(), convertedUpdate.Timestamp.Unix())
1042-
assert.Equal(t, originalUpdate.Value.Int.String(), convertedUpdate.Value.Int.String())
1039+
assert.Equal(t, originalUpdate.Timestamp, convertedUpdate.Timestamp)
1040+
assert.Equal(t, originalUpdate.Value.String(), convertedUpdate.Value.String())
10431041
}
10441042
})
10451043
}
10461044
}
10471045

1048-
func TestTokenUpdatesNilHandling(t *testing.T) {
1049-
t.Run("nil token updates to protobuf", func(t *testing.T) {
1050-
pbMap := tokenUpdatesToPb(nil)
1046+
func TestTokenUpdatesUnixNilHandling(t *testing.T) {
1047+
t.Run("nil unix token updates to protobuf", func(t *testing.T) {
1048+
pbMap := tokenUpdatesUnixToPb(nil)
10511049
assert.Nil(t, pbMap)
10521050
})
10531051

1054-
t.Run("nil protobuf map to token updates", func(t *testing.T) {
1055-
updates := pbToTokenUpdates(nil)
1052+
t.Run("nil protobuf map to unix token updates", func(t *testing.T) {
1053+
updates := pbToTokenUpdatesUnix(nil)
10561054
assert.Nil(t, updates)
10571055
})
10581056

1059-
t.Run("empty protobuf map to token updates", func(t *testing.T) {
1060-
emptyPbMap := make(map[string]*ccipocr3pb.TimestampedBig)
1061-
updates := pbToTokenUpdates(emptyPbMap)
1057+
t.Run("empty protobuf map to unix token updates", func(t *testing.T) {
1058+
emptyPbMap := make(map[string]*ccipocr3pb.TimestampedUnixBig)
1059+
updates := pbToTokenUpdatesUnix(emptyPbMap)
10621060
require.NotNil(t, updates)
10631061
assert.Equal(t, 0, len(updates))
10641062
})
10651063

1066-
t.Run("protobuf map with nil timestamp", func(t *testing.T) {
1067-
pbMap := map[string]*ccipocr3pb.TimestampedBig{
1064+
t.Run("protobuf map with nil value", func(t *testing.T) {
1065+
pbMap := map[string]*ccipocr3pb.TimestampedUnixBig{
10681066
"test-token": {
1069-
Timestamp: nil,
1070-
Value: &ccipocr3pb.BigInt{Value: []byte{0x01}},
1067+
Timestamp: 1705320000, // Some valid unix timestamp
1068+
Value: nil,
10711069
},
10721070
}
10731071

10741072
// Should not panic and handle gracefully
1075-
updates := pbToTokenUpdates(pbMap)
1073+
updates := pbToTokenUpdatesUnix(pbMap)
10761074
require.NotNil(t, updates)
10771075
require.Contains(t, updates, ccipocr3.UnknownEncodedAddress("test-token"))
10781076

1079-
// When timestamp is nil, should default to zero time
1080-
update := updates[ccipocr3.UnknownEncodedAddress("test-token")]
1081-
assert.True(t, update.Timestamp.IsZero())
1077+
// When value is nil, should default to zero big.Int
1078+
update := updates[("test-token")]
1079+
assert.Equal(t, uint32(1705320000), update.Timestamp)
1080+
assert.Equal(t, big.NewInt(0), update.Value)
10821081
})
10831082
}

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/test/chain_accessor.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,17 @@ func (s staticChainAccessor) GetFeedPricesUSD(ctx context.Context, tokens []ccip
404404
return result, nil
405405
}
406406

407-
func (s staticChainAccessor) GetFeeQuoterTokenUpdates(ctx context.Context, tokens []ccipocr3.UnknownEncodedAddress, chain ccipocr3.ChainSelector) (map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig, error) {
407+
func (s staticChainAccessor) GetFeeQuoterTokenUpdates(ctx context.Context, tokens []ccipocr3.UnknownEncodedAddress, chain ccipocr3.ChainSelector) (map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig, error) {
408408
// Return static test token updates
409-
result := make(map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedBig)
409+
result := make(map[ccipocr3.UnknownEncodedAddress]ccipocr3.TimestampedUnixBig)
410410
testTime := time.Date(2024, 1, 15, 12, 0, 0, 0, time.UTC)
411411

412412
for i, token := range tokens {
413413
// Generate different prices for different tokens
414414
price := big.NewInt(2000000 + int64(i)*50000) // Different prices from GetFeedPricesUSD
415-
result[token] = ccipocr3.TimestampedBig{
416-
Timestamp: testTime.Add(time.Duration(i) * time.Minute), // Different timestamps
417-
Value: ccipocr3.NewBigInt(price),
415+
result[token] = ccipocr3.TimestampedUnixBig{
416+
Timestamp: uint32(testTime.Add(time.Duration(i) * time.Minute).Unix()), // Different timestamps
417+
Value: price,
418418
}
419419
}
420420
return result, nil
@@ -1037,11 +1037,11 @@ func (s staticChainAccessor) evaluateGetFeeQuoterTokenUpdates(ctx context.Contex
10371037
if !exists {
10381038
return fmt.Errorf("GetFeeQuoterTokenUpdates missing token %s in other updates", string(token))
10391039
}
1040-
if otherUpdate.Value.Cmp(myUpdate.Value.Int) != 0 {
1040+
if otherUpdate.Value.Cmp(myUpdate.Value) != 0 {
10411041
return fmt.Errorf("GetFeeQuoterTokenUpdates token %s value mismatch: got %s, expected %s", string(token), otherUpdate.Value.String(), myUpdate.Value.String())
10421042
}
1043-
if !otherUpdate.Timestamp.Equal(myUpdate.Timestamp) {
1044-
return fmt.Errorf("GetFeeQuoterTokenUpdates token %s timestamp mismatch: got %s, expected %s", string(token), otherUpdate.Timestamp.Format(time.RFC3339), myUpdate.Timestamp.Format(time.RFC3339))
1043+
if otherUpdate.Timestamp != myUpdate.Timestamp {
1044+
return fmt.Errorf("GetFeeQuoterTokenUpdates token %s timestamp mismatch: got %d, expected %d", string(token), otherUpdate.Timestamp, myUpdate.Timestamp)
10451045
}
10461046
}
10471047
return nil

pkg/types/ccipocr3/chainaccessor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,5 +218,5 @@ type PriceReader interface {
218218
ctx context.Context,
219219
tokens []UnknownEncodedAddress,
220220
chain ChainSelector,
221-
) (map[UnknownEncodedAddress]TimestampedBig, error)
221+
) (map[UnknownEncodedAddress]TimestampedUnixBig, error)
222222
}

0 commit comments

Comments
 (0)