Skip to content

Commit

Permalink
feat: [MR-552] Define RejectCode::SysUnknown and error codes (#1380)
Browse files Browse the repository at this point in the history
[[MR-552]] Define new `RejectCode` variant `SysUnknown` (for when the
response to a best-effort call is unknown) and two `ErrorCode` variants
-- `DeadlineExpired` and `ResponseDropped` -- to be used when expiring
best-effort calls or, respectively, when dropping best-effort responses.

[MR-552]:
https://dfinity.atlassian.net/browse/MR-552?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
alin-at-dfinity authored Sep 11, 2024
1 parent 1a14c58 commit bfba799
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 9 deletions.
4 changes: 2 additions & 2 deletions rs/canonical_state/src/encoding/tests/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ fn try_from_reject_context_code_zero() {
#[test]
fn try_from_reject_context_code_out_of_range() {
let context = types::RejectContext {
code: RejectCode::CanisterError as u8 + 1,
code: RejectCode::SysUnknown as u8 + 1,
message: "Oops".into(),
};

assert_matches!(
RejectContext::try_from(context),
Err(ProxyDecodeError::ValueOutOfRange { typ, err }) if typ == "RejectContext" && err == "6"
Err(ProxyDecodeError::ValueOutOfRange { typ, err }) if typ == "RejectContext" && err == "7"
);
}
8 changes: 4 additions & 4 deletions rs/canonical_state/tests/hash_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ fn reject_code_change_guard() {
// the name.
assert_eq!(
[
62, 95, 239, 10, 9, 26, 135, 101, 93, 198, 15, 123, 76, 160, 97, 217, 51, 216, 73, 141,
199, 167, 113, 136, 162, 143, 206, 234, 246, 179, 138, 81
164, 247, 215, 228, 32, 171, 22, 158, 40, 35, 206, 31, 89, 173, 147, 55, 135, 189, 153,
27, 98, 182, 186, 164, 111, 209, 225, 96, 101, 13, 21, 189
],
hasher.finish()
);
Expand Down Expand Up @@ -197,8 +197,8 @@ fn error_code_change_guard() {
// the name.
assert_eq!(
[
49, 160, 44, 253, 61, 181, 131, 134, 148, 115, 119, 247, 83, 108, 123, 1, 163, 212,
137, 11, 99, 122, 199, 16, 89, 105, 87, 234, 200, 211, 76, 96
182, 138, 143, 247, 243, 232, 107, 63, 92, 206, 38, 118, 216, 57, 9, 207, 108, 209, 25,
104, 54, 48, 195, 235, 98, 96, 17, 181, 111, 140, 146, 247
],
hasher.finish()
);
Expand Down
2 changes: 2 additions & 0 deletions rs/execution_environment/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,7 @@ fn dashboard_label_value_from(code: ErrorCode) -> &'static str {
CanisterWasmModuleNotFound => "Canister Wasm Module Not Found",
CanisterAlreadyInstalled => "Canister Already Installed",
CanisterWasmMemoryLimitExceeded => "Canister exceeded its Wasm memory limit",
DeadlineExpired => "Best-effort call deadline has expired",
ResponseDropped => "Best-effort response was dropped",
}
}
3 changes: 3 additions & 0 deletions rs/protobuf/def/state/ingress/v1/ingress.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ enum ErrorCode {
ERROR_CODE_CANISTER_ALREADY_INSTALLED = 538;
ERROR_CODE_CANISTER_WASM_MEMORY_LIMIT_EXCEEDED = 539;
ERROR_CODE_RESERVED_CYCLES_LIMIT_IS_TOO_LOW = 540;
// 6xx -- `RejectCode::SysUnknown`
ERROR_CODE_DEADLINE_EXPIRED = 601;
ERROR_CODE_RESPONSE_DROPPED = 602;
}

message IngressStatusFailed {
Expand Down
1 change: 1 addition & 0 deletions rs/protobuf/def/types/v1/errors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ enum RejectCode {
REJECT_CODE_DESTINATION_INVALID = 3;
REJECT_CODE_CANISTER_REJECT = 4;
REJECT_CODE_CANISTER_ERROR = 5;
REJECT_CODE_SYS_UNKNOWN = 6;
}
3 changes: 3 additions & 0 deletions rs/protobuf/src/gen/bitcoin/types.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum RejectCode {
DestinationInvalid = 3,
CanisterReject = 4,
CanisterError = 5,
SysUnknown = 6,
}
impl RejectCode {
/// String value of the enum field names used in the ProtoBuf definition.
Expand All @@ -33,6 +34,7 @@ impl RejectCode {
RejectCode::DestinationInvalid => "REJECT_CODE_DESTINATION_INVALID",
RejectCode::CanisterReject => "REJECT_CODE_CANISTER_REJECT",
RejectCode::CanisterError => "REJECT_CODE_CANISTER_ERROR",
RejectCode::SysUnknown => "REJECT_CODE_SYS_UNKNOWN",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand All @@ -44,6 +46,7 @@ impl RejectCode {
"REJECT_CODE_DESTINATION_INVALID" => Some(Self::DestinationInvalid),
"REJECT_CODE_CANISTER_REJECT" => Some(Self::CanisterReject),
"REJECT_CODE_CANISTER_ERROR" => Some(Self::CanisterError),
"REJECT_CODE_SYS_UNKNOWN" => Some(Self::SysUnknown),
_ => None,
}
}
Expand Down
7 changes: 7 additions & 0 deletions rs/protobuf/src/gen/state/state.ingress.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ pub enum ErrorCode {
CanisterAlreadyInstalled = 538,
CanisterWasmMemoryLimitExceeded = 539,
ReservedCyclesLimitIsTooLow = 540,
/// 6xx -- `RejectCode::SysUnknown`
DeadlineExpired = 601,
ResponseDropped = 602,
}
impl ErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
Expand Down Expand Up @@ -296,6 +299,8 @@ impl ErrorCode {
"ERROR_CODE_CANISTER_WASM_MEMORY_LIMIT_EXCEEDED"
}
ErrorCode::ReservedCyclesLimitIsTooLow => "ERROR_CODE_RESERVED_CYCLES_LIMIT_IS_TOO_LOW",
ErrorCode::DeadlineExpired => "ERROR_CODE_DEADLINE_EXPIRED",
ErrorCode::ResponseDropped => "ERROR_CODE_RESPONSE_DROPPED",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand Down Expand Up @@ -387,6 +392,8 @@ impl ErrorCode {
"ERROR_CODE_RESERVED_CYCLES_LIMIT_IS_TOO_LOW" => {
Some(Self::ReservedCyclesLimitIsTooLow)
}
"ERROR_CODE_DEADLINE_EXPIRED" => Some(Self::DeadlineExpired),
"ERROR_CODE_RESPONSE_DROPPED" => Some(Self::ResponseDropped),
_ => None,
}
}
Expand Down
3 changes: 3 additions & 0 deletions rs/protobuf/src/gen/state/types.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub enum RejectCode {
DestinationInvalid = 3,
CanisterReject = 4,
CanisterError = 5,
SysUnknown = 6,
}
impl RejectCode {
/// String value of the enum field names used in the ProtoBuf definition.
Expand All @@ -102,6 +103,7 @@ impl RejectCode {
RejectCode::DestinationInvalid => "REJECT_CODE_DESTINATION_INVALID",
RejectCode::CanisterReject => "REJECT_CODE_CANISTER_REJECT",
RejectCode::CanisterError => "REJECT_CODE_CANISTER_ERROR",
RejectCode::SysUnknown => "REJECT_CODE_SYS_UNKNOWN",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand All @@ -113,6 +115,7 @@ impl RejectCode {
"REJECT_CODE_DESTINATION_INVALID" => Some(Self::DestinationInvalid),
"REJECT_CODE_CANISTER_REJECT" => Some(Self::CanisterReject),
"REJECT_CODE_CANISTER_ERROR" => Some(Self::CanisterError),
"REJECT_CODE_SYS_UNKNOWN" => Some(Self::SysUnknown),
_ => None,
}
}
Expand Down
7 changes: 7 additions & 0 deletions rs/protobuf/src/gen/types/state.ingress.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ pub enum ErrorCode {
CanisterAlreadyInstalled = 538,
CanisterWasmMemoryLimitExceeded = 539,
ReservedCyclesLimitIsTooLow = 540,
/// 6xx -- `RejectCode::SysUnknown`
DeadlineExpired = 601,
ResponseDropped = 602,
}
impl ErrorCode {
/// String value of the enum field names used in the ProtoBuf definition.
Expand Down Expand Up @@ -296,6 +299,8 @@ impl ErrorCode {
"ERROR_CODE_CANISTER_WASM_MEMORY_LIMIT_EXCEEDED"
}
ErrorCode::ReservedCyclesLimitIsTooLow => "ERROR_CODE_RESERVED_CYCLES_LIMIT_IS_TOO_LOW",
ErrorCode::DeadlineExpired => "ERROR_CODE_DEADLINE_EXPIRED",
ErrorCode::ResponseDropped => "ERROR_CODE_RESPONSE_DROPPED",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand Down Expand Up @@ -387,6 +392,8 @@ impl ErrorCode {
"ERROR_CODE_RESERVED_CYCLES_LIMIT_IS_TOO_LOW" => {
Some(Self::ReservedCyclesLimitIsTooLow)
}
"ERROR_CODE_DEADLINE_EXPIRED" => Some(Self::DeadlineExpired),
"ERROR_CODE_RESPONSE_DROPPED" => Some(Self::ResponseDropped),
_ => None,
}
}
Expand Down
3 changes: 3 additions & 0 deletions rs/protobuf/src/gen/types/types.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ pub enum RejectCode {
DestinationInvalid = 3,
CanisterReject = 4,
CanisterError = 5,
SysUnknown = 6,
}
impl RejectCode {
/// String value of the enum field names used in the ProtoBuf definition.
Expand All @@ -338,6 +339,7 @@ impl RejectCode {
RejectCode::DestinationInvalid => "REJECT_CODE_DESTINATION_INVALID",
RejectCode::CanisterReject => "REJECT_CODE_CANISTER_REJECT",
RejectCode::CanisterError => "REJECT_CODE_CANISTER_ERROR",
RejectCode::SysUnknown => "REJECT_CODE_SYS_UNKNOWN",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand All @@ -349,6 +351,7 @@ impl RejectCode {
"REJECT_CODE_DESTINATION_INVALID" => Some(Self::DestinationInvalid),
"REJECT_CODE_CANISTER_REJECT" => Some(Self::CanisterReject),
"REJECT_CODE_CANISTER_ERROR" => Some(Self::CanisterError),
"REJECT_CODE_SYS_UNKNOWN" => Some(Self::SysUnknown),
_ => None,
}
}
Expand Down
22 changes: 20 additions & 2 deletions rs/types/error_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum RejectCode {
DestinationInvalid = 3,
CanisterReject = 4,
CanisterError = 5,
SysUnknown = 6,
}

impl std::fmt::Display for RejectCode {
Expand All @@ -43,6 +44,7 @@ impl RejectCode {
RejectCode::DestinationInvalid => "DESTINATION_INVALID",
RejectCode::CanisterReject => "CANISTER_REJECT",
RejectCode::CanisterError => "CANISTER_ERROR",
RejectCode::SysUnknown => "SYS_UNKNOWN",
}
}
}
Expand All @@ -55,6 +57,7 @@ impl From<RejectCode> for RejectCodeProto {
RejectCode::DestinationInvalid => RejectCodeProto::DestinationInvalid,
RejectCode::CanisterReject => RejectCodeProto::CanisterReject,
RejectCode::CanisterError => RejectCodeProto::CanisterError,
RejectCode::SysUnknown => RejectCodeProto::SysUnknown,
}
}
}
Expand All @@ -73,6 +76,7 @@ impl TryFrom<RejectCodeProto> for RejectCode {
RejectCodeProto::DestinationInvalid => Ok(RejectCode::DestinationInvalid),
RejectCodeProto::CanisterReject => Ok(RejectCode::CanisterReject),
RejectCodeProto::CanisterError => Ok(RejectCode::CanisterError),
RejectCodeProto::SysUnknown => Ok(RejectCode::SysUnknown),
}
}
}
Expand All @@ -86,6 +90,7 @@ impl TryFrom<u64> for RejectCode {
3 => Ok(RejectCode::DestinationInvalid),
4 => Ok(RejectCode::CanisterReject),
5 => Ok(RejectCode::CanisterError),
6 => Ok(RejectCode::SysUnknown),
_ => Err(TryFromError::ValueOutOfRange(code)),
}
}
Expand Down Expand Up @@ -156,6 +161,9 @@ impl From<ErrorCode> for RejectCode {
CanisterWasmModuleNotFound => CanisterError,
CanisterAlreadyInstalled => CanisterError,
CanisterWasmMemoryLimitExceeded => CanisterError,
// Response unknown (best-effort calls only).
DeadlineExpired => SysUnknown,
ResponseDropped => SysUnknown,
}
}
}
Expand Down Expand Up @@ -231,6 +239,9 @@ pub enum ErrorCode {
CanisterAlreadyInstalled = 538,
CanisterWasmMemoryLimitExceeded = 539,
ReservedCyclesLimitIsTooLow = 540,
// 6xx -- `RejectCode::SysUnknown`
DeadlineExpired = 601,
ResponseDropped = 602,
}

impl TryFrom<ErrorCodeProto> for ErrorCode {
Expand Down Expand Up @@ -330,6 +341,8 @@ impl TryFrom<ErrorCodeProto> for ErrorCode {
ErrorCodeProto::ReservedCyclesLimitIsTooLow => {
Ok(ErrorCode::ReservedCyclesLimitIsTooLow)
}
ErrorCodeProto::DeadlineExpired => Ok(ErrorCode::DeadlineExpired),
ErrorCodeProto::ResponseDropped => Ok(ErrorCode::ResponseDropped),
}
}
}
Expand Down Expand Up @@ -418,6 +431,8 @@ impl From<ErrorCode> for ErrorCodeProto {
ErrorCodeProto::CanisterWasmMemoryLimitExceeded
}
ErrorCode::ReservedCyclesLimitIsTooLow => ErrorCodeProto::ReservedCyclesLimitIsTooLow,
ErrorCode::DeadlineExpired => ErrorCodeProto::DeadlineExpired,
ErrorCode::ResponseDropped => ErrorCodeProto::ResponseDropped,
}
}
}
Expand Down Expand Up @@ -538,7 +553,9 @@ impl UserError {
| ErrorCode::InsufficientCyclesInMessageMemoryGrow
| ErrorCode::CanisterSnapshotNotFound
| ErrorCode::CanisterHeapDeltaRateLimited
| ErrorCode::CanisterWasmMemoryLimitExceeded => false,
| ErrorCode::CanisterWasmMemoryLimitExceeded
| ErrorCode::DeadlineExpired
| ErrorCode::ResponseDropped => false,
}
}

Expand Down Expand Up @@ -609,6 +626,7 @@ mod tests {
502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514,
517, 520, 521, 522, 524, 525, 526, 527, 528, 529, 530, 531, 532,
533, 534, 535, 536, 537, 538, 539, 540,
601, 602,
]
);
}
Expand All @@ -629,7 +647,7 @@ mod tests {
// See note [Handling changes to Enums in Replicated State] for how to proceed.
assert_eq!(
RejectCode::iter().map(|x| x as i32).collect::<Vec<i32>>(),
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 6]
);
}
}
5 changes: 4 additions & 1 deletion rs/types/types/src/exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ impl<K: ExhaustiveSet + std::cmp::Ord> ExhaustiveSet for BTreeSet<K> {

impl ExhaustiveSet for RejectCode {
fn exhaustive_set<R: RngCore + CryptoRng>(_: &mut R) -> Vec<Self> {
RejectCode::iter().collect()
RejectCode::iter()
// TODO(MR-610): Drop this after `SysUnknown` is supported on mainnet.
.filter(|code| *code != RejectCode::SysUnknown)
.collect()
}
}

Expand Down

0 comments on commit bfba799

Please sign in to comment.