Skip to content
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

elastic scaling: preserve candidate ordering in provisioner #3778

Merged
merged 11 commits into from
Mar 25, 2024
6 changes: 4 additions & 2 deletions polkadot/node/core/backing/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use std::collections::HashMap;

use fatality::Nested;
use futures::channel::{mpsc, oneshot};

Expand All @@ -24,7 +26,7 @@ use polkadot_node_subsystem::{
use polkadot_node_subsystem_util::{runtime, Error as UtilError};
use polkadot_primitives::{BackedCandidate, ValidationCodeHash};

use crate::LOG_TARGET;
use crate::{ParaId, LOG_TARGET};

pub type Result<T> = std::result::Result<T, Error>;
pub type FatalResult<T> = std::result::Result<T, FatalError>;
Expand Down Expand Up @@ -55,7 +57,7 @@ pub enum Error {
InvalidSignature,

#[error("Failed to send candidates {0:?}")]
Send(Vec<BackedCandidate>),
Send(HashMap<ParaId, Vec<BackedCandidate>>),

#[error("FetchPoV failed")]
FetchPoV,
Expand Down
32 changes: 21 additions & 11 deletions polkadot/node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2231,15 +2231,16 @@ async fn handle_statement_message<Context>(

fn handle_get_backed_candidates_message(
state: &State,
requested_candidates: Vec<(CandidateHash, Hash)>,
tx: oneshot::Sender<Vec<BackedCandidate>>,
requested_candidates: HashMap<ParaId, Vec<(CandidateHash, Hash)>>,
tx: oneshot::Sender<HashMap<ParaId, Vec<BackedCandidate>>>,
metrics: &Metrics,
) -> Result<(), Error> {
let _timer = metrics.time_get_backed_candidates();

let backed = requested_candidates
.into_iter()
.filter_map(|(candidate_hash, relay_parent)| {
let mut backed = HashMap::with_capacity(requested_candidates.len());

for (para_id, para_candidates) in requested_candidates {
for (candidate_hash, relay_parent) in para_candidates.iter() {
let rp_state = match state.per_relay_parent.get(&relay_parent) {
Some(rp_state) => rp_state,
None => {
Expand All @@ -2249,13 +2250,13 @@ fn handle_get_backed_candidates_message(
?candidate_hash,
"Requested candidate's relay parent is out of view",
);
return None
break
},
};
rp_state
let maybe_backed_candidate = rp_state
.table
.attested_candidate(
&candidate_hash,
candidate_hash,
&rp_state.table_context,
rp_state.minimum_backing_votes,
)
Expand All @@ -2265,9 +2266,18 @@ fn handle_get_backed_candidates_message(
&rp_state.table_context,
rp_state.inject_core_index,
)
})
})
.collect();
});

if let Some(backed_candidate) = maybe_backed_candidate {
backed
.entry(para_id)
.or_insert_with(|| Vec::with_capacity(para_candidates.len()))
.push(backed_candidate);
} else {
break
}
}
}

tx.send(backed).map_err(|data| Error::Send(data))?;
Ok(())
Expand Down
Loading
Loading