From ed7ed6d193ff6243e1b326d5b07e2762c221a236 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 23 Jan 2021 20:55:36 -0500 Subject: [PATCH] Hush hush hush --- src/cc/CCPrices.h | 20 ++++++++++---------- src/cc/prices.cpp | 16 ++++++++-------- src/hush_gateway.h | 28 ++++++++++++++-------------- src/hush_notary.h | 18 +++++++++--------- src/hush_structs.h | 5 +---- 5 files changed, 42 insertions(+), 45 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index bb413cabc..97fd7e50e 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -31,16 +31,16 @@ extern CScript HUSH_EARLYTXID_SCRIPTPUB; #define PRICES_TXFEE 10000 #define PRICES_MAXLEVERAGE 777 #define PRICES_SMOOTHWIDTH 1 -#define KOMODO_MAXPRICES 2048 // must be power of 2 and less than 8192 -#define KOMODO_PRICEMASK (~(KOMODO_MAXPRICES - 1)) // actually 1111 1000 0000 0000 -#define PRICES_WEIGHT (KOMODO_MAXPRICES * 1) // 0000 1000 0000 0000 -#define PRICES_MULT (KOMODO_MAXPRICES * 2) // 0001 0000 0000 0000 -#define PRICES_DIV (KOMODO_MAXPRICES * 3) // 0001 1000 0000 0000 -#define PRICES_INV (KOMODO_MAXPRICES * 4) // 0010 0000 0000 0000 -#define PRICES_MDD (KOMODO_MAXPRICES * 5) // 0010 1000 0000 0000 -#define PRICES_MMD (KOMODO_MAXPRICES * 6) // 0011 0000 0000 0000 -#define PRICES_MMM (KOMODO_MAXPRICES * 7) // 0011 1000 0000 0000 -#define PRICES_DDD (KOMODO_MAXPRICES * 8) // 0100 0000 0000 0000 +#define HUSH_MAXPRICES 2048 // must be power of 2 and less than 8192 +#define KOMODO_PRICEMASK (~(HUSH_MAXPRICES - 1)) // actually 1111 1000 0000 0000 +#define PRICES_WEIGHT (HUSH_MAXPRICES * 1) // 0000 1000 0000 0000 +#define PRICES_MULT (HUSH_MAXPRICES * 2) // 0001 0000 0000 0000 +#define PRICES_DIV (HUSH_MAXPRICES * 3) // 0001 1000 0000 0000 +#define PRICES_INV (HUSH_MAXPRICES * 4) // 0010 0000 0000 0000 +#define PRICES_MDD (HUSH_MAXPRICES * 5) // 0010 1000 0000 0000 +#define PRICES_MMD (HUSH_MAXPRICES * 6) // 0011 0000 0000 0000 +#define PRICES_MMM (HUSH_MAXPRICES * 7) // 0011 1000 0000 0000 +#define PRICES_DDD (HUSH_MAXPRICES * 8) // 0100 0000 0000 0000 //#define PRICES_NORMFACTOR (int64_t)(SATOSHIDEN) //#define PRICES_POINTFACTOR (int64_t)10000 diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b42b489d3..c182419e1 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -657,7 +657,7 @@ static std::string prices_getsourceexpression(const std::vector &vec) char name[65]; std::string operand; uint16_t opcode = vec[i]; - int32_t value = (opcode & (KOMODO_MAXPRICES - 1)); // index or weight + int32_t value = (opcode & (HUSH_MAXPRICES - 1)); // index or weight switch (opcode & KOMODO_PRICEMASK) { @@ -934,7 +934,7 @@ int32_t prices_syntheticvec(std::vector &vec, std::vector opcode = PRICES_DDD, need = 3; else if (!is_weight_str(opstr) && (ind = komodo_priceind(opstr.c_str())) >= 0) opcode = ind, need = 0; - else if ((weight = atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES) + else if ((weight = atoi(opstr.c_str())) > 0 && weight < HUSH_MAXPRICES) { opcode = PRICES_WEIGHT | weight; need = 1; @@ -993,7 +993,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t for (i = 0; i < vec.size(); i++) { opcode = vec[i]; - value = (opcode & (KOMODO_MAXPRICES - 1)); // index or weight + value = (opcode & (HUSH_MAXPRICES - 1)); // index or weight mpz_set_ui(mpzResult, 0); // clear result to test overflow (see below) @@ -2228,7 +2228,7 @@ static bool prices_ispositionup(const std::vector &vecparsed, int16_t if (vecparsed.size() > 1 && vecparsed.size() <= 3) { uint16_t opcode = vecparsed[0]; - int32_t value = (opcode & (KOMODO_MAXPRICES - 1)); // filter index or weight = opcode & (2048-1) + int32_t value = (opcode & (HUSH_MAXPRICES - 1)); // filter index or weight = opcode & (2048-1) if ((opcode & KOMODO_PRICEMASK) == 0) { char name[65]; @@ -2277,8 +2277,8 @@ static bool prices_isopposite(BetInfo p1, BetInfo p2) { uint16_t opcode1 = p1.vecparsed[0]; uint16_t opcode2 = p2.vecparsed[0]; - int32_t value1 = (opcode1 & (KOMODO_MAXPRICES - 1)); // index or weight - int32_t value2 = (opcode2 & (KOMODO_MAXPRICES - 1)); // index or weight + int32_t value1 = (opcode1 & (HUSH_MAXPRICES - 1)); // index or weight + int32_t value2 = (opcode2 & (HUSH_MAXPRICES - 1)); // index or weight if ( (opcode1 & KOMODO_PRICEMASK) == 0 && (opcode2 & KOMODO_PRICEMASK) == 0 ) { char name1[65]; @@ -2311,7 +2311,7 @@ static std::string findMatchedBook(const std::vector &vecparsed, const if (vecparsed.size() > 1 && vecparsed.size() <= 3) { uint16_t opcode = vecparsed[0]; - int32_t value = (opcode & (KOMODO_MAXPRICES - 1)); // filter index or weight = opcode & (2048-1) + int32_t value = (opcode & (HUSH_MAXPRICES - 1)); // filter index or weight = opcode & (2048-1) if ((opcode & KOMODO_PRICEMASK) == 0) { char name[65]; @@ -2370,7 +2370,7 @@ void prices_getorderbook(std::map > & bookmatc if (book[0].vecparsed.size() <= 3) { // only short expr check for match: "BTC_USD,1" or "BTC_USD,!,1" char name[65]; - komodo_pricename(name, (book[0].vecparsed[0] & (KOMODO_MAXPRICES - 1))); + komodo_pricename(name, (book[0].vecparsed[0] & (HUSH_MAXPRICES - 1))); std::string sname = name; bookmatched[sname].push_back(book[0]); diff --git a/src/hush_gateway.h b/src/hush_gateway.h index 4b8a9ce06..7799ac09d 100644 --- a/src/hush_gateway.h +++ b/src/hush_gateway.h @@ -1569,7 +1569,7 @@ extern std::vector Mineropret; // opreturn data set by the data gatheri #define PRICES_ERRORRATE (COIN / 100) // maximum acceptable change, set at 1% #define PRICES_SIZEBIT0 (sizeof(uint32_t) * 4) // 4 uint32_t unixtimestamp, BTCUSD, BTCGBP and BTCEUR #define KOMODO_LOCALPRICE_CACHESIZE 13 -#define KOMODO_MAXPRICES 2048 +#define HUSH_MAXPRICES 2048 #define PRICES_SMOOTHWIDTH 1 #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) @@ -1592,10 +1592,10 @@ struct komodo_priceinfo { FILE *fp; char symbol[64]; -} PRICES[KOMODO_MAXPRICES]; +} PRICES[HUSH_MAXPRICES]; -uint32_t PriceCache[KOMODO_LOCALPRICE_CACHESIZE][KOMODO_MAXPRICES];//4+sizeof(Cryptos)/sizeof(*Cryptos)+sizeof(Forex)/sizeof(*Forex)]; -int64_t PriceMult[KOMODO_MAXPRICES]; +uint32_t PriceCache[KOMODO_LOCALPRICE_CACHESIZE][HUSH_MAXPRICES];//4+sizeof(Cryptos)/sizeof(*Cryptos)+sizeof(Forex)/sizeof(*Forex)]; +int64_t PriceMult[HUSH_MAXPRICES]; int32_t komodo_cbopretsize(uint64_t flags); void komodo_PriceCache_shift() @@ -1694,7 +1694,7 @@ int32_t komodo_pricecmp(int32_t nHeight,int32_t n,char *maxflags,uint32_t *price // komodo_priceclamp() clamps any price that is beyond tolerance int32_t komodo_priceclamp(int32_t n,uint32_t *pricebits,uint32_t *refprices,int64_t tolerance) { - int32_t i; uint32_t newprice; char maxflags[KOMODO_MAXPRICES]; + int32_t i; uint32_t newprice; char maxflags[HUSH_MAXPRICES]; memset(maxflags,0,sizeof(maxflags)); for (i=1; i= PRICES_SIZEBIT0 ) { n = (int32_t)(Mineropret.size() / sizeof(uint32_t)); @@ -1775,7 +1775,7 @@ void komodo_queuelocalprice(int32_t dir,int32_t height,uint32_t timestamp,uint25 int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,int32_t nHeight,CScript scriptPubKey) { int32_t testchain_exemption = 0; - std::vector vopret; char maxflags[KOMODO_MAXPRICES]; uint256 bhash; double btcusd,btcgbp,btceur; uint32_t localbits[KOMODO_MAXPRICES],pricebits[KOMODO_MAXPRICES],prevbits[KOMODO_MAXPRICES],newprice; int32_t i,j,prevtime,maxflag,lag,lag2,lag3,n,errflag,iter; uint32_t now; + std::vector vopret; char maxflags[HUSH_MAXPRICES]; uint256 bhash; double btcusd,btcgbp,btceur; uint32_t localbits[HUSH_MAXPRICES],pricebits[HUSH_MAXPRICES],prevbits[HUSH_MAXPRICES],newprice; int32_t i,j,prevtime,maxflag,lag,lag2,lag3,n,errflag,iter; uint32_t now; now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 ) { @@ -2223,7 +2223,7 @@ extern uint256 Queued_reconsiderblock; void komodo_cbopretupdate(int32_t forceflag) { static uint32_t lasttime,lastbtc,pending; - static uint32_t pricebits[4],pricebuf[KOMODO_MAXPRICES],forexprices[sizeof(Forex)/sizeof(*Forex)]; + static uint32_t pricebits[4],pricebuf[HUSH_MAXPRICES],forexprices[sizeof(Forex)/sizeof(*Forex)]; int32_t size; uint32_t flags=0,now; CBlockIndex *pindex; if ( Queued_reconsiderblock != zeroid ) { @@ -2325,7 +2325,7 @@ void komodo_cbopretupdate(int32_t forceflag) int64_t komodo_pricemult(int32_t ind) { int32_t i,j; - if ( (ASSETCHAINS_CBOPRET & 1) != 0 && ind < KOMODO_MAXPRICES ) + if ( (ASSETCHAINS_CBOPRET & 1) != 0 && ind < HUSH_MAXPRICES ) { if ( PriceMult[0] == 0 ) { @@ -2355,7 +2355,7 @@ int64_t komodo_pricemult(int32_t ind) char *komodo_pricename(char *name,int32_t ind) { strcpy(name,"error"); - if ( (ASSETCHAINS_CBOPRET & 1) != 0 && ind < KOMODO_MAXPRICES ) + if ( (ASSETCHAINS_CBOPRET & 1) != 0 && ind < HUSH_MAXPRICES ) { if ( ind < 4 ) { @@ -2431,7 +2431,7 @@ int32_t komodo_priceind(const char *symbol) int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth) { int32_t i,j,k,n,iter,correlation,maxcorrelation=0; int64_t firstprice,price,sum,den,mult,refprice,lowprice,highprice; - if ( PRICES_DAYWINDOW < 2 || ind >= KOMODO_MAXPRICES ) + if ( PRICES_DAYWINDOW < 2 || ind >= HUSH_MAXPRICES ) return(-1); mult = komodo_pricemult(ind); if ( nonzprices != 0 ) @@ -2683,7 +2683,7 @@ int32_t komodo_pricesinit() fprintf(stderr,"pricesinit (%s)\n",pricesdir.string().c_str()); if (!boost::filesystem::exists(pricesdir)) boost::filesystem::create_directories(pricesdir), createflag = 1; - for (i=0; i= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) - htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; + if ( htind >= HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP ) + htind = (HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; numnotaries = Pubkeys[htind].numnotaries; for (i=0; i 0 ) { @@ -162,8 +162,8 @@ 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); - if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) - htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; + if ( htind >= HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP ) + htind = (HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; //printf("htind.%d activation %d from %d vs %d | hwmheight.%d %s\n",htind,height,origheight,(((origheight+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,hwmheight,SMART_CHAIN_SYMBOL); } else htind = 0; pthread_mutex_lock(&komodo_mutex); @@ -181,7 +181,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) } } N.numnotaries = num; - for (i=htind; i= KOMODO_MAXBLOCKS ) + if ( height < 0 )//|| height >= HUSH_MAXBLOCKS ) { printf("hush_chosennotary ht.%d illegal\n",height); return(-1); @@ -219,8 +219,8 @@ int32_t hush_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,ui if ( Pubkeys == 0 ) komodo_init(0); htind = height / KOMODO_ELECTION_GAP; - if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) - htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; + if ( htind >= HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP ) + htind = (HUSH_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; pthread_mutex_lock(&komodo_mutex); HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp); pthread_mutex_unlock(&komodo_mutex); diff --git a/src/hush_structs.h b/src/hush_structs.h index c47eabbd9..30e6c1dbb 100644 --- a/src/hush_structs.h +++ b/src/hush_structs.h @@ -15,7 +15,6 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - #include "hush_defs.h" #include "uthash.h" #include "utlist.h" @@ -28,12 +27,10 @@ #ifndef KOMODO_STRUCTS_H #define KOMODO_STRUCTS_H - #define GENESIS_NBITS 0x1f00ffff #define KOMODO_MINRATIFY ((height < 90000) ? 7 : 11) #define KOMODO_NOTARIES_HARDCODED 180000 // DONT CHANGE -#define KOMODO_MAXBLOCKS 250000 // DONT CHANGE - +#define HUSH_MAXBLOCKS 250000 // DONT CHANGE #define KOMODO_EVENT_RATIFY 'P' #define KOMODO_EVENT_NOTARIZED 'N' #define KOMODO_EVENT_KMDHEIGHT 'K'