Skip to content

Commit 9fb2a2b

Browse files
committed
Merge bitcoin/bitcoin#25536: contrib: dedup get_witness_script helper in signet miner
cccf691 contrib: dedup `get_witness_script` helper in signet miner (Sebastian Falbesoner) Pull request description: The helper `get_witness_script` is already available in the `blocktools` module of our test framework, i.e. there is no need to re-implement it in the signet miner script. Note that the cast from CScript to bytes is necessary for applying the `+=` operator on the scriptPubKey later, which would fail for CScript: ``` File "/home/honeybadger/bitcoin/contrib/signet/miner", line 132, in signet_txs txs[0].vout[-1].scriptPubKey += CScriptOp.encode_op_pushdata(SIGNET_HEADER) File "/home/honeybadger/bitcoin/test/functional/test_framework/script.py", line 460, in __add__ raise NotImplementedError NotImplementedError ``` ACKs for top commit: kallewoof: ACK cccf691 Tree-SHA512: 5965a9f27626e3dd2769a0436263fb646e9d4b67071505122c017f7b0050250e83f524135e57093870b8c64894d64762a51d2c3c68d52dd1e545f23d4734fecb
2 parents 87d0123 + cccf691 commit 9fb2a2b

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

contrib/signet/miner

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ PATH_BASE_CONTRIB_SIGNET = os.path.abspath(os.path.dirname(os.path.realpath(__fi
2121
PATH_BASE_TEST_FUNCTIONAL = os.path.abspath(os.path.join(PATH_BASE_CONTRIB_SIGNET, "..", "..", "test", "functional"))
2222
sys.path.insert(0, PATH_BASE_TEST_FUNCTIONAL)
2323

24-
from test_framework.blocktools import WITNESS_COMMITMENT_HEADER, script_BIP34_coinbase_height # noqa: E402
25-
from test_framework.messages import CBlock, CBlockHeader, COutPoint, CTransaction, CTxIn, CTxInWitness, CTxOut, from_hex, deser_string, hash256, ser_compact_size, ser_string, ser_uint256, tx_from_hex, uint256_from_str # noqa: E402
24+
from test_framework.blocktools import get_witness_script, script_BIP34_coinbase_height # noqa: E402
25+
from test_framework.messages import CBlock, CBlockHeader, COutPoint, CTransaction, CTxIn, CTxInWitness, CTxOut, from_hex, deser_string, ser_compact_size, ser_string, ser_uint256, tx_from_hex # noqa: E402
2626
from test_framework.script import CScriptOp # noqa: E402
2727

2828
logging.basicConfig(
@@ -123,10 +123,6 @@ def create_coinbase(height, value, spk):
123123
cb.vout = [CTxOut(value, spk)]
124124
return cb
125125

126-
def get_witness_script(witness_root, witness_nonce):
127-
commitment = uint256_from_str(hash256(ser_uint256(witness_root) + ser_uint256(witness_nonce)))
128-
return b"\x6a" + CScriptOp.encode_op_pushdata(WITNESS_COMMITMENT_HEADER + ser_uint256(commitment))
129-
130126
def signet_txs(block, challenge):
131127
# assumes signet solution has not been added yet so does not need
132128
# to be removed
@@ -222,7 +218,7 @@ def generate_psbt(tmpl, reward_spk, *, blocktime=None):
222218
cbwit = CTxInWitness()
223219
cbwit.scriptWitness.stack = [ser_uint256(witnonce)]
224220
block.vtx[0].wit.vtxinwit = [cbwit]
225-
block.vtx[0].vout.append(CTxOut(0, get_witness_script(witroot, witnonce)))
221+
block.vtx[0].vout.append(CTxOut(0, bytes(get_witness_script(witroot, witnonce))))
226222

227223
signme, spendme = signet_txs(block, signet_spk_bin)
228224

@@ -627,5 +623,3 @@ def main():
627623

628624
if __name__ == "__main__":
629625
main()
630-
631-

0 commit comments

Comments
 (0)