From 00f28499e9c80bdf7a53f9ac1967722b96b5387f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 21:38:36 -1100 Subject: [PATCH] Check bettxid in mempool --- src/cc/CCinclude.h | 1 + src/cc/dice.cpp | 22 ++++++++++++++++------ src/rpcblockchain.cpp | 12 ++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 2a2d41ef0..749d676e9 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -95,6 +95,7 @@ int32_t is_hexstr(char *str,int32_t n); bool myAddtomempool(CTransaction &tx); //uint64_t myGettxout(uint256 hash,int32_t n); bool myIsutxo_spentinmempool(uint256 txid,int32_t vout); +bool mytxid_inmempool(uint256 txid); int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7b6bf07e9..ae3e90c21 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -169,14 +169,24 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t result; struct dicefinish_info *ptr; uint256 entropyused; + char str[65],str2[65],name[32]; std::string res; int32_t i,result; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - usleep(1000000 + (rand() % 3000000)); // wait for bettxid to be in mempool unstringbits(name,ptr->sbits); - fprintf(stderr,"dicefinish.%d %s funding.%s bet.%s\n",ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); - if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); + usleep((rand() % 100000) + 10000); + for (i=0; i<600; i++) + { + usleep(100000); + if ( mytxid_inmempool(ptr->bettxid) != 0 ) // wait for bettxid to be in mempool + { + fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); + res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + if ( result > 0 ) + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); + break; + } + } + if ( i == 100 ) + fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); free(ptr); return(0); } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 815860c7d..868431f6f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -378,6 +378,18 @@ bool myIsutxo_spentinmempool(uint256 txid,int32_t vout) return(false); } +bool mytxid_inmempool(uint256 txid) +{ + BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) + { + const CTransaction &tx = e.GetTx(); + const uint256 &hash = tx.GetHash(); + if ( txid == hash ) + return(true); + } + return(false); +} + UniValue mempoolToJSON(bool fVerbose = false) { if (fVerbose)