Skip to content

Commit

Permalink
Update common and use unfinalized confidence lvl for CR GetLatestValue
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed Jul 8, 2024
1 parent 6301037 commit f972e7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.3

require (
github.com/hashicorp/go-plugin v1.6.0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240522203001-10ea0211efd7
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240708121854-68161b704058
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
github.com/stretchr/testify v1.9.0
)
Expand Down Expand Up @@ -64,7 +64,6 @@ require (
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ github.com/santhosh-tekuri/jsonschema/v5 v5.2.0 h1:WCcC4vZDS1tYNxjWlwRJZQy28r8CM
github.com/santhosh-tekuri/jsonschema/v5 v5.2.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240522203001-10ea0211efd7 h1:od+11B83s0mQwAMPP3lhtb0nYz63pIKpJEKddfFpu/M=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240522203001-10ea0211efd7/go.mod h1:cFHRblGbGn/rFYOOGsNbtLicMc1+5YdN0KoebYr93pk=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240708121854-68161b704058 h1:Gnxr0HVhXMxiLrtfZ4b+GnpmiKRS13fyjoUxbz4ixPE=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240708121854-68161b704058/go.mod h1:EWvSuqIJUYXZLEHewC7WCaPylM2jyjF3Q36BZPS4MoI=
github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16 h1:TFe+FvzxClblt6qRfqEhUfa4kFQx5UobuoFGO2W4mMo=
github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU=
Expand Down Expand Up @@ -317,8 +317,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
21 changes: 11 additions & 10 deletions median/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"
)

const contractName = "median"
Expand Down Expand Up @@ -55,7 +56,7 @@ func (p *Plugin) NewMedianFactory(ctx context.Context, provider types.MedianProv
}

if cr := provider.ChainReader(); cr != nil {
factory.ContractTransmitter = &chainReaderContract{chainReader: cr, lggr: lggr}
factory.ContractTransmitter = &contractReaderContract{contractReader: cr, lggr: lggr}
} else {
factory.ContractTransmitter = provider.MedianContract()
}
Expand Down Expand Up @@ -100,10 +101,10 @@ func (r *reportingPluginFactoryService) HealthReport() map[string]error {
return map[string]error{r.Name(): r.Healthy()}
}

// chainReaderContract adapts a [types.ChainReader] to [median.MedianContract].
type chainReaderContract struct {
chainReader types.ChainReader
lggr logger.Logger
// contractReaderContract adapts a [types.ContractReader] to [median.MedianContract].
type contractReaderContract struct {
contractReader types.ContractReader
lggr logger.Logger
}

type latestTransmissionDetailsResponse struct {
Expand All @@ -120,10 +121,10 @@ type latestRoundRequested struct {
Round uint8
}

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

err = c.chainReader.GetLatestValue(ctx, contractName, "LatestTransmissionDetails", nil, &resp)
err = c.contractReader.GetLatestValue(ctx, contractName, "LatestTransmissionDetails", primitives.Unconfirmed, nil, &resp)
if err != nil {
if !errors.Is(err, types.ErrNotFound) {
return
Expand All @@ -134,7 +135,7 @@ func (c *chainReaderContract) LatestTransmissionDetails(ctx context.Context) (co
c.lggr.Warn("LatestTransmissionDetails not found", "err", err)
}

// Depending on if there is a LatestAnswer or not, and the implementation of the ChainReader,
// Depending on if there is a LatestAnswer or not, and the implementation of the ContractReader,
// it's possible that this will be unset. The desired behaviour in that case is to have a zero value.
if resp.LatestAnswer == nil {
resp.LatestAnswer = new(big.Int)
Expand All @@ -143,10 +144,10 @@ func (c *chainReaderContract) LatestTransmissionDetails(ctx context.Context) (co
return resp.ConfigDigest, resp.Epoch, resp.Round, resp.LatestAnswer, resp.LatestTimestamp, nil
}

func (c *chainReaderContract) LatestRoundRequested(ctx context.Context, lookback time.Duration) (configDigest ocrtypes.ConfigDigest, epoch uint32, round uint8, err error) {
func (c *contractReaderContract) LatestRoundRequested(ctx context.Context, lookback time.Duration) (configDigest ocrtypes.ConfigDigest, epoch uint32, round uint8, err error) {
var resp latestRoundRequested

err = c.chainReader.GetLatestValue(ctx, contractName, "LatestRoundRequested", nil, &resp)
err = c.contractReader.GetLatestValue(ctx, contractName, "LatestRoundRequested", primitives.Unconfirmed, nil, &resp)
if err != nil {
if !errors.Is(err, types.ErrNotFound) {
return
Expand Down

0 comments on commit f972e7d

Please sign in to comment.