Merge branch 'libscottFIX' into fixgettransactioncrash
This commit is contained in:
15
README.md
15
README.md
@@ -9,15 +9,16 @@ This is the official Komodo sourcecode repository based on https://github.com/jl
|
||||
|
||||
## Development Resources
|
||||
|
||||
- Komodo Website: [https://komodoplatform.com/](https://komodoplatform.com/)
|
||||
- Komodo Blockexplorer: [https://kmdexplorer.io//](https://https://kmdexplorer.io/)
|
||||
- Forum: [https://forum.komodoplatform.com/](https://forum.komodoplatform.com/)
|
||||
- Komodo Website: [https://komodoplatform.com](https://komodoplatform.com/)
|
||||
- Komodo Blockexplorer: [https://kmdexplorer.io](https://kmdexplorer.io/)
|
||||
- Komodo Discord: [https://komodoplatform.com/discord](https://komodoplatform.com/discord)
|
||||
- Forum: [https://forum.komodoplatform.com](https://forum.komodoplatform.com/)
|
||||
- Mail: [info@komodoplatform.com](mailto:info@komodoplatform.com)
|
||||
- Support: [https://support.komodoplatform.com/support/home](https://support.komodoplatform.com/support/home)
|
||||
- Knowledgebase & How-to: [https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages)
|
||||
- API references: [http://docs.komodoplatform.com/](http://docs.komodoplatform.com/)
|
||||
- Blog: [http://blog.komodoplatform.com/](http://blog.komodoplatform.com/)
|
||||
- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/03/2018-03-12-Komodo-White-Paper-Full.pdf)
|
||||
- Knowledgebase & How-to: [https://support.komodoplatform.com/en/support/solutions](https://support.komodoplatform.com/en/support/solutions)
|
||||
- API references & Dev Documentation: [https://docs.komodoplatform.com](https://docs.komodoplatform.com/)
|
||||
- Blog: [https://blog.komodoplatform.com](https://blog.komodoplatform.com/)
|
||||
- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/whitepaper)
|
||||
- Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0)
|
||||
|
||||
## List of Komodo Platform Technologies
|
||||
|
||||
12
resolve.sh
Executable file
12
resolve.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
for f in $(git diff --name-only --diff-filter=U | cat); do
|
||||
echo "Resolve conflict in $f ..."
|
||||
git checkout --theirs $f
|
||||
done
|
||||
|
||||
for f in $(git diff --name-only --diff-filter=U | cat); do
|
||||
echo "Adding file $f ..."
|
||||
git add $f
|
||||
done
|
||||
|
||||
@@ -179,6 +179,7 @@ BITCOIN_CORE_H = \
|
||||
mruset.h \
|
||||
net.h \
|
||||
netbase.h \
|
||||
notaries_staked.h \
|
||||
noui.h \
|
||||
paymentdisclosure.h \
|
||||
paymentdisclosuredb.h \
|
||||
@@ -280,6 +281,7 @@ libbitcoin_server_a_SOURCES = \
|
||||
chain.cpp \
|
||||
checkpoints.cpp \
|
||||
crosschain.cpp \
|
||||
crosschain_authority.cpp \
|
||||
deprecation.cpp \
|
||||
httprpc.cpp \
|
||||
httpserver.cpp \
|
||||
@@ -290,6 +292,7 @@ libbitcoin_server_a_SOURCES = \
|
||||
metrics.cpp \
|
||||
miner.cpp \
|
||||
net.cpp \
|
||||
notaries_staked.cpp \
|
||||
noui.cpp \
|
||||
notarisationdb.cpp \
|
||||
paymentdisclosure.cpp \
|
||||
|
||||
@@ -10,7 +10,6 @@ komodo_test_SOURCES = \
|
||||
test-komodo/test_coinimport.cpp \
|
||||
test-komodo/test_eval_bet.cpp \
|
||||
test-komodo/test_eval_notarisation.cpp \
|
||||
test-komodo/test_crosschain.cpp \
|
||||
test-komodo/test_parse_notarisation.cpp
|
||||
|
||||
komodo_test_CPPFLAGS = $(komodod_CPPFLAGS)
|
||||
|
||||
2
src/ac/dion
Executable file
2
src/ac/dion
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=DION $1 $2 $3 $4 $5 $6
|
||||
2
src/ac/kmdice
Executable file
2
src/ac/kmdice
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=KMDICE $1 $2 $3 $4 $5 $6
|
||||
2
src/ac/mgnx
Executable file
2
src/ac/mgnx
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=MGNX $1 $2 $3 $4 $5 $6
|
||||
2
src/ac/pgt
Executable file
2
src/ac/pgt
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=PGT $1 $2 $3 $4 $5 $6
|
||||
2
src/ac/pirate
Executable file
2
src/ac/pirate
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=PIRATE $1 $2 $3 $4 $5 $6
|
||||
@@ -1,149 +1,118 @@
|
||||
[
|
||||
{
|
||||
"ac_name": "REVS",
|
||||
"ac_supply": "1300000"
|
||||
"ac_name": "STAKEDB1",
|
||||
"ac_supply": "100000",
|
||||
"ac_reward" : "1000000000",
|
||||
"ac_cc": "667",
|
||||
"addnode": [
|
||||
"195.201.137.5",
|
||||
"195.201.20.230"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "SUPERNET",
|
||||
"ac_supply": "816061"
|
||||
"ac_name": "STAKEDW1",
|
||||
"ac_supply": "100000",
|
||||
"ac_reward" : "1000000000",
|
||||
"ac_cc": "667",
|
||||
"addnode": [
|
||||
"195.201.137.5",
|
||||
"195.201.20.230"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "DEX",
|
||||
"ac_supply": "999999"
|
||||
"ac_name": "STAKEDPERC",
|
||||
"ac_supply": "1000000",
|
||||
"ac_reward" : "1000000000",
|
||||
"ac_cc": "667",
|
||||
"ac_perc": "10000000",
|
||||
"ac_pubkey": "03bd221868abc063b54a3fceafb9898b1931ed767298a17ac0c9923500a7c60e4b",
|
||||
"addnode": [
|
||||
"195.201.137.5",
|
||||
"195.201.20.230"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "PANGEA",
|
||||
"ac_supply": "999999"
|
||||
"ac_name": "STAKEDS1",
|
||||
"ac_supply": "1000000",
|
||||
"ac_reward" : "1000000000",
|
||||
"ac_cc": "667",
|
||||
"ac_staked": "10",
|
||||
"addnode": [
|
||||
"195.201.137.5",
|
||||
"195.201.20.230"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "JUMBLR",
|
||||
"ac_supply": "999999"
|
||||
"ac_name": "STAKEDS9",
|
||||
"ac_supply": "1000000",
|
||||
"ac_reward" : "1000000000",
|
||||
"ac_cc": "667",
|
||||
"ac_staked": "90",
|
||||
"addnode": [
|
||||
"195.201.137.5",
|
||||
"195.201.20.230"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "STAKEDED",
|
||||
"ac_supply": "1072452",
|
||||
"ac_reward" : "1000000000",
|
||||
"ac_cc": "667",
|
||||
"addnode": [
|
||||
"195.201.137.5",
|
||||
"195.201.20.230"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "STAKEDPRIV",
|
||||
"ac_supply": "1000000",
|
||||
"ac_reward" : "10000000000",
|
||||
"ac_private": "1",
|
||||
"addnode": [
|
||||
"195.201.137.5",
|
||||
"195.201.20.230"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "BET",
|
||||
"ac_supply": "999999"
|
||||
"ac_name": "STAKEDCCP",
|
||||
"ac_supply": "1000000",
|
||||
"ac_reward" : "10000000000",
|
||||
"ac_private": "1",
|
||||
"ac_cc": "667",
|
||||
"addnode": [
|
||||
"195.201.137.5",
|
||||
"195.201.20.230"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "CRYPTO",
|
||||
"ac_supply": "999999"
|
||||
},
|
||||
{
|
||||
"ac_name": "HODL",
|
||||
"ac_supply": "9999999"
|
||||
},
|
||||
{
|
||||
"ac_name": "MSHARK",
|
||||
"ac_supply": "1400000"
|
||||
},
|
||||
{
|
||||
"ac_name": "BOTS",
|
||||
"ac_supply": "999999"
|
||||
},
|
||||
{
|
||||
"ac_name": "MGW",
|
||||
"ac_supply": "999999"
|
||||
},
|
||||
{
|
||||
"ac_name": "COQUI",
|
||||
"ac_supply": "72000000",
|
||||
"ac_ccactivate": "200000"
|
||||
},
|
||||
{
|
||||
"ac_name": "WLC",
|
||||
"ac_supply": "210000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "KV",
|
||||
"ac_supply": "1000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "CEAL",
|
||||
"ac_supply": "366666666"
|
||||
},
|
||||
{
|
||||
"ac_name": "MESH",
|
||||
"ac_supply": "1000007"
|
||||
},
|
||||
{
|
||||
"ac_name": "MNZ",
|
||||
"ac_supply": "257142858"
|
||||
},
|
||||
{
|
||||
"ac_name": "AXO",
|
||||
"ac_supply": "200000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "ETOMIC",
|
||||
"ac_supply": "100000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "BTCH",
|
||||
"ac_supply": "20998641"
|
||||
},
|
||||
{
|
||||
"ac_name": "PIZZA",
|
||||
"ac_supply": "100000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "BEER",
|
||||
"ac_supply": "100000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "NINJA",
|
||||
"ac_supply": "100000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "OOT",
|
||||
"ac_supply": "216000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "BNTN",
|
||||
"ac_supply": "500000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "CHAIN",
|
||||
"ac_supply": "999999"
|
||||
},
|
||||
{
|
||||
"ac_name": "PRLPAY",
|
||||
"ac_supply": "500000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "DSEC",
|
||||
"ac_supply": "7000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "GLXT",
|
||||
"ac_supply": "10000000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "EQL",
|
||||
"ac_supply": "500000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "ZILLA",
|
||||
"ac_supply": "11000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "RFOX",
|
||||
"ac_supply": "1000000000",
|
||||
"ac_reward": "100000000"
|
||||
},
|
||||
{
|
||||
"ac_name": "SEC",
|
||||
"ac_supply": "1000000000",
|
||||
"ac_cc": "333"
|
||||
},
|
||||
{
|
||||
"ac_name": "CCL",
|
||||
"ac_supply": "200000000",
|
||||
"ac_name": "PGT",
|
||||
"ac_supply": "10000000",
|
||||
"ac_end": "1",
|
||||
"addnode": [
|
||||
"190.114.254.104"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "KMDICE",
|
||||
"ac_supply": "10500000",
|
||||
"ac_reward": "2500000000",
|
||||
"ac_halving": "210000",
|
||||
"ac_cc": "2",
|
||||
"addressindex": "1",
|
||||
"spentindex": "1",
|
||||
"addnode": [
|
||||
"142.93.136.89",
|
||||
"195.201.22.89"
|
||||
"144.76.217.232"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ac_name": "DION",
|
||||
"ac_supply": "3900000000",
|
||||
"ac_reward": "22260000000",
|
||||
"ac_staked": "100",
|
||||
"ac_cc": "1",
|
||||
"ac_end": "4300000000",
|
||||
"addnode": [
|
||||
"51.75.124.34"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -39,3 +39,8 @@ echo $pubkey
|
||||
~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 &
|
||||
./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 &
|
||||
./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 &
|
||||
./komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=136.243.102.225 &
|
||||
./komodod -pubkey=$pubkey -ac_name=MGNX -ac_supply=12465003 -ac_staked=90 -ac_reward=2000000000 -ac_halving=525960 -ac_cc=2 -ac_end=2629800 -addnode=142.93.27.180 &
|
||||
./komodod -pubkey=$pubkey -ac_name=PGT -ac_supply=10000000 -ac_end=1 -addnode=190.114.254.104 &
|
||||
./komodod -pubkey=$pubkey -ac_name=KMDICE -ac_supply=10500000 -ac_reward=2500000000 -ac_halving=210000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=144.76.217.232 &
|
||||
./komodod -pubkey=$pubkey -ac_name=DION -ac_supply=3900000000 -ac_reward=22260000000 -ac_staked=100 -ac_cc=1 -ac_end=4300000000 -addnode=51.75.124.34 &
|
||||
|
||||
@@ -75,10 +75,11 @@ public:
|
||||
#include "komodo_utils.h"
|
||||
#include "komodo_cJSON.c"
|
||||
#include "komodo_notary.h"
|
||||
#include "notaries_staked.cpp"
|
||||
|
||||
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout,uint256 MoM,int32_t MoMdepth)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint32_t komodo_heightstamp(int32_t height)
|
||||
|
||||
@@ -869,7 +869,7 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t
|
||||
memset(&zero,0,sizeof(zero));
|
||||
if ( (cp= Diceinit(fundingPubKey,zero,&C,planstr,txfee,mypk,dicepk,sbits,a,b,c,d)) == 0 )
|
||||
{
|
||||
CCerror = "Diceinit error in create funding";
|
||||
CCerror = "Diceinit error in create funding, is your transaction confirmed?";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
return("");
|
||||
}
|
||||
@@ -894,8 +894,10 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
return("");
|
||||
}
|
||||
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
|
||||
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) {
|
||||
CCerror = "Diceinit error in add funding, is your transaction confirmed?";
|
||||
return("");
|
||||
}
|
||||
scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG;
|
||||
if ( 0 )
|
||||
{
|
||||
@@ -943,8 +945,10 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
return("");
|
||||
}
|
||||
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
|
||||
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) {
|
||||
CCerror = "Diceinit error in bet, is your transaction confirmed?";
|
||||
return("");
|
||||
}
|
||||
if ( bet < minbet || bet > maxbet || odds > maxodds )
|
||||
{
|
||||
CCerror = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds);
|
||||
@@ -984,7 +988,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256
|
||||
//char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid));
|
||||
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
|
||||
{
|
||||
CCerror = "Diceinit error in finish";
|
||||
CCerror = "Diceinit error in finish, is your transaction confirmed?";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
return("");
|
||||
}
|
||||
@@ -1097,7 +1101,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx
|
||||
CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res;
|
||||
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
|
||||
{
|
||||
CCerror = "Diceinit error in status";
|
||||
CCerror = "Diceinit error in status, is your transaction confirmed?";
|
||||
fprintf(stderr,"%s\n", CCerror.c_str() );
|
||||
return(0.);
|
||||
}
|
||||
|
||||
@@ -140,45 +140,17 @@ int32_t Eval::GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t time
|
||||
return komodo_notaries(pubkeys, height, timestamp);
|
||||
}
|
||||
|
||||
|
||||
bool Eval::CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const
|
||||
{
|
||||
if (tx.vin.size() < 11) return false;
|
||||
|
||||
uint8_t seenNotaries[64] = {0};
|
||||
uint8_t notaries[64][33];
|
||||
int nNotaries = GetNotaries(notaries, height, timestamp);
|
||||
CrosschainAuthority auth;
|
||||
auth.requiredSigs = 11;
|
||||
auth.size = GetNotaries(auth.notaries, height, timestamp);
|
||||
|
||||
BOOST_FOREACH(const CTxIn &txIn, tx.vin)
|
||||
{
|
||||
// Get notary pubkey
|
||||
CTransaction tx;
|
||||
uint256 hashBlock;
|
||||
if (!GetTxUnconfirmed(txIn.prevout.hash, tx, hashBlock)) return false;
|
||||
if (tx.vout.size() < txIn.prevout.n) return false;
|
||||
CScript spk = tx.vout[txIn.prevout.n].scriptPubKey;
|
||||
if (spk.size() != 35) return false;
|
||||
const unsigned char *pk = spk.data();
|
||||
if (pk++[0] != 33) return false;
|
||||
if (pk[33] != OP_CHECKSIG) return false;
|
||||
|
||||
// Check it's a notary
|
||||
for (int i=0; i<nNotaries; i++) {
|
||||
if (!seenNotaries[i]) {
|
||||
if (memcmp(pk, notaries[i], 33) == 0) {
|
||||
seenNotaries[i] = 1;
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
found:;
|
||||
}
|
||||
|
||||
return true;
|
||||
return CheckTxAuthority(tx, auth);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get MoM from a notarisation tx hash (on KMD)
|
||||
*/
|
||||
@@ -192,17 +164,6 @@ bool Eval::GetNotarisationData(const uint256 notaryHash, NotarisationData &data)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get MoMoM corresponding to a notarisation tx hash (on assetchain)
|
||||
*/
|
||||
bool Eval::GetProofRoot(uint256 kmdNotarisationHash, uint256 &momom) const
|
||||
{
|
||||
std::pair<uint256,NotarisationData> out;
|
||||
if (!GetNextBacknotarisation(kmdNotarisationHash, out)) return false;
|
||||
momom = out.second.MoMoM;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t Eval::GetAssetchainsCC() const
|
||||
{
|
||||
|
||||
@@ -103,7 +103,6 @@ public:
|
||||
virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const;
|
||||
virtual int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const;
|
||||
virtual bool GetNotarisationData(uint256 notarisationHash, NotarisationData &data) const;
|
||||
virtual bool GetProofRoot(uint256 kmdNotarisationHash, uint256 &momom) const;
|
||||
virtual bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const;
|
||||
virtual uint32_t GetAssetchainsCC() const;
|
||||
virtual std::string GetAssetchainsSymbol() const;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "cc/eval.h"
|
||||
#include "cc/utils.h"
|
||||
#include "importcoin.h"
|
||||
#include "crosschain.h"
|
||||
#include "primitives/transaction.h"
|
||||
|
||||
|
||||
@@ -37,7 +38,7 @@ bool Eval::ImportCoin(const std::vector<uint8_t> params, const CTransaction &imp
|
||||
|
||||
if (!UnmarshalImportTx(importTx, proof, burnTx, payouts))
|
||||
return Invalid("invalid-params");
|
||||
|
||||
|
||||
// Control all aspects of this transaction
|
||||
// It should not be at all malleable
|
||||
if (MakeImportCoinTransaction(proof, burnTx, payouts).GetHash() != importTx.GetHash())
|
||||
@@ -75,16 +76,10 @@ bool Eval::ImportCoin(const std::vector<uint8_t> params, const CTransaction &imp
|
||||
|
||||
// Check proof confirms existance of burnTx
|
||||
{
|
||||
uint256 momom, target;
|
||||
if (!GetProofRoot(proof.first, momom))
|
||||
return Invalid("coudnt-load-momom");
|
||||
|
||||
target = proof.second.Exec(burnTx.GetHash());
|
||||
if (momom != proof.second.Exec(burnTx.GetHash()))
|
||||
uint256 target = proof.second.Exec(burnTx.GetHash());
|
||||
if (!CheckMoMoM(proof.first, target))
|
||||
return Invalid("momom-check-fail");
|
||||
}
|
||||
|
||||
return Valid();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -666,7 +666,7 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
GetCCaddress(cp,coinaddr,pk);
|
||||
SetCCunspents(unspentOutputs,coinaddr);
|
||||
fprintf(stderr,"addoracleinputs from (%s)\n",coinaddr);
|
||||
//fprintf(stderr,"addoracleinputs from (%s)\n",coinaddr);
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
|
||||
{
|
||||
txid = it->first.txhash;
|
||||
|
||||
@@ -50,7 +50,7 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh
|
||||
|
||||
int seenOwnNotarisations = 0;
|
||||
|
||||
bool txscl = IsTXSCL(symbol);
|
||||
int authority = GetSymbolAuthority(symbol);
|
||||
|
||||
for (int i=0; i<NOTARISATION_SCAN_LIMIT_BLOCKS; i++) {
|
||||
if (i > kmdHeight) break;
|
||||
@@ -68,19 +68,27 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh
|
||||
destNotarisationTxid = nota.first;
|
||||
else if (seenOwnNotarisations == 2)
|
||||
goto end;
|
||||
break;
|
||||
fprintf(stderr, "kmd heigt notarisation added: %d\n",kmdHeight-i);
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
if (seenOwnNotarisations == 1) {
|
||||
BOOST_FOREACH(Notarisation& nota, notarisations) {
|
||||
if (IsTXSCL(nota.second.symbol) == txscl)
|
||||
if (nota.second.ccId == targetCCid)
|
||||
moms.push_back(nota.second.MoM);
|
||||
if (GetSymbolAuthority(nota.second.symbol) == authority)
|
||||
if (nota.second.ccId == targetCCid) {
|
||||
moms.push_back(nota.second.MoM);
|
||||
//fprintf(stderr, "added mom: %s\n",nota.second.MoM.GetHex().data());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Not enough own notarisations found to return determinate MoMoM
|
||||
destNotarisationTxid = uint256();
|
||||
moms.clear();
|
||||
return uint256();
|
||||
|
||||
end:
|
||||
return GetMerkleRoot(moms);
|
||||
}
|
||||
@@ -95,8 +103,9 @@ template <typename IsTarget>
|
||||
int ScanNotarisationsFromHeight(int nHeight, const IsTarget f, Notarisation &found)
|
||||
{
|
||||
int limit = std::min(nHeight + NOTARISATION_SCAN_LIMIT_BLOCKS, chainActive.Height());
|
||||
|
||||
for (int h=nHeight; h<limit; h++) {
|
||||
int start = std::max(nHeight, 1);
|
||||
|
||||
for (int h=start; h<limit; h++) {
|
||||
NotarisationsInBlock notarisations;
|
||||
|
||||
if (!GetBlockNotarisations(*chainActive[h]->phashBlock, notarisations))
|
||||
@@ -124,7 +133,7 @@ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_
|
||||
*/
|
||||
EvalRef eval;
|
||||
uint256 MoM = assetChainProof.second.Exec(txid);
|
||||
|
||||
|
||||
// Get a kmd height for given notarisation Txid
|
||||
int kmdHeight;
|
||||
{
|
||||
@@ -156,7 +165,9 @@ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_
|
||||
uint256 MoMoM = CalculateProofRoot(targetSymbol, targetCCid, kmdHeight, moms, targetChainNotarisationTxid);
|
||||
if (MoMoM.IsNull())
|
||||
throw std::runtime_error("No MoMs found");
|
||||
|
||||
|
||||
printf("[%s] GetCrossChainProof MoMoM: %s\n", targetSymbol,MoMoM.GetHex().data());
|
||||
|
||||
// Find index of source MoM in MoMoM
|
||||
int nIndex;
|
||||
for (nIndex=0; nIndex<moms.size(); nIndex++) {
|
||||
@@ -245,6 +256,38 @@ bool GetNextBacknotarisation(uint256 kmdNotarisationTxid, Notarisation &out)
|
||||
}
|
||||
|
||||
|
||||
bool CheckMoMoM(uint256 kmdNotarisationHash, uint256 momom)
|
||||
{
|
||||
/*
|
||||
* Given a notarisation hash and an MoMoM. Backnotarisations may arrive out of order
|
||||
* or multiple in the same block. So dereference the notarisation hash to the corresponding
|
||||
* backnotarisation and scan around the kmdheight to see if the MoMoM is a match.
|
||||
* This is a sledgehammer approach...
|
||||
*/
|
||||
|
||||
Notarisation bn;
|
||||
if (!GetBackNotarisation(kmdNotarisationHash, bn))
|
||||
return false;
|
||||
|
||||
// Need to get block height of that backnotarisation
|
||||
EvalRef eval;
|
||||
CBlockIndex block;
|
||||
CTransaction tx;
|
||||
if (!eval->GetTxConfirmed(bn.first, tx, block)){
|
||||
fprintf(stderr, "Can't get height of backnotarisation, this should not happen\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
Notarisation nota;
|
||||
auto checkMoMoM = [&](Notarisation ¬a) {
|
||||
return nota.second.MoMoM == momom;
|
||||
};
|
||||
|
||||
return (bool) ScanNotarisationsFromHeight(block.nHeight-100, checkMoMoM, nota);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* On assetchain
|
||||
* in: txid
|
||||
@@ -277,7 +320,7 @@ TxProof GetAssetchainProof(uint256 hash)
|
||||
};
|
||||
if (!ScanNotarisationsFromHeight(blockIndex->nHeight, isTarget, nota))
|
||||
throw std::runtime_error("backnotarisation not yet confirmed");
|
||||
|
||||
|
||||
// index of block in MoM leaves
|
||||
nIndex = nota.second.height - blockIndex->nHeight;
|
||||
}
|
||||
@@ -291,7 +334,7 @@ TxProof GetAssetchainProof(uint256 hash)
|
||||
}
|
||||
bool fMutated;
|
||||
BuildMerkleTree(&fMutated, leaves, tree);
|
||||
branch = GetMerkleBranch(nIndex, leaves.size(), tree);
|
||||
branch = GetMerkleBranch(nIndex, leaves.size(), tree);
|
||||
|
||||
// Check branch
|
||||
uint256 ourResult = SafeCheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex);
|
||||
@@ -330,7 +373,7 @@ TxProof GetAssetchainProof(uint256 hash)
|
||||
}
|
||||
|
||||
// Check the proof
|
||||
if (nota.second.MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex))
|
||||
if (nota.second.MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex))
|
||||
throw std::runtime_error("Failed validating MoM");
|
||||
|
||||
// All done!
|
||||
|
||||
@@ -3,6 +3,18 @@
|
||||
|
||||
#include "cc/eval.h"
|
||||
|
||||
const int CROSSCHAIN_KOMODO = 1;
|
||||
const int CROSSCHAIN_TXSCL = 2;
|
||||
const int CROSSCHAIN_STAKED = 3;
|
||||
|
||||
typedef struct CrosschainAuthority {
|
||||
uint8_t notaries[64][33];
|
||||
size_t size;
|
||||
size_t requiredSigs;
|
||||
} CrosschainAuthority;
|
||||
|
||||
int GetSymbolAuthority(const char* symbol);
|
||||
bool CheckTxAuthority(const CTransaction &tx, CrosschainAuthority auth);
|
||||
|
||||
/* On assetchain */
|
||||
TxProof GetAssetchainProof(uint256 hash);
|
||||
@@ -15,7 +27,7 @@ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_
|
||||
void CompleteImportTransaction(CTransaction &importTx);
|
||||
|
||||
/* On assetchain */
|
||||
bool GetNextBacknotarisation(uint256 txid, std::pair<uint256,NotarisationData> &bn);
|
||||
bool CheckMoMoM(uint256 kmdNotarisationHash, uint256 momom);
|
||||
|
||||
|
||||
#endif /* CROSSCHAIN_H */
|
||||
|
||||
67
src/crosschain_authority.cpp
Normal file
67
src/crosschain_authority.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "cc/eval.h"
|
||||
#include "crosschain.h"
|
||||
#include "notarisationdb.h"
|
||||
#include "notaries_staked.h"
|
||||
|
||||
int GetSymbolAuthority(const char* symbol)
|
||||
{
|
||||
if (strncmp(symbol, "TXSCL", 5) == 0)
|
||||
return CROSSCHAIN_TXSCL;
|
||||
if (is_STAKED(symbol) != 0) {
|
||||
//printf("RETURNED CROSSCHAIN STAKED AS TRUE\n");
|
||||
return CROSSCHAIN_STAKED;
|
||||
}
|
||||
//printf("RETURNED CROSSCHAIN KOMODO AS TRUE\n");
|
||||
return CROSSCHAIN_KOMODO;
|
||||
}
|
||||
|
||||
|
||||
bool CheckTxAuthority(const CTransaction &tx, CrosschainAuthority auth)
|
||||
{
|
||||
EvalRef eval;
|
||||
|
||||
if (tx.vin.size() < auth.requiredSigs) return false;
|
||||
|
||||
uint8_t seen[64] = {0};
|
||||
|
||||
BOOST_FOREACH(const CTxIn &txIn, tx.vin)
|
||||
{
|
||||
// Get notary pubkey
|
||||
CTransaction tx;
|
||||
uint256 hashBlock;
|
||||
if (!eval->GetTxUnconfirmed(txIn.prevout.hash, tx, hashBlock)) return false;
|
||||
if (tx.vout.size() < txIn.prevout.n) return false;
|
||||
CScript spk = tx.vout[txIn.prevout.n].scriptPubKey;
|
||||
if (spk.size() != 35) return false;
|
||||
const unsigned char *pk = spk.data();
|
||||
if (pk++[0] != 33) return false;
|
||||
if (pk[33] != OP_CHECKSIG) return false;
|
||||
|
||||
// Check it's a notary
|
||||
for (int i=0; i<auth.size; i++) {
|
||||
if (!seen[i]) {
|
||||
if (memcmp(pk, auth.notaries[i], 33) == 0) {
|
||||
seen[i] = 1;
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
found:;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
const CrosschainAuthority auth_STAKED = [&](){
|
||||
CrosschainAuthority auth;
|
||||
auth.requiredSigs = (num_notaries_STAKED / 5);
|
||||
auth.size = num_notaries_STAKED;
|
||||
for (int n=0; n<auth.size; n++)
|
||||
for (size_t i=0; i<33; i++)
|
||||
sscanf(notaries_STAKED[n][1]+(i*2), "%2hhx", auth.notaries[n]+i);
|
||||
return auth;
|
||||
}();
|
||||
*/
|
||||
2
src/fiat/dion
Executable file
2
src/fiat/dion
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=DION $1 $2 $3 $4 $5 $6
|
||||
2
src/fiat/kmdice
Executable file
2
src/fiat/kmdice
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=KMDICE $1 $2 $3 $4 $5 $6
|
||||
2
src/fiat/mgnx
Executable file
2
src/fiat/mgnx
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=MGNX $1 $2 $3 $4 $5 $6
|
||||
2
src/fiat/pgt
Executable file
2
src/fiat/pgt
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=PGT $1 $2 $3 $4 $5 $6
|
||||
2
src/fiat/pirate
Executable file
2
src/fiat/pirate
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
./komodo-cli -ac_name=PIRATE $1 $2 $3 $4 $5 $6
|
||||
13
src/komodo.h
13
src/komodo.h
@@ -16,6 +16,7 @@
|
||||
#ifndef H_KOMODO_H
|
||||
#define H_KOMODO_H
|
||||
#include "komodo_defs.h"
|
||||
#include "notaries_staked.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define printf(...)
|
||||
@@ -756,7 +757,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
|
||||
printf("ISRATIFICATION (%s)\n",(char *)&scriptbuf[len+32*2+4]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( *isratificationp == 0 && (signedmask != 0 || (scriptbuf[len] != 'X' && scriptbuf[len] != 'A')) ) // && scriptbuf[len] != 'I')
|
||||
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen,j,zero,0);
|
||||
}
|
||||
@@ -830,6 +831,10 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
txn_count = block.vtx.size();
|
||||
for (i=0; i<txn_count; i++)
|
||||
{
|
||||
if ((is_STAKED(ASSETCHAINS_SYMBOL) != 0) && (STAKED_era(pindex->GetBlockTime()) == 0)) {
|
||||
printf("ERA 0 SKIP %s\n",ASSETCHAINS_SYMBOL);
|
||||
continue;
|
||||
}
|
||||
txhash = block.vtx[i].GetHash();
|
||||
numvouts = block.vtx[i].vout.size();
|
||||
notaryid = -1;
|
||||
@@ -854,11 +859,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
|
||||
} //else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j);
|
||||
}
|
||||
numvalid = bitweight(signedmask);
|
||||
if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) ||
|
||||
if ( ((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) ||
|
||||
(numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) ||
|
||||
numvalid > (numnotaries/5)) )
|
||||
numvalid > (numnotaries/5) )
|
||||
{
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0)
|
||||
{
|
||||
static FILE *signedfp;
|
||||
if ( signedfp == 0 )
|
||||
|
||||
@@ -169,7 +169,7 @@ try_again:
|
||||
curl_handle = curl_easy_init();
|
||||
init_string(&s);
|
||||
headers = curl_slist_append(0,"Expect:");
|
||||
|
||||
|
||||
curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )");
|
||||
curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(curl_handle,CURLOPT_URL, url);
|
||||
@@ -198,7 +198,7 @@ try_again:
|
||||
bracket0 = (char *)"[";
|
||||
bracket1 = (char *)"]";
|
||||
}
|
||||
|
||||
|
||||
databuf = (char *)malloc(256 + strlen(command) + strlen(params));
|
||||
sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1);
|
||||
//printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf);
|
||||
@@ -238,7 +238,7 @@ try_again:
|
||||
free(s.ptr);
|
||||
sleep((1<<numretries));
|
||||
goto try_again;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -524,7 +524,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t
|
||||
}
|
||||
return(hash);
|
||||
}
|
||||
|
||||
|
||||
uint256 _komodo_getblockhash(int32_t height);*/
|
||||
|
||||
uint64_t komodo_seed(int32_t height)
|
||||
@@ -1099,31 +1099,39 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_
|
||||
|
||||
/*
|
||||
komodo_checkPOW (fast) is called early in the process and should only refer to data immediately available. it is a filter to prevent bad blocks from going into the local DB. The more blocks we can filter out at this stage, the less junk in the local DB that will just get purged later on.
|
||||
|
||||
|
||||
komodo_checkPOW (slow) is called right before connecting blocks so all prior blocks can be assumed to be there and all checks must pass
|
||||
|
||||
|
||||
commission must be in coinbase.vout[1] and must be >= 10000 sats
|
||||
PoS stake must be without txfee and in the last tx in the block at vout[0]
|
||||
*/
|
||||
extern int32_t ASSETCHAINS_STREAM;
|
||||
|
||||
uint64_t komodo_commission(const CBlock *pblock)
|
||||
{
|
||||
int32_t i,j,n=0,txn_count; uint64_t commission,total = 0;
|
||||
txn_count = pblock->vtx.size();
|
||||
for (i=0; i<txn_count; i++)
|
||||
if ( ASSETCHAINS_STREAM == 0 )
|
||||
{
|
||||
n = pblock->vtx[i].vout.size();
|
||||
for (j=0; j<n; j++)
|
||||
{
|
||||
//fprintf(stderr,"(%d %.8f).%d ",i,dstr(block.vtx[i].vout[j].nValue),j);
|
||||
if ( i != 0 || j != 1 )
|
||||
total += pblock->vtx[i].vout[j].nValue;
|
||||
}
|
||||
txn_count = pblock->vtx.size();
|
||||
for (i=0; i<txn_count; i++)
|
||||
{
|
||||
n = pblock->vtx[i].vout.size();
|
||||
for (j=0; j<n; j++)
|
||||
{
|
||||
//fprintf(stderr,"(%d %.8f).%d ",i,dstr(block.vtx[i].vout[j].nValue),j);
|
||||
if ( i != 0 || j != 1 )
|
||||
total += pblock->vtx[i].vout[j].nValue;
|
||||
}
|
||||
}
|
||||
//fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN));
|
||||
commission = ((total * ASSETCHAINS_COMMISSION) / COIN);
|
||||
if ( commission < 10000 )
|
||||
commission = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
commission = 10000;
|
||||
}
|
||||
//fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN));
|
||||
commission = ((total * ASSETCHAINS_COMMISSION) / COIN);
|
||||
if ( commission < 10000 )
|
||||
commission = 0;
|
||||
return(commission);
|
||||
}
|
||||
|
||||
@@ -1464,7 +1472,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_
|
||||
int64_t komodo_checkcommission(CBlock *pblock,int32_t height)
|
||||
{
|
||||
int64_t checktoshis=0; uint8_t *script;
|
||||
if ( ASSETCHAINS_COMMISSION != 0 )
|
||||
if ( ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0)
|
||||
{
|
||||
checktoshis = komodo_commission(pblock);
|
||||
if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 )
|
||||
@@ -1570,14 +1578,33 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
||||
if ( height == 1 )
|
||||
{
|
||||
script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data();
|
||||
if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 )
|
||||
if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) {
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( komodo_checkcommission(pblock,height) < 0 )
|
||||
return(-1);
|
||||
}
|
||||
if ( ASSETCHAINS_STREAM != 0 && height > 128 )
|
||||
{
|
||||
int lasttx = ( pblock->vtx.size() -1 );
|
||||
printf("ABOUT TO CHECK LAST TX: %d\n",lasttx);
|
||||
if ( lasttx == 0 )
|
||||
return(-1);
|
||||
uint256 hash; CTransaction tx;
|
||||
if (GetTransaction(pblock->vtx[lasttx].vin[0].prevout.hash,tx,hash,false))
|
||||
{
|
||||
printf("CHECKING THE script pubkey\n");
|
||||
script = (uint8_t *)tx.vout[pblock->vtx[lasttx].vin[0].prevout.n].scriptPubKey.data();
|
||||
if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) {
|
||||
printf("THE PUBKEY IS WRONG!\n");
|
||||
return(-1);
|
||||
}
|
||||
printf("THE PUBKEY IS RIGHT! \n");
|
||||
}
|
||||
}
|
||||
}
|
||||
//fprintf(stderr,"komodo_checkPOW possible.%d slowflag.%d ht.%d notaryid.%d failed.%d\n",possible,slowflag,height,notaryid,failed);
|
||||
if ( failed != 0 && possible == 0 && notaryid < 0 )
|
||||
|
||||
@@ -90,7 +90,7 @@ struct pax_transaction *komodo_paxmark(int32_t height,uint256 txid,uint16_t vout
|
||||
pax->marked = mark;
|
||||
//if ( height > 214700 || pax->height > 214700 )
|
||||
// printf("mark ht.%d %.8f %.8f\n",pax->height,dstr(pax->komodoshis),dstr(pax->fiatoshis));
|
||||
|
||||
|
||||
}
|
||||
pthread_mutex_unlock(&komodo_mutex);
|
||||
return(pax);
|
||||
@@ -203,9 +203,9 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t
|
||||
// return(0);
|
||||
incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4));
|
||||
//41e77b91cb68dc2aa02fa88550eae6b6d44db676a7e935337b6d1392d9718f03cb0200305c90660400000000fbcbeb1f000000bde801006201000058e7945ad08ddba1eac9c9b6c8e1e97e8016a2d152
|
||||
|
||||
|
||||
// 41e94d736ec69d88c08b5d238abeeca609c02357a8317e0d56c328bcb1c259be5d0200485bc80200000000404b4c000000000059470200b80b000061f22ba7d19fe29ac3baebd839af8b7127d1f9075553440046bb4cc7a3b5cd39dffe7206507a3482a00780e617f68b273cce9817ed69298d02001069ca1b0000000080f0fa02000000005b470200b90b000061f22ba7d19fe29ac3baebd839af8b7127d1f90755
|
||||
|
||||
|
||||
//for (i=0; i<opretlen; i++)
|
||||
// printf("%02x",opretbuf[i]);
|
||||
//printf(" opretlen.%d (%s)\n",opretlen,base);
|
||||
@@ -744,7 +744,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim
|
||||
else
|
||||
{
|
||||
checktoshis = 0;
|
||||
if ( ASSETCHAINS_COMMISSION != 0 && height > 1 )
|
||||
if ( (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) && height > 1 )
|
||||
{
|
||||
if ( (checktoshis= komodo_checkcommission((CBlock *)&block,height)) < 0 )
|
||||
{
|
||||
@@ -772,7 +772,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim
|
||||
|
||||
const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source)
|
||||
{
|
||||
uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff;
|
||||
uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff;
|
||||
const char *typestr = "unknown";
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 && opretbuf[0] != 'K' )
|
||||
{
|
||||
@@ -1185,7 +1185,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_
|
||||
printf("numR.%d numV.%d numN.%d count.%d\n",numR,numV,numN,count);
|
||||
/*else if ( func == 'K' ) // KMD height: stop after 1st
|
||||
else if ( func == 'T' ) // KMD height+timestamp: stop after 1st
|
||||
|
||||
|
||||
else if ( func == 'N' ) // notarization, scan backwards 1440+ blocks;
|
||||
else if ( func == 'V' ) // price feed: can stop after 1440+
|
||||
else if ( func == 'R' ) // opreturn:*/
|
||||
@@ -1518,4 +1518,3 @@ void komodo_passport_iteration()
|
||||
printf("READY for %s RPC calls at %u! done PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,(uint32_t)time(NULL),ASSETCHAINS_SYMBOL,refid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,9 +45,9 @@ struct komodo_state KOMODO_STATES[34];
|
||||
#define _COINBASE_MATURITY 100
|
||||
int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
|
||||
|
||||
int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1;
|
||||
int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,ASSETCHAINS_STREAM,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1;
|
||||
int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
|
||||
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY;
|
||||
std::string ASSETCHAINS_OVERRIDE_ADDRESS,NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY;
|
||||
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW;
|
||||
|
||||
char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096];
|
||||
@@ -55,7 +55,7 @@ uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
|
||||
uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1;
|
||||
uint32_t ASSETCHAINS_MAGIC = 2387029918;
|
||||
uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE;
|
||||
uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10;
|
||||
uint64_t ASSETCHAINS_FOUNDERS_REWARD,ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10;
|
||||
|
||||
uint32_t KOMODO_INITDONE;
|
||||
char KMDUSERPASS[8192],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771;
|
||||
|
||||
@@ -18,8 +18,13 @@
|
||||
|
||||
#include "komodo_cJSON.h"
|
||||
|
||||
#include "notaries_staked.h"
|
||||
|
||||
#define KOMODO_MAINNET_START 178999
|
||||
|
||||
//extern const char *notaries_STAKED[][2];
|
||||
//extern const int num_notaries_STAKED;
|
||||
|
||||
const char *Notaries_genesis[][2] =
|
||||
{
|
||||
{ "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" },
|
||||
@@ -202,42 +207,121 @@ const char *Notaries_elected1[][2] =
|
||||
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp)
|
||||
{
|
||||
static uint8_t elected_pubkeys0[64][33],elected_pubkeys1[64][33],did0,did1; static int32_t n0,n1;
|
||||
static uint8_t staked_pubkeys1[64][33],staked_pubkeys2[64][33],didstaked1,didstaked2; static int32_t ns1,ns2;
|
||||
static uint8_t staked_pubkeys3[64][33],staked_pubkeys4[64][33],didstaked3,didstaked4; static int32_t ns3,ns4;
|
||||
static uint8_t null_pubkeys[64][33] = {0};
|
||||
int staked_era;
|
||||
int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp;
|
||||
if ( timestamp == 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
timestamp = komodo_heightstamp(height);
|
||||
else if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
timestamp = 0;
|
||||
if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
// If this chain is not a staked chain, use the normal Komodo logic to determine notaries. This allows KMD to still sync and use its proper pubkeys for dPoW.
|
||||
if (is_STAKED(ASSETCHAINS_SYMBOL) == 0)
|
||||
{
|
||||
if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP1) || (ASSETCHAINS_SYMBOL[0] == 0 && height <= KOMODO_NOTARIES_HEIGHT1) )
|
||||
{
|
||||
if ( did0 == 0 )
|
||||
{
|
||||
n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0));
|
||||
for (i=0; i<n0; i++)
|
||||
decode_hex(elected_pubkeys0[i],33,(char *)Notaries_elected0[i][1]);
|
||||
did0 = 1;
|
||||
}
|
||||
memcpy(pubkeys,elected_pubkeys0,n0 * 33);
|
||||
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
//fprintf(stderr,"%s height.%d t.%u elected.%d notaries\n",ASSETCHAINS_SYMBOL,height,timestamp,n0);
|
||||
return(n0);
|
||||
}
|
||||
else //if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP2) || height <= KOMODO_NOTARIES_HEIGHT2 )
|
||||
{
|
||||
if ( did1 == 0 )
|
||||
{
|
||||
n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1));
|
||||
if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
{
|
||||
if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP1) || (ASSETCHAINS_SYMBOL[0] == 0 && height <= KOMODO_NOTARIES_HEIGHT1) )
|
||||
{
|
||||
if ( did0 == 0 )
|
||||
{
|
||||
n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0));
|
||||
for (i=0; i<n0; i++)
|
||||
decode_hex(elected_pubkeys0[i],33,(char *)Notaries_elected0[i][1]);
|
||||
did0 = 1;
|
||||
}
|
||||
memcpy(pubkeys,elected_pubkeys0,n0 * 33);
|
||||
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
//fprintf(stderr,"%s height.%d t.%u elected.%d notaries\n",ASSETCHAINS_SYMBOL,height,timestamp,n0);
|
||||
return(n0);
|
||||
}
|
||||
else //if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP2) || height <= KOMODO_NOTARIES_HEIGHT2 )
|
||||
{
|
||||
if ( did1 == 0 )
|
||||
{
|
||||
n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1));
|
||||
for (i=0; i<n1; i++)
|
||||
decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]);
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"%s height.%d t.%u elected.%d notaries2\n",ASSETCHAINS_SYMBOL,height,timestamp,n1);
|
||||
did1 = 1;
|
||||
}
|
||||
memcpy(pubkeys,elected_pubkeys1,n1 * 33);
|
||||
return(n1);
|
||||
}
|
||||
}
|
||||
memcpy(pubkeys,elected_pubkeys1,n1 * 33);
|
||||
return(n1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // here we can activate our pubkeys for STAKED chains by era.
|
||||
if (timestamp != 0)
|
||||
{
|
||||
staked_era = STAKED_era(timestamp);
|
||||
if (staked_era == 1)
|
||||
{
|
||||
if (didstaked1 == 0)
|
||||
{
|
||||
ns1 = num_notaries_STAKED1;
|
||||
for (i=0; i<ns1; i++)
|
||||
decode_hex(staked_pubkeys1[i],33,(char *)notaries_STAKED1[i][1]);
|
||||
didstaked1 = 1;
|
||||
didstaked2 = 0;
|
||||
didstaked3 = 0;
|
||||
didstaked4 = 0;
|
||||
printf("%s IS A STAKED CHAIN and is era 1 \n",ASSETCHAINS_SYMBOL);
|
||||
}
|
||||
memcpy(pubkeys,staked_pubkeys1,ns1 * 33);
|
||||
return(ns1);
|
||||
} else if (staked_era == 2)
|
||||
{
|
||||
if (didstaked2 == 0)
|
||||
{
|
||||
ns2 = num_notaries_STAKED2;
|
||||
for (i=0; i<ns2; i++)
|
||||
decode_hex(staked_pubkeys2[i],33,(char *)notaries_STAKED2[i][1]);
|
||||
didstaked2 = 1;
|
||||
didstaked3 = 0;
|
||||
didstaked4 = 0;
|
||||
printf("%s IS A STAKED CHAIN and is era 2 \n",ASSETCHAINS_SYMBOL);
|
||||
}
|
||||
memcpy(pubkeys,staked_pubkeys2,ns2 * 33);
|
||||
return(ns2);
|
||||
} else if (staked_era == 3)
|
||||
{
|
||||
if (didstaked3 == 0)
|
||||
{
|
||||
ns3 = num_notaries_STAKED3;
|
||||
for (i=0; i<ns3; i++)
|
||||
decode_hex(staked_pubkeys3[i],33,(char *)notaries_STAKED3[i][1]);
|
||||
didstaked3 = 1;
|
||||
didstaked4 = 0;
|
||||
printf("%s IS A STAKED CHAIN and is era 3 \n",ASSETCHAINS_SYMBOL);
|
||||
}
|
||||
memcpy(pubkeys,staked_pubkeys3,ns3 * 33);
|
||||
return(ns3);
|
||||
} else if (staked_era == 4)
|
||||
{
|
||||
if (didstaked4 == 0)
|
||||
{
|
||||
ns4 = num_notaries_STAKED4;
|
||||
for (i=0; i<ns4; i++)
|
||||
decode_hex(staked_pubkeys4[i],33,(char *)notaries_STAKED4[i][1]);
|
||||
didstaked4 = 1;
|
||||
printf("%s IS A STAKED CHAIN and is era 4 \n",ASSETCHAINS_SYMBOL);
|
||||
}
|
||||
memcpy(pubkeys,staked_pubkeys4,ns4 * 33);
|
||||
return(ns4);
|
||||
} else if (staked_era == 0)
|
||||
{
|
||||
// this means we are in a gap, so we set the array of pubkeys to zero, this does't seem to correctly work, so added exeption to komodo.h aswell.
|
||||
//for (i=0; i<1; i++)
|
||||
// decode_hex(null_pubkeys[i],33,(char *)notaries_STAKED1[i][1]);
|
||||
printf("%s IS A STAKED CHAIN and is in an ERA GAP.\n",ASSETCHAINS_SYMBOL);
|
||||
memcpy(pubkeys,null_pubkeys,64 * 33);
|
||||
return(64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
htind = height / KOMODO_ELECTION_GAP;
|
||||
if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP )
|
||||
htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1;
|
||||
|
||||
@@ -1562,6 +1562,14 @@ void komodo_args(char *argv0)
|
||||
ASSETCHAINS_DECAY = GetArg("-ac_decay",0);
|
||||
ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0);
|
||||
ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey","");
|
||||
ASSETCHAINS_FOUNDERS_REWARD = GetArg("-ac_freward",0);
|
||||
ASSETCHAINS_OVERRIDE_ADDRESS = GetArg("-ac_address","");
|
||||
ASSETCHAINS_STREAM = GetArg("-ac_stream",0);
|
||||
|
||||
if ( ASSETCHAINS_STREAM != 0 && ( ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_PRIVATE != 0 )) {
|
||||
printf("ASSETCHAINS_STREAM cannot be used with:\n ASSETCHAINS_COMMISSION \n ASSETCHAINS_ENDSUBSIDY\n ASSETCHAINS_REWARD\n ASSETCHAINS_HALVING\n ASSETCHAINS_DECAY\n ASSETCHAINS_PRIVATE\n");
|
||||
exit(0);
|
||||
}
|
||||
if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 )
|
||||
ASSETCHAINS_STAKED = 100;
|
||||
if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 )
|
||||
@@ -1590,8 +1598,15 @@ void komodo_args(char *argv0)
|
||||
{
|
||||
ASSETCHAINS_COMMISSION = 0;
|
||||
printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n");
|
||||
}
|
||||
if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 )
|
||||
} else if ( ASSETCHAINS_STREAM != 0) {
|
||||
printf("ASSETCHAINS_STREAM needs ASSETCHAINS_OVERRIDE_PUBKEY! \n");
|
||||
exit(0);
|
||||
}
|
||||
if ( ASSETCHAINS_STREAM != 0 && ASSETCHAINS_SUPPLY == 10 ) {
|
||||
ASSETCHAINS_SUPPLY = 1000000;
|
||||
printf("ASSETCHAINS_STREAM is set with no supply, setting supply at 1,000,000 coins. \n");
|
||||
}
|
||||
if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_STREAM != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 )
|
||||
{
|
||||
fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]);
|
||||
extraptr = extrabuf;
|
||||
@@ -1767,4 +1782,3 @@ void komodo_prefetch(FILE *fp)
|
||||
}
|
||||
fseek(fp,fpos,SEEK_SET);
|
||||
}
|
||||
|
||||
|
||||
1168
src/main.cpp
1168
src/main.cpp
File diff suppressed because it is too large
Load Diff
@@ -916,6 +916,8 @@ extern CBlockTreeDB *pblocktree;
|
||||
*/
|
||||
int GetSpendHeight(const CCoinsViewCache& inputs);
|
||||
|
||||
uint64_t CalculateCurrentUsage();
|
||||
|
||||
/** Return a CMutableTransaction with contextual default values based on set of consensus rules at height */
|
||||
CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight);
|
||||
|
||||
|
||||
159
src/miner.cpp
159
src/miner.cpp
@@ -64,7 +64,7 @@ public:
|
||||
set<uint256> setDependsOn;
|
||||
CFeeRate feeRate;
|
||||
double dPriority;
|
||||
|
||||
|
||||
COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0)
|
||||
{
|
||||
}
|
||||
@@ -78,10 +78,10 @@ typedef boost::tuple<double, CFeeRate, const CTransaction*> TxPriority;
|
||||
class TxPriorityCompare
|
||||
{
|
||||
bool byFee;
|
||||
|
||||
|
||||
public:
|
||||
TxPriorityCompare(bool _byFee) : byFee(_byFee) { }
|
||||
|
||||
|
||||
bool operator()(const TxPriority& a, const TxPriority& b)
|
||||
{
|
||||
if (byFee)
|
||||
@@ -106,7 +106,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
|
||||
|
||||
#include "komodo_defs.h"
|
||||
|
||||
extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE;
|
||||
extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,ASSETCHAINS_STREAM,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE;
|
||||
extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED;
|
||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY;
|
||||
@@ -141,27 +141,27 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
// -blockversion=N to test forking scenarios
|
||||
if (Params().MineBlocksOnDemand())
|
||||
pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
|
||||
|
||||
|
||||
// Add dummy coinbase tx as first transaction
|
||||
pblock->vtx.push_back(CTransaction());
|
||||
pblocktemplate->vTxFees.push_back(-1); // updated at end
|
||||
pblocktemplate->vTxSigOps.push_back(-1); // updated at end
|
||||
|
||||
|
||||
// Largest block you're willing to create:
|
||||
unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
|
||||
// Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity:
|
||||
nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize));
|
||||
|
||||
|
||||
// How much of the block should be dedicated to high-priority transactions,
|
||||
// included regardless of the fees they pay
|
||||
unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
|
||||
nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
|
||||
|
||||
|
||||
// Minimum block size you want to create; block will be filled with free transactions
|
||||
// until there are no more or the block reaches this size:
|
||||
unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
|
||||
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
|
||||
|
||||
|
||||
// Collect memory pool transactions into the block
|
||||
CAmount nFees = 0;
|
||||
CBlockIndex* pindexPrev = 0;
|
||||
@@ -174,12 +174,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
|
||||
CCoinsViewCache view(pcoinsTip);
|
||||
uint32_t expired; uint64_t commission;
|
||||
|
||||
|
||||
// Priority order to process transactions
|
||||
list<COrphan> vOrphan; // list memory doesn't move
|
||||
map<uint256, vector<COrphan*> > mapDependers;
|
||||
bool fPrintPriority = GetBoolArg("-printpriority", false);
|
||||
|
||||
|
||||
// This vector will be sorted into a priority queue:
|
||||
vector<TxPriority> vecPriority;
|
||||
vecPriority.reserve(mempool.mapTx.size());
|
||||
@@ -187,11 +187,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
mi != mempool.mapTx.end(); ++mi)
|
||||
{
|
||||
const CTransaction& tx = mi->GetTx();
|
||||
|
||||
|
||||
int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
|
||||
? nMedianTimePast
|
||||
: pblock->GetBlockTime();
|
||||
|
||||
|
||||
if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight))
|
||||
{
|
||||
//fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight));
|
||||
@@ -256,16 +256,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
}
|
||||
|
||||
if (fMissingInputs) continue;
|
||||
|
||||
|
||||
// Priority is sum(valuein * age) / modified_txsize
|
||||
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
||||
dPriority = tx.ComputePriority(dPriority, nTxSize);
|
||||
|
||||
|
||||
uint256 hash = tx.GetHash();
|
||||
mempool.ApplyDeltas(hash, dPriority, nTotalIn);
|
||||
|
||||
|
||||
CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize);
|
||||
|
||||
|
||||
if (porphan)
|
||||
{
|
||||
porphan->dPriority = dPriority;
|
||||
@@ -274,27 +274,27 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
else
|
||||
vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx())));
|
||||
}
|
||||
|
||||
|
||||
// Collect transactions into block
|
||||
uint64_t nBlockSize = 1000;
|
||||
uint64_t nBlockTx = 0;
|
||||
int64_t interest;
|
||||
int nBlockSigOps = 100;
|
||||
bool fSortedByFee = (nBlockPrioritySize <= 0);
|
||||
|
||||
|
||||
TxPriorityCompare comparer(fSortedByFee);
|
||||
std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
||||
|
||||
|
||||
while (!vecPriority.empty())
|
||||
{
|
||||
// Take highest priority transaction off the priority queue:
|
||||
double dPriority = vecPriority.front().get<0>();
|
||||
CFeeRate feeRate = vecPriority.front().get<1>();
|
||||
const CTransaction& tx = *(vecPriority.front().get<2>());
|
||||
|
||||
|
||||
std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
||||
vecPriority.pop_back();
|
||||
|
||||
|
||||
// Size limits
|
||||
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
||||
if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx
|
||||
@@ -302,7 +302,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
//fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Legacy limits on sigOps:
|
||||
unsigned int nTxSigOps = GetLegacySigOpCount(tx);
|
||||
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1)
|
||||
@@ -329,7 +329,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
comparer = TxPriorityCompare(fSortedByFee);
|
||||
std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
|
||||
}
|
||||
|
||||
|
||||
if (!view.HaveInputs(tx))
|
||||
{
|
||||
//fprintf(stderr,"dont have inputs\n");
|
||||
@@ -345,7 +345,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
}
|
||||
}
|
||||
CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut();
|
||||
|
||||
|
||||
nTxSigOps += GetP2SHSigOpCount(tx, view);
|
||||
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1)
|
||||
{
|
||||
@@ -363,7 +363,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
continue;
|
||||
}
|
||||
UpdateCoins(tx, view, nHeight);
|
||||
|
||||
|
||||
// Added
|
||||
pblock->vtx.push_back(tx);
|
||||
pblocktemplate->vTxFees.push_back(nTxFees);
|
||||
@@ -372,12 +372,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
++nBlockTx;
|
||||
nBlockSigOps += nTxSigOps;
|
||||
nFees += nTxFees;
|
||||
|
||||
|
||||
if (fPrintPriority)
|
||||
{
|
||||
LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString());
|
||||
}
|
||||
|
||||
|
||||
// Add transactions that depend on this one to the priority queue
|
||||
if (mapDependers.count(hash))
|
||||
{
|
||||
@@ -395,7 +395,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nLastBlockTx = nBlockTx;
|
||||
nLastBlockSize = nBlockSize;
|
||||
blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
||||
@@ -420,7 +420,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
//printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13)));
|
||||
} else return(0); //fprintf(stderr,"no utxos eligible for staking\n");
|
||||
}
|
||||
|
||||
|
||||
// Create coinbase tx
|
||||
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight);
|
||||
txNew.vin.resize(1);
|
||||
@@ -435,9 +435,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
// Add fees
|
||||
txNew.vout[0].nValue += nFees;
|
||||
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
|
||||
|
||||
|
||||
pblock->vtx[0] = txNew;
|
||||
if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 )
|
||||
if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 )
|
||||
{
|
||||
int32_t i; uint8_t *ptr;
|
||||
txNew.vout.resize(2);
|
||||
@@ -448,7 +448,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
for (i=0; i<33; i++)
|
||||
ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i];
|
||||
ptr[34] = OP_CHECKSIG;
|
||||
//printf("autocreate commision vout\n");
|
||||
//printf("autocreate commission vout\n");
|
||||
pblock->vtx[0] = txNew;
|
||||
}
|
||||
pblocktemplate->vTxFees[0] = -nFees;
|
||||
@@ -458,7 +458,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
nonce <<= 32;
|
||||
nonce >>= 16;
|
||||
pblock->nNonce = ArithToUint256(nonce);
|
||||
|
||||
|
||||
// Fill in header
|
||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
||||
pblock->hashReserved = uint256();
|
||||
@@ -502,6 +502,26 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
else if ( ASSETCHAINS_STREAM != 0 && ASSETCHAINS_SYMBOL[0] != 0 && nHeight > 128 )
|
||||
{
|
||||
CMutableTransaction txStream = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1);
|
||||
if ( komodo_notaryvin(txStream,ASSETCHAINS_OVERRIDE_PUBKEY33) > 0 )
|
||||
{
|
||||
CAmount txfees = 10000;
|
||||
pblock->vtx.push_back(txStream);
|
||||
pblocktemplate->vTxFees.push_back(txfees);
|
||||
pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStream));
|
||||
nFees += txfees;
|
||||
pblocktemplate->vTxFees[0] = -nFees;
|
||||
//*(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees;
|
||||
//fprintf(stderr,"added notaryvin\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"error adding streamer vin, the chain broke! \n");
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (ASSETCHAINS_SYMBOL[0] != 0 || IS_KOMODO_NOTARY == 0 || My_notaryid < 0) )
|
||||
{
|
||||
CValidationState state;
|
||||
@@ -536,7 +556,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
|
||||
return pblocktemplate.release();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
#ifdef ENABLE_WALLET
|
||||
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
|
||||
@@ -559,11 +579,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
return boost::optional<CScript>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
return scriptPubKey;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
|
||||
{
|
||||
@@ -573,7 +593,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
||||
{
|
||||
boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
|
||||
#endif
|
||||
|
||||
|
||||
if (!scriptPubKey) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -601,7 +621,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
|
||||
CMutableTransaction txCoinbase(pblock->vtx[0]);
|
||||
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
|
||||
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
|
||||
|
||||
|
||||
pblock->vtx[0] = txCoinbase;
|
||||
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
|
||||
}
|
||||
@@ -619,12 +639,18 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in
|
||||
{
|
||||
scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG;
|
||||
}
|
||||
else if ( ASSETCHAINS_STREAM != 0 )
|
||||
{
|
||||
if ( nHeight < 128 )
|
||||
scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG;
|
||||
else
|
||||
scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG;
|
||||
}
|
||||
else if ( USE_EXTERNAL_PUBKEY != 0 )
|
||||
{
|
||||
//fprintf(stderr,"use notary pubkey\n");
|
||||
scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
if (!reservekey.GetReservedKey(pubkey))
|
||||
{
|
||||
@@ -670,7 +696,7 @@ static bool ProcessBlockFound(CBlock* pblock)
|
||||
{
|
||||
LogPrintf("%s\n", pblock->ToString());
|
||||
LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.LastTip()->nHeight+1);
|
||||
|
||||
|
||||
// Found a solution
|
||||
{
|
||||
//LOCK(cs_main);
|
||||
@@ -685,11 +711,11 @@ static bool ProcessBlockFound(CBlock* pblock)
|
||||
for (i=31; i>=0; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
|
||||
fprintf(stderr," <- chainTip (stale)\n");
|
||||
|
||||
|
||||
return error("KomodoMiner: generated block is stale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
// Remove key from key pool
|
||||
if ( IS_KOMODO_NOTARY == 0 )
|
||||
@@ -713,7 +739,7 @@ static bool ProcessBlockFound(CBlock* pblock)
|
||||
CValidationState state;
|
||||
if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL))
|
||||
return error("KomodoMiner: ProcessNewBlock, block not accepted");
|
||||
|
||||
|
||||
TrackMinedBlock(pblock->GetHash());
|
||||
komodo_broadcast(pblock,16);
|
||||
return true;
|
||||
@@ -737,15 +763,15 @@ void static BitcoinMiner()
|
||||
SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
||||
RenameThread("komodo-miner");
|
||||
const CChainParams& chainparams = Params();
|
||||
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
// Each thread has its own key
|
||||
CReserveKey reservekey(pwallet);
|
||||
#endif
|
||||
|
||||
|
||||
// Each thread has its own counter
|
||||
unsigned int nExtraNonce = 0;
|
||||
|
||||
|
||||
unsigned int n = chainparams.EquihashN();
|
||||
unsigned int k = chainparams.EquihashK();
|
||||
uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1;
|
||||
@@ -776,7 +802,7 @@ void static BitcoinMiner()
|
||||
}
|
||||
);
|
||||
miningTimer.start();
|
||||
|
||||
|
||||
try {
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str());
|
||||
@@ -799,7 +825,7 @@ void static BitcoinMiner()
|
||||
break;
|
||||
MilliSleep(15000);
|
||||
//fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload());
|
||||
|
||||
|
||||
} while (true);
|
||||
//fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL);
|
||||
miningTimer.start();
|
||||
@@ -849,14 +875,19 @@ void static BitcoinMiner()
|
||||
{
|
||||
if ( ASSETCHAINS_REWARD == 0 )
|
||||
{
|
||||
if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||
int minvoutsize = 1;
|
||||
int minvtxsize = 1;
|
||||
if ( ASSETCHAINS_STREAM != 0 )
|
||||
minvoutsize = 2;
|
||||
minvtxsize = 2;
|
||||
if ( pblock->vtx.size() == minvtxsize && pblock->vtx[0].vout.size() == minvoutsize && Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||
{
|
||||
static uint32_t counter;
|
||||
if ( counter++ < 10 )
|
||||
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL);
|
||||
sleep(10);
|
||||
continue;
|
||||
} else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT);
|
||||
} else fprintf(stderr,"%s tx.%d vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx.size(),(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT);
|
||||
}
|
||||
}
|
||||
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
|
||||
@@ -935,13 +966,13 @@ void static BitcoinMiner()
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
if ( KOMODO_INSYNC == 0 )
|
||||
/*if ( KOMODO_INSYNC == 0 && Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||
{
|
||||
fprintf(stderr,"Mining when blockchain might not be in sync longest.%d vs %d\n",KOMODO_LONGESTCHAIN,Mining_height);
|
||||
if ( KOMODO_LONGESTCHAIN != 0 && Mining_height >= KOMODO_LONGESTCHAIN )
|
||||
KOMODO_INSYNC = 1;
|
||||
sleep(3);
|
||||
}
|
||||
} */
|
||||
// Hash state
|
||||
KOMODO_CHOSEN_ONE = 0;
|
||||
crypto_generichash_blake2b_state state;
|
||||
@@ -1063,13 +1094,13 @@ void static BitcoinMiner()
|
||||
std::lock_guard<std::mutex> lock{m_cs};
|
||||
return cancelSolver;
|
||||
};
|
||||
|
||||
|
||||
// TODO: factor this out into a function with the same API for each solver.
|
||||
if (solver == "tromp" ) { //&& notaryid >= 0 ) {
|
||||
// Create solver and initialize it.
|
||||
equi eq(1);
|
||||
eq.setstate(&curr_state);
|
||||
|
||||
|
||||
// Initialization done, start algo driver.
|
||||
eq.digit0(0);
|
||||
eq.xfull = eq.bfull = eq.hfull = 0;
|
||||
@@ -1081,7 +1112,7 @@ void static BitcoinMiner()
|
||||
}
|
||||
eq.digitK(0);
|
||||
ehSolverRuns.increment();
|
||||
|
||||
|
||||
// Convert solution indices to byte array (decompress) and pass it to validBlock method.
|
||||
for (size_t s = 0; s < eq.nsols; s++) {
|
||||
LogPrint("pow", "Checking solution %d\n", s+1);
|
||||
@@ -1090,7 +1121,7 @@ void static BitcoinMiner()
|
||||
index_vector[i] = eq.sols[s][i];
|
||||
}
|
||||
std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
|
||||
|
||||
|
||||
if (validBlock(sol_char)) {
|
||||
// If we find a POW solution, do not try other solutions
|
||||
// because they become invalid as we created a new block in blockchain.
|
||||
@@ -1117,7 +1148,7 @@ void static BitcoinMiner()
|
||||
cancelSolver = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check for stop or if block needs to be rebuilt
|
||||
boost::this_thread::interruption_point();
|
||||
// Regtest mode doesn't require peers
|
||||
@@ -1187,7 +1218,7 @@ void static BitcoinMiner()
|
||||
miningTimer.stop();
|
||||
c.disconnect();
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
|
||||
#else
|
||||
@@ -1195,10 +1226,10 @@ void static BitcoinMiner()
|
||||
#endif
|
||||
{
|
||||
static boost::thread_group* minerThreads = NULL;
|
||||
|
||||
|
||||
if (nThreads < 0)
|
||||
nThreads = GetNumCores();
|
||||
|
||||
|
||||
if (minerThreads != NULL)
|
||||
{
|
||||
minerThreads->interrupt_all();
|
||||
@@ -1210,7 +1241,7 @@ void static BitcoinMiner()
|
||||
nThreads = 1;
|
||||
if (nThreads == 0 || !fGenerate)
|
||||
return;
|
||||
|
||||
|
||||
minerThreads = new boost::thread_group();
|
||||
for (int i = 0; i < nThreads; i++) {
|
||||
#ifdef ENABLE_WALLET
|
||||
@@ -1220,5 +1251,5 @@ void static BitcoinMiner()
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // ENABLE_MINING
|
||||
|
||||
158
src/notaries_staked.cpp
Normal file
158
src/notaries_staked.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
|
||||
#include "notaries_staked.h"
|
||||
#include "crosschain.h"
|
||||
#include <cstring>
|
||||
|
||||
// Era 1 set of pubkeys
|
||||
const char *notaries_STAKED1[][2] =
|
||||
{
|
||||
{"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x
|
||||
{"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg
|
||||
{"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8
|
||||
{"CrisF", "03f87f1bccb744d90fdbf7fad1515a98e9fc7feb1800e460d2e7565b88c3971bf3" }, //RMwEpnaVe3cesWbMqqKYPPkaLcDkooTDgZ
|
||||
{"smk762", "02eacef682d2f86e0103c18f4da46116e17196f3fb8f73ed931acb78e81d8e1aa5" }, // RQVvzJ8gepCDVjhqCAc5Tia1kTmt8KDPL9
|
||||
{"jorian", "02150c410a606b898bcab4f083e48e0f98a510e0d48d4db367d37f318d26ae72e3" }, // RFgzxZe2P4RWKx6E9QGPK3rx3TXeWxSqa8
|
||||
{"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev
|
||||
{"Emman", "038f642dcdacbdf510b7869d74544dbc6792548d9d1f8d73a999dd9f45f513c935" }, //RN2KsQGW36Ah4NorJDxLJp2xiYJJEzk9Y6
|
||||
{"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL
|
||||
{"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2
|
||||
{"jusoaresf", "02dfb7ed72a23f6d07f0ea2f28192ee174733cc8412ec0f97b073007b78fab6346" }, // RBQGfE5Hxsjm1BPraTxbneRuNasPDuoLnu
|
||||
{"mylo", "03f6b7fcaf0b8b8ec432d0de839a76598b78418dadd50c8e5594c0e557d914ec09" }, // RXN4hoZkhUkkrnef9nTUDw3E3vVALAD8Kx
|
||||
{"blackjok3r2", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e" }, // RWHGbrLSP89fTzNVF9U9xiekDYJqcibTca
|
||||
{"blackjok3r3", "03c3e4c0206551dbf3a4b24d18e5d2737080541184211e3bfd2b1092177410b9c2" }, // RMMav2AVse5XHPvDfTzRpMbFhK3GqFmtSN
|
||||
{"kmdkrazy", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e" }, // RWHGbrLSP89fTzNVF9U9xiekDYJqcibTca
|
||||
{"alrighttest", "02e9dfe248f453b499315a90375e58a1c9ad79f5f3932ecb2205399a0f262d65fc" }, // RBevSstS8JtDXMEFNcJws4QTYN4PcE2VL5
|
||||
{"alrighttest1", "03527c7ecd6a8c5db6d685a64e6e18c1edb49e2f057a434f56c3f1253a26e9c6a2" }, // RBw2jNU3dnGk86ZLqPMadJwRwg3NU8eC6s
|
||||
};
|
||||
|
||||
int num_notaries_STAKED1 = (sizeof(notaries_STAKED1)/sizeof(*notaries_STAKED1));
|
||||
|
||||
// Era 2 set of pubkeys
|
||||
const char *notaries_STAKED2[][2] =
|
||||
{
|
||||
{"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x
|
||||
{"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg
|
||||
{"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8
|
||||
{"CrisF", "03f87f1bccb744d90fdbf7fad1515a98e9fc7feb1800e460d2e7565b88c3971bf3" }, //RMwEpnaVe3cesWbMqqKYPPkaLcDkooTDgZ
|
||||
{"smk762", "02eacef682d2f86e0103c18f4da46116e17196f3fb8f73ed931acb78e81d8e1aa5" }, // RQVvzJ8gepCDVjhqCAc5Tia1kTmt8KDPL9
|
||||
{"jorian", "02150c410a606b898bcab4f083e48e0f98a510e0d48d4db367d37f318d26ae72e3" }, // RFgzxZe2P4RWKx6E9QGPK3rx3TXeWxSqa8
|
||||
{"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev
|
||||
{"Emman", "038f642dcdacbdf510b7869d74544dbc6792548d9d1f8d73a999dd9f45f513c935" }, //RN2KsQGW36Ah4NorJDxLJp2xiYJJEzk9Y6
|
||||
{"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL
|
||||
{"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2
|
||||
{"jusoaresf", "02dfb7ed72a23f6d07f0ea2f28192ee174733cc8412ec0f97b073007b78fab6346" }, // RBQGfE5Hxsjm1BPraTxbneRuNasPDuoLnu
|
||||
{"mylo", "03f6b7fcaf0b8b8ec432d0de839a76598b78418dadd50c8e5594c0e557d914ec09" }, // RXN4hoZkhUkkrnef9nTUDw3E3vVALAD8Kx
|
||||
{"blackjok3r2", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e" }, // RWHGbrLSP89fTzNVF9U9xiekDYJqcibTca
|
||||
{"blackjok3r3", "03c3e4c0206551dbf3a4b24d18e5d2737080541184211e3bfd2b1092177410b9c2" }, // RMMav2AVse5XHPvDfTzRpMbFhK3GqFmtSN
|
||||
{"kmdkrazy", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e" }, // RWHGbrLSP89fTzNVF9U9xiekDYJqcibTca
|
||||
{"alrighttest", "02e9dfe248f453b499315a90375e58a1c9ad79f5f3932ecb2205399a0f262d65fc" }, // RBevSstS8JtDXMEFNcJws4QTYN4PcE2VL5
|
||||
{"alrighttest1", "03527c7ecd6a8c5db6d685a64e6e18c1edb49e2f057a434f56c3f1253a26e9c6a2" }, // RBw2jNU3dnGk86ZLqPMadJwRwg3NU8eC6s
|
||||
};
|
||||
|
||||
int num_notaries_STAKED2 = (sizeof(notaries_STAKED2)/sizeof(*notaries_STAKED2));
|
||||
|
||||
// Era 3 set of pubkeys
|
||||
const char *notaries_STAKED3[][2] =
|
||||
{
|
||||
{"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x
|
||||
{"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg
|
||||
{"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8
|
||||
{"CrisF", "03f87f1bccb744d90fdbf7fad1515a98e9fc7feb1800e460d2e7565b88c3971bf3" }, //RMwEpnaVe3cesWbMqqKYPPkaLcDkooTDgZ
|
||||
{"smk762", "02eacef682d2f86e0103c18f4da46116e17196f3fb8f73ed931acb78e81d8e1aa5" }, // RQVvzJ8gepCDVjhqCAc5Tia1kTmt8KDPL9
|
||||
{"jorian", "02150c410a606b898bcab4f083e48e0f98a510e0d48d4db367d37f318d26ae72e3" }, // RFgzxZe2P4RWKx6E9QGPK3rx3TXeWxSqa8
|
||||
{"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev
|
||||
{"Emman", "038f642dcdacbdf510b7869d74544dbc6792548d9d1f8d73a999dd9f45f513c935" }, //RN2KsQGW36Ah4NorJDxLJp2xiYJJEzk9Y6
|
||||
{"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL
|
||||
{"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2
|
||||
{"jusoaresf", "02dfb7ed72a23f6d07f0ea2f28192ee174733cc8412ec0f97b073007b78fab6346" }, // RBQGfE5Hxsjm1BPraTxbneRuNasPDuoLnu
|
||||
{"mylo", "03f6b7fcaf0b8b8ec432d0de839a76598b78418dadd50c8e5594c0e557d914ec09" }, // RXN4hoZkhUkkrnef9nTUDw3E3vVALAD8Kx
|
||||
{"blackjok3r2", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e" }, // RWHGbrLSP89fTzNVF9U9xiekDYJqcibTca
|
||||
{"blackjok3r3", "03c3e4c0206551dbf3a4b24d18e5d2737080541184211e3bfd2b1092177410b9c2" }, // RMMav2AVse5XHPvDfTzRpMbFhK3GqFmtSN
|
||||
{"kmdkrazy", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e" }, // RWHGbrLSP89fTzNVF9U9xiekDYJqcibTca
|
||||
{"alrighttest", "02e9dfe248f453b499315a90375e58a1c9ad79f5f3932ecb2205399a0f262d65fc" }, // RBevSstS8JtDXMEFNcJws4QTYN4PcE2VL5
|
||||
{"alrighttest1", "03527c7ecd6a8c5db6d685a64e6e18c1edb49e2f057a434f56c3f1253a26e9c6a2" }, // RBw2jNU3dnGk86ZLqPMadJwRwg3NU8eC6s
|
||||
};
|
||||
|
||||
int num_notaries_STAKED3 = (sizeof(notaries_STAKED3)/sizeof(*notaries_STAKED3));
|
||||
|
||||
// Era 4 set of pubkeys
|
||||
const char *notaries_STAKED4[][2] =
|
||||
{
|
||||
{"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x
|
||||
{"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg
|
||||
{"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8
|
||||
{"CrisF", "03f87f1bccb744d90fdbf7fad1515a98e9fc7feb1800e460d2e7565b88c3971bf3" }, //RMwEpnaVe3cesWbMqqKYPPkaLcDkooTDgZ
|
||||
{"smk762", "02eacef682d2f86e0103c18f4da46116e17196f3fb8f73ed931acb78e81d8e1aa5" }, // RQVvzJ8gepCDVjhqCAc5Tia1kTmt8KDPL9
|
||||
{"jorian", "02150c410a606b898bcab4f083e48e0f98a510e0d48d4db367d37f318d26ae72e3" }, // RFgzxZe2P4RWKx6E9QGPK3rx3TXeWxSqa8
|
||||
{"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev
|
||||
{"Emman", "038f642dcdacbdf510b7869d74544dbc6792548d9d1f8d73a999dd9f45f513c935" }, //RN2KsQGW36Ah4NorJDxLJp2xiYJJEzk9Y6
|
||||
{"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL
|
||||
{"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2
|
||||
{"jusoaresf", "02dfb7ed72a23f6d07f0ea2f28192ee174733cc8412ec0f97b073007b78fab6346" }, // RBQGfE5Hxsjm1BPraTxbneRuNasPDuoLnu
|
||||
{"mylo", "03f6b7fcaf0b8b8ec432d0de839a76598b78418dadd50c8e5594c0e557d914ec09" }, // RXN4hoZkhUkkrnef9nTUDw3E3vVALAD8Kx
|
||||
{"blackjok3r2", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e" }, // RWHGbrLSP89fTzNVF9U9xiekDYJqcibTca
|
||||
{"blackjok3r3", "03c3e4c0206551dbf3a4b24d18e5d2737080541184211e3bfd2b1092177410b9c2" }, // RMMav2AVse5XHPvDfTzRpMbFhK3GqFmtSN
|
||||
{"kmdkrazy", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e" }, // RWHGbrLSP89fTzNVF9U9xiekDYJqcibTca
|
||||
{"alrighttest", "02e9dfe248f453b499315a90375e58a1c9ad79f5f3932ecb2205399a0f262d65fc" }, // RBevSstS8JtDXMEFNcJws4QTYN4PcE2VL5
|
||||
{"alrighttest1", "03527c7ecd6a8c5db6d685a64e6e18c1edb49e2f057a434f56c3f1253a26e9c6a2" }, // RBw2jNU3dnGk86ZLqPMadJwRwg3NU8eC6s
|
||||
};
|
||||
|
||||
int num_notaries_STAKED4 = (sizeof(notaries_STAKED4)/sizeof(*notaries_STAKED4));
|
||||
|
||||
int is_STAKED(const char *chain_name) {
|
||||
int STAKED = 0;
|
||||
if ( (strcmp(chain_name, "STAKED") == 0) || (strncmp(chain_name, "STAKED", 6) == 0) )
|
||||
STAKED = 1;
|
||||
else if ( (strcmp(chain_name, "STKD") == 0) || (strncmp(chain_name, "STKD", 4) == 0) )
|
||||
STAKED = 2;
|
||||
else if ( (strcmp(chain_name, "CFEK") == 0) || (strncmp(chain_name, "CFEK", 4) == 0) )
|
||||
STAKED = 3;
|
||||
//fprintf(stderr, "This chains is: %s which is: %d\n", chain_name,STAKED);
|
||||
return(STAKED);
|
||||
};
|
||||
|
||||
int STAKED_era(int timestamp)
|
||||
{
|
||||
int era;
|
||||
if (timestamp <= STAKED_NOTARIES_TIMESTAMP1)
|
||||
era = 1;
|
||||
else if (timestamp <= STAKED_NOTARIES_TIMESTAMP2 && timestamp >= (STAKED_NOTARIES_TIMESTAMP1 + STAKED_ERA_GAP))
|
||||
era = 2;
|
||||
else if (timestamp <= STAKED_NOTARIES_TIMESTAMP3 && timestamp >= (STAKED_NOTARIES_TIMESTAMP2 + STAKED_ERA_GAP))
|
||||
era = 3;
|
||||
else if (timestamp <= STAKED_NOTARIES_TIMESTAMP4 && timestamp >= (STAKED_NOTARIES_TIMESTAMP3 + STAKED_ERA_GAP))
|
||||
era = 4;
|
||||
else
|
||||
era = 0;
|
||||
// if we are in a gap, return era 0, this allows to invalidate notarizations when in GAP.
|
||||
return(era);
|
||||
};
|
||||
|
||||
CrosschainAuthority Choose_auth_STAKED(int chosen_era) {
|
||||
CrosschainAuthority auth;
|
||||
switch (chosen_era) {
|
||||
case 1:
|
||||
auth = auth_STAKED_chosen(notaries_STAKED1,num_notaries_STAKED1);
|
||||
break;
|
||||
case 2:
|
||||
auth = auth_STAKED_chosen(notaries_STAKED2,num_notaries_STAKED2);
|
||||
break;
|
||||
case 3:
|
||||
auth = auth_STAKED_chosen(notaries_STAKED3,num_notaries_STAKED3);
|
||||
break;
|
||||
case 4:
|
||||
auth = auth_STAKED_chosen(notaries_STAKED4,num_notaries_STAKED4);
|
||||
break;
|
||||
}
|
||||
return(auth);
|
||||
};
|
||||
|
||||
CrosschainAuthority auth_STAKED_chosen(const char *notaries_chosen[][2],int num_notaries) {
|
||||
CrosschainAuthority auth;
|
||||
auth.requiredSigs = (num_notaries / 5);
|
||||
auth.size = num_notaries;
|
||||
for (int n=0; n<auth.size; n++)
|
||||
for (size_t i=0; i<33; i++)
|
||||
sscanf(notaries_chosen[n][1]+(i*2), "%2hhx", auth.notaries[n]+i);
|
||||
return auth;
|
||||
};
|
||||
32
src/notaries_staked.h
Normal file
32
src/notaries_staked.h
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
#ifndef NOTARIES_STAKED
|
||||
#define NOTARIES_STAKED
|
||||
|
||||
#include "crosschain.h"
|
||||
|
||||
static const int STAKED_ERA_GAP = 777;
|
||||
|
||||
static const int STAKED_NOTARIES_TIMESTAMP1 = 1604212834;
|
||||
static const int STAKED_NOTARIES_TIMESTAMP2 = 1604222222;
|
||||
static const int STAKED_NOTARIES_TIMESTAMP3 = 1604233333;
|
||||
static const int STAKED_NOTARIES_TIMESTAMP4 = 1604244444;
|
||||
|
||||
extern const char *notaries_STAKED1[][2];
|
||||
extern int num_notaries_STAKED1;
|
||||
|
||||
extern const char *notaries_STAKED2[][2];
|
||||
extern int num_notaries_STAKED2;
|
||||
|
||||
extern const char *notaries_STAKED3[][2];
|
||||
extern int num_notaries_STAKED3;
|
||||
|
||||
extern const char *notaries_STAKED4[][2];
|
||||
extern int num_notaries_STAKED4;
|
||||
|
||||
int is_STAKED(const char *chain_name);
|
||||
int STAKED_era(int timestamp);
|
||||
|
||||
CrosschainAuthority Choose_auth_STAKED(int chosen_era);
|
||||
CrosschainAuthority auth_STAKED_chosen(const char *notaries_chosen[][2],int num_notaries);
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,9 @@
|
||||
#include "notarisationdb.h"
|
||||
#include "uint256.h"
|
||||
#include "cc/eval.h"
|
||||
#include "crosschain.h"
|
||||
#include "main.h"
|
||||
#include "notaries_staked.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
@@ -17,31 +19,51 @@ NotarisationsInBlock ScanBlockNotarisations(const CBlock &block, int nHeight)
|
||||
{
|
||||
EvalRef eval;
|
||||
NotarisationsInBlock vNotarisations;
|
||||
CrosschainAuthority auth_STAKED;
|
||||
int timestamp = block.nTime;
|
||||
|
||||
for (unsigned int i = 0; i < block.vtx.size(); i++) {
|
||||
CTransaction tx = block.vtx[i];
|
||||
|
||||
// Special case for TXSCL. Should prob be removed at some point.
|
||||
bool isTxscl = 0;
|
||||
{
|
||||
NotarisationData data;
|
||||
if (ParseNotarisationOpReturn(tx, data))
|
||||
if (IsTXSCL(data.symbol))
|
||||
isTxscl = 1;
|
||||
NotarisationData data;
|
||||
bool parsed = ParseNotarisationOpReturn(tx, data);
|
||||
if (!parsed) data = NotarisationData();
|
||||
if (strlen(data.symbol) == 0)
|
||||
continue;
|
||||
|
||||
//printf("Checked notarisation data for %s \n",data.symbol);
|
||||
int authority = GetSymbolAuthority(data.symbol);
|
||||
|
||||
if (authority == CROSSCHAIN_KOMODO) {
|
||||
if (!eval->CheckNotaryInputs(tx, nHeight, block.nTime))
|
||||
continue;
|
||||
//printf("Authorised notarisation data for %s \n",data.symbol);
|
||||
} else if (authority == CROSSCHAIN_STAKED) {
|
||||
// We need to create auth_STAKED dynamically here based on timestamp
|
||||
int staked_era = STAKED_era(timestamp);
|
||||
printf("ERA.(%d) \n",staked_era);
|
||||
if (staked_era == 0) {
|
||||
// this is an ERA GAP, so we will ignore this notarization
|
||||
printf("Notarization for %s occured inside an ERA GAP, we will ignore it! \n",data.symbol);
|
||||
continue;
|
||||
} else {
|
||||
// pass era slection off to notaries_staked.cpp file
|
||||
auth_STAKED = Choose_auth_STAKED(staked_era);
|
||||
}
|
||||
if (!CheckTxAuthority(tx, auth_STAKED))
|
||||
continue;
|
||||
printf("Authorised notarisation data for %s \n",data.symbol);
|
||||
}
|
||||
|
||||
if (isTxscl || eval->CheckNotaryInputs(tx, nHeight, block.nTime)) {
|
||||
NotarisationData data;
|
||||
if (ParseNotarisationOpReturn(tx, data)) {
|
||||
vNotarisations.push_back(std::make_pair(tx.GetHash(), data));
|
||||
//printf("Parsed a notarisation for: %s, txid:%s, ccid:%i, momdepth:%i\n",
|
||||
// data.symbol, tx.GetHash().GetHex().data(), data.ccId, data.MoMDepth);
|
||||
//if (!data.MoMoM.IsNull()) printf("MoMoM:%s\n", data.MoMoM.GetHex().data());
|
||||
}
|
||||
else
|
||||
LogPrintf("WARNING: Couldn't parse notarisation for tx: %s at height %i\n",
|
||||
tx.GetHash().GetHex().data(), nHeight);
|
||||
}
|
||||
if (parsed) {
|
||||
vNotarisations.push_back(std::make_pair(tx.GetHash(), data));
|
||||
printf("Added notarisation data for %s \n",data.symbol);
|
||||
//printf("Parsed a notarisation for: %s, txid:%s, ccid:%i, momdepth:%i\n",
|
||||
// data.symbol, tx.GetHash().GetHex().data(), data.ccId, data.MoMDepth);
|
||||
//if (!data.MoMoM.IsNull()) printf("MoMoM:%s\n", data.MoMoM.GetHex().data());
|
||||
} else
|
||||
LogPrintf("WARNING: Couldn't parse notarisation for tx: %s at height %i\n",
|
||||
tx.GetHash().GetHex().data(), nHeight);
|
||||
}
|
||||
return vNotarisations;
|
||||
}
|
||||
|
||||
48
src/pow.cpp
48
src/pow.cpp
@@ -20,31 +20,39 @@
|
||||
#include "librustzcash.h"
|
||||
#endif // ENABLE_RUST
|
||||
uint32_t komodo_chainactive_timestamp();
|
||||
extern int32_t ASSETCHAINS_STREAM;
|
||||
|
||||
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
|
||||
{
|
||||
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
|
||||
// Genesis block
|
||||
if (pindexLast == NULL )
|
||||
return nProofOfWorkLimit;
|
||||
if ( ASSETCHAINS_STREAM == 0)
|
||||
{
|
||||
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
|
||||
// Genesis block
|
||||
if (pindexLast == NULL )
|
||||
return nProofOfWorkLimit;
|
||||
|
||||
// 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;
|
||||
bnTmp.SetCompact(pindexFirst->nBits);
|
||||
bnTot += bnTmp;
|
||||
pindexFirst = pindexFirst->pprev;
|
||||
// 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;
|
||||
bnTmp.SetCompact(pindexFirst->nBits);
|
||||
bnTot += bnTmp;
|
||||
pindexFirst = pindexFirst->pprev;
|
||||
}
|
||||
|
||||
// Check we have enough blocks
|
||||
if (pindexFirst == NULL)
|
||||
return nProofOfWorkLimit;
|
||||
|
||||
arith_uint256 bnAvg {bnTot / params.nPowAveragingWindow};
|
||||
|
||||
return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 537857807;
|
||||
}
|
||||
|
||||
// Check we have enough blocks
|
||||
if (pindexFirst == NULL)
|
||||
return nProofOfWorkLimit;
|
||||
|
||||
arith_uint256 bnAvg {bnTot / params.nPowAveragingWindow};
|
||||
|
||||
return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
||||
}
|
||||
|
||||
unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
|
||||
|
||||
@@ -260,6 +260,218 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned char hexval(unsigned char c)
|
||||
{
|
||||
if ('0' <= c && c <= '9')
|
||||
return c - '0';
|
||||
else if ('a' <= c && c <= 'f')
|
||||
return c - 'a' + 10;
|
||||
else if ('A' <= c && c <= 'F')
|
||||
return c - 'A' + 10;
|
||||
else abort();
|
||||
}
|
||||
|
||||
void hex2ascii(const string& in, string& out)
|
||||
{
|
||||
out.clear();
|
||||
out.reserve(in.length() / 2);
|
||||
for (string::const_iterator p = in.begin(); p != in.end(); p++)
|
||||
{
|
||||
unsigned char c = hexval(*p);
|
||||
p++;
|
||||
if (p == in.end()) break; // incomplete last digit - should report error
|
||||
c = (c << 4) + hexval(*p); // + takes precedence over <<
|
||||
out.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
UniValue getdatafromblock(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"getdatafromblock \"hash|height\" true/false\n"
|
||||
"\nReturns all the data sent via streamer in block if there was any data in it.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"hash|height\" (string, required) The block hash or height\n"
|
||||
"2. \"true/false\" (bool, optional) if false do not return the actual data. Default true.\n"
|
||||
"\nResult (for verbose = true):\n"
|
||||
"{\n"
|
||||
" \"streamid\" : \"string\", (string) the name of the stream.\n"
|
||||
" \"firsttxid\" : \"hash\", (string) the first transaction of the stream.\n"
|
||||
" \"firstblockheight\" : \"n\", (numeric) the block the stream starts in.\n"
|
||||
" \"firstdeqid\" : n, (numeric) The sequence id of the first data chunk in this block\n"
|
||||
" \"lastseqid\" : n, (numeric) The sequence id of the last data chunk in this block\n"
|
||||
" \"data\" : \"xxxx\", (string) A hex string containing all the data chunks in this block.\n"
|
||||
"}\n"
|
||||
"\nResult (for verbose=false):\n"
|
||||
" \"streamid\" : \"string\", (string) the name of the stream.\n"
|
||||
" \"firsttxid\" : \"hash\", (string) the first transaction of the stream.\n"
|
||||
" \"firstblockheight\" : \"n\", (numeric) the block the stream starts in.\n"
|
||||
" \"firstdeqid\" : n, (numeric) The sequence id of the first data chunk in this block\n"
|
||||
" \"lastseqid\" : n, (numeric) The sequence id of the last data chunk in this block\n"
|
||||
+ HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09 false\"")
|
||||
+ HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
|
||||
+ HelpExampleCli("getblock", "12800")
|
||||
+ HelpExampleRpc("getblock", "12800 false")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
std::string strHash = params[0].get_str();
|
||||
bool fVerbose = true;
|
||||
if (params.size() > 1) {
|
||||
std::string verboseflag = params[1].get_str();
|
||||
if ( verboseflag == "false" )
|
||||
fVerbose = false;
|
||||
}
|
||||
|
||||
// If height is supplied, find the hash
|
||||
if (strHash.size() < (2 * sizeof(uint256))) {
|
||||
// std::stoi allows characters, whereas we want to be strict
|
||||
regex r("[[:digit:]]+");
|
||||
if (!regex_match(strHash, r)) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter");
|
||||
}
|
||||
|
||||
int nHeight = -1;
|
||||
try {
|
||||
nHeight = std::stoi(strHash);
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter");
|
||||
}
|
||||
|
||||
if (nHeight < 0 || nHeight > chainActive.Height()) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
|
||||
}
|
||||
strHash = chainActive[nHeight]->GetBlockHash().GetHex();
|
||||
}
|
||||
|
||||
uint256 hash(uint256S(strHash));
|
||||
|
||||
if (mapBlockIndex.count(hash) == 0)
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||
|
||||
CBlock block;
|
||||
CBlockIndex* pblockindex = mapBlockIndex[hash];
|
||||
|
||||
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
|
||||
|
||||
if(!ReadBlockFromDisk(block, pblockindex,1))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
|
||||
|
||||
UniValue result(UniValue::VOBJ);
|
||||
int firstseqid = 0;
|
||||
int lastseqid = 0;
|
||||
int i = 0;
|
||||
int did1 = 0;
|
||||
int skippedtxs = 0;
|
||||
int failed = 0;
|
||||
int getfirstblock = 0;
|
||||
static std::string streamid,firsttxid;
|
||||
static int firsttxnHeight;
|
||||
std::string blockdata;
|
||||
fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size());
|
||||
// Iif block tx size is > 2 then we can do this
|
||||
if ( block.vtx.size() > 2 )
|
||||
{
|
||||
BOOST_FOREACH(const CTransaction&tx, block.vtx)
|
||||
{
|
||||
// ignore first and last TX and any TX that does not have 3 vouts.
|
||||
if ( (i == 0) || (i == (block.vtx.size() -1)) || (tx.vout.size() != 3) )
|
||||
{
|
||||
fprintf(stderr, "skipped tx number: %d\n",i);
|
||||
skippedtxs = skippedtxs + 1;
|
||||
} else {
|
||||
std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end());
|
||||
// scriptPubKey is longer than 81, should mean its an OP_RETURN, maybe also check vout == 0 ?
|
||||
if ( opretstr.size() > 81 ) {
|
||||
std::string idstr = opretstr.substr (8,64); // stream ID or txid
|
||||
std::string seqidstr = opretstr.substr (72,8); // sequence ID
|
||||
std::string data = opretstr.substr (80); // data chunk
|
||||
unsigned int seqid;
|
||||
std::stringstream ss;
|
||||
ss << std::hex << seqidstr;
|
||||
ss >> seqid;
|
||||
if ( seqid == 1 ) {
|
||||
streamid = idstr;
|
||||
getfirstblock = 1;
|
||||
} else if ( seqid == 2 ) {
|
||||
firsttxid = idstr;
|
||||
} else if (firsttxid.empty()) {
|
||||
firsttxid.append(idstr);
|
||||
} else if ( firsttxid != idstr ) {
|
||||
printf("firsttxid.%s idstr.%s change firsttxid and wipe streamid?\n",firsttxid.c_str(),idstr.c_str());
|
||||
firsttxid.clear();
|
||||
firsttxid.append(idstr);
|
||||
streamid.clear();
|
||||
firsttxnHeight = 0;
|
||||
}
|
||||
if ( seqid == (lastseqid + 1) || did1 == 0 ) {
|
||||
blockdata.append(data);
|
||||
} else {
|
||||
result.push_back(Pair("error","chunck out of order or missing in this block!"));
|
||||
result.push_back(Pair("lastvalidseqid", (int)lastseqid));
|
||||
break;
|
||||
}
|
||||
if ( did1 == 0 ) {
|
||||
firstseqid = seqid;
|
||||
did1 = 1;
|
||||
}
|
||||
lastseqid = seqid;
|
||||
} else {
|
||||
skippedtxs = skippedtxs + 1;
|
||||
fprintf(stderr, "skipped tx number: %d\n",i);
|
||||
}
|
||||
// function here to extract seqid from first and last TX
|
||||
// we an push the data or not depending on input from RPC.
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
if (streamid.empty() || getfirstblock == 1) {
|
||||
if ( lastseqid == 1) {
|
||||
firsttxid = block.vtx[1].GetHash().GetHex();
|
||||
}
|
||||
uint256 hash; CTransaction firsttx;
|
||||
uint256 firsttxid_256(uint256S(firsttxid));
|
||||
if (GetTransaction(firsttxid_256,firsttx,hash,false)) {
|
||||
if ( streamid.empty() ) {
|
||||
std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end());
|
||||
streamid.append(firststreamid.substr (8,64));
|
||||
}
|
||||
printf("first stream id changed to: %s\n", streamid.c_str());
|
||||
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
||||
if (mi != mapBlockIndex.end() && (*mi).second) {
|
||||
CBlockIndex* pindex = (*mi).second;
|
||||
printf("found block height: %d\n",pindex->nHeight);
|
||||
if (chainActive.Contains(pindex)) {
|
||||
firsttxnHeight = pindex->nHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
failed = 1;
|
||||
}
|
||||
|
||||
if ( failed == 1 || skippedtxs == i ) {
|
||||
result.push_back(Pair("error","there is no data in this block."));
|
||||
} else {
|
||||
std::string decodedstreamid;
|
||||
hex2ascii(streamid, decodedstreamid);
|
||||
result.push_back(Pair("streamid", decodedstreamid.c_str()));
|
||||
result.push_back(Pair("firsttxid", firsttxid));
|
||||
result.push_back(Pair("firstblockheight", (int)firsttxnHeight));
|
||||
result.push_back(Pair("firstseqid", (int)firstseqid));
|
||||
result.push_back(Pair("lastseqid", (int)lastseqid));
|
||||
if (fVerbose == true) {
|
||||
result.push_back(Pair("data", blockdata));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
@@ -820,7 +1032,7 @@ UniValue kvsearch(const UniValue& params, bool fHelp)
|
||||
" \"currentheight\": xxxxx, (numeric) current height of the chain\n"
|
||||
" \"key\": \"xxxxx\", (string) key\n"
|
||||
" \"keylen\": xxxxx, (string) length of the key \n"
|
||||
" \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n"
|
||||
" \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n"
|
||||
" \"height\": xxxxx, (numeric) height the key was stored at\n"
|
||||
" \"expiration\": xxxxx, (numeric) height the key will expire\n"
|
||||
" \"flags\": x (numeric) 1 if the key was created with a password; 0 otherwise.\n"
|
||||
@@ -1261,6 +1473,7 @@ void NetworkUpgradeDescPushBack(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
@@ -1278,6 +1491,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"
|
||||
@@ -1327,6 +1541,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("verificationprogress", progress));
|
||||
obj.push_back(Pair("chainwork", chainActive.LastTip()->nChainWork.GetHex()));
|
||||
obj.push_back(Pair("pruned", fPruneMode));
|
||||
obj.push_back(Pair("size_on_disk", CalculateCurrentUsage()));
|
||||
|
||||
ZCIncrementalMerkleTree tree;
|
||||
pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), tree);
|
||||
|
||||
@@ -50,7 +50,7 @@ UniValue assetchainproof(const UniValue& params, bool fHelp)
|
||||
|
||||
UniValue crosschainproof(const UniValue& params, bool fHelp)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ UniValue height_MoM(const UniValue& params, bool fHelp)
|
||||
ret.push_back(Pair("kmdendi",kmdendi));
|
||||
}
|
||||
} else ret.push_back(Pair("error",(char *)"no MoM for height"));
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -169,6 +169,9 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp)
|
||||
if (targetSymbol.size() == 0 || targetSymbol.size() > 32)
|
||||
throw runtime_error("targetSymbol length must be >0 and <=32");
|
||||
|
||||
if (strcmp(ASSETCHAINS_SYMBOL,targetSymbol.c_str()) == 0)
|
||||
throw runtime_error("cant send a coin to the same chain");
|
||||
|
||||
CAmount burnAmount = AmountFromValue(params[2]);
|
||||
if (burnAmount <= 0)
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for export");
|
||||
@@ -220,8 +223,8 @@ UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp)
|
||||
CTransaction burnTx;
|
||||
if (!E_UNMARSHAL(txData, ss >> burnTx))
|
||||
throw runtime_error("Couldn't parse burnTx");
|
||||
|
||||
|
||||
|
||||
|
||||
vector<CTxOut> payouts;
|
||||
if (!E_UNMARSHAL(ParseHexV(params[1], "argument 2"), ss >> payouts))
|
||||
throw runtime_error("Couldn't parse payouts");
|
||||
@@ -240,7 +243,7 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp)
|
||||
throw runtime_error("migrate_completeimporttransaction importTx\n\n"
|
||||
"Takes a cross chain import tx with proof generated on assetchain "
|
||||
"and extends proof to target chain proof root");
|
||||
|
||||
|
||||
if (ASSETCHAINS_SYMBOL[0] != 0)
|
||||
throw runtime_error("Must be called on KMD");
|
||||
|
||||
@@ -294,7 +297,7 @@ UniValue scanNotarisationsDB(const UniValue& params, bool fHelp)
|
||||
if (height == 0) {
|
||||
height = chainActive.Height();
|
||||
}
|
||||
|
||||
|
||||
Notarisation nota;
|
||||
int matchedHeight = ScanNotarisationsDB(height, symbol, limit, nota);
|
||||
if (!matchedHeight) return NullUniValue;
|
||||
|
||||
@@ -65,6 +65,7 @@ extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[];
|
||||
UniValue getinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height;
|
||||
extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[];
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"getinfo\n"
|
||||
|
||||
@@ -285,6 +285,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "blockchain", "getbestblockhash", &getbestblockhash, true },
|
||||
{ "blockchain", "getblockcount", &getblockcount, true },
|
||||
{ "blockchain", "getblock", &getblock, true },
|
||||
{ "blockchain", "getdatafromblock", &getdatafromblock, true },
|
||||
{ "blockchain", "getblockdeltas", &getblockdeltas, false },
|
||||
{ "blockchain", "getblockhashes", &getblockhashes, true },
|
||||
{ "blockchain", "getblockhash", &getblockhash, true },
|
||||
|
||||
@@ -364,6 +364,7 @@ extern UniValue getblockdeltas(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblockhash(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblockheader(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblock(const UniValue& params, bool fHelp);
|
||||
extern UniValue getdatafromblock(const UniValue& params, bool fHelp);
|
||||
extern UniValue gettxoutsetinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue gettxout(const UniValue& params, bool fHelp);
|
||||
extern UniValue verifychain(const UniValue& params, bool fHelp);
|
||||
|
||||
@@ -1,213 +0,0 @@
|
||||
#include <zmq.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <cryptoconditions.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "cc/eval.h"
|
||||
#include "importcoin.h"
|
||||
#include "base58.h"
|
||||
#include "core_io.h"
|
||||
#include "crosschain.h"
|
||||
#include "key.h"
|
||||
#include "komodo_structs.h"
|
||||
#include "main.h"
|
||||
#include "notarisationdb.h"
|
||||
#include "primitives/block.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "script/cc.h"
|
||||
#include "script/interpreter.h"
|
||||
#include "script/serverchecker.h"
|
||||
#include "txmempool.h"
|
||||
#include "crosschain.h"
|
||||
|
||||
#include "testutils.h"
|
||||
|
||||
|
||||
extern uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth);
|
||||
extern bool KOMODO_TEST_ASSETCHAIN_SKIP_POW;
|
||||
|
||||
|
||||
/*
|
||||
* Tests for the whole process of creating and validating notary proofs
|
||||
* using proof roots (MoMoMs). This is to support coin imports.
|
||||
*/
|
||||
|
||||
namespace TestCrossChainProof {
|
||||
|
||||
|
||||
class TestCrossChain : public ::testing::Test, public Eval {
|
||||
public:
|
||||
bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const
|
||||
{
|
||||
NotarisationData data(2);
|
||||
return ParseNotarisationOpReturn(tx, data); // If it parses it's valid
|
||||
}
|
||||
protected:
|
||||
static void SetUpTestCase() { }
|
||||
virtual void SetUp() {
|
||||
KOMODO_TEST_ASSETCHAIN_SKIP_POW = 1;
|
||||
ASSETCHAINS_CC = 1;
|
||||
EVAL_TEST = this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
uint256 endianHash(uint256 h)
|
||||
{
|
||||
uint256 out;
|
||||
for (int i=0; i<32; i++) {
|
||||
out.begin()[31-i] = h.begin()[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
TEST_F(TestCrossChain, testCreateAndValidateImportProof)
|
||||
{
|
||||
/*
|
||||
* This tests the full process of creation of a cross chain proof.
|
||||
* For the purposes of the test we will use one assetchain and a KMD chain.
|
||||
*
|
||||
* In order to do this test, we need 2 blockchains, so we'll fork and make a socket
|
||||
* for IPC.
|
||||
*/
|
||||
|
||||
int childPid = fork();
|
||||
void *ctx = zmq_ctx_new();
|
||||
void *socket = zmq_socket(ctx, ZMQ_PAIR);
|
||||
if (!childPid)
|
||||
strcpy(ASSETCHAINS_SYMBOL, "PIZZA");
|
||||
setupChain();
|
||||
std::vector<CBlock> blocks;
|
||||
blocks.resize(1000);
|
||||
NotarisationData a2kmd(0), kmd2a(1);
|
||||
int numTestNotarisations = 10;
|
||||
|
||||
|
||||
auto SendIPC = [&] (std::vector<uint8_t> v) {
|
||||
assert(v.size() == zmq_send(socket, v.data(), v.size(), 0));
|
||||
};
|
||||
|
||||
auto RecvIPC = [&] () {
|
||||
std::vector<uint8_t> out;
|
||||
out.resize(100000);
|
||||
int len = zmq_recv(socket, out.data(), out.size(), 0);
|
||||
assert(len != -1);
|
||||
out.resize(len);
|
||||
return out;
|
||||
};
|
||||
|
||||
auto RecordNotarisation = [&] (CTransaction inputTx, NotarisationData data) {
|
||||
CMutableTransaction mtx = spendTx(inputTx);
|
||||
mtx.vout.resize(2);
|
||||
mtx.vout[0].scriptPubKey << VCH(notaryKey.GetPubKey().begin(), 33) << OP_CHECKSIG;
|
||||
mtx.vout[1].scriptPubKey << OP_RETURN << E_MARSHAL(ss << data);
|
||||
mtx.vout[1].nValue = 0;
|
||||
mtx.vin[0].scriptSig << getSig(mtx, inputTx.vout[0].scriptPubKey);
|
||||
|
||||
acceptTxFail(CTransaction(mtx));
|
||||
return mtx.GetHash();
|
||||
};
|
||||
|
||||
auto RunTestAssetchain = [&] ()
|
||||
{
|
||||
NotarisationData n(0), back(1);
|
||||
strcpy(n.symbol, "PIZZA");
|
||||
n.ccId = 2;
|
||||
int height = 0;
|
||||
|
||||
/*
|
||||
* Send notarisations and write backnotarisations
|
||||
*/
|
||||
for (int ni=0; ni<numTestNotarisations; ni++)
|
||||
{
|
||||
generateBlock(&blocks[++height]);
|
||||
generateBlock(&blocks[++height]);
|
||||
n.blockHash = blocks[height].GetHash();
|
||||
n.MoM = endianHash(komodo_calcMoM(n.height=height, n.MoMDepth=2));
|
||||
SendIPC(E_MARSHAL(ss << n));
|
||||
assert(E_UNMARSHAL(RecvIPC(), ss >> back));
|
||||
RecordNotarisation(blocks[height].vtx[0], back);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test a proof
|
||||
*/
|
||||
uint256 txid = blocks[7].vtx[0].GetHash();
|
||||
TxProof proof = GetAssetchainProof(txid);
|
||||
SendIPC(E_MARSHAL(ss << txid; ss << proof));
|
||||
E_UNMARSHAL(RecvIPC(), ss >> proof);
|
||||
|
||||
std::pair<uint256,NotarisationData> bn;
|
||||
if (!GetNextBacknotarisation(proof.first, bn)) {
|
||||
printf("GetNextBackNotarisation failed\n");
|
||||
return 1;
|
||||
}
|
||||
if (proof.second.Exec(txid) != bn.second.MoMoM) {
|
||||
printf("MoMom incorrect\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
auto RunTestKmd = [&] ()
|
||||
{
|
||||
NotarisationData n(0);
|
||||
int height = 0;
|
||||
|
||||
/*
|
||||
* Write notarisations and send backnotarisations
|
||||
*/
|
||||
for (int ni=0; ni<numTestNotarisations; ni++)
|
||||
{
|
||||
n.IsBackNotarisation = 0;
|
||||
E_UNMARSHAL(RecvIPC(), ss >> n);
|
||||
// Grab a coinbase input to fund notarisation
|
||||
generateBlock(&blocks[++height]);
|
||||
n.txHash = RecordNotarisation(blocks[height].vtx[0], n);
|
||||
{
|
||||
std::vector<uint256> moms;
|
||||
uint256 destNotarisationTxid;
|
||||
n.MoMoM = CalculateProofRoot(n.symbol, 2, height, moms, destNotarisationTxid);
|
||||
}
|
||||
n.IsBackNotarisation = 1;
|
||||
SendIPC(E_MARSHAL(ss << n));
|
||||
}
|
||||
|
||||
/*
|
||||
* Extend proof
|
||||
*/
|
||||
TxProof proof;
|
||||
uint256 txid;
|
||||
// Extend proof to MoMoM
|
||||
assert(E_UNMARSHAL(RecvIPC(), ss >> txid; ss >> proof));
|
||||
proof = GetCrossChainProof(txid, (char*)"PIZZA", 2, proof);
|
||||
SendIPC(E_MARSHAL(ss << proof));
|
||||
};
|
||||
|
||||
const char endpoint[] = "ipc://tmpKomodoTestCrossChainSock";
|
||||
|
||||
if (!childPid) {
|
||||
assert(0 == zmq_connect(socket, endpoint));
|
||||
usleep(20000);
|
||||
int out = RunTestAssetchain();
|
||||
if (!out) printf("Assetchain success\n");
|
||||
exit(out);
|
||||
}
|
||||
else {
|
||||
assert(0 == zmq_bind(socket, endpoint));
|
||||
RunTestKmd();
|
||||
int returnStatus;
|
||||
waitpid(childPid, &returnStatus, 0);
|
||||
unlink("tmpKomodoTestCrossChainSock");
|
||||
ASSERT_EQ(0, returnStatus);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} /* namespace TestCrossChainProof */
|
||||
@@ -9,7 +9,7 @@
|
||||
* network protocol versioning
|
||||
*/
|
||||
|
||||
static const int PROTOCOL_VERSION = 170003;
|
||||
static const int PROTOCOL_VERSION = 170005;
|
||||
|
||||
//! initial proto version, to be increased after version/verack negotiation
|
||||
static const int INIT_PROTO_VERSION = 209;
|
||||
@@ -19,6 +19,7 @@ static const int GETHEADERS_VERSION = 31800;
|
||||
|
||||
//! disconnect from peers older than this proto version
|
||||
static const int MIN_PEER_PROTO_VERSION = 170002;
|
||||
static const int STAKEDMIN_PEER_PROTO_VERSION = 170005;
|
||||
|
||||
//! nTime field added to CAddress, starting with this version;
|
||||
//! if possible, avoid requesting addresses nodes older than this
|
||||
|
||||
@@ -44,6 +44,8 @@ using namespace std;
|
||||
using namespace libzcash;
|
||||
|
||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
extern std::string ASSETCHAINS_OVERRIDE_PUBKEY;
|
||||
extern int32_t ASSETCHAINS_STREAM;
|
||||
extern UniValue TxJoinSplitToJSON(const CTransaction& tx);
|
||||
extern uint8_t ASSETCHAINS_PRIVATE;
|
||||
uint32_t komodo_segid32(char *coinaddr);
|
||||
@@ -4139,7 +4141,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
strDisabledMsg = "\nWARNING: z_mergetoaddress is DISABLED but can be enabled as an experimental feature.\n";
|
||||
}
|
||||
|
||||
if (fHelp || params.size() < 2 || params.size() > 6)
|
||||
if (fHelp || params.size() < 2 || params.size() > 7)
|
||||
throw runtime_error(
|
||||
"z_mergetoaddress [\"fromaddress\", ... ] \"toaddress\" ( fee ) ( transparent_limit ) ( shielded_limit ) ( memo )\n"
|
||||
+ strDisabledMsg +
|
||||
@@ -4170,7 +4172,9 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
+ strprintf("%d", MERGE_TO_ADDRESS_DEFAULT_TRANSPARENT_LIMIT) + ") Limit on the maximum number of UTXOs to merge. Set to 0 to use node option -mempooltxinputlimit.\n"
|
||||
"4. shielded_limit (numeric, optional, default="
|
||||
+ strprintf("%d", MERGE_TO_ADDRESS_DEFAULT_SHIELDED_LIMIT) + ") Limit on the maximum number of notes to merge. Set to 0 to merge as many as will fit in the transaction.\n"
|
||||
"5. \"memo\" (string, optional) Encoded as hex. When toaddress is a z-addr, this will be stored in the memo field of the new note.\n"
|
||||
"5. maximum_utxo_size (numeric, optional) eg, 0.0001 anything under 10000 satoshies will be merged, ignores p2pk utxo!\n"
|
||||
"6. \"memo\" (string, optional) Encoded as hex. When toaddress is a z-addr, this will be stored in the memo field of the new note.\n"
|
||||
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"remainingUTXOs\": xxx (numeric) Number of UTXOs still available for merging.\n"
|
||||
@@ -4288,9 +4292,19 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
}
|
||||
}
|
||||
|
||||
std::string memo;
|
||||
CAmount maximum_utxo_size;
|
||||
if (params.size() > 5) {
|
||||
memo = params[5].get_str();
|
||||
maximum_utxo_size = AmountFromValue( params[5] );
|
||||
if (maximum_utxo_size < 10) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Maximum size must be bigger than 0.00000010.");
|
||||
}
|
||||
} else {
|
||||
maximum_utxo_size = 0;
|
||||
}
|
||||
|
||||
std::string memo;
|
||||
if (params.size() > 6) {
|
||||
memo = params[6].get_str();
|
||||
if (!isToZaddr) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Memo can not be used with a taddr. It can only be used with a zaddr.");
|
||||
} else if (!IsHex(memo)) {
|
||||
@@ -4346,9 +4360,20 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
continue;
|
||||
}
|
||||
|
||||
utxoCounter++;
|
||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
||||
|
||||
if (maximum_utxo_size != 0) {
|
||||
if (nValue > maximum_utxo_size) {
|
||||
continue;
|
||||
} else {
|
||||
if (out.tx->vout[out.i].scriptPubKey.size() == 35) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
utxoCounter++;
|
||||
|
||||
if (!maxedOutUTXOsFlag) {
|
||||
CBitcoinAddress ba(address);
|
||||
size_t increase = (ba.IsScript()) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE;
|
||||
@@ -4412,7 +4437,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
#endif
|
||||
|
||||
|
||||
if (numUtxos == 0 && numNotes == 0) {
|
||||
if (numUtxos < 2 && numNotes == 0) {
|
||||
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Could not find any funds to merge.");
|
||||
}
|
||||
|
||||
@@ -4592,8 +4617,8 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33)
|
||||
// ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i];
|
||||
txNew.vin[0].prevout.hash = utxotxid; //revtxid;
|
||||
txNew.vin[0].prevout.n = utxovout;
|
||||
txNew.vout[0].scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG;
|
||||
txNew.vout[0].nValue = utxovalue - txfee;
|
||||
txNew.vout[0].scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG;
|
||||
CTransaction txNewConst(txNew);
|
||||
signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, utxovalue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId);
|
||||
if (!signSuccess)
|
||||
@@ -5004,6 +5029,70 @@ UniValue channelsaddress(const UniValue& params, bool fHelp)
|
||||
return(result);
|
||||
}
|
||||
|
||||
bool pubkey2addr(char *destaddr,uint8_t *pubkey33);
|
||||
|
||||
UniValue setpubkey(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
if ( fHelp || params.size() != 1 )
|
||||
throw runtime_error(
|
||||
"setpubkey\n"
|
||||
"\nSets the -pubkey if the daemon was not started with it, if it was already set, it returns the pubkey.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"pubkey\" (string) pubkey to set.\n"
|
||||
"\nResult:\n"
|
||||
" {\n"
|
||||
" \"pubkey\" : \"pubkey\", (string) The pubkey\n"
|
||||
" \"ismine\" : \"true/false\", (bool)\n"
|
||||
" \"R-address\" : \"R address\", (string) The pubkey\n"
|
||||
" }\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e")
|
||||
+ HelpExampleRpc("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e")
|
||||
);
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
LOCK2(cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL);
|
||||
#else
|
||||
LOCK(cs_main);
|
||||
#endif
|
||||
|
||||
char Raddress[18];
|
||||
uint8_t pubkey33[33];
|
||||
extern uint8_t NOTARY_PUBKEY33[];
|
||||
extern std::string NOTARY_PUBKEY;
|
||||
if ( NOTARY_PUBKEY33[0] == 0 ) {
|
||||
if (strlen(params[0].get_str().c_str()) == 66) {
|
||||
decode_hex(pubkey33,33,(char *)params[0].get_str().c_str());
|
||||
pubkey2addr((char *)Raddress,(uint8_t *)pubkey33);
|
||||
if (strcmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",Raddress) == 0) {
|
||||
result.push_back(Pair("error", "pubkey entered is invalid."));
|
||||
} else {
|
||||
CBitcoinAddress address(Raddress);
|
||||
bool isValid = address.IsValid();
|
||||
if (isValid)
|
||||
{
|
||||
CTxDestination dest = address.Get();
|
||||
string currentAddress = address.ToString();
|
||||
result.push_back(Pair("address", currentAddress));
|
||||
#ifdef ENABLE_WALLET
|
||||
isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO;
|
||||
result.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false));
|
||||
#endif
|
||||
}
|
||||
NOTARY_PUBKEY = params[0].get_str();
|
||||
decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str());
|
||||
}
|
||||
} else {
|
||||
result.push_back(Pair("error", "pubkey is wrong length, must be 66 char hex string."));
|
||||
}
|
||||
} else {
|
||||
result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon."));
|
||||
}
|
||||
result.push_back(Pair("pubkey", NOTARY_PUBKEY));
|
||||
return result;
|
||||
}
|
||||
|
||||
UniValue oraclesaddress(const UniValue& params, bool fHelp)
|
||||
{
|
||||
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
|
||||
@@ -6152,7 +6241,10 @@ UniValue dicebet(const UniValue& params, bool fHelp)
|
||||
}
|
||||
if (amount > 0 && odds > 0) {
|
||||
hex = DiceBet(0,name,fundingtxid,amount,odds);
|
||||
if ( hex.size() > 0 )
|
||||
if ( CCerror != "" )
|
||||
{
|
||||
ERR_RESULT(CCerror);
|
||||
} else if ( hex.size() > 0 )
|
||||
{
|
||||
result.push_back(Pair("result", "success"));
|
||||
result.push_back(Pair("hex", hex));
|
||||
|
||||
Reference in New Issue
Block a user