Skip to content

Commit

Permalink
Keep OCR3 and OCR2 config separate
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryNguyen5 committed Sep 18, 2024
1 parent 9c49773 commit eaad372
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 40 deletions.
1 change: 0 additions & 1 deletion core/scripts/keystone/src/01_deploy_contracts_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func deploy(
configFile,
env.ChainID,
publicKeys,
OnChainTransmitter,
)

if dryRun {
Expand Down
47 changes: 9 additions & 38 deletions core/scripts/keystone/src/88_gen_ocr3_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ type NodeKeys struct {
}

type orc2drOracleConfig struct {
Signers [][]byte
// populated when transmitterType == OnChainTransmitter
Transmitters []common.Address
// populated when transmitterType == OffChainTransmitter
OffChainTransmitters [][32]byte
Signers [][]byte
Transmitters []common.Address
F uint8
OnchainConfig []byte
OffchainConfigVersion uint64
Expand Down Expand Up @@ -107,17 +104,10 @@ func mustReadConfig(fileName string) (output TopLevelConfigSource) {
return mustParseJSON[TopLevelConfigSource](fileName)
}

type TransmitterType string

const (
OnChainTransmitter TransmitterType = "onchain"
OffChainTransmitter TransmitterType = "offchain"
)

func generateOCR3Config(nodeList string, configFile string, chainID int64, pubKeysPath string, transmitterType TransmitterType, kbIndex ...int) orc2drOracleConfig {
func generateOCR3Config(nodeList string, configFile string, chainID int64, pubKeysPath string) orc2drOracleConfig {
topLevelCfg := mustReadConfig(configFile)
cfg := topLevelCfg.OracleConfig
nca := downloadNodePubKeys(nodeList, chainID, pubKeysPath, kbIndex...)
nca := downloadNodePubKeys(nodeList, chainID, pubKeysPath)

onchainPubKeys := [][]byte{}
allPubKeys := map[string]any{}
Expand All @@ -144,7 +134,6 @@ func generateOCR3Config(nodeList string, configFile string, chainID int64, pubKe

offchainPubKeysBytes := []types.OffchainPublicKey{}
for _, n := range nca {

pkBytesFixed := strToBytes32(n.OCR2OffchainPublicKey)
offchainPubKeysBytes = append(offchainPubKeysBytes, types.OffchainPublicKey(pkBytesFixed))
}
Expand All @@ -157,20 +146,12 @@ func generateOCR3Config(nodeList string, configFile string, chainID int64, pubKe

identities := []confighelper.OracleIdentityExtra{}
for index := range nca {
var transmitterAccount types.Account
if transmitterType == OnChainTransmitter {
transmitterAccount = types.Account(nca[index].EthAddress)
}
if transmitterType == OffChainTransmitter {
transmitterAccount = types.Account(fmt.Sprintf("%x", nca[index].CSAPublicKey[:]))
}

identities = append(identities, confighelper.OracleIdentityExtra{
OracleIdentity: confighelper.OracleIdentity{
OnchainPublicKey: onchainPubKeys[index][:],
OffchainPublicKey: offchainPubKeysBytes[index],
PeerID: nca[index].P2PPeerID,
TransmitAccount: transmitterAccount,
TransmitAccount: types.Account(nca[index].EthAddress),
},
ConfigEncryptionPublicKey: configPubKeysBytes[index],
})
Expand Down Expand Up @@ -202,26 +183,16 @@ func generateOCR3Config(nodeList string, configFile string, chainID int64, pubKe
configSigners = append(configSigners, signer)
}

transmitterAddresses, err := evm.AccountToAddress(transmitters)
PanicErr(err)

config := orc2drOracleConfig{
Signers: configSigners,
F: f,
OnchainConfig: onchainConfig,
OffchainConfigVersion: offchainConfigVersion,
OffchainConfig: offchainConfig,
}

if transmitterType == OnChainTransmitter {
transmitterAddresses, err := evm.AccountToAddress(transmitters)
PanicErr(err)
config.Transmitters = transmitterAddresses
}
if transmitterType == OffChainTransmitter {
var offChainTransmitters [][32]byte
for _, n := range nca {
fmt.Println("CSAPublicKey", n.CSAPublicKey)
offChainTransmitters = append(offChainTransmitters, strToBytes32(n.CSAPublicKey))
}
config.OffChainTransmitters = offChainTransmitters
Transmitters: transmitterAddresses,
}

return config
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/keystone/src/88_gen_ocr3_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestGenerateOCR3Config(t *testing.T) {
// Generate OCR3 config
config := generateOCR3Config(".cache/NodeList.txt", "./testdata/SampleConfig.json", 1337, "./testdata/PublicKeys.json", OnChainTransmitter)
config := generateOCR3Config(".cache/NodeList.txt", "./testdata/SampleConfig.json", 1337, "./testdata/PublicKeys.json")

matchOffchainConfig := match.Custom("OffchainConfig", func(s any) (any, error) {
// coerce the value to a string
Expand Down

0 comments on commit eaad372

Please sign in to comment.