Skip to content

Commit

Permalink
chore: display the block number correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
renancloudwalk committed May 29, 2024
1 parent 563bfa1 commit af06c7a
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/eth/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use k8s_openapi::api::core::v1::Pod;
use kube::api::Api;
use kube::api::ListParams;
use kube::Client;
use serde::Deserialize;
use serde::Serialize;
use tokio::sync::mpsc::Sender;
use tokio::sync::mpsc::{self};
use tokio::time::sleep;
Expand Down Expand Up @@ -38,12 +36,6 @@ use crate::infra::metrics;
const RETRY_ATTEMPTS: u32 = 3;
const RETRY_DELAY: Duration = Duration::from_millis(10);

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BlockEntry {
index: u64,
data: Block,
}

#[derive(Clone)]
struct Peer {
address: String,
Expand Down Expand Up @@ -87,13 +79,13 @@ impl Consensus {
if Self::is_leader(leader_name_clone.clone()) {
//TODO add data to consensus-log-transactions
//TODO at the begining of temp-storage, load the consensus-log-transactions so the index becomes clear
tracing::info!(number = ?data.number(), "received block to send to followers");
tracing::info!(number = data.header.number.as_u64(), "received block to send to followers");

//TODO use gRPC instead of jsonrpc
//FIXME for now, this has no colateral efects, but it will have in the future
match Self::append_block_commit_to_followers(data.clone(), followers.clone()).await {
Ok(_) => {
tracing::info!(number = ?data.number(), "Data sent to followers");
tracing::info!(number = data.header.number.as_u64(), "Data sent to followers");
}
Err(e) => {
//TODO rediscover followers on comunication error
Expand All @@ -113,7 +105,7 @@ impl Consensus {

tokio::spawn(async move {
while let Some(data) = receiver.recv().await {
tracing::info!(number = ?data.number(), "Received block");
tracing::info!(number = data.header.number.as_u64(), "Received block");
}
});

Expand Down Expand Up @@ -295,9 +287,7 @@ impl AppendEntryService for AppendEntryServiceImpl {
request: Request<AppendTransactionExecutionsRequest>,
) -> Result<Response<AppendTransactionExecutionsResponse>, Status> {
let executions = request.into_inner().executions;
// Process the transaction executions here

// For example, let's just print the executions
//TODO Process the transaction executions here
for execution in executions {
println!("Received transaction execution: {:?}", execution);
}
Expand All @@ -310,11 +300,14 @@ impl AppendEntryService for AppendEntryServiceImpl {
}

async fn append_block_commit(&self, request: Request<AppendBlockCommitRequest>) -> Result<Response<AppendBlockCommitResponse>, Status> {
let header = request.into_inner().header;
// Process the block commit here
let header = match request.into_inner().header {
Some(header) => header,
None => {
return Err(Status::invalid_argument("empty block header"));
}
};

// For example, let's just print the block header
println!("Received block commit: {:?}", header);
tracing::info!(number = header.number, "appending new block");

Ok(Response::new(AppendBlockCommitResponse {
status: StatusCode::AppendSuccess as i32,
Expand Down

0 comments on commit af06c7a

Please sign in to comment.