From fa817515059a9ea9b72ced5aa6514458ce846e7e Mon Sep 17 00:00:00 2001 From: Patrick Pfeiffer <306324+guybrush@users.noreply.github.com> Date: Thu, 5 Dec 2024 12:58:00 +0100 Subject: [PATCH 1/4] fix(v1): improve deposit-count-qry --- db/db.go | 4 +--- ...5125552_add_idx_blocks_status_depositscountgt0.sql | 11 +++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 db/migrations/20241205125552_add_idx_blocks_status_depositscountgt0.sql diff --git a/db/db.go b/db/db.go index 2217eb7f8c..aa36d43642 100644 --- a/db/db.go +++ b/db/db.go @@ -388,9 +388,7 @@ func GetEth2Deposits(query string, length, start uint64, orderBy, orderDir strin // Define the base queries deposistsCountQuery := ` - SELECT COUNT(*) - FROM blocks_deposits - INNER JOIN blocks ON blocks_deposits.block_root = blocks.blockroot AND blocks.status = '1' + select sum(depositscount) from blocks where status = '1' and depositscount > 0 %s` deposistsQuery := ` diff --git a/db/migrations/20241205125552_add_idx_blocks_status_depositscountgt0.sql b/db/migrations/20241205125552_add_idx_blocks_status_depositscountgt0.sql new file mode 100644 index 0000000000..5eb1710559 --- /dev/null +++ b/db/migrations/20241205125552_add_idx_blocks_status_depositscountgt0.sql @@ -0,0 +1,11 @@ +-- +goose Up +-- +goose StatementBegin +SELECT 'creating idx_blocks_status_depositscountgt0'; +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_blocks_status_depositscountgt0 ON blocks (status, (depositscount > 0)) where depositscount > 0; +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +SELECT 'dropping idx_blocks_status_depositscountgt0'; +DROP INDEX CONCURRENTLY IF EXISTS idx_blocks_status_depositscountgt0; +-- +goose StatementEnd From c73c2e2c6e5e09fb9604340b09ac3e7c392d49d6 Mon Sep 17 00:00:00 2001 From: Patrick Pfeiffer <306324+guybrush@users.noreply.github.com> Date: Fri, 6 Dec 2024 08:59:39 +0100 Subject: [PATCH 2/4] fix(v1): improve db.GetTotalAmountDeposited --- db/db.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db/db.go b/db/db.go index aa36d43642..e47800d0cf 100644 --- a/db/db.go +++ b/db/db.go @@ -2247,10 +2247,9 @@ func GetTotalAmountWithdrawn() (sum uint64, count uint64, err error) { func GetTotalAmountDeposited() (uint64, error) { var total uint64 err := ReaderDb.Get(&total, ` - SELECT - COALESCE(sum(d.amount), 0) as sum - FROM blocks_deposits d - INNER JOIN blocks b ON b.blockroot = d.block_root AND b.status = '1'`) + SELECT COALESCE(sum(d.amount), 0) as sum + FROM blocks_deposits d + INNER JOIN blocks b ON b.slot = d.block_slot AND b.blockroot = d.block_root WHERE b.status = '1' AND b.depositscount > 0;`) return total, err } From d4eefe003e1ffa1da6d1584c6bcb0e71a105bae7 Mon Sep 17 00:00:00 2001 From: Patrick Pfeiffer <306324+guybrush@users.noreply.github.com> Date: Fri, 6 Dec 2024 09:18:13 +0100 Subject: [PATCH 3/4] fix(monitoring): remove obsolete check for validatorStateCountsUpdater --- services/monitoring.go | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/services/monitoring.go b/services/monitoring.go index fb84444dd6..a8c3bde977 100644 --- a/services/monitoring.go +++ b/services/monitoring.go @@ -249,26 +249,25 @@ func startServicesMonitoringService() { firstRun := true servicesToCheck := map[string]time.Duration{ - "eth1indexer": time.Minute * 15, - "slotVizUpdater": time.Minute * 15, - "slotUpdater": time.Minute * 15, - "latestProposedSlotUpdater": time.Minute * 15, - "epochUpdater": time.Minute * 15, - "rewardsExporter": time.Minute * 15, - "mempoolUpdater": time.Minute * 15, - "indexPageDataUpdater": time.Minute * 15, - "latestBlockUpdater": time.Minute * 15, - "headBlockRootHashUpdater": time.Minute * 15, - "notification-collector": time.Minute * 15, - "relaysUpdater": time.Minute * 15, - "ethstoreExporter": time.Minute * 60, - "statsUpdater": time.Minute * 30, - "poolsUpdater": time.Minute * 30, - "slotExporter": time.Minute * 15, - "statistics": time.Minute * 90, - "ethStoreStatistics": time.Minute * 15, - "lastExportedStatisticDay": time.Minute * 15, - "validatorStateCountsUpdater": time.Minute * 90, + "eth1indexer": time.Minute * 15, + "slotVizUpdater": time.Minute * 15, + "slotUpdater": time.Minute * 15, + "latestProposedSlotUpdater": time.Minute * 15, + "epochUpdater": time.Minute * 15, + "rewardsExporter": time.Minute * 15, + "mempoolUpdater": time.Minute * 15, + "indexPageDataUpdater": time.Minute * 15, + "latestBlockUpdater": time.Minute * 15, + "headBlockRootHashUpdater": time.Minute * 15, + "notification-collector": time.Minute * 15, + "relaysUpdater": time.Minute * 15, + "ethstoreExporter": time.Minute * 60, + "statsUpdater": time.Minute * 30, + "poolsUpdater": time.Minute * 30, + "slotExporter": time.Minute * 15, + "statistics": time.Minute * 90, + "ethStoreStatistics": time.Minute * 15, + "lastExportedStatisticDay": time.Minute * 15, //"notification-sender", //exclude for now as the sender is only running on mainnet } From eb23daa19fc606dcbf08d313f65ba8b5c0b0dfea Mon Sep 17 00:00:00 2001 From: Patrick Pfeiffer <306324+guybrush@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:12:00 +0100 Subject: [PATCH 4/4] fix(v1): fix db.GetEth2Deposits when searching --- db/db.go | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/db/db.go b/db/db.go index e47800d0cf..9799323716 100644 --- a/db/db.go +++ b/db/db.go @@ -387,11 +387,9 @@ func GetEth2Deposits(query string, length, start uint64, orderBy, orderDir strin var err error // Define the base queries - deposistsCountQuery := ` - select sum(depositscount) from blocks where status = '1' and depositscount > 0 - %s` + depositsCountQuery := `SELECT SUM(depositscount) FROM blocks WHERE status = '1' AND depositscount > 0` - deposistsQuery := ` + depositsQuery := ` SELECT blocks_deposits.block_slot, blocks_deposits.block_index, @@ -417,12 +415,12 @@ func GetEth2Deposits(query string, length, start uint64, orderBy, orderDir strin } } if trimmedQuery == "" { - err = ReaderDb.Get(&totalCount, fmt.Sprintf(deposistsCountQuery, "")) + err = ReaderDb.Get(&totalCount, depositsCountQuery) if err != nil { return nil, 0, err } - err = ReaderDb.Select(&deposits, fmt.Sprintf(deposistsQuery, "", orderBy, orderDir), length, start) + err = ReaderDb.Select(&deposits, fmt.Sprintf(depositsQuery, "", orderBy, orderDir), length, start) if err != nil && err != sql.ErrNoRows { return nil, 0, err } @@ -433,31 +431,47 @@ func GetEth2Deposits(query string, length, start uint64, orderBy, orderDir strin if utils.IsHash(trimmedQuery) { param = hash searchQuery = `WHERE blocks_deposits.publickey = $3` + depositsCountQuery = ` + SELECT SUM(depositscount) + FROM blocks + INNER JOIN blocks_deposits ON blocks.blockroot = blocks_deposits.block_root AND blocks_deposits.publickey = $1 + WHERE status = '1' AND depositscount > 0` } else if utils.IsValidWithdrawalCredentials(trimmedQuery) { param = hash searchQuery = `WHERE blocks_deposits.withdrawalcredentials = $3` + depositsCountQuery = ` + SELECT SUM(depositscount) + FROM blocks + INNER JOIN blocks_deposits ON blocks.blockroot = blocks_deposits.block_root AND blocks_deposits.withdrawalcredentials = $1 + WHERE status = '1' AND depositscount > 0` } else if utils.IsEth1Address(trimmedQuery) { param = hash searchQuery = ` LEFT JOIN eth1_deposits ON blocks_deposits.publickey = eth1_deposits.publickey WHERE eth1_deposits.from_address = $3` + depositsCountQuery = ` + SELECT SUM(depositscount) + FROM blocks + INNER JOIN blocks_deposits ON blocks.blockroot = blocks_deposits.block_root AND blocks_deposits.from_address = $1 + WHERE status = '1' AND depositscount > 0` } else if uiQuery, parseErr := strconv.ParseUint(query, 10, 31); parseErr == nil { // Limit to 31 bits to stay within math.MaxInt32 param = uiQuery searchQuery = `WHERE blocks_deposits.block_slot = $3` + depositsCountQuery = ` + SELECT SUM(depositscount) + FROM blocks + WHERE status = '1' AND depositscount > 0 AND slot = $1` } else { // The query does not fulfill any of the requirements for a search return deposits, totalCount, nil } - // The deposits count query only has one parameter for the search - countSearchQuery := strings.ReplaceAll(searchQuery, "$3", "$1") - - err = ReaderDb.Get(&totalCount, fmt.Sprintf(deposistsCountQuery, countSearchQuery), param) + err = ReaderDb.Get(&totalCount, depositsCountQuery, param) if err != nil { return nil, 0, err } - err = ReaderDb.Select(&deposits, fmt.Sprintf(deposistsQuery, searchQuery, orderBy, orderDir), length, start, param) + err = ReaderDb.Select(&deposits, fmt.Sprintf(depositsQuery, searchQuery, orderBy, orderDir), length, start, param) if err != nil && err != sql.ErrNoRows { return nil, 0, err }