Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: speculative templates #54

Open
wants to merge 34 commits into
base: sv2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
59eacd2
Add sv2 log category for Stratum v2
Sjors Nov 30, 2023
f69fd62
Add sv2 noise protocol
Sjors Jul 11, 2024
176795a
Add sv2 message CoinbaseOutputDataSize
Sjors Jun 20, 2024
c4f2ef9
Convert between Sv2NetMsg and CSerializedNetMsg
Sjors Jun 21, 2024
938570a
Introduce Sv2Transport
Sjors Jun 21, 2024
750f75a
Add sv2 SETUP_CONNECTION messages
Sjors Jul 15, 2024
fc81013
Add strings for Sv2MsgType
Sjors Jul 1, 2024
88e7fbd
test: put the generic parts from StaticContentsSock into a separate c…
vasild Dec 6, 2022
d1e3e3b
test: add a mocked Sock that allows inspecting what has been Send() t…
vasild Dec 6, 2022
3cf779b
Add Sv2Connman
Sjors Jul 17, 2024
a1c8e3c
Chainparams: add default sv2 port
Sjors Nov 29, 2023
fa33ea5
Stratum v2 template provider scaffold
Sjors Jun 18, 2024
0ba8584
Add remaining sv2 messages for TemplateProvider
Sjors Jun 24, 2024
fb31d44
Have createNewBlock return BlockTemplate interface
Sjors Jul 17, 2024
7e2a12f
Add GetCoinBaseMerklePath helper
Sjors Jul 16, 2024
6489500
Add getCoinbaseMerklePath() to Mining interface
Sjors Jul 12, 2024
6c36412
Add submitSolution to BlockTemplate interface
Sjors Jul 15, 2024
3fa41d1
Add waitTipChanged to Mining interface
Sjors Jul 8, 2024
2a9571f
Sv2: construct and submit block templates
Sjors Dec 28, 2023
0e1370c
Handle REQUEST_TRANSACTION_DATA
Sjors Jul 2, 2024
630cf57
Reject RequestTransactionData for stale templates
Sjors Jul 2, 2024
9328d23
Handle SUBMIT_SOLUTION
Sjors Jul 2, 2024
bdfee73
Introduce waitFeesChanged() mining interface
Sjors Jul 18, 2024
e02477f
Incrementally update sv2 block template
Sjors Feb 16, 2024
2bb2838
CKey: add Serialize and Unserialize
Sjors Feb 1, 2024
dabc32c
Persist static key for Template Provider
Sjors Jan 11, 2024
29b37d8
Start Template Provider with -sv2
Sjors Jul 17, 2024
2da69c0
signet: miner skips PSBT step for OP_TRUE
Sjors Dec 8, 2023
17e580a
testnet: Introduce Testnet4
fjahr Mar 31, 2024
998d646
testnet: Add Testnet4 difficulty adjustment rules fix
fjahr May 3, 2024
128f3dc
testnet: Add timewarp attack prevention for Testnet4
fjahr May 3, 2024
718a9ee
doc: explain Stratum v2 design, testing and usage
Sjors Dec 28, 2023
fe730f1
ci: skip Github CI on branch pushes for forks
Sjors Jan 18, 2024
abc852d
WIP: speculative templates
Sjors Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ on:
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push.
push:
branches:
- '**'
# Disable CI on branch pushes to forks. It will still run for pull requests.
# This prevents CI from running twice for typical pull request workflows.
- 'bitcoin/**'
- 'bitcoin-core/**'
tags-ignore:
- '**'

Expand Down
2 changes: 1 addition & 1 deletion contrib/completions/bash/bitcoin-cli.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _bitcoin_rpc() {
local rpcargs=()
for i in ${COMP_LINE}; do
case "$i" in
-conf=*|-datadir=*|-regtest|-rpc*|-testnet)
-conf=*|-datadir=*|-regtest|-rpc*|-testnet|-testnet4)
rpcargs=( "${rpcargs[@]}" "$i" )
;;
esac
Expand Down
3 changes: 2 additions & 1 deletion contrib/signet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Adding the --ongoing parameter will then cause the signet miner to create blocks

$MINER --cli="$CLI" generate --grind-cmd="$GRIND" --address="$ADDR" --nbits=$NBITS --ongoing

For custom signets with a trivial challenge a PSBT is not necessary. The miner detects this for `OP_TRUE`.

Other options
-------------

Expand Down Expand Up @@ -80,4 +82,3 @@ These steps can instead be done explicitly:
$CLI -signet -stdin submitblock

This is intended to allow you to replace part of the pipeline for further experimentation (eg, to sign the block with a hardware wallet).

47 changes: 31 additions & 16 deletions contrib/signet/miner
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ def do_decode_psbt(b64psbt):
return from_binary(CBlock, psbt.g.map[PSBT_SIGNET_BLOCK]), ser_string(scriptSig) + scriptWitness

def finish_block(block, signet_solution, grind_cmd):
block.vtx[0].vout[-1].scriptPubKey += CScriptOp.encode_op_pushdata(SIGNET_HEADER + signet_solution)
block.vtx[0].rehash()
block.hashMerkleRoot = block.calc_merkle_root()
if signet_solution is not None:
block.vtx[0].vout[-1].scriptPubKey += CScriptOp.encode_op_pushdata(SIGNET_HEADER + signet_solution)
block.vtx[0].rehash()
block.hashMerkleRoot = block.calc_merkle_root()
if grind_cmd is None:
block.solve()
else:
Expand All @@ -110,10 +111,12 @@ def finish_block(block, signet_solution, grind_cmd):
block.rehash()
return block

def generate_psbt(tmpl, reward_spk, *, blocktime=None):
signet_spk = tmpl["signet_challenge"]
def generate_psbt(block, signet_spk):
signet_spk_bin = bytes.fromhex(signet_spk)
signme, spendme = signet_txs(block, signet_spk_bin)
return do_createpsbt(block, signme, spendme)

def new_block(tmpl, reward_spk, blocktime=None):
cbtx = create_coinbase(height=tmpl["height"], value=tmpl["coinbasevalue"], spk=reward_spk)
cbtx.vin[0].nSequence = 2**32-2
cbtx.rehash()
Expand All @@ -135,9 +138,10 @@ def generate_psbt(tmpl, reward_spk, *, blocktime=None):
block.vtx[0].wit.vtxinwit = [cbwit]
block.vtx[0].vout.append(CTxOut(0, bytes(get_witness_script(witroot, witnonce))))

signme, spendme = signet_txs(block, signet_spk_bin)
block.vtx[0].rehash()
block.hashMerkleRoot = block.calc_merkle_root()

return do_createpsbt(block, signme, spendme)
return block

def get_reward_address(args, height):
if args.address is not None:
Expand Down Expand Up @@ -177,8 +181,10 @@ def get_reward_addr_spk(args, height):

def do_genpsbt(args):
tmpl = json.load(sys.stdin)
signet_spk = tmpl["signet_challenge"]
_, reward_spk = get_reward_addr_spk(args, tmpl["height"])
psbt = generate_psbt(tmpl, reward_spk)
block = new_block(tmpl, reward_spk)
psbt = generate_psbt(block, signet_spk)
print(psbt)

def do_solvepsbt(args):
Expand Down Expand Up @@ -407,14 +413,23 @@ def do_generate(args):
# mine block
logging.debug("Mining block delta=%s start=%s mine=%s", seconds_to_hms(mine_time-bestheader["time"]), mine_time, is_mine)
mined_blocks += 1
psbt = generate_psbt(tmpl, reward_spk, blocktime=mine_time)
input_stream = os.linesep.join([psbt, "true", "ALL"]).encode('utf8')
psbt_signed = json.loads(args.bcli("-stdin", "walletprocesspsbt", input=input_stream))
if not psbt_signed.get("complete",False):
logging.debug("Generated PSBT: %s" % (psbt,))
sys.stderr.write("PSBT signing failed\n")
return 1
block, signet_solution = do_decode_psbt(psbt_signed["psbt"])
block = new_block(tmpl, reward_spk, blocktime=mine_time)

# BIP325 allows omitting the signet commitment when scriptSig and
# scriptWitness are both empty. This is the case for trivial
# challenges such as OP_TRUE
signet_solution = None
signet_spk = tmpl["signet_challenge"]
if signet_spk != "51":
psbt = generate_psbt(block, signet_spk)
input_stream = os.linesep.join([psbt, "true", "ALL"]).encode('utf8')
psbt_signed = json.loads(args.bcli("-stdin", "walletprocesspsbt", input=input_stream))
if not psbt_signed.get("complete",False):
logging.debug("Generated PSBT: %s" % (psbt,))
sys.stderr.write("PSBT signing failed\n")
return 1
block, signet_solution = do_decode_psbt(psbt_signed["psbt"])

block = finish_block(block, signet_solution, args.grind_cmd)

# submit block
Expand Down
2 changes: 1 addition & 1 deletion doc/REST-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Unauthenticated REST Interface
The REST API can be enabled with the `-rest` option.

The interface runs on the same port as the JSON-RPC interface, by default port 8332 for mainnet, port 18332 for testnet,
port 38332 for signet, and port 18443 for regtest.
port 48332 for testnet4, port 38332 for signet, and port 18443 for regtest.

REST Interface consistency guarantees
-------------------------------------
Expand Down
13 changes: 7 additions & 6 deletions doc/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ Windows | `%LOCALAPPDATA%\Bitcoin\` <sup>[\[1\]](#note1)</sup>

3. All content of the data directory, except for `bitcoin.conf` file, is chain-specific. This means the actual data directory paths for non-mainnet cases differ:

Chain option | Data directory path
-------------------------------|------------------------------
`-chain=main` (default) | *path_to_datadir*`/`
`-chain=test` or `-testnet` | *path_to_datadir*`/testnet3/`
`-chain=signet` or `-signet` | *path_to_datadir*`/signet/`
`-chain=regtest` or `-regtest` | *path_to_datadir*`/regtest/`
Chain option | Data directory path
---------------------------------|------------------------------
`-chain=main` (default) | *path_to_datadir*`/`
`-chain=test` or `-testnet` | *path_to_datadir*`/testnet3/`
`-chain=testnet4` or `-testnet4` | *path_to_datadir*`/testnet4/`
`-chain=signet` or `-signet` | *path_to_datadir*`/signet/`
`-chain=regtest` or `-regtest` | *path_to_datadir*`/regtest/`

## Data directory layout

Expand Down
4 changes: 3 additions & 1 deletion doc/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,15 @@ Both variables are used as a guideline for how much space the user needs on thei
Note that all values should be taken from a **fully synced** node and have an overhead of 5-10% added on top of its base value.

To calculate `m_assumed_blockchain_size`, take the size in GiB of these directories:
- For `mainnet` -> the data directory, excluding the `/testnet3`, `/signet`, and `/regtest` directories and any overly large files, e.g. a huge `debug.log`
- For `mainnet` -> the data directory, excluding the `/testnet3`, `/testnet4`, `/signet`, and `/regtest` directories and any overly large files, e.g. a huge `debug.log`
- For `testnet` -> `/testnet3`
- For `testnet4` -> `/testnet4`
- For `signet` -> `/signet`

To calculate `m_assumed_chain_state_size`, take the size in GiB of these directories:
- For `mainnet` -> `/chainstate`
- For `testnet` -> `/testnet3/chainstate`
- For `testnet4` -> `/testnet4/chainstate`
- For `signet` -> `/signet/chainstate`

Notes:
Expand Down
Loading
Loading