From 9a4056ddad79cbbd913b9a06d870ddc8d7a33e2c Mon Sep 17 00:00:00 2001 From: kanoi Date: Tue, 3 Mar 2015 00:01:37 +1100 Subject: [PATCH] ckdb - add the block diff to block messages --- src/ckdb.h | 4 +++- src/ckdb_data.c | 21 +++++++++++++++++++++ src/ckdb_dbio.c | 9 +++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index a0646a2d..8986339d 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -52,7 +52,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.0" -#define CKDB_VERSION DB_VERSION"-1.011" +#define CKDB_VERSION DB_VERSION"-1.012" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1741,6 +1741,8 @@ void _dbhash2btchash(char *hash, char *buf, size_t siz, WHERE_FFL_ARGS); #define dsp_hash(_hash, _buf, _siz) \ _dsp_hash(_hash, _buf, _siz, WHERE_FFL_HERE) extern void _dsp_hash(char *hash, char *buf, size_t siz, WHERE_FFL_ARGS); +#define blockhash_diff(_hash) _blockhash_diff(_hash, WHERE_FFL_HERE) +extern double _blockhash_diff(char *hash, WHERE_FFL_ARGS); extern void dsp_blocks(K_ITEM *item, FILE *stream); extern cmp_t cmp_blocks(K_ITEM *a, K_ITEM *b); extern K_ITEM *find_blocks(int32_t height, char *blockhash, K_TREE_CTX *ctx); diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 1cf72429..3878f342 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -2086,6 +2086,27 @@ void _dsp_hash(char *hash, char *buf, size_t siz, WHERE_FFL_ARGS) STRNCPYSIZ(buf, ptr, siz); } +double _blockhash_diff(char *hash, WHERE_FFL_ARGS) +{ + uchar binhash[SHA256SIZHEX >> 1]; + uchar swap[SHA256SIZHEX >> 1]; + size_t len; + + len = strlen(hash); + // code bug - check this before calling + if (len != SHA256SIZHEX) { + quitfrom(1, file, func, line, + "%s() invalid hash passed - size %d (%d)", + __func__, (int)len, SHA256SIZHEX); + } + + hex2bin(binhash, hash, sizeof(binhash)); + + flip_32(swap, binhash); + + return diff_from_target(swap); +} + void dsp_blocks(K_ITEM *item, FILE *stream) { char createdate_buf[DATE_BUFSIZ], expirydate_buf[DATE_BUFSIZ]; diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index 73573095..4db4f0ba 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -4018,6 +4018,7 @@ bool blocks_add(PGconn *conn, char *height, char *blockhash, K_ITEM *b_item, *u_item, *old_b_item; char cd_buf[DATE_BUFSIZ]; char hash_dsp[16+1]; + double hash_diff; BLOCKS *row, *oldblocks; USERS *users; char *upd, *ins; @@ -4038,6 +4039,7 @@ bool blocks_add(PGconn *conn, char *height, char *blockhash, STRNCPY(row->blockhash, blockhash); dsp_hash(blockhash, hash_dsp, sizeof(hash_dsp)); + hash_diff = blockhash_diff(blockhash); K_RLOCK(blocks_free); old_b_item = find_blocks(row->height, blockhash, NULL); @@ -4307,10 +4309,13 @@ flail: if (ok) { char pct[16] = "?"; char est[16] = ""; + char diff[16] = ""; K_ITEM *w_item; char tmp[256]; bool blk; + suffix_string(hash_diff, diff, sizeof(diff)-1, 0); + switch (confirmed[0]) { case BLOCKS_NEW: blk = true; @@ -4356,10 +4361,10 @@ flail: break; } - LOGWARNING("%s(): %sStatus: %s, Block: %s/...%s%s", + LOGWARNING("%s(): %sStatus: %s, Block: %s/...%s Diff %s%s", __func__, blk ? "BLOCK! " : "", blocks_confirmed(confirmed), - height, hash_dsp, tmp); + height, hash_dsp, diff, tmp); } return ok;