Skip to content

Commit

Permalink
Implements new chainlink-relay + libocr versions
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzaldysanchez authored and samsondav committed May 1, 2023
1 parent a50ee06 commit d3a46cf
Show file tree
Hide file tree
Showing 78 changed files with 277 additions and 154 deletions.
22 changes: 16 additions & 6 deletions core/internal/features/ocr2/features_ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"github.com/smartcontractkit/libocr/commontypes"
"github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator"
testoffchainaggregator2 "github.com/smartcontractkit/libocr/gethwrappers2/testocr2aggregator"
confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2/confighelper"
ocrtypes2 "github.com/smartcontractkit/libocr/offchainreporting2/types"
confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
ocrtypes2 "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -298,6 +298,7 @@ fromBlock = %d
"0": {}, "10": {}, "20": {}, "30": {},
}
for i := 0; i < 4; i++ {
s := i
err = apps[i].Start(testutils.Context(t))
require.NoError(t, err)

Expand All @@ -307,7 +308,9 @@ fromBlock = %d
res.WriteHeader(http.StatusOK)
res.Write([]byte(`{"data":10}`))
}))
t.Cleanup(slowServers[i].Close)
t.Cleanup(func() {
slowServers[s].Close()
})
servers[i] = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
b, err := io.ReadAll(req.Body)
require.NoError(t, err)
Expand All @@ -321,7 +324,9 @@ fromBlock = %d
res.WriteHeader(http.StatusOK)
res.Write([]byte(`{"data":10}`))
}))
t.Cleanup(servers[i].Close)
t.Cleanup(func() {
servers[s].Close()
})
u, _ := url.Parse(servers[i].URL)
require.NoError(t, apps[i].BridgeORM().CreateBridgeType(&bridges.BridgeType{
Name: bridges.BridgeName(fmt.Sprintf("bridge%d", i)),
Expand Down Expand Up @@ -560,6 +565,7 @@ chainID = 1337
"0": {}, "10": {}, "20": {}, "30": {},
}
for i := 0; i < 4; i++ {
s := i
err = apps[i].Start(testutils.Context(t))
require.NoError(t, err)

Expand All @@ -569,7 +575,9 @@ chainID = 1337
res.WriteHeader(http.StatusOK)
res.Write([]byte(`{"data":10}`))
}))
t.Cleanup(slowServers[i].Close)
t.Cleanup(func() {
slowServers[s].Close()
})
servers[i] = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
b, err := io.ReadAll(req.Body)
require.NoError(t, err)
Expand All @@ -583,7 +591,9 @@ chainID = 1337
res.WriteHeader(http.StatusOK)
res.Write([]byte(`{"data":10}`))
}))
t.Cleanup(servers[i].Close)
t.Cleanup(func() {
servers[s].Close()
})
u, _ := url.Parse(servers[i].URL)
require.NoError(t, apps[i].BridgeORM().CreateBridgeType(&bridges.BridgeType{
Name: bridges.BridgeName(fmt.Sprintf("bridge%d", i)),
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/chaincli/handler/keeper_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
ocr2config "github.com/smartcontractkit/libocr/offchainreporting2/confighelper"
ocr2types "github.com/smartcontractkit/libocr/offchainreporting2/types"
ocr2config "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
ocr2types "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
ocr2keepers "github.com/smartcontractkit/ocr2keepers/pkg/types"
"github.com/umbracle/ethgo/abi"

Expand Down
2 changes: 1 addition & 1 deletion core/scripts/chaincli/handler/ocr2_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/olekukonko/tablewriter"
"github.com/smartcontractkit/libocr/offchainreporting2/confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
plugintypes "github.com/smartcontractkit/ocr2keepers/pkg/types"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/keeper_registry_wrapper2_0"
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/chaincli/handler/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/olekukonko/tablewriter"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
"github.com/smartcontractkit/ocr2keepers/pkg/chain"
plugintypes "github.com/smartcontractkit/ocr2keepers/pkg/types"

Expand Down
4 changes: 2 additions & 2 deletions core/scripts/functions/src/generate_ocr2_config_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

"github.com/ethereum/go-ethereum/common"

"github.com/smartcontractkit/libocr/offchainreporting2/confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"

helpers "github.com/smartcontractkit/chainlink/core/scripts/common"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/functions/config"
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230424191709-c9fec8c08e1
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.0-20230424184429-bfdf6bddb239 h1:YmYkbdM5YXVV+IWgp+5ctfplMEoXamT0LR0qsnM4eps=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.0-20230424184429-bfdf6bddb239/go.mod h1:RZzvRfGjMe4lBOT1H/MRfjnNoyUWOiHlOcHx/BZYg+M=
github.com/smartcontractkit/libocr v0.0.0-20230413082317-9561d14087cc h1:aSCDAai0Dmbhp/KHTtJnC/EJcaEz4CAO80SKRzRZiQA=
github.com/smartcontractkit/libocr v0.0.0-20230413082317-9561d14087cc/go.mod h1:5JnCHuYgmIP9ZyXzgAfI5Iwu0WxBtBKp+ApeT5o1Cjw=
github.com/smartcontractkit/libocr v0.0.0-20230413082317-9561d14087cc/go.mod h1:7Pd28puvezPJXB+xRJlcsx5CfzzkFJbMXydaAEsL4E8=
github.com/smartcontractkit/ocr2keepers v0.6.14 h1:Rg+SYd8PCyd4CcCetwnRKjVEQsHVsV6QOaWcLhi+6sg=
github.com/smartcontractkit/ocr2keepers v0.6.14/go.mod h1:gqIksJFzdXFsHfGdCWm1uTxbwvAltgcwcaqIgAStC1A=
github.com/smartcontractkit/ocr2vrf v0.0.0-20230425184732-a793ac75f0a3 h1:K71txN76a7Tf9teLEpoxsMhWXi36W2gDeicLqqa6/p0=
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/ocr2vrf/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/smartcontractkit/libocr/offchainreporting2/confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
"github.com/smartcontractkit/ocr2vrf/altbn_128"
"github.com/smartcontractkit/ocr2vrf/dkg"
"github.com/smartcontractkit/ocr2vrf/ocr2vrf"
Expand Down
4 changes: 2 additions & 2 deletions core/services/keystore/keys/ocr2key/cosmos_keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/hdevalence/ed25519consensus"
"github.com/pkg/errors"
"github.com/smartcontractkit/libocr/offchainreporting2/chains/evmutil"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/chains/evmutil"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
"golang.org/x/crypto/blake2s"

"github.com/smartcontractkit/chainlink/v2/core/utils"
Expand Down
2 changes: 1 addition & 1 deletion core/services/keystore/keys/ocr2key/cosmos_keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/stretchr/testify/assert"

ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
"github.com/stretchr/testify/require"
)

Expand Down
4 changes: 2 additions & 2 deletions core/services/keystore/keys/ocr2key/evm_keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/smartcontractkit/libocr/offchainreporting2/chains/evmutil"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/chains/evmutil"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)

var _ ocrtypes.OnchainKeyring = &evmKeyring{}
Expand Down
2 changes: 1 addition & 1 deletion core/services/keystore/keys/ocr2key/evm_keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)

func TestEVMKeyring_SignVerify(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/services/keystore/keys/ocr2key/generic_key_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"io"

"github.com/pkg/errors"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
Expand Down
2 changes: 1 addition & 1 deletion core/services/keystore/keys/ocr2key/key_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"

"github.com/ethereum/go-ethereum/crypto/secp256k1"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

starknet "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/keys"

Expand Down
2 changes: 1 addition & 1 deletion core/services/keystore/keys/ocr2key/offchain_keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"golang.org/x/crypto/curve25519"

ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)

var _ ocrtypes.OffchainKeyring = &OffchainKeyring{}
Expand Down
4 changes: 2 additions & 2 deletions core/services/keystore/keys/ocr2key/solana_keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"io"

"github.com/ethereum/go-ethereum/crypto"
"github.com/smartcontractkit/libocr/offchainreporting2/chains/evmutil"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/chains/evmutil"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)

var _ ocrtypes.OnchainKeyring = &solanaKeyring{}
Expand Down
2 changes: 1 addition & 1 deletion core/services/keystore/keys/ocr2key/solana_keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)

func TestSolanaKeyring_Sign_Verify(t *testing.T) {
Expand Down
31 changes: 30 additions & 1 deletion core/services/ocr2/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/lib/pq"
"github.com/pkg/errors"
ocrcommon "github.com/smartcontractkit/libocr/commontypes"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
"github.com/smartcontractkit/sqlx"

"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand Down Expand Up @@ -341,3 +341,32 @@ WHERE ocr2_oracle_spec_id = $1 AND time < $2

return
}

func (d *db) ReadProtocolState(ctx context.Context, configDigest ocrtypes.ConfigDigest, key string) (value []byte, err error) {
err = d.q.GetContext(ctx, &value, `
SELECT value FROM ocr_mercury_protocol_states
WHERE config_digest = $1 AND key = $2;
`, configDigest, key)

if errors.Is(err, sql.ErrNoRows) {
return nil, nil
}

err = errors.Wrapf(err, "ReadProtocolState failed for job %d", d.oracleSpecID)

return
}

func (d *db) WriteProtocolState(ctx context.Context, configDigest ocrtypes.ConfigDigest, key string, value []byte) (err error) {
if value == nil {
_, err = d.q.ExecContext(ctx, `DELETE FROM ocr_mercury_protocol_states WHERE config_digest = $1 AND key = $2;`, configDigest, key)
} else {
_, err = d.q.ExecContext(ctx, `
INSERT INTO ocr_mercury_protocol_states (config_digest, key, value) VALUES ($1, $2, $3)
ON CONFLICT (config_digest, key) DO UPDATE SET value = $3;`, configDigest, key, value)
}

err = errors.Wrapf(err, "WriteProtocolState failed for job %d", d.oracleSpecID)

return
}
75 changes: 74 additions & 1 deletion core/services/ocr2/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (

medianconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/median/config"

ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
"github.com/smartcontractkit/sqlx"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
Expand Down Expand Up @@ -414,3 +415,75 @@ func Test_DB_PendingTransmissions(t *testing.T) {
require.Len(t, m, 1)
})
}

func Test_DB_ReadWriteProtocolState(t *testing.T) {
sqlDB := setupDB(t)

cfg := configtest.NewTestGeneralConfig(t)

lggr := logger.TestLogger(t)
db := ocr2.NewDB(sqlDB, 0, lggr, cfg)
cd1 := testhelpers.MakeConfigDigest(t)
cd2 := testhelpers.MakeConfigDigest(t)
ctx := testutils.Context(t)

assertCount := func(expected int64) {
testutils.AssertCount(t, sqlDB, "ocr_mercury_protocol_states", expected)
}

t.Run("stores and retrieves protocol state", func(t *testing.T) {
assertCount(0)

err := db.WriteProtocolState(ctx, cd1, "key1", []byte{1})
assert.NoError(t, err)

assertCount(1)

err = db.WriteProtocolState(ctx, cd2, "key1", []byte{2})
assert.NoError(t, err)

assertCount(2)

err = db.WriteProtocolState(ctx, cd2, "key2", []byte{3})
assert.NoError(t, err)

assertCount(3)

// should overwrite
err = db.WriteProtocolState(ctx, cd2, "key2", []byte{4})
assert.NoError(t, err)

val, err := db.ReadProtocolState(ctx, cd1, "key1")
assert.NoError(t, err)
assert.Equal(t, []byte{1}, val)

val, err = db.ReadProtocolState(ctx, cd2, "key1")
assert.NoError(t, err)
assert.Equal(t, []byte{2}, val)

val, err = db.ReadProtocolState(ctx, cd2, "key2")
assert.NoError(t, err)
assert.Equal(t, []byte{4}, val)

// should write empty value
err = db.WriteProtocolState(ctx, cd1, "key1", []byte{})
assert.NoError(t, err)

val, err = db.ReadProtocolState(ctx, cd1, "key1")
assert.NoError(t, err)
assert.Equal(t, []byte{}, val)

assertCount(3)

// should delete value
err = db.WriteProtocolState(ctx, cd1, "key1", nil)
assert.NoError(t, err)

assertCount(2)

// trying to read missing value yields nil
val, err = db.ReadProtocolState(ctx, cd1, "key1")
assert.NoError(t, err)
assert.Nil(t, val)
})
}
12 changes: 6 additions & 6 deletions core/services/ocr2/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"

libocr2 "github.com/smartcontractkit/libocr/offchainreporting2"
ocr2types "github.com/smartcontractkit/libocr/offchainreporting2/types"
libocr2 "github.com/smartcontractkit/libocr/offchainreporting2plus"
ocr2types "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
ocr2keepers "github.com/smartcontractkit/ocr2keepers/pkg"
"github.com/smartcontractkit/ocr2vrf/altbn_128"
dkgpkg "github.com/smartcontractkit/ocr2vrf/dkg"
Expand Down Expand Up @@ -333,7 +333,7 @@ func (d *Delegate) ServicesForSpec(jb job.Job) ([]job.ServiceCtx, error) {
if err2 != nil {
return nil, err2
}
oracleArgsNoPlugin := libocr2.OracleArgs{
oracleArgsNoPlugin := libocr2.MercuryOracleArgs{
BinaryNetworkEndpointFactory: peerWrapper.Peer2,
V2Bootstrappers: bootstrapPeers,
ContractTransmitter: mercuryProvider.ContractTransmitter(),
Expand All @@ -353,7 +353,7 @@ func (d *Delegate) ServicesForSpec(jb job.Job) ([]job.ServiceCtx, error) {
me := d.monitoringEndpointGen.GenMonitoringEndpoint(spec.ContractID, synchronization.EnhancedEAMercury)
return mercury.NewServices(jb, mercuryProvider, d.pipelineRunner, runResults, lggr, oracleArgsNoPlugin, d.cfg, me)
case job.Median:
oracleArgsNoPlugin := libocr2.OracleArgs{
oracleArgsNoPlugin := libocr2.OCR2OracleArgs{
BinaryNetworkEndpointFactory: peerWrapper.Peer2,
V2Bootstrappers: bootstrapPeers,
Database: ocrDB,
Expand Down Expand Up @@ -391,7 +391,7 @@ func (d *Delegate) ServicesForSpec(jb job.Job) ([]job.ServiceCtx, error) {
return nil, err2
}
noopMonitoringEndpoint := telemetry.NoopAgent{}
oracleArgsNoPlugin := libocr2.OracleArgs{
oracleArgsNoPlugin := libocr2.OCR2OracleArgs{
BinaryNetworkEndpointFactory: peerWrapper.Peer2,
V2Bootstrappers: bootstrapPeers,
ContractTransmitter: dkgProvider.ContractTransmitter(),
Expand Down Expand Up @@ -689,7 +689,7 @@ func (d *Delegate) ServicesForSpec(jb job.Job) ([]job.ServiceCtx, error) {
return nil, err2
}

sharedOracleArgs := libocr2.OracleArgs{
sharedOracleArgs := libocr2.OCR2OracleArgs{
BinaryNetworkEndpointFactory: peerWrapper.Peer2,
V2Bootstrappers: bootstrapPeers,
ContractTransmitter: functionsProvider.ContractTransmitter(),
Expand Down
Loading

0 comments on commit d3a46cf

Please sign in to comment.