Major rebase and fix staking.
This commit is contained in:
@@ -1112,7 +1112,6 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_
|
||||
commission must be in coinbase.vout[1] and must be >= 10000 sats
|
||||
PoS stake must be without txfee and in the last tx in the block at vout[0]
|
||||
*/
|
||||
extern int32_t ASSETCHAINS_FOUNDERS_PERIOD;
|
||||
|
||||
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
|
||||
|
||||
|
||||
@@ -207,59 +207,55 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
|
||||
int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp;
|
||||
|
||||
if ( timestamp == 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
timestamp = komodo_heightstamp(height);
|
||||
timestamp = komodo_heightstamp(height);
|
||||
else if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||
timestamp = 0;
|
||||
timestamp = 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 ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
{
|
||||
if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP1) || (ASSETCHAINS_SYMBOL[0] == 0 && height <= KOMODO_NOTARIES_HEIGHT1) )
|
||||
{
|
||||
if ( did0 == 0 )
|
||||
{
|
||||
n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0));
|
||||
for (i=0; i<n0; i++) {
|
||||
decode_hex(elected_pubkeys0[i],33,(char *)Notaries_elected0[i][1]);
|
||||
}
|
||||
did0 = 1;
|
||||
}
|
||||
memcpy(pubkeys,elected_pubkeys0,n0 * 33);
|
||||
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
//fprintf(stderr,"%s height.%d t.%u elected.%d notaries\n",ASSETCHAINS_SYMBOL,height,timestamp,n0);
|
||||
return(n0);
|
||||
}
|
||||
else //if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP2) || height <= KOMODO_NOTARIES_HEIGHT2 )
|
||||
{
|
||||
if ( did1 == 0 )
|
||||
{
|
||||
n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1));
|
||||
if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
timestamp = 0;
|
||||
if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP1) || (ASSETCHAINS_SYMBOL[0] == 0 && height <= KOMODO_NOTARIES_HEIGHT1) )
|
||||
{
|
||||
if ( did0 == 0 )
|
||||
{
|
||||
n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0));
|
||||
for (i=0; i<n0; i++) {
|
||||
decode_hex(elected_pubkeys0[i],33,(char *)Notaries_elected0[i][1]);
|
||||
}
|
||||
did0 = 1;
|
||||
}
|
||||
memcpy(pubkeys,elected_pubkeys0,n0 * 33);
|
||||
//if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
//fprintf(stderr,"%s height.%d t.%u elected.%d notaries\n",ASSETCHAINS_SYMBOL,height,timestamp,n0);
|
||||
return(n0);
|
||||
}
|
||||
else //if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP2) || height <= KOMODO_NOTARIES_HEIGHT2 )
|
||||
{
|
||||
if ( did1 == 0 )
|
||||
{
|
||||
n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1));
|
||||
for (i=0; i<n1; i++) {
|
||||
decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]);
|
||||
decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]);
|
||||
}
|
||||
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
fprintf(stderr,"%s height.%d t.%u elected.%d notaries2\n",ASSETCHAINS_SYMBOL,height,timestamp,n1);
|
||||
did1 = 1;
|
||||
}
|
||||
memcpy(pubkeys,elected_pubkeys1,n1 * 33);
|
||||
return(n1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // here we can activate our pubkeys for STAKED chains everythig is in notaries_staked.cpp
|
||||
if (timestamp != 0)
|
||||
{
|
||||
int32_t staked_era; int8_t numSN;
|
||||
uint8_t staked_pubkeys[64][33];
|
||||
staked_era = STAKED_era(timestamp);
|
||||
numSN = numStakedNotaries(staked_pubkeys,staked_era);
|
||||
memcpy(pubkeys,staked_pubkeys,numSN * 33);
|
||||
return(numSN);
|
||||
}
|
||||
memcpy(pubkeys,elected_pubkeys1,n1 * 33);
|
||||
return(n1);
|
||||
}
|
||||
}
|
||||
else if (timestamp != 0)
|
||||
{ // here we can activate our pubkeys for STAKED chains everythig is in notaries_staked.cpp
|
||||
int32_t staked_era; int8_t numSN;
|
||||
uint8_t staked_pubkeys[64][33];
|
||||
staked_era = STAKED_era(timestamp);
|
||||
numSN = numStakedNotaries(staked_pubkeys,staked_era);
|
||||
memcpy(pubkeys,staked_pubkeys,numSN * 33);
|
||||
return(numSN);
|
||||
}
|
||||
|
||||
htind = height / KOMODO_ELECTION_GAP;
|
||||
if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP )
|
||||
|
||||
@@ -1711,7 +1711,7 @@ void komodo_args(char *argv0)
|
||||
{
|
||||
printf("KOMODO_REWIND %d\n",KOMODO_REWIND);
|
||||
}
|
||||
if ( name.c_str()[0] != 0 )
|
||||
if ( name.c_str()[0] != 0 )
|
||||
{
|
||||
std::string selectedAlgo = GetArg("-ac_algo", std::string(ASSETCHAINS_ALGORITHMS[0]));
|
||||
|
||||
|
||||
70
src/main.cpp
70
src/main.cpp
@@ -1244,7 +1244,8 @@ int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only
|
||||
{
|
||||
if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 )
|
||||
{
|
||||
if ( NOTARYADDRS[0][0] != 0 && NUM_NOTARIES != 0 ) {
|
||||
if ( NOTARYADDRS[0][0] != 0 && NUM_NOTARIES != 0 )
|
||||
{
|
||||
for (int32_t i=0; i<=NUM_NOTARIES; i++)
|
||||
if ( strcmp(coinaddr,NOTARYADDRS[i]) == 0 )
|
||||
return(1);
|
||||
@@ -1764,8 +1765,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
||||
if (pfMissingInputs)
|
||||
*pfMissingInputs = true;
|
||||
//fprintf(stderr,"missing inputs\n");
|
||||
return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing");
|
||||
return(false);
|
||||
if (!fSkipExpiry)
|
||||
return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing");
|
||||
else
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1773,7 +1776,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
|
||||
if (!view.HaveInputs(tx))
|
||||
{
|
||||
//fprintf(stderr,"accept failure.1\n");
|
||||
return state.Invalid(error("AcceptToMemoryPool: inputs already spent"),REJECT_DUPLICATE, "bad-txns-inputs-spent");
|
||||
if (!fSkipExpiry)
|
||||
return state.Invalid(error("AcceptToMemoryPool: inputs already spent"),REJECT_DUPLICATE, "bad-txns-inputs-spent");
|
||||
else
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
// are the joinsplit's requirements met?
|
||||
@@ -3302,7 +3308,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
||||
{
|
||||
if (!view.HaveInputs(tx))
|
||||
{
|
||||
return state.DoS(100, error("ConnectBlock(): inputs missing/spent"),
|
||||
return state.DoS(100, error("ConnectBlock(): inputs missing/spent %s",tx.GetHash().ToString().c_str()),
|
||||
REJECT_INVALID, "bad-txns-inputs-missingorspent");
|
||||
}
|
||||
// are the JoinSplit's requirements met?
|
||||
@@ -3846,8 +3852,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
|
||||
if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0)))
|
||||
{
|
||||
#ifdef ENABLE_WALLET
|
||||
TxToRemove.push_back(tx.GetHash());
|
||||
//pwalletMain->EraseFromWallet(tx.GetHash());
|
||||
pwalletMain->EraseFromWallet(tx.GetHash());
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -3855,25 +3860,6 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
|
||||
SyncWithWallets(tx, NULL);
|
||||
}
|
||||
}
|
||||
if ( ASSETCHAINS_STAKED != 0 ) // If Staked chain, scan wallet for orphaned txs and delete them.
|
||||
{
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
|
||||
{
|
||||
CTransaction tx;
|
||||
uint256 hashBlock;
|
||||
if (!GetTransaction((*it).first,tx,hashBlock,true))
|
||||
{
|
||||
fprintf(stderr, "TX Does Not Exist: %s\n",(*it).first.ToString().c_str());
|
||||
TxToRemove.push_back((*it).first);
|
||||
}
|
||||
}
|
||||
BOOST_FOREACH (uint256& hash, TxToRemove)
|
||||
{
|
||||
pwalletMain->EraseFromWallet(hash);
|
||||
fprintf(stderr, "Erased %s from wallet.\n",hash.ToString().c_str());
|
||||
}
|
||||
}
|
||||
// Update cached incremental witnesses
|
||||
GetMainSignals().ChainTip(pindexDelete, &block, newSproutTree, newSaplingTree, false);
|
||||
return true;
|
||||
@@ -6601,32 +6587,20 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
|
||||
CAddress addrFrom;
|
||||
uint64_t nNonce = 1;
|
||||
int nVersion; // use temporary for version, don't set version number until validated as connected
|
||||
int minVersion = MIN_PEER_PROTO_VERSION;
|
||||
if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 )
|
||||
minVersion = STAKEDMIN_PEER_PROTO_VERSION;
|
||||
vRecv >> nVersion >> pfrom->nServices >> nTime >> addrMe;
|
||||
if (nVersion == 10300)
|
||||
nVersion = 300;
|
||||
if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 )
|
||||
if (nVersion < minVersion)
|
||||
{
|
||||
if (nVersion < STAKEDMIN_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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (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;
|
||||
}
|
||||
// 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", minVersion));
|
||||
pfrom->fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reject incoming connections from nodes that don't know about the current epoch
|
||||
|
||||
@@ -5317,7 +5317,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
counter++;
|
||||
if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth )
|
||||
{
|
||||
//fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth);
|
||||
fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth);
|
||||
continue;
|
||||
}
|
||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
||||
@@ -5388,7 +5388,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
}
|
||||
} //else fprintf(stderr,"utxo not eligible\n");
|
||||
}
|
||||
if ( numkp < 10000 && array != 0 )
|
||||
if ( numkp < 1000 && array != 0 )
|
||||
{
|
||||
free(array);
|
||||
array = 0;
|
||||
|
||||
@@ -867,8 +867,6 @@ static bool IsKeyType(string strType)
|
||||
strType == "mkey" || strType == "ckey");
|
||||
}
|
||||
|
||||
extern uint64_t ASSETCHAINS_STAKED;
|
||||
|
||||
DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
|
||||
{
|
||||
pwallet->vchDefaultKey = CPubKey();
|
||||
@@ -920,9 +918,8 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
|
||||
{
|
||||
// Leave other errors alone, if we try to fix them we might make things worse.
|
||||
fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
|
||||
if (strType == "tx" && ASSETCHAINS_STAKED == 0 )
|
||||
if (strType == "tx" )
|
||||
// Rescan if there is a bad transaction record..
|
||||
// But dont on staked chains!
|
||||
SoftSetBoolArg("-rescan", true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user