Skip to content

Commit

Permalink
Add onchainSigningStrategy job spec field support (#12909)
Browse files Browse the repository at this point in the history
* Adds `onchainSigningStrategy` job spec field support

* Makes changeset internal

* Fixes typo and remove unnecessary logs

* Stores `onchain_signing_strategy` values in the DB

* Fixes test error
  • Loading branch information
vyzaldysanchez authored Apr 25, 2024
1 parent 365c38b commit fa5b227
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-knives-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#internal Generic Plugin `onchainSigningStrategy` support
5 changes: 5 additions & 0 deletions core/services/job/job_orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ observationSource = """
chainID = 1
fromBlock = 1000
[onchainSigningStrategy]
strategyName = 'single-chain'
[onchainSigningStrategy.config]
publicKey = '8fa807463ad73f9ee855cfd60ba406dcf98a2855b3dd8af613107b0f6890a707'
[pluginConfig]
serverURL = 'wss://localhost:8080'
serverPubKey = '8fa807463ad73f9ee855cfd60ba406dcf98a2855b3dd8af613107b0f6890a707'
Expand Down
1 change: 1 addition & 0 deletions core/services/job/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ type OCR2OracleSpec struct {
BlockchainTimeout models.Interval `toml:"blockchainTimeout"`
ContractConfigTrackerPollInterval models.Interval `toml:"contractConfigTrackerPollInterval"`
ContractConfigConfirmations uint16 `toml:"contractConfigConfirmations"`
OnchainSigningStrategy JSONConfig `toml:"onchainSigningStrategy"`
PluginConfig JSONConfig `toml:"pluginConfig"`
PluginType types.OCR2PluginType `toml:"pluginType"`
CreatedAt time.Time `toml:"-"`
Expand Down
7 changes: 7 additions & 0 deletions core/services/job/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ func TestOCR2OracleSpec(t *testing.T) {
},
},
},
OnchainSigningStrategy: map[string]interface{}{
"strategyName": "single-chain",
"config": map[string]interface{}{
"evm": "",
"publicKey": "0xdeadbeef",
},
},
PluginConfig: map[string]interface{}{"juelsPerFeeCoinSource": ` // data source 1
ds1 [type=bridge name="%s"];
ds1_parse [type=jsonparse path="data"];
Expand Down
4 changes: 2 additions & 2 deletions core/services/job/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@ func (o *orm) insertOCROracleSpec(ctx context.Context, spec *OCROracleSpec) (spe
}

func (o *orm) insertOCR2OracleSpec(ctx context.Context, spec *OCR2OracleSpec) (specID int32, err error) {
return o.prepareQuerySpecID(ctx, `INSERT INTO ocr2_oracle_specs (contract_id, feed_id, relay, relay_config, plugin_type, plugin_config, p2pv2_bootstrappers, ocr_key_bundle_id, transmitter_id,
return o.prepareQuerySpecID(ctx, `INSERT INTO ocr2_oracle_specs (contract_id, feed_id, relay, relay_config, plugin_type, plugin_config, onchain_signing_strategy, p2pv2_bootstrappers, ocr_key_bundle_id, transmitter_id,
blockchain_timeout, contract_config_tracker_poll_interval, contract_config_confirmations,
created_at, updated_at)
VALUES (:contract_id, :feed_id, :relay, :relay_config, :plugin_type, :plugin_config, :p2pv2_bootstrappers, :ocr_key_bundle_id, :transmitter_id,
VALUES (:contract_id, :feed_id, :relay, :relay_config, :plugin_type, :plugin_config, :onchain_signing_strategy, :p2pv2_bootstrappers, :ocr_key_bundle_id, :transmitter_id,
:blockchain_timeout, :contract_config_tracker_poll_interval, :contract_config_confirmations,
NOW(), NOW())
RETURNING id;`, spec)
Expand Down
7 changes: 7 additions & 0 deletions core/services/job/testdata/compact.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,12 @@ LatestTransmissionDetails = "{\n \"chainSpecificName\": \"latestTransmissionDet
[relayConfig.codec.configs.MedianReport]
typeABI = "[\n {\n \"Name\": \"Timestamp\",\n \"Type\": \"uint32\"\n },\n {\n \"Name\": \"Observers\",\n \"Type\": \"bytes32\"\n },\n {\n \"Name\": \"Observations\",\n \"Type\": \"int192[]\"\n },\n {\n \"Name\": \"JuelsPerFeeCoin\",\n \"Type\": \"int192\"\n }\n]\n"

[onchainSigningStrategy]
strategyName = 'single-chain'

[onchainSigningStrategy.config]
evm = ''
publicKey = '0xdeadbeef'

[pluginConfig]
juelsPerFeeCoinSource = " // data source 1\n ds1 [type=bridge name=\"%s\"];\n ds1_parse [type=jsonparse path=\"data\"];\n ds1_multiply [type=multiply times=2];\n\n // data source 2\n ds2 [type=http method=GET url=\"%s\"];\n ds2_parse [type=jsonparse path=\"data\"];\n ds2_multiply [type=multiply times=2];\n\n ds1 -> ds1_parse -> ds1_multiply -> answer1;\n ds2 -> ds2_parse -> ds2_multiply -> answer1;\n\n answer1 [type=median index=0];\n"
7 changes: 7 additions & 0 deletions core/services/job/testdata/pretty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ typeABI = '''
]
'''

[onchainSigningStrategy]
strategyName = 'single-chain'

[onchainSigningStrategy.config]
evm = ''
publicKey = '0xdeadbeef'

[pluginConfig]
juelsPerFeeCoinSource = """
// data source 1
Expand Down
4 changes: 2 additions & 2 deletions core/services/ocr2/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func MustInsertOCROracleSpec(t *testing.T, db *sqlx.DB, transmitterAddress types

require.NoError(t, db.Get(&spec, `INSERT INTO ocr2_oracle_specs (
relay, relay_config, contract_id, p2pv2_bootstrappers, ocr_key_bundle_id, monitoring_endpoint, transmitter_id,
blockchain_timeout, contract_config_tracker_poll_interval, contract_config_confirmations, plugin_type, plugin_config, created_at, updated_at) VALUES (
blockchain_timeout, contract_config_tracker_poll_interval, contract_config_confirmations, plugin_type, plugin_config, onchain_signing_strategy, created_at, updated_at) VALUES (
'ethereum', '{}', $1, '{}', $2, $3, $4,
0, 0, 0, 'median', $5, NOW(), NOW()
0, 0, 0, 'median', $5, '{}', NOW(), NOW()
) RETURNING *`, cltest.NewEIP55Address().String(), cltest.DefaultOCR2KeyBundleID, "chain.link:1234", transmitterAddress.String(), jsonConfig))
return spec
}
Expand Down
8 changes: 8 additions & 0 deletions core/services/ocr2/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
ocr2keepers21 "github.com/smartcontractkit/chainlink-automation/pkg/v3/plugin"
"github.com/smartcontractkit/chainlink-common/pkg/loop/reportingplugins/ocr3"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"

"github.com/smartcontractkit/chainlink/v2/core/config/env"

"github.com/smartcontractkit/chainlink-vrf/altbn_128"
Expand Down Expand Up @@ -539,6 +540,13 @@ func (d *Delegate) newServicesGenericPlugin(
if err != nil {
return nil, err
}
// NOTE: we don't need to validate the strategy, since that happens as part of creating the job.
// See: validate/validate.go's `validateSpec`.
onchainSigningStrategy := validate.OCR2OnchainSigningStrategy{}
err = json.Unmarshal(spec.OnchainSigningStrategy.Bytes(), &onchainSigningStrategy)
if err != nil {
return nil, err
}

plugEnv := env.NewPlugin(pCfg.PluginName)

Expand Down
48 changes: 48 additions & 0 deletions core/services/ocr2/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/loop/reportingplugins"
"github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink/v2/core/config/env"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
dkgconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/dkg/config"
Expand Down Expand Up @@ -172,6 +173,40 @@ func (o *OCR2GenericPluginConfig) UnmarshalJSON(data []byte) error {
return nil
}

type onchainSigningStrategyInner struct {
StrategyName string `json:"strategyName"`
Config job.JSONConfig `json:"config"`
}

type OCR2OnchainSigningStrategy struct {
onchainSigningStrategyInner
}

func (o *OCR2OnchainSigningStrategy) UnmarshalJSON(data []byte) error {
err := json.Unmarshal(data, &o.onchainSigningStrategyInner)
if err != nil {
return err
}

return nil
}

func (o *OCR2OnchainSigningStrategy) IsMultiChain() bool {
return o.StrategyName == "multi-chain"
}

func (o *OCR2OnchainSigningStrategy) PublicKey() (string, error) {
pk, ok := o.Config["publicKey"]
if !ok {
return "", nil
}
name, ok := pk.(string)
if !ok {
return "", fmt.Errorf("expected string publicKey value, but got: %T", pk)
}
return name, nil
}

func validateGenericPluginSpec(ctx context.Context, spec *job.OCR2OracleSpec, rc plugins.RegistrarConfig) error {
p := OCR2GenericPluginConfig{}
err := json.Unmarshal(spec.PluginConfig.Bytes(), &p)
Expand All @@ -187,6 +222,19 @@ func validateGenericPluginSpec(ctx context.Context, spec *job.OCR2OracleSpec, rc
return errors.New("generic config invalid: only OCR version 2 and 3 are supported")
}

onchainSigningStrategy := OCR2OnchainSigningStrategy{}
err = json.Unmarshal(spec.OnchainSigningStrategy.Bytes(), &onchainSigningStrategy)
if err != nil {
return err
}
pk, err := onchainSigningStrategy.PublicKey()
if err != nil {
return err
}
if pk == "" {
return errors.New("generic config invalid: must provide public key for the onchain signing strategy")
}

plugEnv := env.NewPlugin(p.PluginName)

command := p.Command
Expand Down
Loading

0 comments on commit fa5b227

Please sign in to comment.