Skip to content

Commit 68ccfe6

Browse files
authored
Merge pull request #20 from migalabs/fix/depositors_insert_not_applying
Fix: depositors insert not applying
2 parents 86b85a6 + bdf5633 commit 68ccfe6

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

db/depositors_insert.go

Lines changed: 23 additions & 15 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

@@ -30,7 +38,7 @@ func (p *PostgresDBService) ApplyDepositorsInsert() error {
3038
}
3139
defer conn.Release()
3240

33-
_, err = conn.Query(p.ctx, applyDepositorsInsertQuery)
41+
_, err = conn.Exec(p.ctx, applyDepositorsInsertQuery)
3442
if err != nil {
3543
return errors.Wrap(err, "error applying validators insert")
3644
}

0 commit comments

Comments
 (0)