Skip to content

Commit

Permalink
chore(cre-deployment): validate ocr xmission schedule (#16265)
Browse files Browse the repository at this point in the history
* chore(cre-deployment): validate ocr xmission schedule

* fix tests
  • Loading branch information
krehermann authored and karen-stepanyan committed Feb 10, 2025
1 parent 0638497 commit a36df69
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
16 changes: 9 additions & 7 deletions deployment/keystone/changeset/deploy_ocr3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ func TestDeployOCR3(t *testing.T) {
func TestConfigureOCR3(t *testing.T) {
t.Parallel()

nWfNodes := 4
c := internal.OracleConfig{
MaxFaultyOracles: 1,
DeltaProgressMillis: 12345,
MaxFaultyOracles: 1,
DeltaProgressMillis: 12345,
TransmissionSchedule: []int{nWfNodes},
}

t.Run("no mcms", func(t *testing.T) {
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
WFDonConfig: test.DonConfig{N: nWfNodes},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
Expand Down Expand Up @@ -86,7 +88,7 @@ func TestConfigureOCR3(t *testing.T) {

t.Run("success multiple OCR3 contracts", func(t *testing.T) {
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
WFDonConfig: test.DonConfig{N: nWfNodes},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
Expand Down Expand Up @@ -154,7 +156,7 @@ func TestConfigureOCR3(t *testing.T) {

t.Run("fails multiple OCR3 contracts but unspecified address", func(t *testing.T) {
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
WFDonConfig: test.DonConfig{N: nWfNodes},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
Expand Down Expand Up @@ -197,7 +199,7 @@ func TestConfigureOCR3(t *testing.T) {

t.Run("fails multiple OCR3 contracts but address not found", func(t *testing.T) {
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
WFDonConfig: test.DonConfig{N: nWfNodes},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
Expand Down Expand Up @@ -242,7 +244,7 @@ func TestConfigureOCR3(t *testing.T) {

t.Run("mcms", func(t *testing.T) {
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
WFDonConfig: test.DonConfig{N: nWfNodes},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
Expand Down
4 changes: 4 additions & 0 deletions deployment/keystone/changeset/internal/ocr3config.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func (c *OCR2OracleConfig) UnmarshalJSON(data []byte) error {
}

func GenerateOCR3Config(cfg OracleConfig, nca []NodeKeys, secrets deployment.OCRSecrets) (OCR2OracleConfig, error) {
// the transmission schedule is very specific; arguably it should be not be a parameter
if len(cfg.TransmissionSchedule) != 1 || cfg.TransmissionSchedule[0] != len(nca) {
return OCR2OracleConfig{}, fmt.Errorf("transmission schedule must have exactly one entry, matching the len of the number of nodes want [%d], got %v", len(nca), cfg.TransmissionSchedule)
}
onchainPubKeys := [][]byte{}
allPubKeys := map[string]any{}
if secrets.IsEmpty() {
Expand Down
32 changes: 32 additions & 0 deletions deployment/keystone/changeset/internal/ocr3config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,38 @@ func Test_configureOCR3Request_generateOCR3Config(t *testing.T) {
b, err := json.MarshalIndent(got, "", " ")
require.NoError(t, err)
require.Equal(t, wantOCR3Config, string(b))

t.Run("no multiple transmitters", func(t *testing.T) {
cfg2 := cfg
cfg2.TransmissionSchedule = []int{}
for i := 1; i <= len(nodes); i++ {
cfg2.TransmissionSchedule = append(cfg2.TransmissionSchedule, i)
}
r := configureOCR3Request{
cfg: &cfg2,
nodes: nodes,
chain: deployment.Chain{
Selector: chain_selectors.ETHEREUM_TESTNET_SEPOLIA.Selector,
},
ocrSecrets: deployment.XXXGenerateTestOCRSecrets(),
}
_, err := r.generateOCR3Config()
require.Error(t, err)
})
t.Run("transmitter schedule eqaul num nodes", func(t *testing.T) {
cfg2 := cfg
cfg2.TransmissionSchedule = []int{len(nodes) + 1}
r := configureOCR3Request{
cfg: &cfg2,
nodes: nodes,
chain: deployment.Chain{
Selector: chain_selectors.ETHEREUM_TESTNET_SEPOLIA.Selector,
},
ocrSecrets: deployment.XXXGenerateTestOCRSecrets(),
}
_, err := r.generateOCR3Config()
require.Error(t, err)
})
}

func loadTestData(t *testing.T, path string) []deployment.Node {
Expand Down
3 changes: 2 additions & 1 deletion deployment/keystone/changeset/test/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ func SetupTestEnv(t *testing.T, c TestConfig) TestEnv {
require.NoError(t, err)

var ocr3Config = internal.OracleConfig{
MaxFaultyOracles: len(wfNodes) / 3,
MaxFaultyOracles: len(wfNodes) / 3,
TransmissionSchedule: []int{len(wfNodes)},
}
var allDons = []internal.DonCapabilities{wfDon, cwDon, assetDon}

Expand Down

0 comments on commit a36df69

Please sign in to comment.