Skip to content

Commit 81c54de

Browse files
committed
rpc: update getblocktemplate with signet rule, include signet_challenge
1 parent 25bc840 commit 81c54de

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/rpc/mining.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,13 @@ static RPCHelpMan getblocktemplate()
714714
// TODO: Maybe recheck connections/IBD and (if something wrong) send an expires-immediately template to stop miners?
715715
}
716716

717+
const Consensus::Params& consensusParams = Params().GetConsensus();
718+
719+
// GBT must be called with 'signet' set in the rules for signet chains
720+
if (consensusParams.signet_blocks && setClientRules.count("signet") != 1) {
721+
throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the signet rule set (call with {\"rules\": [\"segwit\", \"signet\"]})");
722+
}
723+
717724
// GBT must be called with 'segwit' set in the rules
718725
if (setClientRules.count("segwit") != 1) {
719726
throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the segwit rule set (call with {\"rules\": [\"segwit\"]})");
@@ -745,7 +752,6 @@ static RPCHelpMan getblocktemplate()
745752
}
746753
CHECK_NONFATAL(pindexPrev);
747754
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
748-
const Consensus::Params& consensusParams = Params().GetConsensus();
749755

750756
// Update nTime
751757
UpdateTime(pblock, consensusParams, pindexPrev);
@@ -809,6 +815,12 @@ static RPCHelpMan getblocktemplate()
809815
UniValue aRules(UniValue::VARR);
810816
aRules.push_back("csv");
811817
if (!fPreSegWit) aRules.push_back("!segwit");
818+
if (consensusParams.signet_blocks) {
819+
// indicate to miner that they must understand signet rules
820+
// when attempting to mine with this template
821+
aRules.push_back("!signet");
822+
}
823+
812824
UniValue vbavailable(UniValue::VOBJ);
813825
for (int j = 0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
814826
Consensus::DeploymentPos pos = Consensus::DeploymentPos(j);
@@ -889,6 +901,10 @@ static RPCHelpMan getblocktemplate()
889901
result.pushKV("bits", strprintf("%08x", pblock->nBits));
890902
result.pushKV("height", (int64_t)(pindexPrev->nHeight+1));
891903

904+
if (consensusParams.signet_blocks) {
905+
result.pushKV("signet_challenge", HexStr(consensusParams.signet_challenge));
906+
}
907+
892908
if (!pblocktemplate->vchCoinbaseCommitment.empty()) {
893909
result.pushKV("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment));
894910
}

0 commit comments

Comments
 (0)