forked from RaoFoundation/subtensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalnet_patch.sh
More file actions
executable file
·64 lines (53 loc) · 2.38 KB
/
Copy pathlocalnet_patch.sh
File metadata and controls
executable file
·64 lines (53 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# This file patches the code in the repository to create a docker image with the ability to run tests in non-fast-runtime
# mode.
set -e
# Function to check for a pattern and apply a replacement
# Args: file_path, search_pattern, replacement_pattern, description
patch_file() {
local file_path="$1"
local search_pattern="$2"
local replacement_pattern="$3"
local description="$4"
# Check if the search pattern exists
if ! grep -qF "$search_pattern" "$file_path" 2>/dev/null && ! grep -qP "$search_pattern" "$file_path" 2>/dev/null; then
echo "Error: Target pattern '$search_pattern' not found in $file_path"
echo "Description: $description"
echo "This may indicate the codebase has changed. Please verify the target code exists."
exit 1
fi
local before_hash after_hash
before_hash=$(cksum "$file_path")
# Apply the replacement
if ! perl -0777 -i -pe "$replacement_pattern" "$file_path"; then
echo "Error: Failed to apply replacement in $file_path"
echo "Description: $description"
exit 1
fi
# The search pattern existing is not enough: the replacement regex must
# actually match, otherwise the patch silently no-ops when the code drifts.
after_hash=$(cksum "$file_path")
if [ "$before_hash" = "$after_hash" ]; then
echo "Error: Replacement pattern did not change $file_path"
echo "Description: $description"
echo "The replacement regex no longer matches the code. Update or remove this patch."
exit 1
fi
}
echo "Applying patches..."
# NOTE: the former Patch 1 (InitialStartCallDelay) was removed: mainline now
# hardcodes `pub const InitialStartCallDelay: u64 = 0;` which already gives
# local testing an immediate start_call.
# Patch 2: DefaultPendingCooldown
patch_file \
"pallets/subtensor/src/lib.rs" \
"pub fn DefaultPendingCooldown<T: Config>() -> u64 {" \
's|pub fn DefaultPendingCooldown<T: Config>\(\) -> u64 \{\s*prod_or_fast!\(7_200, 15\)\s*\}|pub fn DefaultPendingCooldown<T: Config>() -> u64 {\n prod_or_fast!(15, 15)\n }|g' \
"Reduce DefaultPendingCooldown for local testing"
# Patch 3: SetChildren rate limit
patch_file \
"pallets/subtensor/src/utils/rate_limiting.rs" \
"Self::SetChildren => 150, // 30 minutes" \
's|Self::SetChildren => 150, // 30 minutes|Self::SetChildren => 15, // 3 min|' \
"Reduce SetChildren rate limit for local testing"
echo "✓ All patches applied successfully."