From 200ecef2ba822a7bb9e3e715a394c6b9a2337dce Mon Sep 17 00:00:00 2001 From: RamiRond Date: Thu, 7 Sep 2023 18:09:15 +0200 Subject: [PATCH 1/3] (BIDS-2457) remove previous odao members --- exporter/rocketpool.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/exporter/rocketpool.go b/exporter/rocketpool.go index 05eabb370f..d41ce9ecda 100644 --- a/exporter/rocketpool.go +++ b/exporter/rocketpool.go @@ -1117,6 +1117,7 @@ func (rp *RocketpoolExporter) SaveDAOMembers() error { valueStrings := make([]string, 0, batchSize) valueArgs := make([]interface{}, 0, batchSize*nArgs) + addresses := make([][]byte, 0, batchSize) for i, d := range data[start:end] { for j := 0; j < nArgs; j++ { valueStringsArgs[j] = i*nArgs + j + 1 @@ -1130,12 +1131,39 @@ func (rp *RocketpoolExporter) SaveDAOMembers() error { valueArgs = append(valueArgs, d.LastProposalTime) valueArgs = append(valueArgs, d.RPLBondAmount.String()) valueArgs = append(valueArgs, d.UnbondedValidatorCount) + addresses = append(addresses, d.Address) } - stmt := fmt.Sprintf(`insert into rocketpool_dao_members (rocketpool_storage_address, address, id, url, joined_time, last_proposal_time, rpl_bond_amount, unbonded_validator_count) values %s on conflict (rocketpool_storage_address, address) do update set id = excluded.id, url = excluded.url, joined_time = excluded.joined_time, last_proposal_time = excluded.last_proposal_time, rpl_bond_amount = excluded.rpl_bond_amount, unbonded_validator_count = excluded.unbonded_validator_count`, strings.Join(valueStrings, ",")) + stmt := fmt.Sprintf(` + INSERT INTO rocketpool_dao_members ( + rocketpool_storage_address, + address, + id, + url, + joined_time, + last_proposal_time, + rpl_bond_amount, + unbonded_validator_count + ) + values %s + on conflict (rocketpool_storage_address, address) do update set + id = excluded.id, + url = excluded.url, + joined_time = excluded.joined_time, + last_proposal_time = excluded.last_proposal_time, + rpl_bond_amount = excluded.rpl_bond_amount, + unbonded_validator_count = excluded.unbonded_validator_count + `, strings.Join(valueStrings, ",")) _, err := tx.Exec(stmt, valueArgs...) if err != nil { return fmt.Errorf("error inserting into rocketpool_dao_members: %w", err) } + + _, err = tx.Exec(` + DELETE FROM rocketpool_dao_members + WHERE NOT address = ANY($1)`, addresses) + if err != nil { + return fmt.Errorf("error deleting from rocketpool_dao_members: %w", err) + } } return tx.Commit() From 7611058e0bb98bfc421600961f73e3ce47e55646 Mon Sep 17 00:00:00 2001 From: remoterami <142154971+remoterami@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:06:11 +0200 Subject: [PATCH 2/3] use pq.ByteaArray Co-authored-by: Stefan Pletka <124689083+Eisei24@users.noreply.github.com> --- exporter/rocketpool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/rocketpool.go b/exporter/rocketpool.go index d41ce9ecda..b680de4be3 100644 --- a/exporter/rocketpool.go +++ b/exporter/rocketpool.go @@ -1160,7 +1160,7 @@ func (rp *RocketpoolExporter) SaveDAOMembers() error { _, err = tx.Exec(` DELETE FROM rocketpool_dao_members - WHERE NOT address = ANY($1)`, addresses) + WHERE NOT address = ANY($1)`, pq.ByteaArray(addresses)) if err != nil { return fmt.Errorf("error deleting from rocketpool_dao_members: %w", err) } From 1c1ef1592b393274362aa71cf036769e7632edf4 Mon Sep 17 00:00:00 2001 From: RamiRond Date: Wed, 13 Sep 2023 11:20:56 +0200 Subject: [PATCH 3/3] (BIDS-2457) added missing import --- exporter/rocketpool.go | 1 + 1 file changed, 1 insertion(+) diff --git a/exporter/rocketpool.go b/exporter/rocketpool.go index b680de4be3..42893782ce 100644 --- a/exporter/rocketpool.go +++ b/exporter/rocketpool.go @@ -21,6 +21,7 @@ import ( _ "github.com/jackc/pgx/v4/stdlib" "github.com/jmoiron/sqlx" "github.com/klauspost/compress/zstd" + "github.com/lib/pq" rpDAO "github.com/rocket-pool/rocketpool-go/dao" rpDAOTrustedNode "github.com/rocket-pool/rocketpool-go/dao/trustednode" "github.com/rocket-pool/rocketpool-go/minipool"