interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime);
#ifdef KOMODO_ENABLE_INTEREST
if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 )
+ {
+ printf("nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime);
nResult += interest;
+ }
#endif
(*interestp) += interest;
}
#ifndef BITCOIN_COINS_H
#define BITCOIN_COINS_H
+#define KOMODO_ENABLE_INTEREST //enabling this is a hardfork, activate with new RR method
+
#include "compressor.h"
#include "memusage.h"
#include "serialize.h"
// Todo:
// 1. error check fiat redeem amounts
-// 2. net balance limiter, activate dPoW for all fiats
-// 3. REVS and non-fiat chains
+// 2. net balance limiter
+// 3. new RR algo
// 4. verify: interest payment, ratification, reorgs
// 5. automate notarization fee payouts
// 6. automated distribution of test REVS snapshot
#define GENESIS_NBITS 0x1f00ffff
#define KOMODO_MINRATIFY 7
+int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks
+
#include "komodo_globals.h"
#include "komodo_utils.h"
static int32_t hwmheight;
uint64_t signedmask,voutmask;
uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash;
- int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
+ int32_t i,j,k,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count;
komodo_init(pindex->nHeight);
if ( pindex->nHeight > hwmheight )
hwmheight = pindex->nHeight;
#endif
// signedmask is needed here!
notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue);
+ if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 )
+ {
+ if ( height < sizeof(Minerids)/sizeof(*Minerids) )
+ Minerids[height] = nid;
+ }
if ( 0 && i > 0 )
{
for (k=0; k<len; k++)
{
//int32_t i; uint256 hash;
komodo_init(pindex->nHeight);
+ Minerids[pindex->nHeight] = -2;
//hash = block.GetHash();
//for (i=0; i<32; i++)
// printf("%02x",((uint8_t *)&hash)[i]);
}
}
+int8_t komodo_minerid(int32_t height)
+{
+ int32_t notaryid; CBlockIndex *pindex; uint8_t pubkey33[33];
+ if ( height <= chainActive.Tip()->nHeight )
+ {
+ if ( (pindex= chainActive[height]) != 0 )
+ {
+ komodo_index2pubkey33(pubkey33,pindex,height);
+ komodo_chosennotary(¬aryid,height,pubkey33);
+ return(notaryid);
+ }
+ }
+ return(-2);
+}
+
+int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33])
+{
+ int32_t notaryid;
+ komodo_chosennotary(¬aryid,height,pubkey33);
+ if ( height >= 34000 && notaryid >= 0 )
+ {
+ for (i=1; i<64; i++)
+ {
+ if ( Minerids[height-i] == -2 )
+ {
+ Minerids[height-i] = komodo_minerid(height-i);
+ if ( Minerids[height - i] == -2 )
+ fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,CURRENT_HEIGHT);
+ }
+ if ( Minerids[height-i] == notaryid )
+ return(-1);
+ }
+ return(1);
+ }
+ return(0);
+}
+
int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash)
{
int32_t notarized_height; uint256 notarized_hash,notarized_desttxid; CBlockIndex *notary;
{
pthread_mutex_init(&komodo_mutex,NULL);
decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str());
- n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis));
- for (k=0; k<n; k++)
+ if ( height >= 0 )
{
- if ( Notaries_genesis[k][0] == 0 || Notaries_genesis[k][1] == 0 || Notaries_genesis[k][0][0] == 0 || Notaries_genesis[k][1][0] == 0 )
- break;
- decode_hex(pubkeys[k],33,(char *)Notaries_genesis[k][1]);
+ n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis));
+ for (k=0; k<n; k++)
+ {
+ if ( Notaries_genesis[k][0] == 0 || Notaries_genesis[k][1] == 0 || Notaries_genesis[k][0][0] == 0 || Notaries_genesis[k][1][0] == 0 )
+ break;
+ decode_hex(pubkeys[k],33,(char *)Notaries_genesis[k][1]);
+ }
+ komodo_notarysinit(0,pubkeys,k);
}
- komodo_notarysinit(0,pubkeys,k);
memset(&zero,0,sizeof(zero));
+ for (i=0; i<sizeof(Minerids); i++)
+ Minerids[i] = -2;
}
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0,0);
}
}
if ( i == n )
{
- komodo_init(0);
+ komodo_init(-1);
komodo_notarysinit(0,pubkeys,n);
printf("initialize pubkeys[%d]\n",n);
} else fprintf(stderr,"komodo_assetchain_pubkeys i.%d vs n.%d\n",i,n);
printf("ports\n");
}
-char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7778\" --data \"{\\\"unitval\\\":\\\"20\\\",\\\"zcash\\\":1,\\\"RELAY\\\":1,\\\"VALIDATE\\\":1,\\\"prefetchlag\\\":-1,\\\"poll\\\":100,\\\"active\\\":1,\\\"agent\\\":\\\"iguana\\\",\\\"method\\\":\\\"addcoin\\\",\\\"startpend\\\":4,\\\"endpend\\\":4,\\\"services\\\":129,\\\"maxpeers\\\":8,\\\"newcoin\\\":\\\"%s\\\",\\\"name\\\":\\\"%s\\\",\\\"hasheaders\\\":1,\\\"useaddmultisig\\\":0,\\\"netmagic\\\":\\\"%s\\\",\\\"p2p\\\":%u,\\\"rpc\\\":%u,\\\"pubval\\\":60,\\\"p2shval\\\":85,\\\"wifval\\\":188,\\\"txfee_satoshis\\\":\\\"10000\\\",\\\"isPoS\\\":0,\\\"minoutput\\\":10000,\\\"minconfirms\\\":2,\\\"genesishash\\\":\\\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\\\",\\\"protover\\\":170002,\\\"genesisblock\\\":\\\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\\\",\\\"debug\\\":0,\\\"seedipaddr\\\":\\\"%s\\\"}\"";
+char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7778\" --data \"{\\\"conf\\\":\\\"%s.conf\\\",\\\"path\\\":\\\"${HOME#\"/\"}/.komodo/%s\\\",\\\"unitval\\\":\\\"20\\\",\\\"zcash\\\":1,\\\"RELAY\\\":1,\\\"VALIDATE\\\":1,\\\"prefetchlag\\\":-1,\\\"poll\\\":100,\\\"active\\\":1,\\\"agent\\\":\\\"iguana\\\",\\\"method\\\":\\\"addcoin\\\",\\\"startpend\\\":4,\\\"endpend\\\":4,\\\"services\\\":129,\\\"maxpeers\\\":8,\\\"newcoin\\\":\\\"%s\\\",\\\"name\\\":\\\"%s\\\",\\\"hasheaders\\\":1,\\\"useaddmultisig\\\":0,\\\"netmagic\\\":\\\"%s\\\",\\\"p2p\\\":%u,\\\"rpc\\\":%u,\\\"pubval\\\":60,\\\"p2shval\\\":85,\\\"wifval\\\":188,\\\"txfee_satoshis\\\":\\\"10000\\\",\\\"isPoS\\\":0,\\\"minoutput\\\":10000,\\\"minconfirms\\\":2,\\\"genesishash\\\":\\\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\\\",\\\"protover\\\":170002,\\\"genesisblock\\\":\\\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\\\",\\\"debug\\\":0,\\\"seedipaddr\\\":\\\"%s\\\"}\"";
void komodo_args()
sprintf(fname,"gen%s",ASSETCHAINS_SYMBOL);
if ( (fp= fopen(fname,"wb")) != 0 )
{
- fprintf(fp,iguanafmtstr,name.c_str(),name.c_str(),magicstr,ASSETCHAINS_PORT,ASSETCHAINS_PORT+1,"78.47.196.146");
+ fprintf(fp,iguanafmtstr,name.c_str(),name.c_str(),name.c_str(),name.c_str(),magicstr,ASSETCHAINS_PORT,ASSETCHAINS_PORT+1,"78.47.196.146");
fclose(fp);
//printf("created (%s)\n",fname);
} else printf("error creating (%s)\n",fname);
// Komodo globals
#define KOMODO_TESTNET_EXPIRATION 100000
-#define KOMODO_ENABLE_INTEREST //enabling this is a hardfork
#define KOMODO_PAX
#define KOMODO_ZCASH
#include "komodo.h"
view.GetBestBlock();
nValueIn = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime);
-
+ if ( interest != 0 )
+ fprintf(stderr,"add interest %.8f\n",(double)interest/COIN);
// we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool
view.SetBackend(dummy);
}
//
// Internal miner
//
-#define ROUNDROBIN_DELAY 44
+#define ROUNDROBIN_DELAY 30
extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE;
extern std::string NOTARY_PUBKEY;
extern uint8_t NOTARY_PUBKEY33[33];
uint32_t Mining_start,Mining_height;
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33);
+int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]);
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
{
//
// Search
//
- int32_t notaryid; uint32_t savebits; int64_t nStart = GetTime();
+ uint32_t savebits; int64_t nStart = GetTime();
savebits = pblock->nBits;
arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
- if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_chosennotary(¬aryid,pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 )
+ if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_is_special(pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 )
{
hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS);
Mining_start = (uint32_t)time(NULL);
}
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33);
+int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]);
extern int32_t KOMODO_CHOSEN_ONE,CURRENT_HEIGHT;
+extern int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
{
if ( pubkey33[i] != 0 )
nonz++;
- //fprintf(stderr,"%02x",pubkey33[i]);
}
- //fprintf(stderr," height.%d special.%d nonz.%d\n",height,special,nonz);
if ( nonz == 0 )
return(true); // will come back via different path with pubkey set
- else if ( 0 )
+ if ( notaryid >= 0 )
{
- for (i=0; i<33; i++)
- fprintf(stderr,"%02x",pubkey33[i]);
- fprintf(stderr," special.%d notaryid.%d ht.%d mod.%d\n",special,notaryid,height,(height % 35));
- }
- if ( special > 0 ) // special notary id == (height % numnotaries)
- {
- if (UintToArith256(hash) <= bnTarget) // accept normal diff
- return true;
- bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
- flag = 1;
+ if ( komodo_is_special(height,pubkey33) > 0 )
+ {
+ bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
+ flag = 1;
+ }
} //else bnTarget /= 8;
}
- /*else if ( height == 0 && KOMODO_CHOSEN_ONE != 0 )
- {
- extern uint8_t NOTARY_PUBKEY33[33];
- bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
- memcpy(pubkey33,NOTARY_PUBKEY33,33);
- special = 1;
- notaryid = -1;
- printf("KOMODO_CHOSEN_ONE -> MINDIFF\n");
- }*/
- // Check range
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
return error("CheckProofOfWork(): nBits below minimum work");
// Check proof of work matches claimed amount
- if (UintToArith256(hash) > bnTarget)
+ if ( UintToArith256(hash) > bnTarget )
{
for (i=0; i<33; i++)
printf("%02x",pubkey33[i]);
#include "utilmoneystr.h"
#include "zcash/Note.hpp"
#include "crypter.h"
-
+#include "coins.h"
#include <assert.h>
#include <boost/algorithm/string/replace.hpp>
interest = komodo_interest(chainActive.Tip()->nHeight,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime);
#ifdef KOMODO_ENABLE_INTEREST
if ( ASSETCHAINS_SYMBOL[0] == 0 && txheight >= 60000 )
+ {
+ printf("nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime);
nValueRet += interest;
-#endif
+ }
fprintf(stderr,"interest %llu from %llu lock.%u tip.%u\n",(long long)interest,(long long)out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime);
+#endif
setCoinsRet.insert(make_pair(out.tx, out.i));
}
return (nValueRet >= nTargetValue);