Skip to content

Commit

Permalink
Add account address pub key to fms chain config for Starknet (#13421)
Browse files Browse the repository at this point in the history
* add account address pub key to fms chain config for starknet

* Update core/web/resolver/feeds_manager_chain_config.go

Co-authored-by: Chris De Leon <147140544+chris-de-leon-cll@users.noreply.github.com>

---------

Co-authored-by: Chris De Leon <147140544+chris-de-leon-cll@users.noreply.github.com>
  • Loading branch information
eutopian and chris-de-leon-cll authored Jun 6, 2024
1 parent 000f2cb commit c429772
Show file tree
Hide file tree
Showing 13 changed files with 358 additions and 260 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-experts-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

#db_update Add account_address_public_key to feeds_manager_chain_configs
30 changes: 17 additions & 13 deletions core/services/feeds/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ func (p *Plugins) Scan(value interface{}) error {
type ChainType string

const (
ChainTypeUnknown ChainType = "UNKNOWN"
ChainTypeEVM ChainType = "EVM"
ChainTypeUnknown ChainType = "UNKNOWN"
ChainTypeEVM ChainType = "EVM"
ChainTypeStarknet ChainType = "STARKNET"
)

func NewChainType(s string) (ChainType, error) {
switch s {
case "EVM":
return ChainTypeEVM, nil
case "STARKNET":
return ChainTypeStarknet, nil
default:
return ChainTypeUnknown, errors.New("invalid chain type")
}
Expand All @@ -103,17 +106,18 @@ type FeedsManager struct {

// ChainConfig defines the chain configuration for a Feeds Manager.
type ChainConfig struct {
ID int64
FeedsManagerID int64
ChainID string
ChainType ChainType
AccountAddress string
AdminAddress string
FluxMonitorConfig FluxMonitorConfig
OCR1Config OCR1Config
OCR2Config OCR2ConfigModel
CreatedAt time.Time
UpdatedAt time.Time
ID int64
FeedsManagerID int64
ChainID string
ChainType ChainType
AccountAddress string
AccountAddressPublicKey null.String
AdminAddress string
FluxMonitorConfig FluxMonitorConfig
OCR1Config OCR1Config
OCR2Config OCR2ConfigModel
CreatedAt time.Time
UpdatedAt time.Time
}

// FluxMonitorConfig defines configuration for FluxMonitorJobs.
Expand Down
5 changes: 5 additions & 0 deletions core/services/feeds/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func Test_NewChainType(t *testing.T) {
give: "EVM",
want: ChainTypeEVM,
},
{
name: "Starknet Chain Type",
give: "STARKNET",
want: ChainTypeStarknet,
},
{
name: "Invalid Chain Type",
give: "",
Expand Down
22 changes: 13 additions & 9 deletions core/services/feeds/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ RETURNING id;
// CreateChainConfig creates a new chain config.
func (o *orm) CreateChainConfig(ctx context.Context, cfg ChainConfig) (id int64, err error) {
stmt := `
INSERT INTO feeds_manager_chain_configs (feeds_manager_id, chain_id, chain_type, account_address, admin_address, flux_monitor_config, ocr1_config, ocr2_config, created_at, updated_at)
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,NOW(),NOW())
INSERT INTO feeds_manager_chain_configs (feeds_manager_id, chain_id, chain_type, account_address, account_address_public_key, admin_address, flux_monitor_config, ocr1_config, ocr2_config, created_at, updated_at)
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,NOW(),NOW())
RETURNING id;
`

Expand All @@ -113,6 +113,7 @@ RETURNING id;
cfg.ChainID,
cfg.ChainType,
cfg.AccountAddress,
cfg.AccountAddressPublicKey,
cfg.AdminAddress,
cfg.FluxMonitorConfig,
cfg.OCR1Config,
Expand All @@ -129,7 +130,7 @@ func (o *orm) CreateBatchChainConfig(ctx context.Context, cfgs []ChainConfig) (i
}

stmt := `
INSERT INTO feeds_manager_chain_configs (feeds_manager_id, chain_id, chain_type, account_address, admin_address, flux_monitor_config, ocr1_config, ocr2_config, created_at, updated_at)
INSERT INTO feeds_manager_chain_configs (feeds_manager_id, chain_id, chain_type, account_address, account_address_public_key, admin_address, flux_monitor_config, ocr1_config, ocr2_config, created_at, updated_at)
VALUES %s
RETURNING id;
`
Expand All @@ -141,16 +142,16 @@ RETURNING id;

for i, cfg := range cfgs {
// Generate the placeholders
pnumidx := i * 8
pnumidx := i * 9

lo, hi := pnumidx+1, pnumidx+8
lo, hi := pnumidx+1, pnumidx+9
pnums := make([]any, hi-lo+1)
for i := range pnums {
pnums[i] = i + lo
}

vStrs = append(vStrs, fmt.Sprintf(
"($%d, $%d, $%d, $%d, $%d, $%d, $%d, $%d, NOW(), NOW())", pnums...,
"($%d, $%d, $%d, $%d, $%d, $%d, $%d, $%d, $%d, NOW(), NOW())", pnums...,
))

// Append the values
Expand All @@ -159,6 +160,7 @@ RETURNING id;
cfg.ChainID,
cfg.ChainType,
cfg.AccountAddress,
cfg.AccountAddressPublicKey,
cfg.AdminAddress,
cfg.FluxMonitorConfig,
cfg.OCR1Config,
Expand Down Expand Up @@ -192,7 +194,7 @@ RETURNING id;
// GetChainConfig fetches a chain config.
func (o *orm) GetChainConfig(ctx context.Context, id int64) (*ChainConfig, error) {
stmt := `
SELECT id, feeds_manager_id, chain_id, chain_type, account_address, admin_address, flux_monitor_config, ocr1_config, ocr2_config, created_at, updated_at
SELECT id, feeds_manager_id, chain_id, chain_type, account_address, account_address_public_key, admin_address, flux_monitor_config, ocr1_config, ocr2_config, created_at, updated_at
FROM feeds_manager_chain_configs
WHERE id = $1;
`
Expand All @@ -207,7 +209,7 @@ WHERE id = $1;
// ids.
func (o *orm) ListChainConfigsByManagerIDs(ctx context.Context, mgrIDs []int64) ([]ChainConfig, error) {
stmt := `
SELECT id, feeds_manager_id, chain_id, chain_type, account_address, admin_address, flux_monitor_config, ocr1_config, ocr2_config, created_at, updated_at
SELECT id, feeds_manager_id, chain_id, chain_type, account_address, account_address_public_key, admin_address, flux_monitor_config, ocr1_config, ocr2_config, created_at, updated_at
FROM feeds_manager_chain_configs
WHERE feeds_manager_id = ANY($1)
`
Expand All @@ -227,8 +229,9 @@ SET account_address = $1,
flux_monitor_config = $3,
ocr1_config = $4,
ocr2_config = $5,
account_address_public_key = $6,
updated_at = NOW()
WHERE id = $6
WHERE id = $7
RETURNING id;
`

Expand All @@ -239,6 +242,7 @@ RETURNING id;
cfg.FluxMonitorConfig,
cfg.OCR1Config,
cfg.OCR2Config,
cfg.AccountAddressPublicKey,
cfg.ID,
)

Expand Down
125 changes: 67 additions & 58 deletions core/services/feeds/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ func Test_ORM_CreateChainConfig(t *testing.T) {
orm = setupORM(t)
fmID = createFeedsManager(t, orm)
cfg1 = feeds.ChainConfig{
FeedsManagerID: fmID,
ChainID: "1",
ChainType: feeds.ChainTypeEVM,
AccountAddress: "0x0001",
AdminAddress: "0x1001",
FeedsManagerID: fmID,
ChainID: "1",
ChainType: feeds.ChainTypeEVM,
AccountAddress: "0x0001",
AdminAddress: "0x1001",
AccountAddressPublicKey: null.StringFrom("0x0002"),
FluxMonitorConfig: feeds.FluxMonitorConfig{
Enabled: true,
},
Expand All @@ -235,14 +236,15 @@ func Test_ORM_CreateChainConfig(t *testing.T) {
require.NoError(t, err)

assertChainConfigEqual(t, map[string]interface{}{
"feedsManagerID": cfg1.FeedsManagerID,
"chainID": cfg1.ChainID,
"chainType": cfg1.ChainType,
"accountAddress": cfg1.AccountAddress,
"adminAddress": cfg1.AdminAddress,
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
"ocrConfig": cfg1.OCR1Config,
"ocr2Config": cfg1.OCR2Config,
"feedsManagerID": cfg1.FeedsManagerID,
"chainID": cfg1.ChainID,
"chainType": cfg1.ChainType,
"accountAddress": cfg1.AccountAddress,
"accountAddressPublicKey": cfg1.AccountAddressPublicKey,
"adminAddress": cfg1.AdminAddress,
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
"ocrConfig": cfg1.OCR1Config,
"ocr2Config": cfg1.OCR2Config,
}, *actual)
}

Expand All @@ -254,11 +256,12 @@ func Test_ORM_CreateBatchChainConfig(t *testing.T) {
orm = setupORM(t)
fmID = createFeedsManager(t, orm)
cfg1 = feeds.ChainConfig{
FeedsManagerID: fmID,
ChainID: "1",
ChainType: feeds.ChainTypeEVM,
AccountAddress: "0x0001",
AdminAddress: "0x1001",
FeedsManagerID: fmID,
ChainID: "1",
ChainType: feeds.ChainTypeEVM,
AccountAddress: "0x0001",
AccountAddressPublicKey: null.StringFrom("0x0002"),
AdminAddress: "0x1001",
}
cfg2 = feeds.ChainConfig{
FeedsManagerID: fmID,
Expand All @@ -278,14 +281,15 @@ func Test_ORM_CreateBatchChainConfig(t *testing.T) {
require.NoError(t, err)

assertChainConfigEqual(t, map[string]interface{}{
"feedsManagerID": cfg1.FeedsManagerID,
"chainID": cfg1.ChainID,
"chainType": cfg1.ChainType,
"accountAddress": cfg1.AccountAddress,
"adminAddress": cfg1.AdminAddress,
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
"ocrConfig": cfg1.OCR1Config,
"ocr2Config": cfg1.OCR2Config,
"feedsManagerID": cfg1.FeedsManagerID,
"chainID": cfg1.ChainID,
"chainType": cfg1.ChainType,
"accountAddress": cfg1.AccountAddress,
"accountAddressPublicKey": cfg1.AccountAddressPublicKey,
"adminAddress": cfg1.AdminAddress,
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
"ocrConfig": cfg1.OCR1Config,
"ocr2Config": cfg1.OCR2Config,
}, *actual)

actual, err = orm.GetChainConfig(ctx, ids[1])
Expand Down Expand Up @@ -346,11 +350,12 @@ func Test_ORM_ListChainConfigsByManagerIDs(t *testing.T) {
orm = setupORM(t)
fmID = createFeedsManager(t, orm)
cfg1 = feeds.ChainConfig{
FeedsManagerID: fmID,
ChainID: "1",
ChainType: feeds.ChainTypeEVM,
AccountAddress: "0x0001",
AdminAddress: "0x1001",
FeedsManagerID: fmID,
ChainID: "1",
ChainType: feeds.ChainTypeEVM,
AccountAddress: "0x0001",
AccountAddressPublicKey: null.StringFrom("0x0002"),
AdminAddress: "0x1001",
FluxMonitorConfig: feeds.FluxMonitorConfig{
Enabled: true,
},
Expand All @@ -376,14 +381,15 @@ func Test_ORM_ListChainConfigsByManagerIDs(t *testing.T) {
require.Len(t, actual, 1)

assertChainConfigEqual(t, map[string]interface{}{
"feedsManagerID": cfg1.FeedsManagerID,
"chainID": cfg1.ChainID,
"chainType": cfg1.ChainType,
"accountAddress": cfg1.AccountAddress,
"adminAddress": cfg1.AdminAddress,
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
"ocrConfig": cfg1.OCR1Config,
"ocr2Config": cfg1.OCR2Config,
"feedsManagerID": cfg1.FeedsManagerID,
"chainID": cfg1.ChainID,
"chainType": cfg1.ChainType,
"accountAddress": cfg1.AccountAddress,
"accountAddressPublicKey": cfg1.AccountAddressPublicKey,
"adminAddress": cfg1.AdminAddress,
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
"ocrConfig": cfg1.OCR1Config,
"ocr2Config": cfg1.OCR2Config,
}, actual[0])
}

Expand All @@ -395,19 +401,21 @@ func Test_ORM_UpdateChainConfig(t *testing.T) {
orm = setupORM(t)
fmID = createFeedsManager(t, orm)
cfg1 = feeds.ChainConfig{
FeedsManagerID: fmID,
ChainID: "1",
ChainType: feeds.ChainTypeEVM,
AccountAddress: "0x0001",
AdminAddress: "0x1001",
FluxMonitorConfig: feeds.FluxMonitorConfig{Enabled: false},
OCR1Config: feeds.OCR1Config{Enabled: false},
OCR2Config: feeds.OCR2ConfigModel{Enabled: false},
FeedsManagerID: fmID,
ChainID: "1",
ChainType: feeds.ChainTypeEVM,
AccountAddress: "0x0001",
AccountAddressPublicKey: null.NewString("", false),
AdminAddress: "0x1001",
FluxMonitorConfig: feeds.FluxMonitorConfig{Enabled: false},
OCR1Config: feeds.OCR1Config{Enabled: false},
OCR2Config: feeds.OCR2ConfigModel{Enabled: false},
}
updateCfg = feeds.ChainConfig{
AccountAddress: "0x0002",
AdminAddress: "0x1002",
FluxMonitorConfig: feeds.FluxMonitorConfig{Enabled: true},
AccountAddress: "0x0002",
AdminAddress: "0x1002",
AccountAddressPublicKey: null.StringFrom("0x0002"),
FluxMonitorConfig: feeds.FluxMonitorConfig{Enabled: true},
OCR1Config: feeds.OCR1Config{
Enabled: true,
IsBootstrap: false,
Expand All @@ -434,14 +442,15 @@ func Test_ORM_UpdateChainConfig(t *testing.T) {
require.NoError(t, err)

assertChainConfigEqual(t, map[string]interface{}{
"feedsManagerID": cfg1.FeedsManagerID,
"chainID": cfg1.ChainID,
"chainType": cfg1.ChainType,
"accountAddress": updateCfg.AccountAddress,
"adminAddress": updateCfg.AdminAddress,
"fluxMonitorConfig": updateCfg.FluxMonitorConfig,
"ocrConfig": updateCfg.OCR1Config,
"ocr2Config": updateCfg.OCR2Config,
"feedsManagerID": cfg1.FeedsManagerID,
"chainID": cfg1.ChainID,
"chainType": cfg1.ChainType,
"accountAddress": updateCfg.AccountAddress,
"accountAddressPublicKey": updateCfg.AccountAddressPublicKey,
"adminAddress": updateCfg.AdminAddress,
"fluxMonitorConfig": updateCfg.FluxMonitorConfig,
"ocrConfig": updateCfg.OCR1Config,
"ocr2Config": updateCfg.OCR2Config,
}, *actual)
}

Expand Down
Loading

0 comments on commit c429772

Please sign in to comment.