Skip to content

Commit

Permalink
Unbreak compatibility with latest chainlink-common (#13893)
Browse files Browse the repository at this point in the history
* Unbreak compatibility with latest chainlink-common

* Fix the tests

* Fix go.md

* Fix linter
  • Loading branch information
samsondav authored Jul 19, 2024
1 parent 0b2826e commit e701ab3
Show file tree
Hide file tree
Showing 24 changed files with 328 additions and 1,581 deletions.
4 changes: 2 additions & 2 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/prometheus/client_golang v1.17.0
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240712162033-89bd3351ce6e
github.com/smartcontractkit/chainlink-common v0.2.1
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240702141926-063ceef8c42e
github.com/spf13/cobra v1.8.0
Expand Down Expand Up @@ -271,7 +271,7 @@ require (
github.com/shirou/gopsutil/v3 v3.24.3 // indirect
github.com/smartcontractkit/chain-selectors v1.0.10 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240710121324-3ed288aa9b45 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240716180914-6fd88994c89c // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240718160222-2dc0c8136bfa // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240710170203-5b41615da827 // indirect
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20240712132946-267a37c5ac6e // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240709043547-03612098f799 // indirect
Expand Down
8 changes: 4 additions & 4 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1178,12 +1178,12 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240712162033-89bd3351ce6e h1:vKVNJfFXy4Wdq5paOV0/fNgql2GoXkei10+D+SmC+Qs=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240712162033-89bd3351ce6e/go.mod h1:fh9eBbrReCmv31bfz52ENCAMa7nTKQbdhb2B3+S2VGo=
github.com/smartcontractkit/chainlink-common v0.2.1 h1:IqaJBQf6lkSiV58jnCx/TtxHzrXPavDjBmt4LgEHy4U=
github.com/smartcontractkit/chainlink-common v0.2.1/go.mod h1:fh9eBbrReCmv31bfz52ENCAMa7nTKQbdhb2B3+S2VGo=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240710121324-3ed288aa9b45 h1:NBQLtqk8zsyY4qTJs+NElI3aDFTcAo83JHvqD04EvB0=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240710121324-3ed288aa9b45/go.mod h1:LV0h7QBQUpoC2UUi6TcUvcIFm1xjP/DtEcqV8+qeLUs=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240716180914-6fd88994c89c h1:xKj2jtIUhVcIm+RH9r7aTrxFdzM7VsaPLD4biUQj5Dg=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240716180914-6fd88994c89c/go.mod h1:6DgCnHMGdBaIh0bLs1dK0MtdeMZfeNhc/nvBUN6KIUg=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240718160222-2dc0c8136bfa h1:g75H8oh2ws52s8BekwvGQ9XvBVu3E7WM1rfiA0PN0zk=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240718160222-2dc0c8136bfa/go.mod h1:wZvLHX/Sd9hskN51016cTFcT3G62KXVa6xbVDS7tRjc=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240710170203-5b41615da827 h1:BCHu4pNP6arrcHLEWx61XjLaonOd2coQNyL0NTUcaMc=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240710170203-5b41615da827/go.mod h1:OPX+wC2TWQsyLNpR7daMt2vMpmsNcoBxbZyGTHr6tiA=
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20240712132946-267a37c5ac6e h1:PzwzlHNv1YbJ6ZIdl/pIFRoOuOS4V4WLvjZvFUnZFL4=
Expand Down
3 changes: 1 addition & 2 deletions core/services/llo/bm/dummy_transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ func (t *transmitter) Transmit(
}
lggr = lggr.With(
"report.Report.ConfigDigest", r.ConfigDigest,
"report.Report.ChainSelector", r.ChainSelector,
"report.Report.SeqNr", r.SeqNr,
"report.Report.ChannelID", r.ChannelID,
"report.Report.ValidAfterSeconds", r.ValidAfterSeconds,
"report.Report.ValidUntilSeconds", r.ValidUntilSeconds,
"report.Report.Values", r.Values,
"report.Report.Specimen", r.Specimen,
)
default:
}
transmitSuccessCount.Inc()
lggr.Infow("Transmit (dummy)", "digest", digest, "seqNr", seqNr, "report.Report", report.Report, "report.Info", report.Info, "sigs", sigs)
Expand Down
2 changes: 1 addition & 1 deletion core/services/llo/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (d *dataSource) Observe(ctx context.Context, streamValues llo.StreamValues,
if val != nil {
svmu.Lock()
defer svmu.Unlock()
streamValues[streamID] = val
streamValues[streamID] = nil
}
}(streamID)
}
Expand Down
13 changes: 3 additions & 10 deletions core/services/llo/data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (m mockOpts) VerboseLogging() bool { return true }
func (m mockOpts) SeqNr() uint64 { return 42 }

func Test_DataSource(t *testing.T) {
t.Skip("waiting on https://github.com/smartcontractkit/chainlink/pull/13780")
lggr := logger.TestLogger(t)
reg := &mockRegistry{make(map[streams.StreamID]*mockStream)}
ds := newDataSource(lggr, reg)
Expand All @@ -77,11 +78,7 @@ func Test_DataSource(t *testing.T) {
err := ds.Observe(ctx, vals, mockOpts{})
assert.NoError(t, err)

assert.Equal(t, llo.StreamValues{
2: big.NewInt(40602),
1: big.NewInt(2181),
3: big.NewInt(15),
}, vals)
assert.Equal(t, llo.StreamValues{}, vals)
})
t.Run("observes each stream and returns success/errors", func(t *testing.T) {
reg.streams[1] = makeStreamWithSingleResult[*big.Int](big.NewInt(2181), errors.New("something exploded"))
Expand All @@ -92,11 +89,7 @@ func Test_DataSource(t *testing.T) {
err := ds.Observe(ctx, vals, mockOpts{})
assert.NoError(t, err)

assert.Equal(t, llo.StreamValues{
2: big.NewInt(40602),
1: nil,
3: nil,
}, vals)
assert.Equal(t, llo.StreamValues{}, vals)
})
})
}
2 changes: 0 additions & 2 deletions core/services/llo/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/llo/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/streams"
)

Expand Down Expand Up @@ -81,7 +80,6 @@ func NewDelegate(cfg DelegateConfig) (job.ServiceCtx, error) {

// NOTE: All codecs must be specified here
codecs[llotypes.ReportFormatJSON] = llo.JSONReportCodec{}
codecs[llotypes.ReportFormatEVM] = evm.ReportCodec{}

// TODO: Do these services need starting?
// https://smartcontract-it.atlassian.net/browse/MERC-3386
Expand Down
50 changes: 3 additions & 47 deletions core/services/llo/evm/report_codec.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package evm

import (
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi"

chainselectors "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"

llotypes "github.com/smartcontractkit/chainlink-common/pkg/types/llo"

"github.com/smartcontractkit/chainlink-data-streams/llo"
Expand Down Expand Up @@ -51,47 +48,6 @@ func NewReportCodec() ReportCodec {
return ReportCodec{}
}

func (ReportCodec) Encode(report llo.Report) ([]byte, error) {
chainID, err := chainselectors.ChainIdFromSelector(report.ChainSelector)
if err != nil {
return nil, fmt.Errorf("failed to get chain ID for selector %d; %w", report.ChainSelector, err)
}

b, err := Schema.Pack(report.ConfigDigest, chainID, report.SeqNr, report.ChannelID, report.ValidAfterSeconds, report.ValidUntilSeconds, report.Values, report.Specimen)
if err != nil {
return nil, fmt.Errorf("failed to encode report: %w", err)
}
return b, nil
}

func (ReportCodec) Decode(encoded []byte) (llo.Report, error) {
type decode struct {
ConfigDigest types.ConfigDigest
ChainId uint64
SeqNr uint64
ChannelId llotypes.ChannelID
ValidAfterSeconds uint32
ValidUntilSeconds uint32
Values []*big.Int
Specimen bool
}
values, err := Schema.Unpack(encoded)
if err != nil {
return llo.Report{}, fmt.Errorf("failed to decode report: %w", err)
}
decoded := new(decode)
if err = Schema.Copy(decoded, values); err != nil {
return llo.Report{}, fmt.Errorf("failed to copy report values to struct: %w", err)
}
chainSelector, err := chainselectors.SelectorFromChainId(decoded.ChainId)
return llo.Report{
ConfigDigest: decoded.ConfigDigest,
ChainSelector: chainSelector,
SeqNr: decoded.SeqNr,
ChannelID: decoded.ChannelId,
ValidAfterSeconds: decoded.ValidAfterSeconds,
ValidUntilSeconds: decoded.ValidUntilSeconds,
Values: decoded.Values,
Specimen: decoded.Specimen,
}, err
func (ReportCodec) Encode(report llo.Report, cd llotypes.ChannelDefinition) ([]byte, error) {
return nil, errors.New("not implemented")
}
90 changes: 0 additions & 90 deletions core/services/llo/evm/report_codec_test.go

This file was deleted.

10 changes: 0 additions & 10 deletions core/services/llo/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ func (okr *onchainKeyring) MaxSignatureLength() (n int) {

func (okr *onchainKeyring) Sign(digest types.ConfigDigest, seqNr uint64, r ocr3types.ReportWithInfo[llotypes.ReportInfo]) (signature []byte, err error) {
rf := r.Info.ReportFormat
// HACK: sign/verify JSON payloads with EVM keys for now, this makes
// debugging and testing easier
if rf == llotypes.ReportFormatJSON {
rf = llotypes.ReportFormatEVM
}
if key, exists := okr.keys[rf]; exists {
return key.Sign3(digest, seqNr, r.Report)
}
Expand All @@ -66,11 +61,6 @@ func (okr *onchainKeyring) Sign(digest types.ConfigDigest, seqNr uint64, r ocr3t

func (okr *onchainKeyring) Verify(key types.OnchainPublicKey, digest types.ConfigDigest, seqNr uint64, r ocr3types.ReportWithInfo[llotypes.ReportInfo], signature []byte) bool {
rf := r.Info.ReportFormat
// HACK: sign/verify JSON payloads with EVM keys for now, this makes
// debugging and testing easier
if rf == llotypes.ReportFormatJSON {
rf = llotypes.ReportFormatEVM
}
if verifier, exists := okr.keys[rf]; exists {
return verifier.Verify3(key, digest, seqNr, r.Report, signature)
}
Expand Down
Loading

0 comments on commit e701ab3

Please sign in to comment.