From c9e5cf1b128de840d44ab1c8c60cfc61e44a869e Mon Sep 17 00:00:00 2001
From: s0me0ne-unkn0wn <48632512+s0me0ne-unkn0wn@users.noreply.github.com>
Date: Wed, 28 Aug 2024 16:32:42 +0200
Subject: [PATCH] [Backport] Add feature to allow Aura collator to use full PoV
 size (#5393) (#5507)

This PR introduces a feature that allows to optionally enable using the
full PoV size.

Technically, we're ready to enable it by default, but as corresponding
runtime changes have not been propagated to the system parachain
runtimes yet, doing so could put them at risk. On the other hand, there
are teams that could benefit from it right now, and it makes no sense
for them to wait for the fellowship release and everything.

---------

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
---
 cumulus/client/consensus/aura/Cargo.toml         |  4 ++++
 .../client/consensus/aura/src/collators/basic.rs | 16 +++++++++++-----
 .../consensus/aura/src/collators/lookahead.rs    | 16 +++++++++++-----
 .../collators/slot_based/block_builder_task.rs   | 16 +++++++++++-----
 prdoc/pr_5507.prdoc                              | 15 +++++++++++++++
 5 files changed, 52 insertions(+), 15 deletions(-)
 create mode 100644 prdoc/pr_5507.prdoc

diff --git a/cumulus/client/consensus/aura/Cargo.toml b/cumulus/client/consensus/aura/Cargo.toml
index 0b4f1352a0f..f393305ae4f 100644
--- a/cumulus/client/consensus/aura/Cargo.toml
+++ b/cumulus/client/consensus/aura/Cargo.toml
@@ -79,3 +79,7 @@ polkadot-node-subsystem.workspace = true
 polkadot-node-subsystem.default-features = true
 polkadot-overseer.workspace = true
 polkadot-overseer.default-features = true
+
+[features]
+# Allows collator to use full PoV size for block building
+full-pov-size = []
diff --git a/cumulus/client/consensus/aura/src/collators/basic.rs b/cumulus/client/consensus/aura/src/collators/basic.rs
index 4efd50a04ec..16fbb10a209 100644
--- a/cumulus/client/consensus/aura/src/collators/basic.rs
+++ b/cumulus/client/consensus/aura/src/collators/basic.rs
@@ -234,6 +234,16 @@ where
 					.await
 			);
 
+			let allowed_pov_size = if cfg!(feature = "full-pov-size") {
+				validation_data.max_pov_size
+			} else {
+				// Set the block limit to 50% of the maximum PoV size.
+				//
+				// TODO: If we got benchmarking that includes the proof size,
+				// we should be able to use the maximum pov size.
+				validation_data.max_pov_size / 2
+			} as usize;
+
 			let maybe_collation = try_request!(
 				collator
 					.collate(
@@ -242,11 +252,7 @@ where
 						None,
 						(parachain_inherent_data, other_inherent_data),
 						params.authoring_duration,
-						// Set the block limit to 50% of the maximum PoV size.
-						//
-						// TODO: If we got benchmarking that includes the proof size,
-						// we should be able to use the maximum pov size.
-						(validation_data.max_pov_size / 2) as usize,
+						allowed_pov_size,
 					)
 					.await
 			);
diff --git a/cumulus/client/consensus/aura/src/collators/lookahead.rs b/cumulus/client/consensus/aura/src/collators/lookahead.rs
index 749b1311239..ab16d9375dd 100644
--- a/cumulus/client/consensus/aura/src/collators/lookahead.rs
+++ b/cumulus/client/consensus/aura/src/collators/lookahead.rs
@@ -319,6 +319,16 @@ where
 				)
 				.await;
 
+				let allowed_pov_size = if cfg!(feature = "full-pov-size") {
+					validation_data.max_pov_size
+				} else {
+					// Set the block limit to 50% of the maximum PoV size.
+					//
+					// TODO: If we got benchmarking that includes the proof size,
+					// we should be able to use the maximum pov size.
+					validation_data.max_pov_size / 2
+				} as usize;
+
 				match collator
 					.collate(
 						&parent_header,
@@ -326,11 +336,7 @@ where
 						None,
 						(parachain_inherent_data, other_inherent_data),
 						params.authoring_duration,
-						// Set the block limit to 50% of the maximum PoV size.
-						//
-						// TODO: If we got benchmarking that includes the proof size,
-						// we should be able to use the maximum pov size.
-						(validation_data.max_pov_size / 2) as usize,
+						allowed_pov_size,
 					)
 					.await
 				{
diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs
index 1fbc0689da8..b70cfe3841b 100644
--- a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs
+++ b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs
@@ -350,6 +350,16 @@ where
 			)
 			.await;
 
+			let allowed_pov_size = if cfg!(feature = "full-pov-size") {
+				validation_data.max_pov_size
+			} else {
+				// Set the block limit to 50% of the maximum PoV size.
+				//
+				// TODO: If we got benchmarking that includes the proof size,
+				// we should be able to use the maximum pov size.
+				validation_data.max_pov_size / 2
+			} as usize;
+
 			let Ok(Some(candidate)) = collator
 				.build_block_and_import(
 					&parent_header,
@@ -357,11 +367,7 @@ where
 					None,
 					(parachain_inherent_data, other_inherent_data),
 					authoring_duration,
-					// Set the block limit to 50% of the maximum PoV size.
-					//
-					// TODO: If we got benchmarking that includes the proof size,
-					// we should be able to use the maximum pov size.
-					(validation_data.max_pov_size / 2) as usize,
+					allowed_pov_size,
 				)
 				.await
 			else {
diff --git a/prdoc/pr_5507.prdoc b/prdoc/pr_5507.prdoc
new file mode 100644
index 00000000000..7fcf3067fab
--- /dev/null
+++ b/prdoc/pr_5507.prdoc
@@ -0,0 +1,15 @@
+# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
+# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
+
+title: Allow to enable full PoV size
+
+doc:
+  - audience: Node Dev
+    description: |
+      A feature is introduced allowing a collator to enable full PoV size at compile time.
+      WARNING: To use this feature, security considerations must be understood and the latest
+      SDK version must be used.
+
+crates:
+  - name: cumulus-client-consensus-aura
+    bump: minor
-- 
GitLab