Skip to content

Commit

Permalink
Filter timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mike31 committed Oct 21, 2018
1 parent c6e459a commit e632350
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/chainparams/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int64_t MAX_MONEY = 21000000 * COIN;
unsigned int MAX_SCRIPT_ELEMENT_SIZE=520; // script.h
int MIN_BLOCKS_BETWEEN_UPGRADES = 100;
int MAX_OP_RETURN_SHOWN=16384;
int DEFAULT_FILTER_TIMEOUT=100;
int MAX_STREAM_QUERY_ITEMS=5000;
int MAX_FORMATTED_DATA_DEPTH=100;
unsigned int MAX_OP_RETURN_OP_DROP_COUNT=100000000;
Expand Down
1 change: 1 addition & 0 deletions src/core/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += " -chunkrequesttimeout=<n> " + _("Timeout, after which chunk request is dropped and another source is tried, default 10s") + "\n";
strUsage += " -flushsourcechunks=<n> " + _("Flush offchain items created by this node to disk immediately when created, default 1") + "\n";
strUsage += " -sendskipstreamfilters=<n> " + _("Skip checking stream filters when publishing, default 0") + "\n";
strUsage += " -filtertimeout=<n> " + strprintf(_("Timeout, after which filter execution will be aborted, in milliseconds, default %u"),DEFAULT_FILTER_TIMEOUT) + "\n";

strUsage += "\n" + _("MultiChain API response parameters") + "\n";
strUsage += " -hideknownopdrops=<n> " + strprintf(_("Remove recognized MultiChain OP_DROP metadata from the responses to JSON-RPC calls (default: %u)"), 0) + "\n";
Expand Down
6 changes: 3 additions & 3 deletions src/core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2843,7 +2843,7 @@ bool static DisconnectTip(CValidationState &state) {
mc_gState->m_Assets->RollBack(old_height-1);
if(pMultiChainFilterEngine)
{
pMultiChainFilterEngine->Reset(old_height-1);
pMultiChainFilterEngine->Reset(old_height-1,0);
}

MultichainNode_ApplyUpgrades(old_height-1);
Expand Down Expand Up @@ -2922,7 +2922,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
if(fDebug)LogPrint("bench", " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * 0.001, nTimeReadFromDisk * 0.000001);
if(pMultiChainFilterEngine)
{
pMultiChainFilterEngine->Reset(pindexNew->nHeight-1);
pMultiChainFilterEngine->Reset(pindexNew->nHeight-1,1);
}
{
CCoinsViewCache view(pcoinsTip);
Expand Down Expand Up @@ -3349,7 +3349,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
mc_gState->m_Assets->ClearMemPool();
if(pMultiChainFilterEngine)
{
pMultiChainFilterEngine->Reset(chainActive.Height());
pMultiChainFilterEngine->Reset(chainActive.Height(),0);
}

if(fDebug)LogPrint("mcblockperf","mchn-block-perf: Replaying mempool\n");
Expand Down
1 change: 1 addition & 0 deletions src/core/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 50000;
static const unsigned int DEFAULT_MAX_SUCCESSORS_FROM_ONE_NODE = 10;
/* MCHN END */
extern int MAX_OP_RETURN_SHOWN;
extern int DEFAULT_FILTER_TIMEOUT;
extern int MAX_STREAM_QUERY_ITEMS;
extern int MAX_FORMATTED_DATA_DEPTH;
extern int MIN_BLOCKS_BETWEEN_UPGRADES;
Expand Down
18 changes: 12 additions & 6 deletions src/protocol/multichainfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,13 @@ int mc_MultiChainFilterEngine::Destroy()
return MC_ERR_NOERROR;
}

int mc_MultiChainFilterEngine::Add(const unsigned char* short_txid)
int mc_MultiChainFilterEngine::GetTimeout()
{
return GetArg("-filtertimeout",DEFAULT_FILTER_TIMEOUT);
}


int mc_MultiChainFilterEngine::Add(const unsigned char* short_txid,int for_block)
{
int err;
mc_MultiChainFilter filter;
Expand All @@ -209,7 +215,7 @@ int mc_MultiChainFilterEngine::Add(const unsigned char* short_txid)
m_Workers->Add(&worker);

err=pFilterEngine->CreateFilter(m_Filters.back().m_FilterCode,m_Filters.back().m_MainName.c_str(),
m_CallbackNames[m_Filters.back().m_FilterType],worker,m_Filters.back().m_CreateError);
m_CallbackNames[m_Filters.back().m_FilterType],worker,(for_block == 0) ? GetTimeout() : 0,m_Filters.back().m_CreateError);
if(err)
{
LogPrintf("Couldn't create filter with short txid %s, error: %d\n",filter.m_FilterAddress.ToString().c_str(),err);
Expand All @@ -223,11 +229,11 @@ int mc_MultiChainFilterEngine::Add(const unsigned char* short_txid)
return MC_ERR_NOERROR;
}

int mc_MultiChainFilterEngine::Reset(int block)
int mc_MultiChainFilterEngine::Reset(int block,int for_block)
{
int filter_block;
int err;

if(m_Filters.size() == 0)
{
return MC_ERR_NOERROR;
Expand Down Expand Up @@ -261,7 +267,7 @@ int mc_MultiChainFilterEngine::Reset(int block)
mc_Filter *worker=*(mc_Filter **)m_Workers->GetRow(i);

err=pFilterEngine->CreateFilter(m_Filters[i].m_FilterCode,m_Filters[i].m_MainName,m_CallbackNames[m_Filters[i].m_FilterType],
worker,m_Filters[i].m_CreateError);
worker,(for_block == 0) ? GetTimeout() : 0,m_Filters[i].m_CreateError);
if(err)
{
LogPrintf("Couldn't prepare filter %s, error: %d\n",m_Filters[i].m_FilterCaption.c_str(),err);
Expand Down Expand Up @@ -521,7 +527,7 @@ int mc_MultiChainFilterEngine::Initialize()

for(it=filter_refs.begin();it != filter_refs.end();it++)
{
err=Add((unsigned char*)&(it->second)+MC_AST_SHORT_TXID_OFFSET);
err=Add((unsigned char*)&(it->second)+MC_AST_SHORT_TXID_OFFSET,0);
if(err)
{
goto exitlbl;
Expand Down
5 changes: 3 additions & 2 deletions src/protocol/multichainfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ typedef struct mc_MultiChainFilterEngine

int Initialize();
void SetCallbackNames();
int Add(const unsigned char* short_txid);
int Reset(int block);
int GetTimeout();
int Add(const unsigned char* short_txid,int for_block);
int Reset(int block,int for_block);
int RunTxFilters(const CTransaction& tx,std::set <uint160>& sRelevantEntities,std::string &strResult,mc_MultiChainFilter **lppFilter,int *applied);
int RunStreamFilters(const CTransaction& tx,int vout, unsigned char *stream_short_txid,int block,int offset,std::string &strResult,mc_MultiChainFilter **lppFilter,int *applied);
int RunFilter(const CTransaction& tx,mc_Filter *filter,std::string &strResult);
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/multichaintx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2114,7 +2114,7 @@ bool MultiChainTransaction_ProcessEntityCreation(const CTransaction& tx,
}
if(details->new_entity_type == MC_ENT_TYPE_FILTER)
{
pMultiChainFilterEngine->Add((unsigned char*)&txid+MC_AST_SHORT_TXID_OFFSET);
pMultiChainFilterEngine->Add((unsigned char*)&txid+MC_AST_SHORT_TXID_OFFSET,(offset < 0) ? 0 : 1);
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/rpcfilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Value createfilterfromcmd(const Array& params, bool fHelp)

mc_Filter *worker=new mc_Filter;

err=pFilterEngine->CreateFilter(js.c_str(),filter_main_name,pMultiChainFilterEngine->m_CallbackNames[filter_type],worker,strError);
err=pFilterEngine->CreateFilter(js.c_str(),filter_main_name,pMultiChainFilterEngine->m_CallbackNames[filter_type],worker,pMultiChainFilterEngine->GetTimeout(),strError);
delete worker;
if(err)
{
Expand Down Expand Up @@ -797,7 +797,7 @@ Value testfilter(const vector <uint160>& entities,const char *filter_code, stri
}

// err=pFilterEngine->CreateFilter(filter_code,filter_main_name,pMultiChainFilterEngine->m_CallbackNames[filter_type],worker,strError);
err=pFilterEngine->CreateFilter(filter_code,filter_main_name,pMultiChainFilterEngine->m_CallbackNames[filter_type],worker,5000, strError);
err=pFilterEngine->CreateFilter(filter_code,filter_main_name,pMultiChainFilterEngine->m_CallbackNames[filter_type],worker,pMultiChainFilterEngine->GetTimeout(), strError);
if(err)
{
errorCode=RPC_INTERNAL_ERROR;
Expand Down
1 change: 1 addition & 0 deletions src/rpc/rpchelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3632,6 +3632,7 @@ void mc_InitRPCHelpMap15()
" handshakelocal,\n"
" hideknownopdrops\n"
" sendskipstreamfilters\n"
" filtertimeout\n"
"2. parameter-value (required) parameter value\n"
"\nResult:\n"
"\nExamples:\n"
Expand Down
9 changes: 9 additions & 0 deletions src/rpc/rpcmisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ Value getruntimeparams(const json_spirit::Array& params, bool fHelp)
obj.push_back(Pair("gen",GetBoolArg("-gen", true)));
obj.push_back(Pair("genproclimit",GetArg("-genproclimit", 1)));
obj.push_back(Pair("sendskipstreamfilters",GetBoolArg("-sendskipstreamfilters", false)));
obj.push_back(Pair("filtertimeout",GetArg("-filtertimeout", DEFAULT_FILTER_TIMEOUT)));
/*
obj.push_back(Pair("shortoutput",GetBoolArg("-shortoutput",false)));
obj.push_back(Pair("walletdbversion", mc_gState->GetWalletDBVersion()));
Expand Down Expand Up @@ -368,6 +369,7 @@ Value setruntimeparam(const json_spirit::Array& params, bool fHelp)
if( (param_name == "lockadminminerounds") ||
(param_name == "maxshowndata") ||
(param_name == "maxqueryscanitems") ||
(param_name == "filtertimeout") ||
(param_name == "dropmessagestest") )
{
if( (params[1].type() == int_type) || (params[1].type() == str_type) )
Expand All @@ -384,6 +386,13 @@ Value setruntimeparam(const json_spirit::Array& params, bool fHelp)
if( nValue >= 0 )
{
mapArgs ["-" + param_name]=strprintf("%d", nValue);
if(param_name == "filtertimeout")
{
if(pMultiChainFilterEngine)
{
pMultiChainFilterEngine->Reset(chainActive.Height(),0);
}
}
}
else
{
Expand Down

0 comments on commit e632350

Please sign in to comment.