-
Notifications
You must be signed in to change notification settings - Fork 1
/
bitcoin
957 lines (726 loc) · 32.3 KB
/
bitcoin
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
#!/usr/bin/env zsh
###############################################################################
# #
# BITCOIN CORE DOT FILE #
# #
# (`b` and `B` - prefixes for bitcoin) #
# #
###############################################################################
# #
# 1. Intended for macos but can be easily modified for other UNIX and Linux. #
# #
# 2. To include it in your shell write the following line in ~/.zshrc #
# `source <path-to-this-file>` #
# #
# 3. All git operations assume you are working from your fork of bitcoin #
# #
# 4. Read all `Caution!` tags in the file before first use of this file #
# or just live with the consequences! #
# #
# 5. The file has two sections, checklists and zsh #
# - To go through procedures for everyday work use the checklists below as #
# a reference which is by no means exhastive #
# - To change intended behavior or optimise commands edit the zsh section #
# #
# 6. Visual Studio Code optional integration #
# - If you are using visual studio code, there is an optional associated #
# file with debug configuration options and instructions in its comments #
# section #
# - Also, if you select vscode as the default editor below, difftool is #
# setup to open the diffs there as well for more visual aid on changes #
# #
# 7. To check what an alias does after sourcing the file, try: #
# % alias | grep <alias-name> #
# #
###############################################################################
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
# CHECKLISTS #
# (`bh` - prefix for bitcoin help #
#//////////////////////////////////////////////////////////////////////////////
bh() {
echo """
#-----------------------------------------------------------------------------#
# UPDATE, BUILD, TEST & RUN REFERENCE #
#-----------------------------------------------------------------------------#
(1) Get all updates from upstream, this leaves us to the master branch
% bg-update
(2) cmake
% bcmake-<options> # Configure what to build
% bcbuild # Build without tests
% bctest # Unit tests only
(3) Combos
% bb # Build and unit test together
% bbf # Build, unit tests and functional tests
% bbe # Build, unit, functional and extended tests
% bbd # Build for debug
(4) Individualy run tests after compilation
% btest
% btest-ext
(5) Housekeeping
% bnuke # Wipe out all build data
% bg-clean # Git removes all untracked files
(6) Run fork binaries found in under /build/src
% bd
% bdqt
% bcli
% bclin # With named arguments
% bkill
"""
}
bh-pr() {
echo """
#-----------------------------------------------------------------------------#
# PR REVIEWS #
#-----------------------------------------------------------------------------#
Note: Can use \"gh pr list\" and \"gh pr view <pr-number>\" to get info on the
terminal instead of Github
(1) Get the PR to review from upstream
% bg-getpr <pr-number>
(2) Checkout the pr to review with \"git checkout pr/<number>\"
Note: We need to locate the last commit from GitHub
% bg-pr <pr-number>
(3) Checkout the commit to test
% git checkout <commit>
(4) Build and run the tests, look at the <build and test reference> section
(5) Locate how many commits the pr have until the last merge
% bg-oneline
(6) Get the changed file names
% bgd-files <number-of-commits-backwards> # or
% git diff --name-only <last-reviewed-commit> <new-commit>
(7) Examine differences
- In a re-review check the differences since the last review using
% bgd-range <previous-pr-head> <current-pr-head> <number-of-pr-commits>
- Go through each commit from old to new to examine the individual changes
each one interoduced. Just check how many commits the pr includes
% bg-show <number-of-commit-back>
- Or, you can use interactive rebase starting from the last merge before
the PR like:
% git rebase -i <last-merge-commit>
- Examine the changes in each file, will launch on the prefered editor
can use the HEAD~ for a shortcut to the commit hases as well
% git difftool <last-reviewed-commit> <new-commit> -- <file>
- Note: If the \"-- <file>\" is left over, it will go to all of them sequentially
- Open all the changed files witout the diff info
% bgd-files-open <number-of-commits-backwards>
"""
}
bh-pr-create() {
echo """
#-----------------------------------------------------------------------------#
# CREATE PR #
#-----------------------------------------------------------------------------#
(0) Create a local branch
% git branch <new-branch-name>
(1) Update from upstream
% git fetch upstream
(2) Rebase on upstream to get all recent changes
% git rebase upstream/master
(3) Push to fork
% git push --force origin <new-branch-name>
(4) Open a PR from Github (Caution: Select the correct branch!)
(5) Write a meaningful description
(6) Add reviewers as cc @<nym>
"""
}
bh-pr-rebase() {
echo """
#-----------------------------------------------------------------------------#
# REBASE PR #
#-----------------------------------------------------------------------------#
Note: Rebase just for the ci with no changes in the code
% bg-update
% git checkout <branch-name>
% git rebase upstream/master
% git push origin <branch-name> --force
"""
}
bh-debug-cpp() {
echo """
#-----------------------------------------------------------------------------#
# DEBUG CPP - WITH VSCODE #
#-----------------------------------------------------------------------------#
(1) Build for debugging
% bbd
(2) Open workspace on vscode depending on what to debug and follow the
instructions at the .vscode-workspace file of the workspace
% vs-bitcoin
(3) Choose between the debug configurations for bitcoin or unit tests
"""
}
bh-debug-py() {
echo """
#-----------------------------------------------------------------------------#
# DEBUG PY --> CPP WITH VSCODE #
#-----------------------------------------------------------------------------#
(1) Build for debugging
% bbd
(2) Open workspace on vscode depending on what to debug and follow the
instructions at the .vscode-workspace file of the workspace
% vs-bitcoin
(3) Set breakpoints to both cpp and py files
(4) Launch the debugger for the test through the "launch" configuration
(5) Execution stops at the py breakpoint
(6) Attach the python process with the token from the dropdown to lldb
(7) Run to continue debugging on the cpp file
"""
}
bh-lldb() {
echo """
#-----------------------------------------------------------------------------#
# DEBUG WITH LLDB #
#-----------------------------------------------------------------------------#
(1) Build for debugging
% bbd
(2) Open an lldb session on a unit test
Note: See description on how to run unit tests above
% lldb -- build/src/test/test_bitcoin ---log_level=all \
--run_test=<module>/<test-case>
(3) Launch lldb
(lldb) r # or
(lldb) run # or
(lldb) process launch
(3) Set breakpoints on lines
(lldb) b <file>:<line>
(lldb) breakpoint set --file <file-name> --line <line-number>
Set breakpoint on a symbols
(lldb) b <symbol-name>
(lldb) breakpoint set --name myFunction
List and delete breakpoints
(lldb) breakpoint list
(lldb) breakpoint delete # deletes them all
(lldb) breakpoint delete <breakpoint-id>
(4) Set watchpoints
(lldb) watch set var <variable-name>
Stop when the variable has a value we desire
(lldb) watch modify -c '(variable-name==desired-value)'
View all watchpoints
(lldb) watch list -v
(5) You can opt for tui mode after setting break points and
starting the session
(lldb) gui
And return to cli with
(lldb) quit
(6) Start a debugging session
(lldb) run
(7) Step into
(lldb) s
Step over
(lldb) n
Finish current function
(lldb) finish
Run until the next breakpoint
(lldb) complete
(8) Print a variable
(lldb) p <variable-name>
(lldb) fr v <variable-name>
(lldb) fr v # displays all variables
(9) Threads
(lldb) thread step-in
(lldb) thread step-over
(lldb) thread step-out
(lldb) thread list
(lldb) thread backtrace
lldb) thread backtrace all
(lldb) thread select <thread-number>
(10) Attach lldb to existing process
Get the process id from the process name
% pgrep -l <process-name>
See all info about the process
% ps aux | grep <process-name>
Alternatively, you can do the above interactive with htop
% htop
and search for the process name on the pane
(lldb) process attach --pid <process-id>
(lldb) process attach -p <process-id>
(lldb) process attach --name <process-name>
(lldb) process attach --name <process-name> --waitfor
(11) Attach lldb to a future process
% b
% lldb
(lldb) process attach --name test_bitcoin --waitfor
Open another terminal window
% btest-unit-one <module> <test-case>
Return to lldb terminal, set your breakpoints and hit `continue`
"""
}
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
# ZSH #
#//////////////////////////////////////////////////////////////////////////////
#-----------------------------------------------------------------------------#
# VARIABLES #
# (`_` - suffix for all variables in this file) #
#-----------------------------------------------------------------------------#
# Export the LLVM Brew path in order to overide the system default LLVM
# clang-tidy is now also dscoverable by bear
export PATH="$(brew --prefix)/opt/llvm/bin:$PATH"
# System tools
export ED_=code # or vim
export BC_=/opt/homebrew/opt/llvm/bin/clang
export BRCT_=/opt/homebrew/opt/llvm/bin/run-clang-tidy
export BCPP_=/opt/homebrew/opt/llvm/bin/clang++
export BLLDB_=/opt/homebrew/opt/llvm/bin/lldb
# System info
export NCORES_="$(($(sysctl -n hw.physicalcpu)+1))"
# Number of jobs for parallel testing
# ** Caution! ** Optimised for my system, you may begin with smaller numbers
export NJOBS_16_=16
export NJOBS_64_=64
# RAM disc to be used with normal functional tests
# Size calc: { 4096 MiB * 2048 blocks/MiB = 8388608 blocks for 4 GiB }
# Size calc: { 8192 MiB * 2048 blocks/MiB = 16777216 blocks for 8 GiB}
# Size calc: { 12288 MiB * 2048 blocks/MiB = 25165824 blocks for 12 GiB }
export RAMDISK_SIZE_=25165824
# RAM disc to be used with normal extended functional tests
# Size calc: { 12288 MiB * 2048 blocks/MiB = 25165824 blocks for 12 GiB }
# ** Caution! ** Check how much RAM your system supports first
export RAMDISK_SIZE_EXT_=25165824
# Bitcoin paths
export BITDEV_="~/Documents/projects/bitdev"
export BPATH_="$BITDEV_/bitcoin"
export BDATA_="~/Library/Application\ Support/Bitcoin"
export BDATA_LOKI_="/Volumes/loki/Bitcoin"
export BDOT_="$BITDEV_/bitcoin-dot" # Location of THIS file
export BTEST_="$BPATH_/test"
export BFUNC_="$BPATH_/build/test/functional"
export BTEST_LOGS_="/var/folders/qy/mc4396sn0ql8dpl5q852sng40000gn/T"
export BDOX_="$BPATH_/doc/doxygen/html"
# Master branch name (could be `main` for more modern repositories)
export BGMASTER_="master"
#-----------------------------------------------------------------------------#
# INSTALLATIONS #
#-----------------------------------------------------------------------------#
# Install brew dependencies
alias btools="brew install cmake ccache llvm berkeley-db@4 automake boost \
libevent libnatpmp libtool miniupmpc pkg-config python \
qrencode qt@5 sqlite zeromq flame doxygen graphviz lcov \
bear clang-format flake8 mypy codespell vulture"
# Install Xcode tools
# % xcode-select --install
# Upadte all installed brew packages
btools-update() {
brew update;
echo "Running brew upgrade..."
brew upgrade;
echo "Running brew cleanup..."
brew cleanup;
}
# Make sure you are using the latest python 3 release first with `which python`
alias bpips="/usr/bin/python3 -m pip install pyzmq"
#-----------------------------------------------------------------------------#
# PATH SHORTCUTS #
#-----------------------------------------------------------------------------#
# This file in read mode
alias bdot-r="vim -R $BDOT_/bitcoin"
# Bitcoin paths
alias bitdev="cd $BITDEV_;pwd"
alias b="cd $BPATH_;pwd"
alias bdata="cd $BDATA_;pwd" # Local disk
alias bdata-loki="cd $BDATA_LOKI_;pwd" # External disk
alias bdot="cd $BDOT_;pwd"
alias btestlogs="cd $BTEST_LOGS_;pwd"
# Open Bitcoin files on local disk
alias bconf="$ED_ $BDATA_/bitcoin.conf"
alias blog-main="$ED_ $BDATA_/debug.log"
alias blog-test="$ED_ $BDATA_/testnet3/debug.log"
alias blog-signet="$ED_ $BDATA_/signet/debug.log"
alias blog-regtest="$ED_ $BDATA_/regtest/debug.log"
# Open Bitcoin files on external disk
alias bconf-loki="$ED_ $BDATA_LOKI_/bitcoin.conf"
alias blog-main-loki="$ED_ $BDATA_LOKI_/debug.log"
alias blog-test-loki="$ED_ $BDATA_LOKI_/testnet3/debug.log"
alias blog-signet-loki="$ED_ $BDATA_LOKI_/signet/debug.log"
alias blog-regtest-loki="$ED_ $BDATA_LOKI_/regtest/debug.log"
# Visual Studio Code launch and debug workspace configurations
alias vs-bitcoin="code $BDOT_/bitcoin.code-workspace"
#-----------------------------------------------------------------------------#
# BITCOIND AND BITCOIN-CLI #
#-----------------------------------------------------------------------------#
# GLOBAL: System-wide bitcoind and bitcoin-cli found in /usr/local/bin
# Build with `make install` and only for the latest stable release!
# % bitcoind # kept as is
# % bitcoin-cli # kept as is
alias bitcoind="bitcoind -datadir=$BDATA_LOKI_"
alias bitcoin-clin="bitcoin-cli -named"
# LOCAL: bitcoind and bitcoin-cli within the scope of bitcoin core project path
alias bd="$BPATH_/build/src/bitcoind"
alias bd-loki="$BPATH_/build/src/bitcoind -datadir=$BDATA_LOKI_"
alias bdqt="$BPATH_/build/src/qt/bitcoin-qt"
alias bcli="$BPATH_/build/src/bitcoin-cli"
alias bclin="$BPATH_/build/src/bitcoin-cli -named"
# Kill bitcoind if forgotten to stop it properly
alias bkill="pkill -9 bitcoind"
#-----------------------------------------------------------------------------#
# GIT #
# (bg and BG - prefixes) #
#-----------------------------------------------------------------------------#
# TODO: Move as much from this section to .gitcongig link it to a gitconfig
# file in this project?
#---------------------------===<<< Git configuration >>>===-------------------#
# Git difftool and mergetool default editor set up to vs code (default is vim)
bg-ed-setup() {
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'
}
# Open git global editor for manual editing
alias bg-ed="git config --global -e"
#-----------------------------===<<< Git basic >>>===-------------------------#
# Show information and changes of this commit
# % git status
# % git show
# Name of the current branch
alias bg-name="git branch --show-current"
# Commit hash of the current commit
alias bg-last="git rev-parse HEAD"
# Commit hash of the initial commit
alias bg-first="git log --reverse | head -n 1"
# List all tracked files in the repository
alias bg-ls="git ls-files"
# Reset any changes and remove new files since the last commit
alias bg-reset="git reset --hard HEAD; git clean -fd;"
# Clean all untracked files to get a clean project
alias bg-clean="git clean -dfx"
#-----------------------------===<<< Git PR >>>===----------------------------#
bg-getpr() {
# $1: PR number
git fetch upstream pull/$1/head:pr-$1
}
# Checkout a pr
bg-pr() {
# $1: PR number
git checkout pr-$1
}
bg-show() {
# $1: Commit back
git show HEAD~$1
}
#--------------------------===<<< Git fork handling >>>===--------------------#
# Update the fork localy and on github from the original repository
bg-update() {
b
git fetch upstream
git checkout master
git merge upstream/master
git push origin master
echo "Enjoy 😉!"
}
# Update the current branch with all changes from master
bg-branch-update() {
# $1: Branch name
git checkout $1
git rebase
}
#------------------------===<<< Git lists of files >>>===---------------------#
# Search for files including a pattern in a repository
alias bgg="git grep -n " # <pattern> <optional:branch-name> -- <path>
alias bgg-files-only="git grep -l " # <pattern> <optional:branch-name> -- <path>
# List of files w/differences between given number of commits, default is 1
# Hint: Run git log before to see how many commits back is the upstream/master
bgd-files() {
# $1: Number of commits backwards
if [ $# -eq 0 ]; then
git diff --name-only HEAD HEAD~1
else
git diff --name-only HEAD HEAD~$1
fi
}
# Open the changed files with vs code
bgd-files-open() {
# $1: Number of commits backwards
code $(bgd-files $1)
}
# List of files differences between two commits
alias bgd-commits=" git diff --name-only " # <commit-1> <commit-2>
# List of files differences between this branch and the upstream
alias bgd-files-upstream="git diff --name-only upstream/$BGMASTER_ HEAD"
# Differences between ranges of commits to use after rebasing. Use it to
# compare changes between rebases of a pr
bgd-range() {
# $1: commit-1
# $2: commit-2
# $3: range
git range-diff $1~$3..$1 $2~$3..$2
}
#------------------------===<<< Git changes in file >>>===--------------------#
# File changes on current branch compared to upstream
alias bgd-tool="git difftool upstream/$BGMASTER_ " # <file>
# File changes generic case
# % git difftool <commit-to-compare-with-current> <file>
# % git difftool <commit1> <commit2> -- <file> # Open this specific file only
# % git difftool <commit1> <commit2> # Will open all changed files, one by one
# Examine differences in code that have been moved elsewhere
# % git diff --color-moved=dimmed-zebra <commit-1> <commit-2>
#--------------------------===<<< Git archaeology >>>===----------------------#
# Display all the commits including the master's if on a branch
alias bg-oneline="git log --oneline "
# Can specify how many commits back with:
# % git log -n <number-of-commits> --oneline
# Display all commits of the branch since the fork from master
alias bg-commits="bg-oneline $BGMASTER_.."
# Display the number of commits of the branch since the fork from master
alias bg-commits-n="bg-commits | wc -l"
# Get the commit which changed last a line in a file
bg-blame() {
# $1: line number
# $2: file path
git blame -L$1,$1 $2
}
# Get all the commits that changed the file provided as argument
alias bg-log-p="git log -p " # <path>
# Search commits the item (ex. a function name) is modified
alias bg-log-s="git log -S " # <item>
# Search commits the item (ex. a function name) is moved
alias bg-log-g="git log -G " # <item>
# Trace a span of lines in a file
bg-log-l() {
# $1: start line
# $2: end line
# $3: file path
git log -L $1,$2:$3
}
# Follow the history of a file even if it was renamed at some point
alias bg-log-follow="git log --follow " # <path>
# See the history of a removed file
alias bg-log-removed="git log -- " # <path>
# TODO: Remove?
# Get the PR discussion from a commit hash
bg-logp-r() {
# $1: commit hash
git log --merges --reverse --oneline --ancestry-path \
$1..origin/$BGMASTER_ | head -n 1
}
#-----------------------------===<<< Git rebase >>>===------------------------#
# Rebase a local branch
# 1. Open interactive rebase to edit a given last number of commits
# Note: In case of a one commit pr, use `git rebase -i HEAD~ instead`
bg-rebase-i() {
# $1: Number of last commits
git rebase -i HEAD~$1
}
# 2. Select `pick`, `squash` or `edit` to modify the commit contents
# save and close, follow the terminal instructions
# 3. Open the files you want to change with an editor
# 4. Add the file if it had a conflict i.e. change
# % git add <file-with-conflict>
# 5. Continue editing the next commit within the interactive rebase process
alias bg-continue="git rebase --continue"
# 6. Force push changes from rebase
# ** Caution! ** is irreversible
alias bg-force="git push --force " # origin <branch-name>
#-----------------------------------------------------------------------------#
# BUILD #
#-----------------------------------------------------------------------------#
# LLVM used with ccache by default
alias bc=$BC_
alias bcpp=$BCPP_
alias blldb=$BLLDB_
# CMake
# https://github.com/bitcoin/bitcoin/blob/master/doc/build-osx.md
# Note: Use `ccmake build` to check the cmake configuration
# List all cmake build options
alias bcmake-options="cmake -B build -LH"
# Standard config
alias bcmake="cmake -B build -DWITH_BDB=ON \
-DCMAKE_C_COMPILER=$BC_ -DCMAKE_CXX_COMPILER=$BCPP_"
# Debug symbols, use ccmake to confirm DCMAKE_BUILD_TYPE is set to Debug
alias bcmake-debug="cmake -B build -DWITH_BDB=ON \
-DCMAKE_C_COMPILER=$BC_ -DCMAKE_CXX_COMPILER=$BCPP_ \
-DCMAKE_BUILD_TYPE=Debug"
# With gui
alias bcmake-gui= "cmake -B build -DBUILD_GUI=ON \
-DCMAKE_C_COMPILER=$BC_ -DCMAKE_CXX_COMPILER=$BCPP"
# Without wallet
alias bcmake-nowallet="cmake -B build -DENABLE_WALLET=OFF \
-DCMAKE_C_COMPILER=$BC_ -DCMAKE_CXX_COMPILER=$BCPP"
# Clang-tidy
alias bcmake-ct="cmake -B build \
-DCMAKE_C_COMPILER=$BC_ -DCMAKE_CXX_COMPILER=$BCPP_ \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
# CMake builds
alias bcbuild="cmake --build build -j $NCORES_"
alias bctest="ctest --test-dir build -j $NCORES_"
# Build complete toolchain
alias bb="bcmake && bcbuild && bctest"
# Nuke the build directory to start from scratch
alias bnuke="rm -fr $BPATH_/build"
# Make plain commands to be executed from within the build directory
# Note: For versions prior to v28.0
alias bdistclean="make distclean" # Includes make clean as well
alias bclean="make clean"
alias bmake="make -j $NCORES_"
alias bcheck="make -j $NCORES_ check" # Unit and util tests
alias bcache-clean="ccache -C"
# Configure commands used before transition to cmake
# Note: For versions prior to v28.0
alias bconfigure="./autogen.sh && ./configure CC=$BC_ CXX=$BCPP_ \
--with-incompatible-bdb --enable-surpress-external-warnings"
alias bconfigure-bare="./autogen.sh && ./configure CC=$BC_ CXX=$BCPP_"
alias bconfigure-debug="./autogen.sh && ./configure CC=$BC_ CXX=$BCPP_ \
--with-incompatible-bdb
--enable-surpress-external-warnings --enable-debug"
alias bconfigure-tsan="bconfigure-debug -sanitize=thread -02 -g"
alias bconfigure-fuzz="./autogen.sh && ./configure CC=$BC_ CXX=$BCPP_ \
--enable-fuzz --with-sanitizers=fuzzer,address,undefined"
# Sign the bitcoin binaries in order for macos to let you run them
bsign() {
#$1: /path/to/bitcoin/build/src for development, or
# /usr/local/bin for system wide installation
cd $1
xattr -d com.apple.quarantine bitcoin-cli bitcoin-qt bitcoin-tx \
bitcoin-util bitcoin-wallet bitcoind test_bitcoin
codesign -s - bitcoin-cli bitcoin-qt bitcoin-tx bitcoin-util \
bitcoin-wallet bitcoind test_bitcoin
}
#-----------------------------------------------------------------------------#
# TESTS #
#-----------------------------------------------------------------------------#
#---------------------------===<<< Test support >>>===------------------------#
# RAM disks to speed up or constraint testing environment size
# Note: If defined as normal aliases, disk images are implicitly created
bcreate-ram() {
diskutil erasevolume HFS+ ramdisk \
$(hdiutil attach -nomount ram://$RAMDISK_SIZE_)
}
bcreate-ram-ext() {
diskutil erasevolume HFS+ ramdisk \
$(hdiutil attach -nomount ram://$RAMDISK_SIZE_EXT_)
}
alias bdestroy-ram="umount /Volumes/ramdisk"
# Clean up node seeding and debug files after manual tests
alias bdata-clear-main="rm -fr $BDATA_/anchors.dat $BDATA_/peers.dat \
$BDATA_/debug.log"
alias bdata-clear-test="rm -fr $BDATA_/testnet3/anchors.dat \
$BDATA_/testnet3/peers.dat $BDATA_/testnet3/debug.log"
alias bdata-clear-signet="rm -fr $BDATA_/signet/anchors.dat \
$BDATA_/signet/peers.dat $BDATA_/signet/debug.log"
alias bdata-clear-regtest="rm -fr $BDATA_/regtest/anchors.dat \
$BDATA_/regtest/peers.dat $BDATA_/regtest/debug.log"
# Wipe out regtest for a clean run
alias bdata-erase-regtest="rm -fr $BDATA_/regtest/*"
# Clean up test environment
alias btest-clean="rm -rf $BTEST_/cache; pkill -9 bitcoind;"
#-------------------------===<<< Functional tests >>>===----------------------#
# Functional tests
alias btest-plain="$BFUNC_/test_runner.py"
# Attach ramdisk support to functional tests
# Note: Have to manually create and destroy the ramdisk
alias btest-ram="btest-plain --cachedir=/Volumes/ramdisk/cache \
--tmpdir=/Volumes/ramdisk/tmp"
# Functional tests (optimum standalone configuration)
alias btest="bcreate-ram && btest-ram --jobs=$NJOBS_64_ && bdestroy-ram"
# Extended functional tests excluding db_crash
alias btest-ext-db="bcreate-ram-ext && btest-ram --jobs=$NJOBS_16_ --extended \
--exclude=feature_dbcrash.py && bdestroy-ram"
# and then run db_crash only with
alias btest-db-only="btest-plain feature_dbcrash.py"
# Extended functional tests (optimum standalone configuration)
alias btest-ext="bcreate-ram-ext && btest-ram --jobs=$NJOBS_16_ \
--extended && bdestroy-ram"
# Coverage for the exteded functional tests to uncover missing rpcs from harness
alias btest-cov="bcreate-ram-ext && btest-ram --jobs=$NJOBS_16_ --extended \
--coverage && bdestroy-ram"
#----------------------------===<<< Unit tests >>>===-------------------------#
# The `bb` command above runs both the unit and util tests
# To get a list of all unit test cases run
# % /build/src/test/test_bitcoin --list_content
# Run the unit test without re-compiling
btest-unit() {
b
cd build/src/test/
test_bitcoin
b
}
btest-unit-one() {
# $1: module (file name)
# $2: test case
b
./build/src/test/test_bitcoin --run_test=$1/$2
}
# Run util tests without recompiling
alias btest-util="$BPATH_/build/test/util/test_runner.py"
#----------------------------===<<< Lint checks >>>===------------------------#
# Run locally all the lint checks that the CI does on Github
btest-lint() {
b
cd test/lint/test_runner && cargo fmt && cargo clippy && cargo run
b
}
#---------------------------===<<< Clang tidy >>>===-------------------------#
# Build specifically for clang tidy
alias bct-build="bcmake-ct && bcbuild"
# Run clang-tidy on src
alias bct="( cd ./src/ && $BRCT_ -p ../build -j $NCORES_ )"
# Run clang-tidy with the cppcoreguidelines suport on a source file
alias bct-cg="$BRCT_ -p ../build -checks=cppcoreguidelines-" # <source-file>
#----------------------------===<<< Fuzz tests >>>===-------------------------#
# TODO: Fuzz tests
#---------------------------===<<< Test reports >>>===------------------------#
# Unit test coverage report
alias btest-report="open -a /Applications/Firefox.app \
$BPATH_/test_bitcoin.coverage/index.html"
# Unit and functional test coverage report
alias btest-report-total="open -a /Applications/Firefox.app \
$BPATH_/total.coverage/index.html"
# TODO: Test coverage
#-----------------------------===<<< Benchmark >>>===-------------------------#
# Build benchmark support after configuring build with bconfigure-debug
alias bbench-make="make -C src bitcoin_bench"
# Run the benchmarks
alias bbench="src/bench/bench_bitcoin"
# Get help
alias bbench-help="bbench -h"
# List all benchmarks
alias bbench-list="bbench -list"
#----------------------===<<< Build and test combos >>>===-------------------#
# Built and unit tests
# % bb
# Build and run unit and functional tests
alias bbf="bb && btest"
# Build and run unit functional and extended tests
alias bbe="bb && btest-ext"
# Build for debugging with no tests involved
alias bbd="bcmake-debug && bcbuild"
#-----------------------------------------------------------------------------#
# DOCUMENTATION AND CODING STYLE #
#-----------------------------------------------------------------------------#
# Doxygen (run from the project root)
alias bdox-make="make docs"
alias bdox-clean="make clean-docs"
# Format last commit with 0 lines of context, call from the git root folder,
# uses clang-format with the config defined in src/.clang-format
alias bformat="git diff -U0 HEAD~1.. | \
./contrib/devtools/clang-format-diff.py -p1 -i -v"
# View doxygen generated documentation on firefox
alias bdox="open -a /Applications/Firefox.app $BDOX_/index.html"
#-----------------------------------------------------------------------------#
# TROUBLESHOOTING #
#-----------------------------------------------------------------------------#
# Clean up everything in the build and test chains in case of trouble
alias bclean-all="bclean; bcache-clean; btest-clean; bdox-clean"
# Wipe out the entire build with
# % bnuke
#-----------------------------------------------------------------------------#
# BONUS - WARNET #
#-----------------------------------------------------------------------------#
warnet-run() {
bitdev
cd warnet
python3.13 -m venv .venv && source .venv/bin/activate && pip3.12 install -e .
open /Applications/Docker.app
kubectl config set-context --current --namespace=warnet
warnet setup
test/rpc_test.py
}
# Usefull commands
# Run a simulation
# % warnet deploy <path-to-network>
# Get a dashboard on `localhost:2323`
# % kubectl port-forward fork-observer 2323
# Check the kuberbetes pods
# % k9s
# warnet --help
# warnet logs
# warnet deploy test/data/bitcoin_conf
# warnet run resources/scenario/invdos.py
# warnet bitcoin rpc tank-0016 getpeerinfo