From 44b72fe400369a1c57308ab32d98bb5cf409e1c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 16 Nov 2016 08:13:56 -0300 Subject: [PATCH 01/65] test --- src/tinyformat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tinyformat.h b/src/tinyformat.h index a259077f1..e0b5bde76 100644 --- a/src/tinyformat.h +++ b/src/tinyformat.h @@ -821,7 +821,7 @@ inline void formatImpl(std::ostream& out, const char* fmt, // Print remaining part of format string. fmt = printFormatStringLiteral(out, fmt); - if(*fmt != '\0') + if(*fmt != '\0' && 0 ) // disabled due to complaints TINYFORMAT_ERROR("tinyformat: Too many conversion specifiers in format string"); // Restore stream state From 3ec03ada29507551a9763fd8c41558c32463d682 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 12:29:01 -0300 Subject: [PATCH 02/65] test --- src/komodo.h | 12 ++-- src/komodo_events.h | 149 ++++++++++++++++++++++++++++++++++++++++++ src/wallet/wallet.cpp | 19 ++++-- 3 files changed, 171 insertions(+), 9 deletions(-) create mode 100644 src/komodo_events.h diff --git a/src/komodo.h b/src/komodo.h index f308c893b..de3003624 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -17,12 +17,14 @@ #define H_KOMODO_H // Todo: -// 0. optimize assetchains RT loop +// 0. optimize assetchains // 1. error check fiat redeem amounts // 2. net balance limiter // 3. verify: reorgs -// 4. automate notarization fee payouts -// 5. automated distribution of test REVS snapshot + +// non komodod (non-hardfork) todo: +// a. automate notarization fee payouts +// b. automated distribution of test REVS snapshot #include #include @@ -36,6 +38,8 @@ FILE *Minerfp; int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks +#include "komodo_events.h" + #include "komodo_globals.h" #include "komodo_utils.h" @@ -146,7 +150,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } else if ( func == 'D' ) { - //printf("D[%d]\n",ht); + printf("unexpected function D[%d]\n",ht); } //#ifdef KOMODO_PAX else if ( func == 'V' ) diff --git a/src/komodo_events.h b/src/komodo_events.h new file mode 100644 index 000000000..5fa284ef2 --- /dev/null +++ b/src/komodo_events.h @@ -0,0 +1,149 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#ifndef H_KOMODOEVENTS_H +#define H_KOMODOEVENTS_H + +#ifdef WIN32 +#define PACKED +#else +#define PACKED __attribute__((packed)) +#endif + +#define KOMODO_EVENT_PUBKEYS 'P' +#define KOMODO_EVENT_NOTARIZED 'N' +#define KOMODO_EVENT_UTXO 'U' +#define KOMODO_EVENT_KMDHEIGHT 'K' +//#define KOMODO_EVENT_DELETE 'D' +#define KOMODO_EVENT_PRICEFEED 'V' +#define KOMODO_EVENT_OPRETURN 'R' +#define KOMODO_OPRETURN_DEPOSIT 'D' +#define KOMODO_OPRETURN_ISSUE 'I' // assetchain +#define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain +#define KOMODO_OPRETURN_REDEEM 'X' + +struct komodo_event_notarized { bits256 blockhash,desttxid; int32_t notarizedheight; char symbol[16]; } PACKED; +struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; } PACKED; +struct komodo_event_utxo { bits256 txid; uint64_t voutmask; uint8_t numvouts; } PACKED; +struct komodo_event_opreturn { bits256 txid; uint64_t ovalue; uint16_t vout,olen; uint8_t opret[]; } PACKED; +struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; } PACKED; + +struct komodo_event +{ + struct komodo_event *related; + uint16_t len; + int32_t height; + uint8_t type,reorged; + char symbol[16]; + uint8_t space[]; +} PACKED; + +struct komodo_event *komodo_eventadd(int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_datalen) +{ + struct komodo_event *ep; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); + ep = calloc(1,len); + ep->len = len; + ep->height = height; + ep->type = type; + strcpy(ep->symbol,symbol); + if ( datalen != 0 ) + memcpy(ep->space,data,datalen); + return(ep); +} + +void komodo_eventadd_notarized(char *symbol,int32_t height,char *dest,bits256 blockhash,bits256 desttxid,int32_t notarizedheight) +{ + struct komodo_event_notarized N; + memset(&N,0,sizeof(N)); + N.blockhash = blockhash; + N.desttxid = desttxid; + N.notarizedheight = notarizedheight; + strcpy(N.dest,dest); + komodo_eventadd(height,symbol,KOMODO_EVENT_NOTARIZED,(void *)&B,sizeof(N)); +} + +void komodo_eventadd_pubkeys(char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33]) +{ + struct komodo_event_pubkeys P; + memset(&P,0,sizeof(P)); + P.num = num; + memcpy(P.pubkeys,pubkeys,33 * num); + komodo_eventadd(height,symbol,KOMODO_EVENT_RATIFY,(void *)&P,(int32_t)(sizeof(P.num) + 33 * num)); +} + +void komodo_eventadd_utxo(char *symbol,int32_t height,uint8_t notaryid,bits256 txid,uint64_t voutmask,uint8_t numvouts) +{ + struct komodo_event_utxo U; + memset(&U,0,sizeof(U)); + U.txid = txid; + U.voutmask = voutmask; + U.numvouts = numvouts; + komodo_eventadd(height,symbol,KOMODO_EVENT_UTXO,(void *)&U,sizeof(U)); +} + +void komodo_eventadd_pricefeed(char *symbol,int32_t height,uint32_t *prices,uint8_t num) +{ + struct komodo_event_pricefeed F; + memset(&F,0,sizeof(F)); + F.num = num; + memcpy(F.prices,prices,sizeof(*F.prices) * num); + komodo_eventadd(height,symbol,KOMODO_EVENT_PRICEFEED,(void *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num))); +} + +void komodo_eventadd_kmdheight(char *symbol,int32_t height,int32_t kmdheight) +{ + komodo_eventadd(height,symbol,KOMODO_EVENT_KMDHEIGHT,(void *)&kmdheight,sizeof(kmdheight)); +} + +void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 txid,uint64_t value,uint16_t vout,uint8_t *opret,uint16_t opretlen) +{ + struct komodo_event_opreturn O; uint8_t opret[10000]; + memset(&O,0,sizeof(O)); + O.txid = txid; + O.value = value; + O.vout = vout; + memcpy(opret,&O,sizeof(O)); + memcpy(&opret[sizeof(O)],opret,opretlen); + komodo_eventadd(height,symbol,type,opret,(int32_t)(opretlen + sizeof(O))); +} + +void komodo_eventadd_deposit(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 kmdtxid,uint16_t kmdvout,uint64_t price) +{ + uint8_t opret[512]; uint16_t opretlen; + komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_DEPOSIT,kmdtxid,komodoshis,kmdvout,opret,opretlen); +} + +void komodo_eventadd_issued(char *symbol,int32_t height,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,bits256 kmdtxid,uint16_t kmdvout,uint64_t fiatoshis) +{ + uint8_t opret[512]; uint16_t opretlen; + komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_ISSUED,fiattxid,fiatoshis,fiatvout,opret,opretlen); +} + +void komodo_eventadd_withdraw(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 fiattxid,int32_t fiatvout,uint64_t price) +{ + uint8_t opret[512]; uint16_t opretlen; + komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_WITHDRAW,fiattxid,fiatoshis,fiatvout,opret,opretlen); +} + +void komodo_eventadd_redeemed(char *symbol,int32_t height,bits256 kmdtxid,uint16_t kmdvout,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,uint64_t komodoshis) +{ + uint8_t opret[512]; uint16_t opretlen; + komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_REDEEMED,kmdtxid,komodoshis,kmdvout,opret,opretlen); +} + +// process events +// + +#endif diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d37b2793f..0ef2bb723 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2627,11 +2627,20 @@ bool CWallet::CreateTransaction(const vector& vecSend, // Reserve a new key pair from key pool CPubKey vchPubKey; - bool ret; - ret = reservekey.GetReservedKey(vchPubKey); - assert(ret); // should never fail, as we just unlocked - - scriptChange = GetScriptForDestination(vchPubKey.GetID()); + extern int32_t USE_EXTERNAL_PUBKEY; extern std::string NOTARY_PUBKEY; + if ( USE_EXTERNAL_PUBKEY == 0 ) + { + //fprintf(stderr,"use notary pubkey\n"); + //scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + bool ret; + ret = reservekey.GetReservedKey(vchPubKey); + assert(ret); // should never fail, as we just unlocked + scriptChange = GetScriptForDestination(vchPubKey.GetID()); + } + else + { + scriptChange = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + } } CTxOut newTxOut(nChange, scriptChange); From 7d8b97be50fc6dd5c7120bb0d218219d45c68254 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 12:31:00 -0300 Subject: [PATCH 03/65] test --- src/komodo_events.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index 5fa284ef2..9fef1c719 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -34,10 +34,10 @@ #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain #define KOMODO_OPRETURN_REDEEM 'X' -struct komodo_event_notarized { bits256 blockhash,desttxid; int32_t notarizedheight; char symbol[16]; } PACKED; +struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char symbol[16]; } PACKED; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; } PACKED; -struct komodo_event_utxo { bits256 txid; uint64_t voutmask; uint8_t numvouts; } PACKED; -struct komodo_event_opreturn { bits256 txid; uint64_t ovalue; uint16_t vout,olen; uint8_t opret[]; } PACKED; +struct komodo_event_utxo { uint256 txid; uint64_t voutmask; uint8_t numvouts; } PACKED; +struct komodo_event_opreturn { uint256 txid; uint64_t ovalue; uint16_t vout,olen; uint8_t opret[]; } PACKED; struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; } PACKED; struct komodo_event @@ -63,7 +63,7 @@ struct komodo_event *komodo_eventadd(int32_t height,char *symbol,uint8_t type,ui return(ep); } -void komodo_eventadd_notarized(char *symbol,int32_t height,char *dest,bits256 blockhash,bits256 desttxid,int32_t notarizedheight) +void komodo_eventadd_notarized(char *symbol,int32_t height,char *dest,uint256 blockhash,uint256 desttxid,int32_t notarizedheight) { struct komodo_event_notarized N; memset(&N,0,sizeof(N)); @@ -83,7 +83,7 @@ void komodo_eventadd_pubkeys(char *symbol,int32_t height,uint8_t num,uint8_t pub komodo_eventadd(height,symbol,KOMODO_EVENT_RATIFY,(void *)&P,(int32_t)(sizeof(P.num) + 33 * num)); } -void komodo_eventadd_utxo(char *symbol,int32_t height,uint8_t notaryid,bits256 txid,uint64_t voutmask,uint8_t numvouts) +void komodo_eventadd_utxo(char *symbol,int32_t height,uint8_t notaryid,uint256 txid,uint64_t voutmask,uint8_t numvouts) { struct komodo_event_utxo U; memset(&U,0,sizeof(U)); @@ -107,7 +107,7 @@ void komodo_eventadd_kmdheight(char *symbol,int32_t height,int32_t kmdheight) komodo_eventadd(height,symbol,KOMODO_EVENT_KMDHEIGHT,(void *)&kmdheight,sizeof(kmdheight)); } -void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 txid,uint64_t value,uint16_t vout,uint8_t *opret,uint16_t opretlen) +void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,uint256 txid,uint64_t value,uint16_t vout,uint8_t *opret,uint16_t opretlen) { struct komodo_event_opreturn O; uint8_t opret[10000]; memset(&O,0,sizeof(O)); @@ -119,25 +119,25 @@ void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 t komodo_eventadd(height,symbol,type,opret,(int32_t)(opretlen + sizeof(O))); } -void komodo_eventadd_deposit(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 kmdtxid,uint16_t kmdvout,uint64_t price) +void komodo_eventadd_deposit(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],uint256 kmdtxid,uint16_t kmdvout,uint64_t price) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_DEPOSIT,kmdtxid,komodoshis,kmdvout,opret,opretlen); } -void komodo_eventadd_issued(char *symbol,int32_t height,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,bits256 kmdtxid,uint16_t kmdvout,uint64_t fiatoshis) +void komodo_eventadd_issued(char *symbol,int32_t height,int32_t fiatheight,uint256 fiattxid,uint16_t fiatvout,uint256 kmdtxid,uint16_t kmdvout,uint64_t fiatoshis) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_ISSUED,fiattxid,fiatoshis,fiatvout,opret,opretlen); } -void komodo_eventadd_withdraw(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 fiattxid,int32_t fiatvout,uint64_t price) +void komodo_eventadd_withdraw(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],uint256 fiattxid,int32_t fiatvout,uint64_t price) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_WITHDRAW,fiattxid,fiatoshis,fiatvout,opret,opretlen); } -void komodo_eventadd_redeemed(char *symbol,int32_t height,bits256 kmdtxid,uint16_t kmdvout,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,uint64_t komodoshis) +void komodo_eventadd_redeemed(char *symbol,int32_t height,uint256 kmdtxid,uint16_t kmdvout,int32_t fiatheight,uint256 fiattxid,uint16_t fiatvout,uint64_t komodoshis) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_REDEEMED,kmdtxid,komodoshis,kmdvout,opret,opretlen); From c5214efefe2932a28e9d49f124ee782abad60e2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 12:33:13 -0300 Subject: [PATCH 04/65] test --- src/komodo_events.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index 9fef1c719..1a8d4f909 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -16,6 +16,7 @@ #ifndef H_KOMODOEVENTS_H #define H_KOMODOEVENTS_H +/* #ifdef WIN32 #define PACKED #else @@ -34,10 +35,10 @@ #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain #define KOMODO_OPRETURN_REDEEM 'X' -struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char symbol[16]; } PACKED; +struct komodo_event_notarized { bits256 blockhash,desttxid; int32_t notarizedheight; char symbol[16]; } PACKED; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; } PACKED; -struct komodo_event_utxo { uint256 txid; uint64_t voutmask; uint8_t numvouts; } PACKED; -struct komodo_event_opreturn { uint256 txid; uint64_t ovalue; uint16_t vout,olen; uint8_t opret[]; } PACKED; +struct komodo_event_utxo { bits256 txid; uint64_t voutmask; uint8_t numvouts; } PACKED; +struct komodo_event_opreturn { bits256 txid; uint64_t ovalue; uint16_t vout,olen; uint8_t opret[]; } PACKED; struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; } PACKED; struct komodo_event @@ -63,7 +64,7 @@ struct komodo_event *komodo_eventadd(int32_t height,char *symbol,uint8_t type,ui return(ep); } -void komodo_eventadd_notarized(char *symbol,int32_t height,char *dest,uint256 blockhash,uint256 desttxid,int32_t notarizedheight) +void komodo_eventadd_notarized(char *symbol,int32_t height,char *dest,bits256 blockhash,bits256 desttxid,int32_t notarizedheight) { struct komodo_event_notarized N; memset(&N,0,sizeof(N)); @@ -83,7 +84,7 @@ void komodo_eventadd_pubkeys(char *symbol,int32_t height,uint8_t num,uint8_t pub komodo_eventadd(height,symbol,KOMODO_EVENT_RATIFY,(void *)&P,(int32_t)(sizeof(P.num) + 33 * num)); } -void komodo_eventadd_utxo(char *symbol,int32_t height,uint8_t notaryid,uint256 txid,uint64_t voutmask,uint8_t numvouts) +void komodo_eventadd_utxo(char *symbol,int32_t height,uint8_t notaryid,bits256 txid,uint64_t voutmask,uint8_t numvouts) { struct komodo_event_utxo U; memset(&U,0,sizeof(U)); @@ -107,7 +108,7 @@ void komodo_eventadd_kmdheight(char *symbol,int32_t height,int32_t kmdheight) komodo_eventadd(height,symbol,KOMODO_EVENT_KMDHEIGHT,(void *)&kmdheight,sizeof(kmdheight)); } -void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,uint256 txid,uint64_t value,uint16_t vout,uint8_t *opret,uint16_t opretlen) +void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 txid,uint64_t value,uint16_t vout,uint8_t *opret,uint16_t opretlen) { struct komodo_event_opreturn O; uint8_t opret[10000]; memset(&O,0,sizeof(O)); @@ -119,25 +120,25 @@ void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,uint256 t komodo_eventadd(height,symbol,type,opret,(int32_t)(opretlen + sizeof(O))); } -void komodo_eventadd_deposit(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],uint256 kmdtxid,uint16_t kmdvout,uint64_t price) +void komodo_eventadd_deposit(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 kmdtxid,uint16_t kmdvout,uint64_t price) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_DEPOSIT,kmdtxid,komodoshis,kmdvout,opret,opretlen); } -void komodo_eventadd_issued(char *symbol,int32_t height,int32_t fiatheight,uint256 fiattxid,uint16_t fiatvout,uint256 kmdtxid,uint16_t kmdvout,uint64_t fiatoshis) +void komodo_eventadd_issued(char *symbol,int32_t height,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,bits256 kmdtxid,uint16_t kmdvout,uint64_t fiatoshis) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_ISSUED,fiattxid,fiatoshis,fiatvout,opret,opretlen); } -void komodo_eventadd_withdraw(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],uint256 fiattxid,int32_t fiatvout,uint64_t price) +void komodo_eventadd_withdraw(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 fiattxid,int32_t fiatvout,uint64_t price) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_WITHDRAW,fiattxid,fiatoshis,fiatvout,opret,opretlen); } -void komodo_eventadd_redeemed(char *symbol,int32_t height,uint256 kmdtxid,uint16_t kmdvout,int32_t fiatheight,uint256 fiattxid,uint16_t fiatvout,uint64_t komodoshis) +void komodo_eventadd_redeemed(char *symbol,int32_t height,bits256 kmdtxid,uint16_t kmdvout,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,uint64_t komodoshis) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_REDEEMED,kmdtxid,komodoshis,kmdvout,opret,opretlen); @@ -145,5 +146,5 @@ void komodo_eventadd_redeemed(char *symbol,int32_t height,uint256 kmdtxid,uint16 // process events // - +*/ #endif From 3501e4d27fd18d1ac9f7a0faebf87db741cff4ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 14:09:25 -0300 Subject: [PATCH 05/65] test --- src/komodo.h | 2 +- src/komodo_events.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index de3003624..2161d1a3f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -38,10 +38,10 @@ FILE *Minerfp; int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks -#include "komodo_events.h" #include "komodo_globals.h" #include "komodo_utils.h" +#include "komodo_events.h" #include "cJSON.c" #include "komodo_bitcoind.h" diff --git a/src/komodo_events.h b/src/komodo_events.h index 1a8d4f909..e6430126c 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -16,7 +16,7 @@ #ifndef H_KOMODOEVENTS_H #define H_KOMODOEVENTS_H -/* + #ifdef WIN32 #define PACKED #else @@ -146,5 +146,5 @@ void komodo_eventadd_redeemed(char *symbol,int32_t height,bits256 kmdtxid,uint16 // process events // -*/ + #endif From ea5742ed30e5368f20f26a94f1dc20f5e5e6fc9a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 14:11:07 -0300 Subject: [PATCH 06/65] 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 e6430126c..c8154a423 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -51,10 +51,10 @@ struct komodo_event uint8_t space[]; } PACKED; -struct komodo_event *komodo_eventadd(int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_datalen) +struct komodo_event *komodo_eventadd(int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen) { struct komodo_event *ep; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); - ep = calloc(1,len); + ep = (struct komodo_event *)calloc(1,len); ep->len = len; ep->height = height; ep->type = type; From c1139e1e1dd6ebd33f4df73f1c760ee41d63137b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 14:14:45 -0300 Subject: [PATCH 07/65] test --- src/komodo_events.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index c8154a423..68bdab9b6 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -23,7 +23,7 @@ #define PACKED __attribute__((packed)) #endif -#define KOMODO_EVENT_PUBKEYS 'P' +#define KOMODO_EVENT_RATIFY 'P' #define KOMODO_EVENT_NOTARIZED 'N' #define KOMODO_EVENT_UTXO 'U' #define KOMODO_EVENT_KMDHEIGHT 'K' @@ -35,7 +35,7 @@ #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain #define KOMODO_OPRETURN_REDEEM 'X' -struct komodo_event_notarized { bits256 blockhash,desttxid; int32_t notarizedheight; char symbol[16]; } PACKED; +struct komodo_event_notarized { bits256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; } PACKED; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; } PACKED; struct komodo_event_utxo { bits256 txid; uint64_t voutmask; uint8_t numvouts; } PACKED; struct komodo_event_opreturn { bits256 txid; uint64_t ovalue; uint16_t vout,olen; uint8_t opret[]; } PACKED; @@ -72,7 +72,7 @@ void komodo_eventadd_notarized(char *symbol,int32_t height,char *dest,bits256 bl N.desttxid = desttxid; N.notarizedheight = notarizedheight; strcpy(N.dest,dest); - komodo_eventadd(height,symbol,KOMODO_EVENT_NOTARIZED,(void *)&B,sizeof(N)); + komodo_eventadd(height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); } void komodo_eventadd_pubkeys(char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33]) @@ -81,7 +81,7 @@ void komodo_eventadd_pubkeys(char *symbol,int32_t height,uint8_t num,uint8_t pub memset(&P,0,sizeof(P)); P.num = num; memcpy(P.pubkeys,pubkeys,33 * num); - komodo_eventadd(height,symbol,KOMODO_EVENT_RATIFY,(void *)&P,(int32_t)(sizeof(P.num) + 33 * num)); + komodo_eventadd(height,symbol,KOMODO_EVENT_RATIFY,(uint8_t *)&P,(int32_t)(sizeof(P.num) + 33 * num)); } void komodo_eventadd_utxo(char *symbol,int32_t height,uint8_t notaryid,bits256 txid,uint64_t voutmask,uint8_t numvouts) @@ -91,7 +91,7 @@ void komodo_eventadd_utxo(char *symbol,int32_t height,uint8_t notaryid,bits256 t U.txid = txid; U.voutmask = voutmask; U.numvouts = numvouts; - komodo_eventadd(height,symbol,KOMODO_EVENT_UTXO,(void *)&U,sizeof(U)); + komodo_eventadd(height,symbol,KOMODO_EVENT_UTXO,(uint8_t *)&U,sizeof(U)); } void komodo_eventadd_pricefeed(char *symbol,int32_t height,uint32_t *prices,uint8_t num) @@ -100,15 +100,15 @@ void komodo_eventadd_pricefeed(char *symbol,int32_t height,uint32_t *prices,uint memset(&F,0,sizeof(F)); F.num = num; memcpy(F.prices,prices,sizeof(*F.prices) * num); - komodo_eventadd(height,symbol,KOMODO_EVENT_PRICEFEED,(void *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num))); + komodo_eventadd(height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num))); } void komodo_eventadd_kmdheight(char *symbol,int32_t height,int32_t kmdheight) { - komodo_eventadd(height,symbol,KOMODO_EVENT_KMDHEIGHT,(void *)&kmdheight,sizeof(kmdheight)); + komodo_eventadd(height,symbol,KOMODO_EVENT_KMDHEIGHT,(uint8_t *)&kmdheight,sizeof(kmdheight)); } -void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 txid,uint64_t value,uint16_t vout,uint8_t *opret,uint16_t opretlen) +void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 txid,uint64_t value,uint16_t vout,uint8_t *buf,uint16_t opretlen) { struct komodo_event_opreturn O; uint8_t opret[10000]; memset(&O,0,sizeof(O)); @@ -116,7 +116,7 @@ void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 t O.value = value; O.vout = vout; memcpy(opret,&O,sizeof(O)); - memcpy(&opret[sizeof(O)],opret,opretlen); + memcpy(&opret[sizeof(O)],buf,opretlen); komodo_eventadd(height,symbol,type,opret,(int32_t)(opretlen + sizeof(O))); } From 9d4a32f450a782b8b137b820bc0efb85e2d11ae1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 14:15:24 -0300 Subject: [PATCH 08/65] 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 68bdab9b6..450be71c5 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -31,9 +31,9 @@ #define KOMODO_EVENT_PRICEFEED 'V' #define KOMODO_EVENT_OPRETURN 'R' #define KOMODO_OPRETURN_DEPOSIT 'D' -#define KOMODO_OPRETURN_ISSUE 'I' // assetchain +#define KOMODO_OPRETURN_ISSUED 'I' // assetchain #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain -#define KOMODO_OPRETURN_REDEEM 'X' +#define KOMODO_OPRETURN_REDEEMED 'X' struct komodo_event_notarized { bits256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; } PACKED; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; } PACKED; From a882d643578431bfa8dcdd0f4572c15963da2cbc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 14:18:23 -0300 Subject: [PATCH 09/65] test --- src/komodo_events.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index 450be71c5..add1d9eca 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -123,25 +123,25 @@ void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 t void komodo_eventadd_deposit(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 kmdtxid,uint16_t kmdvout,uint64_t price) { uint8_t opret[512]; uint16_t opretlen; - komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_DEPOSIT,kmdtxid,komodoshis,kmdvout,opret,opretlen); + komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_DEPOSIT,kmdtxid,komodoshis,kmdvout,opret,opretlen); } void komodo_eventadd_issued(char *symbol,int32_t height,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,bits256 kmdtxid,uint16_t kmdvout,uint64_t fiatoshis) { uint8_t opret[512]; uint16_t opretlen; - komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_ISSUED,fiattxid,fiatoshis,fiatvout,opret,opretlen); + komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_ISSUED,fiattxid,fiatoshis,fiatvout,opret,opretlen); } void komodo_eventadd_withdraw(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 fiattxid,int32_t fiatvout,uint64_t price) { uint8_t opret[512]; uint16_t opretlen; - komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_WITHDRAW,fiattxid,fiatoshis,fiatvout,opret,opretlen); + komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_WITHDRAW,fiattxid,fiatoshis,fiatvout,opret,opretlen); } void komodo_eventadd_redeemed(char *symbol,int32_t height,bits256 kmdtxid,uint16_t kmdvout,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,uint64_t komodoshis) { uint8_t opret[512]; uint16_t opretlen; - komodo_eventadd_opreturn(symbol,height,KOMODO_EVENT_REDEEMED,kmdtxid,komodoshis,kmdvout,opret,opretlen); + komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_REDEEMED,kmdtxid,komodoshis,kmdvout,opret,opretlen); } // process events From 928dfe4ea32e71301a348eecf9f03030283d9cf1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 14:20:25 -0300 Subject: [PATCH 10/65] test --- src/komodo_events.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index add1d9eca..11cf1dc88 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -38,7 +38,7 @@ struct komodo_event_notarized { bits256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; } PACKED; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; } PACKED; struct komodo_event_utxo { bits256 txid; uint64_t voutmask; uint8_t numvouts; } PACKED; -struct komodo_event_opreturn { bits256 txid; uint64_t ovalue; uint16_t vout,olen; uint8_t opret[]; } PACKED; +struct komodo_event_opreturn { bits256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; } PACKED; struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; } PACKED; struct komodo_event @@ -100,7 +100,7 @@ void komodo_eventadd_pricefeed(char *symbol,int32_t height,uint32_t *prices,uint memset(&F,0,sizeof(F)); F.num = num; memcpy(F.prices,prices,sizeof(*F.prices) * num); - komodo_eventadd(height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num))); + komodo_eventadd(height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num)); } void komodo_eventadd_kmdheight(char *symbol,int32_t height,int32_t kmdheight) @@ -117,7 +117,8 @@ void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 t O.vout = vout; memcpy(opret,&O,sizeof(O)); memcpy(&opret[sizeof(O)],buf,opretlen); - komodo_eventadd(height,symbol,type,opret,(int32_t)(opretlen + sizeof(O))); + O.oplen = (int32_t)(opretlen + sizeof(O)); + komodo_eventadd(height,symbol,type,opret,O.oplen); } void komodo_eventadd_deposit(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 kmdtxid,uint16_t kmdvout,uint64_t price) From c75c18fc3ce3e041dfd30fce06919f9fad482af3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:11:10 -0300 Subject: [PATCH 11/65] test --- src/komodo.h | 316 ++++++++++++++++++++++++++---------------- src/komodo_bitcoind.h | 5 +- src/komodo_events.h | 68 +++++++-- src/komodo_gateway.h | 10 -- src/komodo_globals.h | 5 +- src/komodo_interest.h | 2 + src/komodo_notary.h | 39 ++++-- src/komodo_pax.h | 2 - src/main.cpp | 4 +- src/pow.cpp | 5 +- src/rpcmisc.cpp | 12 +- 11 files changed, 299 insertions(+), 169 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 2161d1a3f..f041e54b7 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -31,17 +31,46 @@ #include #include - #define GENESIS_NBITS 0x1f00ffff #define KOMODO_MINRATIFY 7 +#define KOMODO_MAXBLOCKS 5000000 FILE *Minerfp; -int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks +int8_t Minerids[KOMODO_MAXBLOCKS]; // 5 million blocks +#define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) +struct pax_transaction +{ + UT_hash_handle hh; + uint256 txid; + uint64_t komodoshis,fiatoshis; + int32_t marked,height,otherheight; + uint16_t vout; + char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; +}; + +struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; }; +struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; +struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; }; +struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; }; +pthread_mutex_t komodo_mutex; +int32_t KMDHEIGHT = 43000; + +struct pax_transaction *PAX; +int32_t NUM_PRICES; uint32_t *PVALS; +struct knotaries_entry *Pubkeys; +struct nutxo_entry *NUTXOS; int32_t Num_nutxos; +struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS; + +struct komodo_state +{ + uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; + int32_t CURRENT_HEIGHT,NOTARIZED_HEIGHT; + // gateway state +} KOMODO_STATES[33]; #include "komodo_globals.h" #include "komodo_utils.h" -#include "komodo_events.h" #include "cJSON.c" #include "komodo_bitcoind.h" @@ -49,11 +78,157 @@ int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks #include "komodo_pax.h" #include "komodo_notary.h" #include "komodo_gateway.h" +#include "komodo_events.h" +void komodo_setkmdheight(int32_t kmdheight) +{ + if ( kmdheight > KMDHEIGHT ) + KMDHEIGHT = kmdheight; +} +struct komodo_state *komodo_stateptr(char *symbol,char *dest) +{ + int32_t baseid; struct komodo_state *sp; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + { + strcpy(symbol,"KMD"); + strcpy(dest,"BTC"); + sp = &KOMODO_STATES[0]; + } + else + { + strcpy(symbol,ASSETCHAINS_SYMBOL); + strcpy(dest,"KMD"); + if ( (baseid= komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 ) + sp = &KOMODO_STATES[baseid]; + else + { + fprintf(stderr,"komodo_stateupdate.(%s) not supported\n",ASSETCHAINS_SYMBOL); + return(0); + } + } + return(sp); +} + +void komodo_currentheight_set(int32_t height) +{ + char symbol[16],dest[16]; struct komodo_state *sp; + if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) + sp->CURRENT_HEIGHT = height; +} + +int32_t komodo_currentheight() +{ + char symbol[16],dest[16]; struct komodo_state *sp; + if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) + return(sp->CURRENT_HEIGHT); + else return(0); +} + +int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char *dest) +{ + static int32_t errs; + char symbol[16]; int32_t func,ht,notarized_height,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; + if ( (func= fgetc(fp)) != EOF ) + { + if ( ASSETCHAINS_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 ) + matched = 1; + else matched = (strcmp(symbol,ASSETCHAINS_SYMBOL) == 0); + if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) + errs++; + //printf("fpos.%ld func.(%d %c) ht.%d ",ftell(fp),func,func,ht); + if ( func == 'P' ) + { + if ( (num= fgetc(fp)) < 64 ) + { + if ( fread(pubkeys,33,num,fp) != num ) + errs++; + else + { + printf("updated %d pubkeys at ht.%d\n",num,ht); + if ( matched != 0 ) + komodo_eventadd_pubkeys(sp,symbol,ht,num,pubkeys); + } + } else printf("illegal num.%d\n",num); + } + else if ( func == 'N' ) + { + if ( fread(¬arized_height,1,sizeof(notarized_height),fp) != sizeof(notarized_height) ) + errs++; + if ( fread(¬arized_hash,1,sizeof(notarized_hash),fp) != sizeof(notarized_hash) ) + errs++; + if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) ) + errs++; + printf("load NOTARIZED %d %s\n",notarized_height,notarized_hash.ToString().c_str()); + if ( matched != 0 ) + komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); + } + else if ( func == 'U' ) + { + uint8_t n,nid; uint256 hash; uint64_t mask; + n = fgetc(fp); + nid = fgetc(fp); + //printf("U %d %d\n",n,nid); + if ( fread(&mask,1,sizeof(mask),fp) != sizeof(mask) ) + errs++; + if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) ) + errs++; + if ( matched != 0 ) + komodo_eventadd_utxo(sp,symbol,ht,nid,hash,voutmask,n); + } + else if ( func == 'K' ) + { + int32_t kheight; + if ( fread(&kheight,1,sizeof(kheight),fp) != sizeof(kheight) ) + errs++; + if ( matched != 0 ) + komodo_eventadd_kmdheight(sp,symbol,ht,kheight); + } + else if ( func == 'R' ) + { + uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[10000]; + if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) ) + errs++; + if ( fread(&v,1,sizeof(v),fp) != sizeof(v) ) + errs++; + if ( fread(&ovalue,1,sizeof(ovalue),fp) != sizeof(ovalue) ) + errs++; + if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) ) + errs++; + if ( olen < sizeof(opret) ) + { + if ( fread(opret,1,olen,fp) != olen ) + errs++; + if ( matched != 0 ) + komodo_eventadd_opreturn(sp,symbol,ht,txid,ovalue,v,opret,opretlen); + } else printf("illegal olen.%u\n",olen); + } + else if ( func == 'D' ) + { + printf("unexpected function D[%d]\n",ht); + } + else if ( func == 'V' ) + { + int32_t numpvals; uint32_t pvals[128]; + numpvals = fgetc(fp); + if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals ) + { + if ( matched != 0 ) + komodo_eventadd_pricefeed(sp,symbol,height,pvals,numpvals); + //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); + } else printf("error loading pvals[%d]\n",numpvals); + } + else printf("illegal func.(%d %c)\n",func,func); + return(func); + } else return(-1); +} + void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { - static FILE *fp; static int32_t errs; char fname[512],fname2[512]; int32_t ht,func; uint8_t num,pubkeys[64][33]; + static FILE *fp; static int32_t errs; + struct komodo_state *sp; char fname[512],fname2[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33]; + if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) + return; if ( fp == 0 ) { #ifdef WIN32 @@ -77,95 +252,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar printf("read error Minerids\n"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - while ( (func= fgetc(fp)) != EOF ) - { - if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) - errs++; - //printf("fpos.%ld func.(%d %c) ht.%d ",ftell(fp),func,func,ht); - if ( func == 'P' ) - { - if ( (num= fgetc(fp)) < 64 ) - { - if ( fread(pubkeys,33,num,fp) != num ) - errs++; - else - { - printf("updated %d pubkeys at ht.%d\n",num,ht); - komodo_notarysinit(ht,pubkeys,num); - } - } else printf("illegal num.%d\n",num); - //printf("P[%d]\n",num); - } - else if ( func == 'N' ) - { - if ( fread(&NOTARIZED_HEIGHT,1,sizeof(NOTARIZED_HEIGHT),fp) != sizeof(NOTARIZED_HEIGHT) ) - errs++; - if ( fread(&NOTARIZED_HASH,1,sizeof(NOTARIZED_HASH),fp) != sizeof(NOTARIZED_HASH) ) - errs++; - if ( fread(&NOTARIZED_DESTTXID,1,sizeof(NOTARIZED_DESTTXID),fp) != sizeof(NOTARIZED_DESTTXID) ) - errs++; - printf("load NOTARIZED %d %s\n",NOTARIZED_HEIGHT,NOTARIZED_HASH.ToString().c_str()); - komodo_notarized_update(ht,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID); - } - else if ( func == 'U' ) - { - uint8_t n,nid; uint256 hash; uint64_t mask; - n = fgetc(fp); - nid = fgetc(fp); - //printf("U %d %d\n",n,nid); - if ( fread(&mask,1,sizeof(mask),fp) != sizeof(mask) ) - errs++; - if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) ) - errs++; - komodo_nutxoadd(ht,nid,hash,mask,n); - } - else if ( func == 'K' ) - { - int32_t kheight; - if ( fread(&kheight,1,sizeof(kheight),fp) != sizeof(kheight) ) - errs++; - if ( kheight > KMDHEIGHT ) - { - KMDHEIGHT = kheight; - } - //printf("ht.%d KMDHEIGHT <- %d\n",ht,kheight); - } - else if ( func == 'R' ) - { - uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[10000]; - if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) ) - errs++; - if ( fread(&v,1,sizeof(v),fp) != sizeof(v) ) - errs++; - if ( fread(&ovalue,1,sizeof(ovalue),fp) != sizeof(ovalue) ) - errs++; - if ( fread(&olen,1,sizeof(olen),fp) != sizeof(olen) ) - errs++; - if ( olen < sizeof(opret) ) - { - if ( fread(opret,1,olen,fp) != olen ) - errs++; - komodo_opreturn(ht,ovalue,opret,olen,txid,v); - } else printf("illegal olen.%u\n",olen); - } - else if ( func == 'D' ) - { - printf("unexpected function D[%d]\n",ht); - } -//#ifdef KOMODO_PAX - else if ( func == 'V' ) - { - int32_t numpvals; uint32_t pvals[128]; - numpvals = fgetc(fp); - if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals ) - { - komodo_pvals(ht,pvals,numpvals); - //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); - } else printf("error loading pvals[%d]\n",numpvals); - } -//#endif - else printf("illegal func.(%d %c)\n",func,func); - } + while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) + ; } else fp = fopen(fname,"wb+"); printf("fname.(%s) fpos.%ld\n",fname,ftell(fp)); KOMODO_INITDONE = (uint32_t)time(NULL); @@ -178,22 +266,14 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fp != 0 ) // write out funcid, height, other fields, call side effect function { //printf("fpos.%ld ",ftell(fp)); - if ( height < 0 ) - { - height = -height; - //printf("func D[%d] errs.%d\n",height,errs); - fputc('D',fp); - if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) - errs++; - } - else if ( KMDheight > 0 ) + if ( KMDheight > 0 ) { fputc('K',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; if ( fwrite(&KMDheight,1,sizeof(KMDheight),fp) != sizeof(KMDheight) ) errs++; - //printf("ht.%d K %d\n",height,KMDheight); + komodo_eventadd_kmdheight(sp,symbol,height,KMDheight); } else if ( opretbuf != 0 && opretlen > 0 ) { @@ -212,7 +292,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; //printf("ht.%d R opret[%d]\n",height,olen); - komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout); + //komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout); + komodo_eventadd_opreturn(sp,symbol,height,txhash,opretvalue,vout,opretbuf,olen); } else if ( notarypubs != 0 && numnotaries > 0 ) { @@ -223,7 +304,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar fputc(numnotaries,fp); if ( fwrite(notarypubs,33,numnotaries,fp) != numnotaries ) errs++; - komodo_notarysinit(height,notarypubs,numnotaries); + komodo_eventadd_pubkeys(sp,symbol,height,numnotaries,notarypubs); } else if ( voutmask != 0 && numvouts > 0 ) { @@ -237,7 +318,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) ) errs++; - komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); + komodo_eventadd_utxo(sp,symbol,height,notaryid,txhash,voutmask,numvouts); + //komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); } //#ifdef KOMODO_PAX else if ( pvals != 0 && numpvals > 0 ) @@ -254,7 +336,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar fputc(numpvals,fp); if ( fwrite(pvals,sizeof(uint32_t),numpvals,fp) != numpvals ) errs++; - komodo_pvals(height,pvals,numpvals); + komodo_eventadd_pricefeed(sp,symbol,height,pvals,numpvals); //printf("ht.%d V numpvals[%d]\n",height,numpvals); } //printf("save pvals height.%d numpvals.%d\n",height,numpvals); @@ -266,13 +348,14 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar fputc('N',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; - if ( fwrite(&NOTARIZED_HEIGHT,1,sizeof(NOTARIZED_HEIGHT),fp) != sizeof(NOTARIZED_HEIGHT) ) + if ( fwrite(&sp->NOTARIZED_HEIGHT,1,sizeof(sp->NOTARIZED_HEIGHT),fp) != sizeof(sp->NOTARIZED_HEIGHT) ) errs++; - if ( fwrite(&NOTARIZED_HASH,1,sizeof(NOTARIZED_HASH),fp) != sizeof(NOTARIZED_HASH) ) + if ( fwrite(&sp->NOTARIZED_HASH,1,sizeof(sp->NOTARIZED_HASH),fp) != sizeof(sp->NOTARIZED_HASH) ) errs++; - if ( fwrite(&NOTARIZED_DESTTXID,1,sizeof(NOTARIZED_DESTTXID),fp) != sizeof(NOTARIZED_DESTTXID) ) + if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) ) errs++; - komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID); + komodo_eventadd_notarized(sp,symbol,height,dest,sp->NOTARIZED_HASH,sp->NOTARIZED_DESTTXID,sp->NOTARIZED_HEIGHT); + //komodo_notarized_update(height,NOTARIZED_HEIGHT,NOTARIZED_HASH,NOTARIZED_DESTTXID); } fflush(fp); } @@ -331,12 +414,12 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); - if ( *notarizedheightp > NOTARIZED_HEIGHT && *notarizedheightp < height ) + if ( *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) { printf("ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s)\n",height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len]); - NOTARIZED_HEIGHT = *notarizedheightp; - NOTARIZED_HASH = kmdtxid; - NOTARIZED_DESTTXID = desttxid; + sp->NOTARIZED_HEIGHT = *notarizedheightp; + sp->NOTARIZED_HASH = kmdtxid; + sp->NOTARIZED_DESTTXID = desttxid; komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0); } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } @@ -378,6 +461,7 @@ int32_t komodo_isratify(int32_t isspecial,int32_t numvalid) // if all outputs to notary -> notary utxo // if txi == 0 && 2 outputs and 2nd OP_RETURN, len == 32*2+4 -> notarized, 1st byte 'P' -> pricefeed // OP_RETURN: 'D' -> deposit, 'W' -> withdraw +void komodo_currentheight_set(int32_t height); void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { @@ -394,7 +478,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) printf("hwmheight.%d vs pindex->nHeight.%d reorg.%d\n",hwmheight,pindex->nHeight,hwmheight-pindex->nHeight); // reset komodostate } - CURRENT_HEIGHT = chainActive.Tip()->nHeight; + komodo_currentheight_set(chainActive.Tip()->nHeight); if ( komodo_is_issuer() != 0 ) { while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME ) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8979bae06..c4e5b9822 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -385,7 +385,6 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) //uint256 zero; //printf("disconnect ht.%d\n",pindex->nHeight); //memset(&zero,0,sizeof(zero)); - //komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0,0,0,0); } int32_t komodo_is_notarytx(const CTransaction& tx) @@ -468,7 +467,7 @@ int8_t komodo_minerid(int32_t height) { static uint32_t depth; int32_t notaryid; CBlockIndex *pindex; uint8_t pubkey33[33]; - if ( depth < 3 && height <= CURRENT_HEIGHT )//chainActive.Tip()->nHeight ) + if ( depth < 3 && height <= komodo_currentheight() )//chainActive.Tip()->nHeight ) { if ( Minerids[height] >= -1 ) { @@ -510,7 +509,7 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) Minerids[height-i] = komodo_minerid(height-i); if ( Minerids[height - i] == -2 ) { - //fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,CURRENT_HEIGHT); + //fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,komodo_currentheight()); return(-2); } } diff --git a/src/komodo_events.h b/src/komodo_events.h index 11cf1dc88..dcd589e13 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -51,6 +51,8 @@ struct komodo_event uint8_t space[]; } PACKED; +struct komodo_event **Komodo_events; int32_t Komodo_numevents; + struct komodo_event *komodo_eventadd(int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen) { struct komodo_event *ep; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); @@ -61,10 +63,12 @@ struct komodo_event *komodo_eventadd(int32_t height,char *symbol,uint8_t type,ui strcpy(ep->symbol,symbol); if ( datalen != 0 ) memcpy(ep->space,data,datalen); + Komodo_events = realloc(Komodo_events,(1 + Komodo_numevents) * sizeof(*Komodo_events)); + Komodo_events[Komodo_numevents++] = ep; return(ep); } -void komodo_eventadd_notarized(char *symbol,int32_t height,char *dest,bits256 blockhash,bits256 desttxid,int32_t notarizedheight) +void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight) { struct komodo_event_notarized N; memset(&N,0,sizeof(N)); @@ -73,18 +77,22 @@ void komodo_eventadd_notarized(char *symbol,int32_t height,char *dest,bits256 bl N.notarizedheight = notarizedheight; strcpy(N.dest,dest); komodo_eventadd(height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); + if ( sp != 0 ) + komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid); } -void komodo_eventadd_pubkeys(char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33]) +void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33]) { struct komodo_event_pubkeys P; memset(&P,0,sizeof(P)); P.num = num; memcpy(P.pubkeys,pubkeys,33 * num); komodo_eventadd(height,symbol,KOMODO_EVENT_RATIFY,(uint8_t *)&P,(int32_t)(sizeof(P.num) + 33 * num)); + if ( sp != 0 ) + komodo_notarysinit(height,pubkeys,num); } -void komodo_eventadd_utxo(char *symbol,int32_t height,uint8_t notaryid,bits256 txid,uint64_t voutmask,uint8_t numvouts) +void komodo_eventadd_utxo(struct komodo_state *sp,char *symbol,int32_t height,uint8_t notaryid,bits256 txid,uint64_t voutmask,uint8_t numvouts) { struct komodo_event_utxo U; memset(&U,0,sizeof(U)); @@ -92,23 +100,29 @@ void komodo_eventadd_utxo(char *symbol,int32_t height,uint8_t notaryid,bits256 t U.voutmask = voutmask; U.numvouts = numvouts; komodo_eventadd(height,symbol,KOMODO_EVENT_UTXO,(uint8_t *)&U,sizeof(U)); + if ( sp != 0 ) + komodo_nutxoadd(height,notaryid,txid,voutmask,numvouts); } -void komodo_eventadd_pricefeed(char *symbol,int32_t height,uint32_t *prices,uint8_t num) +void komodo_eventadd_pricefeed(struct komodo_state *sp,char *symbol,int32_t height,uint32_t *prices,uint8_t num) { struct komodo_event_pricefeed F; memset(&F,0,sizeof(F)); F.num = num; memcpy(F.prices,prices,sizeof(*F.prices) * num); komodo_eventadd(height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num)); + if ( sp != 0 ) + komodo_pvals(height,prices,num); } -void komodo_eventadd_kmdheight(char *symbol,int32_t height,int32_t kmdheight) +void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t height,int32_t kmdheight) { komodo_eventadd(height,symbol,KOMODO_EVENT_KMDHEIGHT,(uint8_t *)&kmdheight,sizeof(kmdheight)); + if ( sp != 0 ) + komodo_setkmdheight(kmdheight); } -void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 txid,uint64_t value,uint16_t vout,uint8_t *buf,uint16_t opretlen) +void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t height,bits256 txid,uint64_t value,uint16_t vout,uint8_t *buf,uint16_t opretlen) { struct komodo_event_opreturn O; uint8_t opret[10000]; memset(&O,0,sizeof(O)); @@ -118,32 +132,62 @@ void komodo_eventadd_opreturn(char *symbol,int32_t height,uint8_t type,bits256 t memcpy(opret,&O,sizeof(O)); memcpy(&opret[sizeof(O)],buf,opretlen); O.oplen = (int32_t)(opretlen + sizeof(O)); - komodo_eventadd(height,symbol,type,opret,O.oplen); + komodo_eventadd(height,symbol,KOMODO_EVENT_OPRETURN,opret,O.oplen); + if ( sp != 0 ) + komodo_opreturn(height,value,buf,opretlen,txid,vout); } -void komodo_eventadd_deposit(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 kmdtxid,uint16_t kmdvout,uint64_t price) +void komodo_event_undo(struct komodo_event *ep) +{ + switch ( ep->type ) + { + case KOMODO_EVENT_RATIFY: + case KOMODO_EVENT_NOTARIZED: + case KOMODO_EVENT_UTXO: + case KOMODO_EVENT_KMDHEIGHT: + case KOMODO_EVENT_PRICEFEED: + case KOMODO_EVENT_OPRETURN: + break; + } +} + +void komodo_event_rewind(int32_t height) +{ + while ( Komodo_numevents > 0 ) + { + if ( (ep= Komodo_events[Komodo_numevents-1]) != 0 ) + { + if ( ep->height < height ) + break; + komodo_event_undo(ep); + Komodo_numevents--; + } + } +} + +/*void komodo_eventadd_deposit(int32_t actionflag,char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 kmdtxid,uint16_t kmdvout,uint64_t price) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_DEPOSIT,kmdtxid,komodoshis,kmdvout,opret,opretlen); } -void komodo_eventadd_issued(char *symbol,int32_t height,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,bits256 kmdtxid,uint16_t kmdvout,uint64_t fiatoshis) +void komodo_eventadd_issued(int32_t actionflag,char *symbol,int32_t height,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,bits256 kmdtxid,uint16_t kmdvout,uint64_t fiatoshis) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_ISSUED,fiattxid,fiatoshis,fiatvout,opret,opretlen); } -void komodo_eventadd_withdraw(char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 fiattxid,int32_t fiatvout,uint64_t price) +void komodo_eventadd_withdraw(int32_t actionflag,char *symbol,int32_t height,uint64_t komodoshis,char *fiat,uint64_t fiatoshis,uint8_t rmd160[20],bits256 fiattxid,int32_t fiatvout,uint64_t price) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_WITHDRAW,fiattxid,fiatoshis,fiatvout,opret,opretlen); } -void komodo_eventadd_redeemed(char *symbol,int32_t height,bits256 kmdtxid,uint16_t kmdvout,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,uint64_t komodoshis) +void komodo_eventadd_redeemed(int32_t actionflag,char *symbol,int32_t height,bits256 kmdtxid,uint16_t kmdvout,int32_t fiatheight,bits256 fiattxid,uint16_t fiatvout,uint64_t komodoshis) { uint8_t opret[512]; uint16_t opretlen; komodo_eventadd_opreturn(symbol,height,KOMODO_OPRETURN_REDEEMED,kmdtxid,komodoshis,kmdvout,opret,opretlen); -} +}*/ // process events // diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6b88f8fae..d72c4b1c0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -15,16 +15,6 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse -struct pax_transaction -{ - UT_hash_handle hh; - uint256 txid; - uint64_t komodoshis,fiatoshis; - int32_t marked,height,otherheight; - uint16_t vout; - char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; -} *PAX; - uint64_t komodo_paxtotal() { struct pax_transaction *pax,*tmp; uint64_t total = 0; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index bf9ac25ce..693bf429a 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -23,7 +23,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) int COINBASE_MATURITY = 100; -int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,CURRENT_HEIGHT,ASSETCHAINS_SEED,KOMODO_ON_DEMAND; +int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; uint8_t NOTARY_PUBKEY33[33]; @@ -34,9 +34,6 @@ uint32_t ASSETCHAIN_INIT; uint32_t ASSETCHAINS_MAGIC = 2387029918; uint64_t ASSETCHAINS_SUPPLY = 10; -int32_t NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 43000; -uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; -pthread_mutex_t komodo_mutex; uint32_t KOMODO_INITDONE,KOMODO_REALTIME; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; uint64_t PENDING_KOMODO_TX; diff --git a/src/komodo_interest.h b/src/komodo_interest.h index b3b1e21f7..bc9df3e3a 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -58,6 +58,8 @@ uint64_t komodo_moneysupply(int32_t height) uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes; uint64_t numerator,denominator,interest = 0; + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + return(0); if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) { if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 8cbd3bc0d..8fc4f765a 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -52,13 +52,6 @@ const char *Notaries_genesis[][2] = { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, }; -#define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) - -struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; } *NUTXOS; -struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; -struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; } Pubkeys[10000]; -struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; } *NPOINTS; int32_t NUM_NPOINTS; - void komodo_nutxoadd(int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts) { struct nutxo_entry *np; @@ -124,17 +117,20 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) return(-1); } -void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num) +void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) { static int32_t hwmheight; int32_t k,i,htind,nonz; struct knotary_entry *kp; struct knotaries_entry N; + if ( Pubkeys == 0 ) + Pubkeys = (struct knotaries_entry *)calloc(KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP,sizeof(*Pubkeys)); memset(&N,0,sizeof(N)); if ( height > 0 ) { - height += KOMODO_ELECTION_GAP/2; + height = (origheight + KOMODO_ELECTION_GAP/2); height /= KOMODO_ELECTION_GAP; height = ((height + 1) * KOMODO_ELECTION_GAP); htind = (height / KOMODO_ELECTION_GAP); + printf("htind.%d activation %d from %d\n",htind,height,origheight); } else htind = 0; pthread_mutex_lock(&komodo_mutex); for (k=0; k nHeight ) @@ -201,9 +197,26 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no np = &NPOINTS[NUM_NPOINTS++]; memset(np,0,sizeof(*np)); np->nHeight = nHeight; - np->notarized_height = notarized_height; - np->notarized_hash = notarized_hash; - np->notarized_desttxid = notarized_desttxid; + sp->NOTARIZED_HEIGHT = np->notarized_height = notarized_height; + sp->NOTARIZED_HASH = np->notarized_hash = notarized_hash; + sp->NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid; +} + +int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) +{ + char symbol[16],dest[16]; struct komodo_state *sp; + if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) + { + *hashp = sp->NOTARIZED_HASH; + *txidp = sp->NOTARIZED_DESTTXID; + return(sp->NOTARIZED_HEIGHT); + } + else + { + memset(hashp,0,sizeof(*hashp)); + memset(txidp,0,sizeof(*txidp)); + return(0); + } } int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index a10c4fc0c..d63ffa0f6 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -13,8 +13,6 @@ * * ******************************************************************************/ -int32_t NUM_PRICES; uint32_t *PVALS; - #define USD 0 #define MAX_CURRENCIES 32 diff --git a/src/main.cpp b/src/main.cpp index be9d34e40..ba779dc19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3328,14 +3328,14 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned return (nFound >= nRequired); } +void komodo_currentheight_set(int32_t height); bool ProcessNewBlock(int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) { // Preliminary checks - extern int32_t CURRENT_HEIGHT; bool checked; if ( chainActive.Tip() != 0 ) - CURRENT_HEIGHT = chainActive.Tip()->nHeight; + komodo_currentheight_set(chainActive.Tip()->nHeight); if ( ASSETCHAINS_SYMBOL[0] == 0 ) checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state); else checked = CheckBlock(0,0,*pblock, state); diff --git a/src/pow.cpp b/src/pow.cpp index e9d092bb2..661e0c9d0 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -106,7 +106,8 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33); int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]); -extern int32_t KOMODO_CHOSEN_ONE,CURRENT_HEIGHT; +int32_t komodo_currentheight(); +extern int32_t KOMODO_CHOSEN_ONE; extern int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params) @@ -116,7 +117,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in bnTarget.SetCompact(nBits, &fNegative, &fOverflow); if ( height == 0 ) - height = CURRENT_HEIGHT + 1; + height = komodo_currentheight() + 1; if ( height > 34000 ) // 0 -> non-special notary { special = komodo_chosennotary(¬aryid,height,pubkey33); diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index b2f8aa0b2..9cc9d4d12 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -40,11 +40,12 @@ using namespace std; * Or alternatively, create a specific query method for the information. **/ uint64_t komodo_interestsum(); +int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp); Value getinfo(const Array& params, bool fHelp) { - extern uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; - extern int32_t NOTARIZED_HEIGHT; + uint256 notarized_hash,notarized_desttxid; + int32_t notarized_height; if (fHelp || params.size() != 0) throw runtime_error( "getinfo\n" @@ -81,13 +82,14 @@ Value getinfo(const Array& params, bool fHelp) proxyType proxy; GetProxy(NET_IPV4, proxy); + notarized_height = komodo_notarized_height(¬arized_hash,¬arized_desttxid); Object obj; obj.push_back(Pair("version", CLIENT_VERSION)); obj.push_back(Pair("protocolversion", PROTOCOL_VERSION)); - obj.push_back(Pair("notarized", NOTARIZED_HEIGHT)); - obj.push_back(Pair("notarizedhash", NOTARIZED_HASH.ToString())); - obj.push_back(Pair("notarizedtxid", NOTARIZED_DESTTXID.ToString())); + obj.push_back(Pair("notarized", notarized_height)); + obj.push_back(Pair("notarizedhash", notarized_hash.ToString())); + obj.push_back(Pair("notarizedtxid", notarized_desttxid.ToString())); #ifdef ENABLE_WALLET if (pwalletMain) { obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); From 6d5cb6d448764965b50bdd52911bfb91e3981376 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:15:45 -0300 Subject: [PATCH 12/65] test --- src/komodo.h | 2 ++ src/komodo_utils.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index f041e54b7..5dde73472 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -30,6 +30,8 @@ #include #include #include +#include "uthash.h" +#include "utlist.h" #define GENESIS_NBITS 0x1f00ffff #define KOMODO_MINRATIFY 7 diff --git a/src/komodo_utils.h b/src/komodo_utils.h index ec2e2ce9d..7669d8c12 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -34,8 +34,6 @@ union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uin typedef union _bits256 bits256; #include "mini-gmp.c" -#include "uthash.h" -#include "utlist.h" #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" From e4e76989a06934e369704b2f13f4a1e3ba68cded Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:21:56 -0300 Subject: [PATCH 13/65] test --- src/komodo.h | 32 ++++++++++++++++---------------- src/komodo_bitcoind.h | 1 + src/komodo_notary.h | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 5dde73472..f0276b46e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -71,23 +71,7 @@ struct komodo_state // gateway state } KOMODO_STATES[33]; -#include "komodo_globals.h" #include "komodo_utils.h" - -#include "cJSON.c" -#include "komodo_bitcoind.h" -#include "komodo_interest.h" -#include "komodo_pax.h" -#include "komodo_notary.h" -#include "komodo_gateway.h" -#include "komodo_events.h" - -void komodo_setkmdheight(int32_t kmdheight) -{ - if ( kmdheight > KMDHEIGHT ) - KMDHEIGHT = kmdheight; -} - struct komodo_state *komodo_stateptr(char *symbol,char *dest) { int32_t baseid; struct komodo_state *sp; @@ -112,6 +96,22 @@ struct komodo_state *komodo_stateptr(char *symbol,char *dest) return(sp); } +#include "komodo_globals.h" + +#include "cJSON.c" +#include "komodo_bitcoind.h" +#include "komodo_interest.h" +#include "komodo_pax.h" +#include "komodo_notary.h" +#include "komodo_gateway.h" +#include "komodo_events.h" + +void komodo_setkmdheight(int32_t kmdheight) +{ + if ( kmdheight > KMDHEIGHT ) + KMDHEIGHT = kmdheight; +} + void komodo_currentheight_set(int32_t height) { char symbol[16],dest[16]; struct komodo_state *sp; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c4e5b9822..60dc16c97 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -463,6 +463,7 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } +void komodo_currentheight_set(int32_t height); int8_t komodo_minerid(int32_t height) { static uint32_t depth; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 8fc4f765a..195d8c210 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -120,7 +120,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) { static int32_t hwmheight; - int32_t k,i,htind,nonz; struct knotary_entry *kp; struct knotaries_entry N; + int32_t k,i,htind,nonz,height; struct knotary_entry *kp; struct knotaries_entry N; if ( Pubkeys == 0 ) Pubkeys = (struct knotaries_entry *)calloc(KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP,sizeof(*Pubkeys)); memset(&N,0,sizeof(N)); From 9fb37168070dd45de9fb17dbc3eee6220e9a87e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:23:39 -0300 Subject: [PATCH 14/65] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index f0276b46e..8058acc1e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -71,6 +71,7 @@ struct komodo_state // gateway state } KOMODO_STATES[33]; +#include "komodo_globals.h" #include "komodo_utils.h" struct komodo_state *komodo_stateptr(char *symbol,char *dest) { @@ -96,7 +97,6 @@ struct komodo_state *komodo_stateptr(char *symbol,char *dest) return(sp); } -#include "komodo_globals.h" #include "cJSON.c" #include "komodo_bitcoind.h" From 40d4047da2664ed71df66ad31973d61527a119e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:29:04 -0300 Subject: [PATCH 15/65] test --- src/komodo.h | 10 +++++----- src/komodo_bitcoind.h | 2 +- src/komodo_events.h | 11 ++++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 8058acc1e..f45aa5130 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -97,6 +97,11 @@ struct komodo_state *komodo_stateptr(char *symbol,char *dest) return(sp); } +void komodo_setkmdheight(int32_t kmdheight) +{ + if ( kmdheight > KMDHEIGHT ) + KMDHEIGHT = kmdheight; +} #include "cJSON.c" #include "komodo_bitcoind.h" @@ -106,11 +111,6 @@ struct komodo_state *komodo_stateptr(char *symbol,char *dest) #include "komodo_gateway.h" #include "komodo_events.h" -void komodo_setkmdheight(int32_t kmdheight) -{ - if ( kmdheight > KMDHEIGHT ) - KMDHEIGHT = kmdheight; -} void komodo_currentheight_set(int32_t height) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 60dc16c97..44656808c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -463,7 +463,7 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } -void komodo_currentheight_set(int32_t height); +void komodo_currentheight(); int8_t komodo_minerid(int32_t height) { static uint32_t depth; diff --git a/src/komodo_events.h b/src/komodo_events.h index dcd589e13..18853ef0f 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -63,7 +63,7 @@ struct komodo_event *komodo_eventadd(int32_t height,char *symbol,uint8_t type,ui strcpy(ep->symbol,symbol); if ( datalen != 0 ) memcpy(ep->space,data,datalen); - Komodo_events = realloc(Komodo_events,(1 + Komodo_numevents) * sizeof(*Komodo_events)); + Komodo_events = (struct komodo_event **)realloc(Komodo_events,(1 + Komodo_numevents) * sizeof(*Komodo_events)); Komodo_events[Komodo_numevents++] = ep; return(ep); } @@ -72,8 +72,8 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig { struct komodo_event_notarized N; memset(&N,0,sizeof(N)); - N.blockhash = blockhash; - N.desttxid = desttxid; + N.blockhash = notarized_hash; + N.desttxid = notarized_desttxid; N.notarizedheight = notarizedheight; strcpy(N.dest,dest); komodo_eventadd(height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); @@ -92,7 +92,7 @@ void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height komodo_notarysinit(height,pubkeys,num); } -void komodo_eventadd_utxo(struct komodo_state *sp,char *symbol,int32_t height,uint8_t notaryid,bits256 txid,uint64_t voutmask,uint8_t numvouts) +void komodo_eventadd_utxo(struct komodo_state *sp,char *symbol,int32_t height,uint8_t notaryid,uint256 txid,uint64_t voutmask,uint8_t numvouts) { struct komodo_event_utxo U; memset(&U,0,sizeof(U)); @@ -122,7 +122,7 @@ void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t heig komodo_setkmdheight(kmdheight); } -void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t height,bits256 txid,uint64_t value,uint16_t vout,uint8_t *buf,uint16_t opretlen) +void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t height,uint256 txid,uint64_t value,uint16_t vout,uint8_t *buf,uint16_t opretlen) { struct komodo_event_opreturn O; uint8_t opret[10000]; memset(&O,0,sizeof(O)); @@ -153,6 +153,7 @@ void komodo_event_undo(struct komodo_event *ep) void komodo_event_rewind(int32_t height) { + struct komodo_event *ep; while ( Komodo_numevents > 0 ) { if ( (ep= Komodo_events[Komodo_numevents-1]) != 0 ) From 1e6dafe078287d7f7457a77668644961191cac54 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:32:09 -0300 Subject: [PATCH 16/65] test --- src/komodo_bitcoind.h | 2 +- src/komodo_events.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 44656808c..4d51f8df6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -463,7 +463,7 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } -void komodo_currentheight(); +int32_t komodo_currentheight(); int8_t komodo_minerid(int32_t height) { static uint32_t depth; diff --git a/src/komodo_events.h b/src/komodo_events.h index 18853ef0f..600dac2d6 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -35,10 +35,10 @@ #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain #define KOMODO_OPRETURN_REDEEMED 'X' -struct komodo_event_notarized { bits256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; } PACKED; +struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; } PACKED; struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; } PACKED; -struct komodo_event_utxo { bits256 txid; uint64_t voutmask; uint8_t numvouts; } PACKED; -struct komodo_event_opreturn { bits256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; } PACKED; +struct komodo_event_utxo { uint256 txid; uint64_t voutmask; uint8_t numvouts; } PACKED; +struct komodo_event_opreturn { uint256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; } PACKED; struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; } PACKED; struct komodo_event From 2df2f1937ddda5ce9e9f9897f785a1d4434b04b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:36:51 -0300 Subject: [PATCH 17/65] test --- src/komodo.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index f45aa5130..9d0dd3857 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -130,7 +130,7 @@ int32_t komodo_currentheight() int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char *dest) { static int32_t errs; - char symbol[16]; int32_t func,ht,notarized_height,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; + int32_t func,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; if ( (func= fgetc(fp)) != EOF ) { if ( ASSETCHAINS_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 ) @@ -176,7 +176,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) ) errs++; if ( matched != 0 ) - komodo_eventadd_utxo(sp,symbol,ht,nid,hash,voutmask,n); + komodo_eventadd_utxo(sp,symbol,ht,nid,hash,mask,n); } else if ( func == 'K' ) { @@ -202,7 +202,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( fread(opret,1,olen,fp) != olen ) errs++; if ( matched != 0 ) - komodo_eventadd_opreturn(sp,symbol,ht,txid,ovalue,v,opret,opretlen); + komodo_eventadd_opreturn(sp,symbol,ht,txid,ovalue,v,opret,olen); } else printf("illegal olen.%u\n",olen); } else if ( func == 'D' ) @@ -216,7 +216,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( numpvals*sizeof(uint32_t) <= sizeof(pvals) && fread(pvals,sizeof(uint32_t),numpvals,fp) == numpvals ) { if ( matched != 0 ) - komodo_eventadd_pricefeed(sp,symbol,height,pvals,numpvals); + komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals); //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); } else printf("error loading pvals[%d]\n",numpvals); } @@ -365,7 +365,9 @@ 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) { - static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; + static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16]; + if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) + return(-1); if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); From bd787f59c3266d971014540af5a822a151ba3c9a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:41:10 -0300 Subject: [PATCH 18/65] test --- src/komodo_events.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_events.h b/src/komodo_events.h index 600dac2d6..8351ae37d 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -35,11 +35,11 @@ #define KOMODO_OPRETURN_WITHDRAW 'W' // assetchain #define KOMODO_OPRETURN_REDEEMED 'X' -struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; } PACKED; -struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; } PACKED; -struct komodo_event_utxo { uint256 txid; uint64_t voutmask; uint8_t numvouts; } PACKED; -struct komodo_event_opreturn { uint256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; } PACKED; -struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; } PACKED; +struct komodo_event_notarized { uint256 blockhash,desttxid; int32_t notarizedheight; char dest[16]; }; +struct komodo_event_pubkeys { uint8_t num; uint8_t pubkeys[64][33]; }; +struct komodo_event_utxo { uint256 txid; uint64_t voutmask; uint8_t numvouts; }; +struct komodo_event_opreturn { uint256 txid; uint64_t value; uint16_t vout,oplen; uint8_t opret[]; }; +struct komodo_event_pricefeed { uint8_t num; uint32_t prices[35]; }; struct komodo_event { From b1d10624b7df47e5a7d3f4d62c17e24f219cbfa8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:44:17 -0300 Subject: [PATCH 19/65] test --- src/komodo_utils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7669d8c12..ec2e2ce9d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -34,6 +34,8 @@ union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uin typedef union _bits256 bits256; #include "mini-gmp.c" +#include "uthash.h" +#include "utlist.h" #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" From 3face66929220827b6a5f171f4cd5c4263448ebe Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:48:05 -0300 Subject: [PATCH 20/65] test --- src/bitcoin-cli.cpp | 1 + src/komodo.h | 17 ++--------------- src/komodo_globals.h | 1 + src/komodo_structs.h | 29 +++++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 src/komodo_structs.h diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index e7b0b1476..982e27688 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -60,6 +60,7 @@ public: #include "arith_uint256.h" int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks +#include "komodo_structs.h" #include "komodo_globals.h" #include "komodo_utils.h" diff --git a/src/komodo.h b/src/komodo.h index 9d0dd3857..069019fd5 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -37,25 +37,12 @@ #define KOMODO_MINRATIFY 7 #define KOMODO_MAXBLOCKS 5000000 +#include "komodo_structs.h" + FILE *Minerfp; int8_t Minerids[KOMODO_MAXBLOCKS]; // 5 million blocks #define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) -struct pax_transaction -{ - UT_hash_handle hh; - uint256 txid; - uint64_t komodoshis,fiatoshis; - int32_t marked,height,otherheight; - uint16_t vout; - char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; -}; - -struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; }; -struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; -struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; }; -struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; }; -pthread_mutex_t komodo_mutex; int32_t KMDHEIGHT = 43000; struct pax_transaction *PAX; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 693bf429a..bd04931ae 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -21,6 +21,7 @@ void komodo_init(int32_t height); void komodo_assetchain_pubkeys(char *jsonstr); int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33); +pthread_mutex_t komodo_mutex; int COINBASE_MATURITY = 100; int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND; diff --git a/src/komodo_structs.h b/src/komodo_structs.h new file mode 100644 index 000000000..138051231 --- /dev/null +++ b/src/komodo_structs.h @@ -0,0 +1,29 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +struct pax_transaction +{ + UT_hash_handle hh; + uint256 txid; + uint64_t komodoshis,fiatoshis; + int32_t marked,height,otherheight; + uint16_t vout; + char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; +}; + +struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; }; +struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; +struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; }; +struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; }; From 5fb7481741c90ea70a96274ea03a0de9ac1e7968 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:50:27 -0300 Subject: [PATCH 21/65] test --- src/komodo_structs.h | 3 +++ src/komodo_utils.h | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 138051231..dcf9fdbc5 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -13,6 +13,9 @@ * * ******************************************************************************/ +#include "uthash.h" +#include "utlist.h" + struct pax_transaction { UT_hash_handle hh; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index ec2e2ce9d..7669d8c12 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -34,8 +34,6 @@ union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uin typedef union _bits256 bits256; #include "mini-gmp.c" -#include "uthash.h" -#include "utlist.h" #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" From 0db8cd28d8831f96427d6d2502f25f868a1113e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:53:12 -0300 Subject: [PATCH 22/65] test --- src/bitcoin-cli.cpp | 1 - src/komodo.h | 11 ----------- src/komodo_globals.h | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 982e27688..53204a8c4 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -59,7 +59,6 @@ public: #include "uint256.h" #include "arith_uint256.h" -int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks #include "komodo_structs.h" #include "komodo_globals.h" diff --git a/src/komodo.h b/src/komodo.h index 069019fd5..38f9a68b1 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -39,17 +39,6 @@ #include "komodo_structs.h" -FILE *Minerfp; -int8_t Minerids[KOMODO_MAXBLOCKS]; // 5 million blocks -#define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) - -int32_t KMDHEIGHT = 43000; - -struct pax_transaction *PAX; -int32_t NUM_PRICES; uint32_t *PVALS; -struct knotaries_entry *Pubkeys; -struct nutxo_entry *NUTXOS; int32_t Num_nutxos; -struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS; struct komodo_state { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index bd04931ae..cf3241407 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -22,6 +22,20 @@ void komodo_assetchain_pubkeys(char *jsonstr); int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33); pthread_mutex_t komodo_mutex; + +FILE *Minerfp; +int8_t Minerids[KOMODO_MAXBLOCKS]; // 5 million blocks +#define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) + +int32_t KMDHEIGHT = 43000; + +struct pax_transaction *PAX; +int32_t NUM_PRICES; uint32_t *PVALS; +struct knotaries_entry *Pubkeys; +struct nutxo_entry *NUTXOS; int32_t Num_nutxos; +struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS; + + int COINBASE_MATURITY = 100; int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND; From d1289e418c79281085e82360d2b55d1b2f78c015 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:55:46 -0300 Subject: [PATCH 23/65] test --- src/komodo.h | 7 +------ src/komodo_structs.h | 7 +++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 38f9a68b1..0e7ff2af0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -40,12 +40,7 @@ #include "komodo_structs.h" -struct komodo_state -{ - uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; - int32_t CURRENT_HEIGHT,NOTARIZED_HEIGHT; - // gateway state -} KOMODO_STATES[33]; +struct komodo_state KOMODO_STATES[33]; #include "komodo_globals.h" #include "komodo_utils.h" diff --git a/src/komodo_structs.h b/src/komodo_structs.h index dcf9fdbc5..ee65a20cb 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -30,3 +30,10 @@ struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32 struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; }; struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; }; + +struct komodo_state +{ + uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; + int32_t CURRENT_HEIGHT,NOTARIZED_HEIGHT; + // gateway state +}; From 45a3a2ff00940558da92d6d85426eff90207dd46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 18:59:14 -0300 Subject: [PATCH 24/65] test --- src/komodo.h | 5 ----- src/komodo_structs.h | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0e7ff2af0..540fdb3e6 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -33,13 +33,8 @@ #include "uthash.h" #include "utlist.h" -#define GENESIS_NBITS 0x1f00ffff -#define KOMODO_MINRATIFY 7 -#define KOMODO_MAXBLOCKS 5000000 - #include "komodo_structs.h" - struct komodo_state KOMODO_STATES[33]; #include "komodo_globals.h" diff --git a/src/komodo_structs.h b/src/komodo_structs.h index ee65a20cb..946eb708a 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -16,6 +16,10 @@ #include "uthash.h" #include "utlist.h" +#define GENESIS_NBITS 0x1f00ffff +#define KOMODO_MINRATIFY 7 +#define KOMODO_MAXBLOCKS 5000000 + struct pax_transaction { UT_hash_handle hh; From 5a630fc3ca23e5e26b546dd2256ddda5a784e5e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 19:01:47 -0300 Subject: [PATCH 25/65] test --- src/komodo_notary.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 195d8c210..ab18d578d 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -202,6 +202,7 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not sp->NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid; } +struct komodo_state *komodo_stateptr(char *symbol,char *dest); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) { char symbol[16],dest[16]; struct komodo_state *sp; From 1bfdde1da3a72b1508bdd9a7daf9802d6e22a244 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 19:06:21 -0300 Subject: [PATCH 26/65] test --- src/komodo.h | 24 +----------------------- src/komodo_utils.h | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 540fdb3e6..d49b3224c 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -39,29 +39,7 @@ struct komodo_state KOMODO_STATES[33]; #include "komodo_globals.h" #include "komodo_utils.h" -struct komodo_state *komodo_stateptr(char *symbol,char *dest) -{ - int32_t baseid; struct komodo_state *sp; - if ( ASSETCHAINS_SYMBOL[0] == 0 ) - { - strcpy(symbol,"KMD"); - strcpy(dest,"BTC"); - sp = &KOMODO_STATES[0]; - } - else - { - strcpy(symbol,ASSETCHAINS_SYMBOL); - strcpy(dest,"KMD"); - if ( (baseid= komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 ) - sp = &KOMODO_STATES[baseid]; - else - { - fprintf(stderr,"komodo_stateupdate.(%s) not supported\n",ASSETCHAINS_SYMBOL); - return(0); - } - } - return(sp); -} + void komodo_setkmdheight(int32_t kmdheight) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7669d8c12..78d38141d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1417,4 +1417,28 @@ void komodo_args() //fprintf(stderr,"IS_KOMODO_NOTARY %d %s\n",IS_KOMODO_NOTARY,NOTARY_PUBKEY.c_str()); } //fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL); -} \ No newline at end of file +} + +struct komodo_state *komodo_stateptr(char *symbol,char *dest) +{ + int32_t baseid; struct komodo_state *sp; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + { + strcpy(symbol,"KMD"); + strcpy(dest,"BTC"); + sp = &KOMODO_STATES[0]; + } + else + { + strcpy(symbol,ASSETCHAINS_SYMBOL); + strcpy(dest,"KMD"); + if ( (baseid= komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 ) + sp = &KOMODO_STATES[baseid]; + else + { + fprintf(stderr,"komodo_stateupdate.(%s) not supported\n",ASSETCHAINS_SYMBOL); + return(0); + } + } + return(sp); +} From ca3cf9aa3f6a284ec82c587597a873565843b56a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 19:08:33 -0300 Subject: [PATCH 27/65] test --- src/komodo.h | 2 -- src/komodo_globals.h | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d49b3224c..514919428 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -35,8 +35,6 @@ #include "komodo_structs.h" -struct komodo_state KOMODO_STATES[33]; - #include "komodo_globals.h" #include "komodo_utils.h" diff --git a/src/komodo_globals.h b/src/komodo_globals.h index cf3241407..86cc65ad8 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -35,6 +35,7 @@ struct knotaries_entry *Pubkeys; struct nutxo_entry *NUTXOS; int32_t Num_nutxos; struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS; +struct komodo_state KOMODO_STATES[33]; int COINBASE_MATURITY = 100; From 97fdbcc2ab43293b89c2a3e598f256bbca591583 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 19:11:41 -0300 Subject: [PATCH 28/65] test --- src/komodo-tx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index d5e333093..46004a92e 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -25,6 +25,7 @@ using namespace std; #include "uint256.h" #include "arith_uint256.h" +#include "komodo_structs.h" #include "komodo_globals.h" #include "komodo_interest.h" From 6423c8a9acb80c56a895de950acec974e9f01f63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 19:21:14 -0300 Subject: [PATCH 29/65] test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 514919428..bd1f2e2a1 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -491,7 +491,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { if ( (k= komodo_nutxofind(height,block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) >= 0 ) signedmask |= (1LL << k); - else if ( 0 && signedmask != 0 ) + else if ( signedmask != 0 ) printf("signedmask.%llx but ht.%d i.%d j.%d not found (%s %d)\n",(long long)signedmask,height,i,j,block.vtx[i].vin[j].prevout.hash.ToString().c_str(),block.vtx[i].vin[j].prevout.n); } if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) ) @@ -526,7 +526,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) memset(&txhash,0,sizeof(txhash)); komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0); printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height); - } + } else printf("signedmask.%llx numvalid.%d wt.%d numnotaries.%d\n",(long long)signedmask,numvalid,bitweight(signedmask),numnotaries); } } } From 27a7b467329f5805e7f2c4be2782cbe8d1bcddc9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 19:29:39 -0300 Subject: [PATCH 30/65] test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index ab18d578d..1e87bf7b3 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -139,7 +139,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) memcpy(kp->pubkey,pubkeys[k],33); kp->notaryid = k; HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp); - if ( height > 0 ) + //if ( height > 0 ) { for (i=0; i<33; i++) printf("%02x",pubkeys[k][i]); From 6806478bbfc9a16cdb723164d755cd3d96ee5a99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 19:49:43 -0300 Subject: [PATCH 31/65] test --- src/komodo.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index bd1f2e2a1..ecda8ef52 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -373,12 +373,11 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_paxpricefeed(height,&scriptbuf[len],opretlen); else { - //int32_t k; for (k=0; k= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) { - iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); for (k=0; k<32; k++) if ( scriptbuf[len+k] != 0 ) break; From 76d237f6192aeb0de0f8dd6e6aaca0d9bb797770 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 20:44:49 -0300 Subject: [PATCH 32/65] test --- src/pow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index 661e0c9d0..dc7c2f553 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -133,7 +133,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in if ( notaryid >= 0 ) { special2 = komodo_is_special(height,pubkey33); - if ( 0 && special2 == -2 ) + if ( special2 == -2 ) printf("height.%d special2.%d special.%d\n",height,special2,special); if ( special2 == -2 || (height < 70000 && (special != 0 || special2 > 0)) || (height >= 70000 && special2 > 0) ) @@ -159,9 +159,9 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { - //for (i=0; i<33; i++) - // printf("%02x",pubkey33[i]); - //printf(" special.%d notaryid.%d ht.%d mod.%d error\n",special,notaryid,height,(height % 35)); + for (i=0; i<33; i++) + printf("%02x",pubkey33[i]); + printf(" special.%d notaryid.%d ht.%d mod.%d error\n",special,notaryid,height,(height % 35)); return error("CheckProofOfWork(): hash doesn't match nBits"); } return true; From 050cb9a331e773319cec7d8490f4ef4ba62c4ebb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 20:49:41 -0300 Subject: [PATCH 33/65] test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 1e87bf7b3..3ef45a6ab 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -164,7 +164,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) // -1 if not notary, 0 if notary, 1 if special notary struct knotary_entry *kp; int32_t numnotaries,htind,modval = -1; *notaryidp = -1; - if ( height < 0 || height/KOMODO_ELECTION_GAP >= sizeof(Pubkeys)/sizeof(*Pubkeys) ) + if ( height < 0 || height >= KOMODO_MAXBLOCKS ) return(-1); htind = height / KOMODO_ELECTION_GAP; pthread_mutex_lock(&komodo_mutex); From 05f10aebc34439892ebdf2eb45b16bf4e693d428 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 20:52:48 -0300 Subject: [PATCH 34/65] test --- src/komodo_notary.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 3ef45a6ab..c3676caa3 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -165,7 +165,10 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) struct knotary_entry *kp; int32_t numnotaries,htind,modval = -1; *notaryidp = -1; if ( height < 0 || height >= KOMODO_MAXBLOCKS ) + { + printf("komodo_chosennotary ht.%d illegal\n",height); return(-1); + } htind = height / KOMODO_ELECTION_GAP; pthread_mutex_lock(&komodo_mutex); HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp); @@ -176,12 +179,12 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) { *notaryidp = kp->notaryid; modval = ((height % numnotaries) == kp->notaryid); - //printf("found notary.%d ht.%d modval.%d\n",kp->notaryid,height,modval); + printf("found notary.%d ht.%d modval.%d\n",kp->notaryid,height,modval); } else printf("unexpected zero notaries at height.%d\n",height); } - //int32_t i; for (i=0; i<33; i++) - // printf("%02x",pubkey33[i]); - //printf(" ht.%d notary.%d special.%d\n",height,*notaryidp,modval); + int32_t i; for (i=0; i<33; i++) + printf("%02x",pubkey33[i]); + printf(" ht.%d notary.%d special.%d\n",height,*notaryidp,modval); return(modval); } From 2e3cada2e8f5ffe63e0f847b54b2a5bf41fa7f92 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Nov 2016 20:57:11 -0300 Subject: [PATCH 35/65] test --- src/komodo_notary.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index c3676caa3..f11ed60a7 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -147,7 +147,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) } } N.numnotaries = num; - for (i=htind; i= KOMODO_MAXBLOCKS ) { @@ -179,12 +179,12 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) { *notaryidp = kp->notaryid; modval = ((height % numnotaries) == kp->notaryid); - printf("found notary.%d ht.%d modval.%d\n",kp->notaryid,height,modval); + //printf("found notary.%d ht.%d modval.%d\n",kp->notaryid,height,modval); } else printf("unexpected zero notaries at height.%d\n",height); } - int32_t i; for (i=0; i<33; i++) - printf("%02x",pubkey33[i]); - printf(" ht.%d notary.%d special.%d\n",height,*notaryidp,modval); + //int32_t i; for (i=0; i<33; i++) + // printf("%02x",pubkey33[i]); + //printf(" ht.%d notary.%d special.%d htind.%d num.%d\n",height,*notaryidp,modval,htind,numnotaries); return(modval); } From 165149118f9594b7e5ab1bddb3f358a2f4864162 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 05:05:42 -0300 Subject: [PATCH 36/65] test --- src/main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ba779dc19..50e47689f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3235,15 +3235,13 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc if (mi == mapBlockIndex.end()) return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); pindexPrev = (*mi).second; - if (pindexPrev->nStatus & BLOCK_FAILED_MASK) + if (pindexPrev == 0 || (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); } if (!ContextualCheckBlockHeader(block, state, pindexPrev)) return false; if (pindex == NULL) pindex = AddToBlockIndex(block); - //if (!CheckBlockHeader(pindex!=0?pindex->nHeight:0,pindex, block, state)) - // return false; if (ppindex) *ppindex = pindex; return true; From 60e0c887c56347a983a7ac2ed6b1d15335654857 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 05:11:56 -0300 Subject: [PATCH 37/65] 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 4d51f8df6..c212ef7bb 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -468,13 +468,13 @@ int8_t komodo_minerid(int32_t height) { static uint32_t depth; int32_t notaryid; CBlockIndex *pindex; uint8_t pubkey33[33]; - if ( depth < 3 && height <= komodo_currentheight() )//chainActive.Tip()->nHeight ) + if ( Minerids[height] >= -1 ) + { + printf("cached[%d] -> %d\n",height,Minerids[height]); + return(Minerids[height]); + } + if ( depth < 1 ) { - if ( Minerids[height] >= -1 ) - { - printf("cached[%d] -> %d\n",height,Minerids[height]); - return(Minerids[height]); - } if ( (pindex= chainActive[height]) != 0 ) { depth++; From fc318ffe5d691103b11e3490c9aeca6bc581a755 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 07:32:46 -0300 Subject: [PATCH 38/65] test --- src/komodo.h | 4 ++-- src/komodo_bitcoind.h | 27 +++++++++++++++++++++------ src/rpcblockchain.cpp | 23 +++++++++++++++++++++++ 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index ecda8ef52..18f32f4fa 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -33,12 +33,12 @@ #include "uthash.h" #include "utlist.h" -#include "komodo_structs.h" +int32_t gettxout_scriptPubKey(uint8_t *scriptPubkey,int32_t maxsize,uint256 txid,int32_t n); +#include "komodo_structs.h" #include "komodo_globals.h" #include "komodo_utils.h" - void komodo_setkmdheight(int32_t kmdheight) { if ( kmdheight > KMDHEIGHT ) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c212ef7bb..21cc0e619 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -463,12 +463,27 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } -int32_t komodo_currentheight(); int8_t komodo_minerid(int32_t height) { - static uint32_t depth; - int32_t notaryid; CBlockIndex *pindex; uint8_t pubkey33[33]; - if ( Minerids[height] >= -1 ) + //static uint32_t depth; + int32_t notaryid,num,i; CBlockIndex *pindex; uint8_t pubkeys[64][33],script[35]; + if ( (pindex= chainActive[height]) != 0 ) + { + if ( gettxout_scriptPubKey(script,sizeof(script),pindex->vtx[0].GetHash(),0) == 35 ) + { + if ( (num= komodo_notaries(pubkeys,height)) > 0 ) + { + for (i=0; i= -1 ) { printf("cached[%d] -> %d\n",height,Minerids[height]); return(Minerids[height]); @@ -493,7 +508,7 @@ int8_t komodo_minerid(int32_t height) depth--; return(notaryid); } - } + }*/ return(-2); } @@ -510,7 +525,7 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) Minerids[height-i] = komodo_minerid(height-i); if ( Minerids[height - i] == -2 ) { - //fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,komodo_currentheight()); + fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,komodo_currentheight()); return(-2); } } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ae9f41540..fa5a5e9ea 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -589,6 +589,29 @@ Value gettxout(const Array& params, bool fHelp) return ret; } +int32_t gettxout_scriptPubKey(uint8_t *scriptPubkey,int32_t maxsize,uint256 txid,int32_t n) +{ + int32_t i,m; uint8_t *ptr; + LOCK(cs_main); + CCoins coins; + if (fMempool) + { + LOCK(mempool.cs); + CCoinsViewMemPool view(pcoinsTip,mempool); + if ( view.GetCoins(txid,coins) == 0 ) + return(-1); + mempool.pruneSpent(txid, coins); // TODO: this should be done by the CCoinsViewMemPool + } else if ( pcoinsTip->GetCoins(txid,coins) == 0 ) + return(-1); + if ( n < 0 || (unsigned int)n >= coins.vout.size() || coins.vout[n].IsNull() ) + return(-1); + ptr = (uint8_t *)coins.vout[n].scriptPubKey.data(); + m = coins.vout[n].scriptPubKey.size(); + for (i=0; i 2) From 6034c671dcfe9463d0d9fe3ca1f1c7caaf77593d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 07:42:50 -0300 Subject: [PATCH 39/65] test --- src/komodo_bitcoind.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 21cc0e619..ee7c46c78 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -463,13 +463,15 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } +int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); + int8_t komodo_minerid(int32_t height) { //static uint32_t depth; int32_t notaryid,num,i; CBlockIndex *pindex; uint8_t pubkeys[64][33],script[35]; if ( (pindex= chainActive[height]) != 0 ) { - if ( gettxout_scriptPubKey(script,sizeof(script),pindex->vtx[0].GetHash(),0) == 35 ) + if ( gettxout_scriptPubKey(script,sizeof(script),pindex->block.vtx[0].GetHash(),0) == 35 ) { if ( (num= komodo_notaries(pubkeys,height)) > 0 ) { @@ -508,8 +510,8 @@ int8_t komodo_minerid(int32_t height) depth--; return(notaryid); } - }*/ - return(-2); + } + return(-2);*/ } int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) @@ -525,7 +527,7 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) Minerids[height-i] = komodo_minerid(height-i); if ( Minerids[height - i] == -2 ) { - fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,komodo_currentheight()); + fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,height); return(-2); } } From 42c75f1f02cedfe3175970387c62f582d933e4a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 07:54:53 -0300 Subject: [PATCH 40/65] test --- src/komodo_bitcoind.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ee7c46c78..6761855dd 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -468,19 +468,26 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); int8_t komodo_minerid(int32_t height) { //static uint32_t depth; - int32_t notaryid,num,i; CBlockIndex *pindex; uint8_t pubkeys[64][33],script[35]; + CBlock block; int32_t notaryid,num,i; CBlockIndex *pindex; uint8_t pubkeys[64][33],script[35]; if ( (pindex= chainActive[height]) != 0 ) { - if ( gettxout_scriptPubKey(script,sizeof(script),pindex->block.vtx[0].GetHash(),0) == 35 ) + if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex +#ifndef KOMODO_ZCASH + ,Params().GetConsensus() +#endif + ) != 0 ) { - if ( (num= komodo_notaries(pubkeys,height)) > 0 ) + if ( gettxout_scriptPubKey(script,sizeof(script),block.vtx[0].GetHash(),0) == 35 ) { - for (i=0; i 0 ) + { + for (i=0; i Date: Fri, 18 Nov 2016 07:57:22 -0300 Subject: [PATCH 41/65] test --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index fa5a5e9ea..c7c525a4e 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -589,12 +589,12 @@ Value gettxout(const Array& params, bool fHelp) return ret; } -int32_t gettxout_scriptPubKey(uint8_t *scriptPubkey,int32_t maxsize,uint256 txid,int32_t n) +int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid,int32_t n) { int32_t i,m; uint8_t *ptr; LOCK(cs_main); CCoins coins; - if (fMempool) + if ( 1 ) { LOCK(mempool.cs); CCoinsViewMemPool view(pcoinsTip,mempool); From e21ffa1d2f42456827cea1b87b487c2c300705d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 08:07:26 -0300 Subject: [PATCH 42/65] test --- src/komodo.h | 14 +++++++------- src/komodo_bitcoind.h | 44 ++++--------------------------------------- src/komodo_globals.h | 4 ++-- src/komodo_notary.h | 4 ++-- 4 files changed, 15 insertions(+), 51 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 18f32f4fa..320904725 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -170,19 +170,19 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { static FILE *fp; static int32_t errs; - struct komodo_state *sp; char fname[512],fname2[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33]; + struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33]; if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) return; if ( fp == 0 ) { #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); - sprintf(fname2,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"minerids"); + //sprintf(fname2,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"minerids"); #else sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); - sprintf(fname2,"%s/%s",GetDataDir(false).string().c_str(),(char *)"minerids"); + //sprintf(fname2,"%s/%s",GetDataDir(false).string().c_str(),(char *)"minerids"); #endif - memset(Minerids,0xfe,sizeof(Minerids)); + /*memset(Minerids,0xfe,sizeof(Minerids)); if ( (Minerfp= fopen(fname2,"rb+")) == 0 ) { if ( (Minerfp= fopen(fname2,"wb")) != 0 ) @@ -193,7 +193,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar Minerfp = fopen(fname2,"rb+"); } if ( Minerfp != 0 && fread(Minerids,1,sizeof(Minerids),Minerfp) != sizeof(Minerids) ) - printf("read error Minerids\n"); + printf("read error Minerids\n");*/ if ( (fp= fopen(fname,"rb+")) != 0 ) { while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) @@ -456,7 +456,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); #endif notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue); - if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 ) + /*if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 ) { if ( height < sizeof(Minerids)/sizeof(*Minerids) ) { @@ -470,7 +470,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } - } + }*/ if ( 0 && i > 0 ) { for (k=0; knHeight); - Minerids[pindex->nHeight] = -2; + //Minerids[pindex->nHeight] = -2; //hash = block.GetHash(); //for (i=0; i<32; i++) // printf("%02x",((uint8_t *)&hash)[i]); @@ -492,53 +492,17 @@ int8_t komodo_minerid(int32_t height) } } return(-1); - /*if ( Minerids[height] >= -1 ) - { - printf("cached[%d] -> %d\n",height,Minerids[height]); - return(Minerids[height]); - } - if ( depth < 1 ) - { - if ( (pindex= chainActive[height]) != 0 ) - { - depth++; - komodo_index2pubkey33(pubkey33,pindex,height); - komodo_chosennotary(¬aryid,height,pubkey33); - if ( notaryid >= -1 ) - { - Minerids[height] = notaryid; - if ( Minerfp != 0 ) - { - fseek(Minerfp,height,SEEK_SET); - fputc(Minerids[height],Minerfp); - fflush(Minerfp); - } - } - depth--; - return(notaryid); - } - } - return(-2);*/ } int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) { - int32_t i,notaryid; + int32_t i,notaryid,minerid; komodo_chosennotary(¬aryid,height,pubkey33); if ( height >= 34000 && notaryid >= 0 ) { for (i=1; i<64; i++) { - if ( Minerids[height-i] == -2 ) - { - Minerids[height-i] = komodo_minerid(height-i); - if ( Minerids[height - i] == -2 ) - { - fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,height); - return(-2); - } - } - if ( Minerids[height-i] == notaryid ) + if ( komodo_minerid(height-i) == notaryid ) return(-1); } return(1); @@ -567,7 +531,7 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has return(-1); } } else fprintf(stderr,"unexpected error notary_hash %s ht.%d at ht.%d\n",notarized_hash.ToString().c_str(),notarized_height,notary->nHeight); - } else if ( notarized_height > 0 ) + } else if ( notarized_height > 0 && notarized_height != 73880 ) fprintf(stderr,"couldnt find notary_hash %s ht.%d\n",notarized_hash.ToString().c_str(),notarized_height); return(0); } diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 86cc65ad8..aba22a8eb 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -23,8 +23,8 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) pthread_mutex_t komodo_mutex; -FILE *Minerfp; -int8_t Minerids[KOMODO_MAXBLOCKS]; // 5 million blocks +//FILE *Minerfp; +//int8_t Minerids[KOMODO_MAXBLOCKS]; // 5 million blocks #define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) int32_t KMDHEIGHT = 43000; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index f11ed60a7..ba1bf93f6 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -264,8 +264,8 @@ void komodo_init(int32_t height) komodo_notarysinit(0,pubkeys,k); } memset(&zero,0,sizeof(zero)); - for (i=0; i Date: Fri, 18 Nov 2016 08:32:17 -0300 Subject: [PATCH 43/65] test --- src/komodo_bitcoind.h | 35 ++++++++++++++++++++--------------- src/pow.cpp | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2222fba46..1823ef151 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -471,23 +471,28 @@ int8_t komodo_minerid(int32_t height) CBlock block; int32_t notaryid,num,i; CBlockIndex *pindex; uint8_t pubkeys[64][33],script[35]; if ( (pindex= chainActive[height]) != 0 ) { - if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex -#ifndef KOMODO_ZCASH - ,Params().GetConsensus() -#endif - ) != 0 ) + block.SetNull(); + // Open history file to read + CAutoFile filein(OpenBlockFile(pindex->GetBlockPos(),true),SER_DISK,CLIENT_VERSION); + if (filein.IsNull()) + return(-1); + // Read block + try { filein >> block; } + catch (const std::exception& e) { - if ( gettxout_scriptPubKey(script,sizeof(script),block.vtx[0].GetHash(),0) == 35 ) + fprintf(stderr,"readblockfromdisk err B\n"); + return(-1); + } + if ( gettxout_scriptPubKey(script,sizeof(script),block.vtx[0].GetHash(),0) == 35 ) + { + if ( (num= komodo_notaries(pubkeys,height)) > 0 ) { - if ( (num= komodo_notaries(pubkeys,height)) > 0 ) - { - for (i=0; i Date: Fri, 18 Nov 2016 08:50:11 -0300 Subject: [PATCH 44/65] test --- src/komodo_bitcoind.h | 53 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1823ef151..bc5dc0589 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -437,7 +437,10 @@ void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0]; #endif komodo_init(0); - memcpy(pubkey33,ptr+1,33); + n = block.vtx[0].vout[0].scriptPubKey.size(); + if ( n == 35 ) + memcpy(pubkey33,ptr+1,33); + else memset(pubkey33,0,33); } void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) @@ -447,14 +450,27 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) memset(pubkey33,0,33); if ( pindex != 0 ) { - if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex + block.SetNull(); + // Open history file to read + CAutoFile filein(OpenBlockFile(pindex->GetBlockPos(),true),SER_DISK,CLIENT_VERSION); + if (filein.IsNull()) + return; + // Read block + try { filein >> block; } + catch (const std::exception& e) + { + fprintf(stderr,"readblockfromdisk err B\n"); + return; + } + komodo_block2pubkey33(pubkey33,block); +/* if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex #ifndef KOMODO_ZCASH ,Params().GetConsensus() #endif ) != 0 ) { komodo_block2pubkey33(pubkey33,block); - } + }*/ } else { @@ -467,35 +483,18 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); int8_t komodo_minerid(int32_t height) { - //static uint32_t depth; - CBlock block; int32_t notaryid,num,i; CBlockIndex *pindex; uint8_t pubkeys[64][33],script[35]; + int32_t num,i; CBlockIndex *pindex; uint8_t pubkey33[33],pubkeys[64][33]; if ( (pindex= chainActive[height]) != 0 ) { - block.SetNull(); - // Open history file to read - CAutoFile filein(OpenBlockFile(pindex->GetBlockPos(),true),SER_DISK,CLIENT_VERSION); - if (filein.IsNull()) - return(-1); - // Read block - try { filein >> block; } - catch (const std::exception& e) + komodo_index2pubkey33(pubkey33,pindex,height); + if ( (num= komodo_notaries(pubkeys,height)) > 0 ) { - fprintf(stderr,"readblockfromdisk err B\n"); - return(-1); - } - if ( gettxout_scriptPubKey(script,sizeof(script),block.vtx[0].GetHash(),0) == 35 ) - { - if ( (num= komodo_notaries(pubkeys,height)) > 0 ) - { - for (i=0; i Date: Fri, 18 Nov 2016 08:51:22 -0300 Subject: [PATCH 45/65] test --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bc5dc0589..c64226325 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -431,6 +431,7 @@ int32_t komodo_block2height(CBlock *block) void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) { + int32_t n; #ifdef KOMODO_ZCASH uint8_t *ptr = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data(); #else From 90da0ef535a72a16d4874881617b1c39dc435802 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 08:53:48 -0300 Subject: [PATCH 46/65] 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 c64226325..5ee55ec29 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -495,7 +495,7 @@ int8_t komodo_minerid(int32_t height) return(i); } } - printf("minderid not notary ht.%d\n",height); + //printf("minderid not notary ht.%d\n",height); return(-1); } From 6f3cb4d03ac342f4f46cfbe17797b2dc23404068 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 09:16:18 -0300 Subject: [PATCH 47/65] test --- src/komodo.h | 58 +++++++++++++++++++++++--------------------- src/komodo_events.h | 4 +-- src/komodo_globals.h | 2 +- src/komodo_notary.h | 4 +-- src/komodo_structs.h | 2 +- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 320904725..b431bda48 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -117,8 +117,8 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(&hash,1,sizeof(hash),fp) != sizeof(hash) ) errs++; - if ( matched != 0 ) - komodo_eventadd_utxo(sp,symbol,ht,nid,hash,mask,n); + //if ( matched != 0 ) + // komodo_eventadd_utxo(sp,symbol,ht,nid,hash,mask,n); } else if ( func == 'K' ) { @@ -262,8 +262,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(&txhash,1,sizeof(txhash),fp) != sizeof(txhash) ) errs++; - komodo_eventadd_utxo(sp,symbol,height,notaryid,txhash,voutmask,numvouts); - //komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); + //komodo_eventadd_utxo(sp,symbol,height,notaryid,txhash,voutmask,numvouts); } //#ifdef KOMODO_PAX else if ( pvals != 0 && numpvals > 0 ) @@ -407,15 +406,31 @@ int32_t komodo_isratify(int32_t isspecial,int32_t numvalid) // if txi == 0 && 2 outputs and 2nd OP_RETURN, len == 32*2+4 -> notarized, 1st byte 'P' -> pricefeed // OP_RETURN: 'D' -> deposit, 'W' -> withdraw void komodo_currentheight_set(int32_t height); +int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid,int32_t n); + +int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys[64][33],int32_t numnotaries,uint8_t rmd160[20]) +{ + int32_t i; + if ( scriptlen == 25 && memcmp(&scriptPubKey[3],rmd160,20) == 0 ) + return(0); + else if ( scriptlen == 35 ) + { + for (i=0; inHeight); numnotaries = komodo_notaries(pubkeys,pindex->nHeight); + calc_rmd160_sha256(rmd160,pubkeys[0],33); if ( pindex->nHeight > hwmheight ) hwmheight = pindex->nHeight; else @@ -437,8 +452,6 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { height = pindex->nHeight; txn_count = block.vtx.size(); - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) - printf("%s ht.%d connect txn_count.%d\n",ASSETCHAINS_SYMBOL,height,txn_count); for (i=0; i= 0 ) - { - if ( height < sizeof(Minerids)/sizeof(*Minerids) ) - { - if ( (Minerids[height]= nid) >= -1 ) - { - if ( Minerfp != 0 ) - { - fseek(Minerfp,height,SEEK_SET); - fputc(Minerids[height],Minerfp); - fflush(Minerfp); - } - } - } - }*/ if ( 0 && i > 0 ) { for (k=0; k= 0 && notaryid < 64 && voutmask != 0 ) { - komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0,0,0); - //komodo_nutxoadd(height,notaryid,txhash,voutmask,numvouts); + //komodo_stateupdate(height,0,0,notaryid,txhash,voutmask,numvouts,0,0,0,0,0,0,0); } signedmask = 0; numvins = block.vtx[i].vin.size(); for (j=0; j= 0 ) + if ( (scriptlen= gettxout_scriptPubKey(scriptPubKey,sizeof(scriptPubKey),block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) > 0 ) + { + if ( (k= komodo_notarycmp(scriptPubKey,scriptlen,pubkeys,numnotaries,rmd160)) >= 0 ) + signedmask |= (1LL << k); + } + /*if ( (k= komodo_nutxofind(height,block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) >= 0 ) signedmask |= (1LL << k); else if ( signedmask != 0 ) - printf("signedmask.%llx but ht.%d i.%d j.%d not found (%s %d)\n",(long long)signedmask,height,i,j,block.vtx[i].vin[j].prevout.hash.ToString().c_str(),block.vtx[i].vin[j].prevout.n); + printf("signedmask.%llx but ht.%d i.%d j.%d not found (%s %d)\n",(long long)signedmask,height,i,j,block.vtx[i].vin[j].prevout.hash.ToString().c_str(),block.vtx[i].vin[j].prevout.n);*/ } + if ( signedmask != 0 ) + printf("ht.%d signedmask.%llx numvins.%d numvouts.%d\n",height,(long long)signedmask,numvins,numvouts); if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) ) { printf("NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",(long long)signedmask,numvins,height,i,notarizedheight,specialtx); diff --git a/src/komodo_events.h b/src/komodo_events.h index 8351ae37d..fb1ca452c 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -92,7 +92,7 @@ void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height komodo_notarysinit(height,pubkeys,num); } -void komodo_eventadd_utxo(struct komodo_state *sp,char *symbol,int32_t height,uint8_t notaryid,uint256 txid,uint64_t voutmask,uint8_t numvouts) +/*void komodo_eventadd_utxo(struct komodo_state *sp,char *symbol,int32_t height,uint8_t notaryid,uint256 txid,uint64_t voutmask,uint8_t numvouts) { struct komodo_event_utxo U; memset(&U,0,sizeof(U)); @@ -102,7 +102,7 @@ void komodo_eventadd_utxo(struct komodo_state *sp,char *symbol,int32_t height,ui komodo_eventadd(height,symbol,KOMODO_EVENT_UTXO,(uint8_t *)&U,sizeof(U)); if ( sp != 0 ) komodo_nutxoadd(height,notaryid,txid,voutmask,numvouts); -} +}*/ void komodo_eventadd_pricefeed(struct komodo_state *sp,char *symbol,int32_t height,uint32_t *prices,uint8_t num) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index aba22a8eb..f5eba4929 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -32,7 +32,7 @@ int32_t KMDHEIGHT = 43000; struct pax_transaction *PAX; int32_t NUM_PRICES; uint32_t *PVALS; struct knotaries_entry *Pubkeys; -struct nutxo_entry *NUTXOS; int32_t Num_nutxos; +//struct nutxo_entry *NUTXOS; int32_t Num_nutxos; struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS; struct komodo_state KOMODO_STATES[33]; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index ba1bf93f6..e66fec47e 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -52,7 +52,7 @@ const char *Notaries_genesis[][2] = { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, }; -void komodo_nutxoadd(int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts) +/*void komodo_nutxoadd(int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts) { struct nutxo_entry *np; if ( numvouts > 1 && notaryid < 64 ) @@ -79,7 +79,7 @@ int32_t komodo_nutxofind(int32_t height,uint256 txhash,int32_t vout) if ( np != 0 && ((1LL << vout) & np->voutmask) != 0 ) return(np->notaryid); return(-1); -} +}*/ int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) { diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 946eb708a..f3a572fdc 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -30,7 +30,7 @@ struct pax_transaction char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; }; -struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; }; +//struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; }; struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; }; struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; }; From f3a1de3a99eaa75b0befb5b64ef60c9914bdd6f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 10:30:55 -0300 Subject: [PATCH 48/65] test --- src/komodo.h | 5 +++-- src/komodo_bitcoind.h | 21 ++++----------------- src/komodo_events.h | 21 ++++++++++++++------- src/komodo_notary.h | 2 +- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b431bda48..e6f44ff02 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -34,6 +34,7 @@ #include "utlist.h" int32_t gettxout_scriptPubKey(uint8_t *scriptPubkey,int32_t maxsize,uint256 txid,int32_t n); +void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height); #include "komodo_structs.h" #include "komodo_globals.h" @@ -83,7 +84,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char //printf("fpos.%ld func.(%d %c) ht.%d ",ftell(fp),func,func,ht); if ( func == 'P' ) { - if ( (num= fgetc(fp)) < 64 ) + if ( (num= fgetc(fp)) <= 64 ) { if ( fread(pubkeys,33,num,fp) != num ) errs++; @@ -241,7 +242,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } else if ( notarypubs != 0 && numnotaries > 0 ) { - //printf("ht.%d func P[%d] errs.%d\n",height,numnotaries,errs); + printf("ht.%d func P[%d] errs.%d\n",height,numnotaries,errs); fputc('P',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) errs++; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5ee55ec29..80b300b3d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -375,16 +375,11 @@ uint64_t komodo_seed(int32_t height) void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { - //int32_t i; uint256 hash; + char base[16],dest[16]; struct komodo_state *sp; komodo_init(pindex->nHeight); - //Minerids[pindex->nHeight] = -2; - //hash = block.GetHash(); - //for (i=0; i<32; i++) - // printf("%02x",((uint8_t *)&hash)[i]); - //printf(" <- disconnect block\n"); - //uint256 zero; - //printf("disconnect ht.%d\n",pindex->nHeight); - //memset(&zero,0,sizeof(zero)); + if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) + komodo_event_rewind(sp,symbol,pindex->nHeight); + komodo_stateupdate(); } int32_t komodo_is_notarytx(const CTransaction& tx) @@ -464,14 +459,6 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) return; } komodo_block2pubkey33(pubkey33,block); -/* if ( ReadBlockFromDisk(block,(const CBlockIndex *)pindex -#ifndef KOMODO_ZCASH - ,Params().GetConsensus() -#endif - ) != 0 ) - { - komodo_block2pubkey33(pubkey33,block); - }*/ } else { diff --git a/src/komodo_events.h b/src/komodo_events.h index fb1ca452c..017fcb145 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -27,6 +27,7 @@ #define KOMODO_EVENT_NOTARIZED 'N' #define KOMODO_EVENT_UTXO 'U' #define KOMODO_EVENT_KMDHEIGHT 'K' +#define KOMODO_EVENT_REWIND 'B' //#define KOMODO_EVENT_DELETE 'D' #define KOMODO_EVENT_PRICEFEED 'V' #define KOMODO_EVENT_OPRETURN 'R' @@ -84,6 +85,7 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height,uint8_t num,uint8_t pubkeys[64][33]) { struct komodo_event_pubkeys P; + printf("eventadd pubkeys ht.%d\n",height); memset(&P,0,sizeof(P)); P.num = num; memcpy(P.pubkeys,pubkeys,33 * num); @@ -151,17 +153,22 @@ void komodo_event_undo(struct komodo_event *ep) } } -void komodo_event_rewind(int32_t height) +void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height) { struct komodo_event *ep; - while ( Komodo_numevents > 0 ) + komodo_eventadd(height,symbol,KOMODO_EVENT_REWIND,(uint8_t *)&height,sizeof(height)); + if ( sp != 0 ) { - if ( (ep= Komodo_events[Komodo_numevents-1]) != 0 ) + while ( Komodo_numevents > 0 ) { - if ( ep->height < height ) - break; - komodo_event_undo(ep); - Komodo_numevents--; + if ( (ep= Komodo_events[Komodo_numevents-1]) != 0 ) + { + if ( ep->height < height ) + break; + printf("undo event.%c ht.%d for rewind.%d\n",ep->type,ep->height,height); + komodo_event_undo(ep); + Komodo_numevents--; + } } } } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index e66fec47e..08042abac 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -130,7 +130,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) height /= KOMODO_ELECTION_GAP; height = ((height + 1) * KOMODO_ELECTION_GAP); htind = (height / KOMODO_ELECTION_GAP); - printf("htind.%d activation %d from %d\n",htind,height,origheight); + printf("htind.%d activation %d from %d vs %d\n",htind,height,origheight,(((origheight+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP); } else htind = 0; pthread_mutex_lock(&komodo_mutex); for (k=0; k Date: Fri, 18 Nov 2016 10:37:19 -0300 Subject: [PATCH 49/65] 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 80b300b3d..2cd7d58c0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -379,7 +379,7 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) komodo_init(pindex->nHeight); if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) komodo_event_rewind(sp,symbol,pindex->nHeight); - komodo_stateupdate(); + // add rewind entry komodo_stateupdate(); } int32_t komodo_is_notarytx(const CTransaction& tx) From b46eae724bae39284dd3c5308d0944c519a0af63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 10:38:07 -0300 Subject: [PATCH 50/65] 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 2cd7d58c0..445f8dba6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -375,7 +375,7 @@ uint64_t komodo_seed(int32_t height) void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { - char base[16],dest[16]; struct komodo_state *sp; + char symbol[16],dest[16]; struct komodo_state *sp; komodo_init(pindex->nHeight); if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) komodo_event_rewind(sp,symbol,pindex->nHeight); From 067486c4821c642ba6d710640b30e59987dd1760 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 10:40:50 -0300 Subject: [PATCH 51/65] test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 08042abac..f27231a16 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -124,7 +124,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) if ( Pubkeys == 0 ) Pubkeys = (struct knotaries_entry *)calloc(KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP,sizeof(*Pubkeys)); memset(&N,0,sizeof(N)); - if ( height > 0 ) + if ( origheight > 0 ) { height = (origheight + KOMODO_ELECTION_GAP/2); height /= KOMODO_ELECTION_GAP; From 37e7db0873d41b8f18241c367c26245a0244cbc4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 10:49:31 -0300 Subject: [PATCH 52/65] test --- src/komodo_notary.h | 3 +++ src/rpcblockchain.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index f27231a16..366a3c76f 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -150,7 +150,10 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) for (i=htind; i Date: Fri, 18 Nov 2016 10:52:07 -0300 Subject: [PATCH 53/65] test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 366a3c76f..898c29f5f 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -151,7 +151,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) { if ( Pubkeys[i].height != 0 && height < hwmheight ) { - printf("Pubkeys[%d].height %d < %d hwmheight, i.%d\n",i,Pubkeys[i].height,hwmheight); + printf("Pubkeys[%d].height %d < %d hwmheight\n",i,Pubkeys[i].height,hwmheight); break; } Pubkeys[i] = N; From c054842e54b05eb24675ce0c85ceaf22a8019614 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 10:56:21 -0300 Subject: [PATCH 54/65] test --- src/komodo_notary.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 898c29f5f..d9e529015 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -130,7 +130,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) height /= KOMODO_ELECTION_GAP; height = ((height + 1) * KOMODO_ELECTION_GAP); htind = (height / KOMODO_ELECTION_GAP); - printf("htind.%d activation %d from %d vs %d\n",htind,height,origheight,(((origheight+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP); + printf("htind.%d activation %d from %d vs %d | hwmheight.%d\n",htind,height,origheight,(((origheight+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,hwmheight); } else htind = 0; pthread_mutex_lock(&komodo_mutex); for (k=0; k hwmheight ) - hwmheight = height; + if ( origheight > hwmheight ) + hwmheight = origheight; } int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) From 3d899a389bcee7f518c0dd1fb339f48e4e5e4648 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 11:02:32 -0300 Subject: [PATCH 55/65] test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index d9e529015..bc359650f 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -111,7 +111,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) } else printf("illegal notaryid.%d vs n.%d\n",kp->notaryid,n); } pthread_mutex_unlock(&komodo_mutex); - if ( mask == ((1LL << n)-1) ) + if ( (n < 64 && mask == ((1LL << n)-1)) || (n == 64 && mask == 0xffffffffffffffffLL) ) return(n); printf("error retrieving notaries ht.%d got mask.%llx for n.%d\n",height,(long long)mask,n); return(-1); From 9273e756a15505be174288e6dc40ef923e540de1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 11:10:51 -0300 Subject: [PATCH 56/65] test --- src/komodo.h | 11 ++++++++++- src/komodo_bitcoind.h | 3 +-- src/komodo_structs.h | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e6f44ff02..764a0a5fa 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -426,10 +426,19 @@ int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { static int32_t hwmheight; - uint64_t signedmask,voutmask; + uint64_t signedmask,voutmask; char symbol[16],dest[16]; struct komodo_state *sp; uint8_t scriptbuf[4096],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,btctxid,txhash; int32_t i,j,k,numnotaries,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; komodo_init(pindex->nHeight); + if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) + { + if ( sp->rewinding != 0 ) + { + printf("sp->rewinding.%d connect.%d\n",sp->rewinding,pindex->nHeight); + komodo_event_rewind(sp,symbol,pindex->nHeight); + // komodo_stateupdate(); + } + } numnotaries = komodo_notaries(pubkeys,pindex->nHeight); calc_rmd160_sha256(rmd160,pubkeys[0],33); if ( pindex->nHeight > hwmheight ) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 445f8dba6..3560d1fd1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -378,8 +378,7 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) char symbol[16],dest[16]; struct komodo_state *sp; komodo_init(pindex->nHeight); if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) - komodo_event_rewind(sp,symbol,pindex->nHeight); - // add rewind entry komodo_stateupdate(); + sp->rewinding = pindex->nHeight; } int32_t komodo_is_notarytx(const CTransaction& tx) diff --git a/src/komodo_structs.h b/src/komodo_structs.h index f3a572fdc..dd653fc37 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -38,6 +38,6 @@ struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t struct komodo_state { uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; - int32_t CURRENT_HEIGHT,NOTARIZED_HEIGHT; + int32_t CURRENT_HEIGHT,NOTARIZED_HEIGHT,rewinding; // gateway state }; From 7a1831526e0effbb3d663f9ca8ff037630c5d148 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 11:16:45 -0300 Subject: [PATCH 57/65] test --- src/komodo.h | 3 ++- src/komodo_bitcoind.h | 3 +++ src/pow.cpp | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 764a0a5fa..bddfdaaab 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -436,9 +436,10 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { printf("sp->rewinding.%d connect.%d\n",sp->rewinding,pindex->nHeight); komodo_event_rewind(sp,symbol,pindex->nHeight); + sp->rewinding = 0; // komodo_stateupdate(); } - } + } else printf("komodo_connectblock cant get komodo_state %s\n",ASSETCHAINS_SYMBOL); numnotaries = komodo_notaries(pubkeys,pindex->nHeight); calc_rmd160_sha256(rmd160,pubkeys[0],33); if ( pindex->nHeight > hwmheight ) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3560d1fd1..29a6acc85 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -378,7 +378,10 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) char symbol[16],dest[16]; struct komodo_state *sp; komodo_init(pindex->nHeight); if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) + { sp->rewinding = pindex->nHeight; + printf("-%d",pindex->nHeight); + } else printf("komodo_disconnect: ht.%d cant get komodo_state.(%s)\n",pindex->nHeight,ASSETCHAINS_SYMBOL); } int32_t komodo_is_notarytx(const CTransaction& tx) diff --git a/src/pow.cpp b/src/pow.cpp index 088032c82..8d97786e0 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -159,9 +159,9 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { - for (i=0; i<33; i++) - printf("%02x",pubkey33[i]); - printf(" special.%d notaryid.%d ht.%d mod.%d error\n",special,notaryid,height,(height % 35)); + //for (i=0; i<33; i++) + // printf("%02x",pubkey33[i]); + //printf(" special.%d notaryid.%d ht.%d mod.%d error\n",special,notaryid,height,(height % 35)); return error("CheckProofOfWork(): hash doesn't match nBits"); } return true; From 9c432d66aabec2e90505b91570b7de6c510b2454 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 11:21:16 -0300 Subject: [PATCH 58/65] test --- src/komodo.h | 14 +++----------- src/komodo_bitcoind.h | 4 ++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index bddfdaaab..bdeb33efa 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -430,16 +430,6 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) uint8_t scriptbuf[4096],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,btctxid,txhash; int32_t i,j,k,numnotaries,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; komodo_init(pindex->nHeight); - if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) - { - if ( sp->rewinding != 0 ) - { - printf("sp->rewinding.%d connect.%d\n",sp->rewinding,pindex->nHeight); - komodo_event_rewind(sp,symbol,pindex->nHeight); - sp->rewinding = 0; - // komodo_stateupdate(); - } - } else printf("komodo_connectblock cant get komodo_state %s\n",ASSETCHAINS_SYMBOL); numnotaries = komodo_notaries(pubkeys,pindex->nHeight); calc_rmd160_sha256(rmd160,pubkeys[0],33); if ( pindex->nHeight > hwmheight ) @@ -447,7 +437,9 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) else { printf("hwmheight.%d vs pindex->nHeight.%d reorg.%d\n",hwmheight,pindex->nHeight,hwmheight-pindex->nHeight); - // reset komodostate + if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) + komodo_event_rewind(sp,symbol,pindex->nHeight); + // komodo_stateupdate(); } komodo_currentheight_set(chainActive.Tip()->nHeight); if ( komodo_is_issuer() != 0 ) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 29a6acc85..acea87175 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -379,8 +379,8 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) komodo_init(pindex->nHeight); if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) { - sp->rewinding = pindex->nHeight; - printf("-%d",pindex->nHeight); + //sp->rewinding = pindex->nHeight; + //fprintf(stderr,"-%d ",pindex->nHeight); } else printf("komodo_disconnect: ht.%d cant get komodo_state.(%s)\n",pindex->nHeight,ASSETCHAINS_SYMBOL); } From 875cf683eb86de40c872e5331788e168b3dbffb1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 11:41:49 -0300 Subject: [PATCH 59/65] test --- src/komodo.h | 1 + src/komodo_bitcoind.h | 37 +++++++++++++++++++++++++------------ src/main.cpp | 12 +++++++++++- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index bdeb33efa..ed05c1a46 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -35,6 +35,7 @@ int32_t gettxout_scriptPubKey(uint8_t *scriptPubkey,int32_t maxsize,uint256 txid,int32_t n); void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height); +void komodo_connectblock(CBlockIndex *pindex,CBlock& block); #include "komodo_structs.h" #include "komodo_globals.h" diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index acea87175..544fca79c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -441,6 +441,23 @@ void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) else memset(pubkey33,0,33); } +int32_t komodo_blockload(CBlock& block,cBlockIndex *pindex) +{ + block.SetNull(); + // Open history file to read + CAutoFile filein(OpenBlockFile(pindex->GetBlockPos(),true),SER_DISK,CLIENT_VERSION); + if (filein.IsNull()) + return(-1); + // Read block + try { filein >> block; } + catch (const std::exception& e) + { + fprintf(stderr,"readblockfromdisk err B\n"); + return(-1); + } + return(0); +} + void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) { CBlock block; @@ -448,18 +465,7 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) memset(pubkey33,0,33); if ( pindex != 0 ) { - block.SetNull(); - // Open history file to read - CAutoFile filein(OpenBlockFile(pindex->GetBlockPos(),true),SER_DISK,CLIENT_VERSION); - if (filein.IsNull()) - return; - // Read block - try { filein >> block; } - catch (const std::exception& e) - { - fprintf(stderr,"readblockfromdisk err B\n"); - return; - } + komodo_blockload(block,pindex); komodo_block2pubkey33(pubkey33,block); } else @@ -469,6 +475,13 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } +void komodo_connectpindex(CBlockIndex *pindex) +{ + CBlock block; + komodo_blockload(block,pindex); + komodo_connectblock(pindex,block); +} + int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); int8_t komodo_minerid(int32_t height) diff --git a/src/main.cpp b/src/main.cpp index 50e47689f..b7c528a32 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2324,7 +2324,17 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //FlushStateToDisk(); komodo_connectblock(pindex,*(CBlock *)&block); - + { + static int32_t didinit; + if ( didinit == 0 ) + { + if ( (pindex= chainActive[73673]) != 0 ) + { + komodo_connectpindex(pindex); + } + didiint = 73673 + } + } return true; } From d7093b33803e2d55c6d497f71fff16f5f632f65b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 11:44:12 -0300 Subject: [PATCH 60/65] test --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 544fca79c..89879c84c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -441,7 +441,7 @@ void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) else memset(pubkey33,0,33); } -int32_t komodo_blockload(CBlock& block,cBlockIndex *pindex) +int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex) { block.SetNull(); // Open history file to read diff --git a/src/main.cpp b/src/main.cpp index b7c528a32..c7ef2e09c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2332,7 +2332,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { komodo_connectpindex(pindex); } - didiint = 73673 + didinit = 73673 } } return true; From d3875b05aaf2b41c6fbd187935c758639fe3e4bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 11:46:09 -0300 Subject: [PATCH 61/65] test --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index c7ef2e09c..7e64fafa7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2324,6 +2324,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //FlushStateToDisk(); komodo_connectblock(pindex,*(CBlock *)&block); + uint8_t pubkeys[64][33]; + if ( pindex->nHeight > 73673 && komodo_notaries(pubkeys,76000) == 35 ) { static int32_t didinit; if ( didinit == 0 ) From 7d4d5468622617121acbffca82afba6bcc4466b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 11:46:31 -0300 Subject: [PATCH 62/65] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7e64fafa7..7cfb44787 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2334,7 +2334,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { komodo_connectpindex(pindex); } - didinit = 73673 + didinit = 73673; } } return true; From a92123efb1c4f6500ed1bee81f123724ba3e4e8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 11:50:53 -0300 Subject: [PATCH 63/65] 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 89879c84c..8e915a170 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -465,8 +465,8 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) memset(pubkey33,0,33); if ( pindex != 0 ) { - komodo_blockload(block,pindex); - komodo_block2pubkey33(pubkey33,block); + if ( komodo_blockload(block,pindex) == 0 ) + komodo_block2pubkey33(pubkey33,block); } else { @@ -478,8 +478,8 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) void komodo_connectpindex(CBlockIndex *pindex) { CBlock block; - komodo_blockload(block,pindex); - komodo_connectblock(pindex,block); + if ( komodo_blockload(block,pindex) == 0 ) + komodo_connectblock(pindex,block); } int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); From 9db90ea9b39191ef2b9bd67e348aa5de1d840e7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 12:22:30 -0300 Subject: [PATCH 64/65] test --- src/main.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7cfb44787..41d21c7b8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2324,19 +2324,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //FlushStateToDisk(); komodo_connectblock(pindex,*(CBlock *)&block); - uint8_t pubkeys[64][33]; - if ( pindex->nHeight > 73673 && komodo_notaries(pubkeys,76000) == 35 ) - { - static int32_t didinit; - if ( didinit == 0 ) - { - if ( (pindex= chainActive[73673]) != 0 ) - { - komodo_connectpindex(pindex); - } - didinit = 73673; - } - } return true; } From 2db1372f32590c39fb510655145c5ea13135e86e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 12:27:16 -0300 Subject: [PATCH 65/65] test --- src/komodo_notary.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index bc359650f..954c029a5 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -143,7 +143,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) { for (i=0; i<33; i++) printf("%02x",pubkeys[k][i]); - printf(" notarypubs.[%d] ht.%d active at %d\n",k,height,htind*KOMODO_ELECTION_GAP); + printf(" notarypubs.[%d] ht.%d active at %d\n",k,origheight,htind*KOMODO_ELECTION_GAP); } } N.numnotaries = num; @@ -151,7 +151,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) { if ( Pubkeys[i].height != 0 && origheight < hwmheight ) { - printf("Pubkeys[%d].height %d < %d hwmheight\n",i,Pubkeys[i].height,hwmheight); + printf("Pubkeys[%d].height %d < %d hwmheight, origheight.%d\n",i,Pubkeys[i].height,hwmheight,origheight); break; } Pubkeys[i] = N;