feat: initialize Kurdistan SDK - independent fork of Polkadot SDK

This commit is contained in:
2025-12-13 15:44:15 +03:00
commit e4778b4576
6838 changed files with 1847450 additions and 0 deletions
+191
View File
@@ -0,0 +1,191 @@
#!/usr/bin/env bash
# Run a two node local net with adder-collator.
set -e
chainspec="pezkuwichain-local"
# disabled until we can actually successfully register the chain with pezkuwi-js-api
# if ! command -v pezkuwi-js-api > /dev/null; then
# echo "pezkuwi-js-api required; try"
# echo " sudo yarn global add @pezkuwi/api-cli"
# exit 1
# fi
PROJECT_ROOT=$(git rev-parse --show-toplevel)
# shellcheck disable=SC1090
source "$(dirname "$0")"/common.sh
cd "$PROJECT_ROOT"
last_modified_rust_file=$(
find . -path ./target -prune -o -type f -name '*.rs' -printf '%T@ %p\n' |
sort -nr |
head -1 |
cut -d' ' -f2-
)
pezkuwi="target/release/pezkuwi"
adder_collator="target/release/adder-collator"
# ensure the pezkuwi binary exists and is up to date
if [ ! -x "$pezkuwi" ] || [ "$pezkuwi" -ot "$last_modified_rust_file" ]; then
cargo build --release
fi
# likewise for the adder collator
if [ ! -x "$adder_collator" ] || [ "$adder_collator" -ot "$last_modified_rust_file" ]; then
cargo build --release -p test-teyrchain-adder-collator
fi
genesis="$(mktemp --directory)"
genesis_state="$genesis/state"
validation_code="$genesis/validation_code"
"$adder_collator" export-genesis-state > "$genesis_state"
"$adder_collator" export-genesis-wasm > "$validation_code"
# setup variables
node_offset=0
declare -a node_pids
declare -a node_pipes
# create a sed expression which injects the node name and stream type into each line
function make_sed_expr() {
name="$1"
type="$2"
printf "s/^/%16s %s: /" "$name" "$type"
}
# turn a string into a flag
function flagify() {
printf -- '--%s' "$(tr '[:upper:]' '[:lower:]' <<< "$1")"
}
# start a node and label its output
#
# This function takes a single argument, the node name.
# The name must be one of those which can be passed to the pezkuwi binary, in un-flagged form,
# one of:
# alice, bob, charlie, dave, eve, ferdie, one, two
function run_node() {
name="$1"
# create a named pipe so we can get the node's PID while also sedding its output
local stdout
local stderr
stdout=$(mktemp --dry-run --tmpdir)
stderr=$(mktemp --dry-run --tmpdir)
mkfifo "$stdout"
mkfifo "$stderr"
node_pipes+=("$stdout")
node_pipes+=("$stderr")
# compute ports from offset
local port=$((30333+node_offset))
local rpc_port=$((9933+node_offset))
local ws_port=$((9944+node_offset))
local prometheus_port=$((9615+node_offset))
node_offset=$((node_offset+1))
# start the node
"$pezkuwi" \
--chain "$chainspec" \
--tmp \
--port "$port" \
--rpc-port "$rpc_port" \
--ws-port "$ws_port" \
--prometheus-port "$prometheus_port" \
--rpc-cors all \
"$(flagify "$name")" \
> "$stdout" \
2> "$stderr" \
&
local pid=$!
node_pids+=("$pid")
# send output from the stdout pipe to stdout, prepending the node name
sed -e "$(make_sed_expr "$name" "OUT")" "$stdout" >&1 &
# send output from the stderr pipe to stderr, prepending the node name
sed -e "$(make_sed_expr "$name" "ERR")" "$stderr" >&2 &
}
# start an adder collator and label its output
#
# This function takes a single argument, the node name. This affects only the tagging.
function run_adder_collator() {
name="$1"
# create a named pipe so we can get the node's PID while also sedding its output
local stdout
local stderr
stdout=$(mktemp --dry-run --tmpdir)
stderr=$(mktemp --dry-run --tmpdir)
mkfifo "$stdout"
mkfifo "$stderr"
node_pipes+=("$stdout")
node_pipes+=("$stderr")
# compute ports from offset
local port=$((30333+node_offset))
local rpc_port=$((9933+node_offset))
local ws_port=$((9944+node_offset))
local prometheus_port=$((9615+node_offset))
node_offset=$((node_offset+1))
# start the node
"$adder_collator" \
--chain "$chainspec" \
--tmp \
--port "$port" \
--rpc-port "$rpc_port" \
--ws-port "$ws_port" \
--prometheus-port "$prometheus_port" \
--rpc-cors all \
> "$stdout" \
2> "$stderr" \
&
local pid=$!
node_pids+=("$pid")
# send output from the stdout pipe to stdout, prepending the node name
sed -e "$(make_sed_expr "$name" "OUT")" "$stdout" >&1 &
# send output from the stderr pipe to stderr, prepending the node name
sed -e "$(make_sed_expr "$name" "ERR")" "$stderr" >&2 &
}
# clean up the nodes when this script exits
function finish {
for node_pid in "${node_pids[@]}"; do
kill -9 "$node_pid"
done
for node_pipe in "${node_pipes[@]}"; do
rm "$node_pipe"
done
rm -rf "$genesis"
}
trap finish EXIT
# start the nodes
run_node Alice
run_node Bob
run_adder_collator AdderCollator
# register the adder collator
# doesn't work yet due to https://github.com/polkadot-js/tools/issues/185
# pezkuwi-js-api \
# --ws ws://localhost:9944 \
# --sudo \
# --seed "//Alice" \
# tx.registrar.registerPara \
# 100 \
# '{"scheduling":"Always"}' \
# "@$validation_code" \
# "@$genesis_state"
# now wait; this will exit on its own only if both subprocesses exit
# the practical implication, as both subprocesses are supposed to run forever, is that
# this script will also run forever, until killed, at which point the exit trap should kill
# the subprocesses
wait
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env sh
# Script for building only the WASM binary of the given project.
set -e
PROJECT_ROOT=`git rev-parse --show-toplevel`
if [ "$#" -lt 1 ]; then
echo "You need to pass the name of the crate you want to compile!"
exit 1
fi
WASM_BUILDER_RUNNER="$PROJECT_ROOT/target/release/wbuild-runner/$1"
fl_cargo () {
if command -v forklift >/dev/null 2>&1; then
forklift cargo "$@";
else
cargo "$@";
fi
}
if [ -z "$2" ]; then
export WASM_TARGET_DIRECTORY=$(pwd)
else
export WASM_TARGET_DIRECTORY=$2
fi
if [ -d $WASM_BUILDER_RUNNER ]; then
export DEBUG=false
export OUT_DIR="$PROJECT_ROOT/target/release/build"
fl_cargo run --release --manifest-path="$WASM_BUILDER_RUNNER/Cargo.toml" \
| grep -vE "cargo:rerun-if-|Executing build command"
else
fl_cargo build --release -p $1
fi
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
ROOT=`dirname "$0"`
# A list of directories which contain wasm projects.
SRCS=(
"runtime/wasm"
)
DEMOS=(
"test-teyrchains/addr test-teyrchains/halt test-teyrchains/undying"
)
# Make pushd/popd silent.
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}
@@ -0,0 +1,70 @@
0 (read)
1 (write)
2 (open)
3 (close)
4 (stat)
5 (fstat)
7 (poll)
8 (lseek)
9 (mmap)
10 (mprotect)
11 (munmap)
12 (brk)
13 (rt_sigaction)
14 (rt_sigprocmask)
15 (rt_sigreturn)
20 (writev)
22 (pipe)
24 (sched_yield)
25 (mremap)
28 (madvise)
34 (pause)
39 (getpid)
41 (socket)
42 (connect)
45 (recvfrom)
56 (clone)
57 (fork)
60 (exit)
61 (wait4)
62 (kill)
72 (fcntl)
79 (getcwd)
80 (chdir)
82 (rename)
83 (mkdir)
87 (unlink)
89 (readlink)
96 (gettimeofday)
97 (getrlimit)
98 (getrusage)
99 (sysinfo)
110 (getppid)
131 (sigaltstack)
140 (getpriority)
141 (setpriority)
144 (sched_setscheduler)
157 (prctl)
158 (arch_prctl)
165 (mount)
166 (umount2)
186 (gettid)
200 (tkill)
202 (futex)
203 (sched_setaffinity)
204 (sched_getaffinity)
217 (getdents64)
218 (set_tid_address)
228 (clock_gettime)
230 (clock_nanosleep)
231 (exit_group)
257 (openat)
262 (newfstatat)
263 (unlinkat)
272 (unshare)
273 (set_robust_list)
293 (pipe2)
302 (prlimit64)
309 (getcpu)
318 (getrandom)
319 (memfd_create)
+608
View File
@@ -0,0 +1,608 @@
#!/usr/bin/ruby
# A script to statically list syscalls used by a given binary.
#
# Syntax: list-syscalls.rb <binary> [--only-used-syscalls]
#
# NOTE: For accurate results, build the binary with musl and LTO enabled.
# Example: ./polkadot/scripts/list-syscalls/list-syscalls.rb target/x86_64-unknown-linux-musl/production/polkadot-prepare-worker --only-used-syscalls
#
# Author: @koute
# Source: https://gist.github.com/koute/166f82bfee5e27324077891008fca6eb
require 'shellwords'
require 'set'
SYNTAX_STRING = 'Syntax: list-syscalls.rb <binary> [--only-used-syscalls]'.freeze
# Generated from `libc` using the following regex:
# 'pub const SYS_([a-z0-9_]+): ::c_long = (\d+);'
# ' \2 => "\1",'
SYSCALLS = {
0 => 'read',
1 => 'write',
2 => 'open',
3 => 'close',
4 => 'stat',
5 => 'fstat',
6 => 'lstat',
7 => 'poll',
8 => 'lseek',
9 => 'mmap',
10 => 'mprotect',
11 => 'munmap',
12 => 'brk',
13 => 'rt_sigaction',
14 => 'rt_sigprocmask',
15 => 'rt_sigreturn',
16 => 'ioctl',
17 => 'pread64',
18 => 'pwrite64',
19 => 'readv',
20 => 'writev',
21 => 'access',
22 => 'pipe',
23 => 'select',
24 => 'sched_yield',
25 => 'mremap',
26 => 'msync',
27 => 'mincore',
28 => 'madvise',
29 => 'shmget',
30 => 'shmat',
31 => 'shmctl',
32 => 'dup',
33 => 'dup2',
34 => 'pause',
35 => 'nanosleep',
36 => 'getitimer',
37 => 'alarm',
38 => 'setitimer',
39 => 'getpid',
40 => 'sendfile',
41 => 'socket',
42 => 'connect',
43 => 'accept',
44 => 'sendto',
45 => 'recvfrom',
46 => 'sendmsg',
47 => 'recvmsg',
48 => 'shutdown',
49 => 'bind',
50 => 'listen',
51 => 'getsockname',
52 => 'getpeername',
53 => 'socketpair',
54 => 'setsockopt',
55 => 'getsockopt',
56 => 'clone',
57 => 'fork',
58 => 'vfork',
59 => 'execve',
60 => 'exit',
61 => 'wait4',
62 => 'kill',
63 => 'uname',
64 => 'semget',
65 => 'semop',
66 => 'semctl',
67 => 'shmdt',
68 => 'msgget',
69 => 'msgsnd',
70 => 'msgrcv',
71 => 'msgctl',
72 => 'fcntl',
73 => 'flock',
74 => 'fsync',
75 => 'fdatasync',
76 => 'truncate',
77 => 'ftruncate',
78 => 'getdents',
79 => 'getcwd',
80 => 'chdir',
81 => 'fchdir',
82 => 'rename',
83 => 'mkdir',
84 => 'rmdir',
85 => 'creat',
86 => 'link',
87 => 'unlink',
88 => 'symlink',
89 => 'readlink',
90 => 'chmod',
91 => 'fchmod',
92 => 'chown',
93 => 'fchown',
94 => 'lchown',
95 => 'umask',
96 => 'gettimeofday',
97 => 'getrlimit',
98 => 'getrusage',
99 => 'sysinfo',
100 => 'times',
101 => 'ptrace',
102 => 'getuid',
103 => 'syslog',
104 => 'getgid',
105 => 'setuid',
106 => 'setgid',
107 => 'geteuid',
108 => 'getegid',
109 => 'setpgid',
110 => 'getppid',
111 => 'getpgrp',
112 => 'setsid',
113 => 'setreuid',
114 => 'setregid',
115 => 'getgroups',
116 => 'setgroups',
117 => 'setresuid',
118 => 'getresuid',
119 => 'setresgid',
120 => 'getresgid',
121 => 'getpgid',
122 => 'setfsuid',
123 => 'setfsgid',
124 => 'getsid',
125 => 'capget',
126 => 'capset',
127 => 'rt_sigpending',
128 => 'rt_sigtimedwait',
129 => 'rt_sigqueueinfo',
130 => 'rt_sigsuspend',
131 => 'sigaltstack',
132 => 'utime',
133 => 'mknod',
134 => 'uselib',
135 => 'personality',
136 => 'ustat',
137 => 'statfs',
138 => 'fstatfs',
139 => 'sysfs',
140 => 'getpriority',
141 => 'setpriority',
142 => 'sched_setparam',
143 => 'sched_getparam',
144 => 'sched_setscheduler',
145 => 'sched_getscheduler',
146 => 'sched_get_priority_max',
147 => 'sched_get_priority_min',
148 => 'sched_rr_get_interval',
149 => 'mlock',
150 => 'munlock',
151 => 'mlockall',
152 => 'munlockall',
153 => 'vhangup',
154 => 'modify_ldt',
155 => 'pivot_root',
156 => '_sysctl',
157 => 'prctl',
158 => 'arch_prctl',
159 => 'adjtimex',
160 => 'setrlimit',
161 => 'chroot',
162 => 'sync',
163 => 'acct',
164 => 'settimeofday',
165 => 'mount',
166 => 'umount2',
167 => 'swapon',
168 => 'swapoff',
169 => 'reboot',
170 => 'sethostname',
171 => 'setdomainname',
172 => 'iopl',
173 => 'ioperm',
174 => 'create_module',
175 => 'init_module',
176 => 'delete_module',
177 => 'get_kernel_syms',
178 => 'query_module',
179 => 'quotactl',
180 => 'nfsservctl',
181 => 'getpmsg',
182 => 'putpmsg',
183 => 'afs_syscall',
184 => 'tuxcall',
185 => 'security',
186 => 'gettid',
187 => 'readahead',
188 => 'setxattr',
189 => 'lsetxattr',
190 => 'fsetxattr',
191 => 'getxattr',
192 => 'lgetxattr',
193 => 'fgetxattr',
194 => 'listxattr',
195 => 'llistxattr',
196 => 'flistxattr',
197 => 'removexattr',
198 => 'lremovexattr',
199 => 'fremovexattr',
200 => 'tkill',
201 => 'time',
202 => 'futex',
203 => 'sched_setaffinity',
204 => 'sched_getaffinity',
205 => 'set_thread_area',
206 => 'io_setup',
207 => 'io_destroy',
208 => 'io_getevents',
209 => 'io_submit',
210 => 'io_cancel',
211 => 'get_thread_area',
212 => 'lookup_dcookie',
213 => 'epoll_create',
214 => 'epoll_ctl_old',
215 => 'epoll_wait_old',
216 => 'remap_file_pages',
217 => 'getdents64',
218 => 'set_tid_address',
219 => 'restart_syscall',
220 => 'semtimedop',
221 => 'fadvise64',
222 => 'timer_create',
223 => 'timer_settime',
224 => 'timer_gettime',
225 => 'timer_getoverrun',
226 => 'timer_delete',
227 => 'clock_settime',
228 => 'clock_gettime',
229 => 'clock_getres',
230 => 'clock_nanosleep',
231 => 'exit_group',
232 => 'epoll_wait',
233 => 'epoll_ctl',
234 => 'tgkill',
235 => 'utimes',
236 => 'vserver',
237 => 'mbind',
238 => 'set_mempolicy',
239 => 'get_mempolicy',
240 => 'mq_open',
241 => 'mq_unlink',
242 => 'mq_timedsend',
243 => 'mq_timedreceive',
244 => 'mq_notify',
245 => 'mq_getsetattr',
246 => 'kexec_load',
247 => 'waitid',
248 => 'add_key',
249 => 'request_key',
250 => 'keyctl',
251 => 'ioprio_set',
252 => 'ioprio_get',
253 => 'inotify_init',
254 => 'inotify_add_watch',
255 => 'inotify_rm_watch',
256 => 'migrate_pages',
257 => 'openat',
258 => 'mkdirat',
259 => 'mknodat',
260 => 'fchownat',
261 => 'futimesat',
262 => 'newfstatat',
263 => 'unlinkat',
264 => 'renameat',
265 => 'linkat',
266 => 'symlinkat',
267 => 'readlinkat',
268 => 'fchmodat',
269 => 'faccessat',
270 => 'pselect6',
271 => 'ppoll',
272 => 'unshare',
273 => 'set_robust_list',
274 => 'get_robust_list',
275 => 'splice',
276 => 'tee',
277 => 'sync_file_range',
278 => 'vmsplice',
279 => 'move_pages',
280 => 'utimensat',
281 => 'epoll_pwait',
282 => 'signalfd',
283 => 'timerfd_create',
284 => 'eventfd',
285 => 'fallocate',
286 => 'timerfd_settime',
287 => 'timerfd_gettime',
288 => 'accept4',
289 => 'signalfd4',
290 => 'eventfd2',
291 => 'epoll_create1',
292 => 'dup3',
293 => 'pipe2',
294 => 'inotify_init1',
295 => 'preadv',
296 => 'pwritev',
297 => 'rt_tgsigqueueinfo',
298 => 'perf_event_open',
299 => 'recvmmsg',
300 => 'fanotify_init',
301 => 'fanotify_mark',
302 => 'prlimit64',
303 => 'name_to_handle_at',
304 => 'open_by_handle_at',
305 => 'clock_adjtime',
306 => 'syncfs',
307 => 'sendmmsg',
308 => 'setns',
309 => 'getcpu',
310 => 'process_vm_readv',
311 => 'process_vm_writev',
312 => 'kcmp',
313 => 'finit_module',
314 => 'sched_setattr',
315 => 'sched_getattr',
316 => 'renameat2',
317 => 'seccomp',
318 => 'getrandom',
319 => 'memfd_create',
320 => 'kexec_file_load',
321 => 'bpf',
322 => 'execveat',
323 => 'userfaultfd',
324 => 'membarrier',
325 => 'mlock2',
326 => 'copy_file_range',
327 => 'preadv2',
328 => 'pwritev2',
329 => 'pkey_mprotect',
330 => 'pkey_alloc',
331 => 'pkey_free',
332 => 'statx',
334 => 'rseq',
424 => 'pidfd_send_signal',
425 => 'io_uring_setup',
426 => 'io_uring_enter',
427 => 'io_uring_register',
428 => 'open_tree',
429 => 'move_mount',
430 => 'fsopen',
431 => 'fsconfig',
432 => 'fsmount',
433 => 'fspick',
434 => 'pidfd_open',
435 => 'clone3',
436 => 'close_range',
437 => 'openat2',
438 => 'pidfd_getfd',
439 => 'faccessat2',
440 => 'process_madvise',
441 => 'epoll_pwait2',
442 => 'mount_setattr',
443 => 'quotactl_fd',
444 => 'landlock_create_ruleset',
445 => 'landlock_add_rule',
446 => 'landlock_restrict_self',
447 => 'memfd_secret',
448 => 'process_mrelease',
449 => 'futex_waitv',
450 => 'set_mempolicy_home_node'
}.map { |num, name| [num, "#{num} (#{name})"] }.to_h
REGS_R64 = %w[
rax
rbx
rcx
rdx
rsi
rdi
rsp
rbp
r8
r9
r10
r11
r12
r13
r14
r15
]
REGS_R32 = %w[
eax
ebx
ecx
edx
esi
edi
esp
ebp
r8d
r9d
r10d
r11d
r12d
r13d
r14d
r15d
]
REGS_R16 = %w[
ax
bx
cx
dx
si
di
sp
bp
r8w
r9w
r10w
r11w
r12w
r13w
r14w
r15w
]
REGS_R8 = %w[
al
bl
cl
dl
sil
dil
spl
bpl
r8b
r9b
r10b
r11b
r12b
r13b
r14b
r15b
]
REG_MAP = (REGS_R64.map { |r| [r, r] } + REGS_R32.zip(REGS_R64) + REGS_R16.zip(REGS_R64) + REGS_R8.zip(REGS_R64)).to_h
REGS_R = (REGS_R64 + REGS_R32 + REGS_R16 + REGS_R8).join('|')
if ARGV.empty?
warn SYNTAX_STRING
exit 1
end
file_path = ARGV[0]
raise "no such file: #{file_path}" unless File.exist? file_path
only_used_syscalls = false
ARGV[1..].each do |arg|
if arg == '--only-used-syscalls'
only_used_syscalls = true
else
warn "invalid argument '#{arg}':\n#{SYNTAX_STRING}"
exit 1
end
end
puts 'Running objdump...' unless only_used_syscalls
dump = `objdump -wd -j .text -M intel #{file_path.shellescape}`
raise 'objdump failed' unless $?.exitstatus == 0
puts 'Parsing objdump output...' unless only_used_syscalls
current_fn = nil
code_for_fn = {}
fns_with_syscall = Set.new
fns_with_indirect_syscall = Set.new
dump.split("\n").each do |line|
if line =~ /\A[0-9a-f]+ <(.+?)>:/
current_fn = Regexp.last_match(1)
next
end
next unless current_fn
next if %w[syscall __syscall_cp_c].include?(current_fn) # These are for indirect syscalls.
code = line.strip.split("\t")[2]
next if [nil, ''].include?(code)
code_for_fn[current_fn] ||= []
code_for_fn[current_fn] << code.gsub(/[\t ]+/, ' ')
fns_with_syscall.add(current_fn) if code == 'syscall'
fns_with_indirect_syscall.add(current_fn) if code =~ /<(syscall|__syscall_cp)>/
end
unless only_used_syscalls
puts "Found #{fns_with_syscall.length} functions doing direct syscalls"
puts "Found #{fns_with_indirect_syscall.length} functions doing indirect syscalls"
end
syscalls_for_fn = {}
not_found_count = 0
(fns_with_syscall + fns_with_indirect_syscall).each do |fn_name|
syscalls_for_fn[fn_name] ||= []
if fn_name =~ /_ZN11parking_lot9raw_mutex8RawMutex9lock_slow.+/
# Hardcode 'SYS_futex' as this function produces a really messy assembly.
syscalls_for_fn[fn_name] << 202
next
end
code = code_for_fn[fn_name]
found = false
regs = {}
code.each do |inst|
if inst =~ /mov (#{REGS_R}),(.+)/
reg = Regexp.last_match(1)
value = Regexp.last_match(2)
regs[REG_MAP[reg]] = if value =~ /#{REGS_R}/
regs[REG_MAP[value]]
elsif value =~ /0x([0-9a-f]+)/
Regexp.last_match(1).to_i(16)
end
elsif inst =~ /xor (#{REGS_R}),(#{REGS_R})/
reg_1 = Regexp.last_match(1)
reg_2 = Regexp.last_match(1)
regs[REG_MAP[reg_1]] = 0 if reg_1 == reg_2
elsif inst =~ /lea (#{REGS_R}),(.+)/
reg = Regexp.last_match(1)
value = Regexp.last_match(2)
regs[REG_MAP[reg]] = ('syscall' if value.strip =~ /\[rip\+0x[a-z0-9]+\]\s*#\s*[0-9a-f]+\s*<syscall>/)
elsif inst =~ /(call|jmp) (#{REGS_R})/
reg = Regexp.last_match(2)
if regs[REG_MAP[reg]] == 'syscall'
if !regs['rdi'].nil?
syscalls_for_fn[fn_name] << regs['rdi']
found = true
else
found = false
end
end
elsif inst =~ /(call|jmp) [0-9a-f]+ <(syscall|__syscall_cp)>/
if !regs['rdi'].nil?
syscalls_for_fn[fn_name] << regs['rdi']
found = true
else
found = false
end
elsif inst == 'syscall'
if !regs['rax'].nil?
syscalls_for_fn[fn_name] << regs['rax']
found = true
else
found = false
end
end
end
next if found
puts "WARN: Function triggers a syscall but couldn't figure out which one: #{fn_name}"
puts ' ' + code.join("\n ")
puts
not_found_count += 1
end
puts "WARN: Failed to figure out syscall for #{not_found_count} function(s)" if not_found_count > 0
fns_for_syscall = {}
syscalls_for_fn.each do |fn_name, syscalls|
syscalls.each do |syscall|
fns_for_syscall[syscall] ||= []
fns_for_syscall[syscall] << fn_name
end
end
if only_used_syscalls
puts syscalls_for_fn.values.flatten.sort.uniq.map { |sc| SYSCALLS[sc] || sc }.join("\n")
else
puts 'Functions per syscall:'
fns_for_syscall.sort_by { |sc, _| sc }.each do |syscall, fn_names|
fn_names = fn_names.sort.uniq
puts " #{SYSCALLS[syscall] || syscall} [#{fn_names.length} functions]"
fn_names.each do |fn_name|
puts " #{fn_name}"
end
end
puts
puts 'Used syscalls:'
puts ' ' + syscalls_for_fn.values.flatten.sort.uniq.map { |sc| SYSCALLS[sc] || sc }.join("\n ")
end
@@ -0,0 +1,74 @@
0 (read)
1 (write)
2 (open)
3 (close)
4 (stat)
5 (fstat)
7 (poll)
8 (lseek)
9 (mmap)
10 (mprotect)
11 (munmap)
12 (brk)
13 (rt_sigaction)
14 (rt_sigprocmask)
15 (rt_sigreturn)
16 (ioctl)
19 (readv)
20 (writev)
22 (pipe)
24 (sched_yield)
25 (mremap)
28 (madvise)
34 (pause)
39 (getpid)
41 (socket)
42 (connect)
45 (recvfrom)
46 (sendmsg)
56 (clone)
57 (fork)
60 (exit)
61 (wait4)
62 (kill)
72 (fcntl)
79 (getcwd)
80 (chdir)
82 (rename)
83 (mkdir)
87 (unlink)
89 (readlink)
96 (gettimeofday)
97 (getrlimit)
98 (getrusage)
99 (sysinfo)
102 (getuid)
110 (getppid)
131 (sigaltstack)
140 (getpriority)
141 (setpriority)
144 (sched_setscheduler)
157 (prctl)
158 (arch_prctl)
165 (mount)
166 (umount2)
186 (gettid)
200 (tkill)
202 (futex)
203 (sched_setaffinity)
204 (sched_getaffinity)
217 (getdents64)
218 (set_tid_address)
228 (clock_gettime)
230 (clock_nanosleep)
231 (exit_group)
257 (openat)
262 (newfstatat)
263 (unlinkat)
272 (unshare)
273 (set_robust_list)
293 (pipe2)
302 (prlimit64)
309 (getcpu)
318 (getrandom)
319 (memfd_create)
@@ -0,0 +1,17 @@
#!/bin/sh
set -e
action="$1"
config_file="/etc/default/polkadot"
if [ "$action" = "configure" ]; then
# Make user and group
getent group polkadot >/dev/null 2>&1 || addgroup --system polkadot
getent passwd polkadot >/dev/null 2>&1 ||
adduser --system --home /home/polkadot --disabled-password \
--ingroup polkadot polkadot
if [ ! -e "$config_file" ]; then
echo 'POLKADOT_CLI_ARGS=""' > /etc/default/polkadot
fi
fi
+38
View File
@@ -0,0 +1,38 @@
[Unit]
Description=Polkadot Node
After=network.target
Documentation=https://github.com/pezkuwichain/pezkuwichain-sdk
[Service]
EnvironmentFile=-/etc/default/polkadot
ExecStart=/usr/bin/polkadot $POLKADOT_CLI_ARGS
User=polkadot
Group=polkadot
Restart=always
RestartSec=120
CapabilityBoundingSet=
LockPersonality=true
NoNewPrivileges=true
PrivateDevices=true
PrivateMounts=true
PrivateTmp=true
PrivateUsers=true
ProtectClock=true
ProtectControlGroups=true
ProtectHostname=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectSystem=strict
RemoveIPC=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
RestrictNamespaces=false
RestrictSUIDSGID=true
SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallFilter=landlock_add_rule landlock_create_ruleset landlock_restrict_self seccomp mount umount2
SystemCallFilter=~@clock @module @reboot @swap @privileged
SystemCallFilter=pivot_root
UMask=0027
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,33 @@
#!/bin/sh
# Post-install script for RPM package
set -e
config_file="/etc/default/pezkuwi"
# Create pezkuwi group if it doesn't exist
getent group pezkuwi >/dev/null || groupadd -r pezkuwi
# Create pezkuwi user if it doesn't exist
getent passwd pezkuwi >/dev/null || \
useradd -r -g pezkuwi -d /home/pezkuwi -m -s /sbin/nologin \
-c "User account for running pezkuwi as a service" pezkuwi
# Create default config file if it doesn't exist
if [ ! -e "$config_file" ]; then
echo 'PEZKUWI_CLI_ARGS=""' > "$config_file"
fi
# Set correct permissions for binaries and service files
echo "Setting file permissions..."
chmod 755 /usr/bin/pezkuwi || true
chmod 755 /usr/lib/pezkuwi || true
chmod 755 /usr/lib/pezkuwi/* || true
chmod 644 /usr/lib/systemd/system/pezkuwi.service || true
# Reload systemd daemon to recognize the new service
if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload || true
fi
exit 0
@@ -0,0 +1,14 @@
#!/bin/sh
# Post-uninstall script for RPM package
set -e
# Reload systemd after service file removal (but not on upgrade)
if [ "$1" = "0" ]; then
# $1 = 0 means uninstall (not upgrade)
if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload || true
fi
fi
exit 0
@@ -0,0 +1,15 @@
#!/bin/sh
# Pre-uninstall script for RPM package
set -e
# Stop and disable the service before uninstall (but not on upgrade)
if [ "$1" = "0" ]; then
# $1 = 0 means uninstall (not upgrade)
if command -v systemctl >/dev/null 2>&1; then
systemctl --no-reload disable pezkuwi.service || true
systemctl stop pezkuwi.service || true
fi
fi
exit 0
+58
View File
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
set -e
if [ "$#" -ne 1 ]; then
echo "Please provide the number of initial validators!"
exit 1
fi
generate_account_id() {
subkey inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "Account ID" | awk '{ print $3 }'
}
generate_address() {
subkey inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "SS58 Address" | awk '{ print $3 }'
}
generate_public_key() {
subkey inspect ${3:-} ${4:-} "$SECRET//$1//$2" | grep "Public key (hex)" | awk '{ print $4 }'
}
generate_address_and_public_key() {
ADDRESS=$(generate_address $1 $2 $3)
PUBLIC_KEY=$(generate_public_key $1 $2 $3)
printf "//$ADDRESS\nhex![\"${PUBLIC_KEY#'0x'}\"].unchecked_into(),"
}
generate_address_and_account_id() {
ACCOUNT=$(generate_account_id $1 $2 $3)
ADDRESS=$(generate_address $1 $2 $3)
if ${4:-false}; then
INTO="unchecked_into"
else
INTO="into"
fi
printf "//$ADDRESS\nhex![\"${ACCOUNT#'0x'}\"].$INTO(),"
}
V_NUM=$1
AUTHORITIES=""
for i in $(seq 1 $V_NUM); do
AUTHORITIES+="(\n"
AUTHORITIES+="$(generate_address_and_account_id $i stash)\n"
AUTHORITIES+="$(generate_address_and_account_id $i controller)\n"
AUTHORITIES+="$(generate_address_and_account_id $i babe '--scheme sr25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i grandpa '--scheme ed25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i im_online '--scheme sr25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i para_validator '--scheme sr25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i para_assignment '--scheme sr25519' true)\n"
AUTHORITIES+="$(generate_address_and_account_id $i authority_discovery '--scheme sr25519' true)\n"
AUTHORITIES+="$(generate_address_and_public_key $i beefy '--scheme ecdsa' true)\n"
AUTHORITIES+="),\n"
done
printf "$AUTHORITIES"
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -e
# This script is to be run when we are happy with a release candidate.
# It accepts a single argument: version, in the format 'v1.2.3'
version="$1"
if [ -z "$version" ]; then
echo "No version specified, cannot continue"
exit 1
fi
if [[ ! "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version should be in the format v1.2.3"
exit 1
fi
echo '[+] Checking out the release branch'
git checkout release
echo '[+] Pulling latest version of the release branch from github'
git pull
echo '[+] Attempting to merge the release-candidate branch to the release branch'
git merge "$version"
echo '[+] Tagging the release'
git tag -s -m "$version" "$version"
echo '[+] Pushing the release branch and tag to Github. A new release will be created shortly'
git push origin release
git push origin "refs/tags/$version"
+116
View File
@@ -0,0 +1,116 @@
#!/usr/bin/env bash
# Run a two node local net.
# Unlike the docker-compose script in the /docker folder, this version builds the nodes based
# on the current state of the code, instead of depending on a published version.
set -e
# chainspec defaults to pezkuwi-local if no arguments are passed to this script;
# if arguments are passed in, the first is the chainspec
chainspec="${1:-pezkuwi-local}"
PROJECT_ROOT=$(git rev-parse --show-toplevel)
# shellcheck disable=SC1090
source "$(dirname "$0")"/common.sh
cd "$PROJECT_ROOT"
last_modified_rust_file=$(
find . -path ./target -prune -o -type f -name '*.rs' -printf '%T@ %p\n' |
sort -nr |
head -1 |
cut -d' ' -f2-
)
pezkuwi="target/release/pezkuwi"
# ensure the pezkuwi binary exists and is up to date
if [ ! -x "$pezkuwi" ] || [ "$pezkuwi" -ot "$last_modified_rust_file" ]; then
cargo build --release
fi
# setup variables
node_offset=0
declare -a node_pids
declare -a node_pipes
# create a sed expression which injects the node name and stream type into each line
function make_sed_expr() {
name="$1"
type="$2"
printf "s/^/%8s %s: /" "$name" "$type"
}
# turn a string into a flag
function flagify() {
printf -- '--%s' "$(tr '[:upper:]' '[:lower:]' <<< "$1")"
}
# start a node and label its output
#
# This function takes a single argument, the node name.
# The name must be one of those which can be passed to the pezkuwi binary, in un-flagged form,
# one of:
# alice, bob, charlie, dave, eve, ferdie, one, two
function run_node() {
name="$1"
# create a named pipe so we can get the node's PID while also sedding its output
local stdout
local stderr
stdout=$(mktemp --dry-run --tmpdir)
stderr=$(mktemp --dry-run --tmpdir)
mkfifo "$stdout"
mkfifo "$stderr"
node_pipes+=("$stdout")
node_pipes+=("$stderr")
# compute ports from offset
local port=$((30333+node_offset))
local rpc_port=$((9933+node_offset))
local ws_port=$((9944+node_offset))
node_offset=$((node_offset+1))
# start the node
"$pezkuwi" \
--chain "$chainspec" \
--tmp \
--port "$port" \
--rpc-port "$rpc_port" \
--ws-port "$ws_port" \
--rpc-cors all \
"$(flagify "$name")" \
> "$stdout" \
2> "$stderr" \
&
local pid=$!
node_pids+=("$pid")
# send output from the stdout pipe to stdout, prepending the node name
sed -e "$(make_sed_expr "$name" "OUT")" "$stdout" >&1 &
# send output from the stderr pipe to stderr, prepending the node name
sed -e "$(make_sed_expr "$name" "ERR")" "$stderr" >&2 &
}
# clean up the nodes when this script exits
function finish {
for node_pid in "${node_pids[@]}"; do
kill -9 "$node_pid"
done
for node_pipe in "${node_pipes[@]}"; do
rm "$node_pipe"
done
}
trap finish EXIT
# start the nodes
run_node Alice
run_node Bob
# now wait; this will exit on its own only if both subprocesses exit
# the practical implication, as both subprocesses are supposed to run forever, is that
# this script will also run forever, until killed, at which point the exit trap should kill
# the subprocesses
wait