Skip to content

Commit ab9f095

Browse files
committed
using vec<u8> instead of a wrapper DaPayload
1 parent 28519ca commit ab9f095

8 files changed

Lines changed: 37 additions & 54 deletions

File tree

crates/common/da/src/column.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,6 @@ use serde::{Deserialize, Serialize};
22

33
use crate::id::DaColumnId;
44

5-
/// Opaque, scheme-specific encoding of a DA column payload together with its
6-
/// availability evidence.
7-
///
8-
/// The DA core never interprets these bytes. For the PeerDAS backend they are
9-
/// an SSZ-encoded `DataColumnSidecar` (cells, KZG commitments, KZG proofs,
10-
/// signed block header, and commitments inclusion proof). A future non-KZG
11-
/// backend can encode different evidence without changing storage, API, or
12-
/// serving logic.
13-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14-
pub struct DaPayload(Vec<u8>);
15-
16-
impl DaPayload {
17-
pub fn new(bytes: Vec<u8>) -> Self {
18-
Self(bytes)
19-
}
20-
21-
pub fn as_bytes(&self) -> &[u8] {
22-
&self.0
23-
}
24-
}
25-
265
/// Consensus-derived context attached to a candidate column.
276
///
287
/// Only plain data crosses this boundary; no beacon runtime handles.
@@ -42,7 +21,13 @@ pub struct DaContext {
4221
pub struct CandidateColumn {
4322
pub id: DaColumnId,
4423
pub context: DaContext,
45-
pub payload: DaPayload,
24+
/// Opaque, scheme-specific payload bytes carrying the column and its
25+
/// availability evidence. The DA core never interprets them: for the
26+
/// PeerDAS backend they are an SSZ-encoded `DataColumnSidecar` (cells, KZG
27+
/// commitments, KZG proofs, signed block header, and commitments inclusion
28+
/// proof); a future non-KZG backend can encode different evidence without
29+
/// changing storage, API, or serving logic.
30+
pub payload: Vec<u8>,
4631
}
4732

4833
/// A column that passed verification.
@@ -54,12 +39,12 @@ pub struct CandidateColumn {
5439
pub struct VerifiedColumn {
5540
id: DaColumnId,
5641
context: DaContext,
57-
payload: DaPayload,
42+
payload: Vec<u8>,
5843
}
5944

6045
impl VerifiedColumn {
6146
/// Construct a verified column without running verification.
62-
pub fn new_unchecked(id: DaColumnId, context: DaContext, payload: DaPayload) -> Self {
47+
pub fn new_unchecked(id: DaColumnId, context: DaContext, payload: Vec<u8>) -> Self {
6348
Self {
6449
id,
6550
context,
@@ -75,11 +60,11 @@ impl VerifiedColumn {
7560
self.context
7661
}
7762

78-
pub fn payload(&self) -> &DaPayload {
63+
pub fn payload(&self) -> &[u8] {
7964
&self.payload
8065
}
8166

82-
pub fn into_payload(self) -> DaPayload {
67+
pub fn into_payload(self) -> Vec<u8> {
8368
self.payload
8469
}
8570
}

crates/common/da_adapters/kzg_verifier/src/verifier.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl KzgVerifier {
7070

7171
impl DaVerifier for KzgVerifier {
7272
fn verify(&self, candidate: CandidateColumn) -> Result<VerifiedColumn, ValidationError> {
73-
let sidecar = self.decode(candidate.payload.as_bytes())?;
73+
let sidecar = self.decode(&candidate.payload)?;
7474

7575
// Identifier consistency: the id is derived from the sidecar's own signed
7676
// header, so a candidate cannot claim a (block root, column) its payload
@@ -136,7 +136,7 @@ mod tests {
136136
polynomial_commitments::{kzg_commitment::KZGCommitment, kzg_proof::KZGProof},
137137
};
138138
use ream_da::{
139-
column::{CandidateColumn, DaContext, DaPayload},
139+
column::{CandidateColumn, DaContext},
140140
error::ValidationError,
141141
id::DaColumnId,
142142
verifier::DaVerifier,
@@ -172,8 +172,8 @@ mod tests {
172172
}
173173
}
174174

175-
fn payload_of(sidecar: &DataColumnSidecar) -> DaPayload {
176-
DaPayload::new(sidecar.as_ssz_bytes())
175+
fn payload_of(sidecar: &DataColumnSidecar) -> Vec<u8> {
176+
sidecar.as_ssz_bytes()
177177
}
178178

179179
/// An honest candidate whose id is derived from the sidecar's own header.
@@ -247,15 +247,15 @@ mod tests {
247247
.expect("a KZG-valid sidecar is accepted");
248248

249249
assert_eq!(verified.id().index(), sidecar.index);
250-
assert_eq!(verified.payload().as_bytes(), sidecar.as_ssz_bytes());
250+
assert_eq!(verified.payload(), sidecar.as_ssz_bytes());
251251
}
252252

253253
#[test]
254254
fn rejects_malformed_payload() {
255255
let candidate = CandidateColumn {
256256
id: DaColumnId::new(B256::ZERO, 0).expect("valid index"),
257257
context: DaContext::default(),
258-
payload: DaPayload::new(vec![0xde, 0xad, 0xbe, 0xef]),
258+
payload: vec![0xde, 0xad, 0xbe, 0xef],
259259
};
260260
assert!(matches!(
261261
verifier().verify(candidate),

crates/common/da_node/src/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ mod tests {
169169

170170
use alloy_primitives::B256;
171171
use ream_da::{
172-
column::{CandidateColumn, DaContext, DaPayload, VerifiedColumn},
172+
column::{CandidateColumn, DaContext, VerifiedColumn},
173173
error::ValidationError,
174174
id::DaColumnId,
175175
store::DaReadStore,
@@ -217,7 +217,7 @@ mod tests {
217217
CandidateColumn {
218218
id: DaColumnId::new(block_root, index).expect("index within range"),
219219
context: DaContext { slot },
220-
payload: DaPayload::new(payload.to_vec()),
220+
payload: payload.to_vec(),
221221
}
222222
}
223223

@@ -255,7 +255,7 @@ mod tests {
255255
.get(&candidate.id)
256256
.expect("get succeeds")
257257
.expect("column is present");
258-
assert_eq!(stored.payload().as_bytes(), candidate.payload.as_bytes());
258+
assert_eq!(stored.payload(), candidate.payload);
259259
}
260260
});
261261

crates/common/da_node/src/store.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
use alloy_primitives::B256;
1111
use ream_da::{
1212
availability::DaAvailability,
13-
column::{DaContext, DaPayload, VerifiedColumn},
13+
column::{DaContext, VerifiedColumn},
1414
error::DaStoreError,
1515
id::{ALL_COLUMNS_MASK, DaColumnId, NUMBER_OF_COLUMNS, column_indices},
1616
store::{DaReadStore, DaWriteStore, InsertOutcome},
@@ -248,7 +248,7 @@ impl DaReadStore for DaFileStore {
248248
Ok(Some(VerifiedColumn::new_unchecked(
249249
*id,
250250
DaContext { slot: entry.slot },
251-
DaPayload::new(bytes),
251+
bytes,
252252
)))
253253
}
254254

@@ -294,7 +294,7 @@ impl DaWriteStore for DaFileStore {
294294
let path = self.column_path(&id, slot);
295295
let tmp_path = path.with_extension("tmp");
296296
let mut file = fs::File::create(&tmp_path)?;
297-
file.write_all(column.payload().as_bytes())?;
297+
file.write_all(column.payload())?;
298298
file.sync_all()?;
299299
fs::rename(&tmp_path, &path)?;
300300

@@ -328,7 +328,7 @@ mod tests {
328328

329329
use alloy_primitives::B256;
330330
use ream_da::{
331-
column::{DaContext, DaPayload, VerifiedColumn},
331+
column::{DaContext, VerifiedColumn},
332332
id::DaColumnId,
333333
store::{DaReadStore, DaWriteStore, InsertOutcome},
334334
};
@@ -347,7 +347,7 @@ mod tests {
347347

348348
fn sample_column(block_root: B256, index: u64, slot: u64, payload: &[u8]) -> VerifiedColumn {
349349
let id = DaColumnId::new(block_root, index).expect("index within range");
350-
VerifiedColumn::new_unchecked(id, DaContext { slot }, DaPayload::new(payload.to_vec()))
350+
VerifiedColumn::new_unchecked(id, DaContext { slot }, payload.to_vec())
351351
}
352352

353353
#[test]
@@ -424,7 +424,7 @@ mod tests {
424424

425425
// The originally stored column is untouched...
426426
let fetched = store.get(&id).expect("get succeeds").expect("present");
427-
assert_eq!(fetched.payload().as_bytes(), b"original");
427+
assert_eq!(fetched.payload(), b"original");
428428
assert_eq!(fetched.context().slot, 10);
429429
// ...and the ignored slot left no orphan file behind.
430430
assert!(!store.column_path(&id, 11).exists());

crates/rpc/da/src/handlers/column.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::handlers::block_root_from_id;
1414
/// JSON view of a stored column.
1515
///
1616
/// The payload travels as a `0x`-hex string, symmetric with the
17-
/// ingest envelope, instead of `DaPayload`'s raw byte array.
17+
/// ingest envelope, instead of the raw payload bytes.
1818
///
1919
/// TODO: this hex-JSON form is the dev/debug interface, not the final wire
2020
/// format. The serving path's real consumer is the local beacon, which wants the
@@ -36,7 +36,7 @@ impl From<VerifiedColumn> for ColumnResponse {
3636
block_root: id.block_root(),
3737
index: id.index(),
3838
slot: column.context().slot,
39-
payload: alloy_primitives::hex::encode_prefixed(column.payload().as_bytes()),
39+
payload: alloy_primitives::hex::encode_prefixed(column.payload()),
4040
}
4141
}
4242
}

crates/rpc/da/src/handlers/ingest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use actix_web::{
55
use alloy_primitives::B256;
66
use ream_api_types_common::error::ApiError;
77
use ream_da::{
8-
column::{CandidateColumn, DaContext, DaPayload},
8+
column::{CandidateColumn, DaContext},
99
id::DaColumnId,
1010
};
1111
use ream_da_node::{error::IngestionError, ingest::DaIngestHandle};
@@ -33,7 +33,7 @@ impl IngestRequest {
3333
Ok(CandidateColumn {
3434
id,
3535
context: DaContext { slot: self.slot },
36-
payload: DaPayload::new(payload),
36+
payload,
3737
})
3838
}
3939
}

crates/rpc/da/src/handlers/retention.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ pub async fn post_retention(
2828
.map_err(|err| match err {
2929
// Mirrors `/ingest`: transient overload is a retryable 503, a closed
3030
// service is an internal fault (500).
31-
IngestionError::Overloaded => {
32-
ApiError::ServiceUnavailable("verification queue is full; retry shortly".to_string())
33-
}
31+
IngestionError::Overloaded => ApiError::ServiceUnavailable(
32+
"verification queue is full; retry shortly".to_string(),
33+
),
3434
IngestionError::Closed => {
3535
ApiError::InternalError("verification service is unavailable".to_string())
3636
}

crates/rpc/da/src/tests.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
use actix_web::{App, http::StatusCode, test, web::Data};
1313
use alloy_primitives::B256;
1414
use ream_da::{
15-
column::{DaContext, DaPayload, VerifiedColumn},
15+
column::{DaContext, VerifiedColumn},
1616
id::DaColumnId,
1717
store::{DaReadStore, DaWriteStore},
1818
};
@@ -47,7 +47,7 @@ impl TempStore {
4747
.put(VerifiedColumn::new_unchecked(
4848
id,
4949
DaContext { slot },
50-
DaPayload::new(payload.to_vec()),
50+
payload.to_vec(),
5151
))
5252
.expect("put");
5353
}
@@ -72,9 +72,7 @@ async fn health_reports_ok() {
7272
// No app_data needed: the probe touches neither store nor ingest handle.
7373
let app = test::init_service(App::new().configure(register_routers)).await;
7474

75-
let req = test::TestRequest::get()
76-
.uri("/da/v0/health")
77-
.to_request();
75+
let req = test::TestRequest::get().uri("/da/v0/health").to_request();
7876
let resp = test::call_service(&app, req).await;
7977
assert_eq!(resp.status(), StatusCode::OK);
8078

@@ -116,7 +114,7 @@ async fn ingest_accepts_valid_candidate() {
116114
assert_eq!(candidate.id.block_root(), root);
117115
assert_eq!(candidate.id.index(), 3);
118116
assert_eq!(candidate.context.slot, 42);
119-
assert_eq!(candidate.payload.as_bytes(), &[0xde, 0xad, 0xbe, 0xef]);
117+
assert_eq!(candidate.payload, [0xde, 0xad, 0xbe, 0xef]);
120118
}
121119
other => panic!("expected a candidate, got {other:?}"),
122120
}

0 commit comments

Comments
 (0)