This commit is contained in:
jl777
2016-11-06 10:09:37 -03:00
parent 31a468bdf4
commit 755ead9889
3 changed files with 52 additions and 33 deletions

View File

@@ -17,6 +17,8 @@
#define H_KOMODO_H
// Todo: handle reorg: clear all entries above reorged height
// smooth consensus price
//
#include <stdint.h>
#include <stdio.h>
@@ -29,6 +31,8 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n
char *komodo_issuemethod(char *method,char *params,uint16_t port);
#define GENESIS_NBITS 0x1f00ffff
#define KOMODO_MINRATIFY 7
#include "komodo_globals.h"
#include "komodo_utils.h"
//queue_t DepositsQ,PendingsQ;
@@ -326,13 +330,13 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,
int32_t komodo_isratify(int32_t isspecial,int32_t numvalid)
{
if ( isspecial != 0 && numvalid > 13 )
if ( isspecial != 0 && numvalid >= KOMODO_MINRATIFY )
return(1);
else return(0);
}
// Special tx have vout[0] -> CRYPTO777
// with more than 13 pay2pubkey outputs -> ratify
// with more than KOMODO_MINRATIFY pay2pubkey outputs -> ratify
// 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
@@ -350,8 +354,8 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
fprintf(stderr,"komodo_connect.(%s) waiting for realtime RT.%u now.%u\n",ASSETCHAINS_SYMBOL,KOMODO_REALTIME,(uint32_t)time(NULL));
sleep(3);
}
KOMODO_INITDONE = (uint32_t)time(NULL);
}
KOMODO_INITDONE = (uint32_t)time(NULL);
if ( pindex != 0 )
{
height = pindex->nHeight;
@@ -422,7 +426,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
}
}
}
if ( komodo_isratify(1,numvalid) > 7 )
if ( komodo_isratify(1,numvalid) >= KOMODO_MINRATIFY && numvouts > 13 )
{
memset(&txhash,0,sizeof(txhash));
komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0);

View File

@@ -217,7 +217,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
tokomodo = (komodo_is_issuer() == 0);
if ( opretbuf[0] == ((tokomodo == 0) ? 'D' : 'W') )
{
if ( opretlen == 34 )
if ( opretlen == 34 ) // any KMD tx
{
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
{
@@ -232,35 +232,38 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3
bitcoin_address(coinaddr,addrtype,rmd160,20);
checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height,base,fiatoshis);
typestr = "deposit";
if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 )
if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG )
{
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&txid)[i]);
printf(" <- txid.v%u ",vout);
for (i=0; i<33; i++)
printf("%02x",pubkey33[i]);
printf(" checkpubkey check %.8f v %.8f dest.(%s) height.%d\n",dstr(checktoshis),dstr(value),destaddr,height);
if ( value >= checktoshis && shortflag == ASSETCHAINS_SHORTFLAG )
if ( shortflag == 0 )
{
if ( komodo_paxfind(&space,txid,vout) == 0 )
komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height);
for (i=0; i<32; i++)
printf("%02x",((uint8_t *)&txid)[i]);
printf(" <- txid.v%u ",vout);
for (i=0; i<33; i++)
printf("%02x",pubkey33[i]);
printf(" checkpubkey check %.8f v %.8f dest.(%s) height.%d\n",dstr(checktoshis),dstr(value),destaddr,height);
if ( value >= checktoshis )
{
if ( komodo_paxfind(&space,txid,vout) == 0 )
komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height);
}
}
}
else if ( tokomodo != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
{
for (i=0; i<opretlen; i++)
printf("%02x",opretbuf[i]);
printf(" opret[%c] tokomodo.%d value %.8f vs check %.8f\n",opretbuf[0],tokomodo,dstr(value),dstr(checktoshis));
if ( value <= checktoshis )
else // short
{
for (i=0; i<opretlen; i++)
printf("%02x",opretbuf[i]);
printf(" opret[%c] tokomodo.%d value %.8f vs check %.8f\n",opretbuf[0],tokomodo,dstr(value),dstr(checktoshis));
if ( value <= checktoshis )
{
}
}
}
}
}
else if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 )
{
if ( tokomodo == 0 && opretbuf[0] == 'I' )
if ( tokomodo == 0 && opretbuf[0] == 'I' ) // assetchain coinbase
{
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
{
@@ -302,7 +305,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int
}
else komodo_stateupdate(height,0,0,0,utxid,0,0,0,0,0,value,&script[offset],opretlen,vout);
}
else if ( numvouts > 13 )
else if ( numvouts >= KOMODO_MINRATIFY )
typestr = "ratify";
}
@@ -397,9 +400,10 @@ void komodo_gateway_iteration(char *symbol)
{
for (i=0; i<1000 && KMDHEIGHT<kmdheight; i++,KMDHEIGHT++)
{
if ( (KMDHEIGHT % 100) == 0 )
if ( (KMDHEIGHT % 10) == 0 )
{
fprintf(stderr,"%s.%d ",symbol,KMDHEIGHT);
if ( (KMDHEIGHT % 100) == 0 )
fprintf(stderr,"%s.%d ",symbol,KMDHEIGHT);
memset(&zero,0,sizeof(zero));
komodo_stateupdate(KMDHEIGHT,0,0,0,zero,0,0,0,0,KMDHEIGHT,0,0,0,0);
}

View File

@@ -508,11 +508,22 @@ void static BitcoinMiner(CWallet *pwallet)
unsigned int n = chainparams.EquihashN();
unsigned int k = chainparams.EquihashK();
extern int32_t ASSETCHAIN_INIT,KOMODO_INITDONE; extern uint8_t NOTARY_PUBKEY33[33];
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33);
int32_t notaryid = -1;
while ( ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0 )
{
sleep(1);
}
komodo_chosennotary(&notaryid,int32_t height,NOTARY_PUBKEY33);
std::string solver = GetArg("-equihashsolver", "tromp");
std::string solver;
if ( notaryid >= 0 )
solver = "tromp";
solver = "default";
assert(solver == "tromp" || solver == "default");
LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
//fprintf(stderr,"Mining with %s\n",solver.c_str());
fprintf(stderr,"Mining with %s\n",solver.c_str());
std::mutex m_cs;
bool cancelSolver = false;
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
@@ -606,10 +617,10 @@ void static BitcoinMiner(CWallet *pwallet)
solutionTargetChecks.increment();
if ( UintToArith256(pblock->GetHash()) > hashTarget )
return false;
if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+30 )
if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+20 )
{
printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+30-time(NULL)));
sleep(Mining_start+30-time(NULL));
printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+20-time(NULL)));
sleep(Mining_start+20-time(NULL));
}
// Found a solution
SetThreadPriority(THREAD_PRIORITY_NORMAL);
@@ -639,7 +650,7 @@ void static BitcoinMiner(CWallet *pwallet)
};
// TODO: factor this out into a function with the same API for each solver.
if (solver == "tromp") {
if (solver == "tromp" && notaryid >= 0 ) {
// Create solver and initialize it.
equi eq(1);
eq.setstate(&curr_state);