Skip to content

EquivocationReportSystem trait bounds can recursively use T::KeyOwnerProof in some cases #2641

@StackOverflowExcept1on

Description

@StackOverflowExcept1on

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Description of bug

This PR was merged recently: rust-lang/rust#115801 and it breaks some things. You can't recursively get Trait::AssociatedType. Now this won't compile.

We encountered this problem when building with the -C instrument-coverage flag, but maybe there is some other way to cause it.

The problem is that in rococo runtime or some custom runtime you can do the following:

type KeyOwnerProof =
<Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof;
type EquivocationReportSystem =
pallet_babe::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;

So, it goes to EquivocationReportSystem:

impl<T, R, P, L>
	OffenceReportSystem<Option<T::AccountId>, (EquivocationProof<T::Header>, T::KeyOwnerProof)>
	for EquivocationReportSystem<T, R, P, L>
where
	T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
	R: ReportOffence<
		T::AccountId,
		P::IdentificationTuple,
		EquivocationOffence<P::IdentificationTuple>,
	>,
	P: KeyOwnerProofSystem<(KeyTypeId, AuthorityId), Proof = T::KeyOwnerProof>, //recursion occurs in associated types
	P::IdentificationTuple: Clone,
	L: Get<u64>,
{ ... }

The compiler cannot resolve recursion in associated types:

type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof; 
P: KeyOwnerProofSystem<(KeyTypeId, AuthorityId), Proof = T::KeyOwnerProof>

We can see Proof = T::KeyOwnerProof in P: ..., but the KeyOwnerProof from Config trying to resolve associated type ::Proof. It causes recursion and we do <<T::Proof>::Proof>::Proof...

Steps to reproduce

You can try build rococo runtime with RUSTFLAGS="-C instrument-coverage". Also see: rust-lang/rust#117211

$ RUSTFLAGS="-Cinstrument-coverage" cargo +nightly-2023-10-14 build -p rococo-runtime --release

   Compiling rococo-runtime v1.0.0 (/home/.../work/polkadot-sdk/polkadot/runtime/rococo)
    Building [=======================> ] 639/640: rococo-runtime
error[E0275]: overflow evaluating the requirement `<Runtime as pallet_grandpa::Config>::KeyOwnerProof == _`

For more information about this error, try `rustc --explain E0275`.
error: could not compile `rococo-runtime` (lib) due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    I10-unconfirmedIssue might be valid, but it's not yet known.I2-bugThe node fails to follow expected behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions