Browse Source

fix reorg problem

pull/27/head
blackjok3r 5 years ago
parent
commit
528f39542e
  1. 12
      src/komodo.h
  2. 13
      src/komodo_bitcoind.h
  3. 3
      src/komodo_notary.h
  4. 2
      src/komodo_structs.h
  5. 12
      src/main.cpp
  6. 2
      src/miner.cpp
  7. 6
      src/rpc/misc.cpp
  8. 2
      src/wallet/wallet.cpp

12
src/komodo.h

@ -695,15 +695,17 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar
}
else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 )
komodo_rwccdata((char *)"KMD",1,&ccdata,0);
/*else
{
fprintf(stderr, "NOT VALID NOTARISATION\n");
return (-2);
} */
// If we are checking a reorged notarisation tx we need to return true. So the coinbase can be recreated, otherwise notaries are not paid,
// if a notarisation TX is reorged before the next notarization happens!
if ( fJustCheck && matched != 0 && *notarizedheightp == sp->NOTARIZED_HEIGHT && sp->NOTARIZED_DESTTXID == desttxid && sp->NOTARIZED_HASH == srchash)
return(-2);
if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
{
if ( fJustCheck )
return(-2);
sp->prevNOTARIZED_HEIGHT = sp->NOTARIZED_HEIGHT;
sp->NOTARIZED_HEIGHT = *notarizedheightp;
sp->NOTARIZED_HASH = srchash;
sp->NOTARIZED_DESTTXID = desttxid;

13
src/komodo_bitcoind.h

@ -1776,7 +1776,7 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
return(isPOS);
}
int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp);
int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt);
uint64_t komodo_notarypayamount(int32_t height, int64_t notarycount)
{
@ -1786,14 +1786,15 @@ uint64_t komodo_notarypayamount(int32_t height, int64_t notarycount)
return(0);
}
// fetch notarised height
int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid;
int32_t notarizedht,prevMoMheight,prevnotarizedht; uint256 notarizedhash,txid;
uint64_t AmountToPay=0,ret=0;
notarizedht = komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid);
// dont think this can happen, just sanity check.
notarizedht = komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid,&prevnotarizedht);
// if this is the current checkpoint we will use the previous height.
// incase of reorgs, we still need to create the notary payment.
if ( height == notarizedht )
{
fprintf(stderr, "komodo_notarypayamount failed notarized height = height\n");
return(0);
notarizedht = prevnotarizedht;
fprintf(stderr, "using the current checkpoint, calculating based on previous notarized height!\n");
}
// how many block since last notarisation.
int32_t n = height - notarizedht;

3
src/komodo_notary.h

@ -452,13 +452,14 @@ int32_t komodo_prevMoMheight()
return(0);
}
int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp)
int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt)
{
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp;
if ( (sp= komodo_stateptr(symbol,dest)) != 0 )
{
*hashp = sp->NOTARIZED_HASH;
*txidp = sp->NOTARIZED_DESTTXID;
*prevNotarizedHt = sp->prevNOTARIZED_HEIGHT;
*prevMoMheightp = komodo_prevMoMheight();
return(sp->NOTARIZED_HEIGHT);
}

2
src/komodo_structs.h

@ -119,7 +119,7 @@ struct komodo_ccdata
struct komodo_state
{
uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID,MoM;
int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT,MoMdepth;
int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT,prevNOTARIZED_HEIGHT,MoMdepth;
uint32_t SAVEDTIMESTAMP;
uint64_t deposited,issued,withdrawn,approved,redeemed,shorted;
struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS,last_NPOINTSi;

12
src/main.cpp

@ -3909,8 +3909,8 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
return AbortNode(state, "Failed to read block");
//if ( ASSETCHAINS_SYMBOL[0] != 0 || pindexDelete->GetHeight() > 1400000 )
{
int32_t prevMoMheight; uint256 notarizedhash,txid;
komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid);
int32_t prevMoMheight,prevnotarizedht; uint256 notarizedhash,txid;
komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid,&prevnotarizedht);
if ( block.GetHash() == notarizedhash )
{
fprintf(stderr,"DisconnectTip trying to disconnect notarized block at ht.%d\n",(int32_t)pindexDelete->GetHeight());
@ -4244,8 +4244,8 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
assert(MAX_REORG_LENGTH > 0);//, "We must be able to reorg some distance");
if (reorgLength > MAX_REORG_LENGTH)
{
int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid;
notarizedht = komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid);
int32_t notarizedht,prevnotarizedht,prevMoMheight; uint256 notarizedhash,txid;
notarizedht = komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid,&prevnotarizedht);
if ( pindexFork->GetHeight() < notarizedht )
{
fprintf(stderr,"pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht);
@ -5591,8 +5591,8 @@ uint64_t CalculateCurrentUsage()
/* Prune a block file (modify associated database entries)*/
bool PruneOneBlockFile(bool tempfile, const int fileNumber)
{
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height;
notarized_height = komodo_notarized_height(&prevMoMheight,&notarized_hash,&notarized_desttxid);
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,prevnotarized_height;
notarized_height = komodo_notarized_height(&prevMoMheight,&notarized_hash,&notarized_desttxid,&prevnotarized_height);
//fprintf(stderr, "pruneblockfile.%i\n",fileNumber); sleep(15);
for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); ++it)
{

2
src/miner.cpp

@ -416,7 +416,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
else if ( notarizedheight > last_notarizedheight )
continue; // leave this notarisation for the next block, it will be valid!
else if ( notarizedheight == last_notarizedheight )
continue; // this shouldnt happen :S
continue; // this shouldnt happen, it would mean there are 2 notarisations for the same block!
else
{
// we need to remove the last seen notarzation from block

6
src/rpc/misc.cpp

@ -63,7 +63,7 @@ int32_t Jumblr_depositaddradd(char *depositaddr);
int32_t Jumblr_secretaddradd(char *secretaddr);
uint64_t komodo_interestsum();
int32_t komodo_longestchain();
int32_t komodo_notarized_height(int32_t *prevhtp,uint256 *hashp,uint256 *txidp);
int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp,int32_t *prevNotarizedHt);
bool komodo_txnotarizedconfirmed(uint256 txid);
uint32_t komodo_chainactive_timestamp();
int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp);
@ -164,7 +164,7 @@ UniValue getnotarysendmany(const UniValue& params, bool fHelp)
UniValue getinfo(const UniValue& params, bool fHelp)
{
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height;
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,prevnotarized_height,longestchain,kmdnotarized_height,txid_height;
if (fHelp || params.size() != 0)
throw runtime_error(
"getinfo\n"
@ -200,7 +200,7 @@ UniValue getinfo(const UniValue& params, bool fHelp)
proxyType proxy;
GetProxy(NET_IPV4, proxy);
notarized_height = komodo_notarized_height(&prevMoMheight,&notarized_hash,&notarized_desttxid);
notarized_height = komodo_notarized_height(&prevMoMheight,&notarized_hash,&notarized_desttxid,&prevnotarized_height);
//fprintf(stderr,"after notarized_height %u\n",(uint32_t)time(NULL));
UniValue obj(UniValue::VOBJ);

2
src/wallet/wallet.cpp

@ -2836,6 +2836,8 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
void CWallet::ReacceptWalletTransactions()
{
if ( IsInitialBlockDownload() )
return;
// If transactions aren't being broadcasted, don't let them into local mempool either
if (!fBroadcastTransactions)
return;

Loading…
Cancel
Save