Skip to content

Commit

Permalink
add rebalancer support for feeds manager ocr2 plugins (#12344)
Browse files Browse the repository at this point in the history
  • Loading branch information
eutopian authored and kidambisrinivas committed Mar 18, 2024
1 parent 6f61d04 commit 7db34f0
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 210 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-turtles-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Add rebalancer support for feeds manager ocr2 plugins
22 changes: 13 additions & 9 deletions core/services/feeds/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ const (
type PluginType string

const (
PluginTypeCommit PluginType = "COMMIT"
PluginTypeExecute PluginType = "EXECUTE"
PluginTypeMedian PluginType = "MEDIAN"
PluginTypeMercury PluginType = "MERCURY"
PluginTypeUnknown PluginType = "UNKNOWN"
PluginTypeCommit PluginType = "COMMIT"
PluginTypeExecute PluginType = "EXECUTE"
PluginTypeMedian PluginType = "MEDIAN"
PluginTypeMercury PluginType = "MERCURY"
PluginTypeRebalancer PluginType = "REBALANCER"
PluginTypeUnknown PluginType = "UNKNOWN"
)

func FromPluginTypeInput(pt PluginType) string {
Expand All @@ -44,16 +45,19 @@ func ToPluginType(s string) (PluginType, error) {
return PluginTypeMedian, nil
case "mercury":
return PluginTypeMercury, nil
case "rebalancer":
return PluginTypeRebalancer, nil
default:
return PluginTypeUnknown, errors.New("unknown plugin type")
}
}

type Plugins struct {
Commit bool `json:"commit"`
Execute bool `json:"execute"`
Median bool `json:"median"`
Mercury bool `json:"mercury"`
Commit bool `json:"commit"`
Execute bool `json:"execute"`
Median bool `json:"median"`
Mercury bool `json:"mercury"`
Rebalancer bool `json:"rebalancer"`
}

func (p Plugins) Value() (driver.Value, error) {
Expand Down
49 changes: 29 additions & 20 deletions core/services/feeds/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func Test_ToPluginType(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, pt, PluginTypeMercury)

pt, err = ToPluginType("rebalancer")
require.NoError(t, err)
assert.Equal(t, pt, PluginTypeRebalancer)

pt, err = ToPluginType("xxx")
require.Error(t, err)
assert.Equal(t, pt, PluginTypeUnknown)
Expand All @@ -77,6 +81,7 @@ func Test_FromPluginType(t *testing.T) {
assert.Equal(t, "execute", FromPluginTypeInput(PluginTypeExecute))
assert.Equal(t, "median", FromPluginTypeInput(PluginTypeMedian))
assert.Equal(t, "mercury", FromPluginTypeInput(PluginTypeMercury))
assert.Equal(t, "rebalancer", FromPluginTypeInput(PluginTypeRebalancer))
assert.Equal(t, "unknown", FromPluginTypeInput(PluginTypeUnknown))
}

Expand Down Expand Up @@ -241,12 +246,13 @@ func Test_Plugins_Value(t *testing.T) {

var (
give = Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Rebalancer: false,
}
want = `{"commit":true,"execute":true,"median":false,"mercury":true}`
want = `{"commit":true,"execute":true,"median":false,"mercury":true,"rebalancer":false}`
)

val, err := give.Value()
Expand All @@ -262,12 +268,13 @@ func Test_Plugins_Scan(t *testing.T) {
t.Parallel()

var (
give = `{"commit":true,"execute":true,"median":false,"mercury":true}`
give = `{"commit":true,"execute":true,"median":false,"mercury":true,"rebalancer":false}`
want = Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Rebalancer: false,
}
)

Expand All @@ -290,13 +297,14 @@ func Test_OCR2Config_Value(t *testing.T) {
P2PPeerID: null.StringFrom("peerid"),
KeyBundleID: null.StringFrom("ocrkeyid"),
Plugins: Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Rebalancer: false,
},
}
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}}`
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,"rebalancer":false}}`
)

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

var (
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}}`
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,"rebalancer":false}}`
want = OCR2ConfigModel{
Enabled: true,
IsBootstrap: false,
Expand All @@ -321,10 +329,11 @@ func Test_OCR2Config_Scan(t *testing.T) {
P2PPeerID: null.StringFrom("peerid"),
KeyBundleID: null.StringFrom("ocrkeyid"),
Plugins: Plugins{
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Commit: true,
Execute: true,
Median: false,
Mercury: true,
Rebalancer: false,
},
}
)
Expand Down
Loading

0 comments on commit 7db34f0

Please sign in to comment.