diff --git a/examples/hex-game/tests/hex_game.rs b/examples/hex-game/tests/hex_game.rs index 069e0ac6a6fb..f087000ac703 100644 --- a/examples/hex-game/tests/hex_game.rs +++ b/examples/hex-game/tests/hex_game.rs @@ -21,7 +21,7 @@ async fn hex_game() { let (validator, app_id, creation_chain) = TestValidator::with_current_application::((), Timeouts::default()).await; - let certificate = creation_chain + let start_block = creation_chain .add_block(|block| { let operation = Operation::Start { board_size: 2, @@ -33,8 +33,8 @@ async fn hex_game() { }) .await; - let block = certificate.inner().block(); - let description = block + let description = start_block + .block() .created_blobs() .into_iter() .filter_map(|(blob_id, blob)| { @@ -47,7 +47,7 @@ async fn hex_game() { chain .add_block(|block| { - block.with_messages_from(&certificate); + block.with_messages_from(&start_block); block.with_operation(app_id, Operation::MakeMove { x: 0, y: 0 }); }) .await; @@ -102,7 +102,7 @@ async fn hex_game_clock() { .saturating_sub(TimeDelta::from_millis(1)), ); - let certificate = creation_chain + let start_block = creation_chain .add_block(|block| { let operation = Operation::Start { board_size: 2, @@ -114,8 +114,8 @@ async fn hex_game_clock() { }) .await; - let block = certificate.inner().block(); - let description = block + let description = start_block + .block() .created_blobs() .into_iter() .filter_map(|(blob_id, blob)| { @@ -129,7 +129,7 @@ async fn hex_game_clock() { chain .add_block(|block| { block - .with_messages_from(&certificate) + .with_messages_from(&start_block) .with_operation(app_id, Operation::MakeMove { x: 0, y: 0 }) .with_timestamp(time); }) diff --git a/linera-chain/src/chain.rs b/linera-chain/src/chain.rs index 853f3fc9f1eb..31ddf57f68bd 100644 --- a/linera-chain/src/chain.rs +++ b/linera-chain/src/chain.rs @@ -683,7 +683,7 @@ where round: Option, published_blobs: &[Blob], replaying_oracle_responses: Option>>, - ) -> Result { + ) -> Result<(BlockExecutionOutcome, ResourceTracker), ChainError> { #[cfg(with_metrics)] let _execution_latency = BLOCK_EXECUTION_LATENCY.measure_latency(); @@ -913,7 +913,7 @@ where chain.crypto_hash().await? }; - Ok(BlockExecutionOutcome { + let outcome = BlockExecutionOutcome { messages, previous_message_blocks, state_hash, @@ -921,7 +921,9 @@ where events, blobs, operation_results, - }) + }; + + Ok((outcome, resource_controller.tracker)) } /// Executes a block: first the incoming messages, then the main operation. @@ -933,7 +935,7 @@ where round: Option, published_blobs: &[Blob], replaying_oracle_responses: Option>>, - ) -> Result { + ) -> Result<(BlockExecutionOutcome, ResourceTracker), ChainError> { assert_eq!( block.chain_id, self.execution_state.context().extra().chain_id() diff --git a/linera-chain/src/unit_tests/chain_tests.rs b/linera-chain/src/unit_tests/chain_tests.rs index c59f15f52334..c3710dfd6ee9 100644 --- a/linera-chain/src/unit_tests/chain_tests.rs +++ b/linera-chain/src/unit_tests/chain_tests.rs @@ -228,7 +228,7 @@ async fn test_block_size_limit() -> anyhow::Result<()> { ); // The valid block is accepted... - let outcome = chain + let (outcome, _) = chain .execute_block(&valid_block, time, None, &[], None) .await .unwrap(); @@ -296,7 +296,7 @@ async fn test_application_permissions() -> anyhow::Result<()> { bytes: b"foo".to_vec(), }; let valid_block = make_first_block(chain_id).with_operation(app_operation.clone()); - let outcome = chain + let (outcome, _) = chain .execute_block(&valid_block, time, None, &[], None) .await?; let value = ConfirmedBlock::new(outcome.with(valid_block)); @@ -326,7 +326,7 @@ async fn test_application_permissions() -> anyhow::Result<()> { application.expect_call(ExpectedCall::execute_operation(|_, _| Ok(vec![]))); application.expect_call(ExpectedCall::default_finalize()); let valid_block = make_child_block(&value).with_operation(app_operation); - let outcome = chain + let (outcome, _) = chain .execute_block(&valid_block, time, None, &[], None) .await?; let value = ConfirmedBlock::new(outcome.with(valid_block)); @@ -533,7 +533,10 @@ async fn test_service_as_oracle_response_size_limit( application.expect_call(ExpectedCall::default_finalize()); - chain.execute_block(&block, time, None, &[], None).await + chain + .execute_block(&block, time, None, &[], None) + .await + .map(|(outcome, _)| outcome) } /// Tests contract HTTP response size limit. @@ -589,7 +592,10 @@ async fn test_contract_http_response_size_limit( application.expect_call(ExpectedCall::default_finalize()); - chain.execute_block(&block, time, None, &[], None).await + chain + .execute_block(&block, time, None, &[], None) + .await + .map(|(outcome, _)| outcome) } /// Tests service HTTP response size limit. @@ -645,7 +651,10 @@ async fn test_service_http_response_size_limit( application.expect_call(ExpectedCall::default_finalize()); - chain.execute_block(&block, time, None, &[], None).await + chain + .execute_block(&block, time, None, &[], None) + .await + .map(|(outcome, _)| outcome) } /// Sets up a test with a dummy [`MockApplication`]. diff --git a/linera-core/src/chain_worker/actor.rs b/linera-core/src/chain_worker/actor.rs index e424f8f88585..d5a54ec1f861 100644 --- a/linera-core/src/chain_worker/actor.rs +++ b/linera-core/src/chain_worker/actor.rs @@ -22,7 +22,7 @@ use linera_chain::{ ChainStateView, }; use linera_execution::{ - ExecutionStateView, Query, QueryContext, QueryOutcome, ServiceRuntimeEndpoint, + ExecutionStateView, Query, QueryContext, QueryOutcome, ResourceTracker, ServiceRuntimeEndpoint, ServiceSyncRuntime, }; use linera_storage::Storage; @@ -88,7 +88,7 @@ where round: Option, published_blobs: Vec, #[debug(skip)] - callback: oneshot::Sender>, + callback: oneshot::Sender>, }, /// Process a leader timeout issued for this multi-owner chain. diff --git a/linera-core/src/chain_worker/state/attempted_changes.rs b/linera-core/src/chain_worker/state/attempted_changes.rs index d48adcb9949f..013d4bafbb2b 100644 --- a/linera-core/src/chain_worker/state/attempted_changes.rs +++ b/linera-core/src/chain_worker/state/attempted_changes.rs @@ -367,7 +367,7 @@ where chain.execution_state = execution_state; outcome.clone() } else { - chain + let (outcome, _resources) = chain .execute_block( &proposed_block, local_time, @@ -375,7 +375,8 @@ where &published_blobs, oracle_responses, ) - .await? + .await?; + outcome }; // We should always agree on the messages and state hash. ensure!( diff --git a/linera-core/src/chain_worker/state/mod.rs b/linera-core/src/chain_worker/state/mod.rs index 524775dcbac4..0c34a3788f73 100644 --- a/linera-core/src/chain_worker/state/mod.rs +++ b/linera-core/src/chain_worker/state/mod.rs @@ -26,7 +26,7 @@ use linera_chain::{ ChainError, ChainStateView, }; use linera_execution::{ - ExecutionStateView, Query, QueryContext, QueryOutcome, ServiceRuntimeEndpoint, + ExecutionStateView, Query, QueryContext, QueryOutcome, ResourceTracker, ServiceRuntimeEndpoint, }; use linera_storage::{Clock as _, Storage}; use linera_views::views::{ClonableView, ViewError}; @@ -186,12 +186,12 @@ where block: ProposedBlock, round: Option, published_blobs: &[Blob], - ) -> Result<(Block, ChainInfoResponse), WorkerError> { - let (block, response) = ChainWorkerStateWithTemporaryChanges::new(self) + ) -> Result<(Block, ResourceTracker, ChainInfoResponse), WorkerError> { + let (block, resources, response) = ChainWorkerStateWithTemporaryChanges::new(self) .await .stage_block_execution(block, round, published_blobs) .await?; - Ok((block, response)) + Ok((block, resources, response)) } /// Processes a leader timeout issued for this multi-owner chain. diff --git a/linera-core/src/chain_worker/state/temporary_changes.rs b/linera-core/src/chain_worker/state/temporary_changes.rs index a8e3b0b6e8e2..0cad81d3f92c 100644 --- a/linera-core/src/chain_worker/state/temporary_changes.rs +++ b/linera-core/src/chain_worker/state/temporary_changes.rs @@ -16,7 +16,7 @@ use linera_chain::{ manager, types::Block, }; -use linera_execution::{Query, QueryOutcome}; +use linera_execution::{Query, QueryOutcome, ResourceTracker}; use linera_storage::{Clock as _, Storage}; use linera_views::views::{ClonableView, View}; #[cfg(with_testing)] @@ -122,14 +122,14 @@ where block: ProposedBlock, round: Option, published_blobs: &[Blob], - ) -> Result<(Block, ChainInfoResponse), WorkerError> { + ) -> Result<(Block, ResourceTracker, ChainInfoResponse), WorkerError> { self.0.ensure_is_active().await?; let local_time = self.0.storage.clock().current_time(); let signer = block.authenticated_signer; let (_, committee) = self.0.chain.current_committee()?; block.check_proposal_size(committee.policy().maximum_block_proposal_size)?; - let outcome = self + let (outcome, resources) = self .execute_block(&block, local_time, round, published_blobs) .await?; @@ -145,7 +145,7 @@ where .await?; } - Ok((outcome.with(block), response)) + Ok((outcome.with(block), resources, response)) } /// Validates a proposal's signatures; returns `manager::Outcome::Skip` if we already voted @@ -217,8 +217,10 @@ where let outcome = if let Some(outcome) = outcome { outcome.clone() } else { - self.execute_block(block, local_time, round.multi_leader(), published_blobs) - .await? + let (outcome, _resources) = self + .execute_block(block, local_time, round.multi_leader(), published_blobs) + .await?; + outcome }; ensure!( @@ -316,8 +318,8 @@ where local_time: Timestamp, round: Option, published_blobs: &[Blob], - ) -> Result { - let outcome = + ) -> Result<(BlockExecutionOutcome, ResourceTracker), WorkerError> { + let (outcome, resources) = Box::pin( self.0 .chain @@ -328,7 +330,7 @@ where &outcome.state_hash, self.0.chain.execution_state.clone_unchecked()?, ); - Ok(outcome) + Ok((outcome, resources)) } } diff --git a/linera-core/src/local_node.rs b/linera-core/src/local_node.rs index ef7162300d4d..97a2bf1099ed 100644 --- a/linera-core/src/local_node.rs +++ b/linera-core/src/local_node.rs @@ -178,11 +178,13 @@ where round: Option, published_blobs: Vec, ) -> Result<(Block, ChainInfoResponse), LocalNodeError> { - Ok(self + let (block, _resources, response) = self .node .state .stage_block_execution(block, round, published_blobs) - .await?) + .await?; + + Ok((block, response)) } /// Reads blobs from storage. diff --git a/linera-core/src/unit_tests/worker_tests.rs b/linera-core/src/unit_tests/worker_tests.rs index c4e660c28dab..593c4c77e6ec 100644 --- a/linera-core/src/unit_tests/worker_tests.rs +++ b/linera-core/src/unit_tests/worker_tests.rs @@ -3033,7 +3033,7 @@ where timeout_config: TimeoutConfig::default(), }) .with_authenticated_signer(Some(owner0)); - let (block0, _) = env + let (block0, _, _) = env .worker() .stage_block_execution(proposed_block0, None, vec![]) .await?; @@ -3092,7 +3092,7 @@ where // Now owner 0 can propose a block, but owner 1 can't. let proposed_block1 = make_child_block(&value0.clone()); - let (block1, _) = env + let (block1, _, _) = env .worker() .stage_block_execution(proposed_block1.clone(), None, vec![]) .await?; @@ -3139,7 +3139,7 @@ where // Create block2, also at height 1, but different from block 1. let amount = Amount::from_tokens(1); let proposed_block2 = make_child_block(&value0.clone()).with_simple_transfer(chain_1, amount); - let (block2, _) = env + let (block2, _, _) = env .worker() .stage_block_execution(proposed_block2.clone(), None, vec![]) .await?; @@ -3272,7 +3272,7 @@ where ..TimeoutConfig::default() }, }); - let (block0, _) = env + let (block0, _, _) = env .worker() .stage_block_execution(proposed_block0, None, vec![]) .await?; @@ -3373,7 +3373,7 @@ where ..TimeoutConfig::default() }, }); - let (change_ownership_block, _) = env + let (change_ownership_block, _, _) = env .worker() .stage_block_execution(change_ownership_block, None, vec![]) .await?; @@ -3401,7 +3401,7 @@ where .into_proposal_with_round(owner, &signer, Round::MultiLeader(0)) .await .unwrap(); - let (block, _) = env + let (block, _, _) = env .worker() .stage_block_execution(proposal.content.block.clone(), None, vec![]) .await?; @@ -3444,7 +3444,7 @@ where ..TimeoutConfig::default() }, }); - let (block0, _) = env + let (block0, _, _) = env .worker() .stage_block_execution(proposed_block0, None, vec![]) .await?; @@ -3466,7 +3466,7 @@ where .into_proposal_with_round(owner0, &signer, Round::Fast) .await .unwrap(); - let (block1, _) = env + let (block1, _, _) = env .worker() .stage_block_execution(proposed_block1.clone(), None, vec![]) .await?; @@ -3521,7 +3521,7 @@ where env.worker().handle_block_proposal(proposal3).await?; // A validated block certificate from a later round can override the locked fast block. - let (block2, _) = env + let (block2, _, _) = env .worker() .stage_block_execution(proposed_block2.clone(), None, vec![]) .await?; @@ -3583,7 +3583,7 @@ where let proposed_block = make_first_block(chain_id) .with_simple_transfer(chain_id, Amount::ONE) .with_authenticated_signer(Some(public_key.into())); - let (block, _) = env + let (block, _, _) = env .worker() .stage_block_execution(proposed_block, None, vec![]) .await?; diff --git a/linera-core/src/worker.rs b/linera-core/src/worker.rs index 36d9b63dc782..3cf18a3d2c9b 100644 --- a/linera-core/src/worker.rs +++ b/linera-core/src/worker.rs @@ -31,7 +31,7 @@ use linera_chain::{ }, ChainError, ChainStateView, }; -use linera_execution::{ExecutionError, ExecutionStateView, Query, QueryOutcome}; +use linera_execution::{ExecutionError, ExecutionStateView, Query, QueryOutcome, ResourceTracker}; use linera_storage::Storage; use linera_views::views::ViewError; use lru::LruCache; @@ -540,7 +540,7 @@ where block: ProposedBlock, round: Option, published_blobs: Vec, - ) -> Result<(Block, ChainInfoResponse), WorkerError> { + ) -> Result<(Block, ResourceTracker, ChainInfoResponse), WorkerError> { self.query_chain_worker(block.chain_id, move |callback| { ChainWorkerRequest::StageBlockExecution { block, diff --git a/linera-execution/src/resources.rs b/linera-execution/src/resources.rs index b28f5c3c5e72..838c0883d378 100644 --- a/linera-execution/src/resources.rs +++ b/linera-execution/src/resources.rs @@ -29,8 +29,6 @@ pub struct ResourceController { /// The resources used so far by an execution process. #[derive(Copy, Debug, Clone, Default)] pub struct ResourceTracker { - /// The number of blocks created. - pub blocks: u32, /// The total size of the block so far. pub block_size: u64, /// The fuel used so far. @@ -137,12 +135,6 @@ where /// Tracks the creation of a block. pub fn track_block(&mut self) -> Result<(), ExecutionError> { - self.tracker.as_mut().blocks = self - .tracker - .as_mut() - .blocks - .checked_add(1) - .ok_or(ArithmeticError::Overflow)?; self.update_balance(self.policy.block) } diff --git a/linera-sdk/src/test/block.rs b/linera-sdk/src/test/block.rs index df5e738bf013..c9803d3c14cf 100644 --- a/linera-sdk/src/test/block.rs +++ b/linera-sdk/src/test/block.rs @@ -7,20 +7,20 @@ use linera_base::{ abi::ContractAbi, - data_types::{Amount, ApplicationPermissions, Blob, Epoch, Round, Timestamp}, - identifiers::{AccountOwner, ApplicationId, ChainId}, + data_types::{Amount, ApplicationPermissions, Blob, Epoch, Resources, Round, Timestamp}, + identifiers::{AccountOwner, ApplicationId, ChainId, MessageId}, ownership::TimeoutConfig, }; use linera_chain::{ data_types::{ IncomingBundle, LiteValue, LiteVote, MessageAction, ProposedBlock, SignatureAggregator, }, - types::{ConfirmedBlock, ConfirmedBlockCertificate}, + types::{Block, BlockHeader, ConfirmedBlock, ConfirmedBlockCertificate}, }; use linera_core::worker::WorkerError; use linera_execution::{ system::{Recipient, SystemOperation}, - Operation, + Operation, OutgoingMessage, ResourceTracker, }; use super::TestValidator; @@ -48,13 +48,14 @@ impl BlockBuilder { chain_id: ChainId, owner: AccountOwner, epoch: Epoch, - previous_block: Option<&ConfirmedBlockCertificate>, + previous_block: Option<&CertifiedBlock>, validator: TestValidator, ) -> Self { - let previous_block_hash = previous_block.map(|certificate| certificate.hash()); + let previous_block_hash = previous_block.map(|block| block.certificate.hash()); let height = previous_block - .map(|certificate| { - certificate + .map(|block| { + block + .certificate .inner() .height() .try_add_one() @@ -172,34 +173,31 @@ impl BlockBuilder { } /// Receives all direct messages that were sent to this chain by the given certificate. - pub fn with_messages_from(&mut self, certificate: &ConfirmedBlockCertificate) -> &mut Self { - self.with_messages_from_by_action(certificate, MessageAction::Accept) + pub fn with_messages_from(&mut self, block: &CertifiedBlock) -> &mut Self { + self.with_messages_from_by_action(block, MessageAction::Accept) } /// Receives all messages that were sent to this chain by the given certificate. pub fn with_messages_from_by_action( &mut self, - certificate: &ConfirmedBlockCertificate, + block: &CertifiedBlock, action: MessageAction, ) -> &mut Self { - let origin = certificate.inner().chain_id(); - let bundles = - certificate - .message_bundles_for(self.block.chain_id) - .map(|(_epoch, bundle)| IncomingBundle { - origin, - bundle, - action, - }); + let origin = block.certificate.inner().chain_id(); + let bundles = block + .certificate + .message_bundles_for(self.block.chain_id) + .map(|(_epoch, bundle)| IncomingBundle { + origin, + bundle, + action, + }); self.with_incoming_bundles(bundles) } /// Tries to sign the prepared block with the [`TestValidator`]'s keys and return the /// resulting [`Certificate`]. Returns an error if block execution fails. - pub(crate) async fn try_sign( - self, - blobs: &[Blob], - ) -> Result { + pub(crate) async fn try_sign(self, blobs: &[Blob]) -> Result { let published_blobs = self .block .published_blob_ids() @@ -212,7 +210,7 @@ impl BlockBuilder { .clone() }) .collect(); - let (block, _) = self + let (block, resources, _) = self .validator .worker() .stage_block_execution(self.block, None, published_blobs) @@ -231,6 +229,112 @@ impl BlockBuilder { .expect("Failed to sign block") .expect("Committee has more than one test validator"); - Ok(certificate) + Ok(CertifiedBlock { + certificate, + resources, + }) + } +} + +/// A block that has been confirmed and certified by the validators. +#[derive(Clone, Debug)] +pub struct CertifiedBlock { + pub(super) certificate: ConfirmedBlockCertificate, + pub(super) resources: ResourceTracker, +} + +impl CertifiedBlock { + /// Returns the header of this [`CertifiedBlock`]. + pub fn header(&self) -> &BlockHeader { + &self.certificate.inner().block().header + } + + /// Returns the block of this [`CertifiedBlock`]. + pub fn block(&self) -> &Block { + self.certificate.inner().block() + } + + /// Returns the messages in this [`CertifiedBlock`]. + pub fn messages(&self) -> &[Vec] { + self.certificate.inner().block().messages() + } + + /// Returns the number of messages produced by this [`CertifiedBlock`]. + pub fn outgoing_message_count(&self) -> usize { + self.certificate.outgoing_message_count() + } + + /// Returns the [`MessageId`] for the `message_index`th outgoing message produced by the + /// `operation_index`th operation in this [`CertifiedBlock`]. + pub fn message_id_for_operation( + &self, + operation_index: usize, + message_index: u32, + ) -> MessageId { + self.certificate + .inner() + .block() + .message_id_for_operation(operation_index, message_index) + .expect( + "Missing {message_index}th outgoing message \ + produced by {operation_index}th operation", + ) + } + + /// Returns [`true`] if this block used less than the [`Resources`] listed for comparison. + pub fn consumed_less_than_or_equal_resources(&self, resources: Resources) -> bool { + let Resources { + fuel: maximum_fuel, + read_operations: maximum_read_operations, + write_operations: maximum_write_operations, + bytes_to_read, + bytes_to_write, + blobs_to_read, + blobs_to_publish, + blob_bytes_to_read, + blob_bytes_to_publish, + messages: maximum_messages, + message_size, + storage_size_delta, + service_as_oracle_queries, + http_requests: maximum_http_requests, + } = resources; + + let ResourceTracker { + block_size: _, + fuel, + read_operations, + write_operations, + bytes_read, + bytes_written, + blobs_read, + blobs_published, + blob_bytes_read, + blob_bytes_published, + bytes_stored, + operations: _, + operation_bytes: _, + messages, + message_bytes, + http_requests, + service_oracle_queries, + service_oracle_execution: _, + grants: _, + } = self.resources; + + fuel <= maximum_fuel + && read_operations <= maximum_read_operations + && write_operations <= maximum_write_operations + && bytes_read <= bytes_to_read.into() + && bytes_written <= bytes_to_write.into() + && blobs_read <= blobs_to_read + && blobs_published <= blobs_to_publish + && blob_bytes_read <= blob_bytes_to_read.into() + && blob_bytes_published <= blob_bytes_to_publish.into() + && messages <= maximum_messages + && message_bytes <= message_size.into() + && bytes_stored <= storage_size_delta.try_into().unwrap_or(i32::MAX) + && service_oracle_queries <= service_as_oracle_queries + && http_requests <= maximum_http_requests } } diff --git a/linera-sdk/src/test/chain.rs b/linera-sdk/src/test/chain.rs index 62480b0ab44c..a756e0fa1f36 100644 --- a/linera-sdk/src/test/chain.rs +++ b/linera-sdk/src/test/chain.rs @@ -23,7 +23,7 @@ use linera_base::{ identifiers::{AccountOwner, ApplicationId, ChainId, ModuleId}, vm::VmRuntime, }; -use linera_chain::{types::ConfirmedBlockCertificate, ChainExecutionContext}; +use linera_chain::ChainExecutionContext; use linera_core::{data_types::ChainInfoQuery, worker::WorkerError}; use linera_execution::{ system::{SystemOperation, SystemQuery, SystemResponse}, @@ -33,14 +33,14 @@ use linera_storage::Storage as _; use serde::Serialize; use tokio::{fs, sync::Mutex}; -use super::{BlockBuilder, TestValidator}; +use super::{BlockBuilder, CertifiedBlock, TestValidator}; use crate::{ContractAbi, ServiceAbi}; /// A reference to a single microchain inside a [`TestValidator`]. pub struct ActiveChain { key_pair: AccountSecretKey, description: ChainDescription, - tip: Arc>>, + tip: Arc>>, validator: TestValidator, } @@ -209,10 +209,7 @@ impl ActiveChain { /// /// The `block_builder` parameter is a closure that should use the [`BlockBuilder`] parameter /// to provide the block's contents. - pub async fn add_block( - &self, - block_builder: impl FnOnce(&mut BlockBuilder), - ) -> ConfirmedBlockCertificate { + pub async fn add_block(&self, block_builder: impl FnOnce(&mut BlockBuilder)) -> CertifiedBlock { self.try_add_block(block_builder) .await .expect("Failed to execute block.") @@ -226,7 +223,7 @@ impl ActiveChain { &self, block_builder: impl FnOnce(&mut BlockBuilder), blobs: Vec, - ) -> ConfirmedBlockCertificate { + ) -> CertifiedBlock { self.try_add_block_with_blobs(block_builder, blobs) .await .expect("Failed to execute block.") @@ -239,7 +236,7 @@ impl ActiveChain { pub async fn try_add_block( &self, block_builder: impl FnOnce(&mut BlockBuilder), - ) -> Result { + ) -> Result { self.try_add_block_with_blobs(block_builder, vec![]).await } @@ -254,7 +251,7 @@ impl ActiveChain { &self, block_builder: impl FnOnce(&mut BlockBuilder), blobs: Vec, - ) -> Result { + ) -> Result { let mut tip = self.tip.lock().await; let mut block = BlockBuilder::new( self.description.id(), @@ -267,27 +264,27 @@ impl ActiveChain { block_builder(&mut block); // TODO(#2066): Remove boxing once call-stack is shallower - let certificate = Box::pin(block.try_sign(&blobs)).await?; + let block = Box::pin(block.try_sign(&blobs)).await?; let result = self .validator .worker() - .fully_handle_certificate_with_notifications(certificate.clone(), &()) + .fully_handle_certificate_with_notifications(block.certificate.clone(), &()) .await; if let Err(WorkerError::BlobsNotFound(_)) = &result { self.validator.storage().maybe_write_blobs(&blobs).await?; self.validator .worker() - .fully_handle_certificate_with_notifications(certificate.clone(), &()) + .fully_handle_certificate_with_notifications(block.certificate.clone(), &()) .await .expect("Rejected certificate"); } else { result.expect("Rejected certificate"); } - *tip = Some(certificate.clone()); + *tip = Some(block.clone()); - Ok(certificate) + Ok(block) } /// Receives all queued messages in all inboxes of this microchain. @@ -391,7 +388,7 @@ impl ActiveChain { let module_id = ModuleId::new(contract_blob_hash, service_blob_hash, vm_runtime); - let certificate = self + let block = self .add_block_with_blobs( |block| { block.with_system_operation(SystemOperation::PublishModule { module_id }); @@ -400,9 +397,9 @@ impl ActiveChain { ) .await; - let block = certificate.inner().block(); - assert_eq!(block.messages().len(), 1); - assert_eq!(block.messages()[0].len(), 0); + let messages = block.messages(); + assert_eq!(messages.len(), 1); + assert_eq!(messages[0].len(), 0); module_id.with_abi() } @@ -508,9 +505,7 @@ impl ActiveChain { .await .as_ref() .expect("Block was not successfully added") - .inner() - .block() - .header + .header() .height } @@ -539,7 +534,7 @@ impl ActiveChain { let parameters = serde_json::to_vec(¶meters).unwrap(); let instantiation_argument = serde_json::to_vec(&instantiation_argument).unwrap(); - let creation_certificate = self + let creation_block = self .add_block(|block| { block.with_system_operation(SystemOperation::CreateApplication { module_id: module_id.forget_abi(), @@ -550,14 +545,14 @@ impl ActiveChain { }) .await; - let block = creation_certificate.inner().block(); - assert_eq!(block.messages().len(), 1); - assert!(block.messages()[0].is_empty()); + let messages = creation_block.messages(); + assert_eq!(messages.len(), 1); + assert!(messages[0].is_empty()); let description = ApplicationDescription { module_id: module_id.forget_abi(), - creator_chain_id: block.header.chain_id, - block_height: block.header.height, + creator_chain_id: creation_block.header().chain_id, + block_height: creation_block.header().height, application_index: 0, parameters, required_application_ids, @@ -691,7 +686,7 @@ impl ActiveChain { &self, application_id: ApplicationId, query: impl Into, - ) -> ConfirmedBlockCertificate + ) -> CertifiedBlock where Abi: ServiceAbi, { @@ -708,13 +703,13 @@ impl ActiveChain { &self, application_id: ApplicationId, query: impl Into, - ) -> Result + ) -> Result where Abi: ServiceAbi, { let QueryOutcome { operations, .. } = self.try_graphql_query(application_id, query).await?; - let certificate = self + let block = self .try_add_block(|block| { for operation in operations { match operation { @@ -732,7 +727,7 @@ impl ActiveChain { }) .await?; - Ok(certificate) + Ok(block) } } diff --git a/linera-sdk/src/test/mod.rs b/linera-sdk/src/test/mod.rs index faeadbaff368..b24a3b1f40e3 100644 --- a/linera-sdk/src/test/mod.rs +++ b/linera-sdk/src/test/mod.rs @@ -31,7 +31,7 @@ pub use { pub use self::mock_stubs::*; #[cfg(with_integration_testing)] pub use self::{ - block::BlockBuilder, + block::{BlockBuilder, CertifiedBlock}, chain::{ActiveChain, TryGraphQLMutationError, TryGraphQLQueryError, TryQueryError}, validator::TestValidator, }; diff --git a/linera-sdk/src/test/validator.rs b/linera-sdk/src/test/validator.rs index f93bae32c1ee..0461251a9eba 100644 --- a/linera-sdk/src/test/validator.rs +++ b/linera-sdk/src/test/validator.rs @@ -323,16 +323,15 @@ impl TestValidator { .collect(), ); - let certificate = admin_chain + let block = admin_chain .add_block(|block| { block.with_system_operation(SystemOperation::OpenChain(open_chain_config)); }) .await; - let block = certificate.inner().block(); let origin = ChainOrigin::Child { - parent: block.header.chain_id, - block_height: block.header.height, + parent: block.header().chain_id, + block_height: block.header().height, chain_index: 0, };