Skip to content

Commit 71c37c2

Browse files
authored
make the block exporter context visible in the Storage trait (#3748)
## Motivation #3729 was not enough to re-use `run_with_storage` in the block exporter ## Proposal * Move the new definition to the trait. * Add the necessary associated type. This is a little ugly but the alternative is to have different variants of the `Storage` trait depending on the app using it. This could be done later. ## Test Plan CI
1 parent e1bb7df commit 71c37c2

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

linera-storage/src/db_storage.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ where
456456
{
457457
type Context = ViewContext<ChainRuntimeContext<Self>, Store>;
458458
type Clock = C;
459+
type BlockExporterContext = ViewContext<u32, Store>;
459460

460461
fn clock(&self) -> &C {
461462
&self.clock
@@ -797,6 +798,15 @@ where
797798
fn wasm_runtime(&self) -> Option<WasmRuntime> {
798799
self.wasm_runtime
799800
}
801+
802+
async fn block_exporter_context(
803+
&self,
804+
block_exporter_id: u32,
805+
) -> Result<Self::BlockExporterContext, ViewError> {
806+
let root_key = bcs::to_bytes(&BaseKey::BlockExporterState(block_exporter_id))?;
807+
let store = self.store.clone_with_root_key(&root_key)?;
808+
Ok(ViewContext::create_root_context(store, block_exporter_id).await?)
809+
}
800810
}
801811

802812
impl<Store, C> DbStorage<Store, C>
@@ -892,15 +902,6 @@ where
892902
}
893903
Ok(blob_ids)
894904
}
895-
896-
pub async fn block_exporter_context(
897-
&self,
898-
block_exporter_id: u32,
899-
) -> Result<ViewContext<u32, Store>, ViewError> {
900-
let root_key = bcs::to_bytes(&BaseKey::BlockExporterState(block_exporter_id))?;
901-
let store = self.store.clone_with_root_key(&root_key)?;
902-
Ok(ViewContext::create_root_context(store, block_exporter_id).await?)
903-
}
904905
}
905906

906907
impl<Store> DbStorage<Store, WallClock>

linera-storage/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ pub const DEFAULT_NAMESPACE: &str = "table_linera";
5656
#[cfg_attr(not(web), async_trait)]
5757
#[cfg_attr(web, async_trait(?Send))]
5858
pub trait Storage: Sized {
59-
/// The low-level storage implementation in use.
59+
/// The low-level storage implementation in use by the core protocol (chain workers etc).
6060
type Context: Context<Extra = ChainRuntimeContext<Self>> + Clone + Send + Sync + 'static;
6161

6262
/// The clock type being used.
6363
type Clock: Clock;
6464

65+
/// The low-level storage implementation in use by the block exporter.
66+
type BlockExporterContext: Context<Extra = u32> + Clone + Send + Sync + 'static;
67+
6568
/// Returns the current wall clock time.
6669
fn clock(&self) -> &Self::Clock;
6770

@@ -329,6 +332,11 @@ pub trait Storage: Sized {
329332
}
330333
}
331334
}
335+
336+
async fn block_exporter_context(
337+
&self,
338+
block_exporter_id: u32,
339+
) -> Result<Self::BlockExporterContext, ViewError>;
332340
}
333341

334342
#[derive(Clone)]

0 commit comments

Comments
 (0)