|
|
@@ -81,44 +81,71 @@ impl ProtocolSync {
|
|
|
}
|
|
|
|
|
|
async fn handle_receive_request(self: Arc<Self>) -> Result<()> {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_request()", "ProtocolSync::handle_receive_request() [START]");
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_request()",
|
|
|
+ "START"
|
|
|
+ );
|
|
|
loop {
|
|
|
let order = match self.request_sub.receive().await {
|
|
|
Ok(v) => v,
|
|
|
Err(e) => {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_request()", "ProtocolSync::handle_receive_request(): recv fail: {}", e);
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_request()",
|
|
|
+ "recv fail: {}",
|
|
|
+ e
|
|
|
+ );
|
|
|
continue
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_request()", "ProtocolSync::handle_receive_request() received {:?}", order);
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_request()",
|
|
|
+ "received {:?}",
|
|
|
+ order
|
|
|
+ );
|
|
|
|
|
|
// Extra validations can be added here
|
|
|
let key = order.slot;
|
|
|
let blocks = match self.state.read().await.blockchain.get_blocks_after(key, BATCH) {
|
|
|
Ok(v) => v,
|
|
|
Err(e) => {
|
|
|
- error!(target: "consensus::protocol_sync::handle_receive_request()", "ProtocolSync::handle_receive_request(): get_blocks_after fail: {}", e);
|
|
|
+ error!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_request()",
|
|
|
+ "get_blocks_after fail: {}",
|
|
|
+ e
|
|
|
+ );
|
|
|
continue
|
|
|
}
|
|
|
};
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_request()", "ProtocolSync::handle_receive_request(): Found {} blocks", blocks.len());
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_request()",
|
|
|
+ "Found {} blocks",
|
|
|
+ blocks.len()
|
|
|
+ );
|
|
|
|
|
|
let response = BlockResponse { blocks };
|
|
|
if let Err(e) = self.channel.send(response).await {
|
|
|
- error!(target: "consensus::protocol_sync::handle_receive_request()", "ProtocolSync::handle_receive_request(): channel send fail: {}", e)
|
|
|
+ error!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_request()",
|
|
|
+ "channel send fail: {}",
|
|
|
+ e
|
|
|
+ )
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async fn handle_receive_block(self: Arc<Self>) -> Result<()> {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_block()", "ProtocolSync::handle_receive_block() [START]");
|
|
|
+ debug!(target: "consensus::protocol_sync::handle_receive_block()", "START");
|
|
|
let exclude_list = vec![self.channel.address()];
|
|
|
loop {
|
|
|
let info = match self.block_sub.receive().await {
|
|
|
Ok(v) => v,
|
|
|
Err(e) => {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_block()", "ProtocolSync::handle_receive_block(): recv fail: {}", e);
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_block()",
|
|
|
+ "recv fail: {}",
|
|
|
+ e
|
|
|
+ );
|
|
|
continue
|
|
|
}
|
|
|
};
|
|
|
@@ -136,55 +163,76 @@ impl ProtocolSync {
|
|
|
if current >= slot {
|
|
|
debug!(
|
|
|
target: "consensus::protocol_sync::handle_receive_block()",
|
|
|
- "ProtocolSync::handle_receive_block(): node runs in consensus mode, skipping..."
|
|
|
+ "node runs in consensus mode, skipping..."
|
|
|
);
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- info!(target: "consensus::protocol_sync::handle_receive_block()", "ProtocolSync::handle_receive_block(): Received block: {}", info.blockhash());
|
|
|
+ info!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_block()",
|
|
|
+ "Received block: {}",
|
|
|
+ info.blockhash()
|
|
|
+ );
|
|
|
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_block()", "ProtocolSync::handle_receive_block(): Processing received block");
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_block()",
|
|
|
+ "Processing received block"
|
|
|
+ );
|
|
|
let info_copy = (*info).clone();
|
|
|
match self.state.write().await.receive_finalized_block(info_copy.clone()).await {
|
|
|
Ok(v) => {
|
|
|
if v {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_block()", "ProtocolProposal::handle_receive_block(): block processed successfully, broadcasting...");
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_block()",
|
|
|
+ "block processed successfully, broadcasting..."
|
|
|
+ );
|
|
|
if let Err(e) =
|
|
|
self.p2p.broadcast_with_exclude(info_copy, &exclude_list).await
|
|
|
{
|
|
|
error!(
|
|
|
target: "consensus::protocol_sync::handle_receive_block()",
|
|
|
- "ProtocolSync::handle_receive_block(): p2p broadcast fail: {}",
|
|
|
+ "p2p broadcast fail: {}",
|
|
|
e
|
|
|
);
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
Err(e) => {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_block()", "ProtocolSync::handle_receive_block(): error processing finalized block: {}", e);
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_block()",
|
|
|
+ "error processing finalized block: {}",
|
|
|
+ e
|
|
|
+ );
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async fn handle_receive_slot_checkpoint_request(self: Arc<Self>) -> Result<()> {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_slot_checkpoint_request()", "ProtocolSync::handle_receive_slot_checkpoint_request() [START]");
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_slot_checkpoint_request()",
|
|
|
+ "START"
|
|
|
+ );
|
|
|
loop {
|
|
|
let request = match self.slot_checkpoin_request_sub.receive().await {
|
|
|
Ok(v) => v,
|
|
|
Err(e) => {
|
|
|
debug!(
|
|
|
target: "consensus::protocol_sync::handle_receive_slot_checkpoint_request()",
|
|
|
- "ProtocolSync::handle_receive_slot_checkpoint_request(): recv fail: {}",
|
|
|
+ "recv fail: {}",
|
|
|
e
|
|
|
);
|
|
|
continue
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_slot_checkpoint_request()", "ProtocolSync::handle_receive_slot_checkpoint_request() received {:?}", request);
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_slot_checkpoint_request()",
|
|
|
+ "received {:?}",
|
|
|
+ request
|
|
|
+ );
|
|
|
|
|
|
// Extra validations can be added here
|
|
|
let key = request.slot;
|
|
|
@@ -197,13 +245,17 @@ impl ProtocolSync {
|
|
|
{
|
|
|
Ok(v) => v,
|
|
|
Err(e) => {
|
|
|
- error!(target: "consensus::protocol_sync::handle_receive_slot_checkpoint_request()", "ProtocolSync::handle_receive_slot_checkpoint_request(): get_slot_checkpoints_after fail: {}", e);
|
|
|
+ error!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_slot_checkpoint_request()",
|
|
|
+ "get_slot_checkpoints_after fail: {}",
|
|
|
+ e
|
|
|
+ );
|
|
|
continue
|
|
|
}
|
|
|
};
|
|
|
debug!(
|
|
|
target: "consensus::protocol_sync::handle_receive_slot_checkpoint_request()",
|
|
|
- "ProtocolSync::handle_receive_slot_checkpoint_request(): Found {} slot checkpoints",
|
|
|
+ "Found {} slot checkpoints",
|
|
|
slot_checkpoints.len()
|
|
|
);
|
|
|
|
|
|
@@ -211,7 +263,7 @@ impl ProtocolSync {
|
|
|
if let Err(e) = self.channel.send(response).await {
|
|
|
error!(
|
|
|
target: "consensus::protocol_sync::handle_receive_slot_checkpoint_request()",
|
|
|
- "ProtocolSync::handle_receive_slot_checkpoint_request(): channel send fail: {}",
|
|
|
+ "channel send fail: {}",
|
|
|
e
|
|
|
)
|
|
|
};
|
|
|
@@ -219,13 +271,20 @@ impl ProtocolSync {
|
|
|
}
|
|
|
|
|
|
async fn handle_receive_slot_checkpoint(self: Arc<Self>) -> Result<()> {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_slot_checkpoint()", "ProtocolSync::handle_receive_slot_checkpoint() [START]");
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_slot_checkpoint()",
|
|
|
+ "START"
|
|
|
+ );
|
|
|
let exclude_list = vec![self.channel.address()];
|
|
|
loop {
|
|
|
let slot_checkpoint = match self.slot_checkpoints_sub.receive().await {
|
|
|
Ok(v) => v,
|
|
|
Err(e) => {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_slot_checkpoint()", "ProtocolSync::handle_receive_slot_checkpoint(): recv fail: {}", e);
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_slot_checkpoint()",
|
|
|
+ "recv fail: {}",
|
|
|
+ e
|
|
|
+ );
|
|
|
continue
|
|
|
}
|
|
|
};
|
|
|
@@ -243,7 +302,7 @@ impl ProtocolSync {
|
|
|
if current >= slot {
|
|
|
debug!(
|
|
|
target: "consensus::protocol_sync::handle_receive_slot_checkpoint()",
|
|
|
- "ProtocolSync::handle_receive_block(): node runs in consensus mode, skipping..."
|
|
|
+ "node runs in consensus mode, skipping..."
|
|
|
);
|
|
|
continue
|
|
|
}
|
|
|
@@ -252,11 +311,14 @@ impl ProtocolSync {
|
|
|
|
|
|
info!(
|
|
|
target: "consensus::protocol_sync::handle_receive_slot_checkpoint()",
|
|
|
- "ProtocolSync::handle_receive_slot_checkpoint(): Received slot checkpoint: {}",
|
|
|
+ "Received slot checkpoint: {}",
|
|
|
slot_checkpoint.slot
|
|
|
);
|
|
|
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_slot_checkpoint()", "ProtocolSync::handle_receive_slot_checkpoint(): Processing received slot checkpoint");
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_slot_checkpoint()",
|
|
|
+ "Processing received slot checkpoint"
|
|
|
+ );
|
|
|
let slot_checkpoint_copy = (*slot_checkpoint).clone();
|
|
|
match self
|
|
|
.state
|
|
|
@@ -267,7 +329,10 @@ impl ProtocolSync {
|
|
|
{
|
|
|
Ok(v) => {
|
|
|
if v {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_slot_checkpoint()", "ProtocolProposal::handle_receive_slot_checkpoint(): slot checkpoint processed successfully, broadcasting...");
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_slot_checkpoint()",
|
|
|
+ "slot checkpoint processed successfully, broadcasting..."
|
|
|
+ );
|
|
|
if let Err(e) = self
|
|
|
.p2p
|
|
|
.broadcast_with_exclude(slot_checkpoint_copy, &exclude_list)
|
|
|
@@ -275,14 +340,18 @@ impl ProtocolSync {
|
|
|
{
|
|
|
error!(
|
|
|
target: "consensus::protocol_sync::handle_receive_slot_checkpoint()",
|
|
|
- "ProtocolSync::handle_receive_slot_checkpoint(): p2p broadcast fail: {}",
|
|
|
+ "p2p broadcast fail: {}",
|
|
|
e
|
|
|
);
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
Err(e) => {
|
|
|
- debug!(target: "consensus::protocol_sync::handle_receive_slot_checkpoint()", "ProtocolSync::handle_receive_slot_checkpoint(): error processing finalized slot checkpoint: {}", e);
|
|
|
+ debug!(
|
|
|
+ target: "consensus::protocol_sync::handle_receive_slot_checkpoint()",
|
|
|
+ "error processing finalized slot checkpoint: {}",
|
|
|
+ e
|
|
|
+ );
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
@@ -292,7 +361,7 @@ impl ProtocolSync {
|
|
|
#[async_trait]
|
|
|
impl ProtocolBase for ProtocolSync {
|
|
|
async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
|
|
|
- debug!(target: "consensus::protocol_sync::start()", "ProtocolSync::start() [START]");
|
|
|
+ debug!(target: "consensus::protocol_sync::start()", "START");
|
|
|
self.jobsman.clone().start(executor.clone());
|
|
|
self.jobsman.clone().spawn(self.clone().handle_receive_request(), executor.clone()).await;
|
|
|
self.jobsman
|
|
|
@@ -304,7 +373,7 @@ impl ProtocolBase for ProtocolSync {
|
|
|
.clone()
|
|
|
.spawn(self.clone().handle_receive_slot_checkpoint(), executor.clone())
|
|
|
.await;
|
|
|
- debug!(target: "consensus::protocol_sync::start()", "ProtocolSync::start() [END]");
|
|
|
+ debug!(target: "consensus::protocol_sync::start()", "END");
|
|
|
Ok(())
|
|
|
}
|
|
|
|