requests block + blob always post eip4844
This commit is contained in:
parent
b616c0a056
commit
a0d4aecf30
@ -103,6 +103,7 @@ use store::{
|
|||||||
use task_executor::{ShutdownReason, TaskExecutor};
|
use task_executor::{ShutdownReason, TaskExecutor};
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
use types::beacon_state::CloneConfig;
|
use types::beacon_state::CloneConfig;
|
||||||
|
use types::consts::eip4844::MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS;
|
||||||
use types::signed_block_and_blobs::BlockWrapper;
|
use types::signed_block_and_blobs::BlockWrapper;
|
||||||
use types::*;
|
use types::*;
|
||||||
|
|
||||||
@ -5421,9 +5422,24 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
/// The epoch at which we require a data availability check in block processing.
|
/// The epoch at which we require a data availability check in block processing.
|
||||||
/// `None` if the `Eip4844` fork is disabled.
|
/// `None` if the `Eip4844` fork is disabled.
|
||||||
pub fn data_availability_boundary(&self) -> Option<Epoch> {
|
pub fn data_availability_boundary(&self) -> Option<Epoch> {
|
||||||
self.spec
|
self.spec.eip4844_fork_epoch.map(|fork_epoch| {
|
||||||
|
self.epoch().ok().map(|current_epoch|{
|
||||||
|
std::cmp::max(
|
||||||
|
fork_epoch,
|
||||||
|
current_epoch - *MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}).flatten()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if we are at or past the `Eip4844` fork. This will always return `false` if
|
||||||
|
/// the `Eip4844` fork is disabled.
|
||||||
|
pub fn is_data_availability_check_required(&self) -> Result<bool, Error> {
|
||||||
|
let current_epoch = self.epoch()?;
|
||||||
|
Ok(self.spec
|
||||||
.eip4844_fork_epoch
|
.eip4844_fork_epoch
|
||||||
.map(|e| std::cmp::max(e, self.head().finalized_checkpoint().epoch))
|
.map(|fork_epoch| fork_epoch <= current_epoch)
|
||||||
|
.unwrap_or(false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use slot_clock::SlotClock;
|
use slot_clock::SlotClock;
|
||||||
|
|
||||||
use crate::beacon_chain::{BeaconChain, BeaconChainTypes, MAXIMUM_GOSSIP_CLOCK_DISPARITY};
|
use crate::beacon_chain::{BeaconChain, BeaconChainTypes, MAXIMUM_GOSSIP_CLOCK_DISPARITY};
|
||||||
use bls::PublicKey;
|
|
||||||
use types::consts::eip4844::BLS_MODULUS;
|
|
||||||
use crate::{kzg_utils, BeaconChainError};
|
use crate::{kzg_utils, BeaconChainError};
|
||||||
|
use bls::PublicKey;
|
||||||
use state_processing::per_block_processing::eip4844::eip4844::verify_kzg_commitments_against_transactions;
|
use state_processing::per_block_processing::eip4844::eip4844::verify_kzg_commitments_against_transactions;
|
||||||
|
use types::consts::eip4844::BLS_MODULUS;
|
||||||
use types::{BeaconStateError, BlobsSidecar, Hash256, KzgCommitment, Slot, Transactions};
|
use types::{BeaconStateError, BlobsSidecar, Hash256, KzgCommitment, Slot, Transactions};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -252,6 +252,13 @@ pub struct BlobsByRootRequest {
|
|||||||
pub block_roots: VariableList<Hash256, MaxRequestBlocks>,
|
pub block_roots: VariableList<Hash256, MaxRequestBlocks>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<BlocksByRootRequest> for BlobsByRootRequest {
|
||||||
|
fn from(r: BlocksByRootRequest) -> Self {
|
||||||
|
let BlocksByRootRequest { block_roots } = r;
|
||||||
|
Self { block_roots }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* RPC Handling and Grouping */
|
/* RPC Handling and Grouping */
|
||||||
// Collection of enums and structs used by the Codecs to encode/decode RPC messages
|
// Collection of enums and structs used by the Codecs to encode/decode RPC messages
|
||||||
|
|
||||||
|
@ -10,11 +10,11 @@ use beacon_chain::builder::Witness;
|
|||||||
use beacon_chain::eth1_chain::CachingEth1Backend;
|
use beacon_chain::eth1_chain::CachingEth1Backend;
|
||||||
use lighthouse_network::{NetworkGlobals, Request};
|
use lighthouse_network::{NetworkGlobals, Request};
|
||||||
use slog::{Drain, Level};
|
use slog::{Drain, Level};
|
||||||
use slot_clock::SystemTimeSlotClock;
|
use slot_clock::{SlotClock, SystemTimeSlotClock};
|
||||||
use store::MemoryStore;
|
use store::MemoryStore;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use types::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
use types::test_utils::{SeedableRng, TestRandom, XorShiftRng};
|
||||||
use types::MinimalEthSpec as E;
|
use types::{EthSpec, MainnetEthSpec, MinimalEthSpec as E, Slot};
|
||||||
|
|
||||||
type T = Witness<SystemTimeSlotClock, CachingEth1Backend<E>, E, MemoryStore<E>, MemoryStore<E>>;
|
type T = Witness<SystemTimeSlotClock, CachingEth1Backend<E>, E, MemoryStore<E>, MemoryStore<E>>;
|
||||||
|
|
||||||
@ -55,6 +55,7 @@ impl TestRig {
|
|||||||
network_tx,
|
network_tx,
|
||||||
globals,
|
globals,
|
||||||
beacon_processor_tx,
|
beacon_processor_tx,
|
||||||
|
chain,
|
||||||
log.new(slog::o!("component" => "network_context")),
|
log.new(slog::o!("component" => "network_context")),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
@ -231,6 +231,7 @@ pub fn spawn<T: BeaconChainTypes>(
|
|||||||
network_send,
|
network_send,
|
||||||
network_globals.clone(),
|
network_globals.clone(),
|
||||||
beacon_processor_send,
|
beacon_processor_send,
|
||||||
|
beacon_chain.clone(),
|
||||||
log.clone(),
|
log.clone(),
|
||||||
),
|
),
|
||||||
range_sync: RangeSync::new(beacon_chain.clone(), log.clone()),
|
range_sync: RangeSync::new(beacon_chain.clone(), log.clone()),
|
||||||
|
@ -6,18 +6,21 @@ use super::range_sync::{BatchId, ChainId, ExpectedBatchTy};
|
|||||||
use crate::beacon_processor::WorkEvent;
|
use crate::beacon_processor::WorkEvent;
|
||||||
use crate::service::{NetworkMessage, RequestId};
|
use crate::service::{NetworkMessage, RequestId};
|
||||||
use crate::status::ToStatusMessage;
|
use crate::status::ToStatusMessage;
|
||||||
use beacon_chain::{BeaconChainTypes, EngineState};
|
use beacon_chain::{BeaconChain, BeaconChainTypes, EngineState};
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
use lighthouse_network::rpc::methods::BlobsByRangeRequest;
|
use lighthouse_network::rpc::methods::BlobsByRangeRequest;
|
||||||
use lighthouse_network::rpc::{BlocksByRangeRequest, BlocksByRootRequest, GoodbyeReason};
|
use lighthouse_network::rpc::{BlocksByRangeRequest, BlocksByRootRequest, GoodbyeReason};
|
||||||
use lighthouse_network::{Client, NetworkGlobals, PeerAction, PeerId, ReportSource, Request};
|
use lighthouse_network::{Client, NetworkGlobals, PeerAction, PeerId, ReportSource, Request};
|
||||||
use slog::{debug, trace, warn};
|
use slog::{debug, trace, warn};
|
||||||
|
use slot_clock::SlotClock;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use types::signed_block_and_blobs::BlockWrapper;
|
use types::signed_block_and_blobs::BlockWrapper;
|
||||||
use types::{BlobsSidecar, EthSpec, SignedBeaconBlock, SignedBeaconBlockAndBlobsSidecar};
|
use types::{
|
||||||
|
BlobsSidecar, ChainSpec, EthSpec, SignedBeaconBlock, SignedBeaconBlockAndBlobsSidecar,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
struct BlockBlobRequestInfo<T: EthSpec> {
|
struct BlockBlobRequestInfo<T: EthSpec> {
|
||||||
@ -94,6 +97,8 @@ pub struct SyncNetworkContext<T: BeaconChainTypes> {
|
|||||||
/// Channel to send work to the beacon processor.
|
/// Channel to send work to the beacon processor.
|
||||||
beacon_processor_send: mpsc::Sender<WorkEvent<T>>,
|
beacon_processor_send: mpsc::Sender<WorkEvent<T>>,
|
||||||
|
|
||||||
|
chain: Arc<BeaconChain<T>>,
|
||||||
|
|
||||||
/// Logger for the `SyncNetworkContext`.
|
/// Logger for the `SyncNetworkContext`.
|
||||||
log: slog::Logger,
|
log: slog::Logger,
|
||||||
}
|
}
|
||||||
@ -103,6 +108,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
|||||||
network_send: mpsc::UnboundedSender<NetworkMessage<T::EthSpec>>,
|
network_send: mpsc::UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>,
|
network_globals: Arc<NetworkGlobals<T::EthSpec>>,
|
||||||
beacon_processor_send: mpsc::Sender<WorkEvent<T>>,
|
beacon_processor_send: mpsc::Sender<WorkEvent<T>>,
|
||||||
|
chain: Arc<BeaconChain<T>>,
|
||||||
log: slog::Logger,
|
log: slog::Logger,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
SyncNetworkContext {
|
SyncNetworkContext {
|
||||||
@ -115,6 +121,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
|||||||
backfill_sidecar_pair_requests: Default::default(),
|
backfill_sidecar_pair_requests: Default::default(),
|
||||||
execution_engine_state: EngineState::Online, // always assume `Online` at the start
|
execution_engine_state: EngineState::Online, // always assume `Online` at the start
|
||||||
beacon_processor_send,
|
beacon_processor_send,
|
||||||
|
chain,
|
||||||
log,
|
log,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,11 +466,16 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
|||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
request: BlocksByRootRequest,
|
request: BlocksByRootRequest,
|
||||||
) -> Result<Id, &'static str> {
|
) -> Result<Id, &'static str> {
|
||||||
//FIXME(sean) add prune depth logic here?
|
let request = if self.chain.is_data_availability_check_required().map_err(|_|"Unable to read slot clock")? {
|
||||||
// D: YES
|
trace!(
|
||||||
// MOREINFO: here depending of the boundaries we decide what kind of request we send, if we
|
self.log,
|
||||||
// request just a block or if we request a block, glob pair.
|
"Sending BlobsByRoot Request";
|
||||||
|
"method" => "BlobsByRoot",
|
||||||
|
"count" => request.block_roots.len(),
|
||||||
|
"peer" => %peer_id
|
||||||
|
);
|
||||||
|
Request::BlobsByRoot(request.into())
|
||||||
|
} else {
|
||||||
trace!(
|
trace!(
|
||||||
self.log,
|
self.log,
|
||||||
"Sending BlocksByRoot Request";
|
"Sending BlocksByRoot Request";
|
||||||
@ -471,7 +483,8 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
|||||||
"count" => request.block_roots.len(),
|
"count" => request.block_roots.len(),
|
||||||
"peer" => %peer_id
|
"peer" => %peer_id
|
||||||
);
|
);
|
||||||
let request = Request::BlocksByRoot(request);
|
Request::BlocksByRoot(request)
|
||||||
|
};
|
||||||
let id = self.next_id();
|
let id = self.next_id();
|
||||||
let request_id = RequestId::Sync(SyncRequestId::SingleBlock { id });
|
let request_id = RequestId::Sync(SyncRequestId::SingleBlock { id });
|
||||||
self.send_network_msg(NetworkMessage::SendRequest {
|
self.send_network_msg(NetworkMessage::SendRequest {
|
||||||
@ -488,6 +501,16 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
|||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
request: BlocksByRootRequest,
|
request: BlocksByRootRequest,
|
||||||
) -> Result<Id, &'static str> {
|
) -> Result<Id, &'static str> {
|
||||||
|
let request = if self.chain.is_data_availability_check_required().map_err(|_|"Unable to read slot clock")? {
|
||||||
|
trace!(
|
||||||
|
self.log,
|
||||||
|
"Sending BlobsByRoot Request";
|
||||||
|
"method" => "BlobsByRoot",
|
||||||
|
"count" => request.block_roots.len(),
|
||||||
|
"peer" => %peer_id
|
||||||
|
);
|
||||||
|
Request::BlobsByRoot(request.into())
|
||||||
|
} else {
|
||||||
trace!(
|
trace!(
|
||||||
self.log,
|
self.log,
|
||||||
"Sending BlocksByRoot Request";
|
"Sending BlocksByRoot Request";
|
||||||
@ -495,7 +518,8 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
|
|||||||
"count" => request.block_roots.len(),
|
"count" => request.block_roots.len(),
|
||||||
"peer" => %peer_id
|
"peer" => %peer_id
|
||||||
);
|
);
|
||||||
let request = Request::BlocksByRoot(request);
|
Request::BlocksByRoot(request)
|
||||||
|
};
|
||||||
let id = self.next_id();
|
let id = self.next_id();
|
||||||
let request_id = RequestId::Sync(SyncRequestId::ParentLookup { id });
|
let request_id = RequestId::Sync(SyncRequestId::ParentLookup { id });
|
||||||
self.send_network_msg(NetworkMessage::SendRequest {
|
self.send_network_msg(NetworkMessage::SendRequest {
|
||||||
|
@ -388,11 +388,12 @@ mod tests {
|
|||||||
use slog::{o, Drain};
|
use slog::{o, Drain};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use slot_clock::SystemTimeSlotClock;
|
use slot_clock::{SlotClock, SystemTimeSlotClock};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
use store::MemoryStore;
|
use store::MemoryStore;
|
||||||
use types::{Hash256, MinimalEthSpec as E};
|
use types::{Hash256, MainnetEthSpec, MinimalEthSpec as E};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct FakeStorage {
|
struct FakeStorage {
|
||||||
@ -606,6 +607,7 @@ mod tests {
|
|||||||
network_tx,
|
network_tx,
|
||||||
globals.clone(),
|
globals.clone(),
|
||||||
beacon_processor_tx,
|
beacon_processor_tx,
|
||||||
|
chain,
|
||||||
log.new(o!("component" => "network_context")),
|
log.new(o!("component" => "network_context")),
|
||||||
);
|
);
|
||||||
let test_rig = TestRig {
|
let test_rig = TestRig {
|
||||||
|
@ -23,7 +23,7 @@ pub mod merge {
|
|||||||
pub const INTERVALS_PER_SLOT: u64 = 3;
|
pub const INTERVALS_PER_SLOT: u64 = 3;
|
||||||
}
|
}
|
||||||
pub mod eip4844 {
|
pub mod eip4844 {
|
||||||
use crate::Uint256;
|
use crate::{Epoch, Uint256};
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ pub mod eip4844 {
|
|||||||
"52435875175126190479447740508185965837690552500527637822603658699938581184513"
|
"52435875175126190479447740508185965837690552500527637822603658699938581184513"
|
||||||
)
|
)
|
||||||
.expect("should initialize BLS_MODULUS");
|
.expect("should initialize BLS_MODULUS");
|
||||||
|
pub static ref MIN_EPOCHS_FOR_BLOBS_SIDECARS_REQUESTS: Epoch = Epoch::from(4096_u64);
|
||||||
}
|
}
|
||||||
pub const BLOB_TX_TYPE: u8 = 5;
|
pub const BLOB_TX_TYPE: u8 = 5;
|
||||||
pub const VERSIONED_HASH_VERSION_KZG: u8 = 1;
|
pub const VERSIONED_HASH_VERSION_KZG: u8 = 1;
|
||||||
|
@ -23,7 +23,7 @@ use std::fmt::Debug;
|
|||||||
#[cfg(not(all(feature = "withdrawals", feature = "withdrawals-processing")))]
|
#[cfg(not(all(feature = "withdrawals", feature = "withdrawals-processing")))]
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))]
|
#[cfg(all(feature = "withdrawals"))]
|
||||||
use types::SignedBlsToExecutionChange;
|
use types::SignedBlsToExecutionChange;
|
||||||
use types::{
|
use types::{
|
||||||
Attestation, AttesterSlashing, BeaconBlock, BeaconState, BlindedPayload, ChainSpec, Deposit,
|
Attestation, AttesterSlashing, BeaconBlock, BeaconState, BlindedPayload, ChainSpec, Deposit,
|
||||||
@ -45,10 +45,7 @@ struct ExecutionMetadata {
|
|||||||
/// Newtype for testing withdrawals.
|
/// Newtype for testing withdrawals.
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct WithdrawalsPayload<T: EthSpec> {
|
pub struct WithdrawalsPayload<T: EthSpec> {
|
||||||
#[cfg(all(feature = "withdrawals", feature = "withdrawals-processing"))]
|
|
||||||
payload: FullPayload<T>,
|
payload: FullPayload<T>,
|
||||||
#[cfg(not(all(feature = "withdrawals", feature = "withdrawals-processing")))]
|
|
||||||
_phantom_data: PhantomData<T>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
Loading…
Reference in New Issue
Block a user