Skip to content

Commit

Permalink
runtime-sdk/consensus: remove RoundRoots invalid variant
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Nov 23, 2023
1 parent 0078a07 commit 4628dbd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 20 deletions.
5 changes: 0 additions & 5 deletions runtime-sdk/src/modules/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,10 @@ impl Module {
let params = Self::params();
<C::Runtime as Runtime>::Core::use_tx_gas(ctx, params.gas_costs.round_root)?;

Check warning on line 265 in runtime-sdk/src/modules/consensus/mod.rs

View check run for this annotation

Codecov / codecov/patch

runtime-sdk/src/modules/consensus/mod.rs#L264-L265

Added lines #L264 - L265 were not covered by tests

if !body.kind.is_valid() {
return Err(Error::InvalidArgument);
}

Ok(
Self::round_roots(ctx, body.runtime_id, body.round)?.map(|rr| match body.kind {
types::RootKind::IO => rr.io_root,
types::RootKind::State => rr.state_root,

Check warning on line 270 in runtime-sdk/src/modules/consensus/mod.rs

View check run for this annotation

Codecov / codecov/patch

runtime-sdk/src/modules/consensus/mod.rs#L268-L270

Added lines #L268 - L270 were not covered by tests
_ => panic!("invalid root kind"), // Covered by the is_valid check above.
}),
)
}
Expand Down
16 changes: 3 additions & 13 deletions runtime-sdk/src/modules/consensus/types.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
use oasis_core_runtime::common::namespace::Namespace;

/// Kind of root.
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
#[cfg_attr(test, derive(PartialEq, Eq))]
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
#[repr(u8)]
pub enum RootKind {
#[default]
Invalid = 0,
State = 1,
IO = 2,
}

impl RootKind {
/// Whether the root kind is valid.
pub fn is_valid(&self) -> bool {
!matches!(self, Self::Invalid)
}
}

/// Internal round root call body.
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
#[cfg_attr(test, derive(PartialEq, Eq))]
#[derive(Clone, Debug, cbor::Encode, cbor::Decode)]
#[cbor(no_default)]
pub struct RoundRootBody {
pub runtime_id: Namespace,
pub round: u64,
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/.vscode/settings.json

This file was deleted.

0 comments on commit 4628dbd

Please sign in to comment.