Skip to content

Commit 014488b

Browse files
Several corrections to the error handling. (#3981)
## Motivation Several corrections are done to the error handling. ## Proposal The following unrelated simple changes are made: * Removal of `InactiveLocalChain` which is never used. * Addition of the size to `BlockTooLarge`. * Addition of the timestamp to the timestamp errors. * The `InactiveChain` of the `ExecutionError` now contains a specific `ChainId`. * The ChainId of the `InactiveChain` is now printed as `{0}`, no longer as `{0:?}`. ## Test Plan The CI. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links None.
1 parent e2ae185 commit 014488b

File tree

11 files changed

+37
-38
lines changed

11 files changed

+37
-38
lines changed

linera-chain/src/chain.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,9 +866,13 @@ where
866866

867867
self.ensure_is_active(local_time).await?;
868868

869+
let chain_timestamp = *self.execution_state.system.timestamp.get();
869870
ensure!(
870-
*self.execution_state.system.timestamp.get() <= block.timestamp,
871-
ChainError::InvalidBlockTimestamp
871+
chain_timestamp <= block.timestamp,
872+
ChainError::InvalidBlockTimestamp {
873+
parent: chain_timestamp,
874+
new: block.timestamp
875+
}
872876
);
873877
ensure!(
874878
!block.incoming_bundles.is_empty() || !block.operations.is_empty(),

linera-chain/src/data_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl ProposedBlock {
118118
let size = bcs::serialized_size(self)?;
119119
ensure!(
120120
size <= usize::try_from(maximum_block_proposal_size).unwrap_or(usize::MAX),
121-
ChainError::BlockProposalTooLarge
121+
ChainError::BlockProposalTooLarge(size)
122122
);
123123
Ok(())
124124
}

linera-chain/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum ChainError {
4646
#[error("Execution error: {0} during {1:?}")]
4747
ExecutionError(Box<ExecutionError>, ChainExecutionContext),
4848

49-
#[error("The chain being queried is not active {0:?}")]
49+
#[error("The chain being queried is not active {0}")]
5050
InactiveChain(ChainId),
5151
#[error(
5252
"Cannot vote for block proposal of chain {chain_id:?} because a message \
@@ -119,8 +119,10 @@ pub enum ChainError {
119119
UnexpectedPreviousBlockHash,
120120
#[error("Sequence numbers above the maximal value are not usable for blocks")]
121121
InvalidBlockHeight,
122-
#[error("Block timestamp must not be earlier than the parent block's.")]
123-
InvalidBlockTimestamp,
122+
#[error(
123+
"Block timestamp {new} must not be earlier than the parent block's timestamp {parent}"
124+
)]
125+
InvalidBlockTimestamp { parent: Timestamp, new: Timestamp },
124126
#[error("Cannot initiate a new block while the previous one is still pending confirmation")]
125127
PreviousBlockMustBeConfirmedFirst,
126128
#[error("Round number should be at least {0:?}")]
@@ -143,8 +145,8 @@ pub enum ChainError {
143145
CertificateSignatureVerificationFailed { error: String },
144146
#[error("Internal error {0}")]
145147
InternalError(String),
146-
#[error("Block proposal is too large")]
147-
BlockProposalTooLarge,
148+
#[error("Block proposal has size {0} which is too large")]
149+
BlockProposalTooLarge(usize),
148150
#[error(transparent)]
149151
BcsError(#[from] bcs::Error),
150152
#[error("Insufficient balance to pay the fees")]

linera-core/src/client/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ impl<Env: Environment> Client<Env> {
292292
match self.local_node.chain_info(chain_id).await {
293293
Ok(info) => Ok(info),
294294
Err(LocalNodeError::BlobsNotFound(blob_ids)) => {
295+
// If the chain is missing then the error is a WorkerError
296+
// and so a BlobsNotFound
295297
// TODO(#2351): make sure the blobs are legitimate!
296298
let blobs =
297299
RemoteNode::download_blobs(&blob_ids, validators, self.blob_download_timeout)

linera-core/src/local_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub enum LocalNodeError {
6363
#[error("Failed to read blob {blob_id:?} of chain {chain_id:?}")]
6464
CannotReadLocalBlob { chain_id: ChainId, blob_id: BlobId },
6565

66-
#[error("The local node doesn't have an active chain {0:?}")]
66+
#[error("The local node doesn't have an active chain {0}")]
6767
InactiveChain(ChainId),
6868

6969
#[error("The chain info response received from the local node is invalid")]

linera-core/src/node.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub enum NodeError {
195195
WorkerError { error: String },
196196

197197
// This error must be normalized during conversions.
198-
#[error("The chain {0:?} is not active in validator")]
198+
#[error("The chain {0} is not active in validator")]
199199
InactiveChain(ChainId),
200200

201201
// This error must be normalized during conversions.
@@ -222,11 +222,6 @@ pub enum NodeError {
222222
#[error("Validator's response to block proposal failed to include a vote")]
223223
MissingVoteInValidatorResponse,
224224

225-
#[error(
226-
"Failed to update validator because our local node doesn't have an active chain {0:?}"
227-
)]
228-
InactiveLocalChain(ChainId),
229-
230225
#[error("The received chain info response is invalid")]
231226
InvalidChainInfoResponse,
232227
#[error("Unexpected certificate value")]

linera-core/src/unit_tests/client_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ where
25022502
result,
25032503
Err(ChainClientError::LocalNodeError(
25042504
LocalNodeError::WorkerError(WorkerError::ChainError(chain_error))
2505-
)) if matches!(*chain_error, ChainError::BlockProposalTooLarge)
2505+
)) if matches!(*chain_error, ChainError::BlockProposalTooLarge(_))
25062506
);
25072507

25082508
assert_matches!(

linera-core/src/unit_tests/worker_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ where
689689
assert_matches!(
690690
env.worker().handle_block_proposal(block_proposal).await,
691691
Err(WorkerError::ChainError(error))
692-
if matches!(*error, ChainError::InvalidBlockTimestamp)
692+
if matches!(*error, ChainError::InvalidBlockTimestamp { .. })
693693
);
694694
}
695695
Ok(())

linera-execution/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ pub enum ExecutionError {
281281
ContractModuleSend(#[from] linera_base::task::SendError<UserContractCode>),
282282
#[error("Failed to send service code to worker thread: {0:?}")]
283283
ServiceModuleSend(#[from] linera_base::task::SendError<UserServiceCode>),
284+
#[error("The chain being queried is not active {0}")]
285+
InactiveChain(ChainId),
284286
#[error("Blobs not found: {0:?}")]
285287
BlobsNotFound(Vec<BlobId>),
286288
#[error("Events not found: {0:?}")]
@@ -330,8 +332,6 @@ pub enum ExecutionError {
330332
TicksOutOfOrder,
331333
#[error("Application {0:?} is not registered by the chain")]
332334
UnknownApplicationId(Box<ApplicationId>),
333-
#[error("Chain is not active yet.")]
334-
InactiveChain,
335335
#[error("No recorded response for oracle query")]
336336
MissingOracleResponse,
337337
#[error("process_streams was not called for all stream updates")]

linera-execution/src/system.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ where
515515
let admin_id = self
516516
.admin_id
517517
.get()
518-
.ok_or_else(|| ExecutionError::InactiveChain)?;
518+
.ok_or_else(|| ExecutionError::InactiveChain(context.chain_id))?;
519519
let event_id = EventId {
520520
chain_id: admin_id,
521521
stream_id: StreamId::system(EPOCH_STREAM_NAME),
@@ -545,7 +545,7 @@ where
545545
let admin_id = self
546546
.admin_id
547547
.get()
548-
.ok_or_else(|| ExecutionError::InactiveChain)?;
548+
.ok_or_else(|| ExecutionError::InactiveChain(context.chain_id))?;
549549
let event_id = EventId {
550550
chain_id: admin_id,
551551
stream_id: StreamId::system(REMOVED_EPOCH_STREAM_NAME),

0 commit comments

Comments
 (0)