Browse Source

Fixed issue #145, should fix stake synching with wallets

metaverse
miketout 6 years ago
parent
commit
4c8293dc76
  1. 2
      src/cc/CCinclude.h
  2. 42
      src/main.cpp
  3. 2
      src/rpc/server.cpp
  4. 5
      src/wallet/rpcwallet.cpp

2
src/cc/CCinclude.h

@ -101,7 +101,7 @@ bool GetAddressUnspent(uint160 addressHash, int type,std::vector<std::pair<CAddr
static const uint256 zeroid;
bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock);
int32_t is_hexstr(char *str,int32_t n);
bool myAddtomempool(CTransaction &tx);
bool myAddtomempool(CTransaction &tx, CValidationState *pstate = NULL);
//uint64_t myGettxout(uint256 hash,int32_t n);
bool myIsutxo_spentinmempool(uint256 txid,int32_t vout);
int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout);

42
src/main.cpp

@ -1532,14 +1532,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
}
}
// if this is a valid stake transaction, don't put it in the mempool
CStakeParams p;
if (ValidateStakeTransaction(tx, p, false))
{
return state.DoS(0, error("AcceptToMemoryPool: attempt to add staking transaction to the mempool"),
REJECT_INVALID, "staking");
}
auto verifier = libzcash::ProofVerifier::Strict();
if ( komodo_validate_interest(tx,chainActive.LastTip()->GetHeight()+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 )
{
@ -1579,6 +1571,14 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
return state.DoS(0, false, REJECT_NONSTANDARD, "non-final");
}
// if this is a valid stake transaction, don't put it in the mempool
CStakeParams p;
if (ValidateStakeTransaction(tx, p, false))
{
return state.DoS(0, error("AcceptToMemoryPool: attempt to add staking transaction to the mempool"),
REJECT_INVALID, "staking");
}
// is it already in the memory pool?
uint256 hash = tx.GetHash();
if (pool.exists(hash))
@ -1891,9 +1891,12 @@ bool GetAddressUnspent(uint160 addressHash, int type,
else return(coins.vout[n].nValue);
}*/
bool myAddtomempool(CTransaction &tx)
bool myAddtomempool(CTransaction &tx, CValidationState *pstate)
{
CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false;
CValidationState state;
if (!pstate)
pstate = &state;
CTransaction Ltx; bool fMissingInputs,fOverrideFees = false;
if ( mempool.lookup(tx.GetHash(),Ltx) == 0 )
return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees));
else return(true);
@ -4541,18 +4544,27 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
// Check transactions
if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order
{
CValidationState stateDummy; int32_t i,j,rejects=0,lastrejects=0;
int32_t i,j,rejects=0,lastrejects=0;
//fprintf(stderr,"put block's tx into mempool\n");
while ( 1 )
{
for (i=0; i<block.vtx.size(); i++)
{
CTransaction Tx; const CTransaction &tx = (CTransaction)block.vtx[i];
if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && ((ASSETCHAINS_LWMAPOS && block.IsVerusPOSBlock()) || (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0))))
CValidationState state;
CTransaction Tx;
const CTransaction &tx = (CTransaction)block.vtx[i];
if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0)))
continue;
Tx = tx;
if ( myAddtomempool(Tx) == false ) // happens with out of order tx in block on resync
rejects++;
if ( myAddtomempool(Tx, &state) == false ) // happens with out of order tx in block on resync
{
// take advantage of other checks, but if we were only rejected because it is a staking
// transaction, sync with wallets and don't mark as a reject
if (state.GetRejectReason() == "staking")
SyncWithWallets(Tx, &block);
else
rejects++;
}
}
if ( rejects == 0 || rejects == lastrejects )
{

2
src/rpc/server.cpp

@ -731,7 +731,7 @@ UniValue CRPCTable::execute(const std::string &strMethod, const UniValue &params
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
}
// printf("RPC call: %s\n", strMethod.c_str());
//printf("RPC call: %s\n", strMethod.c_str());
// Find method
const CRPCCommand *pcmd = tableRPC[strMethod];

5
src/wallet/rpcwallet.cpp

@ -6735,8 +6735,9 @@ UniValue getbalance64(const UniValue& params, bool fHelp)
UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR),b(UniValue::VARR); CTxDestination address;
const CKeyStore& keystore = *pwalletMain;
CAmount nValues[64],nValues2[64],nValue,total,total2; int32_t i,segid;
assert(pwalletMain != NULL);
if (fHelp || params.size() > 0)
if (!EnsureWalletIsAvailable(fHelp))
return NullUniValue;
if (params.size() > 0)
throw runtime_error("getbalance64\n");
total = total2 = 0;
memset(nValues,0,sizeof(nValues));

Loading…
Cancel
Save