controller.rs 2.43 KB
Newer Older
Ryan Olson's avatar
Ryan Olson committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

use super::*;

impl<S: Storage, L: LocalityProvider, M: BlockMetadata> ManagedBlockPool<S, L, M> {
    fn _status(&self) -> AsyncResponse<BlockPoolResult<BlockPoolStatus>> {
        let (req, resp_rx) = StatusReq::new(());

        self.ctrl_tx
            .send(ControlRequest::Status(req))
            .map_err(|_| BlockPoolError::ProgressEngineShutdown)?;

        Ok(resp_rx)
    }

    fn _reset_blocks(
        &self,
        sequence_hashes: &[SequenceHash],
    ) -> AsyncResponse<BlockPoolResult<ResetBlocksResponse>> {
        let (req, resp_rx) = ResetBlocksReq::new(sequence_hashes.into());

        self.ctrl_tx
            .send(ControlRequest::ResetBlocks(req))
            .map_err(|_| BlockPoolError::ProgressEngineShutdown)?;

        Ok(resp_rx)
    }
}

impl<S: Storage, L: LocalityProvider, M: BlockMetadata> BlockPoolController
    for ManagedBlockPool<S, L, M>
{
    fn status_blocking(&self) -> Result<BlockPoolStatus, BlockPoolError> {
        self._status()?
            .blocking_recv()
            .map_err(|_| BlockPoolError::ProgressEngineShutdown)?
    }

    fn reset_blocking(&self) -> Result<(), BlockPoolError> {
        self._reset()?
            .blocking_recv()
            .map_err(|_| BlockPoolError::ProgressEngineShutdown)?
    }

    fn reset_blocks_blocking(
        &self,
        sequence_hashes: &[SequenceHash],
    ) -> Result<ResetBlocksResponse, BlockPoolError> {
        self._reset_blocks(sequence_hashes)?
            .blocking_recv()
            .map_err(|_| BlockPoolError::ProgressEngineShutdown)?
    }
}

#[async_trait::async_trait]
impl<S: Storage, L: LocalityProvider, M: BlockMetadata> AsyncBlockPoolController
    for ManagedBlockPool<S, L, M>
{
    async fn status(&self) -> Result<BlockPoolStatus, BlockPoolError> {
        self._status()?
            .await
            .map_err(|_| BlockPoolError::ProgressEngineShutdown)?
    }

    async fn reset(&self) -> Result<(), BlockPoolError> {
        self._reset()?
            .await
            .map_err(|_| BlockPoolError::ProgressEngineShutdown)?
    }

    async fn reset_blocks(
        &self,
        sequence_hashes: &[SequenceHash],
    ) -> Result<ResetBlocksResponse, BlockPoolError> {
        self._reset_blocks(sequence_hashes)?
            .await
            .map_err(|_| BlockPoolError::ProgressEngineShutdown)?
    }
}