Commit Graph

39 Commits

Author SHA1 Message Date
Ava Chow
429ec1aaaa refactor: Rename CTransaction::nVersion to version
In order to ensure that the change of nVersion to a uint32_t in the
previous commit has no effect, rename nVersion to version in this commit
so that reviewers can easily spot if a spot was missed or if there is a
check somewhere whose semantics have changed.
2024-06-07 13:55:23 -04:00
MarcoFalke
fa826db477
scripted-diff: test: Use int.to_bytes over struct packing
-BEGIN VERIFY SCRIPT-
 sed -i --regexp-extended 's!struct.pack\(.<?B., (.*)\)!\1.to_bytes(1, "little")!g'             $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<I., (.*)\)!\1.to_bytes(4, "little")!g'              $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<H., (.*)\)!\1.to_bytes(2, "little")!g'              $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<i., (.*)\)!\1.to_bytes(4, "little", signed=True)!g' $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.<q., (.*)\)!\1.to_bytes(8, "little", signed=True)!g' $( git grep -l struct.pack )
 sed -i --regexp-extended 's!struct.pack\(.>H., (.*)\)!\1.to_bytes(2, "big")!g'                 $( git grep -l struct.pack )
-END VERIFY SCRIPT-
2024-05-07 15:40:47 +02:00
muxator
defdf67765 contrib: use a raw string for a regular expression literal that contains backslashes in signet/miner
Running the miner under python >= 3.12 causes a SyntaxWarning. The problem was
already present in previous versions, but it only triggered a
DeprecationWarning, which was not shown by default.

The change is useful for future-proofing the code base, since future python
versions will start to exit with a runtime exception (see the reference given
later).

Command to see the warning at runtime under python3.11 (DeprecationWarning,
needs "-Walways"):
    $ python3.11 -Walways ./contrib/signet/miner
    <BASE>/contrib/signet/miner:33: DeprecationWarning: invalid escape sequence '\d'
      RE_MULTIMINER = re.compile("^(\d+)(-(\d+))?/(\d+)$")
    2023-11-15 16:02:49 ERROR Must specify command

Command to see the warning at runtime under python3.12 (SyntaxWarning, no
modifiers needed):
    $ python3.12 ./contrib/signet/miner
    <BASE>/contrib/signet/miner:33: SyntaxWarning: invalid escape sequence '\d'
      RE_MULTIMINER = re.compile("^(\d+)(-(\d+))?/(\d+)$")
    2023-11-15 16:03:00 ERROR Must specify command

Reference ( https://docs.python.org/3.8/library/re.html ):
    Regular expressions use the backslash character ('\') [...]. This collides
    with Python’s usage of the same character for the same purpose in string
    literals; [...]

    Also, please note that any invalid escape sequences in Python’s usage of the
    backslash in string literals now generate a DeprecationWarning and in the
    future this will become a SyntaxError.

    The solution is to use Python’s raw string notation for regular expression
    patterns;
2023-11-15 15:55:20 +01:00
fanquake
0c579203d2
Merge bitcoin/bitcoin#25867: lint: enable E722 do not use bare except
61bb4e783b lint: enable E722 do not use bare except (Leonardo Lazzaro)

Pull request description:

  Improve test code and enable E722 lint check.

   If you want to catch all exceptions that signal program errors, use except Exception: (bare except is equivalent to except BaseException:).

  Reference: https://peps.python.org/pep-0008/#programming-recommendations

ACKs for top commit:
  MarcoFalke:
    lgtm ACK 61bb4e783b

Tree-SHA512: c7497769d5745fa02c78a20f4a0e555d8d3996d64af6faf1ce28e22ac1d8be415b98e967294679007b7bda2a9fd04031a9d140b24201e00257ceadeb5c5d7665
2023-02-22 09:28:09 +00:00
Leonardo Lazzaro
61bb4e783b lint: enable E722 do not use bare except 2023-02-18 11:24:09 +00:00
MarcoFalke
fa2a23548a
Revert "contrib: Fix capture_output in getcoins.py"
This reverts commit be59bd17ec
because the changes are no longer needed.
2023-01-18 13:00:29 +01:00
Hennadii Stepanov
306ccd4927
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
- 2021: f47dda2c58
- 2020: fa0074e2d8
- 2019: aaaaad6ac9
2022-12-24 23:49:50 +00:00
fanquake
6c5ef5d460
Merge bitcoin/bitcoin#26208: signet/miner: reduce default interblock interval limit to 30min
51a08f41ff signet/miner: reduce default interblock interval limit to 30min (Anthony Towns)

Pull request description:

  Reduces the cap on the time between blocks from 60 minutes to 30 minutes, and makes it configurable.

Top commit has no ACKs.

Tree-SHA512: 7b880c50e47d055a2737c057fab190017748849d264c6c39dde465959a544d502221d12c6307d4de693f51badb4779b9c147e48775ede6ec6613e808067ab279
2022-10-03 09:14:22 +01:00
willcl-ark
be59bd17ec
contrib: Fix capture_output in getcoins.py
Our required Python version 3.6.12 does not support `capture_output` as
a subprocess.run argument; this was added in python 3.7.

We can emulate it by setting stdout and stderr to subprocess.PIPE
2022-09-30 13:20:48 +01:00
Anthony Towns
51a08f41ff signet/miner: reduce default interblock interval limit to 30min
Also allow the operator to change it, if desired, without having
to edit the code.
2022-09-29 14:02:58 +10:00
Sebastian Falbesoner
fdc1ca3896 test: add constants for PSBT key types (BIP 174)
Also take use of the constants in the signet miner to get rid of
magic numbers and increase readability and maintainability.
2022-07-19 15:40:51 +02:00
Sebastian Falbesoner
1b035c03f9 refactor: move PSBT(Map) helpers from signet miner to test framework
Can be easily reviewed with `--color-moved=dimmed-zebra`.
2022-07-19 15:40:51 +02:00
Sebastian Falbesoner
7c0dfec2dd refactor: move from_binary helper from signet miner to test framework
Can be easily reviewed with `--color-moved=dimmed-zebra`.
2022-07-19 15:40:51 +02:00
Sebastian Falbesoner
597a4b35f6 scripted-diff: rename FromBinary helper to from_binary (signet miner)
-BEGIN VERIFY SCRIPT-
sed -i s/FromBinary/from_binary/g ./contrib/signet/miner
-END VERIFY SCRIPT-
2022-07-19 15:40:51 +02:00
Sebastian Falbesoner
cccf691c24 contrib: dedup get_witness_script helper in signet miner 2022-07-03 20:22:24 +02:00
Sebastian Falbesoner
12cc0201c2 contrib: fix signet miner (sighash mismatch)
PSBT signing was changed to use SIGHASH_DEFAULT by default in #22514.
The signet miner script sets the sighash type of the created PSBT to
SIGHASH_ALL, hence this leads to a sighash mismatch when the
`walletprocesspsbt` RPC is called. Fix this by explicitly passing the
correct sighash type.

Note that the same change was needed in one of our functional tests,
see commit d3992669df.

Reported by gruve-p.
2022-03-14 11:54:50 +01:00
sh15h4nk
7c7dbe4398 improved getcoins.py 2022-02-13 22:59:31 +05:30
Hennadii Stepanov
f47dda2c58
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
* 2020: fa0074e2d8
* 2019: aaaaad6ac9
2021-12-30 19:36:57 +02:00
W. J. van der Laan
a6d9675d60 contrib: Ask for captcha in signet getcoins.py
As the faucet will always ask for a captcha now, the current script is
no longer usable.

Change the script to print the captcha in dot-matrix to the terminal,
using unicode Braille characters.
2021-10-02 05:39:58 +02:00
MarcoFalke
718d9f2f77
Merge bitcoin/bitcoin#22660: contrib: catch bitcoin-cli RPC call errors in getcoins.py
42dbd9025a contrib: return non-zero status if getcoins.py errors (Sebastian Falbesoner)
8c203cf0e1 contrib: catch bitcoin-cli RPC call errors in getcoins.py (Sebastian Falbesoner)
0eca5ebace contrib: refactor: introduce bitcoin-cli RPC call helper in getcoins.py (Sebastian Falbesoner)

Pull request description:

  This PR is based on #22565 ("[script] signet's getcoins.py improvements"), which should be reviewed first.

  The signet faucet script `contrib/signet/getcoins.py` currently issues bitcoin-cli RPC calls without catching errors -- the only case tackled is if there is no `bitcoin-cli` file found. Instead of crashing with a stack-trace on a failed RPC call, the changes in this PR aim to produce a more user-friendly output (see also https://github.com/bitcoin/bitcoin/pull/22565#discussion_r683754875). Additionally, in case of any error, a non-zero status is now returned (instead of 0, indicating success), which could be useful for other scripts taking use of signet faucet script.

  The most straight-forward way to test this is invoking the script without a `bitcoind` running on signet:

  PR22565 branch:
  ```
  $ ./contrib/signet/getcoins.py
  error: Could not connect to the server 127.0.0.1:8332

  Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
  Traceback (most recent call last):
    File "./contrib/signet/getcoins.py", line 26, in <module>
      curr_signet_hash = subprocess.check_output([args.cmd] + args.bitcoin_cli_args + ['getblockhash', '1']).strip().decode()
    File "/usr/local/lib/python3.8/subprocess.py", line 415, in check_output
      return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
    File "/usr/local/lib/python3.8/subprocess.py", line 516, in run
      raise CalledProcessError(retcode, process.args,
  subprocess.CalledProcessError: Command '['bitcoin-cli', 'getblockhash', '1']' returned non-zero exit status 1.
  ```

  this PR branch:
  ```
  $ ./contrib/signet/getcoins.py
  error: Could not connect to the server 127.0.0.1:38332

  Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
  -----
  Error while calling "bitcoin-cli -signet getblockhash 1" (see output above).
  ```

ACKs for top commit:
  kallewoof:
    Code ACK 42dbd9025a
  Zero-1729:
    tACK 42dbd90 🧪

Tree-SHA512: 912240a4ed03c87035e370602f4095c7ffe26806421bbbd6cf86588126f2310a01a6a61606e9e2918fb2c1a0debdd0ce768c69ba2e4b8e7750fa3474a56d01a0
2021-08-26 10:04:57 +02:00
W. J. van der Laan
1bbe289f20
Merge bitcoin/bitcoin#22565: [script] signet's getcoins.py improvements
b0c8246cac Add cleaner errors for unsuccessful faucet transactions (NikhilBartwal)
1c612b274b [script] Update signet getcoins.py for custom network (NikhilBartwal)

Pull request description:

  Currently, using the getcoins.py with a custom signet executes successfully and shows the transfer of 0.001 testBTC as complete, however for obvious reasons, it should not. In fact, upon verification it does not actually execute the transaction, but rather gives the output that it did, as shown below which can be misleading:

  ```
  [nikhilb@nikhil-PC bitcoin]$ echo $datadir
  /home/nikhilb/signet-custom
  [nikhilb@nikhil-PC bitcoin]$ contrib/signet/getcoins.py -- -datadir=$datadir
  Payment of 0.00100000 BTC sent with txid dd22c7d996e95f3e5baf20f73140d517ff48f1b26d0e4fefd61e3c37991b8f86
  [nikhilb@nikhil-PC bitcoin]$ bitcoin-cli -datadir=$datadir getrawtransaction dd22c7d996e95f3e5baf20f73140d517ff48f1b26d0e4fefd61e3c37991b8f86
  error code: -5
  error message:
  No such mempool or blockchain transaction. Use gettransaction for wallet transactions.
  [nikhilb@nikhil-PC bitcoin]$ bitcoin-cli -datadir=$datadir gettransaction dd22c7d996e95f3e5baf20f73140d517ff48f1b26d0e4fefd61e3c37991b8f86
  error code: -5
  error message:
  Invalid or non-wallet transaction id

  ```
  This PR adds a sanity check for custom signet by comparing the current network's first block hash (the block after the genesis block) with global signet's respective block hash (since all signet networks share the same genesis block) and if a custom network is detected, the user is prompted to either work on the global signet or setup their own faucet.

  The PR was checked to be working successfully, giving the output as below:

  ```
  [nikhilb@nikhil-PC bitcoin]$ git checkout update_signet_getcoins
  Switched to branch 'update_signet_getcoins'
  Your branch is ahead of 'upstream/master' by 1 commit.
    (use "git push" to publish your local commits)
  [nikhilb@nikhil-PC bitcoin]$ contrib/signet/getcoins.py -- -datadir=$datadir
  The global faucet cannot be used with a custom Signet network. Please use the global signet or setup your custom faucet for the same.

  You can have a look here for setting up your own faucet: https://en.bitcoin.it/wiki/Signet

  ```

ACKs for top commit:
  prayank23:
    utACK b0c8246cac
  kallewoof:
    ACK b0c8246cac
  arnabsen1729:
    utACK b0c8246
  prakash1512:
    utACK b0c8246
  0xB10C:
    Tested ACK b0c8246cac
  theStack:
    Tested ACK b0c8246cac
  Zero-1729:
    crACK b0c8246 🧉

Tree-SHA512: 144b47a83008521a5cda13f4c1b12809a125a744f865a8e0f792132d52fdb88926d4f4f4d7230452c2e129b5879892cdbeda981b8af10b789e9fc0cda2905a5d
2021-08-23 19:19:00 +02:00
Zero-1729
021daedfa1
refactor: replace remaining binascii method calls 2021-08-16 19:30:56 +01:00
Sebastian Falbesoner
42dbd9025a contrib: return non-zero status if getcoins.py errors 2021-08-07 20:50:19 +02:00
Sebastian Falbesoner
8c203cf0e1 contrib: catch bitcoin-cli RPC call errors in getcoins.py 2021-08-07 20:50:18 +02:00
Sebastian Falbesoner
0eca5ebace contrib: refactor: introduce bitcoin-cli RPC call helper in getcoins.py 2021-08-07 20:50:14 +02:00
NikhilBartwal
b0c8246cac Add cleaner errors for unsuccessful faucet transactions 2021-08-05 02:58:07 +05:30
NikhilBartwal
1c612b274b [script] Update signet getcoins.py for custom network
Currently, using the getcoins.py with a custom signet executes successfully and shows the transaction as complete, however for obvious reasons, it  should not.
This PR adds a sanity check for custom signet by comparing the current network's first block hash with global signet's respective hash.
2021-08-05 02:57:58 +05:30
Sebastian Falbesoner
1914054208 scripted-diff: test: rename FromHex to from_hex
-BEGIN VERIFY SCRIPT-
sed -i 's/\<FromHex\>/from_hex/g' $(git grep -l FromHex)
-END VERIFY SCRIPT-

Co-authored-by: MarcoFalke <falke.marco@gmail.com>
2021-06-21 14:33:59 +02:00
Sebastian Falbesoner
a79396fe5f test: remove ToHex helper, use .serialize().hex() instead 2021-06-21 14:30:03 +02:00
Sebastian Falbesoner
2ce7b47958 test: introduce tx_from_hex helper for tx deserialization
`FromHex` is mostly used for transactions, so we introduce a
shortcut `tx_from_hex` for `FromHex(CTransaction, hex_str)`.
2021-06-21 14:28:05 +02:00
Anthony Towns
b3c712cb28 contrib/signet/miner: remove debug code 2021-02-07 06:52:42 +10:00
Anthony Towns
b6d493fd4d contrib/signet/README.md: Update miner description 2021-02-07 06:50:11 +10:00
Anthony Towns
e66543827c contrib/signet/miner: Automatic timestamp for first block
When mining the first block of a new signet chain, pick a timestamp for
the first block so that after mining 100 blocks the timestamp will be
back to the current time -- this prevents an unnecessary delay before
any miner rewards have matured enough to be spent.  This takes into
account that the delta between blocks may be shorter than 10 minutes due
to attempting to increase the difficulty to match --nbits, but does not
take into account the time spent actually generating the 100 blocks.
2021-02-07 06:50:11 +10:00
Anthony Towns
a383ce5b4a contrib/signet/miner: --grind-cmd is required for calibrate
Thanks to muxator for spotting.
2021-02-07 06:50:11 +10:00
Anthony Towns
1a45cd2e51 contrib/signet: Fix typos
Thanks to muxator, JeremyRubin, and gruve-p for spotting.
2021-02-07 06:50:11 +10:00
Anthony Towns
595a34dbea contrib/signet: Document miner script in README.md 2021-01-12 18:34:29 +10:00
Anthony Towns
ff7dbdc08a contrib/signet: Add script for generating a signet chain 2021-01-12 18:34:29 +10:00
Karl-Johan Alm
e9c8e6eea2
doc: add contrib/signet readme 2020-10-16 12:50:18 +09:00
Karl-Johan Alm
355d0c4f6b
contrib: add getcoins.py script to get coins from (signet) faucet 2020-10-14 08:27:32 +09:00