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

Duplicate codec index in Message #7400

Open
serban300 opened this issue Jan 30, 2025 · 1 comment
Open

Duplicate codec index in Message #7400

serban300 opened this issue Jan 30, 2025 · 1 comment
Assignees
Labels
I2-bug The node fails to follow expected behavior.

Comments

@serban300
Copy link
Contributor

This is related to the Message struct in polkadot-sdk/substrate/client/network/src/protocol/message.rs:

	/// A network message.
	#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
	pub enum Message<Header, Hash, Number, Extrinsic> {
		/// Status packet.
		Status(Status<Hash, Number>),
		/// Block request.
		BlockRequest(BlockRequest<Hash, Number>),
		/// Block response.
		BlockResponse(BlockResponse<Header, Hash, Extrinsic>),
		/// Block announce.
		BlockAnnounce(BlockAnnounce<Header>),
		/// Consensus protocol message.
		// NOTE: index is incremented by 1 due to transaction-related
		// message that was removed
		#[codec(index = 6)]
		Consensus(ConsensusMessage),
		/// Remote method call request.
		RemoteCallRequest(RemoteCallRequest<Hash>),
		/// Remote method call response.
		RemoteCallResponse(RemoteCallResponse),
		/// Remote storage read request.
		RemoteReadRequest(RemoteReadRequest<Hash>),
		/// Remote storage read response.
		RemoteReadResponse(RemoteReadResponse),
		/// Remote header request.
		RemoteHeaderRequest(RemoteHeaderRequest<Number>),
		/// Remote header response.
		RemoteHeaderResponse(RemoteHeaderResponse<Header>),
		/// Remote changes request.
		RemoteChangesRequest(RemoteChangesRequest<Hash>),
		/// Remote changes response.
		RemoteChangesResponse(RemoteChangesResponse<Number, Hash>),
		/// Remote child storage read request.
		RemoteReadChildRequest(RemoteReadChildRequest<Hash>),
		/// Batch of consensus protocol messages.
		// NOTE: index is incremented by 2 due to finality proof related
		// messages that were removed.
		#[codec(index = 17)]
		ConsensusBatch(Vec<ConsensusMessage>),
	}

This encodes to:

                    fn encode_to<__CodecOutputEdqy: ::codec::Output + ?::core::marker::Sized>(
                        &self,
                        __codec_dest_edqy: &mut __CodecOutputEdqy,
                    ) {
                        match *self {
                            Message::Status(ref aa) => {
                                __codec_dest_edqy.push_byte(0usize as ::core::primitive::u8);
                                ::codec::Encode::encode_to(aa, __codec_dest_edqy);
                            }
                            Message::BlockRequest(ref aa) => {
                                __codec_dest_edqy.push_byte(1usize as ::core::primitive::u8);
                                ::codec::Encode::encode_to(aa, __codec_dest_edqy);
                            }
                            Message::BlockResponse(ref aa) => {
                                __codec_dest_edqy.push_byte(2usize as ::core::primitive::u8);
                                ::codec::Encode::encode_to(aa, __codec_dest_edqy);
                            }
                            Message::BlockAnnounce(ref aa) => {
                                __codec_dest_edqy.push_byte(3usize as ::core::primitive::u8);
                                ::codec::Encode::encode_to(aa, __codec_dest_edqy);
                            }
                            Message::Consensus(ref aa) => {
                                __codec_dest_edqy.push_byte(6u8 as ::core::primitive::u8);
                                ::codec::Encode::encode_to(aa, __codec_dest_edqy);
                            }
                            Message::RemoteCallRequest(ref aa) => {
                                __codec_dest_edqy.push_byte(5usize as ::core::primitive::u8);
                                ::codec::Encode::encode_to(aa, __codec_dest_edqy);
                            }
                            Message::RemoteCallResponse(ref aa) => {
                                __codec_dest_edqy.push_byte(6usize as ::core::primitive::u8);
                                ::codec::Encode::encode_to(aa, __codec_dest_edqy);
                            }
                            Message::RemoteReadRequest(ref aa) => {
                                __codec_dest_edqy.push_byte(7usize as ::core::primitive::u8);
                                ::codec::Encode::encode_to(aa, __codec_dest_edqy);
                            }
                            ...
                        }
                    }
                }

Index 6 is used both for Consensus and for RemoteCallResponse

@serban300 serban300 added the I2-bug The node fails to follow expected behavior. label Jan 30, 2025
@serban300
Copy link
Contributor Author

serban300 commented Jan 30, 2025

Uncovered by paritytech/parity-scale-codec#653

We either need to fix this struct or change the parity-scale-codec logic

Related to paritytech/parity-scale-codec#691 as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I2-bug The node fails to follow expected behavior.
Projects
None yet
Development

No branches or pull requests

1 participant