Query editor
WITH recent_sequences AS (SELECT DISTINCT try_cast(generation_seq AS BIGINT) AS generation_seqFROM dune.shroomnetwork.shroom_owner_state_v12_20260917_e1WHERE row_kind='COMMIT' AND try_cast(generation_seq AS BIGINT)>0ORDER BY generation_seq DESC LIMIT 3), stored AS (SELECT DISTINCT generation_seq,generation_id,domain,row_kind,row_key,payload,row_digestFROM dune.shroomnetwork.shroom_owner_state_v12_20260917_e1WHERE try_cast(generation_seq AS BIGINT) IN (SELECT generation_seq FROM recent_sequences)), checked AS (SELECT *,lower(to_hex(sha256(to_utf8(domain||chr(31)||row_kind||chr(31)||row_key||chr(31)||payload))))=row_digest AS row_okFROM stored), manifests AS (SELECT generation_seq,generation_id,count_if(row_kind='COMMIT') AS commits,count_if(NOT coalesce(row_ok,false)) AS bad_rows,count_if(row_kind<>'COMMIT') AS body_rows,count(*)-count(DISTINCT domain||chr(31)||row_kind||chr(31)||row_key) AS duplicate_keys,max(IF(row_kind='COMMIT',try_cast(json_extract_scalar(payload,'$.rows') AS BIGINT),NULL)) AS expected_rows,max(IF(row_kind='COMMIT',json_extract_scalar(payload,'$.content_digest'),NULL)) AS expected_digest,max(IF(row_kind='COMMIT',json_extract_scalar(payload,'$.product_id'),NULL)) AS commit_product,max(IF(row_kind='COMMIT',coalesce(json_format(json_extract(payload,'$.previous')),'null'),NULL)) AS previous_json,lower(to_hex(sha256(to_utf8(array_join(array_agg(row_digest ORDER BY domain,row_kind,row_key) FILTER(WHERE row_kind<>'COMMIT'),''))))) AS body_digest,array_sort(array_agg(domain) FILTER(WHERE row_kind='META')) AS meta_domains,count_if(row_kind='META' AND coalesce((json_extract_scalar(payload,'$.product_id')<>'shroom-v1.2-2b9b6f7abdc32e01c90d2880' OR json_extract_scalar(payload,'$.evidence_complete')<>'true'),true)) AS bad_metaFROM checked GROUP BY 1,2), valid AS (SELECT * FROM manifests WHERE commits=1 AND bad_rows=0 AND duplicate_keys=0AND body_rows=expected_rows AND body_digest=expected_digest AND bad_meta=0AND meta_domains=ARRAY['current','economics','fees_routing','history_coverage','mu','treasury']AND try_cast(generation_seq AS BIGINT)>0AND commit_product='shroom-v1.2-2b9b6f7abdc32e01c90d2880'AND generation_id=lower(to_hex(sha256(to_utf8('{"content_digest":"'||expected_digest||'","previous":'||previous_json||',"product":"shroom-v1.2-2b9b6f7abdc32e01c90d2880","sequence":'||cast(try_cast(generation_seq AS BIGINT) AS VARCHAR)||'}'))))), active_sequence AS (SELECT max(try_cast(generation_seq AS BIGINT)) AS sequence FROM valid), active AS (SELECT max(generation_id) AS generation_id,max(body_digest) AS content_digest FROM valid CROSS JOIN active_sequenceWHERE try_cast(generation_seq AS BIGINT)=sequence HAVING count(*)=1), metadata AS (SELECT s.domain,s.generation_id,s.payload,a.content_digest,try_cast(s.generation_seq AS BIGINT) AS generation_seq,CAST(current_timestamp AT TIME ZONE 'UTC' AS TIMESTAMP) AS now_utc,try_cast(json_extract_scalar(s.payload,'$.data_through_utc') AS TIMESTAMP) AS data_time,try_cast(json_extract_scalar(s.payload,'$.refreshed_utc') AS TIMESTAMP) AS refresh_time,try_cast(json_extract_scalar(s.payload,'$.stable_through_time') AS TIMESTAMP) AS stable_time,try_cast(json_extract_scalar(s.payload,'$.processed_through_block') AS BIGINT) AS through_block,try_cast(json_extract_scalar(s.payload,'$.stable_through_block') AS BIGINT) AS stable_block,try_cast(json_extract_scalar(s.payload,'$.cadence_seconds') AS BIGINT) AS cadence_seconds,try_cast(json_extract_scalar(s.payload,'$.recovery_guard_seconds') AS BIGINT) AS recovery_guard_seconds,try_cast(json_extract_scalar(s.payload,'$.current_data_age_limit_seconds') AS BIGINT) AS current_age_limitFROM stored s JOIN active a ON s.generation_id=a.generation_id WHERE row_kind='META'), freshness AS (SELECT *,date_diff('second',refresh_time,now_utc) AS refresh_age_seconds,date_diff('second',data_time,now_utc) AS data_age_seconds,CASE WHEN data_time IS NULL OR refresh_time IS NULL OR stable_time IS NULLOR through_block IS NULL OR stable_block IS NULL OR cadence_seconds IS NULL OR current_age_limit IS NULL OR recovery_guard_seconds IS NULLOR cadence_seconds<>10800 OR current_age_limit<>21600 OR recovery_guard_seconds<>259200OR stable_time>data_time OR data_time>refresh_timeOR data_time>now_utc OR refresh_time>now_utc OR stable_time>now_utcOR date_diff('second',stable_time,now_utc)>259200OR through_block-stable_block NOT BETWEEN 0 AND 3000000 THEN 'RECOVERY_REQUIRED'