Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions examples/hex-game/tests/hex_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async fn hex_game() {
let (validator, app_id, creation_chain) =
TestValidator::with_current_application::<HexAbi, _, _>((), Timeouts::default()).await;

let certificate = creation_chain
let start_block = creation_chain
.add_block(|block| {
let operation = Operation::Start {
board_size: 2,
Expand All @@ -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)| {
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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)| {
Expand All @@ -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);
})
Expand Down
10 changes: 6 additions & 4 deletions linera-chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ where
round: Option<u32>,
published_blobs: &[Blob],
replaying_oracle_responses: Option<Vec<Vec<OracleResponse>>>,
) -> Result<BlockExecutionOutcome, ChainError> {
) -> Result<(BlockExecutionOutcome, ResourceTracker), ChainError> {
#[cfg(with_metrics)]
let _execution_latency = BLOCK_EXECUTION_LATENCY.measure_latency();

Expand Down Expand Up @@ -913,15 +913,17 @@ where
chain.crypto_hash().await?
};

Ok(BlockExecutionOutcome {
let outcome = BlockExecutionOutcome {
messages,
previous_message_blocks,
state_hash,
oracle_responses,
events,
blobs,
operation_results,
})
};

Ok((outcome, resource_controller.tracker))
}

/// Executes a block: first the incoming messages, then the main operation.
Expand All @@ -933,7 +935,7 @@ where
round: Option<u32>,
published_blobs: &[Blob],
replaying_oracle_responses: Option<Vec<Vec<OracleResponse>>>,
) -> Result<BlockExecutionOutcome, ChainError> {
) -> Result<(BlockExecutionOutcome, ResourceTracker), ChainError> {
assert_eq!(
block.chain_id,
self.execution_state.context().extra().chain_id()
Expand Down
21 changes: 15 additions & 6 deletions linera-chain/src/unit_tests/chain_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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`].
Expand Down
4 changes: 2 additions & 2 deletions linera-core/src/chain_worker/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +88,7 @@ where
round: Option<u32>,
published_blobs: Vec<Blob>,
#[debug(skip)]
callback: oneshot::Sender<Result<(Block, ChainInfoResponse), WorkerError>>,
callback: oneshot::Sender<Result<(Block, ResourceTracker, ChainInfoResponse), WorkerError>>,
},

/// Process a leader timeout issued for this multi-owner chain.
Expand Down
5 changes: 3 additions & 2 deletions linera-core/src/chain_worker/state/attempted_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,16 @@ where
chain.execution_state = execution_state;
outcome.clone()
} else {
chain
let (outcome, _resources) = chain
.execute_block(
&proposed_block,
local_time,
None,
&published_blobs,
oracle_responses,
)
.await?
.await?;
outcome
};
// We should always agree on the messages and state hash.
ensure!(
Expand Down
8 changes: 4 additions & 4 deletions linera-core/src/chain_worker/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -186,12 +186,12 @@ where
block: ProposedBlock,
round: Option<u32>,
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.
Expand Down
20 changes: 11 additions & 9 deletions linera-core/src/chain_worker/state/temporary_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -122,14 +122,14 @@ where
block: ProposedBlock,
round: Option<u32>,
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?;

Expand All @@ -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
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -316,8 +318,8 @@ where
local_time: Timestamp,
round: Option<u32>,
published_blobs: &[Blob],
) -> Result<BlockExecutionOutcome, WorkerError> {
let outcome =
) -> Result<(BlockExecutionOutcome, ResourceTracker), WorkerError> {
let (outcome, resources) =
Box::pin(
self.0
.chain
Expand All @@ -328,7 +330,7 @@ where
&outcome.state_hash,
self.0.chain.execution_state.clone_unchecked()?,
);
Ok(outcome)
Ok((outcome, resources))
}
}

Expand Down
6 changes: 4 additions & 2 deletions linera-core/src/local_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ where
round: Option<u32>,
published_blobs: Vec<Blob>,
) -> 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.
Expand Down
20 changes: 10 additions & 10 deletions linera-core/src/unit_tests/worker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -3272,7 +3272,7 @@ where
..TimeoutConfig::default()
},
});
let (block0, _) = env
let (block0, _, _) = env
.worker()
.stage_block_execution(proposed_block0, None, vec![])
.await?;
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -3444,7 +3444,7 @@ where
..TimeoutConfig::default()
},
});
let (block0, _) = env
let (block0, _, _) = env
.worker()
.stage_block_execution(proposed_block0, None, vec![])
.await?;
Expand All @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down
Loading