Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
undo a bunch of things
  • Loading branch information
kianenigma committed May 23, 2022
commit c330bdb04377c67a0e3b059c9a11d09595b06e05
12 changes: 1 addition & 11 deletions client/allocator/src/freeing_bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ impl Link {
/// | 0 | next element link |
/// +--------------+-------------------+
/// ```
///
/// ## Occupied header
/// ```ignore
/// 64 32 0
Expand Down Expand Up @@ -412,17 +411,8 @@ impl FreeingBumpHeapAllocator {

// Write the order in the occupied header.
Header::Occupied(order).write_into(mem, header_ptr)?;
self.total_size += order.size() + HEADER_SIZE;

if order.size() + HEADER_SIZE > 2 * 1024 * 1024 {
log::warn!(
target: LOG_TARGET,
"large allocation of {} detected, after allocation, total_size = {}, bumper = {}.",
order.size() + HEADER_SIZE,
self.total_size,
self.bumper,
);
}
self.total_size += order.size() + HEADER_SIZE;

log::trace!(
target: LOG_TARGET,
Expand Down
24 changes: 1 addition & 23 deletions frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,8 +1458,7 @@ impl<T: Config> Pallet<T> {

// Read the entire snapshot.
let RoundSnapshot { voters: snapshot_voters, targets: snapshot_targets } =
Self::read_snapshot_with_preallocate()
.map_err(|_| FeasibilityError::SnapshotUnavailable)?;
Self::snapshot().ok_or(FeasibilityError::SnapshotUnavailable)?;

// ----- Start building. First, we need some closures.
let cache = helpers::generate_voter_cache::<T::MinerConfig>(&snapshot_voters);
Expand Down Expand Up @@ -1510,27 +1509,6 @@ impl<T: Config> Pallet<T> {
Ok(ReadySolution { supports, compute, score })
}

/// Should be used instead of the getter of `Snapshot` in memory-bounded code paths.
fn read_snapshot_with_preallocate() -> Result<RoundSnapshot<T>, Error<T>> {
use codec::MaxEncodedLen;
let snap = Self::snapshot_metadata().ok_or(Error::<T>::MissingSnapshot)?;
let voters_size = snap.voters as usize * <VoterOf<T>>::max_encoded_len();
let targets_size = snap.targets as usize * T::AccountId::max_encoded_len();

// we want to decode two vecs, which need two u32s at most for their size.
let initial_capacity = voters_size + targets_size + 4 + 4;
let mut buffer = Vec::<u8>::with_capacity(initial_capacity);

// fill this whole buffer, and decode into it.
buffer.resize(buffer.capacity(), 0);
let _leftover = sp_io::storage::read(&<Snapshot<T>>::hashed_key(), &mut buffer, 0)
.ok_or(Error::<T>::MissingSnapshot)?;

// buffer should have not re-allocated
debug_assert!(buffer.capacity() == initial_capacity);
<RoundSnapshot<T> as codec::Decode>::decode(&mut &*buffer).map_err(|_| Error::<T>::Codec)
}

/// Perform the tasks to be done after a new `elect` has been triggered:
///
/// 1. Increment round.
Expand Down
7 changes: 2 additions & 5 deletions frame/election-provider-multi-phase/src/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ impl<T: Config> Pallet<T> {
pub fn mine_solution(
) -> Result<(RawSolution<SolutionOf<T::MinerConfig>>, SolutionOrSnapshotSize), MinerError> {
let RoundSnapshot { voters, targets } =
Self::read_snapshot_with_preallocate().map_err(|_| MinerError::SnapshotUnAvailable)?;
Self::snapshot().ok_or(MinerError::SnapshotUnAvailable)?;
let desired_targets = Self::desired_targets().ok_or(MinerError::SnapshotUnAvailable)?;
log!(debug, "read-snapshot");
let (solution, score, size) = Miner::<T::MinerConfig>::mine_solution_with_snapshot::<
T::Solver,
>(voters, targets, desired_targets)?;
Expand Down Expand Up @@ -406,7 +405,6 @@ impl<T: MinerConfig> Miner<T> {
where
S: NposSolver<AccountId = T::AccountId>,
{
log_no_system!(debug, "solving..");
S::solve(desired_targets as usize, targets.clone(), voters.clone())
.map_err(|e| {
log_no_system!(error, "solver error: {:?}", e);
Expand All @@ -432,7 +430,6 @@ impl<T: MinerConfig> Miner<T> {
targets: Vec<T::AccountId>,
desired_targets: u32,
) -> Result<(SolutionOf<T>, ElectionScore, SolutionOrSnapshotSize), MinerError> {
log_no_system!(debug, "preparing..");
// now make some helper closures.
let cache = helpers::generate_voter_cache::<T>(&voters);
let voter_index = helpers::voter_index_fn::<T>(&cache);
Expand All @@ -448,7 +445,7 @@ impl<T: MinerConfig> Miner<T> {
SolutionOf::<T>::try_from(assignments).map(|s| s.encoded_size())
};

let ElectionResult { assignments, winners: _w } = election_result;
let ElectionResult { assignments, winners: _ } = election_result;

// Reduce (requires round-trip to staked form)
let sorted_assignments = {
Expand Down