Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 93fe106

Browse files
committed
Merge remote-tracking branch 'origin/master' into oty-try-runtime-checks
2 parents 4078db2 + 7b3eb68 commit 93fe106

56 files changed

Lines changed: 1983 additions & 1450 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 1309 additions & 302 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tikv-jemallocator = "0.5.0"
2727
assert_cmd = "2.0.4"
2828
nix = "0.24.1"
2929
tempfile = "3.2.0"
30-
tokio = "1.22.0"
30+
tokio = "1.24.1"
3131
substrate-rpc-client = { git = "https://github.com/paritytech/substrate", branch = "master" }
3232
polkadot-core-primitives = { path = "core-primitives" }
3333

node/core/av-store/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,14 @@ async fn run_iteration<Context>(
570570
FromOrchestra::Signal(OverseerSignal::BlockFinalized(hash, number)) => {
571571
let _timer = subsystem.metrics.time_process_block_finalized();
572572

573+
if !subsystem.known_blocks.is_known(&hash) {
574+
// If we haven't processed this block yet,
575+
// make sure we write the metadata about the
576+
// candidates backed in this finalized block.
577+
// Otherwise, we won't be able to store our chunk
578+
// for these candidates.
579+
process_block_activated(ctx, subsystem, hash).await?;
580+
}
573581
subsystem.finalized_number = Some(number);
574582
subsystem.known_blocks.prune_finalized(number);
575583
process_block_finalized(

node/core/av-store/src/tests.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,49 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
732732
let test_state = TestState::default();
733733

734734
test_harness(test_state.clone(), store.clone(), |mut virtual_overseer| async move {
735-
overseer_signal(&mut virtual_overseer, OverseerSignal::BlockFinalized(Hash::zero(), 1))
736-
.await;
735+
let block_hash = Hash::repeat_byte(1);
736+
overseer_signal(&mut virtual_overseer, OverseerSignal::BlockFinalized(block_hash, 1)).await;
737+
738+
let header = Header {
739+
parent_hash: Hash::repeat_byte(0),
740+
number: 1,
741+
state_root: Hash::zero(),
742+
extrinsics_root: Hash::zero(),
743+
digest: Default::default(),
744+
};
745+
746+
assert_matches!(
747+
overseer_recv(&mut virtual_overseer).await,
748+
AllMessages::ChainApi(ChainApiMessage::BlockHeader(
749+
relay_parent,
750+
tx,
751+
)) => {
752+
assert_eq!(relay_parent, block_hash);
753+
tx.send(Ok(Some(header))).unwrap();
754+
}
755+
);
756+
757+
assert_matches!(
758+
overseer_recv(&mut virtual_overseer).await,
759+
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
760+
relay_parent,
761+
RuntimeApiRequest::CandidateEvents(tx),
762+
)) => {
763+
assert_eq!(relay_parent, block_hash);
764+
tx.send(Ok(Vec::new())).unwrap();
765+
}
766+
);
767+
768+
assert_matches!(
769+
overseer_recv(&mut virtual_overseer).await,
770+
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
771+
relay_parent,
772+
RuntimeApiRequest::Validators(tx),
773+
)) => {
774+
assert_eq!(relay_parent, Hash::zero());
775+
tx.send(Ok(Vec::new())).unwrap();
776+
}
777+
);
737778

738779
let header = Header {
739780
parent_hash: Hash::repeat_byte(3),

node/core/candidate-validation/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ parity-scale-codec = { version = "3.1.5", default-features = false, features = [
1616
polkadot-primitives = { path = "../../../primitives" }
1717
polkadot-parachain = { path = "../../../parachain" }
1818
polkadot-node-primitives = { path = "../../primitives" }
19-
polkadot-node-subsystem = {path = "../../subsystem" }
20-
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
19+
polkadot-node-subsystem = { path = "../../subsystem" }
20+
polkadot-node-metrics = { path = "../../metrics" }
2121

2222
[target.'cfg(not(any(target_os = "android", target_os = "unknown")))'.dependencies]
2323
polkadot-node-core-pvf = { path = "../pvf" }
@@ -27,5 +27,6 @@ sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master
2727
futures = { version = "0.3.21", features = ["thread-pool"] }
2828
assert_matches = "1.4.0"
2929
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
30+
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
3031
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
3132
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }

node/core/candidate-validation/src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,16 @@ async fn validate_candidate_exhaustive(
604604

605605
#[async_trait]
606606
trait ValidationBackend {
607+
/// Tries executing a PVF a single time (no retries).
607608
async fn validate_candidate(
608609
&mut self,
609610
pvf: Pvf,
610611
timeout: Duration,
611612
encoded_params: Vec<u8>,
612613
) -> Result<WasmValidationResult, ValidationError>;
613614

615+
/// Tries executing a PVF. Will retry once if an error is encountered that may have been
616+
/// transient.
614617
async fn validate_candidate_with_retry(
615618
&mut self,
616619
raw_validation_code: Vec<u8>,
@@ -620,7 +623,7 @@ trait ValidationBackend {
620623
// Construct the PVF a single time, since it is an expensive operation. Cloning it is cheap.
621624
let pvf = Pvf::from_code(raw_validation_code);
622625

623-
let validation_result =
626+
let mut validation_result =
624627
self.validate_candidate(pvf.clone(), timeout, params.encode()).await;
625628

626629
// If we get an AmbiguousWorkerDeath error, retry once after a brief delay, on the
@@ -630,12 +633,19 @@ trait ValidationBackend {
630633
{
631634
// Wait a brief delay before retrying.
632635
futures_timer::Delay::new(PVF_EXECUTION_RETRY_DELAY).await;
636+
637+
gum::debug!(
638+
target: LOG_TARGET,
639+
?pvf,
640+
"Re-trying failed candidate validation due to AmbiguousWorkerDeath."
641+
);
642+
633643
// Encode the params again when re-trying. We expect the retry case to be relatively
634644
// rare, and we want to avoid unconditionally cloning data.
635-
self.validate_candidate(pvf, timeout, params.encode()).await
636-
} else {
637-
validation_result
645+
validation_result = self.validate_candidate(pvf, timeout, params.encode()).await;
638646
}
647+
648+
validation_result
639649
}
640650

641651
async fn precheck_pvf(&mut self, pvf: Pvf) -> Result<Duration, PrepareError>;

node/core/candidate-validation/src/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use super::{ValidationFailed, ValidationResult};
18-
use polkadot_node_subsystem_util::metrics::{self, prometheus};
18+
use polkadot_node_metrics::metrics::{self, prometheus};
1919

2020
#[derive(Clone)]
2121
pub(crate) struct MetricsInner {

node/core/chain-api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ futures = "0.3.21"
99
gum = { package = "tracing-gum", path = "../../gum" }
1010
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
1111
polkadot-primitives = { path = "../../../primitives" }
12+
polkadot-node-metrics = { path = "../../metrics" }
1213
polkadot-node-subsystem = {path = "../../subsystem" }
13-
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
1414
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
1515
sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
1616

node/core/chain-api/src/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17-
use polkadot_node_subsystem_util::metrics::{self, prometheus};
17+
use polkadot_node_metrics::metrics::{self, prometheus};
1818

1919
#[derive(Clone)]
2020
pub(crate) struct MetricsInner {

node/core/dispute-coordinator/src/tests.rs

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -395,57 +395,45 @@ impl TestState {
395395
);
396396
finished_steps.got_scraping_information = true;
397397
tx.send(Ok(0)).unwrap();
398-
399-
// If the activated block number is > 1 the scraper will ask for block ancestors. Handle this case.
400-
if block_number > 1 {
401-
assert_matches!(
402-
overseer_recv(virtual_overseer).await,
403-
AllMessages::ChainApi(ChainApiMessage::Ancestors{
404-
hash,
405-
k,
406-
response_channel,
407-
}) => {
408-
assert_eq!(hash, block_hash); // A bit restrictive, remove if it causes problems.
409-
let target_header = self.headers.get(&hash).expect("The function is called for this block so it should exist");
410-
let mut response = Vec::new();
411-
for i in target_header.number.saturating_sub(k as u32)..target_header.number {
412-
response.push(self.block_num_to_header.get(&i).expect("headers and block_num_to_header should always be in sync").clone());
413-
}
414-
let _ = response_channel.send(Ok(response));
415-
}
416-
);
417-
}
418-
419-
assert_matches!(
420-
overseer_recv(virtual_overseer).await,
421-
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
422-
_new_leaf,
423-
RuntimeApiRequest::CandidateEvents(tx),
424-
)) => {
425-
tx.send(Ok(candidate_events.clone())).unwrap();
426-
}
427-
);
428-
gum::trace!("After answering runtime api request");
429-
assert_matches!(
430-
overseer_recv(virtual_overseer).await,
431-
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
432-
_new_leaf,
433-
RuntimeApiRequest::FetchOnChainVotes(tx),
434-
)) => {
435-
//add some `BackedCandidates` or resolved disputes here as needed
436-
tx.send(Ok(Some(ScrapedOnChainVotes {
437-
session,
438-
backing_validators_per_candidate: Vec::default(),
439-
disputes: MultiDisputeStatementSet::default(),
440-
}))).unwrap();
441-
}
442-
);
443-
gum::trace!("After answering runtime API request (votes)");
444398
},
445399
AllMessages::ChainApi(ChainApiMessage::BlockNumber(hash, tx)) => {
446400
let block_num = self.headers.get(&hash).map(|header| header.number);
447401
tx.send(Ok(block_num)).unwrap();
448402
},
403+
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
404+
_new_leaf,
405+
RuntimeApiRequest::CandidateEvents(tx),
406+
)) => {
407+
tx.send(Ok(candidate_events.clone())).unwrap();
408+
},
409+
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
410+
_new_leaf,
411+
RuntimeApiRequest::FetchOnChainVotes(tx),
412+
)) => {
413+
//add some `BackedCandidates` or resolved disputes here as needed
414+
tx.send(Ok(Some(ScrapedOnChainVotes {
415+
session,
416+
backing_validators_per_candidate: Vec::default(),
417+
disputes: MultiDisputeStatementSet::default(),
418+
})))
419+
.unwrap();
420+
},
421+
AllMessages::ChainApi(ChainApiMessage::Ancestors { hash, k, response_channel }) => {
422+
let target_header = self
423+
.headers
424+
.get(&hash)
425+
.expect("The function is called for this block so it should exist");
426+
let mut response = Vec::new();
427+
for i in target_header.number.saturating_sub(k as u32)..target_header.number {
428+
response.push(
429+
self.block_num_to_header
430+
.get(&i)
431+
.expect("headers and block_num_to_header should always be in sync")
432+
.clone(),
433+
);
434+
}
435+
let _ = response_channel.send(Ok(response));
436+
},
449437
msg => {
450438
panic!("Received unexpected message in `handle_sync_queries`: {:?}", msg);
451439
},

0 commit comments

Comments
 (0)