From ceb3e73b4cbb0f52d08c9866d19b3702b1914c08 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 6 Apr 2018 22:19:59 +0300 Subject: [PATCH 001/202] Fix kvupdate 4096 limit --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index cc15174fb..c387198f8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -693,7 +693,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { static int32_t hwmheight; uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; - uint8_t scriptbuf[4096],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,zero,btctxid,txhash; + uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,zero,btctxid,txhash; int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; memset(&zero,0,sizeof(zero)); komodo_init(pindex->nHeight); From 4f616c5a44ce1eae506575e964a43344712da0ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 6 Apr 2018 22:32:48 +0300 Subject: [PATCH 002/202] Enable overwriting key's value --- src/komodo_kv.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 453608cc1..611f3a77e 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -182,7 +182,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) ptr->value = (uint8_t *)calloc(1,valuesize); memcpy(ptr->value,valueptr,valuesize); } - } + } else fprintf(stderr,"newflag.%d zero or protected %d\n",newflag,(ptr->flags & KOMODO_KVPROTECTED)); /*for (i=0; i<32; i++) printf("%02x",((uint8_t *)&ptr->pubkey)[i]); printf(" <- "); @@ -191,10 +191,10 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) printf(" new pubkey\n");*/ memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); ptr->height = height; - ptr->flags = flags | 1; + ptr->flags = flags; portable_mutex_unlock(&KOMODO_KV_mutex); - } //else printf("size mismatch %d vs %d\n",opretlen,coresize); - } + } else fprintf(stderr,"size mismatch %d vs %d\n",opretlen,coresize); + } else fprintf(stderr,"not enough fee\n"); } #endif From 7e907fddadbe4369a7b4c0b821bbaa7cfdf56ca5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 11:29:40 +0300 Subject: [PATCH 003/202] komodo_port.c to calculate assetchain rpc port, p2p port one below --- src/komodo_kv.h | 2 +- src/komodo_port.c | 848 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 849 insertions(+), 1 deletion(-) create mode 100644 src/komodo_port.c diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 611f3a77e..0d5259eaa 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -191,7 +191,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) printf(" new pubkey\n");*/ memcpy(&ptr->pubkey,&pubkey,sizeof(ptr->pubkey)); ptr->height = height; - ptr->flags = flags; + ptr->flags = flags; // jl777 used to or in KVPROTECTED portable_mutex_unlock(&KOMODO_KV_mutex); } else fprintf(stderr,"size mismatch %d vs %d\n",opretlen,coresize); } else fprintf(stderr,"not enough fee\n"); diff --git a/src/komodo_port.c b/src/komodo_port.c new file mode 100644 index 000000000..11d3ce5b4 --- /dev/null +++ b/src/komodo_port.c @@ -0,0 +1,848 @@ +// +// main.c +// spawn +// +// Created by Mac on 4/7/18. +// Copyright © 2018 SuperNET. All rights reserved. +// + +#include +#include +#include +#include + +uint64_t ASSETCHAINS_COMMISSION; +uint32_t ASSETCHAINS_MAGIC = 2387029918; +uint8_t ASSETCHAINS_OVERRIDE_PUBKEY33[33]; + +struct sha256_vstate { uint64_t length; uint32_t state[8],curlen; uint8_t buf[64]; }; +struct rmd160_vstate { uint64_t length; uint8_t buf[64]; uint32_t curlen, state[5]; }; +union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; +typedef union _bits256 bits256; + +// following is ported from libtom + +#define STORE32L(x, y) \ +{ (y)[3] = (uint8_t)(((x)>>24)&255); (y)[2] = (uint8_t)(((x)>>16)&255); \ +(y)[1] = (uint8_t)(((x)>>8)&255); (y)[0] = (uint8_t)((x)&255); } + +#define LOAD32L(x, y) \ +{ x = (uint32_t)(((uint64_t)((y)[3] & 255)<<24) | \ +((uint32_t)((y)[2] & 255)<<16) | \ +((uint32_t)((y)[1] & 255)<<8) | \ +((uint32_t)((y)[0] & 255))); } + +#define STORE64L(x, y) \ +{ (y)[7] = (uint8_t)(((x)>>56)&255); (y)[6] = (uint8_t)(((x)>>48)&255); \ +(y)[5] = (uint8_t)(((x)>>40)&255); (y)[4] = (uint8_t)(((x)>>32)&255); \ +(y)[3] = (uint8_t)(((x)>>24)&255); (y)[2] = (uint8_t)(((x)>>16)&255); \ +(y)[1] = (uint8_t)(((x)>>8)&255); (y)[0] = (uint8_t)((x)&255); } + +#define LOAD64L(x, y) \ +{ x = (((uint64_t)((y)[7] & 255))<<56)|(((uint64_t)((y)[6] & 255))<<48)| \ +(((uint64_t)((y)[5] & 255))<<40)|(((uint64_t)((y)[4] & 255))<<32)| \ +(((uint64_t)((y)[3] & 255))<<24)|(((uint64_t)((y)[2] & 255))<<16)| \ +(((uint64_t)((y)[1] & 255))<<8)|(((uint64_t)((y)[0] & 255))); } + +#define STORE32H(x, y) \ +{ (y)[0] = (uint8_t)(((x)>>24)&255); (y)[1] = (uint8_t)(((x)>>16)&255); \ +(y)[2] = (uint8_t)(((x)>>8)&255); (y)[3] = (uint8_t)((x)&255); } + +#define LOAD32H(x, y) \ +{ x = (uint32_t)(((uint64_t)((y)[0] & 255)<<24) | \ +((uint32_t)((y)[1] & 255)<<16) | \ +((uint32_t)((y)[2] & 255)<<8) | \ +((uint32_t)((y)[3] & 255))); } + +#define STORE64H(x, y) \ +{ (y)[0] = (uint8_t)(((x)>>56)&255); (y)[1] = (uint8_t)(((x)>>48)&255); \ +(y)[2] = (uint8_t)(((x)>>40)&255); (y)[3] = (uint8_t)(((x)>>32)&255); \ +(y)[4] = (uint8_t)(((x)>>24)&255); (y)[5] = (uint8_t)(((x)>>16)&255); \ +(y)[6] = (uint8_t)(((x)>>8)&255); (y)[7] = (uint8_t)((x)&255); } + +#define LOAD64H(x, y) \ +{ x = (((uint64_t)((y)[0] & 255))<<56)|(((uint64_t)((y)[1] & 255))<<48) | \ +(((uint64_t)((y)[2] & 255))<<40)|(((uint64_t)((y)[3] & 255))<<32) | \ +(((uint64_t)((y)[4] & 255))<<24)|(((uint64_t)((y)[5] & 255))<<16) | \ +(((uint64_t)((y)[6] & 255))<<8)|(((uint64_t)((y)[7] & 255))); } + +// Various logical functions +#define RORc(x, y) ( ((((uint32_t)(x)&0xFFFFFFFFUL)>>(uint32_t)((y)&31)) | ((uint32_t)(x)<<(uint32_t)(32-((y)&31)))) & 0xFFFFFFFFUL) +#define Ch(x,y,z) (z ^ (x & (y ^ z))) +#define Maj(x,y,z) (((x | y) & z) | (x & y)) +#define S(x, n) RORc((x),(n)) +#define R(x, n) (((x)&0xFFFFFFFFUL)>>(n)) +#define Sigma0(x) (S(x, 2) ^ S(x, 13) ^ S(x, 22)) +#define Sigma1(x) (S(x, 6) ^ S(x, 11) ^ S(x, 25)) +#define Gamma0(x) (S(x, 7) ^ S(x, 18) ^ R(x, 3)) +#define Gamma1(x) (S(x, 17) ^ S(x, 19) ^ R(x, 10)) +#define MIN(x, y) ( ((x)<(y))?(x):(y) ) + +static inline int32_t sha256_vcompress(struct sha256_vstate * md,uint8_t *buf) +{ + uint32_t S[8],W[64],t0,t1,i; + for (i=0; i<8; i++) // copy state into S + S[i] = md->state[i]; + for (i=0; i<16; i++) // copy the state into 512-bits into W[0..15] + LOAD32H(W[i],buf + (4*i)); + for (i=16; i<64; i++) // fill W[16..63] + W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16]; + +#define RND(a,b,c,d,e,f,g,h,i,ki) \ +t0 = h + Sigma1(e) + Ch(e, f, g) + ki + W[i]; \ +t1 = Sigma0(a) + Maj(a, b, c); \ +d += t0; \ +h = t0 + t1; + + RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],0,0x428a2f98); + RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],1,0x71374491); + RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],2,0xb5c0fbcf); + RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],3,0xe9b5dba5); + RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],4,0x3956c25b); + RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],5,0x59f111f1); + RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],6,0x923f82a4); + RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],7,0xab1c5ed5); + RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],8,0xd807aa98); + RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],9,0x12835b01); + RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],10,0x243185be); + RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],11,0x550c7dc3); + RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],12,0x72be5d74); + RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],13,0x80deb1fe); + RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],14,0x9bdc06a7); + RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],15,0xc19bf174); + RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],16,0xe49b69c1); + RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],17,0xefbe4786); + RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],18,0x0fc19dc6); + RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],19,0x240ca1cc); + RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],20,0x2de92c6f); + RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],21,0x4a7484aa); + RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],22,0x5cb0a9dc); + RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],23,0x76f988da); + RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],24,0x983e5152); + RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],25,0xa831c66d); + RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],26,0xb00327c8); + RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],27,0xbf597fc7); + RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],28,0xc6e00bf3); + RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],29,0xd5a79147); + RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],30,0x06ca6351); + RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],31,0x14292967); + RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],32,0x27b70a85); + RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],33,0x2e1b2138); + RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],34,0x4d2c6dfc); + RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],35,0x53380d13); + RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],36,0x650a7354); + RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],37,0x766a0abb); + RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],38,0x81c2c92e); + RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],39,0x92722c85); + RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],40,0xa2bfe8a1); + RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],41,0xa81a664b); + RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],42,0xc24b8b70); + RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],43,0xc76c51a3); + RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],44,0xd192e819); + RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],45,0xd6990624); + RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],46,0xf40e3585); + RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],47,0x106aa070); + RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],48,0x19a4c116); + RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],49,0x1e376c08); + RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],50,0x2748774c); + RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],51,0x34b0bcb5); + RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],52,0x391c0cb3); + RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],53,0x4ed8aa4a); + RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],54,0x5b9cca4f); + RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],55,0x682e6ff3); + RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],56,0x748f82ee); + RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],57,0x78a5636f); + RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],58,0x84c87814); + RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],59,0x8cc70208); + RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],60,0x90befffa); + RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],61,0xa4506ceb); + RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],62,0xbef9a3f7); + RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],63,0xc67178f2); +#undef RND + for (i=0; i<8; i++) // feedback + md->state[i] = md->state[i] + S[i]; + return(0); +} + +#undef RORc +#undef Ch +#undef Maj +#undef S +#undef R +#undef Sigma0 +#undef Sigma1 +#undef Gamma0 +#undef Gamma1 + +static inline void sha256_vinit(struct sha256_vstate * md) +{ + md->curlen = 0; + md->length = 0; + md->state[0] = 0x6A09E667UL; + md->state[1] = 0xBB67AE85UL; + md->state[2] = 0x3C6EF372UL; + md->state[3] = 0xA54FF53AUL; + md->state[4] = 0x510E527FUL; + md->state[5] = 0x9B05688CUL; + md->state[6] = 0x1F83D9ABUL; + md->state[7] = 0x5BE0CD19UL; +} + +static inline int32_t sha256_vprocess(struct sha256_vstate *md,const uint8_t *in,uint64_t inlen) +{ + uint64_t n; int32_t err; + if ( md->curlen > sizeof(md->buf) ) + return(-1); + while ( inlen > 0 ) + { + if ( md->curlen == 0 && inlen >= 64 ) + { + if ( (err= sha256_vcompress(md,(uint8_t *)in)) != 0 ) + return(err); + md->length += 64 * 8, in += 64, inlen -= 64; + } + else + { + n = MIN(inlen,64 - md->curlen); + memcpy(md->buf + md->curlen,in,(size_t)n); + md->curlen += n, in += n, inlen -= n; + if ( md->curlen == 64 ) + { + if ( (err= sha256_vcompress(md,md->buf)) != 0 ) + return(err); + md->length += 8*64; + md->curlen = 0; + } + } + } + return(0); +} + +static inline int32_t sha256_vdone(struct sha256_vstate *md,uint8_t *out) +{ + int32_t i; + if ( md->curlen >= sizeof(md->buf) ) + return(-1); + md->length += md->curlen * 8; // increase the length of the message + md->buf[md->curlen++] = (uint8_t)0x80; // append the '1' bit + // if len > 56 bytes we append zeros then compress. Then we can fall back to padding zeros and length encoding like normal. + if ( md->curlen > 56 ) + { + while ( md->curlen < 64 ) + md->buf[md->curlen++] = (uint8_t)0; + sha256_vcompress(md,md->buf); + md->curlen = 0; + } + while ( md->curlen < 56 ) // pad upto 56 bytes of zeroes + md->buf[md->curlen++] = (uint8_t)0; + STORE64H(md->length,md->buf+56); // store length + sha256_vcompress(md,md->buf); + for (i=0; i<8; i++) // copy output + STORE32H(md->state[i],out+(4*i)); + return(0); +} + +void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len) +{ + struct sha256_vstate md; + sha256_vinit(&md); + sha256_vprocess(&md,src,len); + sha256_vdone(&md,hash); +} + +bits256 bits256_doublesha256(char *deprecated,uint8_t *data,int32_t datalen) +{ + bits256 hash,hash2; int32_t i; + vcalc_sha256(0,hash.bytes,data,datalen); + vcalc_sha256(0,hash2.bytes,hash.bytes,sizeof(hash)); + for (i=0; i>(unsigned long)(32-((y)&31)))) & 0xFFFFFFFFUL) + +/* the ten basic operations FF() through III() */ +#define FF(a, b, c, d, e, x, s) \ +(a) += F((b), (c), (d)) + (x);\ +(a) = ROLc((a), (s)) + (e);\ +(c) = ROLc((c), 10); + +#define GG(a, b, c, d, e, x, s) \ +(a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\ +(a) = ROLc((a), (s)) + (e);\ +(c) = ROLc((c), 10); + +#define HH(a, b, c, d, e, x, s) \ +(a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\ +(a) = ROLc((a), (s)) + (e);\ +(c) = ROLc((c), 10); + +#define II(a, b, c, d, e, x, s) \ +(a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\ +(a) = ROLc((a), (s)) + (e);\ +(c) = ROLc((c), 10); + +#define JJ(a, b, c, d, e, x, s) \ +(a) += J((b), (c), (d)) + (x) + 0xa953fd4eUL;\ +(a) = ROLc((a), (s)) + (e);\ +(c) = ROLc((c), 10); + +#define FFF(a, b, c, d, e, x, s) \ +(a) += F((b), (c), (d)) + (x);\ +(a) = ROLc((a), (s)) + (e);\ +(c) = ROLc((c), 10); + +#define GGG(a, b, c, d, e, x, s) \ +(a) += G((b), (c), (d)) + (x) + 0x7a6d76e9UL;\ +(a) = ROLc((a), (s)) + (e);\ +(c) = ROLc((c), 10); + +#define HHH(a, b, c, d, e, x, s) \ +(a) += H((b), (c), (d)) + (x) + 0x6d703ef3UL;\ +(a) = ROLc((a), (s)) + (e);\ +(c) = ROLc((c), 10); + +#define III(a, b, c, d, e, x, s) \ +(a) += I((b), (c), (d)) + (x) + 0x5c4dd124UL;\ +(a) = ROLc((a), (s)) + (e);\ +(c) = ROLc((c), 10); + +#define JJJ(a, b, c, d, e, x, s) \ +(a) += J((b), (c), (d)) + (x) + 0x50a28be6UL;\ +(a) = ROLc((a), (s)) + (e);\ +(c) = ROLc((c), 10); + +static int32_t rmd160_vcompress(struct rmd160_vstate *md,uint8_t *buf) +{ + uint32_t aa,bb,cc,dd,ee,aaa,bbb,ccc,ddd,eee,X[16]; + int i; + + /* load words X */ + for (i = 0; i < 16; i++){ + LOAD32L(X[i], buf + (4 * i)); + } + + /* load state */ + aa = aaa = md->state[0]; + bb = bbb = md->state[1]; + cc = ccc = md->state[2]; + dd = ddd = md->state[3]; + ee = eee = md->state[4]; + + /* round 1 */ + FF(aa, bb, cc, dd, ee, X[ 0], 11); + FF(ee, aa, bb, cc, dd, X[ 1], 14); + FF(dd, ee, aa, bb, cc, X[ 2], 15); + FF(cc, dd, ee, aa, bb, X[ 3], 12); + FF(bb, cc, dd, ee, aa, X[ 4], 5); + FF(aa, bb, cc, dd, ee, X[ 5], 8); + FF(ee, aa, bb, cc, dd, X[ 6], 7); + FF(dd, ee, aa, bb, cc, X[ 7], 9); + FF(cc, dd, ee, aa, bb, X[ 8], 11); + FF(bb, cc, dd, ee, aa, X[ 9], 13); + FF(aa, bb, cc, dd, ee, X[10], 14); + FF(ee, aa, bb, cc, dd, X[11], 15); + FF(dd, ee, aa, bb, cc, X[12], 6); + FF(cc, dd, ee, aa, bb, X[13], 7); + FF(bb, cc, dd, ee, aa, X[14], 9); + FF(aa, bb, cc, dd, ee, X[15], 8); + + /* round 2 */ + GG(ee, aa, bb, cc, dd, X[ 7], 7); + GG(dd, ee, aa, bb, cc, X[ 4], 6); + GG(cc, dd, ee, aa, bb, X[13], 8); + GG(bb, cc, dd, ee, aa, X[ 1], 13); + GG(aa, bb, cc, dd, ee, X[10], 11); + GG(ee, aa, bb, cc, dd, X[ 6], 9); + GG(dd, ee, aa, bb, cc, X[15], 7); + GG(cc, dd, ee, aa, bb, X[ 3], 15); + GG(bb, cc, dd, ee, aa, X[12], 7); + GG(aa, bb, cc, dd, ee, X[ 0], 12); + GG(ee, aa, bb, cc, dd, X[ 9], 15); + GG(dd, ee, aa, bb, cc, X[ 5], 9); + GG(cc, dd, ee, aa, bb, X[ 2], 11); + GG(bb, cc, dd, ee, aa, X[14], 7); + GG(aa, bb, cc, dd, ee, X[11], 13); + GG(ee, aa, bb, cc, dd, X[ 8], 12); + + /* round 3 */ + HH(dd, ee, aa, bb, cc, X[ 3], 11); + HH(cc, dd, ee, aa, bb, X[10], 13); + HH(bb, cc, dd, ee, aa, X[14], 6); + HH(aa, bb, cc, dd, ee, X[ 4], 7); + HH(ee, aa, bb, cc, dd, X[ 9], 14); + HH(dd, ee, aa, bb, cc, X[15], 9); + HH(cc, dd, ee, aa, bb, X[ 8], 13); + HH(bb, cc, dd, ee, aa, X[ 1], 15); + HH(aa, bb, cc, dd, ee, X[ 2], 14); + HH(ee, aa, bb, cc, dd, X[ 7], 8); + HH(dd, ee, aa, bb, cc, X[ 0], 13); + HH(cc, dd, ee, aa, bb, X[ 6], 6); + HH(bb, cc, dd, ee, aa, X[13], 5); + HH(aa, bb, cc, dd, ee, X[11], 12); + HH(ee, aa, bb, cc, dd, X[ 5], 7); + HH(dd, ee, aa, bb, cc, X[12], 5); + + /* round 4 */ + II(cc, dd, ee, aa, bb, X[ 1], 11); + II(bb, cc, dd, ee, aa, X[ 9], 12); + II(aa, bb, cc, dd, ee, X[11], 14); + II(ee, aa, bb, cc, dd, X[10], 15); + II(dd, ee, aa, bb, cc, X[ 0], 14); + II(cc, dd, ee, aa, bb, X[ 8], 15); + II(bb, cc, dd, ee, aa, X[12], 9); + II(aa, bb, cc, dd, ee, X[ 4], 8); + II(ee, aa, bb, cc, dd, X[13], 9); + II(dd, ee, aa, bb, cc, X[ 3], 14); + II(cc, dd, ee, aa, bb, X[ 7], 5); + II(bb, cc, dd, ee, aa, X[15], 6); + II(aa, bb, cc, dd, ee, X[14], 8); + II(ee, aa, bb, cc, dd, X[ 5], 6); + II(dd, ee, aa, bb, cc, X[ 6], 5); + II(cc, dd, ee, aa, bb, X[ 2], 12); + + /* round 5 */ + JJ(bb, cc, dd, ee, aa, X[ 4], 9); + JJ(aa, bb, cc, dd, ee, X[ 0], 15); + JJ(ee, aa, bb, cc, dd, X[ 5], 5); + JJ(dd, ee, aa, bb, cc, X[ 9], 11); + JJ(cc, dd, ee, aa, bb, X[ 7], 6); + JJ(bb, cc, dd, ee, aa, X[12], 8); + JJ(aa, bb, cc, dd, ee, X[ 2], 13); + JJ(ee, aa, bb, cc, dd, X[10], 12); + JJ(dd, ee, aa, bb, cc, X[14], 5); + JJ(cc, dd, ee, aa, bb, X[ 1], 12); + JJ(bb, cc, dd, ee, aa, X[ 3], 13); + JJ(aa, bb, cc, dd, ee, X[ 8], 14); + JJ(ee, aa, bb, cc, dd, X[11], 11); + JJ(dd, ee, aa, bb, cc, X[ 6], 8); + JJ(cc, dd, ee, aa, bb, X[15], 5); + JJ(bb, cc, dd, ee, aa, X[13], 6); + + /* parallel round 1 */ + JJJ(aaa, bbb, ccc, ddd, eee, X[ 5], 8); + JJJ(eee, aaa, bbb, ccc, ddd, X[14], 9); + JJJ(ddd, eee, aaa, bbb, ccc, X[ 7], 9); + JJJ(ccc, ddd, eee, aaa, bbb, X[ 0], 11); + JJJ(bbb, ccc, ddd, eee, aaa, X[ 9], 13); + JJJ(aaa, bbb, ccc, ddd, eee, X[ 2], 15); + JJJ(eee, aaa, bbb, ccc, ddd, X[11], 15); + JJJ(ddd, eee, aaa, bbb, ccc, X[ 4], 5); + JJJ(ccc, ddd, eee, aaa, bbb, X[13], 7); + JJJ(bbb, ccc, ddd, eee, aaa, X[ 6], 7); + JJJ(aaa, bbb, ccc, ddd, eee, X[15], 8); + JJJ(eee, aaa, bbb, ccc, ddd, X[ 8], 11); + JJJ(ddd, eee, aaa, bbb, ccc, X[ 1], 14); + JJJ(ccc, ddd, eee, aaa, bbb, X[10], 14); + JJJ(bbb, ccc, ddd, eee, aaa, X[ 3], 12); + JJJ(aaa, bbb, ccc, ddd, eee, X[12], 6); + + /* parallel round 2 */ + III(eee, aaa, bbb, ccc, ddd, X[ 6], 9); + III(ddd, eee, aaa, bbb, ccc, X[11], 13); + III(ccc, ddd, eee, aaa, bbb, X[ 3], 15); + III(bbb, ccc, ddd, eee, aaa, X[ 7], 7); + III(aaa, bbb, ccc, ddd, eee, X[ 0], 12); + III(eee, aaa, bbb, ccc, ddd, X[13], 8); + III(ddd, eee, aaa, bbb, ccc, X[ 5], 9); + III(ccc, ddd, eee, aaa, bbb, X[10], 11); + III(bbb, ccc, ddd, eee, aaa, X[14], 7); + III(aaa, bbb, ccc, ddd, eee, X[15], 7); + III(eee, aaa, bbb, ccc, ddd, X[ 8], 12); + III(ddd, eee, aaa, bbb, ccc, X[12], 7); + III(ccc, ddd, eee, aaa, bbb, X[ 4], 6); + III(bbb, ccc, ddd, eee, aaa, X[ 9], 15); + III(aaa, bbb, ccc, ddd, eee, X[ 1], 13); + III(eee, aaa, bbb, ccc, ddd, X[ 2], 11); + + /* parallel round 3 */ + HHH(ddd, eee, aaa, bbb, ccc, X[15], 9); + HHH(ccc, ddd, eee, aaa, bbb, X[ 5], 7); + HHH(bbb, ccc, ddd, eee, aaa, X[ 1], 15); + HHH(aaa, bbb, ccc, ddd, eee, X[ 3], 11); + HHH(eee, aaa, bbb, ccc, ddd, X[ 7], 8); + HHH(ddd, eee, aaa, bbb, ccc, X[14], 6); + HHH(ccc, ddd, eee, aaa, bbb, X[ 6], 6); + HHH(bbb, ccc, ddd, eee, aaa, X[ 9], 14); + HHH(aaa, bbb, ccc, ddd, eee, X[11], 12); + HHH(eee, aaa, bbb, ccc, ddd, X[ 8], 13); + HHH(ddd, eee, aaa, bbb, ccc, X[12], 5); + HHH(ccc, ddd, eee, aaa, bbb, X[ 2], 14); + HHH(bbb, ccc, ddd, eee, aaa, X[10], 13); + HHH(aaa, bbb, ccc, ddd, eee, X[ 0], 13); + HHH(eee, aaa, bbb, ccc, ddd, X[ 4], 7); + HHH(ddd, eee, aaa, bbb, ccc, X[13], 5); + + /* parallel round 4 */ + GGG(ccc, ddd, eee, aaa, bbb, X[ 8], 15); + GGG(bbb, ccc, ddd, eee, aaa, X[ 6], 5); + GGG(aaa, bbb, ccc, ddd, eee, X[ 4], 8); + GGG(eee, aaa, bbb, ccc, ddd, X[ 1], 11); + GGG(ddd, eee, aaa, bbb, ccc, X[ 3], 14); + GGG(ccc, ddd, eee, aaa, bbb, X[11], 14); + GGG(bbb, ccc, ddd, eee, aaa, X[15], 6); + GGG(aaa, bbb, ccc, ddd, eee, X[ 0], 14); + GGG(eee, aaa, bbb, ccc, ddd, X[ 5], 6); + GGG(ddd, eee, aaa, bbb, ccc, X[12], 9); + GGG(ccc, ddd, eee, aaa, bbb, X[ 2], 12); + GGG(bbb, ccc, ddd, eee, aaa, X[13], 9); + GGG(aaa, bbb, ccc, ddd, eee, X[ 9], 12); + GGG(eee, aaa, bbb, ccc, ddd, X[ 7], 5); + GGG(ddd, eee, aaa, bbb, ccc, X[10], 15); + GGG(ccc, ddd, eee, aaa, bbb, X[14], 8); + + /* parallel round 5 */ + FFF(bbb, ccc, ddd, eee, aaa, X[12] , 8); + FFF(aaa, bbb, ccc, ddd, eee, X[15] , 5); + FFF(eee, aaa, bbb, ccc, ddd, X[10] , 12); + FFF(ddd, eee, aaa, bbb, ccc, X[ 4] , 9); + FFF(ccc, ddd, eee, aaa, bbb, X[ 1] , 12); + FFF(bbb, ccc, ddd, eee, aaa, X[ 5] , 5); + FFF(aaa, bbb, ccc, ddd, eee, X[ 8] , 14); + FFF(eee, aaa, bbb, ccc, ddd, X[ 7] , 6); + FFF(ddd, eee, aaa, bbb, ccc, X[ 6] , 8); + FFF(ccc, ddd, eee, aaa, bbb, X[ 2] , 13); + FFF(bbb, ccc, ddd, eee, aaa, X[13] , 6); + FFF(aaa, bbb, ccc, ddd, eee, X[14] , 5); + FFF(eee, aaa, bbb, ccc, ddd, X[ 0] , 15); + FFF(ddd, eee, aaa, bbb, ccc, X[ 3] , 13); + FFF(ccc, ddd, eee, aaa, bbb, X[ 9] , 11); + FFF(bbb, ccc, ddd, eee, aaa, X[11] , 11); + + /* combine results */ + ddd += cc + md->state[1]; /* final result for md->state[0] */ + md->state[1] = md->state[2] + dd + eee; + md->state[2] = md->state[3] + ee + aaa; + md->state[3] = md->state[4] + aa + bbb; + md->state[4] = md->state[0] + bb + ccc; + md->state[0] = ddd; + + return 0; +} + +/** + Initialize the hash state + @param md The hash state you wish to initialize + @return 0 if successful + */ +int rmd160_vinit(struct rmd160_vstate * md) +{ + md->state[0] = 0x67452301UL; + md->state[1] = 0xefcdab89UL; + md->state[2] = 0x98badcfeUL; + md->state[3] = 0x10325476UL; + md->state[4] = 0xc3d2e1f0UL; + md->curlen = 0; + md->length = 0; + return 0; +} +#define HASH_PROCESS(func_name, compress_name, state_var, block_size) \ +int func_name (struct rmd160_vstate * md, const unsigned char *in, unsigned long inlen) \ +{ \ +unsigned long n; \ +int err; \ +if (md->curlen > sizeof(md->buf)) { \ +return -1; \ +} \ +while (inlen > 0) { \ +if (md->curlen == 0 && inlen >= block_size) { \ +if ((err = compress_name (md, (unsigned char *)in)) != 0) { \ +return err; \ +} \ +md->length += block_size * 8; \ +in += block_size; \ +inlen -= block_size; \ +} else { \ +n = MIN(inlen, (block_size - md->curlen)); \ +memcpy(md->buf + md->curlen, in, (size_t)n); \ +md->curlen += n; \ +in += n; \ +inlen -= n; \ +if (md->curlen == block_size) { \ +if ((err = compress_name (md, md->buf)) != 0) { \ +return err; \ +} \ +md->length += 8*block_size; \ +md->curlen = 0; \ +} \ +} \ +} \ +return 0; \ +} + +/** + Process a block of memory though the hash + @param md The hash state + @param in The data to hash + @param inlen The length of the data (octets) + @return 0 if successful + */ +HASH_PROCESS(rmd160_vprocess, rmd160_vcompress, rmd160, 64) + +/** + Terminate the hash to get the digest + @param md The hash state + @param out [out] The destination of the hash (20 bytes) + @return 0 if successful + */ +int rmd160_vdone(struct rmd160_vstate * md, unsigned char *out) +{ + int i; + if (md->curlen >= sizeof(md->buf)) { + return -1; + } + /* increase the length of the message */ + md->length += md->curlen * 8; + + /* append the '1' bit */ + md->buf[md->curlen++] = (unsigned char)0x80; + + /* if the length is currently above 56 bytes we append zeros + * then compress. Then we can fall back to padding zeros and length + * encoding like normal. + */ + if (md->curlen > 56) { + while (md->curlen < 64) { + md->buf[md->curlen++] = (unsigned char)0; + } + rmd160_vcompress(md, md->buf); + md->curlen = 0; + } + /* pad upto 56 bytes of zeroes */ + while (md->curlen < 56) { + md->buf[md->curlen++] = (unsigned char)0; + } + /* store length */ + STORE64L(md->length, md->buf+56); + rmd160_vcompress(md, md->buf); + /* copy output */ + for (i = 0; i < 5; i++) { + STORE32L(md->state[i], out+(4*i)); + } + return 0; +} + +void calc_rmd160(char deprecated[41],uint8_t buf[20],uint8_t *msg,int32_t len) +{ + struct rmd160_vstate md; + rmd160_vinit(&md); + rmd160_vprocess(&md,msg,len); + rmd160_vdone(&md, buf); +} +#undef F +#undef G +#undef H +#undef I +#undef J +#undef ROLc +#undef FF +#undef GG +#undef HH +#undef II +#undef JJ +#undef FFF +#undef GGG +#undef HHH +#undef III +#undef JJJ + +static const uint32_t crc32_tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +uint32_t calc_crc32(uint32_t crc,const void *buf,size_t size) +{ + const uint8_t *p; + + p = (const uint8_t *)buf; + crc = crc ^ ~0U; + + while (size--) + crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + + return crc ^ ~0U; +} + +void calc_rmd160_sha256(uint8_t rmd160[20],uint8_t *data,int32_t datalen) +{ + bits256 hash; + vcalc_sha256(0,hash.bytes,data,datalen); + calc_rmd160(0,rmd160,hash.bytes,sizeof(hash)); +} + +int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp) +{ + int32_t i; uint64_t x; + if ( rwflag == 0 ) + { + x = 0; + for (i=len-1; i>=0; i--) + { + x <<= 8; + x |= serialized[i]; + } + switch ( len ) + { + case 1: *(uint8_t *)endianedp = (uint8_t)x; break; + case 2: *(uint16_t *)endianedp = (uint16_t)x; break; + case 4: *(uint32_t *)endianedp = (uint32_t)x; break; + case 8: *(uint64_t *)endianedp = (uint64_t)x; break; + } + } + else + { + x = 0; + switch ( len ) + { + case 1: x = *(uint8_t *)endianedp; break; + case 2: x = *(uint16_t *)endianedp; break; + case 4: x = *(uint32_t *)endianedp; break; + case 8: x = *(uint64_t *)endianedp; break; + } + for (i=0; i>= 8) + serialized[i] = (uint8_t)(x & 0xff); + } + return(len); +} + +uint32_t komodo_assetmagic(char *symbol,uint64_t supply,uint8_t *extraptr,int32_t extralen) +{ + uint8_t buf[512]; uint32_t crc0=0; int32_t len = 0; bits256 hash; + if ( strcmp(symbol,"KMD") == 0 ) + return(0x8de4eef9); + len = iguana_rwnum(1,&buf[len],sizeof(supply),(void *)&supply); + strcpy((char *)&buf[len],symbol); + len += strlen(symbol); + if ( extraptr != 0 && extralen != 0 ) + { + vcalc_sha256(0,hash.bytes,extraptr,extralen); + crc0 = hash.uints[0]; + } + return(calc_crc32(crc0,buf,len)); +} + +uint16_t komodo_assetport(uint32_t magic,int32_t extralen) +{ + if ( magic == 0x8de4eef9 ) + return(7770); + else if ( extralen == 0 ) + return(8000 + (magic % 7777)); + else return(16000 + (magic % 49500)); +} + +uint16_t komodo_port(char *symbol,uint64_t supply,uint32_t *magicp,uint8_t *extraptr,int32_t extralen) +{ + if ( symbol == 0 || symbol[0] == 0 || strcmp("KMD",symbol) == 0 ) + { + *magicp = 0x8de4eef9; + return(7770); + } + *magicp = komodo_assetmagic(symbol,supply,extraptr,extralen); + return(komodo_assetport(*magicp,extralen)); +} + +uint16_t komodo_calcport(char *name,uint64_t supply,uint64_t endsubsidy,uint64_t reward,uint64_t halving,uint64_t decay) +{ + uint8_t extrabuf[4096],*extraptr=0; int32_t extralen=0; + if ( halving != 0 && halving < 1440 ) + { + halving = 1440; + printf("halving must be at least 1440 blocks\n"); + } + if ( decay == 100000000 && endsubsidy == 0 ) + { + decay = 0; + printf("decay of 100000000 means linear and that needs endsubsidy\n"); + } + else if ( decay > 100000000 ) + { + decay = 0; + printf("decay cant be more than 100000000\n"); + } + if ( endsubsidy != 0 || reward != 0 || halving != 0 || decay != 0 || ASSETCHAINS_COMMISSION != 0 ) + { + printf("end.%llu reward.%llu halving.%llu decay.%llu perc.%llu\n",(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,(long long)ASSETCHAINS_COMMISSION); + extraptr = extrabuf; + memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(endsubsidy),(void *)&endsubsidy); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(reward),(void *)&reward); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(halving),(void *)&halving); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(decay),(void *)&decay); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_COMMISSION),(void *)&ASSETCHAINS_COMMISSION); + } + return(komodo_port(name,supply,&ASSETCHAINS_MAGIC,extraptr,extralen)); +} + +int main(int argc, char * argv[]) +{ + uint16_t rpcport; uint64_t supply=10,endsubsidy,reward,halving,decay; + endsubsidy = reward = halving = decay = 0; + if ( argc < 2 ) + { + printf("%s usage: name supply endsubsidy reward halving decay\n",argv[0]); + return(-1); + } + if ( argc > 2 ) + supply = (long long)atof(argv[2]); + if ( argc > 3 ) + endsubsidy = (long long)atof(argv[3]); + if ( argc > 4 ) + reward = (long long)atof(argv[4]); + if ( argc > 5 ) + halving = (long long)atof(argv[5]); + if ( argc > 6 ) + decay = (long long)atof(argv[6]); + rpcport = 1 + komodo_calcport(argv[1],supply,endsubsidy,reward,halving,decay); + printf("%s supply=%llu endsubsidy=%llu reward=%llu halving=%llu decay=%llu -> rpcport %u\n",argv[1],(long long)supply,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport); + return(0); +} From 9e5384c9b4a1615889450a211ff946f00a26cf63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 13:07:25 +0300 Subject: [PATCH 004/202] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 999200c13..34b55a086 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1564,7 +1564,7 @@ void komodo_args(char *argv0) } if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 ) { - printf("end.%llu reward.%llu halving.%llu decay.%llu perc.%llu\n",(long long)ASSETCHAINS_ENDSUBSIDY,(long long)ASSETCHAINS_REWARD,(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,(long long)ASSETCHAINS_COMMISSION); + fprintf(stderr,"end.%llu reward.%llu halving.%llu decay.%llu perc.%llu\n",(long long)ASSETCHAINS_ENDSUBSIDY,(long long)ASSETCHAINS_REWARD,(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,(long long)ASSETCHAINS_COMMISSION); extraptr = extrabuf; memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_ENDSUBSIDY),(void *)&ASSETCHAINS_ENDSUBSIDY); From c244ea42457e7e4fa0456c2dced34156c88f3956 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 13:14:08 +0300 Subject: [PATCH 005/202] komodo_port.c -gen option --- src/komodo_port.c | 60 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/src/komodo_port.c b/src/komodo_port.c index 11d3ce5b4..d866ea5c8 100644 --- a/src/komodo_port.c +++ b/src/komodo_port.c @@ -825,24 +825,56 @@ uint16_t komodo_calcport(char *name,uint64_t supply,uint64_t endsubsidy,uint64_t int main(int argc, char * argv[]) { - uint16_t rpcport; uint64_t supply=10,endsubsidy,reward,halving,decay; + uint16_t rpcport; int32_t i,j,offset=0,num = 1; uint64_t supply=10,endsubsidy,reward,halving,decay; uint8_t *allocated=0; endsubsidy = reward = halving = decay = 0; if ( argc < 2 ) { - printf("%s usage: name supply endsubsidy reward halving decay\n",argv[0]); + printf("%s name supply endsubsidy reward halving decay\n",argv[0]); + printf("%s -gen num name supply endsubsidy reward halving decay\n",argv[0]); return(-1); } - if ( argc > 2 ) - supply = (long long)atof(argv[2]); - if ( argc > 3 ) - endsubsidy = (long long)atof(argv[3]); - if ( argc > 4 ) - reward = (long long)atof(argv[4]); - if ( argc > 5 ) - halving = (long long)atof(argv[5]); - if ( argc > 6 ) - decay = (long long)atof(argv[6]); - rpcport = 1 + komodo_calcport(argv[1],supply,endsubsidy,reward,halving,decay); - printf("%s supply=%llu endsubsidy=%llu reward=%llu halving=%llu decay=%llu -> rpcport %u\n",argv[1],(long long)supply,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport); + if ( strcmp(argv[1],"-gen") == 0 ) + { + num = atoi(argv[2]); + offset = 2; + allocated = calloc(1,1 << 16); + } + if ( argc > offset + 2 ) + supply = (long long)atof(argv[offset + 2]); + if ( argc > offset + 3 ) + endsubsidy = (long long)atof(argv[offset + 3]); + if ( argc > offset + 4 ) + reward = (long long)atof(argv[offset + 4]); + if ( argc > offset + 5 ) + halving = (long long)atof(argv[offset + 5]); + if ( argc > offset + 6 ) + decay = (long long)atof(argv[offset + 6]); + rpcport = 1 + komodo_calcport(argv[offset + 1],supply,endsubsidy,reward,halving,decay); + printf("./komodod -ac_name=%s -ac_supply=%llu -ac_end=%llu -ac_reward=%llu -ac_halving=%llu -ac_decay=%llu & # rpcport %u\n",argv[offset + 1],(long long)supply,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport); + if ( allocated != 0 ) + { + char name[64],newname[64]; + strcpy(name,argv[offset + 1]); + allocated[rpcport] = 1; + allocated[rpcport-1] = 1; + for (i=0; i Date: Sat, 7 Apr 2018 14:27:17 +0300 Subject: [PATCH 006/202] Sane -ac_perc --- src/komodo_gateway.h | 37 ++++++++++++++++++++++++------------- src/miner.cpp | 13 +++++++++++++ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c8fc03980..cc005d9f8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -650,6 +650,22 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) void komodo_passport_iteration(); +uint64_t komodo_commission(const CBlock &block) +{ + int32_t i,j,n,txn_count; uint64_t total = 0; + txn_count = block.vtx.size(); + for (i=0; i 1 ) { - script = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data(); + script = (uint8_t *)block.vtx[0].vout[1].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) return(-1); - total = 0; - for (i=1; i Date: Sat, 7 Apr 2018 14:28:37 +0300 Subject: [PATCH 007/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cc005d9f8..0ba6ec2d3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -741,7 +741,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above } return(0); } - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].size() > 1 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { script = (uint8_t *)block.vtx[0].vout[1].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) From c48fd6e3180c9ef8d9adf0ea70016fdcde86a71d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 14:30:34 +0300 Subject: [PATCH 008/202] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index c14c4286a..f49de0314 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -398,6 +398,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (checktoshis= komodo_commission(block)) != 0 ) { + int32_t i; uint8_t *ptr; txNew.vout.resize(2); txNew.vout[1].nValue = checktoshis; txNew.vout[1].scriptPubKey.resize(35); From f9155fec3ca21159605046f364775abd414e2a63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 14:32:54 +0300 Subject: [PATCH 009/202] Test --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index f49de0314..1e55a2f09 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -190,7 +190,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nTime = GetAdjustedTime(); const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); CCoinsViewCache view(pcoinsTip); - uint32_t expired; + uint32_t expired; uint64_t commission; // Priority order to process transactions list vOrphan; // list memory doesn't move @@ -396,11 +396,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Add fees txNew.vout[0].nValue += nFees; txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (checktoshis= komodo_commission(block)) != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); - txNew.vout[1].nValue = checktoshis; + txNew.vout[1].nValue = commission; txNew.vout[1].scriptPubKey.resize(35); ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); ptr[0] = 33; From 7313172ace3fea6d9f2f631abc581fc53ab4b9bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 14:40:38 +0300 Subject: [PATCH 010/202] Test --- src/komodo_gateway.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0ba6ec2d3..f061a5dbe 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -660,9 +660,13 @@ uint64_t komodo_commission(const CBlock &block) for (j=0; j %.8f\n",dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); return((total * ASSETCHAINS_COMMISSION) / COIN); } From 72af1b7ea5ddf5ed89effc4adcff163bba6cb1b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 14:44:09 +0300 Subject: [PATCH 011/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f061a5dbe..b40d0dad1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -652,7 +652,7 @@ void komodo_passport_iteration(); uint64_t komodo_commission(const CBlock &block) { - int32_t i,j,n,txn_count; uint64_t total = 0; + int32_t i,j,n=0,txn_count; uint64_t total = 0; txn_count = block.vtx.size(); for (i=0; i %.8f\n",dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); + fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); return((total * ASSETCHAINS_COMMISSION) / COIN); } From 418ff77170e7097f3d7d10c624adcbaaacd964f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 14:48:03 +0300 Subject: [PATCH 012/202] Test --- src/komodo_gateway.h | 2 +- src/miner.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b40d0dad1..f34ca1e3d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -659,9 +659,9 @@ uint64_t komodo_commission(const CBlock &block) n = block.vtx[i].vout.size(); for (j=0; jblock)) != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(*pblock)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); From c000c9ca1d6a9b423eff9a9be27651754da66c63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 14:55:14 +0300 Subject: [PATCH 013/202] Test --- src/komodo_utils.h | 2 +- src/miner.cpp | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 34b55a086..4788b039e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1564,7 +1564,7 @@ void komodo_args(char *argv0) } if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 ) { - fprintf(stderr,"end.%llu reward.%llu halving.%llu decay.%llu perc.%llu\n",(long long)ASSETCHAINS_ENDSUBSIDY,(long long)ASSETCHAINS_REWARD,(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,(long long)ASSETCHAINS_COMMISSION); + fprintf(stderr,"end.%llu reward.%llu halving.%llu decay.%llu perc %.4f [%02x]\n",(long long)ASSETCHAINS_ENDSUBSIDY,(long long)ASSETCHAINS_REWARD,(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]); extraptr = extrabuf; memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_ENDSUBSIDY),(void *)&ASSETCHAINS_ENDSUBSIDY); diff --git a/src/miner.cpp b/src/miner.cpp index b61ebe936..de641d5c8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -396,18 +396,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Add fees txNew.vout[0].nValue += nFees; txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(*pblock)) != 0 ) - { - int32_t i; uint8_t *ptr; - txNew.vout.resize(2); - txNew.vout[1].nValue = commission; - txNew.vout[1].scriptPubKey.resize(35); - ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); - ptr[0] = 33; - for (i=0; i<33; i++) - ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; - ptr[34] = OP_CHECKSIG; - } /*if ( ASSETCHAINS_SYMBOL[0] == 0 ) { @@ -434,6 +422,19 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) }*/ pblock->vtx[0] = txNew; + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 ) + { + int32_t i; uint8_t *ptr; + txNew.vout.resize(2); + txNew.vout[1].nValue = commission; + txNew.vout[1].scriptPubKey.resize(35); + ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); + ptr[0] = 33; + for (i=0; i<33; i++) + ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; + ptr[34] = OP_CHECKSIG; + printf("autocreate commision vout\n"); + } pblocktemplate->vTxFees[0] = -nFees; // Randomise nonce arith_uint256 nonce = UintToArith256(GetRandHash()); From 105aceb5a8c8a5bc055998917a605056258f3c12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 14:57:47 +0300 Subject: [PATCH 014/202] Test --- src/miner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index de641d5c8..74bbbefc2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -425,10 +425,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 ) { int32_t i; uint8_t *ptr; - txNew.vout.resize(2); - txNew.vout[1].nValue = commission; - txNew.vout[1].scriptPubKey.resize(35); - ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); + pblock->vtx[0].resize(2); + pblock->vtx[0].vout[1].nValue = commission; + pblock->vtx[0].vout[1].scriptPubKey.resize(35); + ptr = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); ptr[0] = 33; for (i=0; i<33; i++) ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; From 9ed1be037d11577260b855f6e87286c431920865 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 14:59:11 +0300 Subject: [PATCH 015/202] Test --- src/miner.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 74bbbefc2..56b21492f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -422,18 +422,19 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) }*/ pblock->vtx[0] = txNew; - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(*pblock)) != 0 ) { int32_t i; uint8_t *ptr; - pblock->vtx[0].resize(2); - pblock->vtx[0].vout[1].nValue = commission; - pblock->vtx[0].vout[1].scriptPubKey.resize(35); - ptr = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + txNew.vout.resize(2); + txNew.vout[1].nValue = commission; + txNew.vout[1].scriptPubKey.resize(35); + ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); ptr[0] = 33; for (i=0; i<33; i++) ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; ptr[34] = OP_CHECKSIG; printf("autocreate commision vout\n"); + pblock->vtx[0] = txNew; } pblocktemplate->vTxFees[0] = -nFees; // Randomise nonce From 852af44bb5fa02f38997e7344b4aa041af05482b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:00:40 +0300 Subject: [PATCH 016/202] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 56b21492f..22f1ed10c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -422,7 +422,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) }*/ pblock->vtx[0] = txNew; - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(*pblock)) != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); From c4c3dbe2502e74d8eeb7a62589a044e16a3b2b31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:08:32 +0300 Subject: [PATCH 017/202] Test --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 4788b039e..4e4cf1440 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1582,6 +1582,7 @@ void komodo_args(char *argv0) else if ( ASSETCHAINS_REWARD == 0 ) MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN; else MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + ASSETCHAINS_REWARD * (ASSETCHAINS_ENDSUBSIDY==0 ? 10000000 : ASSETCHAINS_ENDSUBSIDY); + MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSOION) / COIN; //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_PORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From ecf5f2b37268d30a604c27f39e132318ea11b700 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:09:17 +0300 Subject: [PATCH 018/202] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 4e4cf1440..6268c6108 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1582,7 +1582,7 @@ void komodo_args(char *argv0) else if ( ASSETCHAINS_REWARD == 0 ) MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN; else MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + ASSETCHAINS_REWARD * (ASSETCHAINS_ENDSUBSIDY==0 ? 10000000 : ASSETCHAINS_ENDSUBSIDY); - MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSOION) / COIN; + MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / COIN; //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_PORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From 10ad05f68ae75f7d41c25531b74d9892d11cc9ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:10:24 +0300 Subject: [PATCH 019/202] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 6268c6108..7c189be50 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1582,7 +1582,7 @@ void komodo_args(char *argv0) else if ( ASSETCHAINS_REWARD == 0 ) MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN; else MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + ASSETCHAINS_REWARD * (ASSETCHAINS_ENDSUBSIDY==0 ? 10000000 : ASSETCHAINS_ENDSUBSIDY); - MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / COIN; + MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / SATOSHIDEN; //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_PORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From a43401b400f8f90bfdf5bbe5f3367eb616f17b4c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:19:20 +0300 Subject: [PATCH 020/202] Test --- src/komodo_gateway.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f34ca1e3d..89b4b0c93 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -740,25 +740,25 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above } else { - if ( overflow != 0 || total > 0 ) + if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) + { + script = (uint8_t *)block.vtx[0].vout[1].scriptPubKey.data(); + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + return(-1); + if ( (checktoshis = komodo_commission(block)) != 0 ) + { + if ( block.vtx[0].vout.size() < 2 || block.vtx[0].vout[1].nValue != checktoshis ) + { + fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue)); + return(-1); + } + } + } + else if ( overflow != 0 || total > 0 ) return(-1); } return(0); } - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) - { - script = (uint8_t *)block.vtx[0].vout[1].scriptPubKey.data(); - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) - return(-1); - if ( (checktoshis = komodo_commission(block)) != 0 ) - { - if ( block.vtx[0].vout.size() < 2 || block.vtx[0].vout[1].nValue != checktoshis ) - { - fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue)); - return(-1); - } - } - } /* //fprintf(stderr,"ht.%d n.%d nValue %.8f (%d %d %d)\n",height,n,dstr(block.vtx[0].vout[1].nValue),KOMODO_PAX,komodo_isrealtime(&ht),KOMODO_PASSPORT_INITDONE); offset += komodo_scriptitemlen(&opretlen,&script[offset]); From 0587a0e53778cf4253d53f9f59668d1d51d3184c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:25:09 +0300 Subject: [PATCH 021/202] CTEST --- src/ctest | 1 + 1 file changed, 1 insertion(+) create mode 100755 src/ctest diff --git a/src/ctest b/src/ctest new file mode 100755 index 000000000..1bb1a92a8 --- /dev/null +++ b/src/ctest @@ -0,0 +1 @@ +./komodod -ac_name=CTEST -ac_supply=1000000 -ac_perc=100000 -ac_pubkey=02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92 -ac_reward=300000000 -addnode=136.243.58.134 & From 146d2aa22d13dfa14ba8b93e6e87f30efc3ba12a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:26:50 +0300 Subject: [PATCH 022/202] Test --- src/komodo_gateway.h | 4 ++-- src/miner.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 89b4b0c93..7e4666d4b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -659,14 +659,14 @@ uint64_t komodo_commission(const CBlock &block) n = block.vtx[i].vout.size(); for (j=0; j %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); + //fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); return((total * ASSETCHAINS_COMMISSION) / COIN); } diff --git a/src/miner.cpp b/src/miner.cpp index 22f1ed10c..46fcc342a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -433,7 +433,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) for (i=0; i<33; i++) ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; ptr[34] = OP_CHECKSIG; - printf("autocreate commision vout\n"); + //printf("autocreate commision vout\n"); pblock->vtx[0] = txNew; } pblocktemplate->vTxFees[0] = -nFees; From de4a435c680da069eaff08adb35f7986a1cf7dbe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:42:18 +0300 Subject: [PATCH 023/202] Test --- src/komodo_gateway.h | 4 ++-- src/main.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7e4666d4b..50641b589 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -751,10 +751,10 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue)); return(-1); - } + } else return(0); } } - else if ( overflow != 0 || total > 0 ) + if ( overflow != 0 || total > 0 ) return(-1); } return(0); diff --git a/src/main.cpp b/src/main.cpp index f45ad7bad..a0b4084e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2585,6 +2585,16 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001); CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus()) + sum; + if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) + { + uint64_t checktoshis; + if ( (checktoshis = komodo_commission(block)) != 0 ) + { + if ( block.vtx[0].vout.size() == 2 && block.vtx[0].vout[1].nValue == checktoshis ) + { + } else fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue)); + } + } if ( block.vtx[0].GetValueOut() > blockReward+1 ) { if ( pindex->nHeight >= KOMODO_NOTARIES_HEIGHT1 || block.vtx[0].vout[0].nValue > blockReward ) @@ -2593,7 +2603,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0].GetValueOut(), blockReward), REJECT_INVALID, "bad-cb-amount"); - } else if ( NOTARY_PUBKEY33[0] != 0 ) + } //else if ( NOTARY_PUBKEY33[0] != 0 ) fprintf(stderr,"allow nHeight.%d coinbase %.8f vs %.8f interest %.8f\n",(int32_t)pindex->nHeight,dstr(block.vtx[0].GetValueOut()),dstr(blockReward),dstr(sum)); } if (!control.Wait()) From 479f8ea9b8e96978e9a9decd0a15cdaa90dd6724 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:48:02 +0300 Subject: [PATCH 024/202] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7c189be50..3973bf305 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1564,7 +1564,7 @@ void komodo_args(char *argv0) } if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 ) { - fprintf(stderr,"end.%llu reward.%llu halving.%llu decay.%llu perc %.4f [%02x]\n",(long long)ASSETCHAINS_ENDSUBSIDY,(long long)ASSETCHAINS_REWARD,(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]); + fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]); extraptr = extrabuf; memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_ENDSUBSIDY),(void *)&ASSETCHAINS_ENDSUBSIDY); From b7dc56995ed0a7861bb5150d880b51407197f92c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:48:51 +0300 Subject: [PATCH 025/202] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a0b4084e8..fd9443f7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2591,8 +2591,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if ( (checktoshis = komodo_commission(block)) != 0 ) { if ( block.vtx[0].vout.size() == 2 && block.vtx[0].vout[1].nValue == checktoshis ) - { - } else fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue)); + blockReward += checktoshis; + else fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue)); } } if ( block.vtx[0].GetValueOut() > blockReward+1 ) From ea1244288b9a478f0942e1ca9ff8e7ee38252527 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 15:50:31 +0300 Subject: [PATCH 026/202] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index fd9443f7c..f6b8feba0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2597,13 +2597,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } if ( block.vtx[0].GetValueOut() > blockReward+1 ) { - if ( pindex->nHeight >= KOMODO_NOTARIES_HEIGHT1 || block.vtx[0].vout[0].nValue > blockReward ) + if ( ASSETCHAINS_SYMBOL[0] != 0 || pindex->nHeight >= KOMODO_NOTARIES_HEIGHT1 || block.vtx[0].vout[0].nValue > blockReward ) { return state.DoS(100, error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0].GetValueOut(), blockReward), REJECT_INVALID, "bad-cb-amount"); - } //else if ( NOTARY_PUBKEY33[0] != 0 ) + } else if ( NOTARY_PUBKEY33[0] != 0 ) fprintf(stderr,"allow nHeight.%d coinbase %.8f vs %.8f interest %.8f\n",(int32_t)pindex->nHeight,dstr(block.vtx[0].GetValueOut()),dstr(blockReward),dstr(sum)); } if (!control.Wait()) From ce5dd5473e55cbbbaa9aed62bb4147ec904eb218 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 18:53:54 +0300 Subject: [PATCH 027/202] Test --- src/komodo_bitcoind.h | 5 ++++- src/komodo_gateway.h | 11 +++++++++-- src/komodo_globals.h | 2 +- src/komodo_kv.h | 2 +- src/komodo_utils.h | 6 ++++-- src/main.cpp | 5 +++-- src/pow.cpp | 12 ------------ src/rpcblockchain.cpp | 1 - 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index edd4d6569..cd780e172 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -557,10 +557,11 @@ uint64_t komodo_seed(int32_t height) return(seed); } -uint32_t komodo_txtime(uint256 hash) +uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n) { CTransaction tx; uint256 hashBlock; + *valuep = 0; if (!GetTransaction(hash, tx, #ifndef KOMODO_ZCASH Params().GetConsensus(), @@ -568,6 +569,8 @@ uint32_t komodo_txtime(uint256 hash) hashBlock, true)) { //printf("null GetTransaction\n"); + if ( n < tx.vout.size() ) + *valuep = tx.vout[n].nValue; return(tx.nLockTime); } return(0); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 50641b589..a4d839c91 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -670,7 +670,7 @@ uint64_t komodo_commission(const CBlock &block) return((total * ASSETCHAINS_COMMISSION) / COIN); } -int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing +int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing { static uint256 array[64]; static int32_t numbanned,indallvouts; int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,subsidy,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; @@ -740,6 +740,13 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above } else { + if ( ASSETCHAINS_STAKED != 0 ) + { + uint32_t txtime,minutes; uint64_t value; + txtime = komodo_txtime(&value,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n); + minutes = (block.nTime - txtime) / 60; + fprintf(stderr,"txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); + } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { script = (uint8_t *)block.vtx[0].vout[1].scriptPubKey.data(); @@ -747,7 +754,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above return(-1); if ( (checktoshis = komodo_commission(block)) != 0 ) { - if ( block.vtx[0].vout.size() < 2 || block.vtx[0].vout[1].nValue != checktoshis ) + if ( block.vtx[0].vout[1].nValue != checktoshis ) { fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue)); return(-1); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 518d22cbd..4f8433f03 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -54,7 +54,7 @@ char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t ASSETCHAINS_PORT; uint32_t ASSETCHAIN_INIT; uint32_t ASSETCHAINS_MAGIC = 2387029918; -uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY = 10; +uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; uint32_t KOMODO_INITDONE; char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t KMD_PORT = 7771,BITCOIND_PORT = 7771; diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 0d5259eaa..7c20becb1 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -171,7 +171,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) memcpy(ptr->key,key,keylen); newflag = 1; HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); - printf("KV add.(%s) (%s)\n",ptr->key,valueptr); + //printf("KV add.(%s) (%s)\n",ptr->key,valueptr); } if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 ) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 3973bf305..47da06c0d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1501,7 +1501,7 @@ char *argv0names[] = void komodo_args(char *argv0) { extern int64_t MAX_MONEY; - std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; int32_t i,baseid,len,n,extralen = 0; + std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; int32_t i,baseid,len,n,extralen = 0; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 ) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); @@ -1540,6 +1540,7 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY = GetArg("-ac_decay",0); ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); + ASSETCHAINS_STAKED = GetArg("-ac_staked",0); if ( ASSETCHAINS_HALVING != 0 && ASSETCHAINS_HALVING < 1440 ) { ASSETCHAINS_HALVING = 1440; @@ -1571,7 +1572,8 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY); - extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_COMMISSION),(void *)&ASSETCHAINS_COMMISSION); + val = ASSETCHAINS_COMMISSION | ((ASSETCHAINS_STAKED & 0xffff) << 32); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); } addn = GetArg("-seednode",""); if ( strlen(addn.c_str()) > 0 ) diff --git a/src/main.cpp b/src/main.cpp index f6b8feba0..3266bf4e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3506,7 +3506,8 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl return true; } -int32_t komodo_check_deposit(int32_t height,const CBlock& block); +int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime); + bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, libzcash::ProofVerifier& verifier, bool fCheckPOW, bool fCheckMerkleRoot) @@ -3568,7 +3569,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat if (nSigOps > MAX_BLOCK_SIGOPS) return state.DoS(100, error("CheckBlock(): out-of-bounds SigOpCount"), REJECT_INVALID, "bad-blk-sigops", true); - if ( komodo_check_deposit(ASSETCHAINS_SYMBOL[0] == 0 ? height : pindex != 0 ? (int32_t)pindex->nHeight : chainActive.Tip()->nHeight+1,block) < 0 ) + if ( komodo_check_deposit(ASSETCHAINS_SYMBOL[0] == 0 ? height : pindex != 0 ? (int32_t)pindex->nHeight : chainActive.Tip()->nHeight+1,block,pindex==0||pindex->pprev==0?0:pindex->pprev->nTime) < 0 ) { static uint32_t counter; if ( counter++ < 100 ) diff --git a/src/pow.cpp b/src/pow.cpp index 76960933d..63806033d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,18 +190,6 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in } else fprintf(stderr,"skip return error height.%d loading.%d\n",height,KOMODO_LOADINGBLOCKS); } //else fprintf(stderr,"skip height.%d loading.%d\n",height,KOMODO_LOADINGBLOCKS); } - if ( 0 && height > 248000 ) - { - for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); - fprintf(stderr," hash vs "); - for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," POW ok for ht.%d notaryid.%d: ",height,notaryid); - for (i=0; i<33; i++) - fprintf(stderr,"%02x",pubkey33[i]); - fprintf(stderr,"\n"); - } return true; } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 1254217ac..168c00f32 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -544,7 +544,6 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp) #define KOMODO_KVBINARY 2 extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); -uint32_t komodo_txtime(uint256 hash); uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel); int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); From d078d0baa8b174d7dfe154c9d4e7269b2fc4224d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 19:05:19 +0300 Subject: [PATCH 028/202] Test --- src/komodo_gateway.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a4d839c91..927a8fd36 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -742,7 +742,12 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( ASSETCHAINS_STAKED != 0 ) { - uint32_t txtime,minutes; uint64_t value; + uint32_t txtime,minutes; uint64_t value; CBlockIndex *previndex; + if ( prevtime == 0 ) + { + if ( (previndex= mapBlockIndex[block.GetHash()]) != 0 ) + prevtime = (uint32_t)previndex->nTime; + } txtime = komodo_txtime(&value,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n); minutes = (block.nTime - txtime) / 60; fprintf(stderr,"txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); From 56832841c2706e1f7d89c87a21826632538de1c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 19:07:27 +0300 Subject: [PATCH 029/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 927a8fd36..818b171f0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -750,7 +750,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } txtime = komodo_txtime(&value,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n); minutes = (block.nTime - txtime) / 60; - fprintf(stderr,"txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); + fprintf(stderr,"ht.%d txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",(int32_t)block.nHeight,txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { From 0cffe79b2fd90801338876f7c9b0686ae68e5ebc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 19:08:49 +0300 Subject: [PATCH 030/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 818b171f0..16e8152a8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -750,7 +750,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } txtime = komodo_txtime(&value,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n); minutes = (block.nTime - txtime) / 60; - fprintf(stderr,"ht.%d txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",(int32_t)block.nHeight,txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); + fprintf(stderr,"ht.%d txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",komodo_block2height(&block),txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { From 145d4d4eee2c6a9e6df675c358b231917acf001d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 19:10:56 +0300 Subject: [PATCH 031/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 16e8152a8..0046042c0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -750,7 +750,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } txtime = komodo_txtime(&value,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n); minutes = (block.nTime - txtime) / 60; - fprintf(stderr,"ht.%d txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",komodo_block2height(&block),txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); + fprintf(stderr,"ht.%d txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",komodo_block2height((CBlock *)&block),txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { From a4a40a38adf9ab136fd5e31aead21fcad940e952 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 20:10:46 +0300 Subject: [PATCH 032/202] Test --- src/komodo_gateway.h | 2 +- src/miner.cpp | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0046042c0..3f22e20e5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -745,7 +745,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim uint32_t txtime,minutes; uint64_t value; CBlockIndex *previndex; if ( prevtime == 0 ) { - if ( (previndex= mapBlockIndex[block.GetHash()]) != 0 ) + if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 ) prevtime = (uint32_t)previndex->nTime; } txtime = komodo_txtime(&value,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n); diff --git a/src/miner.cpp b/src/miner.cpp index 46fcc342a..46ea9f377 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -121,6 +121,11 @@ int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); uint64_t komodo_commission(const CBlock &block); +int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) +{ + return(-1); +} + CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { uint64_t deposits; int32_t isrealtime,kmdheight; const CChainParams& chainparams = Params(); @@ -309,7 +314,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Legacy limits on sigOps: unsigned int nTxSigOps = GetLegacySigOpCount(tx); - if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) + if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) continue; // Skip free transactions if we're past the minimum block size: @@ -336,7 +341,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) CAmount nTxFees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); - if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) + if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) continue; // Note that flags: we don't want to set mempool/IsStandard() @@ -384,6 +389,29 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize); + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) + { + uint64_t txfees,utxovalue; uint256 utxotxid; int32_t numsigs,utxovout; uint8_t utxosig[128]; + if ( komodo_staked(&utxotxid,&utxovout,&utxovalue,utxosig) == 0 ) + { + CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); + CAmount txfees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,txStaked,chainActive.Tip()->nTime)-txStaked.GetValueOut(); + txStaked.vin.resize(1); + txStaked.vout.resize(1); + txStaked.vin[0].prevout.hash = utxotxid; + txStaked.vin[0].prevout.n = utxovout; + txStaked.vin[0].scriptSig = utxosig; + txStaked.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + txStaked.vout[0].nValue = utxovalue - 10000; + txStaked.nLockTime = chainActive.Tip()->nTime + chainparams.GetConsensus().nPowTargetSpacing; + + pblock->vtx.push_back(txStaked); + numsigs = GetLegacySigOpCount(txStaked); + pblocktemplate->vTxFees.push_back(txfees); + pblocktemplate->vTxSigOps.push_back(numsigs); + nFees += txfees; + } + } // Create coinbase tx CMutableTransaction txNew = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); From 44d2da57f21523804c455c28bfa214c6de3fa129 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 20:17:43 +0300 Subject: [PATCH 033/202] Test --- src/miner.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 46ea9f377..99ba3708a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -106,7 +106,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #include "komodo_defs.h" extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; -extern uint32_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION; +extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; @@ -123,7 +123,7 @@ uint64_t komodo_commission(const CBlock &block); int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - return(-1); + return(0); } CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) @@ -391,18 +391,21 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize); if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) { - uint64_t txfees,utxovalue; uint256 utxotxid; int32_t numsigs,utxovout; uint8_t utxosig[128]; - if ( komodo_staked(&utxotxid,&utxovout,&utxovalue,utxosig) == 0 ) + uint64_t txfees,utxovalue; uint256 utxotxid; int32_t siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; + if ( (siglen= komodo_staked(&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); - CAmount txfees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,txStaked,chainActive.Tip()->nTime)-txStaked.GetValueOut(); + CAmount txfees = 10000; txStaked.vin.resize(1); txStaked.vout.resize(1); txStaked.vin[0].prevout.hash = utxotxid; txStaked.vin[0].prevout.n = utxovout; - txStaked.vin[0].scriptSig = utxosig; + txStaked.vin[0].scriptSig.resize(siglen); + ptr = (uint8_t *)txStaked.vin[0].scriptSig.data(); + for (i=0; inTime + chainparams.GetConsensus().nPowTargetSpacing; pblock->vtx.push_back(txStaked); From d913f07b6ea82f2bdabcfb1f52e447eb2c372ff4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 20:18:25 +0300 Subject: [PATCH 034/202] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 99ba3708a..57de5366c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -391,7 +391,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize); if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) { - uint64_t txfees,utxovalue; uint256 utxotxid; int32_t siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; + uint64_t txfees,utxovalue; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; if ( (siglen= komodo_staked(&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); From ec5ed2f7b7ba466e15699aabfce056f70616458b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 20:31:53 +0300 Subject: [PATCH 035/202] Test --- src/komodo_bitcoind.h | 10 ++++++++++ src/miner.cpp | 6 +----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cd780e172..18ac579e3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -987,3 +987,13 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ } return(0); } + +int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) +{ + memset(utxotxidp,0,sizeof(*utxotxidp)); + memset(utxovoutp,0,sizeof(*utxovoutp)); + memset(utxovaluep,0,sizeof(*utxovaluep)); + memset(utxosig,0,72); + return(72); +} + diff --git a/src/miner.cpp b/src/miner.cpp index 57de5366c..e14338641 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -120,11 +120,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); uint64_t komodo_commission(const CBlock &block); - -int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) -{ - return(0); -} +int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { From 85d77224f2093edb8916f8ef501a12bddf8d60ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 20:36:22 +0300 Subject: [PATCH 036/202] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 18ac579e3..217ac7194 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -990,9 +990,9 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { + *utxovaluep = 100000; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); - memset(utxovaluep,0,sizeof(*utxovaluep)); memset(utxosig,0,72); return(72); } From dfb57be5ece1550fce47b06ae7c76c550e34402d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 20:48:53 +0300 Subject: [PATCH 037/202] Test --- src/komodo_bitcoind.h | 9 ++++++++- src/komodo_globals.h | 2 +- src/komodo_utils.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 217ac7194..847ffceb4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -990,10 +990,17 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - *utxovaluep = 100000; + char *retstr; + *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); + if ( (retstr= komodo_issuemethod(KOMODO_USERPASS,"listunspent","[]",BITCOIND_PORT)) != 0 ) + { + fprintf(stderr,"listunspent.(%s)\n",retstr); + free(retstr); + *utxovaluep = 100000; + } return(72); } diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 4f8433f03..cb8f61988 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -50,7 +50,7 @@ int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE,ASSETCHAINS_CC; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; -char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; +char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_PORT; uint32_t ASSETCHAIN_INIT; uint32_t ASSETCHAINS_MAGIC = 2387029918; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 47da06c0d..f86a62a60 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1422,6 +1422,7 @@ uint16_t komodo_userpass(char *userpass,char *symbol) { port = komodo_userpass(username,password,fp); sprintf(userpass,"%s:%s",username,password); + strcpy(ASSETCHAINS_USERPASS,userpass); fclose(fp); return((int32_t)strlen(userpass)); } From b50b085aa843fc90854895acd0d0a000e7c010cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 20:49:54 +0300 Subject: [PATCH 038/202] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 847ffceb4..a15faeade 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -995,7 +995,7 @@ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); - if ( (retstr= komodo_issuemethod(KOMODO_USERPASS,"listunspent","[]",BITCOIND_PORT)) != 0 ) + if ( (retstr= komodo_issuemethod(ASSETCHAINS_USERPASS,"listunspent","[]",BITCOIND_PORT)) != 0 ) { fprintf(stderr,"listunspent.(%s)\n",retstr); free(retstr); From f16f9bb3688adcbcb0dd253e19f320c9f46f6627 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 20:51:42 +0300 Subject: [PATCH 039/202] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a15faeade..13032a12e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -995,7 +995,7 @@ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); - if ( (retstr= komodo_issuemethod(ASSETCHAINS_USERPASS,"listunspent","[]",BITCOIND_PORT)) != 0 ) + if ( (retstr= komodo_issuemethod(ASSETCHAINS_USERPASS,(char *)"listunspent",(char *)"[]",BITCOIND_PORT)) != 0 ) { fprintf(stderr,"listunspent.(%s)\n",retstr); free(retstr); From a643c0781042fc6c5e4df1ee281427a9af337c18 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 20:58:31 +0300 Subject: [PATCH 040/202] Test --- src/komodo_bitcoind.h | 1 + src/komodo_utils.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 13032a12e..04c68620d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -995,6 +995,7 @@ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); + printf("%s port.%u %s\n",ASSETCHAINS_SYMBOL,BITCOIND_PORT,ASSETCHAINS_USERPASS); if ( (retstr= komodo_issuemethod(ASSETCHAINS_USERPASS,(char *)"listunspent",(char *)"[]",BITCOIND_PORT)) != 0 ) { fprintf(stderr,"listunspent.(%s)\n",retstr); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f86a62a60..16886a52c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1422,7 +1422,8 @@ uint16_t komodo_userpass(char *userpass,char *symbol) { port = komodo_userpass(username,password,fp); sprintf(userpass,"%s:%s",username,password); - strcpy(ASSETCHAINS_USERPASS,userpass); + if ( strcmp(symbol,ASSETCHAINS_SYMBOL) == 0 ) + strcpy(ASSETCHAINS_USERPASS,userpass); fclose(fp); return((int32_t)strlen(userpass)); } From bbb607b4db1b6bf514fb8e68926563714a1414a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 21:15:20 +0300 Subject: [PATCH 041/202] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 16886a52c..0f18d5873 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1605,7 +1605,7 @@ void komodo_args(char *argv0) extern int COINBASE_MATURITY; komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); COINBASE_MATURITY = 1; - LogPrintf("ASSETCHAINS_PORT %s %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT); + fprintf(stderr,"ASSETCHAINS_PORT %s %u (%s)\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT,ASSETCHAINS_USERPASS); } //ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); //komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str()); From 4d3e54094d4ccfbfec110e3d377504d902305ab5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 21:20:26 +0300 Subject: [PATCH 042/202] Test --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0f18d5873..e8e801141 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1604,6 +1604,7 @@ void komodo_args(char *argv0) int32_t komodo_baseid(char *origbase); extern int COINBASE_MATURITY; komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); + komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL); COINBASE_MATURITY = 1; fprintf(stderr,"ASSETCHAINS_PORT %s %u (%s)\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT,ASSETCHAINS_USERPASS); } From 4fb123112bb36239215ec61801b402b287c0f3cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 21:23:53 +0300 Subject: [PATCH 043/202] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 04c68620d..f48879e85 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1001,7 +1001,7 @@ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep fprintf(stderr,"listunspent.(%s)\n",retstr); free(retstr); *utxovaluep = 100000; - } + } else printf("null retstr\n"); return(72); } From e5b7a04e768abf788faa9db4d9c65bf1c73e0c25 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 21:31:33 +0300 Subject: [PATCH 044/202] Test --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f48879e85..d7949cc7e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -336,7 +336,7 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { - //static void *cHandle; + static void *cHandle; char url[512],*retstr=0,*retstr2=0,postdata[8192]; if ( params == 0 || params[0] == 0 ) params = (char *)"[]"; @@ -344,9 +344,9 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); - retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); - //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); + printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,userpass); + //retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); + retstr2 = curl_post(&cHandle,url,userpass,postdata,0,0,0,0); } return(retstr2); } From 50653d13c69263411795c84d1a710443f12069e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 21:34:06 +0300 Subject: [PATCH 045/202] Test --- src/komodo_bitcoind.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d7949cc7e..579a2809e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -336,7 +336,7 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { - static void *cHandle; + //static void *cHandle; char url[512],*retstr=0,*retstr2=0,postdata[8192]; if ( params == 0 || params[0] == 0 ) params = (char *)"[]"; @@ -344,9 +344,9 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,userpass); - //retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); - retstr2 = curl_post(&cHandle,url,userpass,postdata,0,0,0,0); + //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); + retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); + //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } return(retstr2); } @@ -996,12 +996,12 @@ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); printf("%s port.%u %s\n",ASSETCHAINS_SYMBOL,BITCOIND_PORT,ASSETCHAINS_USERPASS); - if ( (retstr= komodo_issuemethod(ASSETCHAINS_USERPASS,(char *)"listunspent",(char *)"[]",BITCOIND_PORT)) != 0 ) + if ( (retstr= komodo_issuemethod(ASSETCHAINS_USERPASS,(char *)"getinfo",(char *)"[]",BITCOIND_PORT)) != 0 ) { fprintf(stderr,"listunspent.(%s)\n",retstr); free(retstr); *utxovaluep = 100000; - } else printf("null retstr\n"); + } else fprintf(stderr,"null retstr\n"); return(72); } From aee5fd82c6a70926029f8b1fe2f8790385aaf4dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 21:49:35 +0300 Subject: [PATCH 046/202] Test --- src/komodo_bitcoind.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 579a2809e..498c8511b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -988,20 +988,17 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ return(0); } +UniValue listunspent(const UniValue& params, bool fHelp); + int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - char *retstr; + char *retstr; UniValue ret,params = NullUniValue; *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); - printf("%s port.%u %s\n",ASSETCHAINS_SYMBOL,BITCOIND_PORT,ASSETCHAINS_USERPASS); - if ( (retstr= komodo_issuemethod(ASSETCHAINS_USERPASS,(char *)"getinfo",(char *)"[]",BITCOIND_PORT)) != 0 ) - { - fprintf(stderr,"listunspent.(%s)\n",retstr); - free(retstr); - *utxovaluep = 100000; - } else fprintf(stderr,"null retstr\n"); + ret = listunspent(params,false); + fprintf(stderr,"listunspent.(%s)\n",ret.get_str().c_str()); return(72); } From 701aa497dfbaff142fef10f157decb4a2038edf4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 21:55:15 +0300 Subject: [PATCH 047/202] Test --- src/komodo_bitcoind.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 498c8511b..6a5b2ce8f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -992,13 +992,14 @@ UniValue listunspent(const UniValue& params, bool fHelp); int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - char *retstr; UniValue ret,params = NullUniValue; + UniValue result,params = NullUniValue; *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); - ret = listunspent(params,false); - fprintf(stderr,"listunspent.(%s)\n",ret.get_str().c_str()); + fprintf(stderr,"call listunspent\n"); + result = listunspent(params,false); + fprintf(stderr,"listunspent.(%s)\n",result.get_str().c_str()); return(72); } From 9de70efe3a05513b79f65e872e6d13467f7205f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:05:45 +0300 Subject: [PATCH 048/202] Test --- src/komodo_bitcoind.h | 9 ++++++--- src/komodo_utils.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6a5b2ce8f..7737b1973 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -992,14 +992,17 @@ UniValue listunspent(const UniValue& params, bool fHelp); int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - UniValue result,params = NullUniValue; + UniValue params = NullUniValue; *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); fprintf(stderr,"call listunspent\n"); - result = listunspent(params,false); - fprintf(stderr,"listunspent.(%s)\n",result.get_str().c_str()); + vector vecOutputs; + assert(pwalletMain != NULL); + LOCK2(cs_main, pwalletMain->cs_wallet); + pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + fprintf(stderr,"listunspent done\n"); return(72); } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e8e801141..c38df1411 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1606,7 +1606,7 @@ void komodo_args(char *argv0) komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT + 1); komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL); COINBASE_MATURITY = 1; - fprintf(stderr,"ASSETCHAINS_PORT %s %u (%s)\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT,ASSETCHAINS_USERPASS); + //fprintf(stderr,"ASSETCHAINS_PORT %s %u (%s)\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT,ASSETCHAINS_USERPASS); } //ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); //komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str()); From ee06bbb7b3db2436e9493119de34f7a232243adb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:13:40 +0300 Subject: [PATCH 049/202] Test --- src/komodo_bitcoind.h | 55 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7737b1973..326870f66 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -992,7 +992,7 @@ UniValue listunspent(const UniValue& params, bool fHelp); int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - UniValue params = NullUniValue; + int32_t nMinDepth = 1,nMaxDepth = 9999999; *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); @@ -1002,6 +1002,59 @@ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + BOOST_FOREACH(const COutput& out, vecOutputs) + { + if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + continue; + if ( setAddress.size() ) + { + CTxDestination address; + if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + continue; + if (!setAddress.count(address)) + continue; + } + CAmount nValue = out.tx->vout[out.i].nValue; + const CScript& pk = out.tx->vout[out.i].scriptPubKey; + UniValue entry(UniValue::VOBJ); + entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); + entry.push_back(Pair("vout", out.i)); + entry.push_back(Pair("generated", out.tx->IsCoinBase())); + CTxDestination address; + if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { + entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); + if (pwalletMain->mapAddressBook.count(address)) + entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); + } + entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end()))); + if (pk.IsPayToScriptHash()) + { + CTxDestination address; + if (ExtractDestination(pk, address)) { + const CScriptID& hash = boost::get(address); + CScript redeemScript; + if (pwalletMain->GetCScript(hash, redeemScript)) + entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()))); + } + } + entry.push_back(Pair("amount",ValueFromAmount(nValue))); + if ( out.tx->nLockTime != 0 ) + { + BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); + CBlockIndex *tipindex,*pindex = it->second; + uint64_t interest; uint32_t locktime; int32_t txheight; + if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); + interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); + entry.push_back(Pair("interest",ValueFromAmount(interest))); + } + //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.Tip(),locktime,txheight,pindex->nHeight); + } + entry.push_back(Pair("confirmations",out.nDepth)); + entry.push_back(Pair("spendable", out.fSpendable)); + fprintf(stderr,"%s\n",results.get_str().c_str()); + } fprintf(stderr,"listunspent done\n"); return(72); } From f8d5490f7cd69dd394a6e5da52c35683840e8baf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:14:34 +0300 Subject: [PATCH 050/202] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 326870f66..8c4b99a4b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1053,7 +1053,7 @@ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep } entry.push_back(Pair("confirmations",out.nDepth)); entry.push_back(Pair("spendable", out.fSpendable)); - fprintf(stderr,"%s\n",results.get_str().c_str()); + fprintf(stderr,"%s\n",entry.get_str().c_str()); } fprintf(stderr,"listunspent done\n"); return(72); From 700c389b13796f4ceb1b30640e25f04f74d27d2f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:16:06 +0300 Subject: [PATCH 051/202] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8c4b99a4b..a3a3788fa 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -988,11 +988,11 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ return(0); } -UniValue listunspent(const UniValue& params, bool fHelp); +UniValue ValueFromAmount(const CAmount& amount); int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - int32_t nMinDepth = 1,nMaxDepth = 9999999; + set setAddress; int32_t nMinDepth = 1,nMaxDepth = 9999999; *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); From a16386bc8ccb74ee280bac256fea762117883108 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:23:00 +0300 Subject: [PATCH 052/202] Test --- src/komodo_bitcoind.h | 62 ++-------------------------------------- src/wallet/rpcwallet.cpp | 62 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 59 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a3a3788fa..4c75249b6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -988,7 +988,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ return(0); } -UniValue ValueFromAmount(const CAmount& amount); +void komodo_listunspent(); int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { @@ -997,64 +997,8 @@ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); - fprintf(stderr,"call listunspent\n"); - vector vecOutputs; - assert(pwalletMain != NULL); - LOCK2(cs_main, pwalletMain->cs_wallet); - pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); - BOOST_FOREACH(const COutput& out, vecOutputs) - { - if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) - continue; - if ( setAddress.size() ) - { - CTxDestination address; - if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) - continue; - if (!setAddress.count(address)) - continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - const CScript& pk = out.tx->vout[out.i].scriptPubKey; - UniValue entry(UniValue::VOBJ); - entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); - entry.push_back(Pair("vout", out.i)); - entry.push_back(Pair("generated", out.tx->IsCoinBase())); - CTxDestination address; - if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { - entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); - if (pwalletMain->mapAddressBook.count(address)) - entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); - } - entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end()))); - if (pk.IsPayToScriptHash()) - { - CTxDestination address; - if (ExtractDestination(pk, address)) { - const CScriptID& hash = boost::get(address); - CScript redeemScript; - if (pwalletMain->GetCScript(hash, redeemScript)) - entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()))); - } - } - entry.push_back(Pair("amount",ValueFromAmount(nValue))); - if ( out.tx->nLockTime != 0 ) - { - BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *tipindex,*pindex = it->second; - uint64_t interest; uint32_t locktime; int32_t txheight; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) - { - komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); - interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); - entry.push_back(Pair("interest",ValueFromAmount(interest))); - } - //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.Tip(),locktime,txheight,pindex->nHeight); - } - entry.push_back(Pair("confirmations",out.nDepth)); - entry.push_back(Pair("spendable", out.fSpendable)); - fprintf(stderr,"%s\n",entry.get_str().c_str()); - } + fprintf(stderr,"start listunspent\n"); + komodo_listunspent(); fprintf(stderr,"listunspent done\n"); return(72); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 27e94134d..438b1f0be 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2691,6 +2691,68 @@ UniValue listunspent(const UniValue& params, bool fHelp) return results; } +void komodo_listunspent() +{ + fprintf(stderr,"call listunspent\n"); + vector vecOutputs; + assert(pwalletMain != NULL); + LOCK2(cs_main, pwalletMain->cs_wallet); + pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + BOOST_FOREACH(const COutput& out, vecOutputs) + { + if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + continue; + if ( setAddress.size() ) + { + CTxDestination address; + if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + continue; + if (!setAddress.count(address)) + continue; + } + CAmount nValue = out.tx->vout[out.i].nValue; + const CScript& pk = out.tx->vout[out.i].scriptPubKey; + UniValue entry(UniValue::VOBJ); + entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); + entry.push_back(Pair("vout", out.i)); + entry.push_back(Pair("generated", out.tx->IsCoinBase())); + CTxDestination address; + if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { + entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); + if (pwalletMain->mapAddressBook.count(address)) + entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); + } + entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end()))); + if (pk.IsPayToScriptHash()) + { + CTxDestination address; + if (ExtractDestination(pk, address)) { + const CScriptID& hash = boost::get(address); + CScript redeemScript; + if (pwalletMain->GetCScript(hash, redeemScript)) + entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()))); + } + } + entry.push_back(Pair("amount",ValueFromAmount(nValue))); + if ( out.tx->nLockTime != 0 ) + { + BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); + CBlockIndex *tipindex,*pindex = it->second; + uint64_t interest; uint32_t locktime; int32_t txheight; + if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); + interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); + entry.push_back(Pair("interest",ValueFromAmount(interest))); + } + fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.Tip(),locktime,txheight,pindex->nHeight); + } + entry.push_back(Pair("confirmations",out.nDepth)); + entry.push_back(Pair("spendable", out.fSpendable)); + fprintf(stderr,"%s\n",entry.get_str().c_str()); + } +} + uint64_t komodo_interestsum() { uint64_t interest,sum = 0; From 073421433b0bd31817f11de3ed0806ac826af96b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:25:09 +0300 Subject: [PATCH 053/202] Test --- src/komodo_bitcoind.h | 1 - src/wallet/rpcwallet.cpp | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4c75249b6..53ec13b00 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -992,7 +992,6 @@ void komodo_listunspent(); int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t nMinDepth = 1,nMaxDepth = 9999999; *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 438b1f0be..461b81c89 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2693,8 +2693,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) void komodo_listunspent() { - fprintf(stderr,"call listunspent\n"); - vector vecOutputs; + set setAddress; int32_t nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); From 50a7fa9e125d5a3080cf3901567415c9796d08da Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:32:56 +0300 Subject: [PATCH 054/202] Test --- src/wallet/rpcwallet.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 461b81c89..d999e0d80 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2711,7 +2711,7 @@ void komodo_listunspent() } CAmount nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; - UniValue entry(UniValue::VOBJ); + /*UniValue entry(UniValue::VOBJ); entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); entry.push_back(Pair("vout", out.i)); entry.push_back(Pair("generated", out.tx->IsCoinBase())); @@ -2732,7 +2732,7 @@ void komodo_listunspent() entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()))); } } - entry.push_back(Pair("amount",ValueFromAmount(nValue))); + entry.push_back(Pair("amount",ValueFromAmount(nValue)));*/ if ( out.tx->nLockTime != 0 ) { BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); @@ -2742,13 +2742,11 @@ void komodo_listunspent() { komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); - entry.push_back(Pair("interest",ValueFromAmount(interest))); + //entry.push_back(Pair("interest",ValueFromAmount(interest))); } - fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.Tip(),locktime,txheight,pindex->nHeight); + fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } - entry.push_back(Pair("confirmations",out.nDepth)); - entry.push_back(Pair("spendable", out.fSpendable)); - fprintf(stderr,"%s\n",entry.get_str().c_str()); + fprintf(stderr,"entry done\n"); } } From 74f0baa46875ff256fd743bca29a1c540a2446a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:34:16 +0300 Subject: [PATCH 055/202] Test --- src/wallet/rpcwallet.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d999e0d80..bf785e38c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2693,7 +2693,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) void komodo_listunspent() { - set setAddress; int32_t nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; + set setAddress; int32_t nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; CTxDestination address; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); @@ -2703,7 +2703,6 @@ void komodo_listunspent() continue; if ( setAddress.size() ) { - CTxDestination address; if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) continue; if (!setAddress.count(address)) From c6e53b1ad31d475d06c94fb69af1b9f35019d15d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:39:43 +0300 Subject: [PATCH 056/202] Test --- src/komodo_bitcoind.h | 2 -- src/wallet/rpcwallet.cpp | 20 +++++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 53ec13b00..6933be624 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -996,9 +996,7 @@ int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); - fprintf(stderr,"start listunspent\n"); komodo_listunspent(); - fprintf(stderr,"listunspent done\n"); return(72); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bf785e38c..fee31efcd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2693,7 +2693,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) void komodo_listunspent() { - set setAddress; int32_t nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; CTxDestination address; + set setAddress; int32_t nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); @@ -2703,6 +2703,7 @@ void komodo_listunspent() continue; if ( setAddress.size() ) { + CTxDestination address; if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) continue; if (!setAddress.count(address)) @@ -2710,17 +2711,15 @@ void komodo_listunspent() } CAmount nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; - /*UniValue entry(UniValue::VOBJ); - entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); - entry.push_back(Pair("vout", out.i)); - entry.push_back(Pair("generated", out.tx->IsCoinBase())); + //entry.push_back(Pair("generated", out.tx->IsCoinBase())); CTxDestination address; - if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { - entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); - if (pwalletMain->mapAddressBook.count(address)) - entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); + if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + { + //entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); + //if (pwalletMain->mapAddressBook.count(address)) + // entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); } - entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end()))); + /*entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end()))); if (pk.IsPayToScriptHash()) { CTxDestination address; @@ -2745,7 +2744,6 @@ void komodo_listunspent() } fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } - fprintf(stderr,"entry done\n"); } } From eb6c7bb831b7784cacafdf5b6a3fbdae5ae53d4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:46:38 +0300 Subject: [PATCH 057/202] Test --- src/komodo_bitcoind.h | 12 ------------ src/miner.cpp | 6 +++--- src/wallet/rpcwallet.cpp | 10 +++++++++- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6933be624..46913d43e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -988,15 +988,3 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ return(0); } -void komodo_listunspent(); - -int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) -{ - *utxovaluep = 0; - memset(utxotxidp,0,sizeof(*utxotxidp)); - memset(utxovoutp,0,sizeof(*utxovoutp)); - memset(utxosig,0,72); - komodo_listunspent(); - return(72); -} - diff --git a/src/miner.cpp b/src/miner.cpp index e14338641..2e6305f26 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -120,7 +120,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); uint64_t komodo_commission(const CBlock &block); -int32_t komodo_staked(uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); +int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { @@ -387,8 +387,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize); if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) { - uint64_t txfees,utxovalue; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; - if ( (siglen= komodo_staked(&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) + uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; + if ( (siglen= komodo_staked(&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); CAmount txfees = 10000; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fee31efcd..c7cf5d52b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2691,11 +2691,15 @@ UniValue listunspent(const UniValue& params, bool fHelp) return results; } -void komodo_listunspent() +int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { set setAddress; int32_t nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); + *utxovaluep = 0; + memset(utxotxidp,0,sizeof(*utxotxidp)); + memset(utxovoutp,0,sizeof(*utxovoutp)); + memset(utxosig,0,72); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); BOOST_FOREACH(const COutput& out, vecOutputs) { @@ -2712,6 +2716,10 @@ void komodo_listunspent() CAmount nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); + *utxovaluep = (uint64_t)nValue; + decode_hex(utxotxidp,32,out.tx->GetHash().GetHex().c_str()); + *utxovoutp = out.i; + *txtimep = (uint32_t)out.tx->nLockTime; CTxDestination address; if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { From 478b0dadb10ccd4e1196f50e661d5b9dad67b0c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:50:39 +0300 Subject: [PATCH 058/202] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 2e6305f26..a87a82914 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -402,6 +402,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ptr[i] = utxosig[i]; txStaked.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; txStaked.vout[0].nValue = utxovalue - txfees; + fprintf(stderr,"utxovout.%d txtime.%u %.8f\n",utxovout,txtime,(double)utxovalue/COIN); txStaked.nLockTime = chainActive.Tip()->nTime + chainparams.GetConsensus().nPowTargetSpacing; pblock->vtx.push_back(txStaked); From 30092d77e2697c4d50db3b5e0e295105f81bd957 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:52:09 +0300 Subject: [PATCH 059/202] Test --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c7cf5d52b..bf148e9d2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2691,6 +2691,8 @@ UniValue listunspent(const UniValue& params, bool fHelp) return results; } +int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); + int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { set setAddress; int32_t nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; From 5611b8ff59c92d4d7bc4bf95ad20cb1569c1d927 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:53:26 +0300 Subject: [PATCH 060/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bf148e9d2..62b028042 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2719,7 +2719,7 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); *utxovaluep = (uint64_t)nValue; - decode_hex(utxotxidp,32,out.tx->GetHash().GetHex().c_str()); + decode_hex((uint8_t *)utxotxidp,32,out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; CTxDestination address; From 565aa1b298324271b1f972a802928d891d6d7593 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:54:14 +0300 Subject: [PATCH 061/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 62b028042..8067b429c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2719,7 +2719,7 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); *utxovaluep = (uint64_t)nValue; - decode_hex((uint8_t *)utxotxidp,32,out.tx->GetHash().GetHex().c_str()); + decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; CTxDestination address; From be7928150b3325870a4d202cb6c457e3034ff3b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 22:58:10 +0300 Subject: [PATCH 062/202] Test --- src/komodo_gateway.h | 2 +- src/wallet/rpcwallet.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3f22e20e5..29d8bd984 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -750,7 +750,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } txtime = komodo_txtime(&value,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n); minutes = (block.nTime - txtime) / 60; - fprintf(stderr,"ht.%d txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",komodo_block2height((CBlock *)&block),txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); + fprintf(stderr,"txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8067b429c..09b403f7f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2755,6 +2755,7 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } } + return(72); } uint64_t komodo_interestsum() From 69530bb2c7cb40a7dcfd6eba8b0139321a38ba4e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Apr 2018 23:02:42 +0300 Subject: [PATCH 063/202] Test --- src/miner.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index a87a82914..6f59771bf 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -387,14 +387,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize); if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) { - uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; + uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; if ( (siglen= komodo_staked(&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); CAmount txfees = 10000; txStaked.vin.resize(1); txStaked.vout.resize(1); - txStaked.vin[0].prevout.hash = utxotxid; + for (i=0; i<32; i++) + ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i]; + txStaked.vin[0].prevout.hash = revtxid; txStaked.vin[0].prevout.n = utxovout; txStaked.vin[0].scriptSig.resize(siglen); ptr = (uint8_t *)txStaked.vin[0].scriptSig.data(); From 7214ca0730df0a4854dc6620497c83ecb38ed532 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 13:39:53 +0300 Subject: [PATCH 064/202] Test --- src/komodo_events.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index 315a78686..7e9dfa2df 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -40,7 +40,7 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight,uint256 MoM,int32_t MoMdepth) { struct komodo_event_notarized N; - if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) + if ( 0 && komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) { if ( height > 50000 || ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest); From 9caa00ee19efbfcd6626d63167cdcc228de7515a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 13:48:29 +0300 Subject: [PATCH 065/202] Test --- src/fiat/bntn | 0 src/komodo_events.h | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/fiat/bntn diff --git a/src/fiat/bntn b/src/fiat/bntn old mode 100644 new mode 100755 diff --git a/src/komodo_events.h b/src/komodo_events.h index 7e9dfa2df..897f3b7bd 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -40,12 +40,12 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight,uint256 MoM,int32_t MoMdepth) { struct komodo_event_notarized N; - if ( 0 && komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) + /*if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) { if ( height > 50000 || ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest); } - else + else*/ { if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"validated [%s] ht.%d notarized %d\n",ASSETCHAINS_SYMBOL,height,notarizedheight); From 605e77944e7542ae3780cafe6cc89939fcf6c211 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 14:04:11 +0300 Subject: [PATCH 066/202] Test --- src/komodo_events.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index 897f3b7bd..9b44cdd3e 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -40,12 +40,12 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight,uint256 MoM,int32_t MoMdepth) { struct komodo_event_notarized N; - /*if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) + if ( NOTARY_PUBKEY33[0] == 0 || komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) { if ( height > 50000 || ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest); } - else*/ + else { if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"validated [%s] ht.%d notarized %d\n",ASSETCHAINS_SYMBOL,height,notarizedheight); From 6a933d59d80282fed84a2545e757c7b87392d53e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 18:53:33 +0300 Subject: [PATCH 067/202] Test --- src/komodo.h | 23 ++++++++++++----------- src/komodo_events.h | 2 +- src/main.cpp | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index c387198f8..0ff04b529 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -508,7 +508,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask,uint32_t timestamp) { static uint256 zero; static FILE *signedfp; - int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; + int32_t opretlen,nid,k,len = 0; uint256 srchash,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) return(-1); if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) @@ -566,23 +566,24 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr printf("[%s] notarized.%d notarizedht.%d sp.Nht %d sp.ht %d opretlen.%d (%c %c %c)\n",ASSETCHAINS_SYMBOL,notarized,*notarizedheightp,sp->NOTARIZED_HEIGHT,sp->CURRENT_HEIGHT,opretlen,scriptbuf[len+32*2+4],scriptbuf[len+32*2+4+1],scriptbuf[len+32*2+4+2]); if ( j == 1 && opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) { - len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); + len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&srchash); len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); if ( strcmp("PIZZA",ASSETCHAINS_SYMBOL) == 0 && opretlen == 110 ) { notarized = 1; } - int32_t validated = 1; - /*if ( ASSETCHAINS_SYMBOL[0] != 0 ) - validated = 1; - else if ( height < sp->CURRENT_HEIGHT-64 || komodo_verifynotarization((char *)"KMD",(char *)"BTC",height,*notarizedheightp,kmdtxid,desttxid) == 0 ) - validated = 1;*/ + int32_t validated = 0; + CBlockIndex *pindex; + if ( (pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp ) + { + fprintf(stderr,"FORK detected. notarized.%d %s no in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); + } else validated = 1; if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 ) { int32_t nameoffset = (int32_t)strlen(ASSETCHAINS_SYMBOL) + 1; sp->NOTARIZED_HEIGHT = *notarizedheightp; - sp->NOTARIZED_HASH = kmdtxid; + sp->NOTARIZED_HASH = srchash; sp->NOTARIZED_DESTTXID = desttxid; memset(&sp->MoM,0,sizeof(sp->MoM)); sp->MoMdepth = 0; @@ -603,7 +604,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth); len += nameoffset; if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); + printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( signedfp == 0 ) @@ -629,7 +630,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } } } else //if ( height >= sp->CURRENT_HEIGHT-64 )//KOMODO_MAINNET_START ) - printf("validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s) len.%d opretlen.%d\n",validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len],len,opretlen); + printf("validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s) len.%d opretlen.%d\n",validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len],len,opretlen); } else if ( i == 0 && j == 1 && opretlen == 149 ) { @@ -693,7 +694,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { static int32_t hwmheight; uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; - uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,zero,btctxid,txhash; + uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash; int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; memset(&zero,0,sizeof(zero)); komodo_init(pindex->nHeight); diff --git a/src/komodo_events.h b/src/komodo_events.h index 9b44cdd3e..4d9ff87dc 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -40,7 +40,7 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight,uint256 MoM,int32_t MoMdepth) { struct komodo_event_notarized N; - if ( NOTARY_PUBKEY33[0] == 0 || komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) + if ( NOTARY_PUBKEY33[0] != 0 && komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) { if ( height > 50000 || ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest); diff --git a/src/main.cpp b/src/main.cpp index 929589df9..4bfa9f122 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3089,7 +3089,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo } } fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); - sleep(60); + sleep(300); KOMODO_REWIND = 0; return(true); } From dbbdf7de87a1e5d1a9e7a3c76df9d0e0f317300a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 18:57:56 +0300 Subject: [PATCH 068/202] Test --- src/komodo.h | 2 ++ src/main.cpp | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0ff04b529..c9ee4142c 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -578,6 +578,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( (pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp ) { fprintf(stderr,"FORK detected. notarized.%d %s no in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); + if ( sp->NOTARIZED_HEIGHT > 0 ) + KOMODO_REWIND = sp->NOTARIZED_HEIGHT - 1; } else validated = 1; if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 ) { diff --git a/src/main.cpp b/src/main.cpp index 4bfa9f122..4482cf4c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3079,9 +3079,10 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo } if ( KOMODO_REWIND != 0 ) { - fprintf(stderr,"rewind start ht.%d\n",chainActive.Tip()->nHeight); + fprintf(stderr,">>>>>>>>>>> rewind start ht.%d\n",chainActive.Tip()->nHeight); while ( KOMODO_REWIND > 0 && chainActive.Tip()->nHeight > KOMODO_REWIND ) { + fprintf(stderr,"%d ",(int32_t)chainActive.Tip()->nHeight); if ( !DisconnectTip(state) ) { InvalidateBlock(state,chainActive.Tip()); @@ -3089,7 +3090,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo } } fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); - sleep(300); + sleep(60); KOMODO_REWIND = 0; return(true); } From 91165f19e604d537712061b81aade2b742485bfc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 19:01:04 +0300 Subject: [PATCH 069/202] Test --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 4482cf4c6..9b736d3dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3079,7 +3079,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo } if ( KOMODO_REWIND != 0 ) { - fprintf(stderr,">>>>>>>>>>> rewind start ht.%d\n",chainActive.Tip()->nHeight); + fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.Tip()->nHeight,KOMODO_REWIND); while ( KOMODO_REWIND > 0 && chainActive.Tip()->nHeight > KOMODO_REWIND ) { fprintf(stderr,"%d ",(int32_t)chainActive.Tip()->nHeight); @@ -3091,6 +3091,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo } fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); sleep(60); + fprintf(stderr,"resuming normal operations\n"); KOMODO_REWIND = 0; return(true); } From c5803d26ecb02d8a27b17c1dbe531af54b3896f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 19:11:10 +0300 Subject: [PATCH 070/202] Rewind to min ht --- src/komodo.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index c9ee4142c..2d510acae 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -578,8 +578,10 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( (pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp ) { fprintf(stderr,"FORK detected. notarized.%d %s no in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); - if ( sp->NOTARIZED_HEIGHT > 0 ) + if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarized_heightp ) KOMODO_REWIND = sp->NOTARIZED_HEIGHT - 1; + else if ( *notarized_heightp > 101 ) + KOMODO_REWIND = *notarized_heightp - 101; } else validated = 1; if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 ) { From 986ec226cd7f1df14313a0afdb1795a5243229e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 19:22:47 +0300 Subject: [PATCH 071/202] Print --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 2d510acae..efded0840 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -577,7 +577,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr CBlockIndex *pindex; if ( (pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp ) { - fprintf(stderr,"FORK detected. notarized.%d %s no in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); + fprintf(stderr,"FORK detected. notarized.%d %s not in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarized_heightp ) KOMODO_REWIND = sp->NOTARIZED_HEIGHT - 1; else if ( *notarized_heightp > 101 ) From 6c93ad75b277bd504a027917ba59038a63a9feb9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 19:40:37 +0300 Subject: [PATCH 072/202] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index efded0840..985e28a21 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -578,7 +578,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( (pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp ) { fprintf(stderr,"FORK detected. notarized.%d %s not in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); - if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarized_heightp ) + if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) KOMODO_REWIND = sp->NOTARIZED_HEIGHT - 1; else if ( *notarized_heightp > 101 ) KOMODO_REWIND = *notarized_heightp - 101; From 83de8f955e0cdbc6aadb0805497a37dd72db43e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 19:41:18 +0300 Subject: [PATCH 073/202] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 985e28a21..092c572ac 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -580,7 +580,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr fprintf(stderr,"FORK detected. notarized.%d %s not in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) KOMODO_REWIND = sp->NOTARIZED_HEIGHT - 1; - else if ( *notarized_heightp > 101 ) + else if ( *notarizedheightp > 101 ) KOMODO_REWIND = *notarized_heightp - 101; } else validated = 1; if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 ) From 34dd6cc4fdd7d0398e49fce65b3ca9df2762796d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 19:41:51 +0300 Subject: [PATCH 074/202] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 092c572ac..99bd008d8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -581,7 +581,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) KOMODO_REWIND = sp->NOTARIZED_HEIGHT - 1; else if ( *notarizedheightp > 101 ) - KOMODO_REWIND = *notarized_heightp - 101; + KOMODO_REWIND = *notarizedheightp - 101; } else validated = 1; if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 ) { From 935e05222a7e5d3dab01cb58de6d365343450c0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 19:48:35 +0300 Subject: [PATCH 075/202] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 99bd008d8..2979a49b1 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -575,7 +575,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } int32_t validated = 0; CBlockIndex *pindex; - if ( (pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp ) + if ( IsInitialBlockDownload() == 0 && (pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp ) { fprintf(stderr,"FORK detected. notarized.%d %s not in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) From fd836de79b15c53064e543073e92049525c3399f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 19:59:29 +0300 Subject: [PATCH 076/202] Test --- src/komodo.h | 4 ++-- src/main.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 2979a49b1..8f24032d7 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -578,10 +578,10 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( IsInitialBlockDownload() == 0 && (pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp ) { fprintf(stderr,"FORK detected. notarized.%d %s not in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); - if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) + /*if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) KOMODO_REWIND = sp->NOTARIZED_HEIGHT - 1; else if ( *notarizedheightp > 101 ) - KOMODO_REWIND = *notarizedheightp - 101; + KOMODO_REWIND = *notarizedheightp - 101;*/ } else validated = 1; if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 ) { diff --git a/src/main.cpp b/src/main.cpp index 9b736d3dd..f69adbd50 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3089,7 +3089,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo break; } } - fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); + fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli -ac_name=%s stop\n",KOMODO_REWIND,ASSETCHAINS_SYMBOL); sleep(60); fprintf(stderr,"resuming normal operations\n"); KOMODO_REWIND = 0; From f4e0076aa0914ab6c83ca5ea1f7a6cd8be55aec9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 20:07:56 +0300 Subject: [PATCH 077/202] Test --- src/komodo.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 8f24032d7..95b4a8478 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -575,13 +575,13 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } int32_t validated = 0; CBlockIndex *pindex; - if ( IsInitialBlockDownload() == 0 && (pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp ) + if ( IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp) ) { fprintf(stderr,"FORK detected. notarized.%d %s not in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); - /*if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) + if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) KOMODO_REWIND = sp->NOTARIZED_HEIGHT - 1; else if ( *notarizedheightp > 101 ) - KOMODO_REWIND = *notarizedheightp - 101;*/ + KOMODO_REWIND = *notarizedheightp - 101; } else validated = 1; if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 ) { From 11ed15a670c46c87bbd6eb3710b80b6be4388898 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 21:34:49 +0300 Subject: [PATCH 078/202] Test --- src/komodo.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 95b4a8478..d0e1075be 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -577,11 +577,18 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr CBlockIndex *pindex; if ( IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp) ) { - fprintf(stderr,"FORK detected. notarized.%d %s not in this chain! REWIND to %d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT); + static int32_t last_rewind; int32_t rewindtarget; if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) - KOMODO_REWIND = sp->NOTARIZED_HEIGHT - 1; + rewindtarget = sp->NOTARIZED_HEIGHT - 1; else if ( *notarizedheightp > 101 ) - KOMODO_REWIND = *notarizedheightp - 101; + rewindtarget = *notarizedheightp - 101; + else rewindtarget = 0; + if ( rewindtarget != 0 && rewindtarget > KOMODO_REWIND && rewindtarget > last_rewind ) + { + last_rewind = rewindtarget; + KOMODO_REWIND = rewindtarget; + fprintf(stderr,"FORK detected. notarized.%d %s not in this chain! last notarization %d -> rewindtarget.%d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT,rewindtarget); + } } else validated = 1; if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 ) { From 8d787d2580a72813ab6d8fdef38e6ee35aee277b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 21:55:19 +0300 Subject: [PATCH 079/202] Test --- src/komodo.h | 2 +- src/main.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d0e1075be..95691f33d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -640,7 +640,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j,zero,0); } } - } else //if ( height >= sp->CURRENT_HEIGHT-64 )//KOMODO_MAINNET_START ) + } else if ( *notarizedheightp != sp->NOTARIZED_HEIGHT ) printf("validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s) len.%d opretlen.%d\n",validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len],len,opretlen); } else if ( i == 0 && j == 1 && opretlen == 149 ) diff --git a/src/main.cpp b/src/main.cpp index f69adbd50..6f4dd89fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3610,8 +3610,14 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta { // Check that the block chain matches the known block chain up to a checkpoint if (!Checkpoints::CheckBlock(chainParams.Checkpoints(), nHeight, hash)) - return state.DoS(100, error("%s: rejected by checkpoint lock-in at %d", __func__, nHeight),REJECT_CHECKPOINT, "checkpoint mismatch"); - + { + CBlockIndex *heightblock = chainActive[nHeight]; + if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) + { + //fprintf(stderr,"got a pre notarization block that matches height.%d\n",(int32_t)nHeight); + return true; + } return state.DoS(100, error("%s: rejected by checkpoint lock-in at %d", __func__, nHeight),REJECT_CHECKPOINT, "checkpoint mismatch"); + } // Don't accept any forks from the main chain prior to last checkpoint CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; From 576f0b157f0350631b68fe1a9163b21a76d6066f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 21:56:37 +0300 Subject: [PATCH 080/202] Test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 95691f33d..dbad75aa7 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -574,8 +574,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr notarized = 1; } int32_t validated = 0; - CBlockIndex *pindex; - if ( IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp) ) + CBlockIndex *pindex;//IsInitialBlockDownload() == 0 && + if ( ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp) ) { static int32_t last_rewind; int32_t rewindtarget; if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) From 899aa3878532f56a6e3f8ff33cc5a3743ca5358a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 22:06:26 +0300 Subject: [PATCH 081/202] Test --- src/komodo.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index dbad75aa7..aa358ab4e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -573,11 +573,11 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr { notarized = 1; } - int32_t validated = 0; + static int32_t last_rewind; + int32_t rewindtarget,validated = 0; CBlockIndex *pindex;//IsInitialBlockDownload() == 0 && if ( ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp) ) { - static int32_t last_rewind; int32_t rewindtarget; if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) rewindtarget = sp->NOTARIZED_HEIGHT - 1; else if ( *notarizedheightp > 101 ) @@ -585,11 +585,19 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr else rewindtarget = 0; if ( rewindtarget != 0 && rewindtarget > KOMODO_REWIND && rewindtarget > last_rewind ) { + if ( last_rewind != 0 ) + { + KOMODO_REWIND = rewindtarget; + fprintf(stderr,"%s FORK detected. notarized.%d %s not in this chain! last notarization %d -> rewindtarget.%d\n",ASSETCHAINS_SYMBOL,*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT,rewindtarget); + } last_rewind = rewindtarget; - KOMODO_REWIND = rewindtarget; - fprintf(stderr,"FORK detected. notarized.%d %s not in this chain! last notarization %d -> rewindtarget.%d\n",*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT,rewindtarget); } - } else validated = 1; + } + else + { + last_rewind = 0; + validated = 1; + } if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 ) { int32_t nameoffset = (int32_t)strlen(ASSETCHAINS_SYMBOL) + 1; From 79d54107a1caa69dfb6ceefb322664b3b7f685d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 22:12:14 +0300 Subject: [PATCH 082/202] Test --- src/komodo.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index aa358ab4e..6a27ffb62 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -592,12 +592,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } last_rewind = rewindtarget; } - } - else - { - last_rewind = 0; - validated = 1; - } + } else validated = 1; if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 ) { int32_t nameoffset = (int32_t)strlen(ASSETCHAINS_SYMBOL) + 1; From 6a11ba537be4dc6464b38d9a9e75e24de9a00f5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Apr 2018 22:25:29 +0300 Subject: [PATCH 083/202] Test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 6a27ffb62..32fcce047 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -575,8 +575,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } static int32_t last_rewind; int32_t rewindtarget,validated = 0; - CBlockIndex *pindex;//IsInitialBlockDownload() == 0 && - if ( ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp) ) + CBlockIndex *pindex;// + if ( IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp) ) { if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp ) rewindtarget = sp->NOTARIZED_HEIGHT - 1; From 21965c3f7af9b75e340d804ef9cbeb665fae62e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 14:26:07 +0300 Subject: [PATCH 084/202] Test --- src/wallet/rpcwallet.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 09b403f7f..c350e0e28 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2695,7 +2695,7 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; @@ -2754,8 +2754,21 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui } fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } + bool signSuccess; SignatureData sigdata; uint8_t *ptr; + auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + CTransaction txNewConst(txNew); + signSuccess = ProduceSignature(TransactionSignatureCreator(this, &txNewConst, 0, nValue, SIGHASH_ALL), out.tx->vout[out.i].scriptPubKey, sigdata, consensusBranchId); + if (!signSuccess) + fprintf(stderr,"failed to create signature\n"); + else + { + ptr = (uint8_t *)sigdata.data(); + siglen = sigdata.size(); + for (i=0; i Date: Mon, 9 Apr 2018 14:35:50 +0300 Subject: [PATCH 085/202] Test --- src/wallet/rpcwallet.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c350e0e28..ef0088330 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2691,6 +2691,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) return results; } +#include "script/sign.h" int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) @@ -2754,8 +2755,18 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui } fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } - bool signSuccess; SignatureData sigdata; uint8_t *ptr; + bool signSuccess; SignatureData sigdata; uint8_t *ptr; uint256 revtxid,utxotxid; auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); + txNew.vin.resize(1); + txNew.vout.resize(1); + for (i=0; i<32; i++) + ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; + txNew.vin[0].prevout.hash = revtxid; + txNew.vin[0].prevout.n = *utxovoutp; + txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + txNew.vout[0].nValue = nValue - txfees; + txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + chainparams.GetConsensus().nPowTargetSpacing; // set to a time close to now CTransaction txNewConst(txNew); signSuccess = ProduceSignature(TransactionSignatureCreator(this, &txNewConst, 0, nValue, SIGHASH_ALL), out.tx->vout[out.i].scriptPubKey, sigdata, consensusBranchId); if (!signSuccess) From 969322e04240990be02ddabf710fd516bd56de19 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 14:36:59 +0300 Subject: [PATCH 086/202] Test --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ef0088330..c9e9d0009 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2776,7 +2776,8 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui ptr = (uint8_t *)sigdata.data(); siglen = sigdata.size(); for (i=0; i Date: Mon, 9 Apr 2018 14:37:43 +0300 Subject: [PATCH 087/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c9e9d0009..085d39fd0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2773,7 +2773,7 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui fprintf(stderr,"failed to create signature\n"); else { - ptr = (uint8_t *)sigdata.data(); + ptr = (uint8_t *)sigdata.scriptSig.data(); siglen = sigdata.size(); for (i=0; i Date: Mon, 9 Apr 2018 14:42:07 +0300 Subject: [PATCH 088/202] Test --- src/miner.cpp | 2 +- src/wallet/rpcwallet.cpp | 188 ++++++++++++++++++++------------------- 2 files changed, 97 insertions(+), 93 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 6f59771bf..bba4e62d3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -405,7 +405,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txStaked.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; txStaked.vout[0].nValue = utxovalue - txfees; fprintf(stderr,"utxovout.%d txtime.%u %.8f\n",utxovout,txtime,(double)utxovalue/COIN); - txStaked.nLockTime = chainActive.Tip()->nTime + chainparams.GetConsensus().nPowTargetSpacing; + txStaked.nLockTime = chainActive.Tip()->nTime + 60; pblock->vtx.push_back(txStaked); numsigs = GetLegacySigOpCount(txStaked); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 085d39fd0..68b280651 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2691,98 +2691,6 @@ UniValue listunspent(const UniValue& params, bool fHelp) return results; } -#include "script/sign.h" -int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); - -int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) -{ - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; - assert(pwalletMain != NULL); - LOCK2(cs_main, pwalletMain->cs_wallet); - *utxovaluep = 0; - memset(utxotxidp,0,sizeof(*utxotxidp)); - memset(utxovoutp,0,sizeof(*utxovoutp)); - memset(utxosig,0,72); - pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); - BOOST_FOREACH(const COutput& out, vecOutputs) - { - if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) - continue; - if ( setAddress.size() ) - { - CTxDestination address; - if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) - continue; - if (!setAddress.count(address)) - continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - const CScript& pk = out.tx->vout[out.i].scriptPubKey; - //entry.push_back(Pair("generated", out.tx->IsCoinBase())); - *utxovaluep = (uint64_t)nValue; - decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); - *utxovoutp = out.i; - *txtimep = (uint32_t)out.tx->nLockTime; - CTxDestination address; - if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) - { - //entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); - //if (pwalletMain->mapAddressBook.count(address)) - // entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); - } - /*entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end()))); - if (pk.IsPayToScriptHash()) - { - CTxDestination address; - if (ExtractDestination(pk, address)) { - const CScriptID& hash = boost::get(address); - CScript redeemScript; - if (pwalletMain->GetCScript(hash, redeemScript)) - entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()))); - } - } - entry.push_back(Pair("amount",ValueFromAmount(nValue)));*/ - if ( out.tx->nLockTime != 0 ) - { - BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *tipindex,*pindex = it->second; - uint64_t interest; uint32_t locktime; int32_t txheight; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) - { - komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); - interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); - //entry.push_back(Pair("interest",ValueFromAmount(interest))); - } - fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); - } - bool signSuccess; SignatureData sigdata; uint8_t *ptr; uint256 revtxid,utxotxid; - auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); - txNew.vin.resize(1); - txNew.vout.resize(1); - for (i=0; i<32; i++) - ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; - txNew.vin[0].prevout.hash = revtxid; - txNew.vin[0].prevout.n = *utxovoutp; - txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; - txNew.vout[0].nValue = nValue - txfees; - txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + chainparams.GetConsensus().nPowTargetSpacing; // set to a time close to now - CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(this, &txNewConst, 0, nValue, SIGHASH_ALL), out.tx->vout[out.i].scriptPubKey, sigdata, consensusBranchId); - if (!signSuccess) - fprintf(stderr,"failed to create signature\n"); - else - { - ptr = (uint8_t *)sigdata.scriptSig.data(); - siglen = sigdata.size(); - for (i=0; i setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; + assert(pwalletMain != NULL); + LOCK2(cs_main, pwalletMain->cs_wallet); + *utxovaluep = 0; + memset(utxotxidp,0,sizeof(*utxotxidp)); + memset(utxovoutp,0,sizeof(*utxovoutp)); + memset(utxosig,0,72); + pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + BOOST_FOREACH(const COutput& out, vecOutputs) + { + if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + continue; + if ( setAddress.size() ) + { + CTxDestination address; + if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + continue; + if (!setAddress.count(address)) + continue; + } + CAmount nValue = out.tx->vout[out.i].nValue; + const CScript& pk = out.tx->vout[out.i].scriptPubKey; + //entry.push_back(Pair("generated", out.tx->IsCoinBase())); + *utxovaluep = (uint64_t)nValue; + decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); + *utxovoutp = out.i; + *txtimep = (uint32_t)out.tx->nLockTime; + CTxDestination address; + if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + { + //entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); + //if (pwalletMain->mapAddressBook.count(address)) + // entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); + } + /*entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end()))); + if (pk.IsPayToScriptHash()) + { + CTxDestination address; + if (ExtractDestination(pk, address)) { + const CScriptID& hash = boost::get(address); + CScript redeemScript; + if (pwalletMain->GetCScript(hash, redeemScript)) + entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end()))); + } + } + entry.push_back(Pair("amount",ValueFromAmount(nValue)));*/ + if ( out.tx->nLockTime != 0 ) + { + BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); + CBlockIndex *tipindex,*pindex = it->second; + uint64_t interest; uint32_t locktime; int32_t txheight; + if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); + interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); + //entry.push_back(Pair("interest",ValueFromAmount(interest))); + } + fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); + } + bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; + auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); + txNew.vin.resize(1); + txNew.vout.resize(1); + txfee = 10000; + for (i=0; i<32; i++) + ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; + txNew.vin[0].prevout.hash = revtxid; + txNew.vin[0].prevout.n = *utxovoutp; + txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + txNew.vout[0].nValue = nValue - txfees; + txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 60; // set to a time close to now + CTransaction txNewConst(txNew); + signSuccess = ProduceSignature(TransactionSignatureCreator(this, &txNewConst, 0, nValue, SIGHASH_ALL), out.tx->vout[out.i].scriptPubKey, sigdata, consensusBranchId); + if (!signSuccess) + fprintf(stderr,"failed to create signature\n"); + else + { + ptr = (uint8_t *)sigdata.scriptSig.data(); + siglen = sigdata.scriptSig.size(); + for (i=0; i Date: Mon, 9 Apr 2018 14:46:15 +0300 Subject: [PATCH 089/202] Test --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 68b280651..1ee32af92 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4503,6 +4503,7 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui } bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + const CKeyStore& keystore = ((fGivenKeys || !pwalletMain) ? tempKeystore : *pwalletMain); CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); txNew.vin.resize(1); txNew.vout.resize(1); @@ -4512,10 +4513,10 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui txNew.vin[0].prevout.hash = revtxid; txNew.vin[0].prevout.n = *utxovoutp; txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; - txNew.vout[0].nValue = nValue - txfees; + txNew.vout[0].nValue = nValue - txfee; txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 60; // set to a time close to now CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(this, &txNewConst, 0, nValue, SIGHASH_ALL), out.tx->vout[out.i].scriptPubKey, sigdata, consensusBranchId); + signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), out.tx->vout[out.i].scriptPubKey, sigdata, consensusBranchId); if (!signSuccess) fprintf(stderr,"failed to create signature\n"); else From 786456eecaea697ae23fac3f86be23b3403f3ea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 14:47:43 +0300 Subject: [PATCH 090/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1ee32af92..3a97be75e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4503,7 +4503,7 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui } bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - const CKeyStore& keystore = ((fGivenKeys || !pwalletMain) ? tempKeystore : *pwalletMain); + const CKeyStore& keystore = *pwalletMain; CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); txNew.vin.resize(1); txNew.vout.resize(1); From 2ef19f04884a9e186bc2dd539c6f14fbab42d851 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 15:31:51 +0300 Subject: [PATCH 091/202] Test --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 46913d43e..a377e6d41 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -569,11 +569,11 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n) hashBlock, true)) { //printf("null GetTransaction\n"); - if ( n < tx.vout.size() ) - *valuep = tx.vout[n].nValue; - return(tx.nLockTime); + return(0); } - return(0); + if ( n < tx.vout.size() ) + *valuep = tx.vout[n].nValue; + return(tx.nLockTime); } void komodo_disconnect(CBlockIndex *pindex,CBlock& block) From 47c0694c851f29807786e1009f3e05c3c93dd0d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 15:35:32 +0300 Subject: [PATCH 092/202] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a377e6d41..42c216d8f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -568,7 +568,7 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n) #endif hashBlock, true)) { - //printf("null GetTransaction\n"); + fprintf(stderr,"%s/v%d null GetTransaction locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } if ( n < tx.vout.size() ) From f144f1f4fc058298daff1d0fcf7448a05656e5e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 15:36:02 +0300 Subject: [PATCH 093/202] Test --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 42c216d8f..2cab956c3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -571,6 +571,7 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n) fprintf(stderr,"%s/v%d null GetTransaction locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } + fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); if ( n < tx.vout.size() ) *valuep = tx.vout[n].nValue; return(tx.nLockTime); From 66b4e563100dbd6260ac8fcf45ae5290c2165cf2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 15:43:05 +0300 Subject: [PATCH 094/202] Test --- src/miner.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index bba4e62d3..384a60f40 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -391,7 +391,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( (siglen= komodo_staked(&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); - CAmount txfees = 10000; + CAmount txfees = 0; txStaked.vin.resize(1); txStaked.vout.resize(1); for (i=0; i<32; i++) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3a97be75e..8c9825b37 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4507,7 +4507,7 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); txNew.vin.resize(1); txNew.vout.resize(1); - txfee = 10000; + txfee = 0; for (i=0; i<32; i++) ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; txNew.vin[0].prevout.hash = revtxid; From aa0b9e00b9d175711deaba0e0b39d521c2659427 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 15:50:37 +0300 Subject: [PATCH 095/202] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 384a60f40..d118b3da1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -422,6 +422,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight,chainparams.GetConsensus()); + txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); txNew.nExpiryHeight = 0; // Add fees txNew.vout[0].nValue += nFees; From 9339a0cbbd47a957dfce15c6541acccbbbaff107 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 16:26:57 +0300 Subject: [PATCH 096/202] Test --- src/komodo_gateway.h | 17 +++++++++++++---- src/main.cpp | 4 +++- src/miner.cpp | 13 +++++++------ src/wallet/rpcwallet.cpp | 9 +++++---- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 29d8bd984..ca2b6dcf1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -670,6 +670,17 @@ uint64_t komodo_commission(const CBlock &block) return((total * ASSETCHAINS_COMMISSION) / COIN); } +int32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) +{ + uint32_t txtime,minutes; + txtime = komodo_txtime(&value,hash,n); + minutes = (blocktime - txtime) / 60; + fprintf(stderr,"txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); + if ( nHeight < 200 ) + return(1); + else return(0); +} + int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing { static uint256 array[64]; static int32_t numbanned,indallvouts; @@ -742,15 +753,13 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( ASSETCHAINS_STAKED != 0 ) { - uint32_t txtime,minutes; uint64_t value; CBlockIndex *previndex; + CBlockIndex *previndex; if ( prevtime == 0 ) { if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 ) prevtime = (uint32_t)previndex->nTime; } - txtime = komodo_txtime(&value,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n); - minutes = (block.nTime - txtime) / 60; - fprintf(stderr,"txn_count.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",txn_count,txtime,block.nTime,prevtime,(int32_t)(block.nTime-prevtime),minutes,dstr(value)); + komodo_stake(block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { diff --git a/src/main.cpp b/src/main.cpp index 6f4dd89fa..2505e629c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1636,7 +1636,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) //uint64_t komodo_moneysupply(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint32_t ASSETCHAINS_MAGIC; -extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; +extern uint64_t ASSETCHAINS_STAKED,ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { @@ -3493,6 +3493,8 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl } if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); + else if ( ASSETCHAINS_STAKED != 0 && blockhdr.nTime <= chainActive.Tip()->nTime ) + return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); // Check block version //if (block.nVersion < MIN_BLOCK_VERSION) // return state.DoS(100, error("CheckBlockHeader(): block version too low"),REJECT_INVALID, "version-too-low"); diff --git a/src/miner.cpp b/src/miner.cpp index d118b3da1..1c948e124 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -120,11 +120,11 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); uint64_t komodo_commission(const CBlock &block); -int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); +int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { - uint64_t deposits; int32_t isrealtime,kmdheight; const CChainParams& chainparams = Params(); + uint64_t deposits; int32_t isrealtime,kmdheight; uint32_t blocktime; const CChainParams& chainparams = Params(); // Create new block std::unique_ptr pblocktemplate(new CBlockTemplate()); if(!pblocktemplate.get()) @@ -384,11 +384,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize); + blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + LogPrintf("CreateNewBlock(): total size %u blocktime.%u\n", nBlockSize,blocktime); if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) { uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; - if ( (siglen= komodo_staked(&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) + if ( (siglen= komodo_staked(&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); CAmount txfees = 0; @@ -404,14 +405,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ptr[i] = utxosig[i]; txStaked.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; txStaked.vout[0].nValue = utxovalue - txfees; - fprintf(stderr,"utxovout.%d txtime.%u %.8f\n",utxovout,txtime,(double)utxovalue/COIN); - txStaked.nLockTime = chainActive.Tip()->nTime + 60; + txStaked.nLockTime = blocktime; pblock->vtx.push_back(txStaked); numsigs = GetLegacySigOpCount(txStaked); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(numsigs); nFees += txfees; + pblock->nTime = blocktime; } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8c9825b37..448dc0ab2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4440,7 +4440,7 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp) int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; -int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) +int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; assert(pwalletMain != NULL); @@ -4499,7 +4499,8 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); //entry.push_back(Pair("interest",ValueFromAmount(interest))); } - fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); + komodo_stake(chainActive()->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,chainActive()->nTime); + //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); @@ -4524,8 +4525,8 @@ int32_t komodo_staked(uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,ui ptr = (uint8_t *)sigdata.scriptSig.data(); siglen = sigdata.scriptSig.size(); for (i=0; i Date: Mon, 9 Apr 2018 16:30:42 +0300 Subject: [PATCH 097/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ca2b6dcf1..803d1607d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,7 +672,7 @@ uint64_t komodo_commission(const CBlock &block) int32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) { - uint32_t txtime,minutes; + uint32_t txtime,minutes; uint32_t value; txtime = komodo_txtime(&value,hash,n); minutes = (blocktime - txtime) / 60; fprintf(stderr,"txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); From b8429de9d1196ba62d46ae9c62b901151580727b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 16:33:16 +0300 Subject: [PATCH 098/202] Test --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 448dc0ab2..4c456785c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4439,6 +4439,7 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp) #include "script/sign.h" int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; +int32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime); int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { @@ -4499,7 +4500,7 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); //entry.push_back(Pair("interest",ValueFromAmount(interest))); } - komodo_stake(chainActive()->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,chainActive()->nTime); + komodo_stake((uint32_t)chainActive()->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)chainActive()->nTime); //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; From 16113fd2dc29eb24f5a0fa5e7e2dc49f9e3e49d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 16:34:30 +0300 Subject: [PATCH 099/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 803d1607d..ed8b4f810 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,7 +672,7 @@ uint64_t komodo_commission(const CBlock &block) int32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) { - uint32_t txtime,minutes; uint32_t value; + uint32_t txtime,minutes; uint64_t value; txtime = komodo_txtime(&value,hash,n); minutes = (blocktime - txtime) / 60; fprintf(stderr,"txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); From 14ab43ab455e36cc55ee1a61b4bc0b771bdaa389 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 16:36:18 +0300 Subject: [PATCH 100/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ed8b4f810..2953a8cbc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -759,7 +759,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 ) prevtime = (uint32_t)previndex->nTime; } - komodo_stake(block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); + komodo_stake(height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { From 51217f768f74bcd742fed7dc99c7024b89f316be Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 16:38:45 +0300 Subject: [PATCH 101/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4c456785c..06424bc9f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4500,7 +4500,7 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); //entry.push_back(Pair("interest",ValueFromAmount(interest))); } - komodo_stake((uint32_t)chainActive()->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)chainActive()->nTime); + komodo_stake((uint32_t)chainActive.Tip()->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)chainActive.Tip()->nTime); //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; From 935fee29b52c73d2acc0204e27b9ca73c6934ec7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 16:41:32 +0300 Subject: [PATCH 102/202] Test --- src/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 2505e629c..3228f2fc8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3494,7 +3494,10 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); else if ( ASSETCHAINS_STAKED != 0 && blockhdr.nTime <= chainActive.Tip()->nTime ) + { + fprintf(stderr,"%u vs %u, is not monotonic\n",blockhdr.nTime,chainActive.Tip()->nTime); return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); + } // Check block version //if (block.nVersion < MIN_BLOCK_VERSION) // return state.DoS(100, error("CheckBlockHeader(): block version too low"),REJECT_INVALID, "version-too-low"); From f0a5789a5bd67e8e38f2b58d8958de201e7470f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 16:43:37 +0300 Subject: [PATCH 103/202] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3228f2fc8..7617750de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3495,7 +3495,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); else if ( ASSETCHAINS_STAKED != 0 && blockhdr.nTime <= chainActive.Tip()->nTime ) { - fprintf(stderr,"%u vs %u, is not monotonic\n",blockhdr.nTime,chainActive.Tip()->nTime); + fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",height,blockhdr.nTime,chainActive.Tip()->nHeight,chainActive.Tip()->nTime); return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); } // Check block version From 9aa73758b79992990769c19f18f17f957ef3a7e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 16:46:55 +0300 Subject: [PATCH 104/202] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7617750de..2059fedc3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3493,9 +3493,9 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl } if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); - else if ( ASSETCHAINS_STAKED != 0 && blockhdr.nTime <= chainActive.Tip()->nTime ) + else if ( ASSETCHAINS_STAKED != 0 && pindex->nTime <= chainActive.Tip()->nTime ) { - fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",height,blockhdr.nTime,chainActive.Tip()->nHeight,chainActive.Tip()->nTime); + fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,chainActive.Tip()->nHeight,chainActive.Tip()->nTime); return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); } // Check block version From c38ad7246de27546762a401a3518030994ed2bca Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 16:48:19 +0300 Subject: [PATCH 105/202] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2059fedc3..4008f61e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3493,9 +3493,9 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl } if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); - else if ( ASSETCHAINS_STAKED != 0 && pindex->nTime <= chainActive.Tip()->nTime ) + else if ( ASSETCHAINS_STAKED != 0 && pindex->nTime <= pindex->pprev->nTime ) { - fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,chainActive.Tip()->nHeight,chainActive.Tip()->nTime); + fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,pindex->pprev->nHeight,pindex->pprev->nTime); return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); } // Check block version From d9b696bb26c0eadfed6291a70d6e7f7833db8113 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 17:04:39 +0300 Subject: [PATCH 106/202] Test --- src/komodo_gateway.h | 2 +- src/main.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2953a8cbc..773d35402 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -675,7 +675,7 @@ int32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,u uint32_t txtime,minutes; uint64_t value; txtime = komodo_txtime(&value,hash,n); minutes = (blocktime - txtime) / 60; - fprintf(stderr,"txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); + fprintf(stderr,"ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); if ( nHeight < 200 ) return(1); else return(0); diff --git a/src/main.cpp b/src/main.cpp index 4008f61e9..4639814de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3493,7 +3493,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl } if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); - else if ( ASSETCHAINS_STAKED != 0 && pindex->nTime <= pindex->pprev->nTime ) + else if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime ) { fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,pindex->pprev->nHeight,pindex->pprev->nTime); return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 06424bc9f..31ad605f9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4499,8 +4499,8 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); //entry.push_back(Pair("interest",ValueFromAmount(interest))); + komodo_stake((uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); } - komodo_stake((uint32_t)chainActive.Tip()->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)chainActive.Tip()->nTime); //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; From 8a60c805932d5886928a89701cdfe8bfa68777f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 17:09:47 +0300 Subject: [PATCH 107/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 31ad605f9..393b5afbe 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4516,7 +4516,7 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, txNew.vin[0].prevout.n = *utxovoutp; txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; txNew.vout[0].nValue = nValue - txfee; - txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 60; // set to a time close to now + txNew.nLockTime = *blocktimep; CTransaction txNewConst(txNew); signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), out.tx->vout[out.i].scriptPubKey, sigdata, consensusBranchId); if (!signSuccess) From 1f34df6b3f22a8f6f73257df0c334a5aca2272da Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 17:59:33 +0300 Subject: [PATCH 108/202] Test --- src/komodo_bitcoind.h | 3 +- src/komodo_gateway.h | 15 +++++---- src/wallet/rpcwallet.cpp | 70 ++++++++++++++++++++++------------------ 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2cab956c3..f7d9af114 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -568,10 +568,9 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n) #endif hashBlock, true)) { - fprintf(stderr,"%s/v%d null GetTransaction locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } - fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); + //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); if ( n < tx.vout.size() ) *valuep = tx.vout[n].nValue; return(tx.nLockTime); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 773d35402..e002711ac 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -670,14 +670,15 @@ uint64_t komodo_commission(const CBlock &block) return((total * ASSETCHAINS_COMMISSION) / COIN); } -int32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) +uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) { - uint32_t txtime,minutes; uint64_t value; + uint32_t txtime,minutes; uint64_t value,hit; txtime = komodo_txtime(&value,hash,n); minutes = (blocktime - txtime) / 60; - fprintf(stderr,"ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); + hit = value / (blocktime - txtime); + fprintf(stderr,"hit.%llu ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",(long long)hit,nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); if ( nHeight < 200 ) - return(1); + return(blocktime); else return(0); } @@ -753,13 +754,15 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( ASSETCHAINS_STAKED != 0 ) { - CBlockIndex *previndex; + CBlockIndex *previndex; uint32_t eligible; if ( prevtime == 0 ) { if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 ) prevtime = (uint32_t)previndex->nTime; } - komodo_stake(height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); + eligible = komodo_stake(height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); + if ( eligible > block.nTime ) + fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 393b5afbe..60c1aa7be 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4439,11 +4439,11 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp) #include "script/sign.h" int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; -int32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime); +uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime); int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; const COutput& best; uint32_t earliest = 0; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; @@ -4466,10 +4466,6 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, CAmount nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); - *utxovaluep = (uint64_t)nValue; - decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); - *utxovoutp = out.i; - *txtimep = (uint32_t)out.tx->nLockTime; CTxDestination address; if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { @@ -4499,35 +4495,47 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); //entry.push_back(Pair("interest",ValueFromAmount(interest))); - komodo_stake((uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); + eligible = komodo_stake((uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); + if ( eligible > 0 && eligible < earliest ) + { + earliest = eligible; + best = out; + *utxovaluep = (uint64_t)nValue; + decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); + *utxovoutp = out.i; + *txtimep = (uint32_t)out.tx->nLockTime; + } } //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } - bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; - auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - const CKeyStore& keystore = *pwalletMain; - CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); - txNew.vin.resize(1); - txNew.vout.resize(1); - txfee = 0; - for (i=0; i<32; i++) - ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; - txNew.vin[0].prevout.hash = revtxid; - txNew.vin[0].prevout.n = *utxovoutp; - txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; - txNew.vout[0].nValue = nValue - txfee; - txNew.nLockTime = *blocktimep; - CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), out.tx->vout[out.i].scriptPubKey, sigdata, consensusBranchId); - if (!signSuccess) - fprintf(stderr,"failed to create signature\n"); - else + if ( earliest != 0 ) { - ptr = (uint8_t *)sigdata.scriptSig.data(); - siglen = sigdata.scriptSig.size(); - for (i=0; ivout[best.i].scriptPubKey, sigdata, consensusBranchId); + if (!signSuccess) + fprintf(stderr,"failed to create signature\n"); + else + { + ptr = (uint8_t *)sigdata.scriptSig.data(); + siglen = sigdata.scriptSig.size(); + for (i=0; i Date: Mon, 9 Apr 2018 18:02:28 +0300 Subject: [PATCH 109/202] Test --- src/wallet/rpcwallet.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 60c1aa7be..88454da8d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4443,10 +4443,11 @@ uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime, int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; const COutput& best; uint32_t earliest = 0; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; const COutpu best; uint32_t eligible,earliest = 0; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; + memset(&best,0,sizeof(best)); memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); @@ -4492,9 +4493,6 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, uint64_t interest; uint32_t locktime; int32_t txheight; if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) { - komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); - interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); - //entry.push_back(Pair("interest",ValueFromAmount(interest))); eligible = komodo_stake((uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); if ( eligible > 0 && eligible < earliest ) { From ebcb53068f0c88b536012281d100ee8834d2e904 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 18:03:28 +0300 Subject: [PATCH 110/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 88454da8d..b8a0a87de 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4443,7 +4443,7 @@ uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime, int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; const COutpu best; uint32_t eligible,earliest = 0; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; COutput best; uint32_t eligible,earliest = 0; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; From df643d5cd7d11ce2fda8090ea64b81e54668b462 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 18:06:37 +0300 Subject: [PATCH 111/202] Test --- src/wallet/rpcwallet.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b8a0a87de..5d3feeeb0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4443,11 +4443,10 @@ uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime, int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; COutput best; uint32_t eligible,earliest = 0; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubkey; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; - memset(&best,0,sizeof(best)); memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); @@ -4497,7 +4496,7 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, if ( eligible > 0 && eligible < earliest ) { earliest = eligible; - best = out; + best_scriptPubkey = out.tx->vout[out.i].scriptPubKey; *utxovaluep = (uint64_t)nValue; decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; @@ -4523,7 +4522,7 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, txNew.vout[0].nValue = nValue - txfee; txNew.nLockTime = *blocktimep; CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), best.tx->vout[best.i].scriptPubKey, sigdata, consensusBranchId); + signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); if (!signSuccess) fprintf(stderr,"failed to create signature\n"); else From 9159a0408bfbc53b994caaa1cdcce1872bd4fc80 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 18:07:58 +0300 Subject: [PATCH 112/202] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5d3feeeb0..f208635ff 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4443,7 +4443,7 @@ uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime, int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubkey; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; @@ -4496,7 +4496,7 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, if ( eligible > 0 && eligible < earliest ) { earliest = eligible; - best_scriptPubkey = out.tx->vout[out.i].scriptPubKey; + best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; *utxovaluep = (uint64_t)nValue; decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; From 39e050579014fa89308de9b72269b39545b23544 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 18:24:11 +0300 Subject: [PATCH 113/202] Test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e002711ac..232a78eb1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,11 +672,11 @@ uint64_t komodo_commission(const CBlock &block) uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) { - uint32_t txtime,minutes; uint64_t value,hit; + uint32_t txtime,minutes; uint64_t value,coinage; txtime = komodo_txtime(&value,hash,n); minutes = (blocktime - txtime) / 60; - hit = value / (blocktime - txtime); - fprintf(stderr,"hit.%llu ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",(long long)hit,nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); + coinage = value * (blocktime - txtime); + fprintf(stderr,"coinage.%llu ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",(long long)coinage,nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); if ( nHeight < 200 ) return(blocktime); else return(0); From add7f889fd862c0825afde268778e401f6ff53ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 18:38:38 +0300 Subject: [PATCH 114/202] Test --- src/komodo_gateway.h | 2 ++ src/wallet/rpcwallet.cpp | 27 ++++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 232a78eb1..e1c8ec4fd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -675,6 +675,8 @@ uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime, uint32_t txtime,minutes; uint64_t value,coinage; txtime = komodo_txtime(&value,hash,n); minutes = (blocktime - txtime) / 60; + if ( txtime == 0 ) + txtime = prevtime; coinage = value * (blocktime - txtime); fprintf(stderr,"coinage.%llu ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",(long long)coinage,nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); if ( nHeight < 200 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f208635ff..9954456fd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4485,23 +4485,20 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, } } entry.push_back(Pair("amount",ValueFromAmount(nValue)));*/ - if ( out.tx->nLockTime != 0 ) + BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); + CBlockIndex *tipindex,*pindex = it->second; + uint64_t interest; uint32_t locktime; int32_t txheight; + if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) { - BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *tipindex,*pindex = it->second; - uint64_t interest; uint32_t locktime; int32_t txheight; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + eligible = komodo_stake((uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); + if ( eligible > 0 && eligible < earliest ) { - eligible = komodo_stake((uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); - if ( eligible > 0 && eligible < earliest ) - { - earliest = eligible; - best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; - *utxovaluep = (uint64_t)nValue; - decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); - *utxovoutp = out.i; - *txtimep = (uint32_t)out.tx->nLockTime; - } + earliest = eligible; + best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; + *utxovaluep = (uint64_t)nValue; + decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); + *utxovoutp = out.i; + *txtimep = (uint32_t)out.tx->nLockTime; } //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } From a2cc707b5433bbe343fc0330bd53d8a8d7d83001 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 18:44:52 +0300 Subject: [PATCH 115/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e1c8ec4fd..901fb6487 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -678,7 +678,7 @@ uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime, if ( txtime == 0 ) txtime = prevtime; coinage = value * (blocktime - txtime); - fprintf(stderr,"coinage.%llu ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",(long long)coinage,nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); + fprintf(stderr,"coinage.%llu %d ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",(long long)coinage,(int32_t)(blocktime - txtime),nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); if ( nHeight < 200 ) return(blocktime); else return(0); From f65cd56ff25f590939b8da748a90c7fa146413da Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 18:49:38 +0300 Subject: [PATCH 116/202] Test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 901fb6487..99657dfec 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,13 +672,13 @@ uint64_t komodo_commission(const CBlock &block) uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) { - uint32_t txtime,minutes; uint64_t value,coinage; + uint32_t txtime,minutes; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY*SATOSHIDEN + nHeight*ASSETCHAINS_REWARD; txtime = komodo_txtime(&value,hash,n); minutes = (blocktime - txtime) / 60; if ( txtime == 0 ) txtime = prevtime; - coinage = value * (blocktime - txtime); - fprintf(stderr,"coinage.%llu %d ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f\n",(long long)coinage,(int32_t)(blocktime - txtime),nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value)); + coinage = value * (blocktime - txtime) * value / supply; + fprintf(stderr,"coinage.%llu %d ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f.%.8f\n",(long long)coinage,(int32_t)(blocktime - txtime),nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value),dstr(supply)); if ( nHeight < 200 ) return(blocktime); else return(0); From 97dfa23436a2450d09687b90beddc5cf55192022 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 18:52:59 +0300 Subject: [PATCH 117/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 99657dfec..c5f5b0f5c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,12 +672,12 @@ uint64_t komodo_commission(const CBlock &block) uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) { - uint32_t txtime,minutes; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY*SATOSHIDEN + nHeight*ASSETCHAINS_REWARD; + uint32_t txtime,minutes; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,hash,n); minutes = (blocktime - txtime) / 60; if ( txtime == 0 ) txtime = prevtime; - coinage = value * (blocktime - txtime) * value / supply; + coinage = value * (blocktime - txtime) / supply; fprintf(stderr,"coinage.%llu %d ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f.%.8f\n",(long long)coinage,(int32_t)(blocktime - txtime),nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value),dstr(supply)); if ( nHeight < 200 ) return(blocktime); From d16afe20169cc87c5fa4eadfbe1ca34e859e8361 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 18:57:37 +0300 Subject: [PATCH 118/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c5f5b0f5c..8a026e239 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -678,7 +678,7 @@ uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime, if ( txtime == 0 ) txtime = prevtime; coinage = value * (blocktime - txtime) / supply; - fprintf(stderr,"coinage.%llu %d ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f.%.8f\n",(long long)coinage,(int32_t)(blocktime - txtime),nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value),dstr(supply)); + fprintf(stderr,"coinage.%llu %d ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f/%llu\n",(long long)coinage,(int32_t)(blocktime - txtime),nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value),(long long)supply); if ( nHeight < 200 ) return(blocktime); else return(0); From 357e4ca5f0ea40e93912b90e6c3b5ae90b6738a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 19:33:50 +0300 Subject: [PATCH 119/202] Test --- src/komodo_gateway.h | 32 +++++++++++++++++++++++--------- src/miner.cpp | 11 +++++++---- src/wallet/rpcwallet.cpp | 9 +++++---- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8a026e239..3a6f97af6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -670,18 +670,31 @@ uint64_t komodo_commission(const CBlock &block) return((total * ASSETCHAINS_COMMISSION) / COIN); } -uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) +uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) { - uint32_t txtime,minutes; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t i; uint32_t txtime,minutes,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + if ( nHeight < 200 ) + return(blocktime); txtime = komodo_txtime(&value,hash,n); minutes = (blocktime - txtime) / 60; if ( txtime == 0 ) txtime = prevtime; - coinage = value * (blocktime - txtime) / supply; - fprintf(stderr,"coinage.%llu %d ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f/%llu\n",(long long)coinage,(int32_t)(blocktime - txtime),nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value),(long long)supply); - if ( nHeight < 200 ) - return(blocktime); - else return(0); + if ( (pindex= komodo_chainactive(nHeight-200)) != 0 ) + { + coinage = value * (blocktime - txtime) / supply; + hash = pindex->GetBlockHash(); // hash pubkey + hashval = UintToArith256(hash); + hashval = (hashval / arith_uint256(coinage+1)); + if ( hashval <= bnTarget ) + winner = 1; + for (i=31; i>=0; i--) + printf("%02x",((uint8_t *)&hashval)[i]); + printf(" vs "); + for (i=31; i>=0; i--) + printf("%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," winner.%d %s coinage.%llu %d ht.%d gap.%d minutes.%d %.8f/%llu\n",winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),minutes,dstr(value),(long long)supply); + } + return(0); } int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing @@ -756,13 +769,14 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( ASSETCHAINS_STAKED != 0 ) { - CBlockIndex *previndex; uint32_t eligible; + arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *previndex; uint32_t eligible; if ( prevtime == 0 ) { if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 ) prevtime = (uint32_t)previndex->nTime; } - eligible = komodo_stake(height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); + bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); + eligible = komodo_stake(height,bnTarget,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); if ( eligible > block.nTime ) fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); } diff --git a/src/miner.cpp b/src/miner.cpp index 1c948e124..adc562bdf 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -120,7 +120,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); uint64_t komodo_commission(const CBlock &block); -int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); +int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { @@ -385,7 +385,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); - LogPrintf("CreateNewBlock(): total size %u blocktime.%u\n", nBlockSize,blocktime); + pblock->nTime = blocktime; + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); + LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) { uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; @@ -480,7 +482,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashReserved = uint256(); //UpdateTime(pblock, Params().GetConsensus(), pindexPrev); - pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); + //pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); @@ -1033,7 +1035,8 @@ void static BitcoinMiner() // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; - UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); + if ( ASSETCHAINS_STAKED == 0 ) + UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) { // Changing pblock->nTime can change work required on testnet: diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9954456fd..53e3fdeff 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4439,11 +4439,12 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp) #include "script/sign.h" int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; -uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime); +uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime); -int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) +int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; @@ -4490,7 +4491,7 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp, uint64_t interest; uint32_t locktime; int32_t txheight; if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) { - eligible = komodo_stake((uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); + eligible = komodo_stake(bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); if ( eligible > 0 && eligible < earliest ) { earliest = eligible; From 42673bc0722b84ec03c270b68952cf28679a7625 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 19:34:56 +0300 Subject: [PATCH 120/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3a6f97af6..44abafa92 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -776,7 +776,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim prevtime = (uint32_t)previndex->nTime; } bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - eligible = komodo_stake(height,bnTarget,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); + eligible = komodo_stake(bnTarget,height,bnTarget,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); if ( eligible > block.nTime ) fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); } From 66b30bbc39c4bf0b847e986c742c7d42b44b3cf1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 19:35:48 +0300 Subject: [PATCH 121/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 44abafa92..9541f1949 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -670,12 +670,12 @@ uint64_t komodo_commission(const CBlock &block) return((total * ASSETCHAINS_COMMISSION) / COIN); } -uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime) +uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime) { CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t i; uint32_t txtime,minutes,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; if ( nHeight < 200 ) return(blocktime); - txtime = komodo_txtime(&value,hash,n); + txtime = komodo_txtime(&value,txid,vout); minutes = (blocktime - txtime) / 60; if ( txtime == 0 ) txtime = prevtime; From c59bdf3a8152f2d2dda593bdc0501cf3dd5b1ce1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 19:37:00 +0300 Subject: [PATCH 122/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9541f1949..dc4a021f0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -692,7 +692,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ printf(" vs "); for (i=31; i>=0; i--) printf("%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," winner.%d %s coinage.%llu %d ht.%d gap.%d minutes.%d %.8f/%llu\n",winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),minutes,dstr(value),(long long)supply); + fprintf(stderr," winner.%d coinage.%llu %d ht.%d gap.%d minutes.%d %.8f/%llu\n",winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),minutes,dstr(value),(long long)supply); } return(0); } From fd573503ba10d577bc165dac6f9f7dfadc53ed9d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 19:40:22 +0300 Subject: [PATCH 123/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dc4a021f0..3bfd0b58a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -776,7 +776,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim prevtime = (uint32_t)previndex->nTime; } bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - eligible = komodo_stake(bnTarget,height,bnTarget,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); + eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); if ( eligible > block.nTime ) fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); } From acb3822ea063ff2317c6eadc07d1ccb56b66e7e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 19:42:12 +0300 Subject: [PATCH 124/202] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index adc562bdf..5acd8da34 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -391,7 +391,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) { uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; - if ( (siglen= komodo_staked(&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) + if ( (siglen= komodo_staked(pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); CAmount txfees = 0; From aa789b4f24f1c102573c5eac54bd9f4d629ceae0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 19:46:18 +0300 Subject: [PATCH 125/202] Test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3bfd0b58a..e52c27ac4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -688,10 +688,10 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ if ( hashval <= bnTarget ) winner = 1; for (i=31; i>=0; i--) - printf("%02x",((uint8_t *)&hashval)[i]); - printf(" vs "); + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); for (i=31; i>=0; i--) - printf("%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); fprintf(stderr," winner.%d coinage.%llu %d ht.%d gap.%d minutes.%d %.8f/%llu\n",winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),minutes,dstr(value),(long long)supply); } return(0); From 6eb0958c4d03eae1f2705f667d9cf947f7a5c4af Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 19:57:32 +0300 Subject: [PATCH 126/202] Test --- src/komodo_gateway.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e52c27ac4..4e0257fff 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,21 +672,30 @@ uint64_t komodo_commission(const CBlock &block) uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime) { - CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t i; uint32_t txtime,minutes,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t i; uint32_t txtime,minutes,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; if ( nHeight < 200 ) return(blocktime); txtime = komodo_txtime(&value,txid,vout); minutes = (blocktime - txtime) / 60; if ( txtime == 0 ) txtime = prevtime; - if ( (pindex= komodo_chainactive(nHeight-200)) != 0 ) + if ( blocktime > txtime && (pindex= komodo_chainactive(nHeight-200)) != 0 ) { - coinage = value * (blocktime - txtime) / supply; + diff = (blocktime - txtime); + coinage = value * diff / supply; hash = pindex->GetBlockHash(); // hash pubkey hashval = UintToArith256(hash); hashval = (hashval / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; + else + { + arith_uint256 val; + val = bnTarget * arith_uint256(value*diff/supply) / UintToArith256(hash) + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&val)[i]); + printf(" adjust val\n"); + } for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); From dd5541420a60692d48d5fcd8d78e15a4b834110a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 19:58:41 +0300 Subject: [PATCH 127/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4e0257fff..17a62d990 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -691,7 +691,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ else { arith_uint256 val; - val = bnTarget * arith_uint256(value*diff/supply) / UintToArith256(hash) + val = bnTarget * arith_uint256(value*diff/supply) / UintToArith256(hash); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&val)[i]); printf(" adjust val\n"); From 8e9ef91cf4b37998b77f8cb343d40dd9bc4ae276 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 20:06:19 +0300 Subject: [PATCH 128/202] Test --- src/miner.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 5acd8da34..69a7d240c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -752,7 +752,7 @@ void static BitcoinMiner() Mining_height = pindexPrev->nHeight+1; Mining_start = (uint32_t)time(NULL); } - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED == 0 ) { //fprintf(stderr,"%s create new block ht.%d\n",ASSETCHAINS_SYMBOL,Mining_height); sleep(3); @@ -900,17 +900,26 @@ void static BitcoinMiner() // fprintf(stderr," missed target\n"); return false; } - if ( /*ASSETCHAINS_SYMBOL[0] == 0 &&*/ Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay ) + if ( ASSETCHAINS_STAKED == 0 ) { - //printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+roundrobin_delay-time(NULL))); - int32_t nseconds = Mining_start+roundrobin_delay-time(NULL); - if ( nseconds > 0 ) - sleep(nseconds); - MilliSleep((rand() % 1700) + 1); + if ( Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay ) + { + //printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+roundrobin_delay-time(NULL))); + int32_t nseconds = Mining_start+roundrobin_delay-time(NULL); + if ( nseconds > 0 ) + sleep(nseconds); + MilliSleep((rand() % 1700) + 1); + } + else if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { + sleep(rand() % 30); + } } - else if ( ASSETCHAINS_SYMBOL[0] != 0 ) + else { - sleep(rand() % 30); + printf("need to wait %d seconds to submit\n",(int32_t)(pblock->nTime - GetAdjustedTime())); + while ( GetAdjustedTime() < pblock->nTime ) + sleep(1); } KOMODO_CHOSEN_ONE = 1; // Found a solution From ee2d6a73da2ad82348b0073077783b316eb9ade8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 20:07:45 +0300 Subject: [PATCH 129/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 17a62d990..353f8f72f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -703,7 +703,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); fprintf(stderr," winner.%d coinage.%llu %d ht.%d gap.%d minutes.%d %.8f/%llu\n",winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),minutes,dstr(value),(long long)supply); } - return(0); + return(blocktime * winner); } int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing @@ -786,7 +786,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); - if ( eligible > block.nTime ) + if ( eligible == 0 || eligible > block.nTime ) fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) From 274f9fb365400f89dd81963f033892cfea941f02 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 20:14:41 +0300 Subject: [PATCH 130/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 353f8f72f..9b16c846e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -682,7 +682,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ if ( blocktime > txtime && (pindex= komodo_chainactive(nHeight-200)) != 0 ) { diff = (blocktime - txtime); - coinage = value * diff / supply; + coinage = value * diff;// / supply; hash = pindex->GetBlockHash(); // hash pubkey hashval = UintToArith256(hash); hashval = (hashval / arith_uint256(coinage+1)); From 64eb9cb21d37cc983ae6b882d7039fb0e99aebc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 20:21:15 +0300 Subject: [PATCH 131/202] Test --- src/komodo_gateway.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9b16c846e..10edb63db 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,7 +672,7 @@ uint64_t komodo_commission(const CBlock &block) uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime) { - CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t i; uint32_t txtime,minutes,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t i,j; uint32_t txtime,minutes,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; if ( nHeight < 200 ) return(blocktime); txtime = komodo_txtime(&value,txid,vout); @@ -681,11 +681,10 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ txtime = prevtime; if ( blocktime > txtime && (pindex= komodo_chainactive(nHeight-200)) != 0 ) { - diff = (blocktime - txtime); - coinage = value * diff;// / supply; hash = pindex->GetBlockHash(); // hash pubkey - hashval = UintToArith256(hash); - hashval = (hashval / arith_uint256(coinage+1)); + diff = (blocktime - txtime); + coinage = value * diff / supply; + hashval = (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; else @@ -694,7 +693,19 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ val = bnTarget * arith_uint256(value*diff/supply) / UintToArith256(hash); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&val)[i]); - printf(" adjust val\n"); + fprintf(stderr," adjust val\n"); + for (i=1; i<3600; i++) + { + diff = (i + blocktime - txtime); + coinage = value * diff / supply; + hashval = (UintToArith256(hash) / arith_uint256(coinage+1)); + if ( hashval <= bnTarget ) + { + winner = 1; + break; + } + } + fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); } for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 41ed65c8381b7634d495175058ffd585f1c91d48 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 20:25:20 +0300 Subject: [PATCH 132/202] Test --- src/komodo_gateway.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 10edb63db..bf172052c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -676,6 +676,8 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ if ( nHeight < 200 ) return(blocktime); txtime = komodo_txtime(&value,txid,vout); + if ( value == 0 ) + return(0); minutes = (blocktime - txtime) / 60; if ( txtime == 0 ) txtime = prevtime; @@ -684,7 +686,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); coinage = value * diff / supply; - hashval = (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; else @@ -698,7 +700,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { diff = (i + blocktime - txtime); coinage = value * diff / supply; - hashval = (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; From cb6b9bd10dec6f820a2c2361f721b24124f78d79 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 20:33:08 +0300 Subject: [PATCH 133/202] Test --- src/komodo_gateway.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bf172052c..5008c1753 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -685,25 +685,21 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); - coinage = value * diff / supply; + coinage = (value * diff * diff) / supply; hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; else { - arith_uint256 val; - val = bnTarget * arith_uint256(value*diff/supply) / UintToArith256(hash); - for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&val)[i]); - fprintf(stderr," adjust val\n"); - for (i=1; i<3600; i++) + for (i=1; i<3600*8; i++) { diff = (i + blocktime - txtime); - coinage = value * diff / supply; + coinage = (value * diff * diff) / supply; hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; + blocktime += i; break; } } From 7591c6aa4751baab61fd36726b1e66c7b63e045f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 20:35:59 +0300 Subject: [PATCH 134/202] Test --- src/komodo_gateway.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5008c1753..fdb30bb73 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -686,7 +686,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); coinage = (value * diff * diff) / supply; - hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(100000000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; else @@ -695,7 +695,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { diff = (i + blocktime - txtime); coinage = (value * diff * diff) / supply; - hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(100000000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; @@ -796,7 +796,9 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); if ( eligible == 0 || eligible > block.nTime ) + { fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); + } } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { From 1ac4a10dbe986114695af9b5bb257649b6a942a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 20:38:18 +0300 Subject: [PATCH 135/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index fdb30bb73..8238130ee 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -685,7 +685,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); - coinage = (value * diff * diff) / supply; + coinage = (((value * diff) / supply) * diff) / supply; hashval = arith_uint256(100000000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; @@ -694,7 +694,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ for (i=1; i<3600*8; i++) { diff = (i + blocktime - txtime); - coinage = (value * diff * diff) / supply; + coinage = (((value * diff) / supply) * diff) / supply; hashval = arith_uint256(100000000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { From e1a17ed172f47f65cc253f6775ccdc70daf8649c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 20:47:37 +0300 Subject: [PATCH 136/202] Test --- src/komodo_gateway.h | 19 +++++++++---------- src/wallet/rpcwallet.cpp | 1 + 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8238130ee..3ed0c607f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,13 +672,12 @@ uint64_t komodo_commission(const CBlock &block) uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime) { - CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t i,j; uint32_t txtime,minutes,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; if ( nHeight < 200 ) return(blocktime); txtime = komodo_txtime(&value,txid,vout); if ( value == 0 ) return(0); - minutes = (blocktime - txtime) / 60; if ( txtime == 0 ) txtime = prevtime; if ( blocktime > txtime && (pindex= komodo_chainactive(nHeight-200)) != 0 ) @@ -691,26 +690,26 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ winner = 1; else { - for (i=1; i<3600*8; i++) + for (iter=1; iter<3600*8; iter++) { - diff = (i + blocktime - txtime); + diff = (iter + blocktime - txtime); coinage = (((value * diff) / supply) * diff) / supply; hashval = arith_uint256(100000000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; - blocktime += i; + blocktime += iter; break; } } - fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); + //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); } for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs "); - for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," winner.%d coinage.%llu %d ht.%d gap.%d minutes.%d %.8f/%llu\n",winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),minutes,dstr(value),(long long)supply); + //fprintf(stderr," vs "); + //for (i=31; i>=0; i--) + // fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f/%llu\n",iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(long long)supply); } return(blocktime * winner); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 53e3fdeff..a9e64158c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4530,6 +4530,7 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint for (i=0; i Date: Mon, 9 Apr 2018 20:51:52 +0300 Subject: [PATCH 137/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3ed0c607f..11ce8f359 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -680,7 +680,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ return(0); if ( txtime == 0 ) txtime = prevtime; - if ( blocktime > txtime && (pindex= komodo_chainactive(nHeight-200)) != 0 ) + if ( blocktime > txtime+6000 && (pindex= komodo_chainactive(nHeight-200)) != 0 ) { hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); From d5d586e078189a8485d3a6a99ad980bb55edb08f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 20:59:16 +0300 Subject: [PATCH 138/202] Test --- src/komodo_gateway.h | 4 ++-- src/wallet/rpcwallet.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 11ce8f359..605225eed 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -685,7 +685,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); coinage = (((value * diff) / supply) * diff) / supply; - hashval = arith_uint256(100000000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; else @@ -694,7 +694,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { diff = (iter + blocktime - txtime); coinage = (((value * diff) / supply) * diff) / supply; - hashval = arith_uint256(100000000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a9e64158c..3d36e43ac 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4530,6 +4530,7 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint for (i=0; i Date: Mon, 9 Apr 2018 21:03:02 +0300 Subject: [PATCH 139/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 605225eed..a9cf3edfc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -684,7 +684,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); - coinage = (((value * diff) / supply) * diff) / supply; + coinage = (((value * diff) / supply) * diff); hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; @@ -693,7 +693,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ for (iter=1; iter<3600*8; iter++) { diff = (iter + blocktime - txtime); - coinage = (((value * diff) / supply) * diff) / supply; + coinage = (((value * diff) / supply) * diff); hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { From 14a53f21a1e9e69e226ca150f4d0aad2ecde95ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 21:08:46 +0300 Subject: [PATCH 140/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3d36e43ac..a52d7ab46 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4492,7 +4492,7 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) { eligible = komodo_stake(bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); - if ( eligible > 0 && eligible < earliest ) + if ( (eligible > 0 && eligible < earliest) || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { earliest = eligible; best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; From e005f57633c3f198c821b5726b4ad3c60cd71d89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 21:12:25 +0300 Subject: [PATCH 141/202] Test --- src/komodo_gateway.h | 8 ++++---- src/wallet/rpcwallet.cpp | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a9cf3edfc..367393fde 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -704,11 +704,11 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); } - for (i=31; i>=0; i--) + for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - //fprintf(stderr," vs "); - //for (i=31; i>=0; i--) - // fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," vs "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); fprintf(stderr," iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f/%llu\n",iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(long long)supply); } return(blocktime * winner); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a52d7ab46..b31948013 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4492,14 +4492,17 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) { eligible = komodo_stake(bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); - if ( (eligible > 0 && eligible < earliest) || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) + if ( eligible > 0 ) { - earliest = eligible; - best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; - *utxovaluep = (uint64_t)nValue; - decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); - *utxovoutp = out.i; - *txtimep = (uint32_t)out.tx->nLockTime; + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) + { + earliest = eligible; + best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; + *utxovaluep = (uint64_t)nValue; + decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); + *utxovoutp = out.i; + *txtimep = (uint32_t)out.tx->nLockTime; + } } //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } From fd098285ce5619a15e6fddc2b1e968a23d59008b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 21:12:49 +0300 Subject: [PATCH 142/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 367393fde..a2c726007 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -685,7 +685,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); coinage = (((value * diff) / supply) * diff); - hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(supply) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; else @@ -694,7 +694,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { diff = (iter + blocktime - txtime); coinage = (((value * diff) / supply) * diff); - hashval = arith_uint256(1000000) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(supply) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; From 8c218b4887a14409ea07442cbbfb9d300a2cbb56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 21:18:40 +0300 Subject: [PATCH 143/202] Test --- src/miner.cpp | 4 ++- src/wallet/rpcwallet.cpp | 58 ++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 69a7d240c..6102451d8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -384,7 +384,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + if ( ASSETCHAINS_STAKED != 0 ) + blocktime = pindexPrev->GetMedianTimePast()+1; + else blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); pblock->nTime = blocktime; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b31948013..6d04ccd6a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4506,36 +4506,36 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint } //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } - if ( earliest != 0 ) + } + if ( earliest != 0 ) + { + bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; + auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + const CKeyStore& keystore = *pwalletMain; + CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); + txNew.vin.resize(1); + txNew.vout.resize(1); + txfee = 0; + for (i=0; i<32; i++) + ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; + txNew.vin[0].prevout.hash = revtxid; + txNew.vin[0].prevout.n = *utxovoutp; + txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + txNew.vout[0].nValue = nValue - txfee; + txNew.nLockTime = *blocktimep; + CTransaction txNewConst(txNew); + signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); + if (!signSuccess) + fprintf(stderr,"failed to create signature\n"); + else { - bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; - auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - const CKeyStore& keystore = *pwalletMain; - CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); - txNew.vin.resize(1); - txNew.vout.resize(1); - txfee = 0; - for (i=0; i<32; i++) - ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; - txNew.vin[0].prevout.hash = revtxid; - txNew.vin[0].prevout.n = *utxovoutp; - txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; - txNew.vout[0].nValue = nValue - txfee; - txNew.nLockTime = *blocktimep; - CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); - if (!signSuccess) - fprintf(stderr,"failed to create signature\n"); - else - { - ptr = (uint8_t *)sigdata.scriptSig.data(); - siglen = sigdata.scriptSig.size(); - for (i=0; i Date: Mon, 9 Apr 2018 21:20:28 +0300 Subject: [PATCH 144/202] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6d04ccd6a..ca3fde8d0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4521,10 +4521,10 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint txNew.vin[0].prevout.hash = revtxid; txNew.vin[0].prevout.n = *utxovoutp; txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; - txNew.vout[0].nValue = nValue - txfee; + txNew.vout[0].nValue = *utxovaluep - txfee; txNew.nLockTime = *blocktimep; CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, nValue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); + signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); if (!signSuccess) fprintf(stderr,"failed to create signature\n"); else From 6d649e094ef0e4ca97ce333107fcb4518f80b73b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 21:24:23 +0300 Subject: [PATCH 145/202] Test --- src/komodo_gateway.h | 1 + src/pow.cpp | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a2c726007..645ef6145 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -797,6 +797,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim if ( eligible == 0 || eligible > block.nTime ) { fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); + return(-1); } } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) diff --git a/src/pow.cpp b/src/pow.cpp index 63806033d..23f1cf67b 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -122,6 +122,7 @@ int32_t komodo_currentheight(); CBlockIndex *komodo_chainactive(int32_t height); void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height); extern int32_t KOMODO_CHOSEN_ONE; +extern uint64_t ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[]; #define KOMODO_ELECTION_GAP 2000 @@ -141,7 +142,9 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in height = komodo_currentheight() + 1; special = komodo_chosennotary(¬aryid,height,pubkey33,timestamp); flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height); - if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary + if ( ASSETCHAINS_STAKED != 0 ) + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + else if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary { for (i=0; i<33; i++) { From e12ea51956ec3e70911b50b5090e93ae5f77e75c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 21:24:42 +0300 Subject: [PATCH 146/202] Test --- src/miner.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 6102451d8..69a7d240c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -384,9 +384,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - if ( ASSETCHAINS_STAKED != 0 ) - blocktime = pindexPrev->GetMedianTimePast()+1; - else blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); pblock->nTime = blocktime; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); From d3b5a9083eacd23dbfbcc73d31fdab82ce8de82e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 21:52:41 +0300 Subject: [PATCH 147/202] Test --- src/komodo_gateway.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 645ef6145..7760d907c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,15 +672,17 @@ uint64_t komodo_commission(const CBlock &block) uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime) { - CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - if ( nHeight < 200 ) + CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + if ( nHeight < 30 ) return(blocktime); txtime = komodo_txtime(&value,txid,vout); if ( value == 0 ) return(0); if ( txtime == 0 ) txtime = prevtime; - if ( blocktime > txtime+6000 && (pindex= komodo_chainactive(nHeight-200)) != 0 ) + if ( (minage= nHeight*30) > 6000 ) + minage = 6000; + if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) { hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); @@ -794,7 +796,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); - if ( eligible == 0 || eligible > block.nTime ) + if ( height > 100 && (eligible == 0 || eligible > block.nTime) ) { fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); return(-1); From d3aea61d5629add32ef0fa5246687d0d5c6b7b35 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 21:55:36 +0300 Subject: [PATCH 148/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7760d907c..ae07d92bc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -680,7 +680,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ return(0); if ( txtime == 0 ) txtime = prevtime; - if ( (minage= nHeight*30) > 6000 ) + if ( (minage= nHeight*3) > 6000 ) minage = 6000; if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) { From 36067f15e97747f962276c72a7a9ffe5b1092a07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 21:58:28 +0300 Subject: [PATCH 149/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ae07d92bc..6231c458c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -796,7 +796,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); - if ( height > 100 && (eligible == 0 || eligible > block.nTime) ) + if ( height >= 30 && (eligible == 0 || eligible > block.nTime) ) { fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); return(-1); From 6d94e8a836f4349ed71263dec604598987544606 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 22:13:18 +0300 Subject: [PATCH 150/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6231c458c..23d95ff0b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -676,8 +676,8 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ if ( nHeight < 30 ) return(blocktime); txtime = komodo_txtime(&value,txid,vout); - if ( value == 0 ) - return(0); + //if ( value == 0 ) + // return(0); if ( txtime == 0 ) txtime = prevtime; if ( (minage= nHeight*3) > 6000 ) From d354a959cdba222a738be1f110608171d66da397 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 22:15:42 +0300 Subject: [PATCH 151/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 23d95ff0b..5e792a707 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -673,8 +673,6 @@ uint64_t komodo_commission(const CBlock &block) uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime) { CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - if ( nHeight < 30 ) - return(blocktime); txtime = komodo_txtime(&value,txid,vout); //if ( value == 0 ) // return(0); @@ -713,6 +711,8 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); fprintf(stderr," iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f/%llu\n",iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(long long)supply); } + if ( nHeight < 30 ) + return(blocktime); return(blocktime * winner); } From c4cd1663968c3399fead6a6bb6656e7f98ff2438 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 22:19:21 +0300 Subject: [PATCH 152/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5e792a707..02aacbe86 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -685,7 +685,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); coinage = (((value * diff) / supply) * diff); - hashval = arith_uint256(supply) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; else @@ -694,7 +694,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { diff = (iter + blocktime - txtime); coinage = (((value * diff) / supply) * diff); - hashval = arith_uint256(supply) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; From 28d89a8620fbcb6bc2f15bd263f74e992ab4b6b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 22:22:12 +0300 Subject: [PATCH 153/202] Test --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f7d9af114..0495d12c8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -568,9 +568,10 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n) #endif hashBlock, true)) { + fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } - //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); + fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); if ( n < tx.vout.size() ) *valuep = tx.vout[n].nValue; return(tx.nLockTime); From e6eb32402005a0de39d16dcd20652a44ac90472b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 22:27:24 +0300 Subject: [PATCH 154/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ca3fde8d0..54a9350b6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4504,7 +4504,7 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint *txtimep = (uint32_t)out.tx->nLockTime; } } - //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); + fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); } } if ( earliest != 0 ) From fd331cdc33b951640c78b5a84353a0b5d0fd9a75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 22:30:25 +0300 Subject: [PATCH 155/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 02aacbe86..2a2f1f190 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -711,7 +711,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); fprintf(stderr," iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f/%llu\n",iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(long long)supply); } - if ( nHeight < 30 ) + if ( nHeight < 2 ) return(blocktime); return(blocktime * winner); } @@ -796,7 +796,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); - if ( height >= 30 && (eligible == 0 || eligible > block.nTime) ) + if ( height >= 2 && (eligible == 0 || eligible > block.nTime) ) { fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); return(-1); From 9dd28ae0a3866ef149ea036c8f21f968c003abb0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 22:41:04 +0300 Subject: [PATCH 156/202] Test --- src/komodo_gateway.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2a2f1f190..acd0efed7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -786,7 +786,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } else { - if ( ASSETCHAINS_STAKED != 0 ) + if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) { arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *previndex; uint32_t eligible; if ( prevtime == 0 ) @@ -795,8 +795,10 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim prevtime = (uint32_t)previndex->nTime; } bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); - if ( height >= 2 && (eligible == 0 || eligible > block.nTime) ) + if ( txn_count == 1 ) + eligible = komodo_stake(bnTarget,height,block.vtx[0].vout[0].hash,0,block.nTime,prevtime); + else eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); + if ( eligible == 0 || eligible > block.nTime ) { fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); return(-1); From 34f8b3543763bceaf8b21dcd2fdb3b8ccac0faf4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 22:44:23 +0300 Subject: [PATCH 157/202] Test --- src/komodo_gateway.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index acd0efed7..25d494043 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -786,7 +786,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } else { - if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) + if ( ASSETCHAINS_STAKED != 0 && height >= 2 && txn_count > 1 ) { arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *previndex; uint32_t eligible; if ( prevtime == 0 ) @@ -795,9 +795,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim prevtime = (uint32_t)previndex->nTime; } bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - if ( txn_count == 1 ) - eligible = komodo_stake(bnTarget,height,block.vtx[0].vout[0].hash,0,block.nTime,prevtime); - else eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); + eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); if ( eligible == 0 || eligible > block.nTime ) { fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); From 37af9d4af9a2adf404cc0fb0e6bd77245faeb5d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 22:48:28 +0300 Subject: [PATCH 158/202] Test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 25d494043..60281aabb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -674,6 +674,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout); + fprintf(stderr,"%s/v%d %.8f txtime.%u\n",txid.ToString().c_str(),vout,dstr(value),txtime); //if ( value == 0 ) // return(0); if ( txtime == 0 ) From a030053610246158540e5c8476fd8ba8adf5811d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 22:55:21 +0300 Subject: [PATCH 159/202] Test --- src/miner.cpp | 2 +- src/wallet/rpcwallet.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 69a7d240c..4817da0ba 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -415,7 +415,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblocktemplate->vTxSigOps.push_back(numsigs); nFees += txfees; pblock->nTime = blocktime; - } + } else fprintf(stderr,"no utxos eligible for staking\n"); } // Create coinbase tx diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 54a9350b6..71c2025ed 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4487,9 +4487,9 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint } entry.push_back(Pair("amount",ValueFromAmount(nValue)));*/ BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *tipindex,*pindex = it->second; + CBlockIndex *tipindex; uint64_t interest; uint32_t locktime; int32_t txheight; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( (tipindex= chainActive.Tip()) != 0 ) { eligible = komodo_stake(bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); if ( eligible > 0 ) @@ -4504,7 +4504,7 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint *txtimep = (uint32_t)out.tx->nLockTime; } } - fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d pindexht.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight,pindex->nHeight); + fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight); } } if ( earliest != 0 ) From d10b3e3c62b21601e7eccbb4ffb2f6ccdc5b6ad7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 23:01:54 +0300 Subject: [PATCH 160/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 60281aabb..474184e5c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -686,7 +686,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); coinage = (((value * diff) / supply) * diff); - hashval = (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(supply) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; else @@ -695,7 +695,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { diff = (iter + blocktime - txtime); coinage = (((value * diff) / supply) * diff); - hashval = (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(supply) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; From d231a6a77519acb836cfbd6eda74601791022a7c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 23:17:34 +0300 Subject: [PATCH 161/202] Test --- src/komodo_gateway.h | 6 +++--- src/miner.cpp | 12 ++++++------ src/wallet/rpcwallet.cpp | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 474184e5c..292302a55 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -674,9 +674,9 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout); - fprintf(stderr,"%s/v%d %.8f txtime.%u\n",txid.ToString().c_str(),vout,dstr(value),txtime); - //if ( value == 0 ) - // return(0); + //fprintf(stderr,"%s/v%d %.8f txtime.%u\n",txid.ToString().c_str(),vout,dstr(value),txtime); + if ( value == 0 ) + return(0); if ( txtime == 0 ) txtime = prevtime; if ( (minage= nHeight*3) > 6000 ) diff --git a/src/miner.cpp b/src/miner.cpp index 4817da0ba..2b658d5ee 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -120,7 +120,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); uint64_t komodo_commission(const CBlock &block); -int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); +int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { @@ -391,10 +391,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) { uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; - if ( (siglen= komodo_staked(pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) + CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); + if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { - CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); CAmount txfees = 0; + /*CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); txStaked.vin.resize(1); txStaked.vout.resize(1); for (i=0; i<32; i++) @@ -407,12 +408,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ptr[i] = utxosig[i]; txStaked.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; txStaked.vout[0].nValue = utxovalue - txfees; - txStaked.nLockTime = blocktime; + txStaked.nLockTime = blocktime;*/ pblock->vtx.push_back(txStaked); - numsigs = GetLegacySigOpCount(txStaked); pblocktemplate->vTxFees.push_back(txfees); - pblocktemplate->vTxSigOps.push_back(numsigs); + pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; } else fprintf(stderr,"no utxos eligible for staking\n"); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 71c2025ed..5a56a16f4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4441,7 +4441,7 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime); -int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) +int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); @@ -4504,7 +4504,7 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint *txtimep = (uint32_t)out.tx->nLockTime; } } - fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight); + //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight); } } if ( earliest != 0 ) @@ -4512,7 +4512,6 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); const CKeyStore& keystore = *pwalletMain; - CMutableTransaction txNew = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); txNew.vin.resize(1); txNew.vout.resize(1); txfee = 0; @@ -4529,6 +4528,7 @@ int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint fprintf(stderr,"failed to create signature\n"); else { + UpdateTransaction(txNew,0,sigdata); ptr = (uint8_t *)sigdata.scriptSig.data(); siglen = sigdata.scriptSig.size(); for (i=0; i Date: Mon, 9 Apr 2018 23:27:19 +0300 Subject: [PATCH 162/202] Test --- src/komodo_bitcoind.h | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0495d12c8..ca9157adc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -571,7 +571,7 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n) fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } - fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); + //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); if ( n < tx.vout.size() ) *valuep = tx.vout[n].nValue; return(tx.nLockTime); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5a56a16f4..0a9524d88 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4502,9 +4502,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u txheight.%d\n",earliest,(int32_t)(earliest- *blocktimep)CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,locktime,txheight); } } - //fprintf(stderr,"(%s) %s/v%d nValue %.8f locktime.%u txheight.%d\n",CBitcoinAddress(address).ToString().c_str(),out.tx->GetHash().GetHex().c_str(),out.i,(double)nValue/COIN,locktime,txheight); } } if ( earliest != 0 ) From 3f26119e04eed251f79e2099d62df24a67921248 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 23:29:03 +0300 Subject: [PATCH 163/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0a9524d88..637edbbd8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4502,7 +4502,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u txheight.%d\n",earliest,(int32_t)(earliest- *blocktimep)CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,locktime,txheight); + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u txheight.%d\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,locktime,txheight); } } } From 09cde8ab10f7866f8d262abf811344f1ba16d77a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 23:34:24 +0300 Subject: [PATCH 164/202] Test --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 637edbbd8..98e2cd0f6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4521,7 +4521,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt txNew.vin[0].prevout.n = *utxovoutp; txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; txNew.vout[0].nValue = *utxovaluep - txfee; - txNew.nLockTime = *blocktimep; + txNew.nLockTime = earliest; CTransaction txNewConst(txNew); signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); if (!signSuccess) @@ -4534,8 +4534,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt for (i=0; i Date: Mon, 9 Apr 2018 23:45:45 +0300 Subject: [PATCH 165/202] Test --- src/komodo_gateway.h | 4 ++-- src/miner.cpp | 26 +++++++++++--------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 292302a55..34f1b0161 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -686,7 +686,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ hash = pindex->GetBlockHash(); // hash pubkey diff = (blocktime - txtime); coinage = (((value * diff) / supply) * diff); - hashval = arith_uint256(supply) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) winner = 1; else @@ -695,7 +695,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { diff = (iter + blocktime - txtime); coinage = (((value * diff) / supply) * diff); - hashval = arith_uint256(supply) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; diff --git a/src/miner.cpp b/src/miner.cpp index 2b658d5ee..67e8e9cb3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -395,26 +395,22 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - /*CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); - txStaked.vin.resize(1); - txStaked.vout.resize(1); - for (i=0; i<32; i++) - ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i]; - txStaked.vin[0].prevout.hash = revtxid; - txStaked.vin[0].prevout.n = utxovout; - txStaked.vin[0].scriptSig.resize(siglen); - ptr = (uint8_t *)txStaked.vin[0].scriptSig.data(); - for (i=0; ivtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; + if ( GetAdjustedTime()+30 < pblock->nTime ) + { + printf("need to wait %d seconds to submit: ",(int32_t)(pblock->nTime - GetAdjustedTime())); + while ( GetAdjustedTime()+30 < pblock->nTime ) + { + sleep(1); + fprintf(stderr,"%d ",pblock->nTime - GetAdjustedTime()); + } + fprintf(stderr,"finished waiting\n"); + } + } else fprintf(stderr,"no utxos eligible for staking\n"); } From 1599d4c8efc1a917cdb935dcfd27cfec16046265 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 23:48:34 +0300 Subject: [PATCH 166/202] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 67e8e9cb3..edbc3ae24 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -406,7 +406,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) while ( GetAdjustedTime()+30 < pblock->nTime ) { sleep(1); - fprintf(stderr,"%d ",pblock->nTime - GetAdjustedTime()); + fprintf(stderr,"%d ",(int32_t)(pblock->nTime - GetAdjustedTime())); } fprintf(stderr,"finished waiting\n"); } From 9465da966b7c9102daca7a75ee763b7b2287bc24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Apr 2018 23:59:13 +0300 Subject: [PATCH 167/202] Test --- src/komodo_gateway.h | 15 +++++++++------ src/miner.cpp | 11 ++++++----- src/wallet/rpcwallet.cpp | 5 ++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 34f1b0161..56165d598 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -705,12 +705,15 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); } - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f/%llu\n",iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(long long)supply); + if ( 0 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f/%llu\n",iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(long long)supply); + } } if ( nHeight < 2 ) return(blocktime); diff --git a/src/miner.cpp b/src/miner.cpp index edbc3ae24..853cda770 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -402,13 +402,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nTime = blocktime; if ( GetAdjustedTime()+30 < pblock->nTime ) { - printf("need to wait %d seconds to submit: ",(int32_t)(pblock->nTime - GetAdjustedTime())); - while ( GetAdjustedTime()+30 < pblock->nTime ) + //printf("need to wait %d seconds to submit: ",(int32_t)(pblock->nTime - GetAdjustedTime())); + /*while ( GetAdjustedTime()+30 < pblock->nTime ) { - sleep(1); + sleep(30); fprintf(stderr,"%d ",(int32_t)(pblock->nTime - GetAdjustedTime())); - } - fprintf(stderr,"finished waiting\n"); + }*/ + //fprintf(stderr,"finished waiting\n"); + sleep(30); } } else fprintf(stderr,"no utxos eligible for staking\n"); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 98e2cd0f6..9169f1079 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4486,9 +4486,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } entry.push_back(Pair("amount",ValueFromAmount(nValue)));*/ - BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); + //BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex; - uint64_t interest; uint32_t locktime; int32_t txheight; if ( (tipindex= chainActive.Tip()) != 0 ) { eligible = komodo_stake(bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); @@ -4502,7 +4501,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u txheight.%d\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,locktime,txheight); + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } } From 8d584a9c9142ca7ddc3c927ef3e4dc9a6684c052 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 00:09:41 +0300 Subject: [PATCH 168/202] Test --- src/komodo_bitcoind.h | 10 +++++++--- src/komodo_gateway.h | 10 +++++----- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ca9157adc..0f44119cb 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -557,11 +557,11 @@ uint64_t komodo_seed(int32_t height) return(seed); } -uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n) +uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *address) { - CTransaction tx; - uint256 hashBlock; + CTxDestination address; CTransaction tx; uint256 hashBlock; *valuep = 0; + address[0] = 0; if (!GetTransaction(hash, tx, #ifndef KOMODO_ZCASH Params().GetConsensus(), @@ -573,7 +573,11 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n) } //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); if ( n < tx.vout.size() ) + { *valuep = tx.vout[n].nValue; + if (ExtractDestination(tx.scriptPubKey, address)) + strcpy(address,CBitcoinAddress(address).ToString().c_str()); + } return(tx.nLockTime); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 56165d598..fba23a4bc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -670,11 +670,11 @@ uint64_t komodo_commission(const CBlock &block) return((total * ASSETCHAINS_COMMISSION) / COIN); } -uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime) +uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - txtime = komodo_txtime(&value,txid,vout); - //fprintf(stderr,"%s/v%d %.8f txtime.%u\n",txid.ToString().c_str(),vout,dstr(value),txtime); + CBlockIndex *pindex; char address[64]; arith_uint256 hashval; uint256 hash; int32_t minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + txtime = komodo_txtime(&value,txid,vout,address); + fprintf(stderr,"(%s) vs. (%s) %s/v%d %.8f txtime.%u\n",address,destaddr,txid.ToString().c_str(),vout,dstr(value),txtime); if ( value == 0 ) return(0); if ( txtime == 0 ) @@ -799,7 +799,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim prevtime = (uint32_t)previndex->nTime; } bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime); + eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime,""); if ( eligible == 0 || eligible > block.nTime ) { fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9169f1079..3dcd63951 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4490,7 +4490,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt CBlockIndex *tipindex; if ( (tipindex= chainActive.Tip()) != 0 ) { - eligible = komodo_stake(bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime); + eligible = komodo_stake(bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime,CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) From af79cd4cfc468aafb20ae792897720c487d815fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 00:14:42 +0300 Subject: [PATCH 169/202] Test --- src/komodo_gateway.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index fba23a4bc..839e96304 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,9 +672,8 @@ uint64_t komodo_commission(const CBlock &block) uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; char address[64]; arith_uint256 hashval; uint256 hash; int32_t minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; uint8_t hashbuf[128]; char address[64]; arith_uint256 hashval; uint256 hash,addrhash,pasthash; int32_t minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); - fprintf(stderr,"(%s) vs. (%s) %s/v%d %.8f txtime.%u\n",address,destaddr,txid.ToString().c_str(),vout,dstr(value),txtime); if ( value == 0 ) return(0); if ( txtime == 0 ) @@ -683,7 +682,10 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ minage = 6000; if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) { - hash = pindex->GetBlockHash(); // hash pubkey + vcalc_sha256(0,(uint8_t *)&addrhash,(int32_t)strlen(address)); + pasthash = pindex->GetBlockHash(); + hash = (pasthash ^ addrhash); + fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); diff = (blocktime - txtime); coinage = (((value * diff) / supply) * diff); hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); @@ -799,7 +801,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim prevtime = (uint32_t)previndex->nTime; } bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime,""); + eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > block.nTime ) { fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); From 4da475be2fff2c2302f872fdc2da2a26e09b3078 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 00:18:22 +0300 Subject: [PATCH 170/202] Test --- src/komodo_gateway.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 839e96304..dd7e041de 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -682,9 +682,11 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ minage = 6000; if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) { - vcalc_sha256(0,(uint8_t *)&addrhash,(int32_t)strlen(address)); + vcalc_sha256(0,(uint8_t *)&addrhash,address,(int32_t)strlen(address)); pasthash = pindex->GetBlockHash(); - hash = (pasthash ^ addrhash); + memcpy(hashbuf,&pasthash,sizeof(pasthash)); + memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash)); + vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); diff = (blocktime - txtime); coinage = (((value * diff) / supply) * diff); From fa4d9e24afe2d1e43953156a54187a9ccfa6e10e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 00:26:00 +0300 Subject: [PATCH 171/202] Test --- src/komodo_bitcoind.h | 7 +++---- src/komodo_gateway.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0f44119cb..6ffa4022c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -557,11 +557,10 @@ uint64_t komodo_seed(int32_t height) return(seed); } -uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *address) +uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) { CTxDestination address; CTransaction tx; uint256 hashBlock; *valuep = 0; - address[0] = 0; if (!GetTransaction(hash, tx, #ifndef KOMODO_ZCASH Params().GetConsensus(), @@ -575,8 +574,8 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *address) if ( n < tx.vout.size() ) { *valuep = tx.vout[n].nValue; - if (ExtractDestination(tx.scriptPubKey, address)) - strcpy(address,CBitcoinAddress(address).ToString().c_str()); + if (ExtractDestination(tx.vout[n].scriptPubKey, address)) + strcpy(destaddr,CBitcoinAddress(address).ToString().c_str()); } return(tx.nLockTime); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dd7e041de..e77e8bcb3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -682,7 +682,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ minage = 6000; if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) { - vcalc_sha256(0,(uint8_t *)&addrhash,address,(int32_t)strlen(address)); + vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); pasthash = pindex->GetBlockHash(); memcpy(hashbuf,&pasthash,sizeof(pasthash)); memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash)); From 1a2b98fab06458bd858444e1cdaae7d330c11186 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 00:28:19 +0300 Subject: [PATCH 172/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3dcd63951..8f9234c1b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4439,7 +4439,7 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp) #include "script/sign.h" int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; -uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime); +uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr); int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { From e07cf6b5f9330a2801b1002d425afcda770f6060 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 00:28:51 +0300 Subject: [PATCH 173/202] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8f9234c1b..ed318819a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4490,7 +4490,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt CBlockIndex *tipindex; if ( (tipindex= chainActive.Tip()) != 0 ) { - eligible = komodo_stake(bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime,CBitcoinAddress(address).ToString().c_str()); + eligible = komodo_stake(bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) From 2e90eb0c2a0fa1788bcc218765bf645215f3e132 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 00:37:13 +0300 Subject: [PATCH 174/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e77e8bcb3..7b417c040 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -687,7 +687,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ memcpy(hashbuf,&pasthash,sizeof(pasthash)); memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash)); vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); - fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); + //fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); diff = (blocktime - txtime); coinage = (((value * diff) / supply) * diff); hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); @@ -709,7 +709,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); } - if ( 0 ) + if ( 1 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 22439b80345a3dfff11ddb3b0705e687cc2069ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 00:43:42 +0300 Subject: [PATCH 175/202] Test --- src/komodo_gateway.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7b417c040..c4bbcd92a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -672,7 +672,7 @@ uint64_t komodo_commission(const CBlock &block) uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; uint8_t hashbuf[128]; char address[64]; arith_uint256 hashval; uint256 hash,addrhash,pasthash; int32_t minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t diff,value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); if ( value == 0 ) return(0); @@ -683,6 +683,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) { vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + segid = ((nHeight + addrhash.uints[0]) & 0x3f); pasthash = pindex->GetBlockHash(); memcpy(hashbuf,&pasthash,sizeof(pasthash)); memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash)); @@ -704,6 +705,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ { winner = 1; blocktime += iter; + blocktime += segid; break; } } @@ -716,7 +718,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f/%llu\n",iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(long long)supply); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f/%llu\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(long long)supply); } } if ( nHeight < 2 ) From 1dd815ba0bcf7e7dca15381d950d3628ba716c68 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 00:49:11 +0300 Subject: [PATCH 176/202] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c4bbcd92a..c90e1dd80 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -711,7 +711,7 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); } - if ( 1 ) + if ( 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 8b6faa2e8438e1fec3cfd282917737870c7bafb6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 01:09:27 +0300 Subject: [PATCH 177/202] Test --- src/pow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 23f1cf67b..93ef9ab11 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -142,9 +142,10 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in height = komodo_currentheight() + 1; special = komodo_chosennotary(¬aryid,height,pubkey33,timestamp); flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height); - if ( ASSETCHAINS_STAKED != 0 ) + /*if ( ASSETCHAINS_STAKED != 0 ) bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - else if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary + else*/ + if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary { for (i=0; i<33; i++) { From 5bb3d0fe9f55683827d7ed9bbc0acdb117a7bf38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 01:19:49 +0300 Subject: [PATCH 178/202] Test --- src/main.cpp | 2 +- src/miner.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4639814de..fc5d4873c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3579,7 +3579,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat if ( komodo_check_deposit(ASSETCHAINS_SYMBOL[0] == 0 ? height : pindex != 0 ? (int32_t)pindex->nHeight : chainActive.Tip()->nHeight+1,block,pindex==0||pindex->pprev==0?0:pindex->pprev->nTime) < 0 ) { static uint32_t counter; - if ( counter++ < 100 ) + if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) fprintf(stderr,"check deposit rejection\n"); return(false); } diff --git a/src/miner.cpp b/src/miner.cpp index 853cda770..d249dcce1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -487,7 +487,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) { static uint32_t counter; - if ( counter++ < 100 ) + if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) fprintf(stderr,"warning: testblockvalidity failed\n"); return(0); } @@ -762,7 +762,7 @@ void static BitcoinMiner() if ( ptr == 0 ) { static uint32_t counter; - if ( counter++ < 100 ) + if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) fprintf(stderr,"created illegal block, retry\n"); continue; } From 4786d20c0b2f813c5a209817469cdcf3bc514bcc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 16:40:59 +0300 Subject: [PATCH 179/202] PoW targeting in -ac_staking=perc mode --- src/komodo_gateway.h | 105 ++++++++++++++++++++++++++++++++++++++----- src/komodo_utils.h | 5 ++- src/main.cpp | 2 +- 3 files changed, 98 insertions(+), 14 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c90e1dd80..94a68fb4b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -726,6 +726,66 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ return(blocktime * winner); } +#define KOMODO_POWMINMULT 16 +arith_uint256 komodo_PoWtarget(int32_t *PoSpercp,arith_uint256 target,int32_t height,int32_t goalperc) +{ + CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,i,diff; + *percPoSp = percPoS = 0; + sum = arith_uint256(0); + ave = sum; + for (i=n=0; i<100; i++) + { + ht = height - 100 + i; + if ( (pindex= komodo_chainactive(ht)) != 0 ) + { + bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); + bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); + hashval = UintToArith256(pindex->GetBlockHash()); + if ( hashval <= bnTarget ) // PoW is never as easy as PoS/64, some PoS will be counted as PoW + { + sum += hashval; + n++; + } else percPoS++; + } + } + *percPoSp = percPoS; + target = (target / arith_uint256(KOMODO_POWMINMULT)); + if ( n > 0 ) + { + ave = (sum / arith_uint256(n)); + if ( ave > target ) + ave = target; + } else return(target); + if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget + { + bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); + fprintf(stderr," increase diff -> ") + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," floor diff ") + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&target)[i]); + fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); + } + else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget + { + bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); + fprintf(stderr," decrease diff -> ") + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," floor diff ") + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&target)[i]); + fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); + } + else bnTarget = ave; // recent ave is perfect + return(bnTarget); +} + int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing { static uint256 array[64]; static int32_t numbanned,indallvouts; @@ -796,20 +856,43 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } else { - if ( ASSETCHAINS_STAKED != 0 && height >= 2 && txn_count > 1 ) + if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) { - arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *previndex; uint32_t eligible; - if ( prevtime == 0 ) - { - if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 ) - prevtime = (uint32_t)previndex->nTime; - } + arith_uint256 bnTarget,hashval; int32_t PoSperc; bool fNegative,fOverflow; CBlockIndex *previndex; uint32_t eligible,isPoS = 0; bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime,(char *)""); - if ( eligible == 0 || eligible > block.nTime ) + if ( txn_count > 1 ) { - fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); - return(-1); + if ( prevtime == 0 ) + { + if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 ) + prevtime = (uint32_t)previndex->nTime; + } + eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime,(char *)""); + if ( eligible == 0 || eligible > block.nTime ) + { + fprintf(stderr,"PoS failute ht.%d eligible.%u vs blocktime.%u, lag.%d\n",height,eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); + } else isPoS = 1; + } + if ( isPoS == 0 && height > 100 ) + { + if ( ASSETCHAINS_STAKED == 100 ) + { + fprintf(stderr,"ht.%d 100% PoS after height 100 rule violated for -ac_staking=100\n",height); + return(-1); + } + // check PoW + bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); + hashval = UintToArith256(block.GetBlockHash()); + if ( hashval > bnTarget ) + { + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," > "); + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," ht.%d PoW diff violation PoSperc.%d vs goalperc.%d\n",height,PoSperc,(int32_t)ASSETCHAINS_STAKED); + return(-1); + } } } if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c38df1411..3059ebf64 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1542,7 +1542,8 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY = GetArg("-ac_decay",0); ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); - ASSETCHAINS_STAKED = GetArg("-ac_staked",0); + if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) + ASSETCHAINS_STAKED = 100; if ( ASSETCHAINS_HALVING != 0 && ASSETCHAINS_HALVING < 1440 ) { ASSETCHAINS_HALVING = 1440; @@ -1574,7 +1575,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY); - val = ASSETCHAINS_COMMISSION | ((ASSETCHAINS_STAKED & 0xffff) << 32); + val = ASSETCHAINS_COMMISSION | ((ASSETCHAINS_STAKED & 0xff) << 32); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); } addn = GetArg("-seednode",""); diff --git a/src/main.cpp b/src/main.cpp index fc5d4873c..94c536c2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3626,7 +3626,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta // Don't accept any forks from the main chain prior to last checkpoint CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; - if (pcheckpoint && (nHeight < pcheckpoint->nHeight || nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1) ) + if (pcheckpoint && nHeight > 1 && nHeight < pcheckpoint->nHeight ) return state.DoS(100, error("%s: forked chain older than last checkpoint (height %d) vs %d", __func__, nHeight,pcheckpoint->nHeight)); else if ( komodo_checkpoint(¬arized_height,nHeight,hash) < 0 ) { From 2d9c76280a19f9c2d1a673a48614ecd3706763ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 16:49:15 +0300 Subject: [PATCH 180/202] Test --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 94a68fb4b..a87c1deb8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -727,9 +727,9 @@ uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_ } #define KOMODO_POWMINMULT 16 -arith_uint256 komodo_PoWtarget(int32_t *PoSpercp,arith_uint256 target,int32_t height,int32_t goalperc) +arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { - CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,i,diff; + CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff; *percPoSp = percPoS = 0; sum = arith_uint256(0); ave = sum; @@ -877,12 +877,12 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( ASSETCHAINS_STAKED == 100 ) { - fprintf(stderr,"ht.%d 100% PoS after height 100 rule violated for -ac_staking=100\n",height); + fprintf(stderr,"ht.%d 100%% PoS after height 100 rule violated for -ac_staking=100\n",height); return(-1); } // check PoW bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - hashval = UintToArith256(block.GetBlockHash()); + hashval = UintToArith256(block.GetHash()); if ( hashval > bnTarget ) { for (i=31; i>=0; i--) From 8706c053521e8ffcdacbdd26afae674c3e4cd124 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 16:50:39 +0300 Subject: [PATCH 181/202] Test --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a87c1deb8..89e4b6080 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -761,10 +761,10 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); - fprintf(stderr," increase diff -> ") + fprintf(stderr," increase diff -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," floor diff ") + fprintf(stderr," floor diff "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&target)[i]); fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); @@ -774,10 +774,10 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); - fprintf(stderr," decrease diff -> ") + fprintf(stderr," decrease diff -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," floor diff ") + fprintf(stderr," floor diff "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&target)[i]); fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); From deba7f205242c6b980df9bea40bd9e0389bcfdd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 17:05:51 +0300 Subject: [PATCH 182/202] Mine PoW for ac_staking --- src/miner.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index d249dcce1..e29ec3e08 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -855,6 +855,14 @@ void static BitcoinMiner() } //else fprintf(stderr,"duplicate at j.%d\n",j); } else Mining_start = 0; } else Mining_start = 0; + if ( ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] == 0 ) + { + int32_t percPoS,z; + haskTarget = komodo_PoWtarget(&percPoS,haskTarget,pblock->nHeight,ASSETCHAINS_STAKED); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + fprintf(stderr," PoW for staked coin\n"); + } while (true) { /*if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) // skips when it shouldnt @@ -914,9 +922,12 @@ void static BitcoinMiner() } else { - printf("need to wait %d seconds to submit\n",(int32_t)(pblock->nTime - GetAdjustedTime())); - while ( GetAdjustedTime() < pblock->nTime ) - sleep(1); + if ( NOTARY_PUBKEY33[0] != 0 ) + { + printf("need to wait %d seconds to submit\n",(int32_t)(pblock->nTime - GetAdjustedTime())); + while ( GetAdjustedTime() < pblock->nTime ) + sleep(1); + } } KOMODO_CHOSEN_ONE = 1; // Found a solution From a8e51a65048be2b04c9e9831066d4fe1d502f778 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 17:09:15 +0300 Subject: [PATCH 183/202] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index e29ec3e08..e4991515e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -858,7 +858,7 @@ void static BitcoinMiner() if ( ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] == 0 ) { int32_t percPoS,z; - haskTarget = komodo_PoWtarget(&percPoS,haskTarget,pblock->nHeight,ASSETCHAINS_STAKED); + hashTarget = komodo_PoWtarget(&percPoS,haskTarget,Mining_height,ASSETCHAINS_STAKED); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); fprintf(stderr," PoW for staked coin\n"); From 898a4b9b6847ba4d52820de6e51eb7ce6a9898e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 17:09:50 +0300 Subject: [PATCH 184/202] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index e4991515e..78dcbea9d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -858,7 +858,7 @@ void static BitcoinMiner() if ( ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] == 0 ) { int32_t percPoS,z; - hashTarget = komodo_PoWtarget(&percPoS,haskTarget,Mining_height,ASSETCHAINS_STAKED); + hashTarget = komodo_PoWtarget(&percPoS,hashTarget,Mining_height,ASSETCHAINS_STAKED); for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); fprintf(stderr," PoW for staked coin\n"); From 13691369bf9993e120183ad0dd561ef2a2f0c8f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 17:10:41 +0300 Subject: [PATCH 185/202] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 78dcbea9d..b02a62513 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -654,6 +654,7 @@ static bool ProcessBlockFound(CBlock* pblock) int32_t komodo_baseid(char *origbase); int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height); +arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc); int32_t FOUND_BLOCK,KOMODO_MAYBEMINED; extern int32_t KOMODO_LASTMINED; int32_t roundrobin_delay; From 7dbeae5dc35def1354d346c688757074a7c73984 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 17:21:31 +0300 Subject: [PATCH 186/202] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index b02a62513..27ac64234 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -387,7 +387,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); pblock->nTime = blocktime; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); - LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); + //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) { uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; From 0d8ffadc4a924f25d40ce7ffb99e362cee170ef6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 17:29:21 +0300 Subject: [PATCH 187/202] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 27ac64234..17ab7353e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1053,7 +1053,7 @@ void static BitcoinMiner() // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; - if ( ASSETCHAINS_STAKED == 0 ) + if ( ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 ) UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) { From 4972b74b60027f75534811b6e63bf027171a15e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 17:49:11 +0300 Subject: [PATCH 188/202] Test --- src/komodo_gateway.h | 42 ++++++++++++++++++++++++------------------ src/miner.cpp | 6 +++--- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 89e4b6080..1363a6c84 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -759,28 +759,34 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); - fprintf(stderr," increase diff -> "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," floor diff "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&target)[i]); - fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); + if ( 0 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); + fprintf(stderr," increase diff -> "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," floor diff "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&target)[i]); + fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); + } } else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget { bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); - fprintf(stderr," decrease diff -> "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," floor diff "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&target)[i]); - fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); + if ( 0 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); + fprintf(stderr," decrease diff -> "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," floor diff "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&target)[i]); + fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); + } } else bnTarget = ave; // recent ave is perfect return(bnTarget); diff --git a/src/miner.cpp b/src/miner.cpp index 17ab7353e..79cd2588e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -100,7 +100,7 @@ public: void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { - pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->nTime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); } #include "komodo_defs.h" @@ -902,8 +902,8 @@ void static BitcoinMiner() solutionTargetChecks.increment(); if ( UintToArith256(pblock->GetHash()) > hashTarget ) { - //if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) - // fprintf(stderr," missed target\n"); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + fprintf(stderr," missed target\n"); return false; } if ( ASSETCHAINS_STAKED == 0 ) From 68d0354d9de9c556cbce49ff9270462c37eba6b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 17:58:38 +0300 Subject: [PATCH 189/202] Test --- src/miner.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 79cd2588e..21e0a8fdd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -929,6 +929,15 @@ void static BitcoinMiner() while ( GetAdjustedTime() < pblock->nTime ) sleep(1); } + else + { + CValidationState state; + if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + { + fprintf(stderr,"Invalid block mined, try again\n"); + return(false); + } + } } KOMODO_CHOSEN_ONE = 1; // Found a solution From 25d977f73d321acf9c1d3909ed36b2fcf1741c21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 17:58:56 +0300 Subject: [PATCH 190/202] Test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 21e0a8fdd..1a0a5c6f7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -902,8 +902,8 @@ void static BitcoinMiner() solutionTargetChecks.increment(); if ( UintToArith256(pblock->GetHash()) > hashTarget ) { - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - fprintf(stderr," missed target\n"); + //if ( ASSETCHAINS_SYMBOL[0] != 0 ) + // fprintf(stderr," missed target\n"); return false; } if ( ASSETCHAINS_STAKED == 0 ) From 14bbc7eb1d4bc42352e7a89b0ebaffd70837f7f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 18:01:04 +0300 Subject: [PATCH 191/202] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 1a0a5c6f7..9fbe1adb0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -932,7 +932,7 @@ void static BitcoinMiner() else { CValidationState state; - if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), false, false)) { fprintf(stderr,"Invalid block mined, try again\n"); return(false); From b1e74295fd6f3ee91dfeb4eb713374051f5d80d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 18:19:27 +0300 Subject: [PATCH 192/202] Test --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 94c536c2f..1aafc6c26 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3576,7 +3576,8 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat if (nSigOps > MAX_BLOCK_SIGOPS) return state.DoS(100, error("CheckBlock(): out-of-bounds SigOpCount"), REJECT_INVALID, "bad-blk-sigops", true); - if ( komodo_check_deposit(ASSETCHAINS_SYMBOL[0] == 0 ? height : pindex != 0 ? (int32_t)pindex->nHeight : chainActive.Tip()->nHeight+1,block,pindex==0||pindex->pprev==0?0:pindex->pprev->nTime) < 0 ) + if ( komodo_check_deposit(height,block,(pindex==0||pindex->pprev==0)?0:pindex->pprev->nTime) < 0 ) + //if ( komodo_check_deposit(ASSETCHAINS_SYMBOL[0] == 0 ? height : pindex != 0 ? (int32_t)pindex->nHeight : chainActive.Tip()->nHeight+1,block,pindex==0||pindex->pprev==0?0:pindex->pprev->nTime) < 0 ) { static uint32_t counter; if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) From 294925c70ab56c5d52d09889f3ea131d5f348a74 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 18:22:32 +0300 Subject: [PATCH 193/202] Test --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 1aafc6c26..2895e888e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4534,6 +4534,8 @@ bool InitBlockIndex() { if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) return error("LoadBlockIndex(): writing genesis block to disk failed"); CBlockIndex *pindex = AddToBlockIndex(block); + if ( pindex == 0 ) + return error("LoadBlockIndex(): couldnt add to block index"); if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) return error("LoadBlockIndex(): genesis block not accepted"); if (!ActivateBestChain(state, &block)) From b7aaca4be3ce163c523911f2a2a11e8f212e9e8d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 19:03:31 +0300 Subject: [PATCH 194/202] Test --- src/miner.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 9fbe1adb0..9e705a40f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -937,6 +937,10 @@ void static BitcoinMiner() fprintf(stderr,"Invalid block mined, try again\n"); return(false); } + arith_uint256 tmp = pblock->GetHash(); + int32_t z; for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); + fprintf(stderr," mined block!\n"); } } KOMODO_CHOSEN_ONE = 1; From e4821a8282527c676f6026e3a58b9b059b59b511 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 19:06:11 +0300 Subject: [PATCH 195/202] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9e705a40f..c444f0423 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -937,7 +937,7 @@ void static BitcoinMiner() fprintf(stderr,"Invalid block mined, try again\n"); return(false); } - arith_uint256 tmp = pblock->GetHash(); + uint256 tmp = pblock->GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); fprintf(stderr," mined block!\n"); From dc60244b09ccbcdaf514133ad5a80e32ae69a2df Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 19:08:25 +0300 Subject: [PATCH 196/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1363a6c84..a5654363d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -891,12 +891,12 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim hashval = UintToArith256(block.GetHash()); if ( hashval > bnTarget ) { - for (i=31; i>=0; i--) + /*for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," > "); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," ht.%d PoW diff violation PoSperc.%d vs goalperc.%d\n",height,PoSperc,(int32_t)ASSETCHAINS_STAKED); + fprintf(stderr," ht.%d PoW diff violation PoSperc.%d vs goalperc.%d\n",height,PoSperc,(int32_t)ASSETCHAINS_STAKED);*/ return(-1); } } From 88287857643acde870e749da79b4a59551327df9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 19:10:18 +0300 Subject: [PATCH 197/202] Test --- src/miner.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c444f0423..d8211a869 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -658,6 +658,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t FOUND_BLOCK,KOMODO_MAYBEMINED; extern int32_t KOMODO_LASTMINED; int32_t roundrobin_delay; +arith_uint256 HASHTarget; #ifdef ENABLE_WALLET void static BitcoinMiner(CWallet *pwallet) @@ -800,7 +801,7 @@ void static BitcoinMiner() // uint8_t pubkeys[66][33]; int mids[256],gpucount,nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); savebits = pblock->nBits; - arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); + HASHTarget = arith_uint256().SetCompact(pblock->nBits); roundrobin_delay = ROUNDROBIN_DELAY; if ( ASSETCHAINS_SYMBOL[0] == 0 && notaryid >= 0 ) { @@ -851,7 +852,7 @@ void static BitcoinMiner() } else fprintf(stderr,"no nonz pubkeys\n"); if ( (Mining_height >= 235300 && Mining_height < 236000) || (j == 65 && Mining_height > KOMODO_MAYBEMINED+1 && Mining_height > KOMODO_LASTMINED+64) ) { - hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); + HASHTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1); } //else fprintf(stderr,"duplicate at j.%d\n",j); } else Mining_start = 0; @@ -859,9 +860,9 @@ void static BitcoinMiner() if ( ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] == 0 ) { int32_t percPoS,z; - hashTarget = komodo_PoWtarget(&percPoS,hashTarget,Mining_height,ASSETCHAINS_STAKED); + HASHTarget = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + fprintf(stderr,"%02x",((uint8_t *)&HASHTarget)[z]); fprintf(stderr," PoW for staked coin\n"); } while (true) @@ -891,16 +892,16 @@ void static BitcoinMiner() //fprintf(stderr,"running solver\n"); std::function)> validBlock = #ifdef ENABLE_WALLET - [&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] + [&pblock, &HASHTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] #else - [&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams] + [&pblock, &HASHTarget, &m_cs, &cancelSolver, &chainparams] #endif (std::vector soln) { // Write the solution to the hash and compute the result. LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); - if ( UintToArith256(pblock->GetHash()) > hashTarget ) + if ( UintToArith256(pblock->GetHash()) > HASHTarget ) { //if ( ASSETCHAINS_SYMBOL[0] != 0 ) // fprintf(stderr," missed target\n"); @@ -934,7 +935,7 @@ void static BitcoinMiner() CValidationState state; if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), false, false)) { - fprintf(stderr,"Invalid block mined, try again\n"); + //fprintf(stderr,"Invalid block mined, try again\n"); return(false); } uint256 tmp = pblock->GetHash(); @@ -947,7 +948,7 @@ void static BitcoinMiner() // Found a solution SetThreadPriority(THREAD_PRIORITY_NORMAL); LogPrintf("KomodoMiner:\n"); - LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), hashTarget.GetHex()); + LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), HASHTarget.GetHex()); #ifdef ENABLE_WALLET if (ProcessBlockFound(pblock, *pwallet, reservekey)) { #else @@ -1071,7 +1072,7 @@ void static BitcoinMiner() if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) { // Changing pblock->nTime can change work required on testnet: - hashTarget.SetCompact(pblock->nBits); + HASHTarget.SetCompact(pblock->nBits); } } } From 7da8410746ded9c6daff43dc22fc7d777240fddc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 19:11:57 +0300 Subject: [PATCH 198/202] Test --- src/miner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index d8211a869..e45b9e59b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -889,12 +889,13 @@ void static BitcoinMiner() crypto_generichash_blake2b_update(&curr_state,pblock->nNonce.begin(),pblock->nNonce.size()); // (x_1, x_2, ...) = A(I, V, n, k) LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString()); + arith_uint256 hashTarget = HASHTarget; //fprintf(stderr,"running solver\n"); std::function)> validBlock = #ifdef ENABLE_WALLET - [&pblock, &HASHTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] + [&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] #else - [&pblock, &HASHTarget, &m_cs, &cancelSolver, &chainparams] + [&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams] #endif (std::vector soln) { // Write the solution to the hash and compute the result. From 053fef7cfd9904cc251c3186f5c21561d6d4c32f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 19:18:32 +0300 Subject: [PATCH 199/202] Test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a5654363d..0ebccabcf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -759,7 +759,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); - if ( 0 ) + if ( 1 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); @@ -775,7 +775,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget { bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); - if ( 0 ) + if ( 1 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); From 49c374d7ad712d50f2d7ff4b2aafc3cc14271908 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 19:34:22 +0300 Subject: [PATCH 200/202] Test --- src/komodo_gateway.h | 2 +- src/miner.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0ebccabcf..b4ff7affd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -876,7 +876,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > block.nTime ) { - fprintf(stderr,"PoS failute ht.%d eligible.%u vs blocktime.%u, lag.%d\n",height,eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); + fprintf(stderr,"PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d\n",height,eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); } else isPoS = 1; } if ( isPoS == 0 && height > 100 ) diff --git a/src/miner.cpp b/src/miner.cpp index e45b9e59b..be2c5a0aa 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -925,6 +925,12 @@ void static BitcoinMiner() } else { + CValidationState state; + if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), false, false)) + { + //fprintf(stderr,"Invalid block mined, try again\n"); + return(false); + } if ( NOTARY_PUBKEY33[0] != 0 ) { printf("need to wait %d seconds to submit\n",(int32_t)(pblock->nTime - GetAdjustedTime())); @@ -933,12 +939,6 @@ void static BitcoinMiner() } else { - CValidationState state; - if ( !TestBlockValidity(state, *pblock, chainActive.Tip(), false, false)) - { - //fprintf(stderr,"Invalid block mined, try again\n"); - return(false); - } uint256 tmp = pblock->GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From 409c28a2e2c43d21ecca6f9687c70581c6eb4590 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 19:46:33 +0300 Subject: [PATCH 201/202] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2895e888e..fb833bff5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -562,7 +562,7 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc CBlockIndex* pindex = (*mi).second; if (pindex != 0 && chain.Contains(pindex)) return pindex; - if (pindex->GetAncestor(chain.Height()) == chain.Tip()) { + if (pindex != 0 && pindex->GetAncestor(chain.Height()) == chain.Tip()) { return chain.Tip(); } } From 007aca381b562e2c2e32ee8dc89cf00efc0c92f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Apr 2018 20:38:12 +0300 Subject: [PATCH 202/202] Test --- src/arith_uint256.cpp | 2 +- src/komodo_gateway.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp index a1865b649..c9074fe91 100644 --- a/src/arith_uint256.cpp +++ b/src/arith_uint256.cpp @@ -111,7 +111,7 @@ int base_uint::CompareTo(const base_uint& b) const { if ( (uint64_t)pn < 0x1000 || (uint64_t)b.pn <= 0x1000 ) { - fprintf(stderr,"CompareTo null %p or %p\n",pn,b.pn); + //fprintf(stderr,"CompareTo null %p or %p\n",pn,b.pn); return(0); } for (int i = WIDTH - 1; i >= 0; i--) { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b4ff7affd..e85252367 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -876,7 +876,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim eligible = komodo_stake(bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > block.nTime ) { - fprintf(stderr,"PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d\n",height,eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); + fprintf(stderr,"PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); } else isPoS = 1; } if ( isPoS == 0 && height > 100 )