Skip to content

Commit

Permalink
use CryptoHash instead of ChainAndHeight in received_log
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2bd committed Jul 21, 2024
1 parent b8ee184 commit ee11318
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 70 deletions.
13 changes: 5 additions & 8 deletions linera-chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use {linera_base::identifiers::BytecodeId, linera_execution::BytecodeLocation};

use crate::{
data_types::{
Block, BlockExecutionOutcome, ChainAndHeight, ChannelFullName, Event, EventRecord,
IncomingMessage, MessageAction, MessageBundle, Origin, OutgoingMessage, Target,
Block, BlockExecutionOutcome, ChannelFullName, Event, EventRecord, IncomingMessage,
MessageAction, MessageBundle, Origin, OutgoingMessage, Target,
},
inbox::{Cursor, InboxError, InboxStateView},
manager::ChainManager,
Expand Down Expand Up @@ -252,8 +252,8 @@ where
/// Hashes of all certified blocks for this sender.
/// This ends with `block_hash` and has length `usize::from(next_block_height)`.
pub confirmed_log: LogView<C, CryptoHash>,
/// Sender chain and height of all certified blocks known as a receiver (local ordering).
pub received_log: LogView<C, ChainAndHeight>,
/// The hash of all the certified blocks known as a receiver (local ordering).
pub received_log: LogView<C, CryptoHash>,

/// Mailboxes used to receive messages indexed by their origin.
pub inboxes: ReentrantCollectionView<C, Origin, InboxStateView<C>>,
Expand Down Expand Up @@ -630,10 +630,7 @@ where
}
}
// Remember the certificate for future validator/client synchronizations.
self.received_log.push(ChainAndHeight {
chain_id: origin.sender,
height: bundle.height,
});
self.received_log.push(bundle.hash);
Ok(())
}

Expand Down
7 changes: 0 additions & 7 deletions linera-chain/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ impl Block {
}
}

/// A chain ID with a block height.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, SimpleObject)]
pub struct ChainAndHeight {
pub chain_id: ChainId,
pub height: BlockHeight,
}

/// A message received from a block of another chain.
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize, SimpleObject)]
pub struct IncomingMessage {
Expand Down
33 changes: 8 additions & 25 deletions linera-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
use tracing::{debug, error, info, Instrument as _};

use crate::{
data_types::{
BlockHeightRange, ChainInfo, ChainInfoQuery, ChainInfoResponse, ClientOutcome, RoundTimeout,
},
data_types::{ChainInfo, ChainInfoQuery, ChainInfoResponse, ClientOutcome, RoundTimeout},
local_node::{LocalNodeClient, LocalNodeError},
node::{
CrossChainMessageDelivery, LocalValidatorNode, LocalValidatorNodeProvider, NodeError,
Expand Down Expand Up @@ -1071,31 +1069,16 @@ where
response.check(name)?;
let mut certificates = Vec::new();
let mut new_tracker = tracker;
for entry in response.info.requested_received_log {
let query = ChainInfoQuery::new(entry.chain_id)
.with_sent_certificate_hashes_in_range(BlockHeightRange::single(entry.height));
let local_response = node_client
.handle_chain_info_query(query.clone())
.await
.map_err(|error| NodeError::LocalNodeQuery {
for hash in response.info.requested_received_log {
if node_client.has_certificate(hash).await.map_err(|error| {
NodeError::LocalNodeQuery {
error: error.to_string(),
})?;
if !local_response
.info
.requested_sent_certificate_hashes
.is_empty()
{
new_tracker += 1;
}
})? {
// Certificates present in storage have been executed already.
continue;
}

let mut response = node.handle_chain_info_query(query).await?;
let Some(certificate_hash) = response.info.requested_sent_certificate_hashes.pop()
else {
break;
};

let certificate = node.download_certificate(certificate_hash).await?;
let certificate = node.download_certificate(hash).await?;
let CertificateValue::ConfirmedBlock { executed_block, .. } = certificate.value()
else {
return Err(NodeError::InvalidChainInfoResponse);
Expand Down
4 changes: 2 additions & 2 deletions linera-core/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use linera_base::{
identifiers::{ChainDescription, ChainId, Owner},
};
use linera_chain::{
data_types::{ChainAndHeight, IncomingMessage, Medium, MessageBundle},
data_types::{IncomingMessage, Medium, MessageBundle},
manager::ChainManagerInfo,
ChainStateView,
};
Expand Down Expand Up @@ -162,7 +162,7 @@ pub struct ChainInfo {
/// The current number of received certificates (useful for `request_received_log_excluding_first_nth`)
pub count_received_log: usize,
/// The response to `request_received_certificates_excluding_first_nth`
pub requested_received_log: Vec<ChainAndHeight>,
pub requested_received_log: Vec<CryptoHash>,
}

/// The response to an `ChainInfoQuery`
Expand Down
7 changes: 7 additions & 0 deletions linera-core/src/local_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use futures::{
lock::{Mutex, MutexGuard},
};
use linera_base::{
crypto::CryptoHash,
data_types::{ArithmeticError, Blob, BlockHeight, HashedBlob},
identifiers::{BlobId, ChainId, MessageId},
};
Expand Down Expand Up @@ -187,6 +188,12 @@ where
let node = self.lock_node().await;
node.state.storage_client().clone()
}

#[tracing::instrument(level = "trace", skip_all)]
pub(crate) async fn has_certificate(&self, hash: CryptoHash) -> Result<bool, LocalNodeError> {
let client = self.storage_client().await;
Ok(client.contains_certificate(hash).await?)
}
}

impl<S> LocalNodeClient<S>
Expand Down
17 changes: 7 additions & 10 deletions linera-core/src/unit_tests/worker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use linera_base::{
};
use linera_chain::{
data_types::{
Block, BlockExecutionOutcome, BlockProposal, Certificate, ChainAndHeight, ChannelFullName,
Event, HashedCertificateValue, IncomingMessage, LiteVote, Medium, MessageAction, Origin,
Block, BlockExecutionOutcome, BlockProposal, Certificate, ChannelFullName, Event,
HashedCertificateValue, IncomingMessage, LiteVote, Medium, MessageAction, Origin,
OutgoingMessage, SignatureAggregator,
},
test::{make_child_block, make_first_block, BlockTestExt, VoteTestExt},
Expand Down Expand Up @@ -1850,7 +1850,7 @@ where
})
);

let certificate = make_simple_transfer_certificate(
let transfer_certificate = make_simple_transfer_certificate(
ChainDescription::Root(1),
&sender_key_pair,
ChainId::root(2),
Expand All @@ -1864,13 +1864,13 @@ where
.await;

let info = worker
.fully_handle_certificate(certificate.clone(), vec![], vec![])
.fully_handle_certificate(transfer_certificate.clone(), vec![], vec![])
.await?
.info;
assert_eq!(ChainId::root(1), info.chain_id);
assert_eq!(Amount::ZERO, info.chain_balance);
assert_eq!(BlockHeight::from(1), info.next_block_height);
assert_eq!(Some(certificate.hash()), info.block_hash);
assert_eq!(Some(transfer_certificate.hash()), info.block_hash);
assert!(info.manager.pending.is_none());
assert_eq!(
worker
Expand All @@ -1891,7 +1891,7 @@ where
vec![IncomingMessage {
origin: Origin::chain(ChainId::root(1)),
event: Event {
certificate_hash: certificate.hash(),
certificate_hash: transfer_certificate.hash(),
height: BlockHeight::ZERO,
index: 0,
authenticated_signer: None,
Expand Down Expand Up @@ -1950,10 +1950,7 @@ where
assert_eq!(response.info.requested_received_log.len(), 1);
assert_eq!(
response.info.requested_received_log[0],
ChainAndHeight {
chain_id: ChainId::root(1),
height: BlockHeight::ZERO
}
transfer_certificate.hash()
);
Ok(())
}
Expand Down
5 changes: 1 addition & 4 deletions linera-service-graphql-client/gql/service_requests.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ query Chain(
entries
}
receivedLog {
entries {
chainId
height
}
entries
}
inboxes {
keys
Expand Down
16 changes: 2 additions & 14 deletions linera-service-graphql-client/gql/service_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ type CertificateValue {
status: String!
}

"""
A chain ID with a block height.
"""
type ChainAndHeight {
chainId: ChainId!
height: BlockHeight!
}

"""
How to create a chain
"""
Expand Down Expand Up @@ -195,9 +187,9 @@ type ChainStateExtendedView {
"""
confirmedLog: LogView_CryptoHash_b0541e41!
"""
Sender chain and height of all certified blocks known as a receiver (local ordering).
The hash of all the certified blocks known as a receiver (local ordering).
"""
receivedLog: LogView_ChainAndHeight_de85b393!
receivedLog: LogView_CryptoHash_b0541e41!
"""
Mailboxes used to receive messages indexed by their origin.
"""
Expand Down Expand Up @@ -496,10 +488,6 @@ A scalar that can represent any JSON Object value.
"""
scalar JSONObject

type LogView_ChainAndHeight_de85b393 {
entries(start: Int, end: Int): [ChainAndHeight!]!
}

type LogView_CryptoHash_b0541e41 {
entries(start: Int, end: Int): [CryptoHash!]!
}
Expand Down

0 comments on commit ee11318

Please sign in to comment.