Skip to content

Commit

Permalink
fix(host-runner): return Self for State::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelstanley committed Jul 31, 2023
1 parent 4e63107 commit 36d47d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
run: cargo machete .
continue-on-error: true

- name: Check format
- name: Check code format
run: cargo fmt --all -- --check

- name: Run linter
run: cargo clippy -- -A clippy::module_inception -A clippy::new_ret_no_self
run: cargo clippy -- -A clippy::module_inception
42 changes: 21 additions & 21 deletions offchain/host-runner/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ struct Service {
impl Service {
fn new(data: SharedStateData) -> Self {
Self {
state: IdleState::new(data),
state: Box::new(IdleState::new(data)),
}
}

Expand Down Expand Up @@ -271,8 +271,8 @@ struct IdleState {
}

impl IdleState {
fn new(data: SharedStateData) -> Box<dyn State> {
Box::new(Self { data })
fn new(data: SharedStateData) -> Self {
Self { data }
}
}

Expand All @@ -285,7 +285,7 @@ impl State for IdleState {
tracing::debug!("received finish request; changing state to fetch request");
tracing::debug!("request: {:?}", request);
let (_, response_tx) = request.into_inner();
Some(FetchRequestState::new(self.data, response_tx))
Some(Box::new(FetchRequestState::new(self.data, response_tx)))
}
Some(request) = self.data.voucher_rx.recv() => {
Service::handle_invalid(request, self, "voucher")
Expand Down Expand Up @@ -322,11 +322,11 @@ impl FetchRequestState {
finish_response_tx: oneshot::Sender<
Result<RollupRequest, ControllerError>,
>,
) -> Box<dyn State> {
Box::new(Self {
) -> Self {
Self {
data,
finish_response_tx,
})
}
}
}

Expand All @@ -339,31 +339,31 @@ impl State for FetchRequestState {
tracing::debug!("fetch request timed out; setting state to idle");
let timeout_err = ControllerError::FetchRequestTimeout;
send_response(self.finish_response_tx, Err(timeout_err));
Some(IdleState::new(self.data))
Some(Box::new(IdleState::new(self.data)))
}
Some(request) = self.data.inspect_rx.recv() => {
tracing::debug!("received inspect request; setting state to inspect");
tracing::debug!("request: {:?}", request);
let (inspect_request, inspect_response_tx) = request.into_inner();
let rollup_request = RollupRequest::InspectState(inspect_request);
send_response(self.finish_response_tx, Ok(rollup_request));
Some(InspectState::new(self.data, inspect_response_tx))
Some(Box::new(InspectState::new(self.data, inspect_response_tx)))
}
Some(request) = self.data.advance_rx.recv() => {
tracing::debug!("received advance request; setting state to advance");
tracing::debug!("request: {:?}", request);
let (advance_request, advance_response_tx) = request.into_inner();
let rollup_request = RollupRequest::AdvanceState(advance_request);
send_response(self.finish_response_tx, Ok(rollup_request));
Some(AdvanceState::new(self.data, advance_response_tx))
Some(Box::new(AdvanceState::new(self.data, advance_response_tx)))
}
Some(request) = self.data.finish_rx.recv() => {
tracing::debug!("received finish request; terminating previous finish request");
tracing::debug!("request: {:?}", request);
let timeout_err = ControllerError::FetchRequestTimeout;
send_response(self.finish_response_tx, Err(timeout_err));
let (_, response_tx) = request.into_inner();
Some(FetchRequestState::new(self.data, response_tx))
Some(Box::new(FetchRequestState::new(self.data, response_tx)))
}
Some(request) = self.data.voucher_rx.recv() => {
Service::handle_invalid(request, self, "voucher")
Expand Down Expand Up @@ -399,12 +399,12 @@ impl InspectState {
fn new(
data: SharedStateData,
inspect_response_tx: oneshot::Sender<InspectResult>,
) -> Box<dyn State> {
Box::new(Self {
) -> Self {
Self {
data,
inspect_response_tx,
reports: vec![],
})
}
}
}

Expand All @@ -422,7 +422,7 @@ impl State for InspectState {
FinishStatus::Reject => InspectResult::rejected(self.reports),
};
send_response(self.inspect_response_tx, result);
Some(FetchRequestState::new(self.data, response_tx))
Some(Box::new(FetchRequestState::new(self.data, response_tx)))
}
Some(request) = self.data.report_rx.recv() => {
tracing::debug!("received report request");
Expand All @@ -440,7 +440,7 @@ impl State for InspectState {
let result = InspectResult::exception(self.reports, exception);
send_response(self.inspect_response_tx, result);
send_response(exception_response_tx, Ok(()));
Some(IdleState::new(self.data))
Some(Box::new(IdleState::new(self.data)))
}
Some(request) = self.data.voucher_rx.recv() => {
Service::handle_invalid(request, self, "voucher")
Expand Down Expand Up @@ -472,14 +472,14 @@ impl AdvanceState {
fn new(
data: SharedStateData,
advance_response_tx: oneshot::Sender<AdvanceResult>,
) -> Box<dyn State> {
Box::new(Self {
) -> Self {
Self {
data,
advance_response_tx,
vouchers: vec![],
notices: vec![],
reports: vec![],
})
}
}
}

Expand Down Expand Up @@ -507,7 +507,7 @@ impl State for AdvanceState {
},
};
send_response(self.advance_response_tx, result);
Some(FetchRequestState::new(self.data, response_tx))
Some(Box::new(FetchRequestState::new(self.data, response_tx)))
}
Some(request) = self.data.voucher_rx.recv() => {
tracing::debug!("received voucher request");
Expand Down Expand Up @@ -546,7 +546,7 @@ impl State for AdvanceState {
);
send_response(self.advance_response_tx, result);
send_response(exception_response_tx, Ok(()));
Some(IdleState::new(self.data))
Some(Box::new(IdleState::new(self.data)))
}
Some(request) = self.data.shutdown_rx.recv() => {
Service::shutdown(request)
Expand Down

0 comments on commit 36d47d6

Please sign in to comment.