Skip to content

Commit

Permalink
Merge pull request #11659 from smartcontractkit/rtinianov_smoke_clean
Browse files Browse the repository at this point in the history
Add smoke test and feature test for chain reader.
  • Loading branch information
nolag authored Dec 22, 2023
2 parents 8ea316a + d825448 commit 4f4bdbf
Show file tree
Hide file tree
Showing 22 changed files with 363 additions and 374 deletions.
3 changes: 2 additions & 1 deletion common/txmgr/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
"go.uber.org/multierr"

commonhex "github.com/smartcontractkit/chainlink-common/pkg/utils/hex"

"github.com/smartcontractkit/chainlink-common/pkg/chains/label"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"
commonhex "github.com/smartcontractkit/chainlink-common/pkg/utils/hex"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox"

"github.com/smartcontractkit/chainlink/v2/common/client"
Expand Down
382 changes: 235 additions & 147 deletions core/internal/features/ocr2/features_ocr2_test.go

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ require (
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/bytedance/sonic v1.10.1 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
Expand Down Expand Up @@ -237,11 +236,11 @@ require (
github.com/shirou/gopsutil/v3 v3.23.11 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231222201016-da3f0a763f71 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231213175155-181d4a261f5d // indirect
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231130211003-6d1bb2f0b68a // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231128204445-3d61b12a0006 // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231222013040-c93f24a1b105 // indirect
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231222220348-c7d81beaf8fd // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231221191127-1f32389044ea // indirect
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 // indirect
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 // indirect
github.com/smartcontractkit/wsrpc v0.7.2 // indirect
Expand Down
20 changes: 11 additions & 9 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ github.com/blendle/zapdriver v1.3.1 h1:C3dydBOWYRiOk+B8X9IVZ5IOe+7cl+tGOexN4QqHf
github.com/blendle/zapdriver v1.3.1/go.mod h1:mdXfREi6u5MArG4j9fewC+FGnXaBR+T4Ox4J2u4eHCc=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.23.0 h1:V2/ZgjfDFIygAX3ZapeigkVBoVUtOJKSwrhZdlpSvaA=
github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
Expand All @@ -179,8 +180,9 @@ github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUB
github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ=
github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.3 h1:SDlJ7bAm4ewvrmZtR0DaiYbQGdKPeaaIm7bM+qRhFeU=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.3/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
Expand Down Expand Up @@ -1148,16 +1150,16 @@ github.com/smartcontractkit/chainlink-automation v1.0.1 h1:vVjBFq2Zsz21kPy1Pb0wp
github.com/smartcontractkit/chainlink-automation v1.0.1/go.mod h1:INSchkV3ntyDdlZKGWA030MPDpp6pbeuiRkRKYFCm2k=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231222013743-f67285bba7bd h1:DsExL564kL/YwKWvUIMUKgdcpUE4Ryfi0aYIS/uXxmY=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231222013743-f67285bba7bd/go.mod h1:f+0ei9N4PlTJHu7pbGzEjTnBUr45syPdGFu5+31lS5Q=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679 h1:iu1pNbUoSDTrp+7BUtfTygZ2C0f5C2ZOBQhIoJjp+S0=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679/go.mod h1:2Jx7bTEk4ujFQdsZpZq3A0BydvaVPs6mX8clUfxHOEM=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231222201016-da3f0a763f71 h1:Ju0cxdrzGFwHGDPp16IzkOyX87LZ/kKDFG1A+VSEJHY=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231222201016-da3f0a763f71/go.mod h1:Ppv5X8MTUkkpKdb270dLefjio724vMkCWmSSaWo7CzI=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 h1:xYqRgZO0nMSO8CBCMR0r3WA+LZ4kNL8a6bnbyk/oBtQ=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1/go.mod h1:GuPvyXryvbiUZIHmPeLBz4L+yJKeyGUjrDfd1KNne+o=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231213175155-181d4a261f5d h1:MicPzjBP6vbcSLNDoCD6Y16/l/8O+e2jlmn7t6gQbhU=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231213175155-181d4a261f5d/go.mod h1:/gErwx/BBGs7gKXy3a3mfnNtL0TrmcODzVQkUvPTXtY=
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231130211003-6d1bb2f0b68a h1:JoyTazNcqXvZoMQjNfB0eapnlaoMS6pI0NeRvouRvog=
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231130211003-6d1bb2f0b68a/go.mod h1:rioELYwPY2xBtzPRN/D08Y7iTPbIQEjPknYdJK51CzQ=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231128204445-3d61b12a0006 h1:1GzOKT53e8N7ZPwsyf1hSbKsynZmXmLOIL3DMvGq9sc=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231128204445-3d61b12a0006/go.mod h1:tJLhL7gJ+V3+4N/yLxXIvJ0DAiuyqZCa31+2BSbw7zo=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231222013040-c93f24a1b105 h1:UUHT19viW3IIxsELz3jsvlk5MnID7cMFZlmor4seTKE=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231222013040-c93f24a1b105/go.mod h1:vQIT9tsN85b4DNgdweUilSUPX7R6gosvCmK5fvFgJAs=
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231222220348-c7d81beaf8fd h1:9xSwDgRJDIfDw6171PQEyn5IQ1JKpaJnG5NX6KfCaHQ=
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231222220348-c7d81beaf8fd/go.mod h1:kY435jBtHbyzhe+ImAxZ6G229uHbB0ablA+A0tJkDn8=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231221191127-1f32389044ea h1:WzMa0O6DEauMYMIjzS/T1JF8zvFDt4aG6EUTDlStaZo=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231221191127-1f32389044ea/go.mod h1:J4A5pQh3CiVs5S2eQMHezToXHoC+Wj0UHBtMXCiTIJA=
github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868 h1:FFdvEzlYwcuVHkdZ8YnZR/XomeMGbz5E2F2HZI3I3w8=
github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868/go.mod h1:Kn1Hape05UzFZ7bOUnm3GVsHzP0TNrVmpfXYNHdqGGs=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss=
Expand Down
21 changes: 20 additions & 1 deletion core/services/job/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,21 @@ type JSONConfig map[string]interface{}

// Bytes returns the raw bytes
func (r JSONConfig) Bytes() []byte {
b, _ := json.Marshal(r)
var retCopy = make(JSONConfig, len(r))
for key, value := range r {
copiedVal := value
// If the value is a json structure string, unmarshal it to preserve JSON structure
// e.g. instead of this {"key":"{\"nestedKey\":{\"nestedValue\":123}}"}
// we want this {"key":{"nestedKey":{"nestedValue":123}}},
if strValue, ok := copiedVal.(string); ok {
if object, ok := asObject(strValue); ok {
copiedVal = object
}
}
retCopy[key] = copiedVal
}

b, _ := json.Marshal(retCopy)
return b
}

Expand Down Expand Up @@ -308,6 +322,11 @@ func (r JSONConfig) MercuryCredentialName() (string, error) {
return name, nil
}

func asObject(s string) (any, bool) {
var js map[string]interface{}
return js, json.Unmarshal([]byte(s), &js) == nil
}

var ForwardersSupportedPlugins = []types.OCR2PluginType{types.Median, types.DKG, types.OCR2VRF, types.OCR2Keeper, types.Functions}

// OCR2OracleSpec defines the job spec for OCR2 jobs.
Expand Down
68 changes: 0 additions & 68 deletions core/services/ocr2/plugins/median/plugin.go

This file was deleted.

84 changes: 2 additions & 82 deletions core/services/ocr2/plugins/median/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
libocr "github.com/smartcontractkit/libocr/offchainreporting2plus"
ocr2types "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

mediantypes "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"

"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/types"
Expand Down Expand Up @@ -57,21 +52,6 @@ func (m *medianConfig) JobPipelineResultWriteQueueDepth() uint64 {
return m.jobPipelineResultWriteQueueDepth
}

// This wrapper avoids the need to modify the signature of NewMedianFactory in all of the non-evm
// relay repos as well as its primary definition in chainlink-common. Once ChainReader is implemented
// and working on all 4 blockchain families, we can remove the original MedianContract() method from
// MedianProvider and pass medianContract as a separate param to NewMedianFactory
type medianProviderWrapper struct {
types.MedianProvider
contract mediantypes.MedianContract
}

// Override relay's implementation of MedianContract with product plugin's implementation of
// MedianContract, making use of product-agnostic ChainReader to read the contract instead of relay MedianContract
func (m medianProviderWrapper) MedianContract() mediantypes.MedianContract {
return m.contract
}

func NewMedianServices(ctx context.Context,
jb job.Job,
isNewlyCreatedJob bool,
Expand Down Expand Up @@ -145,24 +125,10 @@ func NewMedianServices(ctx context.Context,
CreatedAt: time.Now(),
}, lggr)

medianPluginCmd := env.MedianPluginCmd.Get()
medianLoopEnabled := medianPluginCmd != ""

// TODO BCF-2821 handle this properly as this blocks Solana chain reader dev
if !medianLoopEnabled && medianProvider.ChainReader() != nil {
lggr.Info("Chain Reader enabled")
medianProvider = medianProviderWrapper{
medianProvider, // attach newer MedianContract which uses ChainReader
newMedianContract(provider.ChainReader(), common.HexToAddress(spec.ContractID)),
}
} else {
lggr.Info("Chain Reader disabled")
}

if medianLoopEnabled {
if cmdName := env.MedianPluginCmd.Get(); cmdName != "" {
// use unique logger names so we can use it to register a loop
medianLggr := lggr.Named("Median").Named(spec.ContractID).Named(spec.GetID())
cmdFn, telem, err2 := cfg.RegisterLOOP(medianLggr.Name(), medianPluginCmd)
cmdFn, telem, err2 := cfg.RegisterLOOP(medianLggr.Name(), cmdName)
if err2 != nil {
err = fmt.Errorf("failed to register loop: %w", err2)
abort()
Expand Down Expand Up @@ -192,49 +158,3 @@ func NewMedianServices(ctx context.Context,
}
return
}

type medianContract struct {
chainReader types.ChainReader
contract types.BoundContract
}

type latestTransmissionDetailsResponse struct {
configDigest ocr2types.ConfigDigest
epoch uint32
round uint8
latestAnswer *big.Int
latestTimestamp time.Time
}

type latestRoundRequested struct {
configDigest ocr2types.ConfigDigest
epoch uint32
round uint8
}

func (m *medianContract) LatestTransmissionDetails(ctx context.Context) (configDigest ocr2types.ConfigDigest, epoch uint32, round uint8, latestAnswer *big.Int, latestTimestamp time.Time, err error) {
var resp latestTransmissionDetailsResponse

err = m.chainReader.GetLatestValue(ctx, m.contract.Name, "LatestTransmissionDetails", nil, &resp)
if err != nil {
return
}

return resp.configDigest, resp.epoch, resp.round, resp.latestAnswer, resp.latestTimestamp, err
}

func (m *medianContract) LatestRoundRequested(ctx context.Context, lookback time.Duration) (configDigest ocr2types.ConfigDigest, epoch uint32, round uint8, err error) {
var resp latestRoundRequested

err = m.chainReader.GetLatestValue(ctx, m.contract.Name, "LatestRoundRequested", map[string]string{}, &resp)
if err != nil {
return
}

return resp.configDigest, resp.epoch, resp.round, err
}

func newMedianContract(chainReader types.ChainReader, address common.Address) *medianContract {
contract := types.BoundContract{Address: address.String(), Name: "median", Pending: true}
return &medianContract{chainReader, contract}
}
2 changes: 1 addition & 1 deletion core/services/relay/evm/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (e *eventBinding) GetLatestValue(_ context.Context, _ any) ([]byte, error)
if err != nil {
errStr := err.Error()
if strings.Contains(errStr, "not found") || strings.Contains(errStr, "no rows") {
return nil, nil
return nil, fmt.Errorf("%w: %w", commontypes.ErrNotFound, err)
}
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/services/relay/evm/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *evmCodec) CreateType(itemType string, forEncoding bool) (any, error) {

def, ok := itemTypes[itemType]
if !ok {
return nil, commontypes.ErrInvalidType
return nil, fmt.Errorf("%w: cannot find type name %s", commontypes.ErrInvalidType, itemType)
}

return reflect.New(def.checkedType).Interface(), nil
Expand Down
5 changes: 3 additions & 2 deletions core/services/relay/evm/codec_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (entry *codecEntry) Init() error {

func (entry *codecEntry) GetMaxSize(n int) (int, error) {
if entry == nil {
return 0, commontypes.ErrInvalidType
return 0, fmt.Errorf("%w: nil entry", commontypes.ErrInvalidType)
}
return GetMaxSize(n, entry.Args)
}
Expand Down Expand Up @@ -104,7 +104,8 @@ func getNativeAndCheckedTypes(curType *abi.Type) (reflect.Type, reflect.Type, er
}
curType = curType.Elem
default:
return nil, nil, commontypes.ErrInvalidType
return nil, nil, fmt.Errorf(
"%w: cannot create type for kind %v", commontypes.ErrInvalidType, curType.GetType().Kind())
}
}
base, ok := types.GetType(curType.String())
Expand Down
14 changes: 10 additions & 4 deletions core/services/relay/evm/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package evm

import (
"context"
"fmt"
"reflect"

"github.com/mitchellh/mapstructure"
Expand All @@ -18,7 +19,7 @@ var _ commontypes.Decoder = &decoder{}
func (m *decoder) Decode(ctx context.Context, raw []byte, into any, itemType string) error {
info, ok := m.Definitions[itemType]
if !ok {
return commontypes.ErrInvalidType
return fmt.Errorf("%w: cannot find definition for %s", commontypes.ErrInvalidType, itemType)
}

decode, err := extractDecoding(info, raw)
Expand Down Expand Up @@ -53,7 +54,7 @@ func (m *decoder) GetMaxDecodingSize(ctx context.Context, n int, itemType string
func extractDecoding(info *codecEntry, raw []byte) (any, error) {
unpacked := map[string]any{}
if err := info.Args.UnpackIntoMap(unpacked, raw); err != nil {
return nil, commontypes.ErrInvalidEncoding
return nil, fmt.Errorf("%w: %w: for args %#v", commontypes.ErrInvalidEncoding, err, info.Args)
}
var decode any = unpacked

Expand All @@ -79,8 +80,13 @@ func mapstructureDecode(src, dest any) error {
Result: dest,
Squash: true,
})
if err != nil || mDecoder.Decode(src) != nil {
return commontypes.ErrInvalidType
if err != nil {
return fmt.Errorf("%w: %w", commontypes.ErrInvalidType, err)
}

if err = mDecoder.Decode(src); err != nil {
return fmt.Errorf("%w: %w", commontypes.ErrInvalidType, err)
}

return nil
}
Loading

0 comments on commit 4f4bdbf

Please sign in to comment.