P2Pool and Solo-Mining only

This commit is contained in:
_xxfedexx_ 2023-02-17 22:03:49 +01:00
parent fa8932597b
commit d25099a23a
7 changed files with 68 additions and 30 deletions

View file

@ -473,7 +473,9 @@ namespace cryptonote
if (major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG)
{
FIELD(signature)
FIELD(vote)
if (major_version < HF_VERSION_P2POOL) {
FIELD(vote)
}
}
END_SERIALIZE()
};

View file

@ -199,6 +199,9 @@ namespace boost
if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG)
{
a & b.signature;
if (b.major_version < HF_VERSION_P2POOL) {
FIELD(vote)
}
a & b.vote;
}
//------------------

View file

@ -627,7 +627,10 @@ namespace cryptonote
crypto::generate_signature(sig_data, eph_pub_key, eph_secret_key, signature);
// amend signature to block header before PoW hashing
b.signature = signature;
b.vote = m_int_vote;
if (b.major_version < HF_VERSION_P2POOL) {
b.vote = m_int_vote;
}
}
crypto::hash h;

View file

@ -198,6 +198,10 @@
#define HF_VERSION_VIEW_TAGS 20
#define HF_VERSION_2021_SCALING 20
#define HF_VERSION_BLOCK_HEADER_MINER_SIG 18
#define HF_VERSION_P2POOL 20
#define MIN_MINER_OUTPUTS 5
#define MIN_MINER_AMOUNT_FACTOR 500
#define PER_KB_FEE_QUANTIZATION_DECIMALS 8
#define CRYPTONOTE_SCALING_2021_FEE_ROUNDING_PLACES 2

View file

@ -1414,34 +1414,42 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height,
// Miner Block Header Signing
if (hf_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG)
{
// sanity checks
if (b.miner_tx.vout.size() != 1)
// block has been P2Pool mined, no signature required
if (hf_version >= HF_VERSION_P2POOL && b.miner_tx.vout.size() >= MIN_MINER_OUTPUTS)
{
MWARNING("Only 1 output in miner transaction allowed");
return false;
}
if (b.miner_tx.vout[0].target.type() != typeid(txout_to_key))
{
MWARNING("Wrong txout type");
return false;
}
if (b.vote > 2)
{
MWARNING("Vote integer must be either 0, 1, or 2");
return false;
}
// keccak hash block header data and check miner signature
// if signature is invalid, reject block
crypto::hash sig_data = get_sig_data(b);
crypto::signature signature = b.signature;
crypto::public_key eph_pub_key = boost::get<txout_to_key>(b.miner_tx.vout[0].target).key;
if (!crypto::check_signature(sig_data, eph_pub_key, signature))
{
MWARNING("Miner signature is invalid");
return false;
LOG_PRINT_L1("Transaction meets MIN_MINER_OUTPUTS")
} else {
LOG_PRINT_L1("Miner signature is good");
LOG_PRINT_L1("Vote: " << b.vote);
// sanity checks
if (b.miner_tx.vout.size() != 1)
{
MWARNING("Only 1 output in miner transaction allowed");
return false;
}
if (b.miner_tx.vout[0].target.type() != typeid(txout_to_key))
{
MWARNING("Wrong txout type");
return false;
}
if (hf_version < HF_VERSION_P2POOL && b.vote > 2)
{
MWARNING("Vote integer must be either 0, 1, or 2");
return false;
}
// keccak hash block header data and check miner signature
// if signature is invalid, reject block
crypto::hash sig_data = get_sig_data(b);
crypto::signature signature = b.signature;
crypto::public_key eph_pub_key = boost::get<txout_to_key>(b.miner_tx.vout[0].target).key;
if (!crypto::check_signature(sig_data, eph_pub_key, signature))
{
MWARNING("Miner signature is invalid");
return false;
} else {
LOG_PRINT_L1("Miner signature is good");
if (hf_version < HF_VERSION_P2POOL) {
LOG_PRINT_L1("Vote: " << b.vote);
}
}
}
}
@ -1546,6 +1554,20 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
partial_block_reward = true;
base_reward = money_in_use - fee;
}
// check that each output has minimal amount of WOW
if (version >= HF_VERSION_P2POOL) {
uint64_t min_miner_amount = base_reward / MIN_MINER_AMOUNT_FACTOR;
for (auto &o: b.miner_tx.vout)
{
if (o.amount+1 < min_miner_amount)
{
MERROR_VER("Each output must have at least " << print_money(min_miner_amount) << " block reward");
return false;
}
}
}
return true;
}
//------------------------------------------------------------------

View file

@ -2204,7 +2204,9 @@ namespace cryptonote
if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG)
{
b.signature = {};
b.vote = 0;
if (b.major_version < HF_VERSION_P2POOL) {
b.vote = 0;
}
}
crypto::hash seed_hash = crypto::null_hash;
if (b.major_version >= RX_BLOCK_VERSION && !epee::string_tools::hex_to_pod(template_res.seed_hash, seed_hash))

View file

@ -898,7 +898,9 @@ namespace rpc
if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG)
{
header.signature = b.signature;
header.vote = b.vote;
if (b.major_version < HF_VERSION_P2POOL) {
header.vote = b.vote;
}
}
header.prev_id = b.prev_id;