Browse Source

ckdb - add the block diff to block messages

master
kanoi 10 years ago
parent
commit
9a4056ddad
  1. 4
      src/ckdb.h
  2. 21
      src/ckdb_data.c
  3. 9
      src/ckdb_dbio.c

4
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);

21
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];

9
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;

Loading…
Cancel
Save