Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Sep 27, 2023
1 parent dc50a91 commit b219382
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 29 deletions.
2 changes: 1 addition & 1 deletion core/services/ocr2/plugins/ccip/commit_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func jobSpecToCommitPluginConfig(lggr logger.Logger, jb job.Job, pr pipeline.Run
if err != nil {
return nil, nil, err
}
sourceRouter, err := router.NewRouter(onRampReader.Router(), sourceChain.Client())
sourceRouter, err := router.NewRouter(onRampReader.RouterAddress(), sourceChain.Client())
if err != nil {
return nil, nil, err
}
Expand Down
18 changes: 9 additions & 9 deletions core/services/ocr2/plugins/ccip/commit_reporting_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ func TestCommitReportingPlugin_Observation(t *testing.T) {
commitStore, _ := testhelpers.NewFakeCommitStore(t, tc.commitStoreSeqNum)
commitStore.SetPaused(tc.commitStoreIsPaused)

sourceReader := ccipdata.NewMockOnRampReader(t)
onRampReader := ccipdata.NewMockOnRampReader(t)
if len(tc.sendReqs) > 0 {
sourceReader.On("GetSendRequestsGteSeqNum", ctx, tc.commitStoreSeqNum, sourceFinalityDepth).
onRampReader.On("GetSendRequestsGteSeqNum", ctx, tc.commitStoreSeqNum, sourceFinalityDepth).
Return(tc.sendReqs, nil)
}

Expand Down Expand Up @@ -130,7 +130,7 @@ func TestCommitReportingPlugin_Observation(t *testing.T) {
p.inflightReports = newInflightCommitReportsContainer(time.Hour)
p.config.commitStore = commitStore
p.offchainConfig.SourceFinalityDepth = uint32(sourceFinalityDepth)
p.config.onRampReader = sourceReader
p.config.onRampReader = onRampReader
p.tokenDecimalsCache = tokenDecimalsCache
p.config.priceGetter = priceGet
p.config.sourceFeeEstimator = sourceFeeEst
Expand Down Expand Up @@ -234,17 +234,17 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
destReader.On("GetGasPriceUpdatesCreatedAfter", ctx, destPriceRegistryAddress, uint64(sourceChainSelector), mock.Anything, 0).Return(tc.gasPriceUpdates, nil)
destReader.On("GetTokenPriceUpdatesCreatedAfter", ctx, destPriceRegistryAddress, mock.Anything, 0).Return(tc.tokenPriceUpdates, nil)

sourceReader := ccipdata.NewMockOnRampReader(t)
onRampReader := ccipdata.NewMockOnRampReader(t)
if len(tc.sendRequests) > 0 {
sourceReader.On("GetSendRequestsBetweenSeqNums", ctx, tc.expSeqNumRange.Min, tc.expSeqNumRange.Max, 0).Return(tc.sendRequests, nil)
onRampReader.On("GetSendRequestsBetweenSeqNums", ctx, tc.expSeqNumRange.Min, tc.expSeqNumRange.Max, 0).Return(tc.sendRequests, nil)
}

p := &CommitReportingPlugin{}
p.lggr = logger.TestLogger(t)
p.inflightReports = newInflightCommitReportsContainer(time.Minute)
p.destPriceRegistry = destPriceRegistry
p.config.destReader = destReader
p.config.onRampReader = sourceReader
p.config.onRampReader = onRampReader
p.config.sourceChainSelector = uint64(sourceChainSelector)

aos := make([]types.AttributedObservation, 0, len(tc.observations))
Expand Down Expand Up @@ -1024,7 +1024,7 @@ func TestCommitReportingPlugin_calculateMinMaxSequenceNumbers(t *testing.T) {
}
}

sourceReader := ccipdata.NewMockOnRampReader(t)
onRampReader := ccipdata.NewMockOnRampReader(t)
var sendReqs []ccipdata.Event[ccipdata.EVM2EVMMessage]
for _, seqNum := range tc.msgSeqNums {
sendReqs = append(sendReqs, ccipdata.Event[ccipdata.EVM2EVMMessage]{
Expand All @@ -1033,8 +1033,8 @@ func TestCommitReportingPlugin_calculateMinMaxSequenceNumbers(t *testing.T) {
},
})
}
sourceReader.On("GetSendRequestsGteSeqNum", ctx, tc.expQueryMin, 0).Return(sendReqs, nil)
p.config.onRampReader = sourceReader
onRampReader.On("GetSendRequestsGteSeqNum", ctx, tc.expQueryMin, 0).Return(sendReqs, nil)
p.config.onRampReader = onRampReader

minSeqNum, maxSeqNum, err := p.calculateMinMaxSequenceNumbers(ctx, lggr)
if tc.expErr {
Expand Down
13 changes: 10 additions & 3 deletions core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/pkg/errors"
Expand All @@ -25,14 +26,20 @@ const (
COMMIT_CCIP_SENDS = "Commit ccip sends"
)

type Hash [32]byte

func (h Hash) String() string {
return hexutil.Encode(h[:])
}

// EVM2EVMMessage is the interface for a message sent from the offramp to the onramp
// Plugin can operate against any lane version which has a message satisfying this interface.
type EVM2EVMMessage struct {
SequenceNumber uint64
GasLimit *big.Int
Nonce uint64
MessageId [32]byte
Hash [32]byte
MessageId Hash
Hash Hash
// TODO: add more fields as we abstract exec plugin
// also this Log can eventually go away with destchain abstractions
Log types.Log // Raw event data
Expand All @@ -48,7 +55,7 @@ type OnRampReader interface {
GetSendRequestsBetweenSeqNums(ctx context.Context, seqNumMin, seqNumMax uint64, confs int) ([]Event[EVM2EVMMessage], error)

// Get router configured in the onRamp
Router() common.Address
RouterAddress() common.Address

// TODO: temporary until we abstract offramp as well
// (currently this works since all versions are compatible with the same offramp ABI)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

const (
CCIPSendRequestedEventNameV1_0_0 = "CCIPSendRequested"
MetaDataHashPrefixV1_0_0 = "EVM2EVMMessageEvent"
)

var leafDomainSeparator = [1]byte{0x00}

type LeafHasherV1_0_0 struct {
Expand All @@ -38,7 +43,7 @@ func getMetaDataHash[H hashlib.Hash](ctx hashlib.Ctx[H], prefix [32]byte, source

func NewLeafHasherV1_0_0(sourceChainSelector uint64, destChainSelector uint64, onRampId common.Address, ctx hashlib.Ctx[[32]byte], onRamp *evm_2_evm_onramp_1_0_0.EVM2EVMOnRamp) *LeafHasherV1_0_0 {
return &LeafHasherV1_0_0{
metaDataHash: getMetaDataHash(ctx, ctx.Hash([]byte("EVM2EVMMessageEvent")), sourceChainSelector, onRampId, destChainSelector),
metaDataHash: getMetaDataHash(ctx, ctx.Hash([]byte(MetaDataHashPrefixV1_0_0)), sourceChainSelector, onRampId, destChainSelector),
ctx: ctx,
onRamp: onRamp,
}
Expand Down Expand Up @@ -120,7 +125,7 @@ func NewOnRampV1_0_0(lggr logger.Logger, sourceSelector, destSelector uint64, on
}
// Subscribe to the relevant logs
name := logpoller.FilterName(COMMIT_CCIP_SENDS, onRampAddress)
eventSig := abihelpers.GetIDOrPanic("CCIPSendRequested", onRampABI)
eventSig := abihelpers.GetIDOrPanic(CCIPSendRequestedEventNameV1_0_0, onRampABI)
err = sourceLP.RegisterFilter(logpoller.Filter{
Name: name,
EventSigs: []common.Hash{eventSig},
Expand Down Expand Up @@ -194,7 +199,7 @@ func (o *OnRampV1_0_0) GetSendRequestsGteSeqNum(ctx context.Context, seqNum uint
return parseLogs[EVM2EVMMessage](logs, o.lggr, o.logToMessage)
}

func (o *OnRampV1_0_0) Router() common.Address {
func (o *OnRampV1_0_0) RouterAddress() common.Address {
config, _ := o.onRamp.GetDynamicConfig(nil)
return config.Router
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestHasherV1_0_0(t *testing.T) {
MessageId: [32]byte{},
}

data, err := onRampABI.Events["CCIPSendRequested"].Inputs.Pack(message)
data, err := onRampABI.Events[CCIPSendRequestedEventNameV1_0_0].Inputs.Pack(message)
require.NoError(t, err)
hash, err := hasher.HashLeaf(types.Log{Topics: []common.Hash{abihelpers.GetIDOrPanic("CCIPSendRequested", onRampABI)}, Data: data})
require.NoError(t, err)
Expand All @@ -68,7 +68,7 @@ func TestHasherV1_0_0(t *testing.T) {
MessageId: [32]byte{},
}

data, err = onRampABI.Events["CCIPSendRequested"].Inputs.Pack(message)
data, err = onRampABI.Events[CCIPSendRequestedEventNameV1_0_0].Inputs.Pack(message)
require.NoError(t, err)
hash, err = hasher.HashLeaf(types.Log{Topics: []common.Hash{abihelpers.GetIDOrPanic("CCIPSendRequested", onRampABI)}, Data: data})
require.NoError(t, err)
Expand All @@ -81,6 +81,6 @@ func TestMetaDataHash(t *testing.T) {
sourceChainSelector, destChainSelector := uint64(1), uint64(4)
onRampAddress := common.HexToAddress("0x5550000000000000000000000000000000000001")
ctx := hashlib.NewKeccakCtx()
hash := getMetaDataHash(ctx, ctx.Hash([]byte("EVM2EVMSubscriptionMessagePlus")), sourceChainSelector, onRampAddress, destChainSelector)
require.Equal(t, "e8b93c9d01a7a72ec6c7235e238701cf1511b267a31fdb78dd342649ee58c08d", hex.EncodeToString(hash[:]))
hash := getMetaDataHash(ctx, ctx.Hash([]byte(MetaDataHashPrefixV1_0_0)), sourceChainSelector, onRampAddress, destChainSelector)
require.Equal(t, "1409948abde219f43870c3d6d1c16beabd8878eb5039a3fa765eb56e4b8ded9e", hex.EncodeToString(hash[:]))
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewOnRampV1_1_0(lggr logger.Logger, sourceSelector, destSelector uint64, on
}, nil
}

func (o *OnRampV1_1_0) Router() common.Address {
func (o *OnRampV1_1_0) RouterAddress() common.Address {
config, _ := o.onRamp.GetDynamicConfig(nil)
return config.Router
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ var (

const (
CCIPSendRequestSeqNumIndexV1_2_0 = 4
CCIPSendRequestedEventNameV1_2_0 = "CCIPSendRequested"
EVM2EVMOffRampEventNameV1_2_0 = "EVM2EVMMessage"
MetaDataHashPrefixV1_2_0 = "EVM2EVMMessageHashV2"
)

func init() {
onRampABI, err := abi.JSON(strings.NewReader(evm_2_evm_onramp.EVM2EVMOnRampABI))
if err != nil {
panic(err)
}
CCIPSendRequestEventSigV1_2_0 = abihelpers.GetIDOrPanic("CCIPSendRequested", onRampABI)
CCIPSendRequestEventSigV1_2_0 = abihelpers.GetIDOrPanic(CCIPSendRequestedEventNameV1_2_0, onRampABI)
}

// Backwards compat for integration tests
Expand All @@ -44,7 +47,7 @@ func DecodeOffRampMessageV1_2_0(b []byte) (*evm_2_evm_offramp.InternalEVM2EVMMes
if err != nil {
panic(err)
}
event, ok := offRampABI.Events["EVM2EVMMessage"]
event, ok := offRampABI.Events[EVM2EVMOffRampEventNameV1_2_0]
if !ok {
panic("no such event")
}
Expand Down Expand Up @@ -111,7 +114,7 @@ type LeafHasherV1_2_0 struct {

func NewLeafHasherV1_2_0(sourceChainSelector uint64, destChainSelector uint64, onRampId common.Address, ctx hashlib.Ctx[[32]byte], onRamp *evm_2_evm_onramp.EVM2EVMOnRamp) *LeafHasherV1_2_0 {
return &LeafHasherV1_2_0{
metaDataHash: getMetaDataHash(ctx, ctx.Hash([]byte("EVM2EVMMessageHashV2")), sourceChainSelector, onRampId, destChainSelector),
metaDataHash: getMetaDataHash(ctx, ctx.Hash([]byte(MetaDataHashPrefixV1_2_0)), sourceChainSelector, onRampId, destChainSelector),
ctx: ctx,
onRamp: onRamp,
}
Expand Down Expand Up @@ -270,7 +273,7 @@ func (o *OnRampV1_2_0) GetSendRequestsBetweenSeqNums(ctx context.Context, seqNum
return parseLogs[EVM2EVMMessage](logs, o.lggr, o.logToMessage)
}

func (o *OnRampV1_2_0) Router() common.Address {
func (o *OnRampV1_2_0) RouterAddress() common.Address {
config, _ := o.onRamp.GetDynamicConfig(nil)
return config.Router
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestHasherV1_2_0(t *testing.T) {
MessageId: [32]byte{},
}

data, err := onRampABI.Events["CCIPSendRequested"].Inputs.Pack(message)
data, err := onRampABI.Events[CCIPSendRequestedEventNameV1_2_0].Inputs.Pack(message)
require.NoError(t, err)
hash, err := hasher.HashLeaf(types.Log{Topics: []common.Hash{CCIPSendRequestEventSigV1_2_0}, Data: data})
require.NoError(t, err)
Expand All @@ -78,7 +78,7 @@ func TestHasherV1_2_0(t *testing.T) {
MessageId: [32]byte{},
}

data, err = onRampABI.Events["CCIPSendRequested"].Inputs.Pack(message)
data, err = onRampABI.Events[CCIPSendRequestedEventNameV1_2_0].Inputs.Pack(message)
require.NoError(t, err)
hash, err = hasher.HashLeaf(types.Log{Topics: []common.Hash{CCIPSendRequestEventSigV1_2_0}, Data: data})
require.NoError(t, err)
Expand Down

0 comments on commit b219382

Please sign in to comment.