add/beacon-blocks-retry (#749)

* retry for withdrawals

* test

* number seq

* simplify

* space

* updated test
This commit is contained in:
drethereum 2023-11-09 12:48:51 -07:00 committed by GitHub
parent d1ecb835ba
commit 5aee17233f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,37 @@
{% test withdrawal_index_gaps(
model,
column_name
) %}
WITH base AS (
SELECT
{{ column_name }} AS withdrawal_index,
LEAD(withdrawal_index) over (
ORDER BY
withdrawal_index
) AS next_index,
slot_number AS start_slot_number,
LEAD(slot_number) over (
ORDER BY
withdrawal_index
) AS end_slot_number
FROM
{{ model }}
),
gaps AS (
SELECT
withdrawal_index,
next_index,
withdrawal_index + 1 AS expected_index,
start_slot_number,
end_slot_number
FROM
base
WHERE
next_index IS NOT NULL
AND expected_index <> next_index
)
SELECT
next_index - withdrawal_index AS gaps
FROM
gaps
{% endtest %}

View File

@ -53,6 +53,10 @@ models:
column_type_list:
- NUMBER
- FLOAT
- withdrawal_index_gaps:
config:
severity: error
error_if: ">0"
- name: VALIDATOR_INDEX
tests:
- not_null

View File

@ -7,6 +7,8 @@
tags = ['streamline_beacon_realtime']
) }}
WITH to_do AS (
SELECT
{{ dbt_utils.generate_surrogate_key(
['slot_number']
@ -25,3 +27,15 @@ FROM
{{ ref("streamline__complete_beacon_blocks") }}
WHERE
slot_number > 5000000
)
SELECT
id,
slot_number
FROM to_do
UNION
SELECT
id,
slot_number
FROM
{{ ref("_missing_withdrawals") }}

View File

@ -0,0 +1,58 @@
{{ config (
materialized = "ephemeral"
) }}
WITH base AS (
SELECT
INDEX AS withdrawal_index,
LEAD(withdrawal_index) over (
ORDER BY
withdrawal_index
) AS next_index,
slot_number AS start_slot_number,
LEAD(slot_number) over (
ORDER BY
withdrawal_index
) AS end_slot_number
FROM
{{ ref('silver__beacon_withdrawals') }}
),
gaps AS (
SELECT
withdrawal_index,
next_index,
withdrawal_index + 1 AS expected_index,
start_slot_number,
end_slot_number
FROM
base
WHERE
next_index IS NOT NULL
AND expected_index <> next_index
),
FINAL AS (
SELECT
withdrawal_index,
next_index,
expected_index,
start_slot_number,
end_slot_number,
start_slot_number + _id AS missing_slot_number
FROM
gaps
JOIN {{ ref('silver__number_sequence') }}
ON _id BETWEEN 1
AND (
end_slot_number - start_slot_number - 1
)
WHERE
missing_slot_number < end_slot_number
)
SELECT
DISTINCT missing_slot_number AS slot_number,
{{ dbt_utils.generate_surrogate_key(
['slot_number']
) }} AS id
FROM
FINAL