/// The actual priority computation utilizing cached BlockSets instead of
/// having to read from the pool every time when it is called.
The actual priority computation utilizing cached BlockSets instead of
having to read from the pool every time when it is called.
The actual priority computation utilizing cached BlockSets instead of having to read from the pool every time when it is called .
fn compute_priority(
    catch_up_height: Height,
    expected_batch_height: Height,
    finalized_height: Height,
    notarized_height: Height,
    beacon_height: Height,
    block_sets: &BlockSets,
    attr: &ConsensusMessageAttribute,
) -> Priority {
    let height = attr.height();
    // Ignore older than the min of catch-up height and expected_batch_height
    if height < expected_batch_height.min(catch_up_height) {
        return Drop;
    }
    // Other decisions depend on type, default is to fetch.
    match attr {
        ConsensusMessageAttribute::RandomBeacon(_)
        | ConsensusMessageAttribute::RandomBeaconShare(_) => {
            // Ignore old beacon or beacon shares
            if height <= beacon_height {
                Drop
            } else if height < beacon_height + Height::from(LOOK_AHEAD) {
                Fetch
            } else {
                Stash
            }
        }
        ConsensusMessageAttribute::NotarizationShare(_) => {
            // Ignore old notarization shares
            if height <= notarized_height {
                Drop
            } else if height < notarized_height + Height::from(LOOK_AHEAD) {
                Fetch
            } else {
                Stash
            }
        }
        ConsensusMessageAttribute::Notarization(block_hash, _) => {
            // Ignore older than finalized
            if height <= finalized_height {
                Drop
            } else {
                // Drop notarization we already have
                if block_sets.notarized_validated.contains(block_hash) {
                    Drop
                }
                // Postpone notarization we might already have
                else if block_sets.notarized_unvalidated.contains(block_hash)
                    || height >= finalized_height + Height::from(LOOK_AHEAD)
                {
                    Stash
                } else {
                    Fetch
                }
            }
        }
        ConsensusMessageAttribute::Finalization(block_hash, _) => {
            // Ignore older than finalized
            if height <= finalized_height {
                Drop
            } else {
                // Postpone finalization we might already have
                if block_sets.finalized_unvalidated.contains(block_hash)
                    || height >= finalized_height + Height::from(LOOK_AHEAD)
                {
                    Stash
                } else {
                    Fetch
                }
            }
        }
        ConsensusMessageAttribute::FinalizationShare(_)
        | ConsensusMessageAttribute::BlockProposal(_, _) => {
            // Ignore finalized
            if height <= finalized_height {
                Drop
            } else if height < finalized_height + Height::from(LOOK_AHEAD) {
                Fetch
            } else {
                Stash
            }
        }
        ConsensusMessageAttribute::RandomTape(_)
        | ConsensusMessageAttribute::RandomTapeShare(_) => {
            if height < expected_batch_height {
                Drop
            } else if height < finalized_height + Height::from(LOOK_AHEAD) {
                Fetch
            } else {
                Stash
            }
        }
        ConsensusMessageAttribute::CatchUpPackage(_) => FetchNow,
        ConsensusMessageAttribute::CatchUpPackageShare(_) => {
            if height <= catch_up_height {
                Drop
            } else if height > finalized_height {
                Stash
            } else {
                Fetch
            }
        }
    }
}
fn compute_priority ( catch_up_height : Height , expected_batch_height : Height , finalized_height : Height , notarized_height : Height , beacon_height : Height , block_sets : & BlockSets , attr : & ConsensusMessageAttribute , ) -> Priority { let height = attr . height ( ) ; // Ignore older than the min of catch-up height and expected_batch_height if height < expected_batch_height . min ( catch_up_height ) { return Drop ; } // Other decisions depend on type, default is to fetch. match attr { ConsensusMessageAttribute :: RandomBeacon ( _ ) | ConsensusMessageAttribute :: RandomBeaconShare ( _ ) => { // Ignore old beacon or beacon shares if height <= beacon_height { Drop } else if height < beacon_height + Height :: from ( LOOK_AHEAD ) { Fetch } else { Stash } } ConsensusMessageAttribute :: NotarizationShare ( _ ) => { // Ignore old notarization shares if height <= notarized_height { Drop } else if height < notarized_height + Height :: from ( LOOK_AHEAD ) { Fetch } else { Stash } } ConsensusMessageAttribute :: Notarization ( block_hash , _ ) => { // Ignore older than finalized if height <= finalized_height { Drop } else { // Drop notarization we already have if block_sets . notarized_validated . contains ( block_hash ) { Drop } // Postpone notarization we might already have else if block_sets . notarized_unvalidated . contains ( block_hash ) || height >= finalized_height + Height :: from ( LOOK_AHEAD ) { Stash } else { Fetch } } } ConsensusMessageAttribute :: Finalization ( block_hash , _ ) => { // Ignore older than finalized if height <= finalized_height { Drop } else { // Postpone finalization we might already have if block_sets . finalized_unvalidated . contains ( block_hash ) || height >= finalized_height + Height :: from ( LOOK_AHEAD ) { Stash } else { Fetch } } } ConsensusMessageAttribute :: FinalizationShare ( _ ) | ConsensusMessageAttribute :: BlockProposal ( _ , _ ) => { // Ignore finalized if height <= finalized_height { Drop } else if height < finalized_height + Height :: from ( LOOK_AHEAD ) { Fetch } else { Stash } } ConsensusMessageAttribute :: RandomTape ( _ ) | ConsensusMessageAttribute :: RandomTapeShare ( _ ) => { if height < expected_batch_height { Drop } else if height < finalized_height + Height :: from ( LOOK_AHEAD ) { Fetch } else { Stash } } ConsensusMessageAttribute :: CatchUpPackage ( _ ) => FetchNow , ConsensusMessageAttribute :: CatchUpPackageShare ( _ ) => { if height <= catch_up_height { Drop } else if height > finalized_height { Stash } else { Fetch } } } }
The actual priority computation utilizing cached BlockSets instead of
having to read from the pool every time when it is called.
The actual priority computation utilizing cached BlockSets instead of having to read from the pool every time when it is called .
catch_up_height
Height
expected_batch_height
Height
finalized_height
Height
notarized_height
Height
beacon_height
Height
block_sets
&BlockSets
attr
&ConsensusMessageAttribute