Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
matYang committed Jun 27, 2024
1 parent 4dfa1fe commit 99e7a08
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
32 changes: 17 additions & 15 deletions core/services/ocr2/plugins/ccip/ccipcommit/ocr2.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,10 @@ func (r *CommitReportingPlugin) Observation(ctx context.Context, epochAndRound t
}

// Fetches multi-lane gasPricesUSD and tokenPricesUSD for the same dest chain
gasPricesUSD, tokenPricesUSD, err := r.observePriceUpdates(ctx)
gasPricesUSD, sourceGasPriceUSD, tokenPricesUSD, err := r.observePriceUpdates(ctx)
if err != nil {
return nil, err
}
// Set prices to empty maps if nil to be friendlier to JSON encoding
if gasPricesUSD == nil {
gasPricesUSD = map[uint64]*big.Int{}
}
if tokenPricesUSD == nil {
tokenPricesUSD = map[cciptypes.Address]*big.Int{}
}
// For backwards compatibility with the older release during phased rollout, set the default gas price on this lane
defaultGasPricesUSD := gasPricesUSD[r.sourceChainSelector]

lggr.Infow("Observation",
"minSeqNr", minSeqNr,
Expand All @@ -145,7 +136,7 @@ func (r *CommitReportingPlugin) Observation(ctx context.Context, epochAndRound t
Max: maxSeqNr,
},
TokenPricesUSD: tokenPricesUSD,
SourceGasPriceUSD: defaultGasPricesUSD,
SourceGasPriceUSD: sourceGasPriceUSD,
SourceGasPriceUSDPerChain: gasPricesUSD,
}.Marshal()
}
Expand All @@ -154,20 +145,31 @@ func (r *CommitReportingPlugin) Observation(ctx context.Context, epochAndRound t
// The prices are aggregated for all lanes for the same destination chain.
func (r *CommitReportingPlugin) observePriceUpdates(
ctx context.Context,
) (gasPricesUSD map[uint64]*big.Int, tokenPricesUSD map[cciptypes.Address]*big.Int, err error) {
) (gasPricesUSD map[uint64]*big.Int, sourceGasPriceUSD *big.Int, tokenPricesUSD map[cciptypes.Address]*big.Int, err error) {
// Do not observe prices if price reporting is disabled. Price reporting will be disabled for lanes that are not leader lanes.
if r.offchainConfig.PriceReportingDisabled {
r.lggr.Infow("Price reporting disabled, skipping gas and token price reads")
return nil, nil, nil
return map[uint64]*big.Int{}, nil, map[cciptypes.Address]*big.Int{}, nil
}

// Fetches multi-lane gas prices and token prices, for the given dest chain
gasPricesUSD, tokenPricesUSD, err = r.priceService.GetGasAndTokenPrices(ctx, r.destChainSelector)
if err != nil {
return nil, nil, err
return nil, nil, nil, fmt.Errorf("failed to get prices from PriceService: %w", err)
}

return gasPricesUSD, tokenPricesUSD, nil
// Set prices to empty maps if nil to be friendlier to JSON encoding
if gasPricesUSD == nil {
gasPricesUSD = map[uint64]*big.Int{}
}
if tokenPricesUSD == nil {
tokenPricesUSD = map[cciptypes.Address]*big.Int{}
}

// For backwards compatibility with the older release during phased rollout, set the default gas price on this lane
sourceGasPriceUSD = gasPricesUSD[r.sourceChainSelector]

return gasPricesUSD, sourceGasPriceUSD, tokenPricesUSD, nil
}

func (r *CommitReportingPlugin) calculateMinMaxSequenceNumbers(ctx context.Context, lggr logger.Logger) (uint64, uint64, []cciptypes.Hash, error) {
Expand Down
11 changes: 7 additions & 4 deletions core/services/ocr2/plugins/ccip/ccipcommit/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ func TestCommitReportingPlugin_observePriceUpdates(t *testing.T) {
psGasPricesResult: gasPrices,
psTokenPricesResult: tokenPrices,
PriceReportingDisabled: true,
expectedGasPrice: nil,
expectedTokenPrices: nil,
expectedGasPrice: map[uint64]*big.Int{},
expectedTokenPrices: map[cciptypes.Address]*big.Int{},
psError: false,
expectedErr: false,
},
Expand Down Expand Up @@ -737,13 +737,16 @@ func TestCommitReportingPlugin_observePriceUpdates(t *testing.T) {
PriceReportingDisabled: tc.PriceReportingDisabled,
},
}
sourceGasPriceUSD, tokenPricesUSD, err := p.observePriceUpdates(ctx)
gasPricesUSD, sourceGasPriceUSD, tokenPricesUSD, err := p.observePriceUpdates(ctx)
if tc.expectedErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tc.expectedGasPrice, sourceGasPriceUSD)
assert.Equal(t, tc.expectedGasPrice, gasPricesUSD)
assert.Equal(t, tc.expectedTokenPrices, tokenPricesUSD)
if tc.expectedGasPrice != nil {
assert.Equal(t, tc.expectedGasPrice[sourceChainSelector], sourceGasPriceUSD)
}
}
})
}
Expand Down

0 comments on commit 99e7a08

Please sign in to comment.