Merge pull request #1413 from jl777/jl777

automatically rejoin a prices chain after being stranded
fix OUR staking
This commit is contained in:
jl777
2019-04-14 18:18:46 -11:00
committed by GitHub
17 changed files with 326 additions and 120 deletions

View File

@@ -19,6 +19,7 @@
#include "CCinclude.h"
int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind);
int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks);
#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1)
#define PRICES_TXFEE 10000

View File

@@ -164,6 +164,7 @@ UniValue CClib_info(struct CCcontract_info *cp);
CBlockIndex *komodo_blockindex(uint256 hash);
CBlockIndex *komodo_chainactive(int32_t height);
int32_t komodo_blockheight(uint256 hash);
void StartShutdown();
static const uint256 zeroid;
static uint256 ignoretxid;

View File

@@ -1662,7 +1662,7 @@ void *dealer0_loop(void *_arg)
if ( (cp= Diceinit(fundingPubKey,dealer0_fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
{
fprintf(stderr,"error initializing dealer0_loop\n");
exit(-1);
StartShutdown();
}
fprintf(stderr,"dealer0 node running\n");
height = lastht = 0;

View File

@@ -68,7 +68,7 @@ void lockSign() {
}
if (!secp256k1_context_randomize(ec_ctx_sign, ent)) {
fprintf(stderr, "Could not randomize secp256k1 context\n");
exit(1);
exit(-1);
}
}

View File

@@ -451,6 +451,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-wallet=<file>", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), "wallet.dat"));
strUsage += HelpMessageOpt("-walletbroadcast", _("Make the wallet broadcast transactions") + " " + strprintf(_("(default: %u)"), true));
strUsage += HelpMessageOpt("-walletnotify=<cmd>", _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)"));
strUsage += HelpMessageOpt("-whitelistaddress=<Raddress>", _("Enable the wallet filter for notary nodes and add one Raddress to the whitelist of the wallet filter. If -whitelistaddress= is used, then the wallet filter is automatically activated. Several Raddresses can be defined using several -whitelistaddress= (similar to -addnode). The wallet filter will filter the utxo to only ones coming from my own Raddress (derived from pubkey) and each Raddress defined using -whitelistaddress= this option is mostly for Notary Nodes)."));
strUsage += HelpMessageOpt("-zapwallettxes=<mode>", _("Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup") +
" " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)"));
#endif

View File

@@ -57,7 +57,7 @@ void init_string(struct return_string *s)
if ( s->ptr == NULL )
{
fprintf(stderr,"init_string malloc() failed\n");
exit(-1);
StartShutdown();
}
s->ptr[0] = '\0';
}
@@ -94,7 +94,7 @@ size_t accumulatebytes(void *ptr,size_t size,size_t nmemb,struct return_string *
if ( s->ptr == NULL )
{
fprintf(stderr, "accumulate realloc() failed\n");
exit(-1);
StartShutdown();
}
memcpy(s->ptr+s->len,ptr,size*nmemb);
s->ptr[new_len] = '\0';
@@ -371,7 +371,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port)
{
sprintf(url,(char *)"http://127.0.0.1:%u",port);
sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params);
//printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS);
//printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS);
retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params);
//retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0);
}
@@ -448,6 +448,18 @@ int32_t komodo_verifynotarizedscript(int32_t height,uint8_t *script,int32_t len,
return(-1);
}
void komodo_reconsiderblock(uint256 blockhash)
{
char params[256],*jsonstr,*hexstr;
sprintf(params,"[\"%s\"]",blockhash.ToString().c_str());
if ( (jsonstr= komodo_issuemethod(ASSETCHAINS_USERPASS,(char *)"reconsiderblock",params,ASSETCHAINS_RPCPORT)) != 0 )
{
//fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> (%s)\n",params,ASSETCHAINS_USERPASS,ASSETCHAINS_RPCPORT,jsonstr);
free(jsonstr);
}
//fprintf(stderr,"komodo_reconsiderblock.(%s) (%s %u) -> NULL\n",params,ASSETCHAINS_USERPASS,ASSETCHAINS_RPCPORT);
}
int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t NOTARIZED_HEIGHT,uint256 NOTARIZED_HASH,uint256 NOTARIZED_DESTTXID)
{
char params[256],*jsonstr,*hexstr; uint8_t *script,_script[8192]; int32_t n,len,retval = -1; cJSON *json,*txjson,*vouts,*vout,*skey;

View File

@@ -57,25 +57,21 @@ extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_NOTARY_PAY
extern const char *ASSETCHAINS_ALGORITHMS[];
extern int32_t VERUS_MIN_STAKEAGE;
extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV1_1, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[];
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB;
extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA;
extern std::vector<std::string> ASSETCHAINS_PRICES;
extern std::vector<std::string> ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS;
extern char ASSETCHAINS_SYMBOL[65];
extern int32_t VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD;
extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE;
extern uint32_t ASSETCHAINS_CC;
extern char ASSETCHAINS_SYMBOL[];
extern std::string CCerror,ASSETCHAINS_CCLIB;
extern uint8_t ASSETCHAINS_CCDISABLES[256];
extern int32_t USE_EXTERNAL_PUBKEY;
extern std::string NOTARY_PUBKEY;
extern int32_t KOMODO_EXCHANGEWALLET;
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern int32_t VERUS_MIN_STAKEAGE;
extern std::string DONATION_PUBKEY;
extern uint8_t ASSETCHAINS_PRIVATE;
@@ -85,8 +81,31 @@ int tx_height( const uint256 &hash );
extern std::vector<std::string> vWhiteListAddress;
void komodo_netevent(std::vector<uint8_t> payload);
#define IGUANA_MAXSCRIPTSIZE 10001
#define KOMODO_KVDURATION 1440
#define KOMODO_KVBINARY 2
#define PRICES_SMOOTHWIDTH 1
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume);
int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel);
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len);
int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width);
int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
int32_t komodo_longestchain();
int32_t komodo_dpowconfs(int32_t height,int32_t numconfs);
int8_t komodo_segid(int32_t nocache,int32_t height);
int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight);
char *komodo_pricename(char *name,int32_t ind);
int32_t komodo_priceind(char *symbol);
void komodo_pricesinit();
int32_t komodo_pricesinit();
int64_t komodo_priceave(int64_t *tmpbuf,int64_t *correlated,int32_t cskip);
int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth);
int32_t komodo_nextheight();
uint32_t komodo_heightstamp(int32_t height);
int64_t komodo_pricemult(int32_t ind);
int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks);
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight);
#endif

View File

@@ -653,7 +653,7 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max)
if ( sizeof(banned_txids)/sizeof(*banned_txids) > max )
{
fprintf(stderr,"komodo_bannedset: buffer too small %ld vs %d\n",sizeof(banned_txids)/sizeof(*banned_txids),max);
exit(-1);
StartShutdown();
}
for (i=0; i<sizeof(banned_txids)/sizeof(*banned_txids); i++)
array[i] = uint256S(banned_txids[i]);
@@ -2014,21 +2014,42 @@ cJSON *get_urljson(char *url)
return(json);
}
uint32_t get_stockprice(const char *symbol)
int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector<std::string> symbols)
{
char url[512]; cJSON *json,*obj; uint32_t high,low,price = 0;
sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50);
if ( (json= get_urljson(url)) != 0 )
char url[32768],*symbol,*timestr; cJSON *json,*obj; int32_t i,n=0,retval=-1; uint32_t uprice,timestamp;
sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","").c_str());
if ( (json= send_curl(url,(char *)"iex")) != 0 ) //if ( (json= get_urljson(url)) != 0 )
{
if ( (obj= jobj(json,(char *)"Time Series (15min)")) != 0 )
if ( (n= cJSON_GetArraySize(json)) > 0 )
{
high = jdouble(jitem(obj,0),(char *)"2. high")*10000 + 0.000049;
low = jdouble(jitem(obj,0),(char *)"3. low")*10000 + 0.000049;
price = (high + low) / 2;
retval = n;
for (i=0; i<n; i++)
{
obj = jitem(json,i);
if ( (symbol= jstr(obj,(char *)"symbol")) != 0 )
{
uprice = jdouble(obj,(char *)"price")*100 + 0.0049;
prices[i] = uprice;
/*timestamp = j64bits(obj,(char *)"time");
if ( timestamp > now+60 || timestamp < now-ASSETCHAINS_BLOCKTIME )
{
fprintf(stderr,"time error.%d (%u vs %u)\n",timestamp-now,timestamp,now);
retval = -1;
}*/
if ( symbols[i] != symbol )
{
retval = -1;
fprintf(stderr,"MISMATCH.");
}
fprintf(stderr,"(%s %u) ",symbol,uprice);
}
}
fprintf(stderr,"numstocks.%d\n",n);
}
//https://api.iextrading.com/1.0/tops/last?symbols=AAPL -> [{"symbol":"AAPL","price":198.63,"size":100,"time":1555092606076}]
free_json(json);
}
return(price);
return(retval);
}
uint32_t get_dailyfx(uint32_t *prices)
@@ -2085,6 +2106,23 @@ int32_t get_cryptoprices(uint32_t *prices,const char *list[],int32_t n,std::vect
return(-errs);
}
/*uint32_t oldget_stockprice(const char *symbol)
{
char url[512]; cJSON *json,*obj; uint32_t high,low,price = 0;
sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50);
if ( (json= get_urljson(url)) != 0 )
{
if ( (obj= jobj(json,(char *)"Time Series (15min)")) != 0 )
{
high = jdouble(jitem(obj,0),(char *)"2. high")*10000 + 0.000049;
low = jdouble(jitem(obj,0),(char *)"3. low")*10000 + 0.000049;
price = (high + low) / 2;
}
free_json(json);
}
return(price);
}
uint32_t get_currencyprice(const char *symbol)
{
char url[512]; cJSON *json,*obj; uint32_t price = 0;
@@ -2109,7 +2147,7 @@ int32_t get_stocks(const char *list[],int32_t n)
}
fprintf(stderr," errs.%d\n",errs);
return(-errs);
}
}*/
// parse the coindesk specific data. yes, if this changes, it will require an update. However, regardless if the format from the data source changes, then the code that extracts it must be changed. One way to mitigate this is to have a large variety of data sources so that there is only a very remote chance that all of them are not available. Certainly the data gathering needs to be made more robust, but it doesnt really affect the proof of concept for the decentralized trustless oracle. The trustlessness is achieved by having all nodes get the oracle data.
@@ -2159,16 +2197,26 @@ int32_t komodo_cbopretsize(uint64_t flags)
if ( (ASSETCHAINS_CBOPRET & 2) != 0 )
size += (sizeof(Forex)/sizeof(*Forex)) * sizeof(uint32_t);
if ( (ASSETCHAINS_CBOPRET & 4) != 0 )
size += (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size())*sizeof(uint32_t);
size += (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size()) * sizeof(uint32_t);
if ( (ASSETCHAINS_CBOPRET & 8) != 0 )
size += (ASSETCHAINS_STOCKS.size() * sizeof(uint32_t));
}
return(size);
}
extern uint256 Queued_reconsiderblock;
void komodo_cbopretupdate(int32_t forceflag)
{
static uint32_t lasttime,lastcrypto,lastbtc,pending;
static uint32_t pricebits[4],cryptoprices[KOMODO_MAXPRICES],forexprices[sizeof(Forex)/sizeof(*Forex)];
static uint32_t lasttime,lastbtc,pending;
static uint32_t pricebits[4],pricebuf[KOMODO_MAXPRICES],forexprices[sizeof(Forex)/sizeof(*Forex)];
int32_t size; uint32_t flags=0,now; CBlockIndex *pindex;
if ( Queued_reconsiderblock != zeroid )
{
fprintf(stderr,"Queued_reconsiderblock %s\n",Queued_reconsiderblock.GetHex().c_str());
komodo_reconsiderblock(Queued_reconsiderblock);
Queued_reconsiderblock = zeroid;
}
if ( forceflag != 0 && pending != 0 )
{
while ( pending != 0 )
@@ -2208,23 +2256,35 @@ void komodo_cbopretupdate(int32_t forceflag)
{
if ( forceflag != 0 || flags != 0 )
{
get_cryptoprices(cryptoprices,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos)),ASSETCHAINS_PRICES);
get_cryptoprices(pricebuf,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos)),ASSETCHAINS_PRICES);
if ( flags == 0 )
komodo_PriceCache_shift();
memcpy(&PriceCache[0][size/sizeof(uint32_t)],cryptoprices,(sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t));
memcpy(&PriceCache[0][size/sizeof(uint32_t)],pricebuf,(sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t));
flags |= 4; // very rarely we can see flags == 6 case
}
size += (sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t);
}
now = (uint32_t)time(NULL);
if ( (ASSETCHAINS_CBOPRET & 8) != 0 )
{
if ( forceflag != 0 || flags != 0 )
{
if ( get_stockprices(now,pricebuf,ASSETCHAINS_STOCKS) == ASSETCHAINS_STOCKS.size() )
{
if ( flags == 0 )
komodo_PriceCache_shift();
memcpy(&PriceCache[0][size/sizeof(uint32_t)],pricebuf,ASSETCHAINS_STOCKS.size() * sizeof(uint32_t));
flags |= 8; // very rarely we can see flags == 10 case
}
}
size += (ASSETCHAINS_STOCKS.size()) * sizeof(uint32_t);
}
if ( flags != 0 )
{
now = (uint32_t)time(NULL);
if ( (flags & 1) != 0 )
lastbtc = now;
if ( (flags & 2) != 0 )
lasttime = now;
if ( (flags & 4) != 0 )
lastcrypto = now;
memcpy(Mineropret.data(),PriceCache[0],size);
if ( ExtremePrice.dir != 0 && ExtremePrice.ind > 0 && ExtremePrice.ind < size/sizeof(uint32_t) && now < ExtremePrice.timestamp+3600 )
{
@@ -2244,19 +2304,6 @@ void komodo_cbopretupdate(int32_t forceflag)
// fprintf(stderr,"%02x",Mineropret[i]);
//fprintf(stderr," <- set Mineropret[%d] size.%d %ld\n",(int32_t)Mineropret.size(),size,sizeof(PriceCache[0]));
}
/*
if ( (ASSETCHAINS_CBOPRET & 4) != 0 )
{
get_currencies(Metals,(int32_t)(sizeof(Metals)/sizeof(*Metals)));
}
if ( (ASSETCHAINS_CBOPRET & 32) != 0 )
{
get_stocks(Markets,(int32_t)(sizeof(Markets)/sizeof(*Markets)));
}
if ( (ASSETCHAINS_CBOPRET & 64) != 0 )
{
get_stocks(Techstocks,(int32_t)(sizeof(Techstocks)/sizeof(*Techstocks)));
}*/
}
pending = 0;
}
@@ -2280,6 +2327,11 @@ int64_t komodo_pricemult(int32_t ind)
for (j=0; j<sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size(); j++)
PriceMult[i++] = 1;
}
if ( (ASSETCHAINS_CBOPRET & 8) != 0 )
{
for (j=0; j<ASSETCHAINS_STOCKS.size(); j++)
PriceMult[i++] = 1000000;
}
}
return(PriceMult[ind]);
}
@@ -2296,9 +2348,9 @@ char *komodo_pricename(char *name,int32_t ind)
switch ( ind )
{
case 0: strcpy(name,"timestamp"); break;
case 1: strcpy(name,"BTCUSD"); break;
case 2: strcpy(name,"BTCGBP"); break;
case 3: strcpy(name,"BTCEUR"); break;
case 1: strcpy(name,"BTC_USD"); break;
case 2: strcpy(name,"BTC_GBP"); break;
case 3: strcpy(name,"BTC_EUR"); break;
default: return(0); break;
}
return(name);
@@ -2312,8 +2364,8 @@ char *komodo_pricename(char *name,int32_t ind)
return(0);
if ( ind < sizeof(Forex)/sizeof(*Forex) )
{
name[0] = 'U', name[1] = 'S', name[2] = 'D';
strcpy(name+3,Forex[ind]);
name[0] = 'U', name[1] = 'S', name[2] = 'D', name[3] = '_';
strcpy(name+4,Forex[ind]);
return(name);
} else ind -= sizeof(Forex)/sizeof(*Forex);
}
@@ -2330,10 +2382,21 @@ char *komodo_pricename(char *name,int32_t ind)
ind -= (sizeof(Cryptos)/sizeof(*Cryptos));
strcpy(name,ASSETCHAINS_PRICES[ind].c_str());
}
strcat(name,"BTC");
strcat(name,"_BTC");
return(name);
} else ind -= (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size());
}
if ( (ASSETCHAINS_CBOPRET & 8) != 0 )
{
if ( ind < 0 )
return(0);
if ( ind < ASSETCHAINS_STOCKS.size() )
{
strcpy(name,ASSETCHAINS_STOCKS[ind].c_str());
strcat(name,"_USD");
return(name);
} else ind -= ASSETCHAINS_STOCKS.size();
}
}
}
return(0);
@@ -2595,9 +2658,13 @@ int64_t komodo_priceave(int64_t *buf,int64_t *correlated,int32_t cskip)
return((price*7 + halfave*5 + thirdave*3 + fourthave*2 + decayprice + buf[PRICES_DAYWINDOW-1]) / 19);
}
void komodo_pricesinit()
int32_t komodo_pricesinit()
{
int32_t i,createflag = 0;
static int32_t didinit;
int32_t i,num=0,createflag = 0;
if ( didinit != 0 )
return(-1);
didinit = 1;
boost::filesystem::path pricefname,pricesdir = GetDataDir() / "prices";
fprintf(stderr,"pricesinit (%s)\n",pricesdir.string().c_str());
if (!boost::filesystem::exists(pricesdir))
@@ -2606,16 +2673,24 @@ void komodo_pricesinit()
{
if ( komodo_pricename(PRICES[i].symbol,i) == 0 )
break;
//fprintf(stderr,"%s.%d ",PRICES[i].symbol,i);
if ( i == 0 )
strcpy(PRICES[i].symbol,"rawprices");
pricefname = pricesdir / PRICES[i].symbol;
PRICES[i].fp = fopen(pricefname.string().c_str(), createflag != 0 ? "wb+" : "rb+");
if ( createflag != 0 )
PRICES[i].fp = fopen(pricefname.string().c_str(),"wb+");
else if ( (PRICES[i].fp= fopen(pricefname.string().c_str(),"rb+")) == 0 )
PRICES[i].fp = fopen(pricefname.string().c_str(),"wb+");
if ( PRICES[i].fp != 0 )
{
fseek(PRICES[i].fp,(2*PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH) * sizeof(int64_t) * PRICES_MAXDATAPOINTS,SEEK_SET);
fputc(0,PRICES[i].fp);
fflush(PRICES[i].fp);
}
num++;
if ( createflag != 0 )
{
fseek(PRICES[i].fp,(2*PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH) * sizeof(int64_t) * PRICES_MAXDATAPOINTS,SEEK_SET);
fputc(0,PRICES[i].fp);
fflush(PRICES[i].fp);
}
} else fprintf(stderr,"error opening %s createflag.%d\n",pricefname.string().c_str(), createflag);
}
if ( i > 0 && PRICES[0].fp != 0 && createflag != 0 )
{
@@ -2623,15 +2698,31 @@ void komodo_pricesinit()
fputc(0,PRICES[0].fp);
fflush(PRICES[0].fp);
}
fprintf(stderr,"pricesinit done i.%d num.%d numprices.%d\n",i,num,(int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET)/sizeof(uint32_t)));
if ( i != num || i != komodo_cbopretsize(ASSETCHAINS_CBOPRET)/sizeof(uint32_t) )
{
fprintf(stderr,"fatal error opening prices files, start shutdown\n");
StartShutdown();
}
return(0);
}
pthread_mutex_t pricemutex;
// PRICES file layouts
// [0] rawprice32 / timestamp
// [1] correlated
// [2] 24hr ave
// [3] to [7] reserved
void komodo_pricesupdate(int32_t height,CBlock *pblock)
{
static int numprices; static uint32_t *ptr32; static int64_t *ptr64,*tmpbuf;
int32_t ind,offset,width; int64_t correlated,smoothed; uint64_t seed,rngval; uint32_t rawprices[KOMODO_MAXPRICES],buf[4];
int32_t ind,offset,width; int64_t correlated,smoothed; uint64_t seed,rngval; uint32_t rawprices[KOMODO_MAXPRICES],buf[PRICES_MAXDATAPOINTS*2];
width = PRICES_DAYWINDOW;//(2*PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH);
if ( numprices == 0 )
{
pthread_mutex_init(&pricemutex,0);
numprices = (int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET) / sizeof(uint32_t));
ptr32 = (uint32_t *)calloc(sizeof(uint32_t),numprices * width);
ptr64 = (int64_t *)calloc(sizeof(int64_t),PRICES_DAYWINDOW*PRICES_MAXDATAPOINTS);
@@ -2645,6 +2736,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock)
//fprintf(stderr,"numprices.%d\n",numprices);
if ( PRICES[0].fp != 0 )
{
pthread_mutex_lock(&pricemutex);
fseek(PRICES[0].fp,height * numprices * sizeof(uint32_t),SEEK_SET);
if ( fwrite(rawprices,sizeof(uint32_t),numprices,PRICES[0].fp) != numprices )
fprintf(stderr,"error writing rawprices for ht.%d\n",height);
@@ -2657,11 +2749,17 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock)
rngval = seed;
for (ind=1; ind<numprices; ind++)
{
if ( PRICES[ind].fp == 0 )
{
fprintf(stderr,"PRICES[%d].fp is null\n",ind);
continue;
}
offset = (width-1)*numprices + ind;
rngval = (rngval*11109 + 13849);
if ( (correlated= komodo_pricecorrelated(rngval,ind,&ptr32[offset],-numprices,0,PRICES_SMOOTHWIDTH)) > 0 )
{
fseek(PRICES[ind].fp,height * sizeof(int64_t) * PRICES_MAXDATAPOINTS,SEEK_SET);
memset(buf,0,sizeof(buf));
buf[0] = rawprices[ind];
buf[1] = rawprices[0]; // timestamp
memcpy(&buf[2],&correlated,sizeof(correlated));
@@ -2670,7 +2768,7 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock)
else if ( height > PRICES_DAYWINDOW*2 )
{
fseek(PRICES[ind].fp,(height-PRICES_DAYWINDOW+1) * PRICES_MAXDATAPOINTS * sizeof(int64_t),SEEK_SET);
if ( fread(ptr64,sizeof(int64_t),(PRICES_DAYWINDOW-1)*PRICES_MAXDATAPOINTS+2,PRICES[ind].fp) == (PRICES_DAYWINDOW-1)*PRICES_MAXDATAPOINTS+2 )
if ( fread(ptr64,sizeof(int64_t),PRICES_DAYWINDOW*PRICES_MAXDATAPOINTS,PRICES[ind].fp) == PRICES_DAYWINDOW*PRICES_MAXDATAPOINTS )
{
if ( (smoothed= komodo_priceave(tmpbuf,&ptr64[(PRICES_DAYWINDOW-1)*PRICES_MAXDATAPOINTS+1],-PRICES_MAXDATAPOINTS)) > 0 )
{
@@ -2686,8 +2784,22 @@ void komodo_pricesupdate(int32_t height,CBlock *pblock)
fprintf(stderr,"height.%d\n",height);
} else fprintf(stderr,"error reading rawprices for ht.%d\n",height);
} else fprintf(stderr,"height.%d <= width.%d\n",height,width);
pthread_mutex_unlock(&pricemutex);
} else fprintf(stderr,"null PRICES[0].fp\n");
} else fprintf(stderr,"numprices mismatch\n");
} else fprintf(stderr,"numprices mismatch, height.%d\n",height);
}
int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks)
{
FILE *fp; int32_t retval = PRICES_MAXDATAPOINTS;
pthread_mutex_lock(&pricemutex);
if ( ind < KOMODO_MAXPRICES && (fp= PRICES[ind].fp) != 0 )
{
fseek(fp,height * PRICES_MAXDATAPOINTS * sizeof(int64_t),SEEK_SET);
if ( fread(buf64,sizeof(int64_t),numblocks*PRICES_MAXDATAPOINTS,fp) != numblocks*PRICES_MAXDATAPOINTS )
retval = -1;
}
pthread_mutex_unlock(&pricemutex);
return(retval);
}

View File

@@ -74,7 +74,7 @@ uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0,ASSETCHAIN
uint64_t ASSETCHAINS_LASTERA = 1;
uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS];
uint8_t ASSETCHAINS_CCDISABLES[256];
std::vector<std::string> ASSETCHAINS_PRICES;
std::vector<std::string> ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS;
#define _ASSETCHAINS_EQUIHASH 0
uint32_t ASSETCHAINS_NUMALGOS = 3;

View File

@@ -1675,7 +1675,7 @@ void komodo_args(char *argv0)
IS_STAKED_NOTARY = GetArg("-stakednotary", -1);
if ( IS_STAKED_NOTARY != -1 && IS_KOMODO_NOTARY == true ) {
fprintf(stderr, "Cannot be STAKED and KMD notary at the same time!\n");
exit(0);
StartShutdown();
}
memset(ccenables,0,sizeof(ccenables));
memset(disablebits,0,sizeof(disablebits));
@@ -1800,7 +1800,7 @@ void komodo_args(char *argv0)
if ( ASSETCHAINS_SUPPLY > (uint64_t)90*1000*1000000 )
{
fprintf(stderr,"-ac_supply must be less than 90 billion\n");
exit(0);
StartShutdown();
}
fprintf(stderr,"ASSETCHAINS_SUPPLY %llu\n",(long long)ASSETCHAINS_SUPPLY);
@@ -1815,11 +1815,17 @@ void komodo_args(char *argv0)
if ( ASSETCHAINS_CBOPRET != 0 )
{
SplitStr(GetArg("-ac_prices",""), ASSETCHAINS_PRICES);
for (i=0; i<ASSETCHAINS_PRICES.size(); i++)
fprintf(stderr,"%s ",ASSETCHAINS_PRICES[i].c_str());
if ( ASSETCHAINS_PRICES.size() > 0 )
ASSETCHAINS_CBOPRET |= 4;
SplitStr(GetArg("-ac_stocks",""), ASSETCHAINS_STOCKS);
if ( ASSETCHAINS_STOCKS.size() > 0 )
ASSETCHAINS_CBOPRET |= 8;
for (i=0; i<ASSETCHAINS_PRICES.size(); i++)
fprintf(stderr,"%s ",ASSETCHAINS_PRICES[i].c_str());
fprintf(stderr,"%d -ac_prices\n",(int32_t)ASSETCHAINS_PRICES.size());
for (i=0; i<ASSETCHAINS_STOCKS.size(); i++)
fprintf(stderr,"%s ",ASSETCHAINS_STOCKS[i].c_str());
fprintf(stderr,"%d -ac_stocks\n",(int32_t)ASSETCHAINS_STOCKS.size());
}
hexstr = GetArg("-ac_mineropret","");
if ( hexstr.size() != 0 )
@@ -1833,7 +1839,7 @@ void komodo_args(char *argv0)
if ( ASSETCHAINS_COMMISSION != 0 && ASSETCHAINS_FOUNDERS_REWARD != 0 )
{
fprintf(stderr,"cannot use founders reward and commission on the same chain.\n");
exit(0);
StartShutdown();
}
if ( ASSETCHAINS_CC != 0 )
{
@@ -1873,7 +1879,7 @@ void komodo_args(char *argv0)
if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 )
{
fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n");
exit(0);
StartShutdown();
}
ASSETCHAINS_SELFIMPORT = GetArg("-ac_import",""); // BEAM, CODA, PUBKEY, GATEWAY
if ( ASSETCHAINS_SELFIMPORT == "PUBKEY" )
@@ -1881,18 +1887,18 @@ void komodo_args(char *argv0)
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 )
{
fprintf(stderr,"invalid -ac_pubkey for -ac_import=PUBKEY\n");
exit(0);
StartShutdown();
}
}
else if ( ASSETCHAINS_SELFIMPORT == "BEAM" && ASSETCHAINS_BEAMPORT == 0 )
{
fprintf(stderr,"missing -ac_beam for BEAM rpcport\n");
exit(0);
StartShutdown();
}
else if ( ASSETCHAINS_SELFIMPORT == "CODA" && ASSETCHAINS_CODAPORT == 0 )
{
fprintf(stderr,"missing -ac_coda for CODA rpcport\n");
exit(0);
StartShutdown();
}
// else it can be gateway coin
@@ -1920,12 +1926,12 @@ void komodo_args(char *argv0)
if ( ASSETCHAINS_SUPPLY > 10000000000 )
{
printf("ac_pubkey or ac_script wont work with ac_supply over 10 billion\n");
exit(0);
StartShutdown();
}
if ( ASSETCHAINS_NOTARY_PAY[0] != 0 )
{
printf("Assetchains NOTARY PAY cannot be used with ac_pubkey or ac_script.\n");
exit(0);
StartShutdown();
}
if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 )
{
@@ -1966,7 +1972,7 @@ void komodo_args(char *argv0)
if ( ASSETCHAINS_SCRIPTPUB.size() > 1 && ASSETCHAINS_MARMARA != 0 )
{
fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n");
exit(0);
StartShutdown();
}
if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 )
{
@@ -2085,6 +2091,16 @@ void komodo_args(char *argv0)
extralen += symbol.size();
}
}
if ( ASSETCHAINS_STOCKS.size() != 0 )
{
for (i=0; i<ASSETCHAINS_STOCKS.size(); i++)
{
symbol = ASSETCHAINS_STOCKS[i];
memcpy(&extraptr[extralen],(char *)symbol.c_str(),symbol.size());
extralen += symbol.size();
}
}
//komodo_pricesinit();
komodo_cbopretupdate(1); // will set Mineropret
fprintf(stderr,"This blockchain uses data produced from CoinDesk Bitcoin Price Index\n");
}
@@ -2134,7 +2150,7 @@ void komodo_args(char *argv0)
if ( strcmp(ASSETCHAINS_SYMBOL,"KMD") == 0 )
{
fprintf(stderr,"cant have assetchain named KMD\n");
exit(0);
StartShutdown();
}
if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 )
ASSETCHAINS_RPCPORT = port;
@@ -2216,6 +2232,11 @@ void komodo_args(char *argv0)
}
else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 )
dpowconfs = 0;
else if ( ASSETCHAINS_PRIVATE != 0 )
{
fprintf(stderr,"-ac_private for a non-PIRATE chain is not supported. The only reason to have an -ac_private chain is for total privacy and that is best achieved with the largest anon set. PIRATE has that and it is recommended to just use PIRATE\n");
StartShutdown();
}
} else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort());
KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs);
if ( ASSETCHAINS_SYMBOL[0] == 0 || strcmp(ASSETCHAINS_SYMBOL,"SUPERNET") == 0 || strcmp(ASSETCHAINS_SYMBOL,"DEX") == 0 || strcmp(ASSETCHAINS_SYMBOL,"COQUI") == 0 || strcmp(ASSETCHAINS_SYMBOL,"PIRATE") == 0 || strcmp(ASSETCHAINS_SYMBOL,"KMDICE") == 0 )

View File

@@ -512,7 +512,7 @@ namespace {
// Never fetch further than the best block we know the peer has, or more than BLOCK_DOWNLOAD_WINDOW + 1 beyond the last
// linked block we have in common with this peer. The +1 is so we can detect stalling, namely if we would be able to
// download that next block if the window were 1 larger.
if ( ASSETCHAINS_CBOPRET != 0 )
if ( ASSETCHAINS_CBOPRET != 0 && IsInitialBlockDownload() == 0 )
BLOCK_DOWNLOAD_WINDOW = 1;
int nWindowEnd = state->pindexLastCommonBlock->GetHeight() + BLOCK_DOWNLOAD_WINDOW;
int nMaxHeight = std::min<int>(state->pindexBestKnownBlock->GetHeight(), nWindowEnd + 1);
@@ -980,7 +980,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
* Ensure that a coinbase transaction is structured according to the consensus rules of the
* chain
*/
bool ContextualCheckCoinbaseTransaction(const CBlock *block,CBlockIndex * const previndex,const CTransaction& tx, const int nHeight)
bool ContextualCheckCoinbaseTransaction(const CBlock *block,CBlockIndex * const previndex,const CTransaction& tx, const int nHeight,int32_t validateprices)
{
// if time locks are on, ensure that this coin base is time locked exactly as it should be
if (((uint64_t)(tx.GetValueOut()) >= ASSETCHAINS_TIMELOCKGTE) ||
@@ -1021,7 +1021,7 @@ bool ContextualCheckCoinbaseTransaction(const CBlock *block,CBlockIndex * const
{
}
else if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 && tx.vout.size() > 0 )
else if ( ASSETCHAINS_CBOPRET != 0 && validateprices != 0 && nHeight > 0 && tx.vout.size() > 0 )
{
if ( komodo_opretvalidate(block,previndex,nHeight,tx.vout[tx.vout.size()-1].scriptPubKey) < 0 )
return(false);
@@ -1043,7 +1043,7 @@ bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const prevind
CValidationState &state,
const int nHeight,
const int dosLevel,
bool (*isInitBlockDownload)())
bool (*isInitBlockDownload)(),int32_t validateprices)
{
bool overwinterActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER);
bool saplingActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING);
@@ -1174,7 +1174,7 @@ bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const prevind
if (tx.IsCoinBase())
{
if (!ContextualCheckCoinbaseTransaction(block,previndex,tx, nHeight))
if (!ContextualCheckCoinbaseTransaction(block,previndex,tx, nHeight,validateprices))
return state.DoS(100, error("CheckTransaction(): invalid script data for coinbase time lock"),
REJECT_INVALID, "bad-txns-invalid-script-data-for-coinbase-time-lock");
}
@@ -1679,7 +1679,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
}
// DoS level set to 10 to be more forgiving.
// Check transaction contextually against the set of consensus rules which apply in the next block to be mined.
if (!fSkipExpiry && !ContextualCheckTransaction(0,0,tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel))
if (!fSkipExpiry && !ContextualCheckTransaction(0,0,tx, state, nextBlockHeight, (dosLevel == -1) ? 10 : dosLevel,0))
{
return error("AcceptToMemoryPool: ContextualCheckTransaction failed");
}
@@ -5273,6 +5273,8 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat
return true;
}
uint256 Queued_reconsiderblock;
bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool fRequested, CDiskBlockPos* dbp)
{
const CChainParams& chainparams = Params();
@@ -5333,6 +5335,18 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C
fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+50000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720));
if ( pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+50000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) )
*futureblockp = 1;
if ( ASSETCHAINS_CBOPRET != 0 )
{
CValidationState tmpstate; CBlockIndex *tmpindex; int32_t ht,longest;
ht = (int32_t)pindex->GetHeight();
longest = komodo_longestchain();
if ( (longest == 0 || ht < longest-6) && (tmpindex=komodo_chainactive(ht)) != 0 )
{
fprintf(stderr,"reconsider height.%d, longest.%d\n",(int32_t)ht,longest);
if ( Queued_reconsiderblock == zeroid )
Queued_reconsiderblock = pindex->GetBlockHash();
}
}
}
if ( *futureblockp == 0 )
{

View File

@@ -707,7 +707,7 @@ bool ContextualCheckInputs(const CTransaction& tx, CValidationState &state, cons
/** Check a transaction contextually against a set of consensus rules */
bool ContextualCheckTransaction(const CBlock *block, CBlockIndex * const pindexPrev,const CTransaction& tx, CValidationState &state, int nHeight, int dosLevel,
bool (*isInitBlockDownload)() = IsInitialBlockDownload);
bool (*isInitBlockDownload)() = IsInitialBlockDownload,int32_t validateprices=1);
/** Apply the effects of this transaction on the UTXO set represented by view */
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);

View File

@@ -224,7 +224,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
CBlockIndex* pindexPrev = 0;
{
LOCK2(cs_main,mempool.cs);
ENTER_CRITICAL_SECTION(cs_main);
ENTER_CRITICAL_SECTION(mempool.cs);
pindexPrev = chainActive.LastTip();
const int nHeight = pindexPrev->GetHeight() + 1;
const Consensus::Params &consensusParams = chainparams.GetConsensus();
@@ -563,10 +564,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
//LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x stake.%i\n", nBlockSize,blocktime,pblock->nBits,isStake);
if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake )
{
uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[512],*ptr;
CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), stakeHeight);
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[512],*ptr;
CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), stakeHeight);
if (ASSETCHAINS_LWMAPOS != 0)
{
uint32_t nBitsPOS;
@@ -591,7 +593,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
{
sleep(1);
if ( (rand() % 100) < 1 )
fprintf(stderr, "%u seconds until elegible, waiting...\n", blocktime-((uint32_t)GetAdjustedTime()+57));
fprintf(stderr, "%u seconds until elegible, waiting.\n", blocktime-((uint32_t)GetAdjustedTime()+57));
if ( chainActive.LastTip()->GetHeight() >= stakeHeight )
{
fprintf(stderr, "Block Arrived, reset staking loop.\n");
@@ -601,8 +603,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
return(0);
}
}
ENTER_CRITICAL_SECTION(cs_main);
ENTER_CRITICAL_SECTION(mempool.cs);
if ( siglen > 0 )
{
CAmount txfees;
@@ -615,7 +616,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
nFees += txfees;
pblock->nTime = blocktime;
//printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13)));
} else return(0); //fprintf(stderr,"no utxos eligible for staking\n");
} else return(0); //fprintf(stderr,"no utxos eligible for staking\n");
}
// Create coinbase tx
@@ -687,6 +688,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition())
{
fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n");
if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) )
{
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
}
return 0;
}
@@ -708,6 +714,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
if ( totalsats == 0 )
{
fprintf(stderr, "Could not create notary payment, trying again.\n");
if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) )
{
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
}
return(0);
}
fprintf(stderr, "Created notary payment coinbase totalsat.%lu\n",totalsats);
@@ -778,6 +789,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
else
{
fprintf(stderr,"error adding notaryvin, need to create 0.0001 utxos\n");
if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) )
{
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
}
return(0);
}
}
@@ -792,6 +808,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
//fprintf(stderr,"valid\n");
}
}
if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) )
{
LEAVE_CRITICAL_SECTION(cs_main);
LEAVE_CRITICAL_SECTION(mempool.cs);
}
//fprintf(stderr,"done new block\n");
return pblocktemplate.release();
}

View File

@@ -47,10 +47,8 @@ using namespace std;
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
int32_t komodo_longestchain();
int32_t komodo_dpowconfs(int32_t height,int32_t numconfs);
extern int8_t komodo_segid(int32_t nocache,int32_t height);
extern int32_t KOMODO_LONGESTCHAIN;
#include "komodo_defs.h"
#include "komodo_structs.h"
double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficulty)
{
@@ -628,8 +626,6 @@ UniValue getblockhash(const UniValue& params, bool fHelp)
return pblockindex->GetBlockHash().GetHex();
}
extern int32_t ASSETCHAINS_STAKED;
UniValue getlastsegidstakes(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
@@ -915,20 +911,6 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp)
return ret;
}
#include "komodo_defs.h"
#include "komodo_structs.h"
#define IGUANA_MAXSCRIPTSIZE 10001
#define KOMODO_KVDURATION 1440
#define KOMODO_KVBINARY 2
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern int32_t ASSETCHAINS_LWMAPOS;
uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume);
int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel);
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len);
int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width);
int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
UniValue kvsearch(const UniValue& params, bool fHelp)
{
@@ -1174,15 +1156,6 @@ UniValue paxprice(const UniValue& params, bool fHelp)
return ret;
}
int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight);
char *komodo_pricename(char *name,int32_t ind);
int64_t komodo_priceave(int64_t *tmpbuf,int64_t *correlated,int32_t cskip);
int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth);
int32_t komodo_nextheight();
uint32_t komodo_heightstamp(int32_t height);
int64_t komodo_pricemult(int32_t ind);
#define PRICES_SMOOTHWIDTH 1
int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind)
{
int32_t height,i,n,width,numpricefeeds = -1; uint64_t seed,ignore,rngval; uint32_t rawprices[1440*6],*ptr; int64_t *tmpbuf;
@@ -1282,6 +1255,7 @@ UniValue prices(const UniValue& params, bool fHelp)
rngval = (rngval*11109 + 13849);
if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],1,0,PRICES_SMOOTHWIDTH)) < 0 )
throw JSONRPCError(RPC_INVALID_PARAMETER, "null correlated price");
}
tmpbuf = (int64_t *)calloc(sizeof(int64_t),2*PRICES_DAYWINDOW);
for (i=0; i<maxsamples&&i<numsamples; i++)
@@ -1324,8 +1298,6 @@ UniValue prices(const UniValue& params, bool fHelp)
return ret;
}
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight);
UniValue gettxout(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 2 || params.size() > 3)

View File

@@ -413,7 +413,7 @@ public:
UniValue coinsupply(const UniValue& params, bool fHelp)
{
int32_t height = 0; int32_t currentHeight; int64_t sproutfunds,zfunds,supply = 0; UniValue result(UniValue::VOBJ);
int32_t height = 0; int32_t currentHeight; int64_t blocks_per_year,zf1,zf3,zf12,sf1,sf3,sf12,sproutfunds,zfunds,supply1,supply3,supply12,supply = 0; UniValue result(UniValue::VOBJ);
if (fHelp || params.size() > 1)
throw runtime_error("coinsupply <height>\n"
"\nReturn coin supply information at a given block height. If no height is given, the current height is used.\n"
@@ -448,6 +448,27 @@ UniValue coinsupply(const UniValue& params, bool fHelp)
result.push_back(Pair("zfunds", ValueFromAmount(zfunds)));
result.push_back(Pair("sprout", ValueFromAmount(sproutfunds)));
result.push_back(Pair("total", ValueFromAmount(zfunds + supply)));
if ( ASSETCHAINS_BLOCKTIME > 0 )
{
blocks_per_year = 24*3600*365 / ASSETCHAINS_BLOCKTIME;
if ( height > blocks_per_year )
{
supply1 = komodo_coinsupply(&zf1,&sf1,height - blocks_per_year/12);
supply3 = komodo_coinsupply(&zf3,&sf3,height - blocks_per_year/4);
supply12 = komodo_coinsupply(&zf12,&sf12,height - blocks_per_year);
if ( supply1 != 0 && supply3 != 0 && supply12 != 0 )
{
result.push_back(Pair("lastmonth", ValueFromAmount(supply1+zf1)));
result.push_back(Pair("monthcoins", ValueFromAmount(zfunds + supply - supply1-zf1)));
result.push_back(Pair("lastquarter", ValueFromAmount(supply3+zf3)));
result.push_back(Pair("quartercoins", ValueFromAmount(zfunds + supply - supply3-zf3)));
result.push_back(Pair("lastyear", ValueFromAmount(supply12+zf12)));
result.push_back(Pair("yearcoins", ValueFromAmount(zfunds + supply - supply12-zf12)));
result.push_back(Pair("inflation", 100. * (((double)(zfunds + supply)/(supply12+zf12))-1.)));
result.push_back(Pair("blocksperyear", (int64_t)blocks_per_year));
}
}
}
} else result.push_back(Pair("error", "couldnt calculate supply"));
} else {
result.push_back(Pair("error", "invalid height"));

View File

@@ -31,6 +31,17 @@ CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stop
CScheduler::~CScheduler()
{
/*int32_t i;
if ( nThreadsServicingQueue != 0 )
{
for (i=0; i<10; i++)
{
sleep(1);
fprintf(stderr,"CScheduler nThreadsServicingQueue.%d\n",(int32_t)nThreadsServicingQueue);
if ( nThreadsServicingQueue == 0 )
break;
}
}*/
assert(nThreadsServicingQueue == 0);
}

View File

@@ -961,7 +961,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
if (GetTransaction(hash,tx,blockhash,true))
{
CWalletTx wtx(pwallet,tx);
pwallet->AddToWallet(wtx, true, NULL);
pwallet->AddToWallet(wtx, false, NULL);
reAdded++;
}
}