mirror of
https://github.com/monero-project/monero.git
synced 2024-12-27 05:39:22 -05:00
Merge pull request #5128
a17da720
Print the reason why a notification spec failed to parse (moneromooo-monero)356d8137
blockchain: include number of discarded blocks in --reorg-notify (moneromooo-monero)4d598e3d
core: add a few more block rate window sizes (moneromooo-monero)d4fb9641
core: add --block-rate-notify (moneromooo-monero)28b6dbf2
notify: fix tokenizing being too strict (moneromooo-monero)
This commit is contained in:
commit
194c4c0bcb
@ -48,7 +48,7 @@ Notify::Notify(const char *spec)
|
|||||||
{
|
{
|
||||||
CHECK_AND_ASSERT_THROW_MES(spec, "Null spec");
|
CHECK_AND_ASSERT_THROW_MES(spec, "Null spec");
|
||||||
|
|
||||||
boost::split(args, spec, boost::is_any_of(" "));
|
boost::split(args, spec, boost::is_any_of(" \t"), boost::token_compress_on);
|
||||||
CHECK_AND_ASSERT_THROW_MES(args.size() > 0, "Failed to parse spec");
|
CHECK_AND_ASSERT_THROW_MES(args.size() > 0, "Failed to parse spec");
|
||||||
if (strchr(spec, '\'') || strchr(spec, '\"') || strchr(spec, '\\'))
|
if (strchr(spec, '\'') || strchr(spec, '\"') || strchr(spec, '\\'))
|
||||||
MWARNING("A notification spec contains a quote or backslash: note that these are handled verbatim, which may not be the intent");
|
MWARNING("A notification spec contains a quote or backslash: note that these are handled verbatim, which may not be the intent");
|
||||||
|
@ -1056,6 +1056,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we're to keep the disconnected blocks, add them as alternates
|
// if we're to keep the disconnected blocks, add them as alternates
|
||||||
|
const size_t discarded_blocks = disconnected_chain.size();
|
||||||
if(!discard_disconnected_chain)
|
if(!discard_disconnected_chain)
|
||||||
{
|
{
|
||||||
//pushing old chain as alternative chain
|
//pushing old chain as alternative chain
|
||||||
@ -1083,7 +1084,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
|
|||||||
std::shared_ptr<tools::Notify> reorg_notify = m_reorg_notify;
|
std::shared_ptr<tools::Notify> reorg_notify = m_reorg_notify;
|
||||||
if (reorg_notify)
|
if (reorg_notify)
|
||||||
reorg_notify->notify("%s", std::to_string(split_height).c_str(), "%h", std::to_string(m_db->height()).c_str(),
|
reorg_notify->notify("%s", std::to_string(split_height).c_str(), "%h", std::to_string(m_db->height()).c_str(),
|
||||||
"%n", std::to_string(m_db->height() - split_height).c_str(), NULL);
|
"%n", std::to_string(m_db->height() - split_height).c_str(), "%d", std::to_string(discarded_blocks).c_str(), NULL);
|
||||||
|
|
||||||
MGINFO_GREEN("REORGANIZE SUCCESS! on height: " << split_height << ", new blockchain size: " << m_db->height());
|
MGINFO_GREEN("REORGANIZE SUCCESS! on height: " << split_height << ", new blockchain size: " << m_db->height());
|
||||||
return true;
|
return true;
|
||||||
|
@ -188,8 +188,21 @@ namespace cryptonote
|
|||||||
static const command_line::arg_descriptor<std::string> arg_reorg_notify = {
|
static const command_line::arg_descriptor<std::string> arg_reorg_notify = {
|
||||||
"reorg-notify"
|
"reorg-notify"
|
||||||
, "Run a program for each reorg, '%s' will be replaced by the split height, "
|
, "Run a program for each reorg, '%s' will be replaced by the split height, "
|
||||||
"'%h' will be replaced by the new blockchain height, and '%n' will be "
|
"'%h' will be replaced by the new blockchain height, '%n' will be "
|
||||||
"replaced by the number of new blocks in the new chain"
|
"replaced by the number of new blocks in the new chain, and '%d' will be "
|
||||||
|
"replaced by the number of blocks discarded from the old chain"
|
||||||
|
, ""
|
||||||
|
};
|
||||||
|
static const command_line::arg_descriptor<std::string> arg_block_rate_notify = {
|
||||||
|
"block-rate-notify"
|
||||||
|
, "Run a program when the block rate undergoes large fluctuations. This might "
|
||||||
|
"be a sign of large amounts of hash rate going on and off the Monero network, "
|
||||||
|
"and thus be of potential interest in predicting attacks. %t will be replaced "
|
||||||
|
"by the number of minutes for the observation window, %b by the number of "
|
||||||
|
"blocks observed within that window, and %e by the number of blocks that was "
|
||||||
|
"expected in that window. It is suggested that this notification is used to "
|
||||||
|
"automatically increase the number of confirmations required before a payment "
|
||||||
|
"is acted upon."
|
||||||
, ""
|
, ""
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -308,6 +321,7 @@ namespace cryptonote
|
|||||||
command_line::add_arg(desc, arg_block_notify);
|
command_line::add_arg(desc, arg_block_notify);
|
||||||
command_line::add_arg(desc, arg_prune_blockchain);
|
command_line::add_arg(desc, arg_prune_blockchain);
|
||||||
command_line::add_arg(desc, arg_reorg_notify);
|
command_line::add_arg(desc, arg_reorg_notify);
|
||||||
|
command_line::add_arg(desc, arg_block_rate_notify);
|
||||||
|
|
||||||
miner::init_options(desc);
|
miner::init_options(desc);
|
||||||
BlockchainDB::init_options(desc);
|
BlockchainDB::init_options(desc);
|
||||||
@ -587,7 +601,7 @@ namespace cryptonote
|
|||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
MERROR("Failed to parse block notify spec");
|
MERROR("Failed to parse block notify spec: " << e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -597,7 +611,17 @@ namespace cryptonote
|
|||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
MERROR("Failed to parse reorg notify spec");
|
MERROR("Failed to parse reorg notify spec: " << e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!command_line::is_arg_defaulted(vm, arg_block_rate_notify))
|
||||||
|
m_block_rate_notify.reset(new tools::Notify(command_line::get_arg(vm, arg_block_rate_notify).c_str()));
|
||||||
|
}
|
||||||
|
catch (const std::exception &e)
|
||||||
|
{
|
||||||
|
MERROR("Failed to parse block rate notify spec: " << e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::pair<uint8_t, uint64_t> regtest_hard_forks[3] = {std::make_pair(1, 0), std::make_pair(Blockchain::get_hard_fork_heights(MAINNET).back().version, 1), std::make_pair(0, 0)};
|
const std::pair<uint8_t, uint64_t> regtest_hard_forks[3] = {std::make_pair(1, 0), std::make_pair(Blockchain::get_hard_fork_heights(MAINNET).back().version, 1), std::make_pair(0, 0)};
|
||||||
@ -1765,7 +1789,7 @@ namespace cryptonote
|
|||||||
const time_t now = time(NULL);
|
const time_t now = time(NULL);
|
||||||
const std::vector<time_t> timestamps = m_blockchain_storage.get_last_block_timestamps(60);
|
const std::vector<time_t> timestamps = m_blockchain_storage.get_last_block_timestamps(60);
|
||||||
|
|
||||||
static const unsigned int seconds[] = { 5400, 1800, 600 };
|
static const unsigned int seconds[] = { 5400, 3600, 1800, 1200, 600 };
|
||||||
for (size_t n = 0; n < sizeof(seconds)/sizeof(seconds[0]); ++n)
|
for (size_t n = 0; n < sizeof(seconds)/sizeof(seconds[0]); ++n)
|
||||||
{
|
{
|
||||||
unsigned int b = 0;
|
unsigned int b = 0;
|
||||||
@ -1776,6 +1800,14 @@ namespace cryptonote
|
|||||||
if (p < threshold)
|
if (p < threshold)
|
||||||
{
|
{
|
||||||
MWARNING("There were " << b << " blocks in the last " << seconds[n] / 60 << " minutes, there might be large hash rate changes, or we might be partitioned, cut off from the Monero network or under attack. Or it could be just sheer bad luck.");
|
MWARNING("There were " << b << " blocks in the last " << seconds[n] / 60 << " minutes, there might be large hash rate changes, or we might be partitioned, cut off from the Monero network or under attack. Or it could be just sheer bad luck.");
|
||||||
|
|
||||||
|
std::shared_ptr<tools::Notify> block_rate_notify = m_block_rate_notify;
|
||||||
|
if (block_rate_notify)
|
||||||
|
{
|
||||||
|
auto expected = seconds[n] / DIFFICULTY_TARGET_V2;
|
||||||
|
block_rate_notify->notify("%t", std::to_string(seconds[n] / 60).c_str(), "%b", std::to_string(b).c_str(), "%e", std::to_string(expected).c_str(), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
break; // no need to look further
|
break; // no need to look further
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1062,6 +1062,8 @@ namespace cryptonote
|
|||||||
bool m_fluffy_blocks_enabled;
|
bool m_fluffy_blocks_enabled;
|
||||||
bool m_offline;
|
bool m_offline;
|
||||||
bool m_pad_transactions;
|
bool m_pad_transactions;
|
||||||
|
|
||||||
|
std::shared_ptr<tools::Notify> m_block_rate_notify;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,7 +373,7 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
|
|||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
MERROR("Failed to parse tx notify spec");
|
MERROR("Failed to parse tx notify spec: " << e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
return wallet;
|
return wallet;
|
||||||
|
Loading…
Reference in New Issue
Block a user