Compare commits

...

20 Commits

Author SHA1 Message Date
Jonathan "Duke" Leto d40e640b87 Add size_on_disk to getblockchaininfo from BTC master 6 years ago
Duke Leto 3ff1205367
Merge pull request #151 from MyHush/getchaintips 6 years ago
Jonathan "Duke" Leto 52e6bd74ca Make getchaintips tests pass (they never worked previously, because of assumptions about the number of blocks mined in regtest inherited from BTC/ZEC) and add test for new minBranchLen argument 6 years ago
Jonathan "Duke" Leto 9e54048778 Fix getchaintips to only include currently active chain tip when it makes sense 6 years ago
FireMartZ ad9cb03132 Merge remote-tracking branch 'remotes/origin/v2.0.0-rc' into dev 6 years ago
FireMartZ 38c1e0ebaf Add getchaintips parameter 0 in the convertible list. 6 years ago
Jonathan "Duke" Leto aa00b0421c Make getchaintips work correctly via curl, but still get 'JSON value is not an integer as expected' from hush-cli 6 years ago
Jonathan "Duke" Leto dcb5f16c93 Merge branch 'dev' into getchaintips 6 years ago
Martin 24d581ff8a Define HAVE_CONFIG_H to windres to fetch version from config/bitcoin-config.h 6 years ago
FireMartZ 401b860f65
Merge pull request #148 from MyHush/master 6 years ago
FireMartZ f25acdf47b Move dpow print outs from stdout to debug log file. 6 years ago
Jonathan "Duke" Leto 09b31a9ae9 Merge branch 'dev' of github.com:MyHush/hush into dev 6 years ago
FireMartZ c7d6ba61c4
Update INSTALL.md 6 years ago
Martin b4f1a4ce23 Merge branch 'v2.0.0-rc' of https://github.com/MyHush/hush into v2.0.0-rc 6 years ago
Martin 17a9a39026 Update debian package script. 6 years ago
FireMartZ 7e81c6dd0b
Update debian package name. 6 years ago
FireMartZ bc7396110a
Update MAC build instructions. 6 years ago
Jonathan "Duke" Leto f5d84d3705 Organize install instructions and clarify some stuff 6 years ago
Jonathan "Duke" Leto cae75b122c Organize install instructions and clarify some stuff 6 years ago
Jonathan "Duke" Leto 4e66ca4026 WIP optional min branch length argument to getchaintips, which makes it easier to see mining attacks 6 years ago
  1. 18
      qa/rpc-tests/getchaintips.py
  2. 2
      src/Makefile.am
  3. 44
      src/komodo_validation011.h
  4. 4
      src/main.h
  5. 20
      src/rpcblockchain.cpp
  6. 1
      src/rpcclient.cpp
  7. 4
      zcutil/build-debian-package.sh

18
qa/rpc-tests/getchaintips.py

@ -13,13 +13,15 @@ from test_framework.util import assert_equal
class GetChainTipsTest (BitcoinTestFramework):
def run_test (self):
BitcoinTestFramework.run_test (self)
rpc = self.nodes[0]
#for node in self.nodes:
# node.generate(200)
tips = self.nodes[0].getchaintips ()
tips = self.nodes[0].getchaintips()
assert_equal (len (tips), 1)
assert_equal (tips[0]['branchlen'], 0)
assert_equal (tips[0]['height'], 200)
assert_equal (tips[0]['status'], 'active')
assert_equal (tips[0]['branchlen'], 0)
assert_equal (tips[0]['height'], 0)
# Split the network and build two chains of different lengths.
self.split_network ()
@ -31,14 +33,14 @@ class GetChainTipsTest (BitcoinTestFramework):
assert_equal (len (tips), 1)
shortTip = tips[0]
assert_equal (shortTip['branchlen'], 0)
assert_equal (shortTip['height'], 210)
assert_equal (shortTip['height'], 10)
assert_equal (tips[0]['status'], 'active')
tips = self.nodes[3].getchaintips ()
assert_equal (len (tips), 1)
longTip = tips[0]
assert_equal (longTip['branchlen'], 0)
assert_equal (longTip['height'], 220)
assert_equal (longTip['height'], 20)
assert_equal (tips[0]['status'], 'active')
# Join the network halves and check that we now have two tips
@ -55,5 +57,9 @@ class GetChainTipsTest (BitcoinTestFramework):
tips[1]['status'] = 'active'
assert_equal (tips[1], shortTip)
# test optional minBranchLen
tips = self.nodes[0].getchaintips(42)
assert_equal (len (tips), 0)
if __name__ == '__main__':
GetChainTipsTest ().main ()

2
src/Makefile.am

@ -613,7 +613,7 @@ clean-local:
.rc.o:
@test -f $(WINDRES)
$(AM_V_GEN) $(WINDRES) -DWINDRES_PREPROC -i $< -o $@
$(AM_V_GEN) $(WINDRES) -DWINDRES_PREPROC -DHAVE_CONFIG_H -i $< -o $@
.mm.o:
$(AM_V_CXX) $(OBJCXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \

44
src/komodo_validation011.h

@ -142,7 +142,7 @@ int32_t komodo_importaddress(std::string addr)
return(1);
}
}
printf("%s -> komodo_importaddress failed valid.%d\n",addr.c_str(),address.IsValid());
LogPrint("dpow","%s -> komodo_importaddress failed valid.%d\n",addr.c_str(),address.IsValid());
}
return(-1);
}
@ -514,7 +514,7 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex)
if ( n > 0 )
{
bytes[0] = unhex(hex[0]);
printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex));
LogPrint("dpow","decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex));
}
bytes++;
hex++;
@ -754,7 +754,7 @@ void komodo_importpubkeys()
//fprintf(stderr,"pubkey=%s, addr=%s\n", pubkey, addr.c_str() );
if ( (val= komodo_importaddress(addr)) < 0 )
LogPrintf("dpow: error importing (%s)\n",addr.c_str());
LogPrint("dpow","dpow: error importing (%s)\n",addr.c_str());
else if ( val == 0 )
dispflag++;
}
@ -954,7 +954,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n
{
if ( NPOINTS[i].nHeight >= nHeight )
{
LogPrintf("dpow: flag.1 i.%d np->ht %d [%d].ht %d >= nHeight.%d, last.%d num.%d\n",i,np->nHeight,i,NPOINTS[i].nHeight,nHeight,last_NPOINTSi,NUM_NPOINTS);
LogPrint("dpow","dpow: flag.1 i.%d np->ht %d [%d].ht %d >= nHeight.%d, last.%d num.%d\n",i,np->nHeight,i,NPOINTS[i].nHeight,nHeight,last_NPOINTSi,NUM_NPOINTS);
flag = 1;
break;
}
@ -1007,7 +1007,7 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
sep = "/";
#endif
sprintf(fname,"%s%snotarizations%s",GetDefaultDataDir().string().c_str(), sep.c_str(), suffix.c_str());
LogPrintf("dpow: fname.(%s)\n",fname);
LogPrint("dpow","dpow: fname.(%s)\n",fname);
if ( (fp= fopen(fname,"rb+")) == 0 )
fp = fopen(fname,"wb+");
else
@ -1030,12 +1030,12 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
NOTARIZED_MOMDEPTH = np->MoMdepth;
//fprintf(stderr,"%d ",np->notarized_height);
fpos = ftell(fp);
} else LogPrintf("dpow: %s error with notarization ht.%d %s\n",ASSETCHAINS_SYMBOL,N.notarized_height,pindex->GetBlockHash().ToString().c_str());
} else LogPrint("dpow","dpow: %s error with notarization ht.%d %s\n",ASSETCHAINS_SYMBOL,N.notarized_height,pindex->GetBlockHash().ToString().c_str());
}
if ( ftell(fp) != fpos )
fseek(fp,fpos,SEEK_SET);
}
LogPrintf("dpow: finished loading %s [pubkey %s]\n",fname,NOTARY_PUBKEY.c_str());
LogPrint("dpow","dpow: finished loading %s [pubkey %s]\n",fname,NOTARY_PUBKEY.c_str());
didinit = 1;
}
if ( notarized_height == 0 )
@ -1045,16 +1045,16 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
}
if ( notarized_height >= nHeight )
{
LogPrintf("dpow: komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight);
LogPrint("dpow","dpow: komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight);
return;
}
pindex = komodo_chainactive(notarized_height);
if ( pindex == 0 || pindex->GetBlockHash() != notarized_hash || notarized_height != pindex->nHeight )
{
LogPrintf("dpow: komodo_notarized_update reject nHeight.%d notarized_height.%d:%d\n",nHeight,notarized_height,(int32_t)pindex->nHeight);
LogPrint("dpow","dpow: komodo_notarized_update reject nHeight.%d notarized_height.%d:%d\n",nHeight,notarized_height,(int32_t)pindex->nHeight);
return;
}
LogPrintf("dpow: komodo_notarized_update nHeight.%d notarized_height.%d prev.%d\n",nHeight,notarized_height,NPOINTS!=0?NPOINTS[NUM_NPOINTS-1].notarized_height:-1);
LogPrint("dpow","dpow: komodo_notarized_update nHeight.%d notarized_height.%d prev.%d\n",nHeight,notarized_height,NPOINTS!=0?NPOINTS[NUM_NPOINTS-1].notarized_height:-1);
portable_mutex_lock(&komodo_mutex);
NPOINTS = (struct notarized_checkpoint *)realloc(NPOINTS,(NUM_NPOINTS+1) * sizeof(*NPOINTS));
np = &NPOINTS[NUM_NPOINTS++];
@ -1073,7 +1073,7 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
{
if ( fwrite(np,1,sizeof(*np),fp) == sizeof(*np) )
fflush(fp);
else LogPrintf("dpow: error writing notarization to %d\n",(int32_t)ftell(fp));
else LogPrint("dpow","dpow: error writing notarization to %d\n",(int32_t)ftell(fp));
}
// add to stored notarizations
portable_mutex_unlock(&komodo_mutex);
@ -1092,7 +1092,7 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
{
notary = mapBlockIndex[notarized_hash];
if ( IS_NOTARY )
printf("nHeight.%d -> (%d %s)\n",pindex->nHeight,notarized_height,notarized_hash.ToString().c_str());
LogPrint("dpow","nHeight.%d -> (%d %s)\n",pindex->nHeight,notarized_height,notarized_hash.ToString().c_str());
if ( notary->nHeight == notarized_height ) // if notarized_hash not in chain, reorg
{
if ( nHeight < notarized_height )
@ -1132,7 +1132,7 @@ void komodo_voutupdate(int32_t txi,int32_t vout,uint8_t *scriptbuf,int32_t scrip
opretlen = scriptbuf[len++];
opretlen += (scriptbuf[len++] << 8);
}
printf("opretlen.%d vout.%d [%s].(%s)\n",opretlen,vout,(char *)&scriptbuf[len+32*2+4],ASSETCHAINS_SYMBOL);
LogPrint("dpow","opretlen.%d vout.%d [%s].(%s)\n",opretlen,vout,(char *)&scriptbuf[len+32*2+4],ASSETCHAINS_SYMBOL);
if ( vout == 1 && opretlen-3 >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
{
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&hash);
@ -1158,12 +1158,12 @@ void komodo_voutupdate(int32_t txi,int32_t vout,uint8_t *scriptbuf,int32_t scrip
}
else
{
LogPrintf("dpow: VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,MoM.ToString().c_str(),MoMdepth);
LogPrint("dpow","dpow: VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,MoM.ToString().c_str(),MoMdepth);
}
}
komodo_notarized_update(height,*notarizedheightp,hash,desttxid,MoM,MoMdepth);
LogPrintf("dpow: %s ht.%d NOTARIZED.%d %s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,hash.ToString().c_str(),"KMD",desttxid.ToString().c_str(),opretlen,len);
} else LogPrintf("dpow: notarized.%d ht %d vs prev %d vs height.%d\n",notarized,*notarizedheightp,NOTARIZED_HEIGHT,height);
LogPrint("dpow","dpow: %s ht.%d NOTARIZED.%d %s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,hash.ToString().c_str(),"KMD",desttxid.ToString().c_str(),opretlen,len);
} else LogPrint("dpow","dpow: notarized.%d ht %d vs prev %d vs height.%d\n",notarized,*notarizedheightp,NOTARIZED_HEIGHT,height);
}
}
}
@ -1187,7 +1187,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
else
{
if ( pindex->nHeight != hwmheight )
LogPrintf("dpow: %s hwmheight.%d vs pindex->nHeight.%d t.%u reorg.%d\n",ASSETCHAINS_SYMBOL,hwmheight,pindex->nHeight,(uint32_t)pindex->nTime,hwmheight-pindex->nHeight);
LogPrint("dpow","dpow: %s hwmheight.%d vs pindex->nHeight.%d t.%u reorg.%d\n",ASSETCHAINS_SYMBOL,hwmheight,pindex->nHeight,(uint32_t)pindex->nTime,hwmheight-pindex->nHeight);
}
if ( pindex != 0 )
@ -1225,11 +1225,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
if ( numvalid >= KOMODO_MINRATIFY )
notarized = 1;
if ( IS_NOTARY )
printf("(tx.%d: ",i);
LogPrint("dpow","(tx.%d: ",i);
for (j=0; j<numvouts; j++)
{
if ( IS_NOTARY )
printf("%.8f ",dstr(block.vtx[i].vout[j].nValue));
LogPrint("dpow","%.8f ",dstr(block.vtx[i].vout[j].nValue));
len = block.vtx[i].vout[j].scriptPubKey.size();
if ( len >= (int32_t)sizeof(uint32_t) && len <= (int32_t)sizeof(scriptbuf) )
{
@ -1238,10 +1238,10 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
}
}
if ( NOTARY_PUBKEY33[0] != 0 )
printf(") ");
LogPrint("dpow",") ");
if ( NOTARY_PUBKEY33[0] != 0 )
printf("%s ht.%d\n",ASSETCHAINS_SYMBOL,height);
LogPrintf("dpow: [%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx);
LogPrint("dpow","%s ht.%d\n",ASSETCHAINS_SYMBOL,height);
LogPrint("dpow","dpow: [%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx);
}
} else LogPrint("dpow","komodo_connectblock: unexpected null pindex\n");

4
src/main.h

@ -872,8 +872,6 @@ extern CBlockTreeDB *pblocktree;
*/
int GetSpendHeight(const CCoinsViewCache& inputs);
namespace Consensus {
bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, const Consensus::Params& consensusParams);
}
uint64_t CalculateCurrentUsage();
#endif // BITCOIN_MAIN_H

20
src/rpcblockchain.cpp

@ -889,6 +889,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
" \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
" \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
" \"size_on_disk\": xxxxxx, (numeric) the estimated size of the block and undo files on disk\n"
" \"commitments\": xxxxxx, (numeric) the current number of note commitments in the commitment tree\n"
" \"softforks\": [ (array) status of softforks in progress\n"
" {\n"
@ -920,6 +921,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip())));
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
obj.push_back(Pair("pruned", fPruneMode));
obj.push_back(Pair("size_on_disk", CalculateCurrentUsage()));
ZCIncrementalMerkleTree tree;
pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), tree);
@ -965,7 +967,7 @@ struct CompareBlocksByHeight
UniValue getchaintips(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
if (fHelp || params.size() > 1)
throw runtime_error(
"getchaintips\n"
"Return information about all known tips in the block tree,"
@ -998,6 +1000,10 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
LOCK(cs_main);
int minBranchLen = 0;
if (params.size() > 0)
minBranchLen = params[0].get_int();
/* Build up a list of chain tips. We start with the list of all
known blocks, and successively remove blocks that appear as pprev
of another block. */
@ -1011,18 +1017,22 @@ UniValue getchaintips(const UniValue& params, bool fHelp)
setTips.erase(pprev);
}
// Always report the currently active tip.
setTips.insert(chainActive.Tip());
if (minBranchLen == 0) {
// insert currently active tip
setTips.insert(chainActive.Tip());
}
/* Construct the output array. */
UniValue res(UniValue::VARR);
BOOST_FOREACH(const CBlockIndex* block, setTips)
{
const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight;
if (branchLen < minBranchLen)
continue;
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("height", block->nHeight));
obj.push_back(Pair("hash", block->phashBlock->GetHex()));
const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight;
obj.push_back(Pair("branchlen", branchLen));
string status;

1
src/rpcclient.cpp

@ -46,6 +46,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "getbalance", 1 },
{ "getbalance", 2 },
{ "getblockhash", 0 },
{ "getchaintips", 0 },
{ "move", 2 },
{ "move", 3 },
{ "sendfrom", 2 },

4
zcutil/build-debian-package.sh

@ -51,8 +51,8 @@ cp $SRC_DOC/man/hushd.1 $DEB_MAN
cp $SRC_DOC/man/hush-cli.1 $DEB_MAN
cp $SRC_DOC/man/hush-fetch-params.1 $DEB_MAN
# Copy bash completion files
cp $SRC_PATH/contrib/bitcoind.bash-completion $DEB_CMP/hushd
cp $SRC_PATH/contrib/bitcoin-cli.bash-completion $DEB_CMP/hush-cli
cp $SRC_PATH/contrib/hushd.bash-completion $DEB_CMP/hushd
cp $SRC_PATH/contrib/hush-cli.bash-completion $DEB_CMP/hush-cli
# Gzip files
gzip --best -n $DEB_DOC/changelog
gzip --best -n $DEB_DOC/changelog.Debian

Loading…
Cancel
Save