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 7abd46d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 45 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"OffchainConfigVersion": 30,
"OnchainConfig": "0x",
"Signers": [
"0xbB9dA64fEfbAe323B45Ec98970863279824cf08D",
"0x26F04f488F6383Cd4099b7aEF16c0DC2e553aDDA",
"0xD754a628C5B34D027e4ccd8d90B54b9403A9B5f2",
"0xe366aEd6fe28F47cC2c463Cda40d4BB8573e15D4",
"0x405Aeb4fa9359A7338217bFc4Fdc77C886A6a6Ee"
"011400bb9da64fefbae323b45ec98970863279824cf08d",
"01140026f04f488f6383cd4099b7aef16c0dc2e553adda",
"011400d754a628c5b34d027e4ccd8d90b54b9403a9b5f2",
"011400e366aed6fe28f47cc2c463cda40d4bb8573e15d4",
"011400405aeb4fa9359a7338217bfc4fdc77c886a6a6ee"
],
"Transmitters": [
"0x9DfB1E962Fc6363087fB60A131aba2b7884dAD97",
Expand Down

0 comments on commit 7abd46d

Please sign in to comment.