From 0470bd6851bbf7d1a4af593ede35d9a628510150 Mon Sep 17 00:00:00 2001
From: Parth <desaiparth08@gmail.com>
Date: Tue, 12 Dec 2023 23:50:08 +0400
Subject: [PATCH] Make crate visible methods of `OverlayedChanges` public
 (#2597)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

# Description

- What does this PR do?
This PR make some methods of `OverlayedChanges` public which were
previously only visible in same crate.
- Why are these changes needed?
Since, some methods of the `OverlayedChanges` only have crate level
visibility, which makes `OverlayedChanges` somewhat unusable outside the
crate to create custom implementation of `Externalities`. We make those
method public to enable `OverlayedChanges` to remedy this.
- How were these changes implemented and what do they affect?
Changes are implemented by replacing crate visibility to public
visibility of 4 functions.


# Checklist

- [x] My PR includes a detailed description as outlined in the
"Description" section above
- [ ] My PR follows the [labeling requirements](CONTRIBUTING.md#Process)
of this project (at minimum one label for `T`
  required)
- [ ] I have made corresponding changes to the documentation (if
applicable)
- [ ] I have added tests that prove my fix is effective or that my
feature works (if applicable)

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
---
 prdoc/pr_2597.prdoc                             | 17 +++++++++++++++++
 .../state-machine/src/overlayed_changes/mod.rs  |  8 ++++----
 2 files changed, 21 insertions(+), 4 deletions(-)
 create mode 100644 prdoc/pr_2597.prdoc

diff --git a/prdoc/pr_2597.prdoc b/prdoc/pr_2597.prdoc
new file mode 100644
index 00000000000..33d85053184
--- /dev/null
+++ b/prdoc/pr_2597.prdoc
@@ -0,0 +1,17 @@
+title: Make crate visible methods of `OverlayedChanges` public.
+
+doc:
+  - audience: Node Dev
+    description: | 
+      Make some methods of `OverlayedChanges` namely `set_child_storage`, `clear_child_storage`, `clear_prefix` 
+      and `clear_child_prefix` public which only had crate level visibility.
+
+migrations:
+  db: []
+
+  runtime: []
+
+crates:
+  - name: sp-state-machine
+
+host_functions: []
diff --git a/substrate/primitives/state-machine/src/overlayed_changes/mod.rs b/substrate/primitives/state-machine/src/overlayed_changes/mod.rs
index 9525c2c9dfe..626cf6c3caf 100644
--- a/substrate/primitives/state-machine/src/overlayed_changes/mod.rs
+++ b/substrate/primitives/state-machine/src/overlayed_changes/mod.rs
@@ -348,7 +348,7 @@ impl<H: Hasher> OverlayedChanges<H> {
 	/// `None` can be used to delete a value specified by the given key.
 	///
 	/// Can be rolled back or committed when called inside a transaction.
-	pub(crate) fn set_child_storage(
+	pub fn set_child_storage(
 		&mut self,
 		child_info: &ChildInfo,
 		key: StorageKey,
@@ -373,7 +373,7 @@ impl<H: Hasher> OverlayedChanges<H> {
 	/// Clear child storage of given storage key.
 	///
 	/// Can be rolled back or committed when called inside a transaction.
-	pub(crate) fn clear_child_storage(&mut self, child_info: &ChildInfo) -> u32 {
+	pub fn clear_child_storage(&mut self, child_info: &ChildInfo) -> u32 {
 		self.mark_dirty();
 
 		let extrinsic_index = self.extrinsic_index();
@@ -391,7 +391,7 @@ impl<H: Hasher> OverlayedChanges<H> {
 	/// Removes all key-value pairs which keys share the given prefix.
 	///
 	/// Can be rolled back or committed when called inside a transaction.
-	pub(crate) fn clear_prefix(&mut self, prefix: &[u8]) -> u32 {
+	pub fn clear_prefix(&mut self, prefix: &[u8]) -> u32 {
 		self.mark_dirty();
 
 		self.top.clear_where(|key, _| key.starts_with(prefix), self.extrinsic_index())
@@ -400,7 +400,7 @@ impl<H: Hasher> OverlayedChanges<H> {
 	/// Removes all key-value pairs which keys share the given prefix.
 	///
 	/// Can be rolled back or committed when called inside a transaction
-	pub(crate) fn clear_child_prefix(&mut self, child_info: &ChildInfo, prefix: &[u8]) -> u32 {
+	pub fn clear_child_prefix(&mut self, child_info: &ChildInfo, prefix: &[u8]) -> u32 {
 		self.mark_dirty();
 
 		let extrinsic_index = self.extrinsic_index();
-- 
GitLab