Skip to content

Commit

Permalink
support operator forwarder for ocr2 feeds manager (#10425)
Browse files Browse the repository at this point in the history
  • Loading branch information
eutopian authored Aug 31, 2023
1 parent 38b462f commit 68e2197
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 289 deletions.
13 changes: 7 additions & 6 deletions core/services/feeds/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@ func (c *OCR1Config) Scan(value interface{}) error {

// OCR2ConfigModel defines configuration for OCR2 Jobs.
type OCR2ConfigModel struct {
Enabled bool `json:"enabled"`
IsBootstrap bool `json:"is_bootstrap"`
Multiaddr null.String `json:"multiaddr"`
P2PPeerID null.String `json:"p2p_peer_id"`
KeyBundleID null.String `json:"key_bundle_id"`
Plugins Plugins `json:"plugins"`
Enabled bool `json:"enabled"`
IsBootstrap bool `json:"is_bootstrap"`
Multiaddr null.String `json:"multiaddr"`
ForwarderAddress null.String `json:"forwarder_address"`
P2PPeerID null.String `json:"p2p_peer_id"`
KeyBundleID null.String `json:"key_bundle_id"`
Plugins Plugins `json:"plugins"`
}

func (c OCR2ConfigModel) Value() (driver.Value, error) {
Expand Down
26 changes: 14 additions & 12 deletions core/services/feeds/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,20 @@ func Test_OCR2Config_Value(t *testing.T) {

var (
give = OCR2ConfigModel{
Enabled: true,
IsBootstrap: false,
Multiaddr: null.StringFrom("multiaddr"),
P2PPeerID: null.StringFrom("peerid"),
KeyBundleID: null.StringFrom("ocrkeyid"),
Enabled: true,
IsBootstrap: false,
Multiaddr: null.StringFrom("multiaddr"),
ForwarderAddress: null.StringFrom("forwarderaddress"),
P2PPeerID: null.StringFrom("peerid"),
KeyBundleID: null.StringFrom("ocrkeyid"),
Plugins: Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
},
}
want = `{"enabled":true,"is_bootstrap":false,"multiaddr":"multiaddr","p2p_peer_id":"peerid","key_bundle_id":"ocrkeyid","plugins":{"commit":true,"execute":true,"median":false,"mercury":true}}`
want = `{"enabled":true,"is_bootstrap":false,"multiaddr":"multiaddr","forwarder_address":"forwarderaddress","p2p_peer_id":"peerid","key_bundle_id":"ocrkeyid","plugins":{"commit":true,"execute":true,"median":false,"mercury":true}}`
)

val, err := give.Value()
Expand All @@ -311,13 +312,14 @@ func Test_OCR2Config_Scan(t *testing.T) {
t.Parallel()

var (
give = `{"enabled":true,"is_bootstrap":false,"multiaddr":"multiaddr","p2p_peer_id":"peerid","key_bundle_id":"ocrkeyid","plugins":{"commit":true,"execute":true,"median":false,"mercury":true}}`
give = `{"enabled":true,"is_bootstrap":false,"multiaddr":"multiaddr","forwarder_address":"forwarderaddress","p2p_peer_id":"peerid","key_bundle_id":"ocrkeyid","plugins":{"commit":true,"execute":true,"median":false,"mercury":true}}`
want = OCR2ConfigModel{
Enabled: true,
IsBootstrap: false,
Multiaddr: null.StringFrom("multiaddr"),
P2PPeerID: null.StringFrom("peerid"),
KeyBundleID: null.StringFrom("ocrkeyid"),
Enabled: true,
IsBootstrap: false,
Multiaddr: null.StringFrom("multiaddr"),
ForwarderAddress: null.StringFrom("forwarderaddress"),
P2PPeerID: null.StringFrom("peerid"),
KeyBundleID: null.StringFrom("ocrkeyid"),
Plugins: Plugins{
Commit: true,
Execute: true,
Expand Down
339 changes: 176 additions & 163 deletions core/services/feeds/proto/feeds_manager.pb.go

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions core/services/feeds/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,10 @@ func (s *service) newOCR2ConfigMsg(cfg OCR2ConfigModel) (*pb.OCR2Config, error)
}

msg := &pb.OCR2Config{
Enabled: true,
IsBootstrap: cfg.IsBootstrap,
Multiaddr: cfg.Multiaddr.ValueOrZero(),
Enabled: true,
IsBootstrap: cfg.IsBootstrap,
Multiaddr: cfg.Multiaddr.ValueOrZero(),
ForwarderAddress: cfg.ForwarderAddress.Ptr(),
Plugins: &pb.OCR2Config_Plugins{
Commit: cfg.Plugins.Commit,
Execute: cfg.Plugins.Execute,
Expand Down
21 changes: 12 additions & 9 deletions core/services/feeds/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1123,9 +1123,10 @@ func Test_Service_SyncNodeInfo(t *testing.T) {
require.NoError(t, err)

var (
multiaddr = "/dns4/chain.link/tcp/1234/p2p/16Uiu2HAm58SP7UL8zsnpeuwHfytLocaqgnyaYKP8wu7qRdrixLju"
mgr = &feeds.FeedsManager{ID: 1}
ccfg = feeds.ChainConfig{
multiaddr = "/dns4/chain.link/tcp/1234/p2p/16Uiu2HAm58SP7UL8zsnpeuwHfytLocaqgnyaYKP8wu7qRdrixLju"
mgr = &feeds.FeedsManager{ID: 1}
forwarderAddr = "0x0002"
ccfg = feeds.ChainConfig{
ID: 100,
FeedsManagerID: mgr.ID,
ChainID: "42",
Expand All @@ -1142,9 +1143,10 @@ func Test_Service_SyncNodeInfo(t *testing.T) {
KeyBundleID: null.StringFrom(ocrKey.GetID()),
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
IsBootstrap: true,
Multiaddr: null.StringFrom(multiaddr),
Enabled: true,
IsBootstrap: true,
Multiaddr: null.StringFrom(multiaddr),
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Expand Down Expand Up @@ -1192,9 +1194,10 @@ func Test_Service_SyncNodeInfo(t *testing.T) {
},
},
Ocr2Config: &proto.OCR2Config{
Enabled: true,
IsBootstrap: ccfg.OCR2Config.IsBootstrap,
Multiaddr: multiaddr,
Enabled: true,
IsBootstrap: ccfg.OCR2Config.IsBootstrap,
Multiaddr: multiaddr,
ForwarderAddress: &forwarderAddr,
Plugins: &proto.OCR2Config_Plugins{
Commit: ccfg.OCR2Config.Plugins.Commit,
Execute: ccfg.OCR2Config.Plugins.Execute,
Expand Down
4 changes: 4 additions & 0 deletions core/web/resolver/feeds_manager_chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (r *OCR2JobConfigResolver) Multiaddr() *string {
return r.cfg.Multiaddr.Ptr()
}

func (r *OCR2JobConfigResolver) ForwarderAddress() *string {
return r.cfg.ForwarderAddress.Ptr()
}

func (r *OCR2JobConfigResolver) P2PPeerID() *string {
return r.cfg.P2PPeerID.Ptr()
}
Expand Down
116 changes: 63 additions & 53 deletions core/web/resolver/feeds_manager_chain_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import (

func Test_CreateFeedsManagerChainConfig(t *testing.T) {
var (
mgrID = int64(100)
cfgID = int64(1)
chainID = "42"
accountAddr = "0x0000001"
adminAddr = "0x0000002"
peerID = null.StringFrom("p2p_12D3KooWMoejJznyDuEk5aX6GvbjaG12UzeornPCBNzMRqdwrFJw")
keyBundleID = null.StringFrom("6fdb8235e16e099de91df7ef8a8088e9deea0ed6ae106b133e5d985a8a9e1562")
mgrID = int64(100)
cfgID = int64(1)
chainID = "42"
accountAddr = "0x0000001"
adminAddr = "0x0000002"
forwarderAddr = "0x0000003"
peerID = null.StringFrom("p2p_12D3KooWMoejJznyDuEk5aX6GvbjaG12UzeornPCBNzMRqdwrFJw")
keyBundleID = null.StringFrom("6fdb8235e16e099de91df7ef8a8088e9deea0ed6ae106b133e5d985a8a9e1562")

mutation = `
mutation CreateFeedsManagerChainConfig($input: CreateFeedsManagerChainConfigInput!) {
Expand All @@ -45,21 +46,22 @@ func Test_CreateFeedsManagerChainConfig(t *testing.T) {
}`
variables = map[string]interface{}{
"input": map[string]interface{}{
"feedsManagerID": stringutils.FromInt64(mgrID),
"chainID": chainID,
"chainType": "EVM",
"accountAddr": accountAddr,
"adminAddr": adminAddr,
"fluxMonitorEnabled": false,
"ocr1Enabled": true,
"ocr1IsBootstrap": false,
"ocr1P2PPeerID": peerID.String,
"ocr1KeyBundleID": keyBundleID.String,
"ocr2Enabled": true,
"ocr2IsBootstrap": false,
"ocr2P2PPeerID": peerID.String,
"ocr2KeyBundleID": keyBundleID.String,
"ocr2Plugins": `{"commit":true,"execute":true,"median":false,"mercury":true}`,
"feedsManagerID": stringutils.FromInt64(mgrID),
"chainID": chainID,
"chainType": "EVM",
"accountAddr": accountAddr,
"adminAddr": adminAddr,
"fluxMonitorEnabled": false,
"ocr1Enabled": true,
"ocr1IsBootstrap": false,
"ocr1P2PPeerID": peerID.String,
"ocr1KeyBundleID": keyBundleID.String,
"ocr2Enabled": true,
"ocr2IsBootstrap": false,
"ocr2P2PPeerID": peerID.String,
"ocr2KeyBundleID": keyBundleID.String,
"ocr2Plugins": `{"commit":true,"execute":true,"median":false,"mercury":true}`,
"ocr2ForwarderAddress": forwarderAddr,
},
}
)
Expand All @@ -86,9 +88,10 @@ func Test_CreateFeedsManagerChainConfig(t *testing.T) {
KeyBundleID: keyBundleID,
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Expand All @@ -112,9 +115,10 @@ func Test_CreateFeedsManagerChainConfig(t *testing.T) {
KeyBundleID: keyBundleID,
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Expand Down Expand Up @@ -265,9 +269,12 @@ func Test_DeleteFeedsManagerChainConfig(t *testing.T) {

func Test_UpdateFeedsManagerChainConfig(t *testing.T) {
var (
cfgID = int64(1)
peerID = null.StringFrom("p2p_12D3KooWMoejJznyDuEk5aX6GvbjaG12UzeornPCBNzMRqdwrFJw")
keyBundleID = null.StringFrom("6fdb8235e16e099de91df7ef8a8088e9deea0ed6ae106b133e5d985a8a9e1562")
cfgID = int64(1)
peerID = null.StringFrom("p2p_12D3KooWMoejJznyDuEk5aX6GvbjaG12UzeornPCBNzMRqdwrFJw")
keyBundleID = null.StringFrom("6fdb8235e16e099de91df7ef8a8088e9deea0ed6ae106b133e5d985a8a9e1562")
accountAddr = "0x0000001"
adminAddr = "0x0000002"
forwarderAddr = "0x0000003"

mutation = `
mutation UpdateFeedsManagerChainConfig($id: ID!, $input: UpdateFeedsManagerChainConfigInput!) {
Expand All @@ -293,18 +300,19 @@ func Test_UpdateFeedsManagerChainConfig(t *testing.T) {
variables = map[string]interface{}{
"id": "1",
"input": map[string]interface{}{
"accountAddr": "0x0000001",
"adminAddr": "0x0000001",
"fluxMonitorEnabled": false,
"ocr1Enabled": true,
"ocr1IsBootstrap": false,
"ocr1P2PPeerID": peerID.String,
"ocr1KeyBundleID": keyBundleID.String,
"ocr2Enabled": true,
"ocr2IsBootstrap": false,
"ocr2P2PPeerID": peerID.String,
"ocr2KeyBundleID": keyBundleID.String,
"ocr2Plugins": `{"commit":true,"execute":true,"median":false,"mercury":true}`,
"accountAddr": accountAddr,
"adminAddr": adminAddr,
"fluxMonitorEnabled": false,
"ocr1Enabled": true,
"ocr1IsBootstrap": false,
"ocr1P2PPeerID": peerID.String,
"ocr1KeyBundleID": keyBundleID.String,
"ocr2Enabled": true,
"ocr2IsBootstrap": false,
"ocr2P2PPeerID": peerID.String,
"ocr2KeyBundleID": keyBundleID.String,
"ocr2Plugins": `{"commit":true,"execute":true,"median":false,"mercury":true}`,
"ocr2ForwarderAddress": forwarderAddr,
},
}
)
Expand All @@ -318,8 +326,8 @@ func Test_UpdateFeedsManagerChainConfig(t *testing.T) {
f.App.On("GetFeedsService").Return(f.Mocks.feedsSvc)
f.Mocks.feedsSvc.On("UpdateChainConfig", mock.Anything, feeds.ChainConfig{
ID: cfgID,
AccountAddress: "0x0000001",
AdminAddress: "0x0000001",
AccountAddress: accountAddr,
AdminAddress: adminAddr,
FluxMonitorConfig: feeds.FluxMonitorConfig{
Enabled: false,
},
Expand All @@ -329,9 +337,10 @@ func Test_UpdateFeedsManagerChainConfig(t *testing.T) {
KeyBundleID: null.StringFrom(keyBundleID.String),
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Expand All @@ -342,8 +351,8 @@ func Test_UpdateFeedsManagerChainConfig(t *testing.T) {
}).Return(cfgID, nil)
f.Mocks.feedsSvc.On("GetChainConfig", cfgID).Return(&feeds.ChainConfig{
ID: cfgID,
AccountAddress: "0x0000001",
AdminAddress: "0x0000001",
AccountAddress: accountAddr,
AdminAddress: adminAddr,
FluxMonitorConfig: feeds.FluxMonitorConfig{
Enabled: false,
},
Expand All @@ -353,9 +362,10 @@ func Test_UpdateFeedsManagerChainConfig(t *testing.T) {
KeyBundleID: null.StringFrom(keyBundleID.String),
},
OCR2Config: feeds.OCR2ConfigModel{
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
Enabled: true,
P2PPeerID: peerID,
KeyBundleID: keyBundleID,
ForwarderAddress: null.StringFrom(forwarderAddr),
Plugins: feeds.Plugins{
Commit: true,
Execute: true,
Expand Down
Loading

0 comments on commit 68e2197

Please sign in to comment.