@@ -608,20 +608,33 @@ namespace eosio {
608
608
609
609
constexpr uint16_t net_version_max = proto_block_nack;
610
610
611
- /* *
612
- * Index by start_block_num
613
- */
614
611
struct peer_sync_state {
615
- explicit peer_sync_state (uint32_t start = 0 , uint32_t end = 0 , uint32_t last_acted = 0 )
616
- :start_block( start ), end_block( end ), last( last_acted ),
617
- start_time(time_point::now())
612
+ enum class sync_t {
613
+ peer_sync, // LIB or head catchup, syncing request_message:catch_up
614
+ block_nack // sync due to block nack (block_notice_message) request_message:normal
615
+ };
616
+ peer_sync_state (uint32_t start, uint32_t end, uint32_t last_acted, sync_t sync_type)
617
+ :start_block( start ), end_block( end ), last( last_acted ), sync_type( sync_type )
618
618
{}
619
+
620
+ bool valid () const ;
621
+
619
622
uint32_t start_block;
620
623
uint32_t end_block;
621
624
uint32_t last; // /< last sent or received
622
- time_point start_time; // /< time request made or received
625
+ sync_t sync_type;
623
626
};
624
627
628
+ bool peer_sync_state::valid () const {
629
+ bool valid = start_block > 0 && end_block >= start_block && last >= start_block && last <= end_block;
630
+ if (sync_type == sync_t ::block_nack && valid) {
631
+ // block nack should only be used for "current" blocks, limit size to something reasonable
632
+ const auto size = end_block - start_block;
633
+ valid = size < 100 ;
634
+ }
635
+ return valid;
636
+ }
637
+
625
638
// thread safe
626
639
class queued_buffer : boost::noncopyable {
627
640
public:
@@ -1010,7 +1023,7 @@ namespace eosio {
1010
1023
1011
1024
void blk_send_branch ( const block_id_type& msg_head_id );
1012
1025
void blk_send_branch_from_nack_request ( const block_id_type& msg_head_id, const block_id_type& req_id );
1013
- void blk_send_branch ( uint32_t msg_head_num, uint32_t fork_db_root_num, uint32_t head_num );
1026
+ void blk_send_branch (uint32_t msg_head_num, uint32_t fork_db_root_num, uint32_t head_num, peer_sync_state:: sync_t sync_type );
1014
1027
1015
1028
void enqueue ( const net_message& msg );
1016
1029
size_t enqueue_block ( const std::vector<char >& sb, uint32_t block_num, queued_buffer::queue_t queue );
@@ -1516,7 +1529,7 @@ namespace eosio {
1516
1529
1517
1530
auto msg_head_num = block_header::num_from_id (msg_head_id);
1518
1531
if (msg_head_num == 0 ) {
1519
- blk_send_branch ( msg_head_num, fork_db_root_num, head_num );
1532
+ blk_send_branch ( msg_head_num, fork_db_root_num, head_num, peer_sync_state:: sync_t ::peer_sync );
1520
1533
return ;
1521
1534
}
1522
1535
@@ -1529,7 +1542,7 @@ namespace eosio {
1529
1542
// if peer on fork, start at their last fork_db_root_num, otherwise we can start at msg_head+1
1530
1543
if (on_fork)
1531
1544
msg_head_num = 0 ;
1532
- blk_send_branch ( msg_head_num, fork_db_root_num, head_num );
1545
+ blk_send_branch ( msg_head_num, fork_db_root_num, head_num, peer_sync_state:: sync_t ::peer_sync );
1533
1546
}
1534
1547
}
1535
1548
@@ -1542,28 +1555,30 @@ namespace eosio {
1542
1555
// a more complicated better approach would be to find where the fork branches and send from there, for now use lib
1543
1556
uint32_t fork_db_root_num = my_impl->get_fork_db_root_num ();
1544
1557
// --fork_db_root_num since blk_send_branch adds one to the request, and we want to start at fork_db_root_num
1545
- blk_send_branch ( --fork_db_root_num, 0 , head_num);
1558
+ blk_send_branch ( --fork_db_root_num, 0 , head_num, peer_sync_state:: sync_t ::block_nack );
1546
1559
} else {
1547
1560
auto msg_req_num = block_header::num_from_id (req_id);
1548
1561
// --msg_req_num since blk_send_branch adds one to the request, and we need to start at msg_req_num
1549
- blk_send_branch ( --msg_req_num, 0 , head_num );
1562
+ blk_send_branch ( --msg_req_num, 0 , head_num, peer_sync_state:: sync_t ::block_nack );
1550
1563
}
1551
1564
}
1552
1565
1553
1566
// called from connection strand
1554
- void connection::blk_send_branch ( uint32_t msg_head_num, uint32_t fork_db_root_num, uint32_t head_num ) {
1567
+ void connection::blk_send_branch ( uint32_t msg_head_num, uint32_t fork_db_root_num, uint32_t head_num, peer_sync_state:: sync_t sync_type ) {
1555
1568
if ( !peer_requested ) {
1556
1569
auto last = msg_head_num != 0 ? msg_head_num : fork_db_root_num;
1557
- peer_requested = peer_sync_state ( last+1 , head_num, last );
1570
+ peer_requested = peer_sync_state ( last+1 , head_num, last, sync_type );
1558
1571
} else {
1559
1572
auto last = msg_head_num != 0 ? msg_head_num : std::min ( peer_requested->last , fork_db_root_num );
1560
1573
uint32_t end = std::max ( peer_requested->end_block , head_num );
1561
1574
if (peer_requested->start_block <= last+1 && peer_requested->end_block >= end)
1562
1575
return ; // nothing to do, send in progress
1563
- peer_requested = peer_sync_state ( last+1 , end, last );
1576
+ peer_requested = peer_sync_state ( last+1 , end, last, sync_type );
1564
1577
}
1565
- if ( peer_requested->start_block <= peer_requested->end_block ) {
1566
- peer_ilog ( this , " enqueue ${s} - ${e}" , (" s" , peer_requested->start_block )(" e" , peer_requested->end_block ) );
1578
+ if ( peer_requested->valid () ) {
1579
+ peer_ilog ( this , " enqueue ${t} ${s} - ${e}" ,
1580
+ (" t" , sync_type == peer_sync_state::sync_t ::peer_sync ? " peer" : " block" )
1581
+ (" s" , peer_requested->start_block )(" e" , peer_requested->end_block ) );
1567
1582
enqueue_sync_block ();
1568
1583
} else {
1569
1584
peer_ilog ( this , " nothing to enqueue" );
@@ -1778,7 +1793,7 @@ namespace eosio {
1778
1793
peer_dlog ( this , " completing enqueue_sync_block ${num}" , (" num" , num) );
1779
1794
}
1780
1795
} else {
1781
- peer_ilog ( this , " enqueue sync, unable to fetch block ${num}, sending benign_other go away" , (" num" , num) );
1796
+ peer_ilog ( this , " enqueue peer sync, unable to fetch block ${num}, sending benign_other go away" , (" num" , num) );
1782
1797
peer_requested.reset (); // unable to provide requested blocks
1783
1798
block_sync_send_start = 0ns;
1784
1799
block_sync_frame_bytes_sent = 0 ;
@@ -3813,7 +3828,7 @@ namespace eosio {
3813
3828
peer_requested->end_block = std::max (msg.end_block , peer_requested->end_block );
3814
3829
}
3815
3830
else {
3816
- peer_requested = peer_sync_state ( msg.start_block , msg.end_block , msg.start_block -1 );
3831
+ peer_requested = peer_sync_state (msg.start_block , msg.end_block , msg.start_block -1 , peer_sync_state:: sync_t ::peer_sync );
3817
3832
}
3818
3833
enqueue_sync_block ();
3819
3834
}
0 commit comments