Merge branch 'libscottFIX' into fixgettransactioncrash

This commit is contained in:
blackjok3rtt
2018-11-03 20:58:06 +08:00
committed by GitHub
46 changed files with 1779 additions and 1167 deletions

View File

@@ -9,15 +9,16 @@ This is the official Komodo sourcecode repository based on https://github.com/jl
## Development Resources ## Development Resources
- Komodo Website: [https://komodoplatform.com/](https://komodoplatform.com/) - Komodo Website: [https://komodoplatform.com](https://komodoplatform.com/)
- Komodo Blockexplorer: [https://kmdexplorer.io//](https://https://kmdexplorer.io/) - Komodo Blockexplorer: [https://kmdexplorer.io](https://kmdexplorer.io/)
- Forum: [https://forum.komodoplatform.com/](https://forum.komodoplatform.com/) - 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) - Mail: [info@komodoplatform.com](mailto:info@komodoplatform.com)
- Support: [https://support.komodoplatform.com/support/home](https://support.komodoplatform.com/support/home) - 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) - Knowledgebase & How-to: [https://support.komodoplatform.com/en/support/solutions](https://support.komodoplatform.com/en/support/solutions)
- API references: [http://docs.komodoplatform.com/](http://docs.komodoplatform.com/) - API references & Dev Documentation: [https://docs.komodoplatform.com](https://docs.komodoplatform.com/)
- Blog: [http://blog.komodoplatform.com/](http://blog.komodoplatform.com/) - Blog: [https://blog.komodoplatform.com](https://blog.komodoplatform.com/)
- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/03/2018-03-12-Komodo-White-Paper-Full.pdf) - 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) - Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0)
## List of Komodo Platform Technologies ## List of Komodo Platform Technologies

12
resolve.sh Executable file
View 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

View File

@@ -179,6 +179,7 @@ BITCOIN_CORE_H = \
mruset.h \ mruset.h \
net.h \ net.h \
netbase.h \ netbase.h \
notaries_staked.h \
noui.h \ noui.h \
paymentdisclosure.h \ paymentdisclosure.h \
paymentdisclosuredb.h \ paymentdisclosuredb.h \
@@ -280,6 +281,7 @@ libbitcoin_server_a_SOURCES = \
chain.cpp \ chain.cpp \
checkpoints.cpp \ checkpoints.cpp \
crosschain.cpp \ crosschain.cpp \
crosschain_authority.cpp \
deprecation.cpp \ deprecation.cpp \
httprpc.cpp \ httprpc.cpp \
httpserver.cpp \ httpserver.cpp \
@@ -290,6 +292,7 @@ libbitcoin_server_a_SOURCES = \
metrics.cpp \ metrics.cpp \
miner.cpp \ miner.cpp \
net.cpp \ net.cpp \
notaries_staked.cpp \
noui.cpp \ noui.cpp \
notarisationdb.cpp \ notarisationdb.cpp \
paymentdisclosure.cpp \ paymentdisclosure.cpp \

View File

@@ -10,7 +10,6 @@ komodo_test_SOURCES = \
test-komodo/test_coinimport.cpp \ test-komodo/test_coinimport.cpp \
test-komodo/test_eval_bet.cpp \ test-komodo/test_eval_bet.cpp \
test-komodo/test_eval_notarisation.cpp \ test-komodo/test_eval_notarisation.cpp \
test-komodo/test_crosschain.cpp \
test-komodo/test_parse_notarisation.cpp test-komodo/test_parse_notarisation.cpp
komodo_test_CPPFLAGS = $(komodod_CPPFLAGS) komodo_test_CPPFLAGS = $(komodod_CPPFLAGS)

2
src/ac/dion Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=DION $1 $2 $3 $4 $5 $6

2
src/ac/kmdice Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=KMDICE $1 $2 $3 $4 $5 $6

2
src/ac/mgnx Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=MGNX $1 $2 $3 $4 $5 $6

2
src/ac/pgt Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=PGT $1 $2 $3 $4 $5 $6

2
src/ac/pirate Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=PIRATE $1 $2 $3 $4 $5 $6

View File

@@ -1,149 +1,118 @@
[ [
{ {
"ac_name": "REVS", "ac_name": "STAKEDB1",
"ac_supply": "1300000" "ac_supply": "100000",
"ac_reward" : "1000000000",
"ac_cc": "667",
"addnode": [
"195.201.137.5",
"195.201.20.230"
]
}, },
{ {
"ac_name": "SUPERNET", "ac_name": "STAKEDW1",
"ac_supply": "816061" "ac_supply": "100000",
"ac_reward" : "1000000000",
"ac_cc": "667",
"addnode": [
"195.201.137.5",
"195.201.20.230"
]
}, },
{ {
"ac_name": "DEX", "ac_name": "STAKEDPERC",
"ac_supply": "999999" "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_name": "STAKEDS1",
"ac_supply": "999999" "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_name": "STAKEDS9",
"ac_supply": "999999" "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_name": "STAKEDCCP",
"ac_supply": "999999" "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_name": "PGT",
"ac_supply": "999999" "ac_supply": "10000000",
},
{
"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_end": "1", "ac_end": "1",
"addnode": [
"190.114.254.104"
]
},
{
"ac_name": "KMDICE",
"ac_supply": "10500000",
"ac_reward": "2500000000",
"ac_halving": "210000",
"ac_cc": "2", "ac_cc": "2",
"addressindex": "1", "addressindex": "1",
"spentindex": "1", "spentindex": "1",
"addnode": [ "addnode": [
"142.93.136.89", "144.76.217.232"
"195.201.22.89" ]
},
{
"ac_name": "DION",
"ac_supply": "3900000000",
"ac_reward": "22260000000",
"ac_staked": "100",
"ac_cc": "1",
"ac_end": "4300000000",
"addnode": [
"51.75.124.34"
] ]
} }
] ]

View File

@@ -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 & ~/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=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=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 &

View File

@@ -75,6 +75,7 @@ public:
#include "komodo_utils.h" #include "komodo_utils.h"
#include "komodo_cJSON.c" #include "komodo_cJSON.c"
#include "komodo_notary.h" #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) 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)
{ {

View File

@@ -869,7 +869,7 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
if ( (cp= Diceinit(fundingPubKey,zero,&C,planstr,txfee,mypk,dicepk,sbits,a,b,c,d)) == 0 ) 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() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
@@ -894,8 +894,10 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6
fprintf(stderr,"%s\n", CCerror.c_str() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); 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(""); return("");
}
scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG;
if ( 0 ) 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() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); 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(""); return("");
}
if ( bet < minbet || bet > maxbet || odds > maxodds ) 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); 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)); //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 ) 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() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); 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; 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 ) 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() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(0.); return(0.);
} }

View File

@@ -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); return komodo_notaries(pubkeys, height, timestamp);
} }
bool Eval::CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const bool Eval::CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const
{ {
if (tx.vin.size() < 11) return false; if (tx.vin.size() < 11) return false;
uint8_t seenNotaries[64] = {0}; CrosschainAuthority auth;
uint8_t notaries[64][33]; auth.requiredSigs = 11;
int nNotaries = GetNotaries(notaries, height, timestamp); auth.size = GetNotaries(auth.notaries, height, timestamp);
BOOST_FOREACH(const CTxIn &txIn, tx.vin) return CheckTxAuthority(tx, auth);
{
// 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;
} }
/* /*
* Get MoM from a notarisation tx hash (on KMD) * Get MoM from a notarisation tx hash (on KMD)
*/ */
@@ -192,17 +164,6 @@ bool Eval::GetNotarisationData(const uint256 notaryHash, NotarisationData &data)
return true; 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 uint32_t Eval::GetAssetchainsCC() const
{ {

View File

@@ -103,7 +103,6 @@ public:
virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const; 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 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 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 bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const;
virtual uint32_t GetAssetchainsCC() const; virtual uint32_t GetAssetchainsCC() const;
virtual std::string GetAssetchainsSymbol() const; virtual std::string GetAssetchainsSymbol() const;

View File

@@ -16,6 +16,7 @@
#include "cc/eval.h" #include "cc/eval.h"
#include "cc/utils.h" #include "cc/utils.h"
#include "importcoin.h" #include "importcoin.h"
#include "crosschain.h"
#include "primitives/transaction.h" #include "primitives/transaction.h"
@@ -75,16 +76,10 @@ bool Eval::ImportCoin(const std::vector<uint8_t> params, const CTransaction &imp
// Check proof confirms existance of burnTx // Check proof confirms existance of burnTx
{ {
uint256 momom, target; uint256 target = proof.second.Exec(burnTx.GetHash());
if (!GetProofRoot(proof.first, momom)) if (!CheckMoMoM(proof.first, target))
return Invalid("coudnt-load-momom");
target = proof.second.Exec(burnTx.GetHash());
if (momom != proof.second.Exec(burnTx.GetHash()))
return Invalid("momom-check-fail"); return Invalid("momom-check-fail");
} }
return Valid(); return Valid();
} }

View File

@@ -666,7 +666,7 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs; std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
GetCCaddress(cp,coinaddr,pk); GetCCaddress(cp,coinaddr,pk);
SetCCunspents(unspentOutputs,coinaddr); 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++) for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++)
{ {
txid = it->first.txhash; txid = it->first.txhash;

View File

@@ -50,7 +50,7 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh
int seenOwnNotarisations = 0; int seenOwnNotarisations = 0;
bool txscl = IsTXSCL(symbol); int authority = GetSymbolAuthority(symbol);
for (int i=0; i<NOTARISATION_SCAN_LIMIT_BLOCKS; i++) { for (int i=0; i<NOTARISATION_SCAN_LIMIT_BLOCKS; i++) {
if (i > kmdHeight) break; if (i > kmdHeight) break;
@@ -68,19 +68,27 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh
destNotarisationTxid = nota.first; destNotarisationTxid = nota.first;
else if (seenOwnNotarisations == 2) else if (seenOwnNotarisations == 2)
goto end; goto end;
break; fprintf(stderr, "kmd heigt notarisation added: %d\n",kmdHeight-i);
//break;
} }
} }
if (seenOwnNotarisations == 1) { if (seenOwnNotarisations == 1) {
BOOST_FOREACH(Notarisation& nota, notarisations) { BOOST_FOREACH(Notarisation& nota, notarisations) {
if (IsTXSCL(nota.second.symbol) == txscl) if (GetSymbolAuthority(nota.second.symbol) == authority)
if (nota.second.ccId == targetCCid) if (nota.second.ccId == targetCCid) {
moms.push_back(nota.second.MoM); 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: end:
return GetMerkleRoot(moms); return GetMerkleRoot(moms);
} }
@@ -95,8 +103,9 @@ template <typename IsTarget>
int ScanNotarisationsFromHeight(int nHeight, const IsTarget f, Notarisation &found) int ScanNotarisationsFromHeight(int nHeight, const IsTarget f, Notarisation &found)
{ {
int limit = std::min(nHeight + NOTARISATION_SCAN_LIMIT_BLOCKS, chainActive.Height()); int limit = std::min(nHeight + NOTARISATION_SCAN_LIMIT_BLOCKS, chainActive.Height());
int start = std::max(nHeight, 1);
for (int h=nHeight; h<limit; h++) { for (int h=start; h<limit; h++) {
NotarisationsInBlock notarisations; NotarisationsInBlock notarisations;
if (!GetBlockNotarisations(*chainActive[h]->phashBlock, notarisations)) if (!GetBlockNotarisations(*chainActive[h]->phashBlock, notarisations))
@@ -157,6 +166,8 @@ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_
if (MoMoM.IsNull()) if (MoMoM.IsNull())
throw std::runtime_error("No MoMs found"); throw std::runtime_error("No MoMs found");
printf("[%s] GetCrossChainProof MoMoM: %s\n", targetSymbol,MoMoM.GetHex().data());
// Find index of source MoM in MoMoM // Find index of source MoM in MoMoM
int nIndex; int nIndex;
for (nIndex=0; nIndex<moms.size(); 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 &nota) {
return nota.second.MoMoM == momom;
};
return (bool) ScanNotarisationsFromHeight(block.nHeight-100, checkMoMoM, nota);
}
/* /*
* On assetchain * On assetchain
* in: txid * in: txid

View File

@@ -3,6 +3,18 @@
#include "cc/eval.h" #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 */ /* On assetchain */
TxProof GetAssetchainProof(uint256 hash); TxProof GetAssetchainProof(uint256 hash);
@@ -15,7 +27,7 @@ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_
void CompleteImportTransaction(CTransaction &importTx); void CompleteImportTransaction(CTransaction &importTx);
/* On assetchain */ /* On assetchain */
bool GetNextBacknotarisation(uint256 txid, std::pair<uint256,NotarisationData> &bn); bool CheckMoMoM(uint256 kmdNotarisationHash, uint256 momom);
#endif /* CROSSCHAIN_H */ #endif /* CROSSCHAIN_H */

View 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
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=DION $1 $2 $3 $4 $5 $6

2
src/fiat/kmdice Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=KMDICE $1 $2 $3 $4 $5 $6

2
src/fiat/mgnx Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=MGNX $1 $2 $3 $4 $5 $6

2
src/fiat/pgt Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=PGT $1 $2 $3 $4 $5 $6

2
src/fiat/pirate Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
./komodo-cli -ac_name=PIRATE $1 $2 $3 $4 $5 $6

View File

@@ -16,6 +16,7 @@
#ifndef H_KOMODO_H #ifndef H_KOMODO_H
#define H_KOMODO_H #define H_KOMODO_H
#include "komodo_defs.h" #include "komodo_defs.h"
#include "notaries_staked.h"
#ifdef _WIN32 #ifdef _WIN32
#define printf(...) #define printf(...)
@@ -830,6 +831,10 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
txn_count = block.vtx.size(); txn_count = block.vtx.size();
for (i=0; i<txn_count; i++) 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(); txhash = block.vtx[i].GetHash();
numvouts = block.vtx[i].vout.size(); numvouts = block.vtx[i].vout.size();
notaryid = -1; 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); } //else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j);
} }
numvalid = bitweight(signedmask); 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 >= 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; static FILE *signedfp;
if ( signedfp == 0 ) if ( signedfp == 0 )

View File

@@ -1105,25 +1105,33 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_
commission must be in coinbase.vout[1] and must be >= 10000 sats 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] 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) uint64_t komodo_commission(const CBlock *pblock)
{ {
int32_t i,j,n=0,txn_count; uint64_t commission,total = 0; int32_t i,j,n=0,txn_count; uint64_t commission,total = 0;
txn_count = pblock->vtx.size(); if ( ASSETCHAINS_STREAM == 0 )
for (i=0; i<txn_count; i++)
{ {
n = pblock->vtx[i].vout.size(); txn_count = pblock->vtx.size();
for (j=0; j<n; j++) for (i=0; i<txn_count; i++)
{ {
//fprintf(stderr,"(%d %.8f).%d ",i,dstr(block.vtx[i].vout[j].nValue),j); n = pblock->vtx[i].vout.size();
if ( i != 0 || j != 1 ) for (j=0; j<n; j++)
total += pblock->vtx[i].vout[j].nValue; {
} //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); 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 komodo_checkcommission(CBlock *pblock,int32_t height)
{ {
int64_t checktoshis=0; uint8_t *script; int64_t checktoshis=0; uint8_t *script;
if ( ASSETCHAINS_COMMISSION != 0 ) if ( ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0)
{ {
checktoshis = komodo_commission(pblock); checktoshis = komodo_commission(pblock);
if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) 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 ) if ( height == 1 )
{ {
script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data(); 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); return(-1);
}
} }
else else
{ {
if ( komodo_checkcommission(pblock,height) < 0 ) if ( komodo_checkcommission(pblock,height) < 0 )
return(-1); 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); //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 ) if ( failed != 0 && possible == 0 && notaryid < 0 )

View File

@@ -744,7 +744,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim
else else
{ {
checktoshis = 0; 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 ) if ( (checktoshis= komodo_checkcommission((CBlock *)&block,height)) < 0 )
{ {
@@ -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); printf("READY for %s RPC calls at %u! done PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,(uint32_t)time(NULL),ASSETCHAINS_SYMBOL,refid);
} }
} }

View File

@@ -45,9 +45,9 @@ struct komodo_state KOMODO_STATES[34];
#define _COINBASE_MATURITY 100 #define _COINBASE_MATURITY 100
int COINBASE_MATURITY = _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; 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; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW;
char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; 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 ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1;
uint32_t ASSETCHAINS_MAGIC = 2387029918; uint32_t ASSETCHAINS_MAGIC = 2387029918;
uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; 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; uint32_t KOMODO_INITDONE;
char KMDUSERPASS[8192],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; char KMDUSERPASS[8192],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771;

View File

@@ -18,8 +18,13 @@
#include "komodo_cJSON.h" #include "komodo_cJSON.h"
#include "notaries_staked.h"
#define KOMODO_MAINNET_START 178999 #define KOMODO_MAINNET_START 178999
//extern const char *notaries_STAKED[][2];
//extern const int num_notaries_STAKED;
const char *Notaries_genesis[][2] = const char *Notaries_genesis[][2] =
{ {
{ "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, { "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) 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 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; int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp;
if ( timestamp == 0 && ASSETCHAINS_SYMBOL[0] != 0 ) if ( timestamp == 0 && ASSETCHAINS_SYMBOL[0] != 0 )
timestamp = komodo_heightstamp(height); timestamp = komodo_heightstamp(height);
else if ( ASSETCHAINS_SYMBOL[0] == 0 ) else if ( ASSETCHAINS_SYMBOL[0] == 0 )
timestamp = 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 ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 )
{ {
if ( did0 == 0 ) if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP1) || (ASSETCHAINS_SYMBOL[0] == 0 && height <= KOMODO_NOTARIES_HEIGHT1) )
{ {
n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0)); if ( did0 == 0 )
for (i=0; i<n0; i++) {
decode_hex(elected_pubkeys0[i],33,(char *)Notaries_elected0[i][1]); n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0));
did0 = 1; for (i=0; i<n0; i++)
} decode_hex(elected_pubkeys0[i],33,(char *)Notaries_elected0[i][1]);
memcpy(pubkeys,elected_pubkeys0,n0 * 33); did0 = 1;
//if ( ASSETCHAINS_SYMBOL[0] != 0 ) }
//fprintf(stderr,"%s height.%d t.%u elected.%d notaries\n",ASSETCHAINS_SYMBOL,height,timestamp,n0); memcpy(pubkeys,elected_pubkeys0,n0 * 33);
return(n0); //if ( ASSETCHAINS_SYMBOL[0] != 0 )
} //fprintf(stderr,"%s height.%d t.%u elected.%d notaries\n",ASSETCHAINS_SYMBOL,height,timestamp,n0);
else //if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP2) || height <= KOMODO_NOTARIES_HEIGHT2 ) return(n0);
{ }
if ( did1 == 0 ) else //if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP2) || height <= KOMODO_NOTARIES_HEIGHT2 )
{ {
n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1)); if ( did1 == 0 )
{
n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1));
for (i=0; i<n1; i++) for (i=0; i<n1; i++)
decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]); decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]);
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
fprintf(stderr,"%s height.%d t.%u elected.%d notaries2\n",ASSETCHAINS_SYMBOL,height,timestamp,n1); fprintf(stderr,"%s height.%d t.%u elected.%d notaries2\n",ASSETCHAINS_SYMBOL,height,timestamp,n1);
did1 = 1; did1 = 1;
} }
memcpy(pubkeys,elected_pubkeys1,n1 * 33); memcpy(pubkeys,elected_pubkeys1,n1 * 33);
return(n1); 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; htind = height / KOMODO_ELECTION_GAP;
if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP )
htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1;

View File

@@ -1562,6 +1562,14 @@ void komodo_args(char *argv0)
ASSETCHAINS_DECAY = GetArg("-ac_decay",0); ASSETCHAINS_DECAY = GetArg("-ac_decay",0);
ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0);
ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); 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 ) if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 )
ASSETCHAINS_STAKED = 100; ASSETCHAINS_STAKED = 100;
if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 ) if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 )
@@ -1590,8 +1598,15 @@ void komodo_args(char *argv0)
{ {
ASSETCHAINS_COMMISSION = 0; ASSETCHAINS_COMMISSION = 0;
printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n");
} } else if ( ASSETCHAINS_STREAM != 0) {
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 ) 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]); 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; extraptr = extrabuf;
@@ -1767,4 +1782,3 @@ void komodo_prefetch(FILE *fp)
} }
fseek(fp,fpos,SEEK_SET); fseek(fp,fpos,SEEK_SET);
} }

View File

@@ -4,7 +4,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "main.h" #include "main.h"
#include "notaries_staked.h"
#include "sodium.h" #include "sodium.h"
#include "addrman.h" #include "addrman.h"
@@ -34,6 +34,8 @@
#include "wallet/asyncrpcoperation_sendmany.h" #include "wallet/asyncrpcoperation_sendmany.h"
#include "wallet/asyncrpcoperation_shieldcoinbase.h" #include "wallet/asyncrpcoperation_shieldcoinbase.h"
#include "notaries_staked.h"
#include <sstream> #include <sstream>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
@@ -60,6 +62,7 @@ extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CON
int32_t KOMODO_NEWBLOCKS; int32_t KOMODO_NEWBLOCKS;
int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block);
void komodo_broadcast(CBlock *pblock,int32_t limit); void komodo_broadcast(CBlock *pblock,int32_t limit);
void komodo_broadcast(CBlock *pblock,int32_t limit);
bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey);
BlockMap mapBlockIndex; BlockMap mapBlockIndex;
@@ -1044,21 +1047,21 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state,
int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only
{ {
static int32_t didinit; static char notaryaddrs[sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) + 1][64]; static int32_t didinit; static char notaryaddrs[17 + 1][64];
int32_t i; int32_t i;
if ( didinit == 0 ) if ( didinit == 0 )
{ {
uint8_t pubkey33[33]; uint8_t pubkey33[33];
for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) for (i=0; i<=17; i++)
{ {
if ( i < sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) ) if ( i < 17 )
decode_hex(pubkey33,33,(char *)Notaries_elected1[i][1]); decode_hex(pubkey33,33,(char *)notaries_STAKED1[i][1]);
else decode_hex(pubkey33,33,(char *)CRYPTO777_PUBSECPSTR); else decode_hex(pubkey33,33,(char *)CRYPTO777_PUBSECPSTR);
pubkey2addr((char *)notaryaddrs[i],(uint8_t *)pubkey33); pubkey2addr((char *)notaryaddrs[i],(uint8_t *)pubkey33);
} }
didinit = 1; didinit = 1;
} }
for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) for (i=0; i<=17; i++)
if ( strcmp(coinaddr,notaryaddrs[i]) == 0 ) if ( strcmp(coinaddr,notaryaddrs[i]) == 0 )
return(1); return(1);
return(0); return(0);
@@ -1196,6 +1199,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
REJECT_INVALID, "bad-txns-txouttotal-toolarge"); REJECT_INVALID, "bad-txns-txouttotal-toolarge");
} }
} }
if ( ASSETCHAINS_TXPOW != 0 && tx.vjoinsplit.size() == 0 ) if ( ASSETCHAINS_TXPOW != 0 && tx.vjoinsplit.size() == 0 )
{ {
// genesis coinbase 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b // genesis coinbase 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
@@ -1880,6 +1884,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW)
//uint64_t komodo_moneysupply(int32_t height); //uint64_t komodo_moneysupply(int32_t height);
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern uint32_t ASSETCHAINS_MAGIC; extern uint32_t ASSETCHAINS_MAGIC;
extern int32_t ASSETCHAINS_STREAM;
extern uint64_t ASSETCHAINS_STAKED,ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; extern uint64_t ASSETCHAINS_STAKED,ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY;
extern uint8_t ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; extern uint8_t ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE;
@@ -1908,8 +1913,13 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
else if ( ASSETCHAINS_ENDSUBSIDY == 0 || nHeight < ASSETCHAINS_ENDSUBSIDY ) else if ( ASSETCHAINS_ENDSUBSIDY == 0 || nHeight < ASSETCHAINS_ENDSUBSIDY )
{ {
if ( ASSETCHAINS_REWARD == 0 ) if ( ASSETCHAINS_REWARD == 0 )
return(10000); {
else if ( ASSETCHAINS_ENDSUBSIDY != 0 && nHeight >= ASSETCHAINS_ENDSUBSIDY ) if ( ASSETCHAINS_STREAM != 0 && nHeight > 128 )
return(0);
else
return(10000);
}
else if ( ASSETCHAINS_ENDSUBSIDY != 0 && nHeight >= ASSETCHAINS_ENDSUBSIDY )
return(0); return(0);
else else
{ {
@@ -2975,6 +2985,19 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (!view.HaveJoinSplitRequirements(tx)) if (!view.HaveJoinSplitRequirements(tx))
return state.DoS(100, error("ConnectBlock(): JoinSplit requirements not met"), return state.DoS(100, error("ConnectBlock(): JoinSplit requirements not met"),
REJECT_INVALID, "bad-txns-joinsplit-requirements-not-met"); REJECT_INVALID, "bad-txns-joinsplit-requirements-not-met");
if ( ASSETCHAINS_SYMBOL[0] != 0 )
{
if ( ASSETCHAINS_STREAM != 0 )
{
if ( block.vtx.size() == 1 && block.vtx[0].vout.size() == 2 && pindex->nHeight > ASSETCHAINS_MINHEIGHT)
{
return state.DoS(100, error("ConnectBlock(): There are no TX in this block, it is invalid!"),
REJECT_INVALID, "bad-block-no-transactions");
}
}
}
if (fAddressIndex || fSpentIndex) if (fAddressIndex || fSpentIndex)
{ {
for (size_t j = 0; j < tx.vin.size(); j++) { for (size_t j = 0; j < tx.vin.size(); j++) {
@@ -3124,7 +3147,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001); LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001);
CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus()) + sum; CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus()) + sum;
if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) )
{ {
uint64_t checktoshis; uint64_t checktoshis;
if ( (checktoshis= komodo_commission((CBlock *)&block)) != 0 ) if ( (checktoshis= komodo_commission((CBlock *)&block)) != 0 )
@@ -3423,6 +3446,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
CBlock block; CBlock block;
if (!ReadBlockFromDisk(block, pindexDelete,1)) if (!ReadBlockFromDisk(block, pindexDelete,1))
return AbortNode(state, "Failed to read block"); return AbortNode(state, "Failed to read block");
//if ( ASSETCHAINS_SYMBOL[0] != 0 || pindexDelete->nHeight > 1400000 )
{ {
int32_t prevMoMheight; uint256 notarizedhash,txid; int32_t prevMoMheight; uint256 notarizedhash,txid;
komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid); komodo_notarized_height(&prevMoMheight,&notarizedhash,&txid);
@@ -6013,14 +6037,28 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
CAddress addrFrom; CAddress addrFrom;
uint64_t nNonce = 1; uint64_t nNonce = 1;
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe; vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
if (pfrom->nVersion < MIN_PEER_PROTO_VERSION) if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 )
{ {
// disconnect from peers older than this proto version if (pfrom->nVersion < STAKEDMIN_PEER_PROTO_VERSION)
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion); {
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE, // disconnect from peers older than this proto version
strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION)); LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
pfrom->fDisconnect = true; pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
return false; strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION));
pfrom->fDisconnect = true;
return false;
}
} else
{
if (pfrom->nVersion < MIN_PEER_PROTO_VERSION)
{
// disconnect from peers older than this proto version
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION));
pfrom->fDisconnect = true;
return false;
}
} }
// When Overwinter is active, reject incoming connections from non-Overwinter nodes // When Overwinter is active, reject incoming connections from non-Overwinter nodes

View File

@@ -916,6 +916,8 @@ extern CBlockTreeDB *pblocktree;
*/ */
int GetSpendHeight(const CCoinsViewCache& inputs); int GetSpendHeight(const CCoinsViewCache& inputs);
uint64_t CalculateCurrentUsage();
/** Return a CMutableTransaction with contextual default values based on set of consensus rules at height */ /** Return a CMutableTransaction with contextual default values based on set of consensus rules at height */
CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight); CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight);

View File

@@ -106,7 +106,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams,
#include "komodo_defs.h" #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 uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED;
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY;
@@ -437,7 +437,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
pblock->vtx[0] = txNew; 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; int32_t i; uint8_t *ptr;
txNew.vout.resize(2); txNew.vout.resize(2);
@@ -448,7 +448,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
for (i=0; i<33; i++) for (i=0; i<33; i++)
ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i];
ptr[34] = OP_CHECKSIG; ptr[34] = OP_CHECKSIG;
//printf("autocreate commision vout\n"); //printf("autocreate commission vout\n");
pblock->vtx[0] = txNew; pblock->vtx[0] = txNew;
} }
pblocktemplate->vTxFees[0] = -nFees; pblocktemplate->vTxFees[0] = -nFees;
@@ -502,6 +502,26 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
return(0); 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) ) else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (ASSETCHAINS_SYMBOL[0] != 0 || IS_KOMODO_NOTARY == 0 || My_notaryid < 0) )
{ {
CValidationState state; CValidationState state;
@@ -619,12 +639,18 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in
{ {
scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; 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 ) else if ( USE_EXTERNAL_PUBKEY != 0 )
{ {
//fprintf(stderr,"use notary pubkey\n"); //fprintf(stderr,"use notary pubkey\n");
scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
} } else
else
{ {
if (!reservekey.GetReservedKey(pubkey)) if (!reservekey.GetReservedKey(pubkey))
{ {
@@ -849,14 +875,19 @@ void static BitcoinMiner()
{ {
if ( ASSETCHAINS_REWARD == 0 ) 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; static uint32_t counter;
if ( counter++ < 10 ) if ( counter++ < 10 )
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL); fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL);
sleep(10); sleep(10);
continue; 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); IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
@@ -935,13 +966,13 @@ void static BitcoinMiner()
} }
while (true) 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); 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 ) if ( KOMODO_LONGESTCHAIN != 0 && Mining_height >= KOMODO_LONGESTCHAIN )
KOMODO_INSYNC = 1; KOMODO_INSYNC = 1;
sleep(3); sleep(3);
} } */
// Hash state // Hash state
KOMODO_CHOSEN_ONE = 0; KOMODO_CHOSEN_ONE = 0;
crypto_generichash_blake2b_state state; crypto_generichash_blake2b_state state;

158
src/notaries_staked.cpp Normal file
View 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
View 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

View File

@@ -2,7 +2,9 @@
#include "notarisationdb.h" #include "notarisationdb.h"
#include "uint256.h" #include "uint256.h"
#include "cc/eval.h" #include "cc/eval.h"
#include "crosschain.h"
#include "main.h" #include "main.h"
#include "notaries_staked.h"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
@@ -17,31 +19,51 @@ NotarisationsInBlock ScanBlockNotarisations(const CBlock &block, int nHeight)
{ {
EvalRef eval; EvalRef eval;
NotarisationsInBlock vNotarisations; NotarisationsInBlock vNotarisations;
CrosschainAuthority auth_STAKED;
int timestamp = block.nTime;
for (unsigned int i = 0; i < block.vtx.size(); i++) { for (unsigned int i = 0; i < block.vtx.size(); i++) {
CTransaction tx = block.vtx[i]; CTransaction tx = block.vtx[i];
// Special case for TXSCL. Should prob be removed at some point. NotarisationData data;
bool isTxscl = 0; bool parsed = ParseNotarisationOpReturn(tx, data);
{ if (!parsed) data = NotarisationData();
NotarisationData data; if (strlen(data.symbol) == 0)
if (ParseNotarisationOpReturn(tx, data)) continue;
if (IsTXSCL(data.symbol))
isTxscl = 1; //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)) { if (parsed) {
NotarisationData data; vNotarisations.push_back(std::make_pair(tx.GetHash(), data));
if (ParseNotarisationOpReturn(tx, data)) { printf("Added notarisation data for %s \n",data.symbol);
vNotarisations.push_back(std::make_pair(tx.GetHash(), data)); //printf("Parsed a notarisation for: %s, txid:%s, ccid:%i, momdepth:%i\n",
//printf("Parsed a notarisation for: %s, txid:%s, ccid:%i, momdepth:%i\n", // data.symbol, tx.GetHash().GetHex().data(), data.ccId, data.MoMDepth);
// data.symbol, tx.GetHash().GetHex().data(), data.ccId, data.MoMDepth); //if (!data.MoMoM.IsNull()) printf("MoMoM:%s\n", data.MoMoM.GetHex().data());
//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",
else tx.GetHash().GetHex().data(), nHeight);
LogPrintf("WARNING: Couldn't parse notarisation for tx: %s at height %i\n",
tx.GetHash().GetHex().data(), nHeight);
}
} }
return vNotarisations; return vNotarisations;
} }

View File

@@ -20,31 +20,39 @@
#include "librustzcash.h" #include "librustzcash.h"
#endif // ENABLE_RUST #endif // ENABLE_RUST
uint32_t komodo_chainactive_timestamp(); 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 GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{ {
unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); if ( ASSETCHAINS_STREAM == 0)
// Genesis block {
if (pindexLast == NULL ) unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact();
return nProofOfWorkLimit; // Genesis block
if (pindexLast == NULL )
return nProofOfWorkLimit;
// Find the first block in the averaging interval // Find the first block in the averaging interval
const CBlockIndex* pindexFirst = pindexLast; const CBlockIndex* pindexFirst = pindexLast;
arith_uint256 bnTot {0}; arith_uint256 bnTot {0};
for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) { for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) {
arith_uint256 bnTmp; arith_uint256 bnTmp;
bnTmp.SetCompact(pindexFirst->nBits); bnTmp.SetCompact(pindexFirst->nBits);
bnTot += bnTmp; bnTot += bnTmp;
pindexFirst = pindexFirst->pprev; 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, unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,

View File

@@ -260,6 +260,218 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
return result; 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 blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
{ {
UniValue result(UniValue::VOBJ); UniValue result(UniValue::VOBJ);
@@ -1261,6 +1473,7 @@ void NetworkUpgradeDescPushBack(
} }
} }
UniValue getblockchaininfo(const UniValue& params, bool fHelp) UniValue getblockchaininfo(const UniValue& params, bool fHelp)
{ {
if (fHelp || params.size() != 0) if (fHelp || params.size() != 0)
@@ -1278,6 +1491,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n" " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
" \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n" " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
" \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\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" " \"commitments\": xxxxxx, (numeric) the current number of note commitments in the commitment tree\n"
" \"softforks\": [ (array) status of softforks in progress\n" " \"softforks\": [ (array) status of softforks in progress\n"
" {\n" " {\n"
@@ -1327,6 +1541,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("verificationprogress", progress)); obj.push_back(Pair("verificationprogress", progress));
obj.push_back(Pair("chainwork", chainActive.LastTip()->nChainWork.GetHex())); obj.push_back(Pair("chainwork", chainActive.LastTip()->nChainWork.GetHex()));
obj.push_back(Pair("pruned", fPruneMode)); obj.push_back(Pair("pruned", fPruneMode));
obj.push_back(Pair("size_on_disk", CalculateCurrentUsage()));
ZCIncrementalMerkleTree tree; ZCIncrementalMerkleTree tree;
pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), tree); pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), tree);

View File

@@ -169,6 +169,9 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp)
if (targetSymbol.size() == 0 || targetSymbol.size() > 32) if (targetSymbol.size() == 0 || targetSymbol.size() > 32)
throw runtime_error("targetSymbol length must be >0 and <=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]); CAmount burnAmount = AmountFromValue(params[2]);
if (burnAmount <= 0) if (burnAmount <= 0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for export"); throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for export");

View File

@@ -65,6 +65,7 @@ extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[];
UniValue getinfo(const UniValue& params, bool fHelp) UniValue getinfo(const UniValue& params, bool fHelp)
{ {
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height; uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height;
extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[];
if (fHelp || params.size() != 0) if (fHelp || params.size() != 0)
throw runtime_error( throw runtime_error(
"getinfo\n" "getinfo\n"

View File

@@ -285,6 +285,7 @@ static const CRPCCommand vRPCCommands[] =
{ "blockchain", "getbestblockhash", &getbestblockhash, true }, { "blockchain", "getbestblockhash", &getbestblockhash, true },
{ "blockchain", "getblockcount", &getblockcount, true }, { "blockchain", "getblockcount", &getblockcount, true },
{ "blockchain", "getblock", &getblock, true }, { "blockchain", "getblock", &getblock, true },
{ "blockchain", "getdatafromblock", &getdatafromblock, true },
{ "blockchain", "getblockdeltas", &getblockdeltas, false }, { "blockchain", "getblockdeltas", &getblockdeltas, false },
{ "blockchain", "getblockhashes", &getblockhashes, true }, { "blockchain", "getblockhashes", &getblockhashes, true },
{ "blockchain", "getblockhash", &getblockhash, true }, { "blockchain", "getblockhash", &getblockhash, true },

View File

@@ -364,6 +364,7 @@ extern UniValue getblockdeltas(const UniValue& params, bool fHelp);
extern UniValue getblockhash(const UniValue& params, bool fHelp); extern UniValue getblockhash(const UniValue& params, bool fHelp);
extern UniValue getblockheader(const UniValue& params, bool fHelp); extern UniValue getblockheader(const UniValue& params, bool fHelp);
extern UniValue getblock(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 gettxoutsetinfo(const UniValue& params, bool fHelp);
extern UniValue gettxout(const UniValue& params, bool fHelp); extern UniValue gettxout(const UniValue& params, bool fHelp);
extern UniValue verifychain(const UniValue& params, bool fHelp); extern UniValue verifychain(const UniValue& params, bool fHelp);

View File

@@ -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 */

View File

@@ -9,7 +9,7 @@
* network protocol versioning * 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 //! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209; 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 //! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION = 170002; 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; //! nTime field added to CAddress, starting with this version;
//! if possible, avoid requesting addresses nodes older than this //! if possible, avoid requesting addresses nodes older than this

View File

@@ -44,6 +44,8 @@ using namespace std;
using namespace libzcash; using namespace libzcash;
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; 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 UniValue TxJoinSplitToJSON(const CTransaction& tx);
extern uint8_t ASSETCHAINS_PRIVATE; extern uint8_t ASSETCHAINS_PRIVATE;
uint32_t komodo_segid32(char *coinaddr); 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"; 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( throw runtime_error(
"z_mergetoaddress [\"fromaddress\", ... ] \"toaddress\" ( fee ) ( transparent_limit ) ( shielded_limit ) ( memo )\n" "z_mergetoaddress [\"fromaddress\", ... ] \"toaddress\" ( fee ) ( transparent_limit ) ( shielded_limit ) ( memo )\n"
+ strDisabledMsg + + 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" + 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=" "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" + 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" "\nResult:\n"
"{\n" "{\n"
" \"remainingUTXOs\": xxx (numeric) Number of UTXOs still available for merging.\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) { 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) { if (!isToZaddr) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Memo can not be used with a taddr. It can only be used with a zaddr."); 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)) { } else if (!IsHex(memo)) {
@@ -4346,9 +4360,20 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
continue; continue;
} }
utxoCounter++;
CAmount nValue = out.tx->vout[out.i].nValue; 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) { if (!maxedOutUTXOsFlag) {
CBitcoinAddress ba(address); CBitcoinAddress ba(address);
size_t increase = (ba.IsScript()) ? CTXIN_SPEND_P2SH_SIZE : CTXIN_SPEND_DUST_SIZE; 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 #endif
if (numUtxos == 0 && numNotes == 0) { if (numUtxos < 2 && numNotes == 0) {
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Could not find any funds to merge."); 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]; // ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i];
txNew.vin[0].prevout.hash = utxotxid; //revtxid; txNew.vin[0].prevout.hash = utxotxid; //revtxid;
txNew.vin[0].prevout.n = utxovout; 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].nValue = utxovalue - txfee;
txNew.vout[0].scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG;
CTransaction txNewConst(txNew); CTransaction txNewConst(txNew);
signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, utxovalue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, utxovalue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId);
if (!signSuccess) if (!signSuccess)
@@ -5004,6 +5029,70 @@ UniValue channelsaddress(const UniValue& params, bool fHelp)
return(result); 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) UniValue oraclesaddress(const UniValue& params, bool fHelp)
{ {
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey; 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) { if (amount > 0 && odds > 0) {
hex = DiceBet(0,name,fundingtxid,amount,odds); 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("result", "success"));
result.push_back(Pair("hex", hex)); result.push_back(Pair("hex", hex));