-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(keystone): support multiple OCR3 contracts #15803
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0cdba03
feat(keystone): enable multiple OCR contracts per chain
MStreet3 969a96a
fix(keystone/changeset): use common.Address vs string
MStreet3 56c1438
chore(keystone/changeset): adds unit test
MStreet3 0b428a8
lint(keystone/changeset): fixes loop var lint
MStreet3 4d594bd
refactor(keystone/changeset): move OCR3 selector func and add logs
MStreet3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package internal | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
|
@@ -28,7 +29,7 @@ type GetContractSetsResponse struct { | |
|
||
type ContractSet struct { | ||
commonchangeset.MCMSWithTimelockState | ||
OCR3 *ocr3_capability.OCR3Capability | ||
OCR3 map[common.Address]*ocr3_capability.OCR3Capability | ||
Forwarder *forwarder.KeystoneForwarder | ||
CapabilitiesRegistry *capabilities_registry.CapabilitiesRegistry | ||
WorkflowRegistry *workflow_registry.WorkflowRegistry | ||
|
@@ -37,7 +38,9 @@ type ContractSet struct { | |
func (cs ContractSet) TransferableContracts() []common.Address { | ||
var out []common.Address | ||
if cs.OCR3 != nil { | ||
out = append(out, cs.OCR3.Address()) | ||
for _, ocr := range cs.OCR3 { | ||
out = append(out, ocr.Address()) | ||
} | ||
} | ||
if cs.Forwarder != nil { | ||
out = append(out, cs.Forwarder.Address()) | ||
|
@@ -63,6 +66,10 @@ func (cs ContractSet) View() (view.KeystoneChainView, error) { | |
return out, nil | ||
} | ||
|
||
func (cs ContractSet) GetOCR3Contract(addr *common.Address) (*ocr3_capability.OCR3Capability, error) { | ||
return getOCR3Contract(cs.OCR3, addr) | ||
} | ||
|
||
func GetContractSets(lggr logger.Logger, req *GetContractSetsRequest) (*GetContractSetsResponse, error) { | ||
resp := &GetContractSetsResponse{ | ||
ContractSets: make(map[uint64]ContractSet), | ||
|
@@ -109,7 +116,10 @@ func loadContractSet(lggr logger.Logger, chain deployment.Chain, addresses map[s | |
if err != nil { | ||
return nil, fmt.Errorf("failed to create OCR3Capability contract from address %s: %w", addr, err) | ||
} | ||
out.OCR3 = c | ||
if out.OCR3 == nil { | ||
out.OCR3 = make(map[common.Address]*ocr3_capability.OCR3Capability) | ||
} | ||
out.OCR3[common.HexToAddress(addr)] = c | ||
case WorkflowRegistry: | ||
c, err := workflow_registry.NewWorkflowRegistry(common.HexToAddress(addr), chain.Client) | ||
if err != nil { | ||
|
@@ -123,3 +133,35 @@ func loadContractSet(lggr logger.Logger, chain deployment.Chain, addresses map[s | |
} | ||
return &out, nil | ||
} | ||
|
||
// getOCR3Contract returns the OCR3 contract from the contract set. By default, it returns the only | ||
// contract in the set if there is no address specified. If an address is specified, it returns the | ||
// contract with that address. If the address is specified but not found in the contract set, it returns | ||
// an error. | ||
func getOCR3Contract(contracts map[common.Address]*ocr3_capability.OCR3Capability, addr *common.Address) (*ocr3_capability.OCR3Capability, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MStreet3 Style nit: IMO this feels a bit like premature optimization -- why not just inline this code into the ContractSet GetOCR3Contract method? |
||
// Fail if the OCR3 contract address is unspecified and there are multiple OCR3 contracts | ||
if addr == nil && len(contracts) > 1 { | ||
return nil, errors.New("OCR contract address is unspecified") | ||
} | ||
|
||
// Use the first OCR3 contract if the address is unspecified | ||
if addr == nil && len(contracts) == 1 { | ||
// use the first OCR3 contract | ||
for _, c := range contracts { | ||
return c, nil | ||
} | ||
} | ||
|
||
// Select the OCR3 contract by address | ||
if contract, ok := contracts[*addr]; ok { | ||
return contract, nil | ||
} | ||
|
||
addrSet := make([]string, 0, len(contracts)) | ||
for a := range contracts { | ||
addrSet = append(addrSet, a.String()) | ||
} | ||
|
||
// Fail if the OCR3 contract address is specified but not found in the contract set | ||
return nil, fmt.Errorf("OCR3 contract address %s not found in contract set %v", *addr, addrSet) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MStreet3 How come we need to both log + return an error here? Does the returned error not get bubbled up to the user when executing the changeset?