Skip to content

Commit c429772

Browse files
Add account address pub key to fms chain config for Starknet (#13421)
* 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 <[email protected]> --------- Co-authored-by: Chris De Leon <[email protected]>
1 parent 000f2cb commit c429772

13 files changed

+358
-260
lines changed

.changeset/olive-experts-matter.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink": patch
3+
---
4+
5+
#db_update Add account_address_public_key to feeds_manager_chain_configs

core/services/feeds/models.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,17 @@ func (p *Plugins) Scan(value interface{}) error {
7676
type ChainType string
7777

7878
const (
79-
ChainTypeUnknown ChainType = "UNKNOWN"
80-
ChainTypeEVM ChainType = "EVM"
79+
ChainTypeUnknown ChainType = "UNKNOWN"
80+
ChainTypeEVM ChainType = "EVM"
81+
ChainTypeStarknet ChainType = "STARKNET"
8182
)
8283

8384
func NewChainType(s string) (ChainType, error) {
8485
switch s {
8586
case "EVM":
8687
return ChainTypeEVM, nil
88+
case "STARKNET":
89+
return ChainTypeStarknet, nil
8790
default:
8891
return ChainTypeUnknown, errors.New("invalid chain type")
8992
}
@@ -103,17 +106,18 @@ type FeedsManager struct {
103106

104107
// ChainConfig defines the chain configuration for a Feeds Manager.
105108
type ChainConfig struct {
106-
ID int64
107-
FeedsManagerID int64
108-
ChainID string
109-
ChainType ChainType
110-
AccountAddress string
111-
AdminAddress string
112-
FluxMonitorConfig FluxMonitorConfig
113-
OCR1Config OCR1Config
114-
OCR2Config OCR2ConfigModel
115-
CreatedAt time.Time
116-
UpdatedAt time.Time
109+
ID int64
110+
FeedsManagerID int64
111+
ChainID string
112+
ChainType ChainType
113+
AccountAddress string
114+
AccountAddressPublicKey null.String
115+
AdminAddress string
116+
FluxMonitorConfig FluxMonitorConfig
117+
OCR1Config OCR1Config
118+
OCR2Config OCR2ConfigModel
119+
CreatedAt time.Time
120+
UpdatedAt time.Time
117121
}
118122

119123
// FluxMonitorConfig defines configuration for FluxMonitorJobs.

core/services/feeds/models_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ func Test_NewChainType(t *testing.T) {
2323
give: "EVM",
2424
want: ChainTypeEVM,
2525
},
26+
{
27+
name: "Starknet Chain Type",
28+
give: "STARKNET",
29+
want: ChainTypeStarknet,
30+
},
2631
{
2732
name: "Invalid Chain Type",
2833
give: "",

core/services/feeds/orm.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ RETURNING id;
101101
// CreateChainConfig creates a new chain config.
102102
func (o *orm) CreateChainConfig(ctx context.Context, cfg ChainConfig) (id int64, err error) {
103103
stmt := `
104-
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)
105-
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,NOW(),NOW())
104+
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)
105+
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,NOW(),NOW())
106106
RETURNING id;
107107
`
108108

@@ -113,6 +113,7 @@ RETURNING id;
113113
cfg.ChainID,
114114
cfg.ChainType,
115115
cfg.AccountAddress,
116+
cfg.AccountAddressPublicKey,
116117
cfg.AdminAddress,
117118
cfg.FluxMonitorConfig,
118119
cfg.OCR1Config,
@@ -129,7 +130,7 @@ func (o *orm) CreateBatchChainConfig(ctx context.Context, cfgs []ChainConfig) (i
129130
}
130131

131132
stmt := `
132-
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)
133+
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)
133134
VALUES %s
134135
RETURNING id;
135136
`
@@ -141,16 +142,16 @@ RETURNING id;
141142

142143
for i, cfg := range cfgs {
143144
// Generate the placeholders
144-
pnumidx := i * 8
145+
pnumidx := i * 9
145146

146-
lo, hi := pnumidx+1, pnumidx+8
147+
lo, hi := pnumidx+1, pnumidx+9
147148
pnums := make([]any, hi-lo+1)
148149
for i := range pnums {
149150
pnums[i] = i + lo
150151
}
151152

152153
vStrs = append(vStrs, fmt.Sprintf(
153-
"($%d, $%d, $%d, $%d, $%d, $%d, $%d, $%d, NOW(), NOW())", pnums...,
154+
"($%d, $%d, $%d, $%d, $%d, $%d, $%d, $%d, $%d, NOW(), NOW())", pnums...,
154155
))
155156

156157
// Append the values
@@ -159,6 +160,7 @@ RETURNING id;
159160
cfg.ChainID,
160161
cfg.ChainType,
161162
cfg.AccountAddress,
163+
cfg.AccountAddressPublicKey,
162164
cfg.AdminAddress,
163165
cfg.FluxMonitorConfig,
164166
cfg.OCR1Config,
@@ -192,7 +194,7 @@ RETURNING id;
192194
// GetChainConfig fetches a chain config.
193195
func (o *orm) GetChainConfig(ctx context.Context, id int64) (*ChainConfig, error) {
194196
stmt := `
195-
SELECT id, feeds_manager_id, chain_id, chain_type, account_address, admin_address, flux_monitor_config, ocr1_config, ocr2_config, created_at, updated_at
197+
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
196198
FROM feeds_manager_chain_configs
197199
WHERE id = $1;
198200
`
@@ -207,7 +209,7 @@ WHERE id = $1;
207209
// ids.
208210
func (o *orm) ListChainConfigsByManagerIDs(ctx context.Context, mgrIDs []int64) ([]ChainConfig, error) {
209211
stmt := `
210-
SELECT id, feeds_manager_id, chain_id, chain_type, account_address, admin_address, flux_monitor_config, ocr1_config, ocr2_config, created_at, updated_at
212+
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
211213
FROM feeds_manager_chain_configs
212214
WHERE feeds_manager_id = ANY($1)
213215
`
@@ -227,8 +229,9 @@ SET account_address = $1,
227229
flux_monitor_config = $3,
228230
ocr1_config = $4,
229231
ocr2_config = $5,
232+
account_address_public_key = $6,
230233
updated_at = NOW()
231-
WHERE id = $6
234+
WHERE id = $7
232235
RETURNING id;
233236
`
234237

@@ -239,6 +242,7 @@ RETURNING id;
239242
cfg.FluxMonitorConfig,
240243
cfg.OCR1Config,
241244
cfg.OCR2Config,
245+
cfg.AccountAddressPublicKey,
242246
cfg.ID,
243247
)
244248

core/services/feeds/orm_test.go

+67-58
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ func Test_ORM_CreateChainConfig(t *testing.T) {
206206
orm = setupORM(t)
207207
fmID = createFeedsManager(t, orm)
208208
cfg1 = feeds.ChainConfig{
209-
FeedsManagerID: fmID,
210-
ChainID: "1",
211-
ChainType: feeds.ChainTypeEVM,
212-
AccountAddress: "0x0001",
213-
AdminAddress: "0x1001",
209+
FeedsManagerID: fmID,
210+
ChainID: "1",
211+
ChainType: feeds.ChainTypeEVM,
212+
AccountAddress: "0x0001",
213+
AdminAddress: "0x1001",
214+
AccountAddressPublicKey: null.StringFrom("0x0002"),
214215
FluxMonitorConfig: feeds.FluxMonitorConfig{
215216
Enabled: true,
216217
},
@@ -235,14 +236,15 @@ func Test_ORM_CreateChainConfig(t *testing.T) {
235236
require.NoError(t, err)
236237

237238
assertChainConfigEqual(t, map[string]interface{}{
238-
"feedsManagerID": cfg1.FeedsManagerID,
239-
"chainID": cfg1.ChainID,
240-
"chainType": cfg1.ChainType,
241-
"accountAddress": cfg1.AccountAddress,
242-
"adminAddress": cfg1.AdminAddress,
243-
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
244-
"ocrConfig": cfg1.OCR1Config,
245-
"ocr2Config": cfg1.OCR2Config,
239+
"feedsManagerID": cfg1.FeedsManagerID,
240+
"chainID": cfg1.ChainID,
241+
"chainType": cfg1.ChainType,
242+
"accountAddress": cfg1.AccountAddress,
243+
"accountAddressPublicKey": cfg1.AccountAddressPublicKey,
244+
"adminAddress": cfg1.AdminAddress,
245+
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
246+
"ocrConfig": cfg1.OCR1Config,
247+
"ocr2Config": cfg1.OCR2Config,
246248
}, *actual)
247249
}
248250

@@ -254,11 +256,12 @@ func Test_ORM_CreateBatchChainConfig(t *testing.T) {
254256
orm = setupORM(t)
255257
fmID = createFeedsManager(t, orm)
256258
cfg1 = feeds.ChainConfig{
257-
FeedsManagerID: fmID,
258-
ChainID: "1",
259-
ChainType: feeds.ChainTypeEVM,
260-
AccountAddress: "0x0001",
261-
AdminAddress: "0x1001",
259+
FeedsManagerID: fmID,
260+
ChainID: "1",
261+
ChainType: feeds.ChainTypeEVM,
262+
AccountAddress: "0x0001",
263+
AccountAddressPublicKey: null.StringFrom("0x0002"),
264+
AdminAddress: "0x1001",
262265
}
263266
cfg2 = feeds.ChainConfig{
264267
FeedsManagerID: fmID,
@@ -278,14 +281,15 @@ func Test_ORM_CreateBatchChainConfig(t *testing.T) {
278281
require.NoError(t, err)
279282

280283
assertChainConfigEqual(t, map[string]interface{}{
281-
"feedsManagerID": cfg1.FeedsManagerID,
282-
"chainID": cfg1.ChainID,
283-
"chainType": cfg1.ChainType,
284-
"accountAddress": cfg1.AccountAddress,
285-
"adminAddress": cfg1.AdminAddress,
286-
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
287-
"ocrConfig": cfg1.OCR1Config,
288-
"ocr2Config": cfg1.OCR2Config,
284+
"feedsManagerID": cfg1.FeedsManagerID,
285+
"chainID": cfg1.ChainID,
286+
"chainType": cfg1.ChainType,
287+
"accountAddress": cfg1.AccountAddress,
288+
"accountAddressPublicKey": cfg1.AccountAddressPublicKey,
289+
"adminAddress": cfg1.AdminAddress,
290+
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
291+
"ocrConfig": cfg1.OCR1Config,
292+
"ocr2Config": cfg1.OCR2Config,
289293
}, *actual)
290294

291295
actual, err = orm.GetChainConfig(ctx, ids[1])
@@ -346,11 +350,12 @@ func Test_ORM_ListChainConfigsByManagerIDs(t *testing.T) {
346350
orm = setupORM(t)
347351
fmID = createFeedsManager(t, orm)
348352
cfg1 = feeds.ChainConfig{
349-
FeedsManagerID: fmID,
350-
ChainID: "1",
351-
ChainType: feeds.ChainTypeEVM,
352-
AccountAddress: "0x0001",
353-
AdminAddress: "0x1001",
353+
FeedsManagerID: fmID,
354+
ChainID: "1",
355+
ChainType: feeds.ChainTypeEVM,
356+
AccountAddress: "0x0001",
357+
AccountAddressPublicKey: null.StringFrom("0x0002"),
358+
AdminAddress: "0x1001",
354359
FluxMonitorConfig: feeds.FluxMonitorConfig{
355360
Enabled: true,
356361
},
@@ -376,14 +381,15 @@ func Test_ORM_ListChainConfigsByManagerIDs(t *testing.T) {
376381
require.Len(t, actual, 1)
377382

378383
assertChainConfigEqual(t, map[string]interface{}{
379-
"feedsManagerID": cfg1.FeedsManagerID,
380-
"chainID": cfg1.ChainID,
381-
"chainType": cfg1.ChainType,
382-
"accountAddress": cfg1.AccountAddress,
383-
"adminAddress": cfg1.AdminAddress,
384-
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
385-
"ocrConfig": cfg1.OCR1Config,
386-
"ocr2Config": cfg1.OCR2Config,
384+
"feedsManagerID": cfg1.FeedsManagerID,
385+
"chainID": cfg1.ChainID,
386+
"chainType": cfg1.ChainType,
387+
"accountAddress": cfg1.AccountAddress,
388+
"accountAddressPublicKey": cfg1.AccountAddressPublicKey,
389+
"adminAddress": cfg1.AdminAddress,
390+
"fluxMonitorConfig": cfg1.FluxMonitorConfig,
391+
"ocrConfig": cfg1.OCR1Config,
392+
"ocr2Config": cfg1.OCR2Config,
387393
}, actual[0])
388394
}
389395

@@ -395,19 +401,21 @@ func Test_ORM_UpdateChainConfig(t *testing.T) {
395401
orm = setupORM(t)
396402
fmID = createFeedsManager(t, orm)
397403
cfg1 = feeds.ChainConfig{
398-
FeedsManagerID: fmID,
399-
ChainID: "1",
400-
ChainType: feeds.ChainTypeEVM,
401-
AccountAddress: "0x0001",
402-
AdminAddress: "0x1001",
403-
FluxMonitorConfig: feeds.FluxMonitorConfig{Enabled: false},
404-
OCR1Config: feeds.OCR1Config{Enabled: false},
405-
OCR2Config: feeds.OCR2ConfigModel{Enabled: false},
404+
FeedsManagerID: fmID,
405+
ChainID: "1",
406+
ChainType: feeds.ChainTypeEVM,
407+
AccountAddress: "0x0001",
408+
AccountAddressPublicKey: null.NewString("", false),
409+
AdminAddress: "0x1001",
410+
FluxMonitorConfig: feeds.FluxMonitorConfig{Enabled: false},
411+
OCR1Config: feeds.OCR1Config{Enabled: false},
412+
OCR2Config: feeds.OCR2ConfigModel{Enabled: false},
406413
}
407414
updateCfg = feeds.ChainConfig{
408-
AccountAddress: "0x0002",
409-
AdminAddress: "0x1002",
410-
FluxMonitorConfig: feeds.FluxMonitorConfig{Enabled: true},
415+
AccountAddress: "0x0002",
416+
AdminAddress: "0x1002",
417+
AccountAddressPublicKey: null.StringFrom("0x0002"),
418+
FluxMonitorConfig: feeds.FluxMonitorConfig{Enabled: true},
411419
OCR1Config: feeds.OCR1Config{
412420
Enabled: true,
413421
IsBootstrap: false,
@@ -434,14 +442,15 @@ func Test_ORM_UpdateChainConfig(t *testing.T) {
434442
require.NoError(t, err)
435443

436444
assertChainConfigEqual(t, map[string]interface{}{
437-
"feedsManagerID": cfg1.FeedsManagerID,
438-
"chainID": cfg1.ChainID,
439-
"chainType": cfg1.ChainType,
440-
"accountAddress": updateCfg.AccountAddress,
441-
"adminAddress": updateCfg.AdminAddress,
442-
"fluxMonitorConfig": updateCfg.FluxMonitorConfig,
443-
"ocrConfig": updateCfg.OCR1Config,
444-
"ocr2Config": updateCfg.OCR2Config,
445+
"feedsManagerID": cfg1.FeedsManagerID,
446+
"chainID": cfg1.ChainID,
447+
"chainType": cfg1.ChainType,
448+
"accountAddress": updateCfg.AccountAddress,
449+
"accountAddressPublicKey": updateCfg.AccountAddressPublicKey,
450+
"adminAddress": updateCfg.AdminAddress,
451+
"fluxMonitorConfig": updateCfg.FluxMonitorConfig,
452+
"ocrConfig": updateCfg.OCR1Config,
453+
"ocr2Config": updateCfg.OCR2Config,
445454
}, *actual)
446455
}
447456

0 commit comments

Comments
 (0)