mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Add missing_const_for_fn clippy lint (#8498)
This commit is contained in:
@ -23,7 +23,7 @@ pub struct AutoSealClient {
|
||||
}
|
||||
|
||||
impl AutoSealClient {
|
||||
pub(crate) fn new(storage: Storage) -> Self {
|
||||
pub(crate) const fn new(storage: Storage) -> Self {
|
||||
Self { storage }
|
||||
}
|
||||
|
||||
|
||||
@ -76,12 +76,12 @@ impl ForkchoiceStateTracker {
|
||||
}
|
||||
|
||||
/// Returns the last received ForkchoiceState to which we need to sync.
|
||||
pub(crate) fn sync_target_state(&self) -> Option<ForkchoiceState> {
|
||||
pub(crate) const fn sync_target_state(&self) -> Option<ForkchoiceState> {
|
||||
self.last_syncing
|
||||
}
|
||||
|
||||
/// Returns true if no forkchoice state has been received yet.
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
pub(crate) const fn is_empty(&self) -> bool {
|
||||
self.latest.is_none()
|
||||
}
|
||||
}
|
||||
@ -106,20 +106,20 @@ pub enum ForkchoiceStatus {
|
||||
}
|
||||
|
||||
impl ForkchoiceStatus {
|
||||
pub(crate) fn is_valid(&self) -> bool {
|
||||
pub(crate) const fn is_valid(&self) -> bool {
|
||||
matches!(self, Self::Valid)
|
||||
}
|
||||
|
||||
pub(crate) fn is_invalid(&self) -> bool {
|
||||
pub(crate) const fn is_invalid(&self) -> bool {
|
||||
matches!(self, Self::Invalid)
|
||||
}
|
||||
|
||||
pub(crate) fn is_syncing(&self) -> bool {
|
||||
pub(crate) const fn is_syncing(&self) -> bool {
|
||||
matches!(self, Self::Syncing)
|
||||
}
|
||||
|
||||
/// Converts the general purpose [PayloadStatusEnum] into a [ForkchoiceStatus].
|
||||
pub(crate) fn from_payload_status(status: &PayloadStatusEnum) -> Self {
|
||||
pub(crate) const fn from_payload_status(status: &PayloadStatusEnum) -> Self {
|
||||
match status {
|
||||
PayloadStatusEnum::Valid | PayloadStatusEnum::Accepted => {
|
||||
// `Accepted` is only returned on `newPayload`. It would be a valid state here.
|
||||
@ -160,7 +160,7 @@ impl ForkchoiceStateHash {
|
||||
}
|
||||
|
||||
/// Returns true if this is the head hash of the [ForkchoiceState]
|
||||
pub(crate) fn is_head(&self) -> bool {
|
||||
pub(crate) const fn is_head(&self) -> bool {
|
||||
matches!(self, Self::Head(_))
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ where
|
||||
Engine: EngineTypes,
|
||||
{
|
||||
/// Creates a new beacon consensus engine handle.
|
||||
pub fn new(
|
||||
pub const fn new(
|
||||
to_engine: UnboundedSender<BeaconEngineMessage<Engine>>,
|
||||
event_sender: EventSender<BeaconConsensusEngineEvent>,
|
||||
) -> Self {
|
||||
|
||||
@ -83,12 +83,12 @@ pub enum EngineHookEvent {
|
||||
|
||||
impl EngineHookEvent {
|
||||
/// Returns `true` if the event is [`EngineHookEvent::Started`].
|
||||
pub fn is_started(&self) -> bool {
|
||||
pub const fn is_started(&self) -> bool {
|
||||
matches!(self, Self::Started)
|
||||
}
|
||||
|
||||
/// Returns `true` if the event is [`EngineHookEvent::Finished`].
|
||||
pub fn is_finished(&self) -> bool {
|
||||
pub const fn is_finished(&self) -> bool {
|
||||
matches!(self, Self::Finished(_))
|
||||
}
|
||||
}
|
||||
@ -118,12 +118,12 @@ pub enum EngineHookDBAccessLevel {
|
||||
|
||||
impl EngineHookDBAccessLevel {
|
||||
/// Returns `true` if the hook needs read-only access to the database.
|
||||
pub fn is_read_only(&self) -> bool {
|
||||
pub const fn is_read_only(&self) -> bool {
|
||||
matches!(self, Self::ReadOnly)
|
||||
}
|
||||
|
||||
/// Returns `true` if the hook needs read-write access to the database.
|
||||
pub fn is_read_write(&self) -> bool {
|
||||
pub const fn is_read_write(&self) -> bool {
|
||||
matches!(self, Self::ReadWrite)
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ pub struct OnForkChoiceUpdated {
|
||||
|
||||
impl OnForkChoiceUpdated {
|
||||
/// Returns the determined status of the received ForkchoiceState.
|
||||
pub fn forkchoice_status(&self) -> ForkchoiceStatus {
|
||||
pub const fn forkchoice_status(&self) -> ForkchoiceStatus {
|
||||
self.forkchoice_status
|
||||
}
|
||||
|
||||
|
||||
@ -602,7 +602,7 @@ where
|
||||
///
|
||||
/// If the `local_tip` is greater than the `block`, then this will return false.
|
||||
#[inline]
|
||||
fn exceeds_pipeline_run_threshold(&self, local_tip: u64, block: u64) -> bool {
|
||||
const fn exceeds_pipeline_run_threshold(&self, local_tip: u64, block: u64) -> bool {
|
||||
block > local_tip && block - local_tip > self.pipeline_run_threshold
|
||||
}
|
||||
|
||||
@ -692,7 +692,7 @@ where
|
||||
/// Returns how far the local tip is from the given block. If the local tip is at the same
|
||||
/// height or its block number is greater than the given block, this returns None.
|
||||
#[inline]
|
||||
fn distance_from_local_tip(&self, local_tip: u64, block: u64) -> Option<u64> {
|
||||
const fn distance_from_local_tip(&self, local_tip: u64, block: u64) -> Option<u64> {
|
||||
if block > local_tip {
|
||||
Some(block - local_tip)
|
||||
} else {
|
||||
|
||||
@ -123,23 +123,23 @@ where
|
||||
}
|
||||
|
||||
/// Returns whether or not the sync controller is set to run the pipeline continuously.
|
||||
pub(crate) fn run_pipeline_continuously(&self) -> bool {
|
||||
pub(crate) const fn run_pipeline_continuously(&self) -> bool {
|
||||
self.run_pipeline_continuously
|
||||
}
|
||||
|
||||
/// Returns `true` if a pipeline target is queued and will be triggered on the next `poll`.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn is_pipeline_sync_pending(&self) -> bool {
|
||||
pub(crate) const fn is_pipeline_sync_pending(&self) -> bool {
|
||||
self.pending_pipeline_target.is_some() && self.pipeline_state.is_idle()
|
||||
}
|
||||
|
||||
/// Returns `true` if the pipeline is idle.
|
||||
pub(crate) fn is_pipeline_idle(&self) -> bool {
|
||||
pub(crate) const fn is_pipeline_idle(&self) -> bool {
|
||||
self.pipeline_state.is_idle()
|
||||
}
|
||||
|
||||
/// Returns `true` if the pipeline is active.
|
||||
pub(crate) fn is_pipeline_active(&self) -> bool {
|
||||
pub(crate) const fn is_pipeline_active(&self) -> bool {
|
||||
!self.is_pipeline_idle()
|
||||
}
|
||||
|
||||
@ -418,7 +418,7 @@ enum PipelineState<DB: Database> {
|
||||
|
||||
impl<DB: Database> PipelineState<DB> {
|
||||
/// Returns `true` if the state matches idle.
|
||||
fn is_idle(&self) -> bool {
|
||||
const fn is_idle(&self) -> bool {
|
||||
matches!(self, Self::Idle(_))
|
||||
}
|
||||
}
|
||||
@ -478,7 +478,7 @@ mod tests {
|
||||
|
||||
/// Sets the max block for the pipeline to run.
|
||||
#[allow(dead_code)]
|
||||
fn with_max_block(mut self, max_block: BlockNumber) -> Self {
|
||||
const fn with_max_block(mut self, max_block: BlockNumber) -> Self {
|
||||
self.max_block = Some(max_block);
|
||||
self
|
||||
}
|
||||
@ -516,13 +516,13 @@ mod tests {
|
||||
|
||||
impl<Client> TestSyncControllerBuilder<Client> {
|
||||
/// Create a new [TestSyncControllerBuilder].
|
||||
fn new() -> Self {
|
||||
const fn new() -> Self {
|
||||
Self { max_block: None, client: None }
|
||||
}
|
||||
|
||||
/// Sets the max block for the pipeline to run.
|
||||
#[allow(dead_code)]
|
||||
fn with_max_block(mut self, max_block: BlockNumber) -> Self {
|
||||
const fn with_max_block(mut self, max_block: BlockNumber) -> Self {
|
||||
self.max_block = Some(max_block);
|
||||
self
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ impl TestConsensusEngineBuilder {
|
||||
}
|
||||
|
||||
/// Sets the max block for the pipeline to run.
|
||||
pub fn with_max_block(mut self, max_block: BlockNumber) -> Self {
|
||||
pub const fn with_max_block(mut self, max_block: BlockNumber) -> Self {
|
||||
self.max_block = Some(max_block);
|
||||
self
|
||||
}
|
||||
@ -210,21 +210,24 @@ impl TestConsensusEngineBuilder {
|
||||
}
|
||||
|
||||
/// Uses a real consensus engine instead of a test consensus engine.
|
||||
pub fn with_real_consensus(mut self) -> Self {
|
||||
pub const fn with_real_consensus(mut self) -> Self {
|
||||
self.consensus = TestConsensusConfig::Real;
|
||||
self
|
||||
}
|
||||
|
||||
/// Disables blockchain tree driven sync. This is the same as setting the pipeline run
|
||||
/// threshold to 0.
|
||||
pub fn disable_blockchain_tree_sync(mut self) -> Self {
|
||||
pub const fn disable_blockchain_tree_sync(mut self) -> Self {
|
||||
self.pipeline_run_threshold = Some(0);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the client to use for network operations.
|
||||
#[allow(dead_code)]
|
||||
pub fn with_client<Client>(self, client: Client) -> NetworkedTestConsensusEngineBuilder<Client>
|
||||
pub const fn with_client<Client>(
|
||||
self,
|
||||
client: Client,
|
||||
) -> NetworkedTestConsensusEngineBuilder<Client>
|
||||
where
|
||||
Client: HeadersClient + BodiesClient + 'static,
|
||||
{
|
||||
@ -274,7 +277,7 @@ where
|
||||
|
||||
/// Sets the max block for the pipeline to run.
|
||||
#[allow(dead_code)]
|
||||
pub fn with_max_block(mut self, max_block: BlockNumber) -> Self {
|
||||
pub const fn with_max_block(mut self, max_block: BlockNumber) -> Self {
|
||||
self.base_config.max_block = Some(max_block);
|
||||
self
|
||||
}
|
||||
@ -296,7 +299,7 @@ where
|
||||
/// Disables blockchain tree driven sync. This is the same as setting the pipeline run
|
||||
/// threshold to 0.
|
||||
#[allow(dead_code)]
|
||||
pub fn disable_blockchain_tree_sync(mut self) -> Self {
|
||||
pub const fn disable_blockchain_tree_sync(mut self) -> Self {
|
||||
self.base_config.pipeline_run_threshold = Some(0);
|
||||
self
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ pub fn base_block_reward(
|
||||
/// - Definition: [Yellow Paper][yp] (page 15, 11.3)
|
||||
///
|
||||
/// [yp]: https://ethereum.github.io/yellowpaper/paper.pdf
|
||||
pub fn block_reward(base_block_reward: u128, ommers: usize) -> u128 {
|
||||
pub const fn block_reward(base_block_reward: u128, ommers: usize) -> u128 {
|
||||
base_block_reward + (base_block_reward >> 5) * ommers as u128
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ pub fn block_reward(base_block_reward: u128, ommers: usize) -> u128 {
|
||||
///
|
||||
/// [oe]: https://github.com/openethereum/openethereum/blob/6c2d392d867b058ff867c4373e40850ca3f96969/crates/ethcore/src/ethereum/ethash.rs#L319-L333
|
||||
/// [yp]: https://ethereum.github.io/yellowpaper/paper.pdf
|
||||
pub fn ommer_reward(
|
||||
pub const fn ommer_reward(
|
||||
base_block_reward: u128,
|
||||
block_number: BlockNumber,
|
||||
ommer_block_number: BlockNumber,
|
||||
|
||||
@ -33,7 +33,7 @@ pub struct PostExecutionInput<'a> {
|
||||
|
||||
impl<'a> PostExecutionInput<'a> {
|
||||
/// Creates a new instance of `PostExecutionInput`.
|
||||
pub fn new(receipts: &'a [Receipt], requests: &'a [Request]) -> Self {
|
||||
pub const fn new(receipts: &'a [Receipt], requests: &'a [Request]) -> Self {
|
||||
Self { receipts, requests }
|
||||
}
|
||||
}
|
||||
@ -327,7 +327,7 @@ pub enum ConsensusError {
|
||||
|
||||
impl ConsensusError {
|
||||
/// Returns `true` if the error is a state root error.
|
||||
pub fn is_state_root_error(&self) -> bool {
|
||||
pub const fn is_state_root_error(&self) -> bool {
|
||||
matches!(self, Self::BodyStateRootDiff(_))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user