Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/rm-median-wrapper' into rtiniano…
Browse files Browse the repository at this point in the history
…v_smoke
  • Loading branch information
nolag committed Dec 22, 2023
2 parents d06d482 + bbaaa0d commit df82950
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 150 deletions.
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}
}

0 comments on commit df82950

Please sign in to comment.