Skip to content

Commit bdf5633

Browse files
committed
fix: update SQL query in ApplyDepositorsInsert method for using last depositor address for tagging
1 parent a6cc577 commit bdf5633

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

db/depositors_insert.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@ import "github.com/pkg/errors"
44

55
const (
66
applyDepositorsInsertQuery = `
7-
INSERT INTO t_identified_validators (
8-
f_validator_pubkey,
9-
f_pool_name
10-
)
11-
SELECT DISTINCT
12-
t1.f_validator_pubkey,
13-
f_pool_name
14-
FROM
15-
t_beacon_deposits t1
16-
RIGHT JOIN
17-
t_depositors_insert t2
18-
ON
19-
t1.f_depositor = t2.f_depositor
20-
ON CONFLICT (f_validator_pubkey) DO UPDATE SET f_pool_name = EXCLUDED.f_pool_name;
7+
INSERT INTO t_identified_validators (
8+
f_validator_pubkey,
9+
f_pool_name
10+
)
11+
SELECT DISTINCT
12+
t1.f_validator_pubkey,
13+
t2.f_pool_name
14+
FROM (
15+
SELECT
16+
f_validator_pubkey,
17+
f_depositor,
18+
ROW_NUMBER() OVER (
19+
PARTITION BY f_validator_pubkey
20+
ORDER BY f_block_num DESC
21+
) as rn
22+
FROM t_beacon_deposits
23+
) t1
24+
INNER JOIN t_depositors_insert t2
25+
ON t1.f_depositor = t2.f_depositor
26+
WHERE t1.rn = 1
27+
ON CONFLICT (f_validator_pubkey) DO UPDATE SET
28+
f_pool_name = EXCLUDED.f_pool_name;
2129
`
2230
)
2331

0 commit comments

Comments
 (0)