Skip to content

Commit 59751a4

Browse files
vtnerdnahuhh
authored andcommitted
checkpoints: reduce ban time to 300s
1 parent 297c05b commit 59751a4

File tree

9 files changed

+18
-13
lines changed

9 files changed

+18
-13
lines changed

src/cryptonote_basic/verification_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@ namespace cryptonote
7171
bool m_partial_block_reward;
7272
bool m_bad_pow; // if bad pow, ban peer outright for DoS protection
7373
bool m_missing_txs; // set if, during verif, we don't have all the necessary txs available
74+
bool m_failed_checkpoint;
7475
};
7576
}

src/cryptonote_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154

155155
#define P2P_FAILED_ADDR_FORGET_SECONDS (60*60) //1 hour
156156
#define P2P_IP_BLOCKTIME (60*60*24) //24 hour
157+
#define P2P_IP_BLOCKTIME_LIGHT (60*5) // 5 mins
157158
#define P2P_IP_FAILS_BEFORE_BLOCK 10
158159
#define P2P_IDLE_CONNECTION_KILL_INTERVAL (5*60) //5 minutes
159160

src/cryptonote_core/blockchain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
18851885
{
18861886
MERROR_VER("Block with id: " << id << std::endl << " can't be accepted for alternative chain, block height: " << block_height << std::endl << " blockchain height: " << get_current_blockchain_height());
18871887
bvc.m_verifivation_failed = true;
1888+
bvc.m_failed_checkpoint = true;
18881889
return false;
18891890
}
18901891

src/cryptonote_protocol/cryptonote_protocol_handler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ namespace cryptonote
159159
void drop_connection(cryptonote_connection_context &context, bool add_fail, bool flush_all_spans);
160160
void drop_connection_with_score(cryptonote_connection_context &context, unsigned int score, bool flush_all_spans);
161161
void drop_connection(const boost::uuids::uuid&);
162-
void drop_connections(const epee::net_utils::network_address address);
162+
void drop_connections(const epee::net_utils::network_address address, unsigned score = 5, bool block_light = false);
163163
bool kick_idle_peers();
164164
bool check_standby_peers();
165165
bool update_sync_search();

src/cryptonote_protocol/cryptonote_protocol_handler.inl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ namespace cryptonote
15271527

15281528
if(bvc.m_verifivation_failed)
15291529
{
1530-
drop_connections(span_origin);
1530+
drop_connections(span_origin, 5, bvc.m_failed_checkpoint);
15311531
if (!m_p2p->for_connection(span_connection_id, [&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t f)->bool{
15321532
LOG_PRINT_CCONTEXT_L1("Block verification failed, dropping connection");
15331533
drop_connection_with_score(context, bvc.m_bad_pow ? P2P_IP_FAILS_BEFORE_BLOCK : 1, true);
@@ -2821,11 +2821,11 @@ skip:
28212821
}
28222822
//------------------------------------------------------------------------------------------------------------------------
28232823
template<class t_core>
2824-
void t_cryptonote_protocol_handler<t_core>::drop_connections(const epee::net_utils::network_address address)
2824+
void t_cryptonote_protocol_handler<t_core>::drop_connections(const epee::net_utils::network_address address, unsigned score, bool block_light)
28252825
{
28262826
MWARNING("dropping connections to " << address.str());
28272827

2828-
m_p2p->add_host_fail(address, 5);
2828+
m_p2p->add_host_fail(address, score, block_light);
28292829

28302830
std::vector<boost::uuids::uuid> drop;
28312831
m_p2p->for_each_connection([&](const connection_context& cntxt, nodetool::peerid_type peer_id, uint32_t support_flags) {

src/p2p/net_node.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ namespace nodetool
350350
virtual void request_callback(const epee::net_utils::connection_context_base& context);
351351
virtual void for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type, uint32_t)> f);
352352
virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type, uint32_t)> f);
353-
virtual bool add_host_fail(const epee::net_utils::network_address &address, unsigned int score = 1);
353+
virtual bool add_host_fail(const epee::net_utils::network_address &address, unsigned int score = 1, bool block_light = false);
354354
//----------------- i_connection_filter --------------------------------------------------------
355355
virtual bool is_remote_host_allowed(const epee::net_utils::network_address &address, time_t *t = NULL);
356356
//----------------- i_connection_limit ---------------------------------------------------------
@@ -509,6 +509,7 @@ namespace nodetool
509509

510510
epee::critical_section m_host_fails_score_lock;
511511
std::map<std::string, uint64_t> m_host_fails_score;
512+
std::map<std::string, uint64_t> m_host_fails_score_light;
512513

513514
boost::mutex m_used_stripe_peers_mutex;
514515
std::array<std::list<epee::net_utils::network_address>, 1 << CRYPTONOTE_PRUNING_LOG_STRIPES> m_used_stripe_peers;

src/p2p/net_node.inl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,20 +403,21 @@ namespace nodetool
403403
}
404404
//-----------------------------------------------------------------------------------
405405
template<class t_payload_net_handler>
406-
bool node_server<t_payload_net_handler>::add_host_fail(const epee::net_utils::network_address &address, unsigned int score)
406+
bool node_server<t_payload_net_handler>::add_host_fail(const epee::net_utils::network_address &address, unsigned int score, bool block_light)
407407
{
408408
if(!address.is_blockable())
409409
return false;
410410

411411
CRITICAL_REGION_LOCAL(m_host_fails_score_lock);
412-
uint64_t fails = m_host_fails_score[address.host_str()] += score;
412+
auto& host_fails_score = block_light ? m_host_fails_score_light : m_host_fails_score;
413+
uint64_t fails = host_fails_score[address.host_str()] += score;
413414
MDEBUG("Host " << address.host_str() << " fail score=" << fails);
414415
if(fails > P2P_IP_FAILS_BEFORE_BLOCK)
415416
{
416-
auto it = m_host_fails_score.find(address.host_str());
417-
CHECK_AND_ASSERT_MES(it != m_host_fails_score.end(), false, "internal error");
417+
auto it = host_fails_score.find(address.host_str());
418+
CHECK_AND_ASSERT_MES(it != host_fails_score.end(), false, "internal error");
418419
it->second = P2P_IP_FAILS_BEFORE_BLOCK/2;
419-
block_host(address);
420+
block_host(address, block_light ? P2P_IP_BLOCKTIME_LIGHT : P2P_IP_BLOCKTIME);
420421
}
421422
return true;
422423
}

src/p2p/net_node_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace nodetool
6464
virtual bool unblock_host(const epee::net_utils::network_address &address)=0;
6565
virtual std::map<std::string, time_t> get_blocked_hosts()=0;
6666
virtual std::map<epee::net_utils::ipv4_network_subnet, time_t> get_blocked_subnets()=0;
67-
virtual bool add_host_fail(const epee::net_utils::network_address &address, unsigned int score = 1)=0;
67+
virtual bool add_host_fail(const epee::net_utils::network_address &address, unsigned int score = 1, bool block_light = false)=0;
6868
virtual void add_used_stripe_peer(const t_connection_context &context)=0;
6969
virtual void remove_used_stripe_peer(const t_connection_context &context)=0;
7070
virtual void clear_used_stripe_peers()=0;
@@ -122,7 +122,7 @@ namespace nodetool
122122
{
123123
return std::map<epee::net_utils::ipv4_network_subnet, time_t>();
124124
}
125-
virtual bool add_host_fail(const epee::net_utils::network_address &address, unsigned int score)
125+
virtual bool add_host_fail(const epee::net_utils::network_address &address, unsigned int score, bool block_light)
126126
{
127127
return true;
128128
}

tests/unit_tests/node_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ TEST(cryptonote_protocol_handler, race_condition)
608608
core_protocol->on_connection_close(context);
609609
}
610610
virtual ~net_node_t() override {}
611-
virtual bool add_host_fail(const address_t&, unsigned int = {}) override {
611+
virtual bool add_host_fail(const address_t&, unsigned int = {}, bool = {}) override {
612612
return {};
613613
}
614614
virtual bool block_host(address_t address, time_t = {}, bool = {}) override {

0 commit comments

Comments
 (0)