Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM WIP for smoke test] #11576

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
282bfeb
Add smoke test for chain reader and codec
nolag Dec 11, 2023
107298f
not found fix
nolag Dec 14, 2023
365242f
WIP
nolag Dec 14, 2023
82fb436
bytes32
nolag Dec 14, 2023
08477d0
Add a bit more info in logging to make it easier to see results
nolag Dec 15, 2023
82ce318
Use better logging form libocr
nolag Dec 15, 2023
fa460ba
more logging from libocr and use my mapstrcture, like common does
nolag Dec 15, 2023
481bc42
Even more logging from libocr :D
nolag Dec 15, 2023
83c0776
update test with new framework
nolag Dec 15, 2023
fef7edd
latest
nolag Dec 15, 2023
750ce74
core/internal/features/ocr2: add chain reader sub-test to TestIntegra…
jmank88 Dec 16, 2023
0ebd5dd
WIP - check if any RoundRequested events were emitted by contract
reductionista Dec 18, 2023
7fbbc35
fix types in the new feature test's assertion
nolag Dec 18, 2023
50f1b55
Update to use my logger again for new median factory. The version wa…
nolag Dec 18, 2023
4e8f88c
Point back to logging for -common, after merging in the time hook
nolag Dec 18, 2023
174f39d
Update chainlink-feeds for LatestRoundReported->LatestRoundRequested fix
reductionista Dec 18, 2023
d1ef734
Add more logging on config
nolag Dec 18, 2023
627b398
10 5 again :D
nolag Dec 18, 2023
6d17425
Update ChainReaderDefinitions, & add block range to RoundRequested query
reductionista Dec 18, 2023
1d2acb1
WIP
reductionista Dec 19, 2023
fe8ec89
bump chainlink-feeds; rm moved wrapper
jmank88 Dec 18, 2023
9d315cb
Fix misleading LogPoller logging
reductionista Dec 19, 2023
1530c04
Add second trial run to OCR2 feature test
reductionista Dec 19, 2023
69a18bd
More logging
nolag Dec 19, 2023
574ffe0
Import more logging that uses cmp to find diffs between old and new m…
nolag Dec 19, 2023
978e43b
import one more log line
nolag Dec 19, 2023
8ca7b93
import change to use logger
nolag Dec 19, 2023
dee584a
Use newer logging from median
nolag Dec 19, 2023
8acbccb
Update to log diffs twice, once with a call before and once after to …
nolag Dec 19, 2023
7999d45
More debug stuff
nolag Dec 19, 2023
e08fc14
Try passing MinConfirmations=1 like LogBroadcaster does
reductionista Dec 20, 2023
79fa968
Fix integration test, and add debug output
reductionista Dec 20, 2023
0271622
Update integration test
reductionista Dec 20, 2023
66fe7e7
Track NewTransmission and Transmitted events in OCR2 integration test
reductionista Dec 21, 2023
19c20b3
Try to fix bug in StartNewOCRRound()
reductionista Dec 21, 2023
0a701cc
Try adding 5s sleep
reductionista Dec 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,9 @@ func (lp *logPoller) backfill(ctx context.Context, start, end int64) error {
gethLogs, err := lp.ec.FilterLogs(ctx, lp.Filter(big.NewInt(from), big.NewInt(to), nil))
if err != nil {
var rpcErr client.JsonError
if errors.As(err, &rpcErr) {
if rpcErr.Code != jsonRpcLimitExceeded {
lp.lggr.Errorw("Unable to query for logs", "err", err, "from", from, "to", to)
return err
}
if !errors.As(err, &rpcErr) || rpcErr.Code != jsonRpcLimitExceeded {
lp.lggr.Errorw("Unable to query for logs", "err", err, "from", from, "to", to)
return err
}
if batchSize == 1 {
lp.lggr.Criticalw("Too many log results in a single block, failed to retrieve logs! Node may be running in a degraded state.", "err", err, "from", from, "to", to, "LogBackfillBatchSize", lp.backfillBatchSize)
Expand Down
383 changes: 234 additions & 149 deletions core/internal/features/ocr2/features_ocr2_test.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ 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-common v0.1.7-0.20231213203435-f213bca2982d // indirect
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218192030-a1f59aa9e04b // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231127231053-2232d3a6766d // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231219204752-f623ecc16802 // 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/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 // 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 @@ -1148,14 +1148,14 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M=
github.com/smartcontractkit/chainlink-automation v1.0.1 h1:vVjBFq2Zsz21kPy1Pb0wpjF9zrbJX+zjXphDeeR4XZk=
github.com/smartcontractkit/chainlink-automation v1.0.1/go.mod h1:INSchkV3ntyDdlZKGWA030MPDpp6pbeuiRkRKYFCm2k=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231213203435-f213bca2982d h1:azq9Vi7aWsq7HOUIYKFCD3Xksuz03q+UFUUkhPwYByc=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231213203435-f213bca2982d/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218192030-a1f59aa9e04b h1:4S2FO2YsCRT3KiImGxI+ZAUMl/peweiQuIk8Tm4WEBU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218192030-a1f59aa9e04b/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs=
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-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-20231127231053-2232d3a6766d h1:w4MsbOtNk6nD/mcXLstHWk9hB6g7QLtcAfhPjhwvOaQ=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231127231053-2232d3a6766d/go.mod h1:YPAfLNowdBwiKiYOwgwtbJHi8AJWbcxkbOY0ItAvkfc=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231219204752-f623ecc16802 h1:gTbzH7DfK6N4RbO+SAAdJUnkaZ5Gu5IHjZdF40Fufbg=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231219204752-f623ecc16802/go.mod h1:Mr81s6sKCXcIyxv6cJ4OOPEdbxLCY6BkO7NiP26AOJ0=
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=
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 @@ -276,7 +276,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 @@ -306,6 +320,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}
}
37 changes: 31 additions & 6 deletions core/services/relay/evm/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewChainReaderService(lggr logger.Logger, lp logpoller.LogPoller, b Binding
return nil, err
}

c, err := parsed.toCodec()
c, err := parsed.toCodec(lggr)

return &chainReader{
lggr: lggr.Named("ChainReader"),
Expand All @@ -63,8 +63,10 @@ func (cr *chainReader) Name() string { return cr.lggr.Name() }
var _ commontypes.ContractTypeProvider = &chainReader{}

func (cr *chainReader) GetLatestValue(ctx context.Context, contractName, method string, params any, returnVal any) error {
cr.lggr.Infof("!!!!!!!!!!\nEVM CR\n%s.%s\n%#v\n%s\n!!!!!!!!!!\n", contractName, method, params)
ae, err := cr.bindings.getBinding(contractName, method, false)
if err != nil {
cr.lggr.Errorf("!!!!!!!!!!\nEVM CR err:\n%v\n!!!!!!!!!!\n", err)
return err
}

Expand All @@ -76,29 +78,43 @@ func (cr *chainReader) GetLatestValue(ctx context.Context, contractName, method
}

func (cr *chainReader) getLatestValueFromLogPoller(ctx context.Context, contractName, method string, hash common.Hash, returnVal any) error {
cr.lggr.Infof("!!!!!!!!!!\nlp: EVM latest from log poller\n!!!!!!!!!!\n")
ae, err := cr.bindings.getBinding(contractName, method, false)
if err != nil {
cr.lggr.Errorf("!!!!!!!!!!\nlp: EVM no binding err:\n%v\n!!!!!!!!!!\n", err)
return err
}

log, err := cr.lp.LatestLogByEventSigWithConfs(hash, ae.addr, logpoller.Finalized)
log, err := cr.lp.LatestLogByEventSigWithConfs(hash, ae.addr, 1)
if err != nil {
if strings.Contains(err.Error(), "not found") {
return fmt.Errorf("%w: %w", commontypes.ErrNotFound, err)
errStr := err.Error()
if strings.Contains(errStr, "not found") || strings.Contains(errStr, "no rows") {
cr.lggr.Infof("!!!!!!!!!!\nlp: Returning no error when nothing is found\n!!!!!!!!!!\n")
return nil
}
cr.lggr.Errorf("!!!!!!!!!!\nlp: No sig err:\n%v\n!!!!!!!!!!\n", err)
return fmt.Errorf("%w: %w", commontypes.ErrInternal, err)
}
return cr.codec.Decode(ctx, log.Data, returnVal, wrapItemType(contractName, method, false))
err = cr.codec.Decode(ctx, log.Data, returnVal, wrapItemType(contractName, method, false))
if err != nil {
cr.lggr.Errorf("!!!!!!!!!!\nlp: EVM decode err:\n%v\n!!!!!!!!!!\n", err)
} else {
cr.lggr.Infof("!!!!!!!!!!\nlp: EVM decode success\n%#v\n!!!!!!!!!!\n", returnVal)
}
return err
}

func (cr *chainReader) getLatestValueFromContract(ctx context.Context, contractName, method string, params any, returnVal any) error {
cr.lggr.Infof("!!!!!!!!!!\nEVM latest from contract\n!!!!!!!!!!\n")
data, err := cr.codec.Encode(ctx, params, wrapItemType(contractName, method, true))
if err != nil {
cr.lggr.Errorf("!!!!!!!!!!\nEVM encode err:\n%v\n!!!!!!!!!!\n", err)
return err
}

ae, err := cr.bindings.getBinding(contractName, method, true)
if err != nil {
cr.lggr.Errorf("!!!!!!!!!!\nEVM no binding err:\n%v\n!!!!!!!!!!\n", err)
return err
}
callMsg := ethereum.CallMsg{
Expand All @@ -110,10 +126,19 @@ func (cr *chainReader) getLatestValueFromContract(ctx context.Context, contractN
output, err := cr.client.CallContract(ctx, callMsg, nil)

if err != nil {
cr.lggr.Errorf("!!!!!!!!!!\nEVM call err:\n%v\n!!!!!!!!!!\n", err)
return err
}

return cr.codec.Decode(ctx, output, returnVal, wrapItemType(contractName, method, false))
cr.lggr.Infof("!!!!!!!!!!\nEVM results \n%x\n!!!!!!!!!!\n", output)

err = cr.codec.Decode(ctx, output, returnVal, wrapItemType(contractName, method, false))
if err != nil {
cr.lggr.Errorf("!!!!!!!!!!\nEVM decode err:\n%v\n!!!!!!!!!!\n", err)
} else {
cr.lggr.Infof("!!!!!!!!!!\nEVM decode success\n%#v\n!!!!!!!!!!\n", returnVal)
}
return err
}

func (cr *chainReader) Start(_ context.Context) error {
Expand Down
Loading