From 0cfa3abe61461e4c4fa3d025873a79a0b41f3564 Mon Sep 17 00:00:00 2001 From: kanoi Date: Thu, 11 Sep 2014 08:31:55 +1000 Subject: [PATCH] sql - comments and updates for bs.sql --- sql/bs.sql | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/sql/bs.sql b/sql/bs.sql index 4d526cc0..c39b6abe 100644 --- a/sql/bs.sql +++ b/sql/bs.sql @@ -1,3 +1,12 @@ +-- SQL to calculate a block's diffacc (difficulty accepted) +-- This should match the block's confirmed diffacc +-- i.e. when a block has statsconfirmed='Y' +-- If the block has any unaged sharesummaries, +-- the script will abort and report the count +-- Sharesummaries are aged at ~10 minutes after the next workinfo, +-- after the sharesummary's workinfo, was first generated +-- You need to set the block number at line 21 - hi := blockheight; + SET SESSION AUTHORIZATION 'postgres'; DO $$ @@ -12,23 +21,30 @@ BEGIN hi := 318177; -- This will randomly choose between multiple blocks of the same height - -- if we happen to orphan ourselves + -- if we happen to orphan ourselves on block 'hi' select workinfoid from blocks where height = hi - and expirydate > '6666-06-01' into wi; + and expirydate > '6666-06-01' limit 1 into wi; IF NOT found THEN RAISE EXCEPTION 'Block % not found', hi; END IF; select max(height) from blocks where height < hi into hi0; - IF NOT found THEN + IF hi0 is NULL THEN wi0 := -1; ELSE + -- This will randomly choose between multiple blocks of the same height + -- if we happen to orphan ourselves on block 'hi0' select workinfoid from blocks where height = hi0 - and expirydate > '6666-06-01' into Wi0; + and expirydate > '6666-06-01' limit 1 into wi0; END IF; - RAISE WARNING 'Block: %(%)', hi, wi; - RAISE WARNING 'Previous block: %(%)', hi0, wi0; + RAISE NOTICE 'Block: %(%)', hi, wi; + + IF hi0 is NULL THEN + RAISE NOTICE 'No previous block'; + ELSE + RAISE NOTICE 'Previous block: %(%)', hi0, wi0; + END IF; select count(*) from sharesummary where workinfoid > wi0 and workinfoid <= wi and complete = 'n' into ssc; @@ -39,6 +55,6 @@ BEGIN select sum(diffacc) from sharesummary where workinfoid > wi0 and workinfoid <= wi into da; - RAISE WARNING 'diffacc: %', to_char(da::bigint, 'FM999,999,999,999,999,990'); + RAISE NOTICE 'diffacc: %', to_char(da::bigint, 'FM999,999,999,999,999,990'); END IF; END $$;