-
Notifications
You must be signed in to change notification settings - Fork 741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement data columns by network boilerplate #6224
Changes from all commits
5c59e7f
32b27a2
3690a46
d045a6a
3a67dcd
f3bd42c
815599c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,11 @@ use std::marker::PhantomData; | |
use std::sync::Arc; | ||
use tokio_util::codec::{Decoder, Encoder}; | ||
use types::{ | ||
BlobSidecar, ChainSpec, EthSpec, ForkContext, ForkName, Hash256, LightClientBootstrap, | ||
LightClientFinalityUpdate, LightClientOptimisticUpdate, RuntimeVariableList, SignedBeaconBlock, | ||
SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockBellatrix, | ||
SignedBeaconBlockCapella, SignedBeaconBlockDeneb, SignedBeaconBlockElectra, | ||
BlobSidecar, ChainSpec, DataColumnSidecar, EthSpec, ForkContext, ForkName, Hash256, | ||
LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate, | ||
RuntimeVariableList, SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase, | ||
SignedBeaconBlockBellatrix, SignedBeaconBlockCapella, SignedBeaconBlockDeneb, | ||
SignedBeaconBlockElectra, | ||
}; | ||
use unsigned_varint::codec::Uvi; | ||
|
||
|
@@ -70,6 +71,8 @@ impl<E: EthSpec> Encoder<RPCCodedResponse<E>> for SSZSnappyInboundCodec<E> { | |
RPCResponse::BlocksByRoot(res) => res.as_ssz_bytes(), | ||
RPCResponse::BlobsByRange(res) => res.as_ssz_bytes(), | ||
RPCResponse::BlobsByRoot(res) => res.as_ssz_bytes(), | ||
RPCResponse::DataColumnsByRoot(res) => res.as_ssz_bytes(), | ||
RPCResponse::DataColumnsByRange(res) => res.as_ssz_bytes(), | ||
RPCResponse::LightClientBootstrap(res) => res.as_ssz_bytes(), | ||
RPCResponse::LightClientOptimisticUpdate(res) => res.as_ssz_bytes(), | ||
RPCResponse::LightClientFinalityUpdate(res) => res.as_ssz_bytes(), | ||
|
@@ -224,6 +227,8 @@ impl<E: EthSpec> Encoder<OutboundRequest<E>> for SSZSnappyOutboundCodec<E> { | |
}, | ||
OutboundRequest::BlobsByRange(req) => req.as_ssz_bytes(), | ||
OutboundRequest::BlobsByRoot(req) => req.blob_ids.as_ssz_bytes(), | ||
OutboundRequest::DataColumnsByRange(req) => req.as_ssz_bytes(), | ||
OutboundRequest::DataColumnsByRoot(req) => req.data_column_ids.as_ssz_bytes(), | ||
OutboundRequest::Ping(req) => req.as_ssz_bytes(), | ||
OutboundRequest::MetaData(_) => return Ok(()), // no metadata to encode | ||
}; | ||
|
@@ -414,7 +419,12 @@ fn context_bytes<E: EthSpec>( | |
} | ||
}; | ||
} | ||
RPCResponse::BlobsByRange(_) | RPCResponse::BlobsByRoot(_) => { | ||
RPCResponse::BlobsByRange(_) | ||
| RPCResponse::BlobsByRoot(_) | ||
| RPCResponse::DataColumnsByRoot(_) | ||
| RPCResponse::DataColumnsByRange(_) => { | ||
// TODO(das): If DataColumnSidecar is defined as an Electra type, update the | ||
// context bytes to point to ForkName::Electra | ||
return fork_context.to_context_bytes(ForkName::Deneb); | ||
jimmygchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
RPCResponse::LightClientBootstrap(lc_bootstrap) => { | ||
|
@@ -512,6 +522,17 @@ fn handle_rpc_request<E: EthSpec>( | |
)?, | ||
}))) | ||
} | ||
SupportedProtocol::DataColumnsByRootV1 => Ok(Some(InboundRequest::DataColumnsByRoot( | ||
DataColumnsByRootRequest { | ||
data_column_ids: RuntimeVariableList::from_ssz_bytes( | ||
decoded_buffer, | ||
spec.max_request_data_column_sidecars as usize, | ||
)?, | ||
}, | ||
))), | ||
SupportedProtocol::DataColumnsByRangeV1 => Ok(Some(InboundRequest::DataColumnsByRange( | ||
DataColumnsByRangeRequest::from_ssz_bytes(decoded_buffer)?, | ||
))), | ||
SupportedProtocol::PingV1 => Ok(Some(InboundRequest::Ping(Ping { | ||
data: u64::from_ssz_bytes(decoded_buffer)?, | ||
}))), | ||
|
@@ -604,6 +625,51 @@ fn handle_rpc_response<E: EthSpec>( | |
), | ||
)), | ||
}, | ||
SupportedProtocol::DataColumnsByRootV1 => match fork_name { | ||
Some(fork_name) => { | ||
// TODO(das): PeerDAS is currently supported for both deneb and electra. This check | ||
// does not advertise the topic on deneb, simply allows it to decode it. Advertise | ||
// logic is in `SupportedTopic::currently_supported`. | ||
if fork_name.deneb_enabled() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! we can perhaps add a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PeerDAS is currently supported for both deneb and electra. This check does not advertise the topic on deneb, simply allows it to decode it. Advertise logic is in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah right, thanks |
||
Ok(Some(RPCResponse::DataColumnsByRoot(Arc::new( | ||
DataColumnSidecar::from_ssz_bytes(decoded_buffer)?, | ||
)))) | ||
} else { | ||
Err(RPCError::ErrorResponse( | ||
RPCResponseErrorCode::InvalidRequest, | ||
"Invalid fork name for data columns by root".to_string(), | ||
)) | ||
} | ||
} | ||
None => Err(RPCError::ErrorResponse( | ||
RPCResponseErrorCode::InvalidRequest, | ||
format!( | ||
"No context bytes provided for {:?} response", | ||
versioned_protocol | ||
), | ||
)), | ||
}, | ||
SupportedProtocol::DataColumnsByRangeV1 => match fork_name { | ||
Some(fork_name) => { | ||
if fork_name.deneb_enabled() { | ||
dapplion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Ok(Some(RPCResponse::DataColumnsByRange(Arc::new( | ||
DataColumnSidecar::from_ssz_bytes(decoded_buffer)?, | ||
)))) | ||
} else { | ||
Err(RPCError::ErrorResponse( | ||
RPCResponseErrorCode::InvalidRequest, | ||
"Invalid fork name for data columns by range".to_string(), | ||
)) | ||
} | ||
} | ||
None => Err(RPCError::ErrorResponse( | ||
RPCResponseErrorCode::InvalidRequest, | ||
format!( | ||
"No context bytes provided for {:?} response", | ||
versioned_protocol | ||
), | ||
)), | ||
}, | ||
SupportedProtocol::PingV1 => Ok(Some(RPCResponse::Pong(Ping { | ||
data: u64::from_ssz_bytes(decoded_buffer)?, | ||
}))), | ||
|
@@ -747,7 +813,8 @@ mod tests { | |
use crate::types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield}; | ||
use types::{ | ||
blob_sidecar::BlobIdentifier, BeaconBlock, BeaconBlockAltair, BeaconBlockBase, | ||
BeaconBlockBellatrix, EmptyBlock, Epoch, FullPayload, Signature, Slot, | ||
BeaconBlockBellatrix, DataColumnIdentifier, EmptyBlock, Epoch, FullPayload, Signature, | ||
Slot, | ||
}; | ||
|
||
type Spec = types::MainnetEthSpec; | ||
|
@@ -794,6 +861,10 @@ mod tests { | |
Arc::new(BlobSidecar::empty()) | ||
} | ||
|
||
fn empty_data_column_sidecar() -> Arc<DataColumnSidecar<Spec>> { | ||
Arc::new(DataColumnSidecar::empty()) | ||
} | ||
|
||
/// Bellatrix block with length < max_rpc_size. | ||
fn bellatrix_block_small( | ||
fork_context: &ForkContext, | ||
|
@@ -855,6 +926,27 @@ mod tests { | |
} | ||
} | ||
|
||
fn dcbrange_request() -> DataColumnsByRangeRequest { | ||
DataColumnsByRangeRequest { | ||
start_slot: 0, | ||
count: 10, | ||
columns: vec![1, 2, 3], | ||
} | ||
} | ||
|
||
fn dcbroot_request(spec: &ChainSpec) -> DataColumnsByRootRequest { | ||
DataColumnsByRootRequest { | ||
data_column_ids: RuntimeVariableList::new( | ||
vec![DataColumnIdentifier { | ||
block_root: Hash256::zero(), | ||
index: 0, | ||
}], | ||
spec.max_request_data_column_sidecars as usize, | ||
) | ||
.unwrap(), | ||
} | ||
} | ||
|
||
fn bbroot_request_v1(spec: &ChainSpec) -> BlocksByRootRequest { | ||
BlocksByRootRequest::new_v1(vec![Hash256::zero()], spec) | ||
} | ||
|
@@ -1012,6 +1104,12 @@ mod tests { | |
OutboundRequest::BlobsByRoot(bbroot) => { | ||
assert_eq!(decoded, InboundRequest::BlobsByRoot(bbroot)) | ||
} | ||
OutboundRequest::DataColumnsByRoot(dcbroot) => { | ||
assert_eq!(decoded, InboundRequest::DataColumnsByRoot(dcbroot)) | ||
} | ||
OutboundRequest::DataColumnsByRange(dcbrange) => { | ||
assert_eq!(decoded, InboundRequest::DataColumnsByRange(dcbrange)) | ||
} | ||
OutboundRequest::Ping(ping) => { | ||
assert_eq!(decoded, InboundRequest::Ping(ping)) | ||
} | ||
|
@@ -1138,6 +1236,34 @@ mod tests { | |
), | ||
Ok(Some(RPCResponse::BlobsByRoot(empty_blob_sidecar()))), | ||
); | ||
|
||
assert_eq!( | ||
encode_then_decode_response( | ||
SupportedProtocol::DataColumnsByRangeV1, | ||
RPCCodedResponse::Success(RPCResponse::DataColumnsByRange( | ||
empty_data_column_sidecar() | ||
)), | ||
ForkName::Deneb, | ||
&chain_spec | ||
), | ||
Ok(Some(RPCResponse::DataColumnsByRange( | ||
empty_data_column_sidecar() | ||
))), | ||
); | ||
|
||
assert_eq!( | ||
encode_then_decode_response( | ||
SupportedProtocol::DataColumnsByRootV1, | ||
RPCCodedResponse::Success(RPCResponse::DataColumnsByRoot( | ||
empty_data_column_sidecar() | ||
)), | ||
ForkName::Deneb, | ||
&chain_spec | ||
), | ||
Ok(Some(RPCResponse::DataColumnsByRoot( | ||
empty_data_column_sidecar() | ||
))), | ||
); | ||
} | ||
|
||
// Test RPCResponse encoding/decoding for V1 messages | ||
|
@@ -1491,6 +1617,8 @@ mod tests { | |
OutboundRequest::MetaData(MetadataRequest::new_v1()), | ||
OutboundRequest::BlobsByRange(blbrange_request()), | ||
OutboundRequest::BlobsByRoot(blbroot_request(&chain_spec)), | ||
OutboundRequest::DataColumnsByRange(dcbrange_request()), | ||
OutboundRequest::DataColumnsByRoot(dcbroot_request(&chain_spec)), | ||
OutboundRequest::MetaData(MetadataRequest::new_v2()), | ||
]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the intent before was to prioritize all by roots requests ahead of all by range requests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no evidence this is useful, so let's just extend the deneb priorization