Browse Source

Merge remote-tracking branch 'jl777/FSM' into duke

warmup
Jonathan "Duke" Leto 5 years ago
parent
commit
6fab065e45
  1. 169
      qa/rpc-tests/nspv_client_test.py
  2. 114
      qa/rpc-tests/src/nspv_client_test.py
  3. 13
      src/bitcoind.cpp
  4. 2
      src/cc/CCtokens.cpp
  5. 10
      src/cc/CCtx.cpp
  6. 6
      src/cc/CCutils.cpp
  7. 30
      src/cc/payments.cpp
  8. 2
      src/consensus/upgrades.cpp
  9. 21
      src/init.cpp
  10. 28
      src/komodo_bitcoind.h
  11. 5
      src/komodo_defs.h
  12. 1
      src/komodo_globals.h
  13. 4
      src/komodo_nSPV.h
  14. 7
      src/komodo_nSPV_defs.h
  15. 11
      src/komodo_nSPV_fullnode.h
  16. 15
      src/komodo_nSPV_superlite.h
  17. 5
      src/komodo_utils.h
  18. 72
      src/main.cpp
  19. 38
      src/miner.cpp
  20. 2
      src/net.cpp
  21. 140
      src/pow.cpp
  22. 4
      src/rpc/blockchain.cpp
  23. 6
      src/rpc/mining.cpp
  24. 2
      src/rpc/misc.cpp
  25. 4
      src/rpc/rawtransaction.cpp
  26. 8
      src/script/sign.cpp
  27. 2
      src/timedata.cpp
  28. 20
      src/tui/lib/tuilib.py
  29. 24
      src/wallet/rpcdump.cpp
  30. 8
      src/wallet/rpcwallet.cpp

169
qa/rpc-tests/nspv_client_test.py

@ -0,0 +1,169 @@
import sys
sys.path.append('../../src/tui')
from lib import tuilib
import unittest
import time
'''
specify chain ticker (daemon should be up), wif which will be imported and address to which you want to broadcast
change chain parameters if needed or add a new chain to test below
added 1 second sleep after each case to surely not face the nSPV server limitation (1 call/second)
'''
wif = ''
dest_address = ''
amount = '0.01'
chain = 'ILN'
if not wif or not dest_address:
raise Exception("Please set test wif and address to send transactions to")
rpc_proxy = tuilib.def_credentials(chain)
chain_params = {"KMD": {
'tx_list_address': 'RGShWG446Pv24CKzzxjA23obrzYwNbs1kA',
'min_chain_height': 1468080,
'notarization_height': '1468000',
'prev_notarization_h': 1467980,
'next_notarization_h': 1468020,
'hdrs_proof_low': '1468100',
'hdrs_proof_high': '1468200',
'numhdrs_expected': 151,
'tx_proof_id': 'f7beb36a65bc5bcbc9c8f398345aab7948160493955eb4a1f05da08c4ac3784f',
'tx_spent_height': 1456212,
'tx_proof_height': '1468520',
},
"ILN": {
'tx_list_address': 'RUp3xudmdTtxvaRnt3oq78FJBjotXy55uu',
'min_chain_height': 3689,
'notarization_height': '2000',
'prev_notarization_h': 1998,
'next_notarization_h': 2008,
'hdrs_proof_low': '2000',
'hdrs_proof_high': '2100',
'numhdrs_expected': 113,
'tx_proof_id': '67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418',
'tx_spent_height': 2681,
'tx_proof_height': '2690',
}
}
class TestNspvClient(unittest.TestCase):
def test_nspv_mempool(self):
print("testing nspv_mempool")
result = rpc_proxy.nspv_mempool("0", dest_address, "0")
self.assertEqual(result["result"], "success")
self.assertEqual(result["address"], dest_address)
self.assertEqual(result["isCC"], 0)
time.sleep(1)
def test_nspv_listtransactions(self):
print("testing nspv_listtransactions")
rpc_proxy.nspv_login(wif)
result = rpc_proxy.nspv_listtransactions()
self.assertEqual(result["result"], "success")
time.sleep(1)
result = rpc_proxy.nspv_listtransactions(chain_params.get(chain).get("tx_list_address"))
self.assertEqual(result["result"], "success")
self.assertEqual(result["address"], chain_params.get(chain).get("tx_list_address"))
rpc_proxy.nspv_logout()
def test_nspv_getinfo(self):
print("testing nspv_getinfo")
result = rpc_proxy.nspv_getinfo()
self.assertEqual(result["result"], "success")
self.assertGreater(result["height"], chain_params.get(chain).get("min_chain_height"))
time.sleep(1)
def test_nspv_notarizations(self):
print("testing nspv_notarizations")
result = rpc_proxy.nspv_notarizations(chain_params.get(chain).get("notarization_height"))
self.assertEqual(result["result"], "success")
self.assertEqual(result["prev"]["notarized_height"], chain_params.get(chain).get("prev_notarization_h"))
self.assertEqual(result["next"]["notarized_height"], chain_params.get(chain).get("next_notarization_h"))
time.sleep(1)
def test_nspv_hdrsproof(self):
print("testing nspv_hdrsproof")
result = rpc_proxy.nspv_hdrsproof(chain_params.get(chain).get("hdrs_proof_low"),
chain_params.get(chain).get("hdrs_proof_high"))
self.assertEqual(result["result"], "success")
self.assertEqual(result["numhdrs"], chain_params.get(chain).get("numhdrs_expected"))
time.sleep(1)
def test_nspv_login(self):
print("testing nspv_login")
result = rpc_proxy.nspv_login(wif)
self.assertEqual(result["result"], "success")
self.assertEqual(result["status"], "wif will expire in 777 seconds")
time.sleep(1)
def test_nspv_listunspent(self):
print("testing nspv_listunspent")
result = rpc_proxy.nspv_listunspent()
self.assertEqual(result["result"], "success")
time.sleep(1)
result = rpc_proxy.nspv_listunspent(chain_params.get(chain).get("tx_list_address"))
self.assertEqual(result["result"], "success")
self.assertEqual(result["address"], chain_params.get(chain).get("tx_list_address"))
def test_nspv_spend(self):
print("testing nspv_spend")
result = rpc_proxy.nspv_login(wif)
result = rpc_proxy.nspv_spend(dest_address, amount)
self.assertEqual(result["result"], "success")
self.assertEqual(result["vout"][0]["valueZat"], 1000000)
time.sleep(1)
def test_nspv_broadcast(self):
print("testing nspv_broadcast")
result = rpc_proxy.nspv_login(wif)
broadcast_hex = rpc_proxy.nspv_spend(dest_address, amount)["hex"]
time.sleep(1)
result = rpc_proxy.nspv_broadcast(broadcast_hex)
self.assertEqual(result["result"], "success")
self.assertEqual(result["retcode"], 1)
self.assertEqual(result["expected"], result["broadcast"])
print("Broadcast txid: " + result["broadcast"])
time.sleep(1)
def test_nspv_logout(self):
print("testing nspv_logout")
rpc_proxy.nspv_login(wif)
time.sleep(1)
rpc_proxy.nspv_logout()
time.sleep(1)
result = rpc_proxy.nspv_spend(dest_address, amount)
self.assertEqual(result["result"], "error")
self.assertEqual(result["error"], "wif expired")
time.sleep(1)
def test_nspv_spentinfo(self):
print("testing nspv_spent_info")
result = rpc_proxy.nspv_spentinfo(chain_params.get(chain).get("tx_proof_id"), "1")
self.assertEqual(result["result"], "success")
self.assertEqual(result["spentheight"], chain_params.get(chain).get("tx_spent_height"))
time.sleep(1)
def test_nspv_txproof(self):
print("testing nspv_txproof")
result = rpc_proxy.nspv_txproof(chain_params.get(chain).get("tx_proof_id"),
chain_params.get(chain).get("tx_proof_height"))
self.assertEqual(result["txid"], chain_params.get(chain).get("tx_proof_id"))
time.sleep(1)
def test_nspv_login_timout(self):
print("testing auto-logout in 777 seconds")
rpc_proxy.nspv_login(wif)
time.sleep(778)
result = rpc_proxy.nspv_spend(dest_address, amount)
self.assertEqual(result["result"], "error")
self.assertEqual(result["error"], "wif expired")
time.sleep(1)
if __name__ == '__main__':
unittest.main()

114
qa/rpc-tests/src/nspv_client_test.py

@ -1,114 +0,0 @@
import sys
sys.path.append('../../src/tui')
from lib import tuilib
import unittest
'''
specify chain ticker (daemon should be up), wif which will be imported and address to which you want to broadcast
added 1 second sleep after each case to surely not face the nSPV server limitation (1 call/second)
'''
wif = ''
dest_address = 'RMjy5VkHFJkXTJDTJ3XX1zVzukP48sKyva'
amount = '0.1'
chain = 'ILN'
rpc_proxy = tuilib.def_credentials(chain)
class TestNspvClient(unittest.TestCase):
def test_nspv_getinfo(self):
print("testing nspv_getinfo")
result = rpc_proxy.nspv_getinfo()
self.assertEqual(result["result"], "success")
self.assertGreater(result["height"], 2689)
time.sleep(1)
def test_nspv_notarizations(self):
print("testing nspv_notarizations")
result = rpc_proxy.nspv_notarizations("2000")
self.assertEqual(result["result"], "success")
self.assertEqual(result["prev"]["notarized_height"], 1998)
self.assertEqual(result["next"]["notarized_height"], 2002)
time.sleep(1)
def test_nspv_hdrsproof(self):
print("testing nspv_hdrsproof")
result = rpc_proxy.nspv_hdrsproof("2000", "2100")
self.assertEqual(result["result"], "success")
self.assertEqual(result["numhdrs"], 101)
time.sleep(1)
def test_nspv_login(self):
print("testing nspv_login")
result = rpc_proxy.nspv_login(wif)
self.assertEqual(result["result"], "success")
self.assertEqual(result["status"], "wif will expire in 777 seconds")
time.sleep(1)
def test_nspv_listunspent(self):
print("testing nspv_listunspent")
result = rpc_proxy.nspv_listunspent()
self.assertEqual(result["result"], "success")
time.sleep(1)
result = rpc_proxy.nspv_listunspent("RQ1mvCUcziWzRwE8Ugtex29VjoFjRzxQJT")
self.assertEqual(result["result"], "error")
def test_nspv_spend(self):
print("testing nspv_spend")
result = rpc_proxy.nspv_login(wif)
result = rpc_proxy.nspv_spend(dest_address, amount)
self.assertEqual(result["result"], "success")
self.assertEqual(result["vout"][0]["valueZat"], 10000000)
time.sleep(1)
def test_nspv_broadcast(self):
print("testing nspv_broadcast")
result = rpc_proxy.nspv_login(wif)
broadcast_hex = rpc_proxy.nspv_spend(dest_address, amount)["hex"]
time.sleep(1)
result = rpc_proxy.nspv_broadcast(broadcast_hex)
self.assertEqual(result["result"], "success")
self.assertEqual(result["retcode"], 1)
self.assertEqual(result["expected"], result["broadcast"])
print("Broadcast txid: " + result["broadcast"])
time.sleep(1)
def test_nspv_logout(self):
print("testing nspv_logout")
rpc_proxy.nspv_login(wif)
time.sleep(1)
rpc_proxy.nspv_logout()
time.sleep(1)
result = rpc_proxy.nspv_spend(dest_address, amount)
self.assertEqual(result["result"], "error")
self.assertEqual(result["error"], "wif expired")
time.sleep(1)
def test_nspv_spentinfo(self):
print("testing nspv_spent_info")
result = rpc_proxy.nspv_spentinfo("67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418", "1")
self.assertEqual(result["result"], "success")
self.assertEqual(result["spentheight"], 2681)
time.sleep(1)
def test_nspv_txproof(self):
print("testing nspv_txproof")
result = rpc_proxy.nspv_txproof("67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418", "2673")
self.assertEqual(result["txid"], "67ffe0eaecd6081de04675c492a59090b573ee78955c4e8a85b8ac0be0e8e418")
time.sleep(1)
def test_nspv_login_timout(self):
print("testing auto-logout in 777 seconds")
rpc_proxy.nspv_login(wif)
time.sleep(777)
result = rpc_proxy.nspv_spend(dest_address, amount)
self.assertEqual(result["result"], "error")
self.assertEqual(result["error"], "wif expired")
time.sleep(1)
if __name__ == '__main__':
unittest.main()

13
src/bitcoind.cpp

@ -65,16 +65,25 @@ void komodo_passport_iteration();
uint64_t komodo_interestsum();
int32_t komodo_longestchain();
void komodo_cbopretupdate(int32_t forceflag);
CBlockIndex *komodo_chainactive(int32_t height);
void WaitForShutdown(boost::thread_group* threadGroup)
{
int32_t i,height; bool fShutdown = ShutdownRequested(); const uint256 zeroid;
int32_t i,height; CBlockIndex *pindex; bool fShutdown = ShutdownRequested(); const uint256 zeroid;
// Tell the main threads to shutdown.
if (komodo_currentheight()>KOMODO_EARLYTXID_HEIGHT && KOMODO_EARLYTXID!=zeroid && ((height=tx_height(KOMODO_EARLYTXID))==0 || height>KOMODO_EARLYTXID_HEIGHT))
{
fprintf(stderr,"error: earlytx must be before block height %d or tx does not exist\n",KOMODO_EARLYTXID_HEIGHT);
StartShutdown();
}
if ( ASSETCHAINS_STAKED == 0 && ASSETCHAINS_ADAPTIVEPOW == 0 && (pindex= komodo_chainactive(1)) != 0 )
{
if ( pindex->nTime > ADAPTIVEPOW_CHANGETO_DEFAULTON )
{
ASSETCHAINS_ADAPTIVEPOW = 1;
fprintf(stderr,"default activate adaptivepow\n");
} else fprintf(stderr,"height1 time %u vs %u\n",pindex->nTime,ADAPTIVEPOW_CHANGETO_DEFAULTON);
} //else fprintf(stderr,"cant find height 1\n");
if ( ASSETCHAINS_CBOPRET != 0 )
komodo_pricesinit();
while (!fShutdown)
@ -82,7 +91,7 @@ void WaitForShutdown(boost::thread_group* threadGroup)
//fprintf(stderr,"call passport iteration\n");
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
komodo_passport_iteration();
for (i=0; i<10; i++)
{

2
src/cc/CCtokens.cpp

@ -957,7 +957,7 @@ UniValue TokenInfo(uint256 tokenid)
result.push_back(Pair("error", "cant find tokenid"));
return(result);
}
if ( KOMODO_NSPV == 0 && hashBlock.IsNull()) {
if ( KOMODO_NSPV <= 0 && hashBlock.IsNull()) {
result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "the transaction is still in mempool"));
return(result);

10
src/cc/CCtx.cpp

@ -162,7 +162,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran
utxovout = mtx.vin[i].prevout.n;
if ( vintx.vout[utxovout].scriptPubKey.IsPayToCryptoCondition() == 0 )
{
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
{
if ( SignTx(mtx,i,vintx.vout[utxovout].nValue,vintx.vout[utxovout].scriptPubKey) == 0 )
fprintf(stderr,"signing error for vini.%d of %llx\n",i,(long long)vinimask);
@ -344,7 +344,7 @@ void NSPV_CCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &txids,char
void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs,char *coinaddr,bool ccflag)
{
int32_t type=0,i,n; char *ptr; std::string addrstr; uint160 hashBytes; std::vector<std::pair<uint160, int> > addresses;
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
NSPV_CCunspents(unspentOutputs,coinaddr,ccflag);
return;
@ -368,7 +368,7 @@ void SetCCunspents(std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValu
void SetCCtxids(std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,char *coinaddr,bool ccflag)
{
int32_t type=0,i,n; char *ptr; std::string addrstr; uint160 hashBytes; std::vector<std::pair<uint160, int> > addresses;
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
NSPV_CCtxids(addressIndex,coinaddr,ccflag);
return;
@ -555,7 +555,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs)
{
int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector<COutput> vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up;
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,&NSPV_U));
#ifdef ENABLE_WALLET
assert(pwalletMain != NULL);
@ -652,7 +652,7 @@ int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinput
{
int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
return(NSPV_AddNormalinputs(mtx,pubkey2pk(Mypubkey()),total,maxinputs,&NSPV_U));
utxos = (struct CC_utxo *)calloc(CC_MAXVINS,sizeof(*utxos));
if ( maxinputs > CC_MAXVINS )

6
src/cc/CCutils.cpp

@ -450,7 +450,7 @@ extern uint32_t NSPV_logintime;
bool Myprivkey(uint8_t myprivkey[])
{
char coinaddr[64],checkaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; uint8_t buf33[33];
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT )
{
@ -590,7 +590,7 @@ int32_t NSPV_coinaddr_inmempool(char const *logcategory,char *coinaddr,uint8_t C
int32_t myIs_coinaddr_inmempoolvout(char const *logcategory,char *coinaddr)
{
int32_t i,n; char destaddr[64];
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
return(NSPV_coinaddr_inmempool(logcategory,coinaddr,1));
BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx)
{
@ -619,7 +619,7 @@ int32_t myGet_mempool_txs(std::vector<CTransaction> &txs,uint8_t evalcode,uint8_
{
int i=0;
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
CTransaction tx; uint256 hashBlock;

30
src/cc/payments.cpp

@ -75,36 +75,6 @@
*/
// payments cc fix
#if (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#undef mpz_set_si
#undef mpz_get_si
#define GMP_LIMB_HIGHBIT ((mp_limb_t) 1 << (GMP_LIMB_BITS - 1))
#define GMP_NEG_CAST(T,x) (-(int64_t)((T)((x) + 1) - 1))
int64_t mpz_get_si (const mpz_t u)
{
mp_size_t us = u->_mp_size;
if (us > 0)
return (int64_t) (u->_mp_d[0] & ~GMP_LIMB_HIGHBIT);
else if (us < 0)
return (int64_t) (- u->_mp_d[0] | GMP_LIMB_HIGHBIT);
else
return 0;
}
void mpz_set_si (mpz_t r, int64_t x)
{
if (x >= 0)
mpz_set_ui (r, x);
else /* (x < 0) */
{
r->_mp_size = -1;
r->_mp_d[0] = GMP_NEG_CAST (uint64_t, x);
}
}
#endif
// start of consensus code
CScript EncodePaymentsTxidOpRet(int64_t allocation,std::vector<uint8_t> scriptPubKey,std::vector<uint8_t> destopret)

2
src/consensus/upgrades.cpp

@ -101,7 +101,7 @@ int CurrentEpoch(int nHeight, const Consensus::Params& params) {
uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params)
{
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
return(NSPV_BRANCHID);
return NetworkUpgradeInfo[CurrentEpoch(nHeight, params)].nBranchId;
}

21
src/init.cpp

@ -1059,7 +1059,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
RegisterAllCoreRPCCommands(tableRPC);
#ifdef ENABLE_WALLET
bool fDisableWallet = GetBoolArg("-disablewallet", false);
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
fDisableWallet = true;
nLocalServices = 0;
@ -1140,7 +1140,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// Option to startup with mocktime set (used for regression testing):
SetMockTime(GetArg("-mocktime", 0)); // SetMockTime(0) is a no-op
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
{
if (GetBoolArg("-peerbloomfilters", true))
nLocalServices |= NODE_BLOOM;
@ -1304,7 +1304,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
libsnark::inhibit_profiling_info = true;
libsnark::inhibit_profiling_counters = true;
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
{
// Initialize Zcash circuit parameters
ZC_LoadParams(chainparams);
@ -1485,7 +1485,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
}
#endif
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
std::vector<boost::filesystem::path> vImportFiles;
threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles));
@ -1909,11 +1909,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
PruneAndFlush();
}
}
if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) != 0 )
nLocalServices |= NODE_ADDRINDEX;
if ( GetBoolArg("-spentindex", DEFAULT_SPENTINDEX) != 0 )
nLocalServices |= NODE_SPENTINDEX;
fprintf(stderr,"nLocalServices %llx %d, %d\n",(long long)nLocalServices,GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),GetBoolArg("-spentindex", DEFAULT_SPENTINDEX));
if ( KOMODO_NSPV >= 0 )
{
if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) != 0 )
nLocalServices |= NODE_ADDRINDEX;
if ( GetBoolArg("-spentindex", DEFAULT_SPENTINDEX) != 0 )
nLocalServices |= NODE_SPENTINDEX;
fprintf(stderr,"nLocalServices %llx %d, %d\n",(long long)nLocalServices,GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),GetBoolArg("-spentindex", DEFAULT_SPENTINDEX));
}
// ********************************************************* Step 10: import blocks
if (mapArgs.count("-blocknotify"))

28
src/komodo_bitcoind.h

@ -1416,6 +1416,32 @@ uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256
return(addrhash.uints[0]);
}
arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime)
{
arith_uint256 origtarget,easy; int32_t diff,tipdiff; int64_t mult; bool fNegative,fOverflow; CBlockIndex *tipindex;
if ( height > 10 && (tipindex= komodo_chainactive(height - 1)) != 0 ) // disable offchain diffchange
{
diff = (nTime - tipindex->GetMedianTimePast());
tipdiff = (nTime - tipindex->nTime);
if ( tipdiff > 13*ASSETCHAINS_BLOCKTIME )
diff = tipdiff;
if ( diff >= 13 * ASSETCHAINS_BLOCKTIME && (height < 30 || tipdiff > 2*ASSETCHAINS_BLOCKTIME) )
{
mult = diff - 12 * ASSETCHAINS_BLOCKTIME;
mult = (mult / ASSETCHAINS_BLOCKTIME) * ASSETCHAINS_BLOCKTIME + ASSETCHAINS_BLOCKTIME / 2;
origtarget = bnTarget;
bnTarget = bnTarget * arith_uint256(mult * mult);
easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
if ( bnTarget < origtarget || bnTarget > easy ) // deal with overflow
{
bnTarget = easy;
fprintf(stderr,"tipdiff.%d diff.%d height.%d miner overflowed mult.%lld, set to mindiff\n",tipdiff,diff,height,(long long)mult);
} else fprintf(stderr,"tipdiff.%d diff.%d height.%d miner elapsed %d, adjust by factor of %lld\n",tipdiff,diff,height,diff,(long long)mult);
} //else fprintf(stderr,"height.%d tipdiff.%d diff %d, vs %d\n",height,tipdiff,diff,13*ASSETCHAINS_BLOCKTIME);
} else fprintf(stderr,"adaptive cant find height.%d\n",height);
return(bnTarget);
}
arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc)
{
int32_t oldflag = 0,dispflag = 0;
@ -2260,6 +2286,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
if ( height == 0 )
return(0);
}
//if ( ASSETCHAINS_ADAPTIVEPOW > 0 )
// bnTarget = komodo_adaptivepow_target(height,bnTarget,pblock->nTime);
if ( ASSETCHAINS_LWMAPOS != 0 && bhash > bnTarget )
{
// if proof of stake is active, check if this is a valid PoS block before we fail

5
src/komodo_defs.h

@ -15,9 +15,12 @@
#ifndef KOMODO_DEFS_H
#define KOMODO_DEFS_H
#include "arith_uint256.h"
#include "komodo_nk.h"
#define KOMODO_EARLYTXID_HEIGHT 100
#define ADAPTIVEPOW_CHANGETO_DEFAULTON 1572480000
#define ASSETCHAINS_MINHEIGHT 128
#define ASSETCHAINS_MAX_ERAS 7
#define KOMODO_ELECTION_GAP 2000
@ -262,6 +265,7 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] =
//#endif
extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC;
extern int8_t ASSETCHAINS_ADAPTIVEPOW;
int32_t MAX_BLOCK_SIZE(int32_t height);
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
@ -337,6 +341,7 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo
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);
int32_t komodo_currentheight();
int32_t komodo_notarized_bracket(struct notarized_checkpoint *nps[2],int32_t height);
arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime);
uint256 Parseuint256(const char *hexstr);

1
src/komodo_globals.h

@ -51,6 +51,7 @@ int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,USE_EXTERNAL
int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,ASSETCHAINS_SELFIMPORT,ASSETCHAINS_CCLIB;
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA;
int8_t ASSETCHAINS_ADAPTIVEPOW;
bool VERUS_MINTBLOCKS;
std::vector<uint8_t> Mineropret;
std::vector<std::string> vWhiteListAddress;

4
src/komodo_nSPV.h

@ -255,6 +255,7 @@ int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr)
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->othertxid),(uint8_t *)&ptr->othertxid);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->txidheight),&ptr->txidheight);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->timestamp),&ptr->timestamp);
return(len);
}
@ -286,7 +287,8 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight);
len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H);
//fprintf(stderr,"hdr rwlen.%d\n",len);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->version),&ptr->version);
//fprintf(stderr,"getinfo rwlen.%d\n",len);
return(len);
}

7
src/komodo_nSPV_defs.h

@ -17,8 +17,9 @@
#ifndef KOMODO_NSPV_DEFSH
#define KOMODO_NSPV_DEFSH
#define NSPV_POLLITERS 100
#define NSPV_POLLMICROS 30000
#define NSPV_PROTOCOL_VERSION 0x00000002
#define NSPV_POLLITERS 200
#define NSPV_POLLMICROS 50000
#define NSPV_MAXVINS 64
#define NSPV_AUTOLOGOUT 777
#define NSPV_BRANCHID 0x76b809bb
@ -110,6 +111,7 @@ struct NSPV_ntz
{
uint256 blockhash,txid,othertxid;
int32_t height,txidheight;
uint32_t timestamp;
};
struct NSPV_ntzsresp
@ -124,6 +126,7 @@ struct NSPV_inforesp
uint256 blockhash;
int32_t height,hdrheight;
struct NSPV_equihdr H;
uint32_t version;
};
struct NSPV_txproof

11
src/komodo_nSPV_fullnode.h

@ -69,11 +69,14 @@ int32_t NSPV_notarized_bracket(struct NSPV_ntzargs *prev,struct NSPV_ntzargs *ne
int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint256 desttxid,int32_t ntzheight)
{
CBlockIndex *pindex;
ptr->blockhash = *chainActive[ntzheight]->phashBlock;
ptr->height = ntzheight;
ptr->txidheight = txidht;
ptr->othertxid = desttxid;
ptr->txid = ntztxid;
if ( (pindex= komodo_chainactive(ptr->txidheight)) != 0 )
ptr->timestamp = pindex->nTime;
return(0);
}
@ -121,7 +124,7 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height)
int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight)
{
int32_t prevMoMheight,len = 0; CBlockIndex *pindex; struct NSPV_ntzsresp pair;
int32_t prevMoMheight,len = 0; CBlockIndex *pindex, *pindex2; struct NSPV_ntzsresp pair;
if ( (pindex= chainActive.LastTip()) != 0 )
{
ptr->height = pindex->GetHeight();
@ -130,9 +133,13 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight)
if ( NSPV_getntzsresp(&pair,ptr->height-1) < 0 )
return(-1);
ptr->notarization = pair.prevntz;
if ( (pindex2= komodo_chainactive(ptr->notarization.txidheight)) != 0 )
ptr->notarization.timestamp = pindex->nTime;
//fprintf(stderr, "timestamp.%i\n", ptr->notarization.timestamp );
if ( reqheight == 0 )
reqheight = ptr->height;
ptr->hdrheight = reqheight;
ptr->version = NSPV_PROTOCOL_VERSION;
if ( NSPV_setequihdr(&ptr->H,reqheight) < 0 )
return(-1);
return(sizeof(*ptr));
@ -537,7 +544,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a req
{
response.resize(1 + slen);
response[0] = NSPV_INFORESP;
//fprintf(stderr,"slen.%d\n",slen);
//fprintf(stderr,"slen.%d version.%d\n",slen,I.version);
if ( NSPV_rwinforesp(1,&response[1],&I) == slen )
{
//fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id);

15
src/komodo_nSPV_superlite.h

@ -139,7 +139,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector<uint8_t> response) // received a r
switch ( response[0] )
{
case NSPV_INFORESP:
//fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status
fprintf(stderr,"got version.%d info response %u size.%d height.%d\n",NSPV_inforesult.version,timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status
I = NSPV_inforesult;
NSPV_inforesp_purge(&NSPV_inforesult);
NSPV_rwinforesp(0,&response[1],&NSPV_inforesult);
@ -214,7 +214,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector<uint8_t> response) // received a r
CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind)
{
int32_t n,flag = 0; CNode *pnodes[64]; uint32_t timestamp = (uint32_t)time(NULL);
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
return(0);
if ( pnode == 0 )
{
@ -243,7 +243,7 @@ CNode *NSPV_req(CNode *pnode,uint8_t *msg,int32_t len,uint64_t mask,int32_t ind)
std::vector<uint8_t> request;
request.resize(len);
memcpy(&request[0],msg,len);
if ( (0) && KOMODO_NSPV != 0 )
if ( (0) && KOMODO_NSPV > 0 )
fprintf(stderr,"pushmessage [%d] len.%d\n",msg[0],len);
pnode->PushMessage("getnSPV",request);
pnode->prevtimes[ind] = timestamp;
@ -279,7 +279,7 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages
return;
if ( pto->prevtimes[NSPV_INFO>>1] > timestamp )
pto->prevtimes[NSPV_INFO>>1] = 0;
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 )
{
@ -370,6 +370,7 @@ UniValue NSPV_getinfo_json(struct NSPV_inforesp *ptr)
result.push_back(Pair("chaintip",ptr->blockhash.GetHex()));
result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization)));
result.push_back(Pair("header",NSPV_header_json(&ptr->H,ptr->hdrheight)));
result.push_back(Pair("protocolversion",(int64_t)ptr->version));
result.push_back(Pair("lastpeer",NSPV_lastpeer));
return(result);
}
@ -536,7 +537,7 @@ UniValue NSPV_login(char *wifstr)
result.push_back(Pair("address",NSPV_address));
result.push_back(Pair("pubkey",HexStr(pubkey)));
strcpy(NSPV_pubkeystr,HexStr(pubkey).c_str());
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
decode_hex(NOTARY_PUBKEY33,33,NSPV_pubkeystr);
result.push_back(Pair("wifprefix",(int64_t)data[0]));
result.push_back(Pair("compressed",(int64_t)(data[len-5] == 1)));
@ -586,8 +587,8 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount,int32
{
UniValue result(UniValue::VOBJ); uint8_t msg[512]; int32_t i,iter,slen,len = 0;
//fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str());
if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount )
return(NSPV_utxosresp_json(&NSPV_utxosresult));
//if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount && filter == NSPV_utxosresult.filter )
// return(NSPV_utxosresp_json(&NSPV_utxosresult));
if ( skipcount < 0 )
skipcount = 0;
NSPV_utxosresp_purge(&NSPV_utxosresult);

5
src/komodo_utils.h

@ -1879,6 +1879,7 @@ void komodo_args(char *argv0)
ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0);
ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0);
ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",0);
ASSETCHAINS_ADAPTIVEPOW = GetArg("-ac_adaptivepow",0);
//fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET);
if ( ASSETCHAINS_CBOPRET != 0 )
{
@ -2065,7 +2066,7 @@ void komodo_args(char *argv0)
fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n");
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 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0)
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 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0 || ASSETCHAINS_ADAPTIVEPOW != 0 )
{
fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size());
extraptr = extrabuf;
@ -2214,6 +2215,8 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen);
{
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_CBMATURITY),(void *)&ASSETCHAINS_CBMATURITY);
}
if ( ASSETCHAINS_ADAPTIVEPOW != 0 )
extraptr[extralen++] = ASSETCHAINS_ADAPTIVEPOW;
}
addn = GetArg("-seednode","");

72
src/main.cpp

@ -2227,7 +2227,7 @@ bool myAddtomempool(CTransaction &tx, CValidationState *pstate, bool fSkipExpiry
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock)
{
memset(&hashBlock,0,sizeof(hashBlock));
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
int64_t rewardsum = 0; int32_t i,retval,txheight,currentheight,height=0,vout = 0;
for (i=0; i<NSPV_U.U.numutxos; i++)
@ -2281,7 +2281,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo
bool NSPV_myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, int32_t &txheight, int32_t &currentheight)
{
memset(&hashBlock,0,sizeof(hashBlock));
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
int64_t rewardsum = 0; int32_t i,retval,height=0,vout = 0;
for (i=0; i<NSPV_U.U.numutxos; i++)
@ -3427,7 +3427,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
{
CDiskBlockPos blockPos;
const CChainParams& chainparams = Params();
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
return(true);
if ( KOMODO_STOPAT != 0 && pindex->GetHeight() > KOMODO_STOPAT )
return(false);
@ -4011,7 +4011,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
void FlushStateToDisk() {
CValidationState state;
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
FlushStateToDisk(state, FLUSH_STATE_ALWAYS);
}
@ -4162,7 +4162,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight(),true) != 0)))
{
#ifdef ENABLE_WALLET
if ( !GetBoolArg("-disablewallet", false) && KOMODO_NSPV == 0 )
if ( !GetBoolArg("-disablewallet", false) && KOMODO_NSPV <= 0 )
pwalletMain->EraseFromWallet(tx.GetHash());
#endif
}
@ -4267,7 +4267,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
// Get the current commitment tree
SproutMerkleTree oldSproutTree;
SaplingMerkleTree oldSaplingTree;
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
{
assert(pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), oldSproutTree));
assert(pcoinsTip->GetSaplingAnchorAt(pcoinsTip->GetBestAnchor(SAPLING), oldSaplingTree));
@ -4296,13 +4296,13 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
mapBlockSource.erase(pindexNew->GetBlockHash());
nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2;
LogPrint("bench", " - Connect total: %.2fms [%.2fs]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001);
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
assert(view.Flush());
}
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
LogPrint("bench", " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001);
// Write the chain state to disk, if necessary.
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
{
if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED))
return false;
@ -4318,7 +4318,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
// Update chainActive & related variables.
UpdateTip(pindexNew);
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
{
// Tell wallet about transactions that went from mempool
// to conflicted:
@ -4346,7 +4346,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
komodo_broadcast(pblock,8);
else if ( ASSETCHAINS_SYMBOL[0] != 0 )
komodo_broadcast(pblock,4);*/
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
{
if ( ASSETCHAINS_CBOPRET != 0 )
komodo_pricesupdate(pindexNew->GetHeight(),pblock);
@ -5043,7 +5043,15 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,
}
}
*futureblockp = 0;
if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60)
if ( ASSETCHAINS_ADAPTIVEPOW > 0 )
{
if (blockhdr.GetBlockTime() > GetAdjustedTime() + 4)
{
//LogPrintf("CheckBlockHeader block from future %d error",blockhdr.GetBlockTime() - GetAdjustedTime());
return false;
}
}
else if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60)
{
/*CBlockIndex *tipindex;
//fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime());
@ -5288,10 +5296,23 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
}
// Check timestamp against prev
if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast())
if ( ASSETCHAINS_ADAPTIVEPOW <= 0 || nHeight < 30 )
{
return state.Invalid(error("%s: block's timestamp is too early", __func__),
REJECT_INVALID, "time-too-old");
if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast() )
{
fprintf(stderr,"ht.%d too early %u vs %u\n",(int32_t)nHeight,(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->GetMedianTimePast());
return state.Invalid(error("%s: block's timestamp is too early", __func__),
REJECT_INVALID, "time-too-old");
}
}
else
{
if ( block.GetBlockTime() <= pindexPrev->nTime )
{
fprintf(stderr,"ht.%d too early2 %u vs %u\n",(int32_t)nHeight,(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->nTime);
return state.Invalid(error("%s: block's timestamp is too early2", __func__),
REJECT_INVALID, "time-too-old");
}
}
// Check that timestamp is not too far in the future
@ -6547,7 +6568,7 @@ bool InitBlockIndex() {
if (!ActivateBestChain(true, state, &block))
return error("LoadBlockIndex(): genesis block cannot be activated");
// Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
return FlushStateToDisk(state, FLUSH_STATE_ALWAYS);
else return(true);
} catch (const std::runtime_error& e) {
@ -7107,7 +7128,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
{
const CChainParams& chainparams = Params();
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
//if ( KOMODO_NSPV != 0 )
//if ( KOMODO_NSPV > 0 )
//if ( strCommand != "version" && strCommand != "verack" )
// fprintf(stderr, "recv: %s (%u bytes) peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)vRecv.size(), (int32_t)pfrom->GetId());
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
@ -7282,7 +7303,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
{
pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION));
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
if ( (pfrom->nServices & NODE_NSPV) == 0 )
{
@ -7482,14 +7503,17 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}
else if (strCommand == "getnSPV")
{
std::vector<uint8_t> payload;
vRecv >> payload;
komodo_nSPVreq(pfrom,payload);
if ( KOMODO_NSPV == 0 && KOMODO_INSYNC != 0 )
{
std::vector<uint8_t> payload;
vRecv >> payload;
komodo_nSPVreq(pfrom,payload);
}
return(true);
}
else if (strCommand == "nSPV")
{
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
std::vector<uint8_t> payload;
vRecv >> payload;
@ -7497,7 +7521,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}
return(true);
}
else if ( KOMODO_NSPV != 0 )
else if ( KOMODO_NSPV > 0 )
return(true);
else if (strCommand == "inv")
{
@ -8287,7 +8311,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
}
state.fShouldBan = false;
}
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
komodo_nSPV(pto);
return(true);
@ -8498,7 +8522,7 @@ extern "C" const char* getDataDir()
CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight)
{
CMutableTransaction mtx;
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
mtx.fOverwintered = true;
mtx.nExpiryHeight = 0;

38
src/miner.cpp

@ -123,10 +123,13 @@ public:
void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
{
pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
if ( ASSETCHAINS_ADAPTIVEPOW <= 0 )
pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
else pblock->nTime = std::max((int64_t)(pindexPrev->nTime+1), GetAdjustedTime());
// Updating time can change work required on testnet:
if (consensusParams.nPowAllowMinDifficultyBlocksAfterHeight != boost::none) {
if (ASSETCHAINS_ADAPTIVEPOW > 0 || consensusParams.nPowAllowMinDifficultyBlocksAfterHeight != boost::none)
{
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
}
}
@ -567,7 +570,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
nLastBlockTx = nBlockTx;
nLastBlockSize = nBlockSize;
blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
if ( ASSETCHAINS_ADAPTIVEPOW <= 0 )
blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
else blocktime = 1 + std::max((int64_t)(pindexPrev->nTime+1), GetAdjustedTime());
//pblock->nTime = blocktime + 1;
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
@ -596,8 +601,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
else
{
blocktime = GetAdjustedTime();
//if ( blocktime > pindexPrev->GetMedianTimePast()+60 )
// blocktime = pindexPrev->GetMedianTimePast() + 60;
siglen = komodo_staked(txStaked, pblock->nBits, &blocktime, &txtime, &utxotxid, &utxovout, &utxovalue, utxosig);
// if you skip this check it will create a block too far into the future and not pass ProcessBlock or AcceptBlock.
// This has been moved from the mining loop to save CPU, and to also make ac_staked work with the verus miner.
@ -642,7 +645,10 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
txNew.vout[0].nValue = GetBlockSubsidy(nHeight,consensusParams) + nFees;
//fprintf(stderr,"mine ht.%d with %.8f\n",nHeight,(double)txNew.vout[0].nValue/COIN);
txNew.nExpiryHeight = 0;
txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
if ( ASSETCHAINS_ADAPTIVEPOW <= 0 )
txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
else txNew.nLockTime = std::max((int64_t)(pindexPrev->nTime+1), GetAdjustedTime());
if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 )
txNew.vout[0].nValue += 5000;
@ -1447,7 +1453,9 @@ void static BitcoinMiner_noeq()
HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED);
}
//else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 )
// HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime);
while (true)
{
arith_uint256 arNonce = UintToArith256(pblock->nNonce);
@ -1480,7 +1488,9 @@ void static BitcoinMiner_noeq()
}
else if ( ASSETCHAINS_STAKED == 100 && Mining_height > 100 )
hashTarget = HASHTarget;
//else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 )
// hashTarget = HASHTarget_POW;
// for speed check NONCEMASK at a time
for (i = 0; i < count; i++)
{
@ -1816,6 +1826,8 @@ void static BitcoinMiner()
if ( ASSETCHAINS_STAKED < 100 )
LogPrintf("Block %d : PoS %d%% vs target %d%% \n",Mining_height,percPoS,(int32_t)ASSETCHAINS_STAKED);
}
//else if ( ASSETCHAINS_ADAPTIVEPOW > 0 )
// HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime);
gotinvalid = 0;
while (true)
{
@ -1843,6 +1855,8 @@ void static BitcoinMiner()
arith_uint256 hashTarget;
if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 )
hashTarget = HASHTarget_POW;
//else if ( ASSETCHAINS_ADAPTIVEPOW > 0 )
// hashTarget = HASHTarget_POW;
else hashTarget = HASHTarget;
std::function<bool(std::vector<unsigned char>)> validBlock =
#ifdef ENABLE_WALLET
@ -2032,6 +2046,14 @@ void static BitcoinMiner()
// Update nNonce and nTime
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
pblock->nBits = savebits;
if ( ASSETCHAINS_ADAPTIVEPOW > 0 )
{
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
HASHTarget.SetCompact(pblock->nBits);
hashTarget = HASHTarget;
savebits = pblock->nBits;
//hashTarget = HASHTarget_POW = komodo_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime);
}
/*if ( NOTARY_PUBKEY33[0] == 0 )
{
int32_t percPoS;

2
src/net.cpp

@ -1843,7 +1843,7 @@ bool StopNode()
for (int i=0; i<MAX_OUTBOUND_CONNECTIONS; i++)
semOutbound->post();
if (KOMODO_NSPV == 0 && fAddressesInitialized)
if (KOMODO_NSPV <= 0 && fAddressesInitialized)
{
DumpAddresses();
fAddressesInitialized = false;

140
src/pow.cpp

@ -42,6 +42,33 @@ uint32_t komodo_chainactive_timestamp();
unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params);
unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params);
arith_uint256 zawy_targetMA(arith_uint256 easy,arith_uint256 bnSum,int32_t num,int32_t numerator,int32_t divisor)
{
bnSum /= arith_uint256(ASSETCHAINS_BLOCKTIME * num * num * divisor);
bnSum *= arith_uint256(numerator);
if ( bnSum > easy )
bnSum = easy;
return(bnSum);
}
arith_uint256 zawy_exponential(arith_uint256 bnTarget,int32_t mult)
{
int32_t i,n,modval; int64_t A = 1, B = 3600 * 100;
if ( (n= (mult/ASSETCHAINS_BLOCKTIME)) > 0 )
{
for (i=1; i<=n; i++)
A *= 3;
}
if ( (modval= (mult % ASSETCHAINS_BLOCKTIME)) != 0 )
{
B += (3600 * 110 * modval) / ASSETCHAINS_BLOCKTIME;
B += (3600 * 60 * modval * modval) / (ASSETCHAINS_BLOCKTIME * ASSETCHAINS_BLOCKTIME);
}
bnTarget /= arith_uint256(100 * 3600);
bnTarget *= arith_uint256(A * B);
return(bnTarget);
}
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{
if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_STAKED == 0)
@ -73,21 +100,106 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
// Find the first block in the averaging interval
const CBlockIndex* pindexFirst = pindexLast;
arith_uint256 bnTot {0};
for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) {
arith_uint256 bnTmp;
arith_uint256 bnTmp,bnTarget,bnPrev {0},bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0};
uint32_t nbits,blocktime,block4diff=0,block7diff=0,block12diff=0; int32_t diff,mult = 0;
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 )
{
mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME;
bnPrev.SetCompact(pindexFirst->nBits);
//fprintf(stderr,"ht.%d mult.%d = (%u - %u - 7x)\n",pindexLast->GetHeight(),(int32_t)mult,pblock->nTime, pindexFirst->nTime);
}
for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++)
{
bnTmp.SetCompact(pindexFirst->nBits);
bnTot += bnTmp;
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pblock != 0 )
{
blocktime = pindexFirst->nTime;
diff = (pblock->nTime - blocktime);
//fprintf(stderr,"%d ",diff);
if ( i < 12 )
{
if ( i == 3 )
{
block4diff = diff;
bnSum4 = bnTot;
}
else if ( i == 6 )
{
block7diff = diff;
bnSum7 = bnTot;
}
else if ( i == 11 )
{
block12diff = diff;
bnSum12 = bnTot;
}
diff -= (8+i)*ASSETCHAINS_BLOCKTIME;
if ( diff > mult )
{
//fprintf(stderr,"i.%d diff.%d (%u - %u - %dx)\n",i,(int32_t)diff,pblock->nTime,pindexFirst->nTime,(8+i));
mult = diff;
}
}
}
pindexFirst = pindexFirst->pprev;
}
//fprintf(stderr,"diffs %d\n",(int32_t) pindexLast->GetHeight());
// Check we have enough blocks
if (pindexFirst == NULL)
return nProofOfWorkLimit;
arith_uint256 bnAvg {bnTot / params.nPowAveragingWindow};
return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
bool fNegative,fOverflow; int32_t flag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow};
nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && block12diff != 0 && block7diff != 0 && block4diff != 0 )
{
origtarget = bnTarget = arith_uint256().SetCompact(nbits);
easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 5,1);
bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 3,1);
bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 2,1);
if ( bnSum4 < bnSum7 )
bnTmp = bnSum4;
else bnTmp = bnSum7;
if ( bnSum12 < bnTmp )
bnTmp = bnSum12;
if ( bnTmp < bnTarget )
{
fprintf(stderr,"ht.%d block12diff %d vs %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11);
bnTarget = (bnTmp + bnPrev) / arith_uint256(2);
flag = 1;
}
else if ( flag == 0 && mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t???
{
flag = 1;
bnTarget = zawy_exponential(bnTarget,mult);
if ( bnTarget < origtarget || bnTarget > easy )
{
bnTarget = easy;
fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight());
return(KOMODO_MINDIFF_NBITS);
} else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight());
}
if ( flag == 0 )
{
bnSum4 = zawy_targetMA(easy,bnSum4,4,block4diff * 3,10);
bnSum7 = zawy_targetMA(easy,bnSum7,7,block7diff * 5,10);
bnSum12 = zawy_targetMA(easy,bnSum12,12,block12diff * 6,10);
if ( bnSum4 > bnSum7 )
bnTmp = bnSum4;
else bnTmp = bnSum7;
if ( bnSum12 > bnTmp )
bnTmp = bnSum12;
if ( bnTmp > bnTarget )
{
fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13);
bnTarget = (bnTmp + bnPrev) / arith_uint256(2);
flag = 1;
}
}
nbits = bnTarget.GetCompact();
}
return(nbits);
}
unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
@ -101,11 +213,13 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
nActualTimespan = params.AveragingWindowTimespan() + (nActualTimespan - params.AveragingWindowTimespan())/4;
LogPrint("pow", " nActualTimespan = %d before bounds\n", nActualTimespan);
if (nActualTimespan < params.MinActualTimespan())
nActualTimespan = params.MinActualTimespan();
if (nActualTimespan > params.MaxActualTimespan())
nActualTimespan = params.MaxActualTimespan();
if ( ASSETCHAINS_ADAPTIVEPOW <= 0 )
{
if (nActualTimespan < params.MinActualTimespan())
nActualTimespan = params.MinActualTimespan();
if (nActualTimespan > params.MaxActualTimespan())
nActualTimespan = params.MaxActualTimespan();
}
// Retarget
arith_uint256 bnLimit;
if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH)
@ -453,6 +567,8 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t
arith_uint256 bnMaxPoSdiff;
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
}
//else if ( ASSETCHAINS_ADAPTIVEPOW > 0 && ASSETCHAINS_STAKED == 0 )
// bnTarget = komodo_adaptivepow_target(height,bnTarget,blkHeader.nTime);
// Check proof of work matches claimed amount
if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() )
{

4
src/rpc/blockchain.cpp

@ -396,7 +396,7 @@ bool NSPV_inmempool(uint256 txid);
bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int32_t vout)
{
int32_t vini = 0;
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
return(NSPV_spentinmempool(spenttxid,spentvini,txid,vout));
BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx)
{
@ -420,7 +420,7 @@ bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,
bool mytxid_inmempool(uint256 txid)
{
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
}

6
src/rpc/mining.cpp

@ -837,7 +837,11 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
result.push_back(Pair("PoSperc", (int64_t)PoSperc));
result.push_back(Pair("ac_staked", (int64_t)ASSETCHAINS_STAKED));
result.push_back(Pair("origtarget", hashTarget.GetHex()));
} else result.push_back(Pair("target", hashTarget.GetHex()));
}
/*else if ( ASSETCHAINS_ADAPTIVEPOW > 0 )
result.push_back(Pair("target",komodo_adaptivepow_target((int32_t)(pindexPrev->GetHeight()+1),hashTarget,pblock->nTime).GetHex()));
else*/
result.push_back(Pair("target", hashTarget.GetHex()));
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
result.push_back(Pair("mutable", aMutable));
result.push_back(Pair("noncerange", "00000000ffffffff"));

2
src/rpc/misc.cpp

@ -243,7 +243,7 @@ UniValue getinfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("prevMoMheight", prevMoMheight));
obj.push_back(Pair("notarizedhash", notarized_hash.ToString()));
obj.push_back(Pair("notarizedtxid", notarized_desttxid.ToString()));
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
{
txid_height = notarizedtxid_height(ASSETCHAINS_SYMBOL[0] != 0 ? (char *)"KMD" : (char *)"BTC",(char *)notarized_desttxid.ToString().c_str(),&kmdnotarized_height);
if ( txid_height > 0 )

4
src/rpc/rawtransaction.cpp

@ -374,7 +374,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
const CTxOut& txout = tx.vout[i];
UniValue out(UniValue::VOBJ);
out.push_back(Pair("value", ValueFromAmount(txout.nValue)));
if ( KOMODO_NSPV == 0 && ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 )
if ( KOMODO_NSPV <= 0 && ASSETCHAINS_SYMBOL[0] == 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 )
{
int64_t interest; int32_t txheight; uint32_t locktime;
interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->GetHeight());
@ -1366,7 +1366,7 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp)
bool fOverrideFees = false;
if (params.size() > 1)
fOverrideFees = params[1].get_bool();
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
{
CCoinsViewCache &view = *pcoinsTip;
const CCoins* existingCoins = view.AccessCoins(hashTx);

8
src/script/sign.cpp

@ -53,7 +53,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
}
}
SIG_TXHASH = hash;
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
key = DecodeSecret(NSPV_wifstr);
else if (pprivKey)
key = *pprivKey;
@ -74,7 +74,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
return false;
}
vchSig = CCSigVec(cc);
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
memset((uint8_t *)key.begin(),0,32);
return true;
}
@ -100,7 +100,7 @@ bool TransactionSignatureCreator::CreateSig(std::vector<unsigned char>& vchSig,
}
vchSig.push_back((unsigned char)nHashType);
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
memset((uint8_t *)key.begin(),0,32);
return true;
}
@ -381,7 +381,7 @@ static bool SignStep(const BaseSignatureCreator& creator, const CScript& scriptP
}
else
{
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
{
CPubKey vch;
creator.KeyStore().GetPubKey(keyID, vch);

2
src/timedata.cpp

@ -94,7 +94,7 @@ void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
int64_t nMedian = vTimeOffsets.median();
std::vector<int64_t> vSorted = vTimeOffsets.sorted();
// Only let other nodes change our time by so much
if (abs64(nMedian) < 70 * 60)
if (abs64(nMedian) < 30) // thanks to zawy for pointing this out!! zcash issues 4021 //70 * 60)
{
nTimeOffset = nMedian;
}

20
src/tui/lib/tuilib.py

@ -21,6 +21,24 @@ if operating_system != 'Win64' and operating_system != 'Windows':
import readline
class CustomProxy(Proxy):
def __init__(self,
service_url=None,
service_port=None,
conf_file=None,
timeout=3000):
config = dict()
if conf_file:
config = slickrpc.ConfigObj(conf_file)
if service_url:
config.update(self.url_to_conf(service_url))
if service_port:
config.update(rpcport=service_port)
elif not config.get('rpcport'):
config['rpcport'] = 7771
self.conn = self.prepare_connection(config, timeout=timeout)
def colorize(string, color):
colors = {
@ -97,7 +115,7 @@ def def_credentials(chain):
print("check "+coin_config_file)
exit(1)
return(Proxy("http://%s:%s@127.0.0.1:%d"%(rpcuser, rpcpassword, int(rpcport))))
return(CustomProxy("http://%s:%s@127.0.0.1:%d"%(rpcuser, rpcpassword, int(rpcport))))
def getinfo_tui(rpc_connection):

24
src/wallet/rpcdump.cpp

@ -993,7 +993,7 @@ UniValue nspv_getinfo(const UniValue& params, bool fHelp)
int32_t reqht = 0;
if ( fHelp || params.size() > 1 )
throw runtime_error("nspv_getinfo [hdrheight]\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
if ( params.size() == 1 )
reqht = atoi((char *)params[0].get_str().c_str());
@ -1004,7 +1004,7 @@ UniValue nspv_logout(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() != 0 )
throw runtime_error("nspv_logout\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
return(NSPV_logout());
}
@ -1013,7 +1013,7 @@ UniValue nspv_login(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() != 1 )
throw runtime_error("nspv_login wif\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
return(NSPV_login((char *)params[0].get_str().c_str()));
}
@ -1023,7 +1023,7 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp)
int32_t skipcount = 0,CCflag = 0;
if ( fHelp || params.size() > 3 )
throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
if ( params.size() == 0 )
{
@ -1048,7 +1048,7 @@ UniValue nspv_mempool(const UniValue& params, bool fHelp)
memset(&txid,0,sizeof(txid));
if ( fHelp || params.size() > 5 )
throw runtime_error("nspv_mempool func(0 all, 1 address recv, 2 txid/vout spent, 3 txid inmempool) address isCC [txid vout]]]\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
funcid = atoi((char *)params[0].get_str().c_str());
coinaddr = (char *)params[1].get_str().c_str();
@ -1068,7 +1068,7 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp)
int32_t skipcount = 0,CCflag = 0;
if ( fHelp || params.size() > 3 )
throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
if ( params.size() == 0 )
{
@ -1093,7 +1093,7 @@ UniValue nspv_spentinfo(const UniValue& params, bool fHelp)
uint256 txid; int32_t vout;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_spentinfo txid vout\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
txid = Parseuint256((char *)params[0].get_str().c_str());
vout = atoi((char *)params[1].get_str().c_str());
@ -1105,7 +1105,7 @@ UniValue nspv_notarizations(const UniValue& params, bool fHelp)
int32_t height;
if ( fHelp || params.size() != 1 )
throw runtime_error("nspv_notarizations height\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
height = atoi((char *)params[0].get_str().c_str());
return(NSPV_notarizations(height));
@ -1116,7 +1116,7 @@ UniValue nspv_hdrsproof(const UniValue& params, bool fHelp)
int32_t prevheight,nextheight;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_hdrsproof prevheight nextheight\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
prevheight = atoi((char *)params[0].get_str().c_str());
nextheight = atoi((char *)params[1].get_str().c_str());
@ -1128,7 +1128,7 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp)
uint256 txid; int32_t height;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_txproof txid height\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
txid = Parseuint256((char *)params[0].get_str().c_str());
height = atoi((char *)params[1].get_str().c_str());
@ -1140,7 +1140,7 @@ UniValue nspv_spend(const UniValue& params, bool fHelp)
uint64_t satoshis;
if ( fHelp || params.size() != 2 )
throw runtime_error("nspv_spend address amount\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
if ( NSPV_address.size() == 0 )
throw runtime_error("to nspv_send you need an active nspv_login\n");
@ -1155,7 +1155,7 @@ UniValue nspv_broadcast(const UniValue& params, bool fHelp)
{
if ( fHelp || params.size() != 1 )
throw runtime_error("nspv_broadcast hex\n");
if ( KOMODO_NSPV == 0 )
if ( KOMODO_NSPV <= 0 )
throw runtime_error("-nSPV=1 must be set to use nspv\n");
return(NSPV_broadcast((char *)params[0].get_str().c_str()));
}

8
src/wallet/rpcwallet.cpp

@ -162,7 +162,7 @@ void OS_randombytes(unsigned char *x,long xlen);
UniValue getnewaddress(const UniValue& params, bool fHelp)
{
if ( KOMODO_NSPV == 0 && !EnsureWalletIsAvailable(fHelp) )
if ( KOMODO_NSPV <= 0 && !EnsureWalletIsAvailable(fHelp) )
return NullUniValue;
if (fHelp || params.size() > 1)
@ -178,7 +178,7 @@ UniValue getnewaddress(const UniValue& params, bool fHelp)
+ HelpExampleRpc("getnewaddress", "")
);
if ( KOMODO_NSPV != 0 )
if ( KOMODO_NSPV > 0 )
{
UniValue result(UniValue::VOBJ); uint8_t priv32[32];
#ifndef __WIN32
@ -2974,7 +2974,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
uint64_t komodo_interestsum()
{
#ifdef ENABLE_WALLET
if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 && KOMODO_NSPV == 0 )
if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 && KOMODO_NSPV <= 0 )
{
uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime;
vector<COutput> vecOutputs;
@ -7002,7 +7002,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp)
if ( fHelp || params.size() > 1 )
throw runtime_error("faucetfund amount\n");
funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999;
if ( (0) && KOMODO_NSPV != 0 )
if ( (0) && KOMODO_NSPV > 0 )
{
char coinaddr[64]; struct CCcontract_info *cp,C; CTxOut v;
cp = CCinit(&C,EVAL_FAUCET);

Loading…
Cancel
Save