Skip MIN_MINER_OUTPUTS for solo blocks

This commit is contained in:
XfedeX 2023-02-03 23:25:47 +01:00
parent 0d8cada1ff
commit e13257107a
6 changed files with 52 additions and 46 deletions

View file

@ -470,10 +470,12 @@ namespace cryptonote
VARINT_FIELD(timestamp)
FIELD(prev_id)
FIELD(nonce)
if (major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && major_version < HF_VERSION_P2POOL)
if (major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG)
{
FIELD(signature)
FIELD(signature)
if (major_version < HF_VERSION_P2POOL) {
FIELD(vote)
}
}
END_SERIALIZE()
};

View file

@ -196,10 +196,12 @@ namespace boost
a & b.timestamp;
a & b.prev_id;
a & b.nonce;
if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && b.major_version < HF_VERSION_P2POOL)
if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG)
{
a & b.signature;
a & b.vote;
if (b.major_version < HF_VERSION_P2POOL) {
a & b.vote;
}
}
//------------------
a & b.miner_tx;

View file

@ -610,7 +610,7 @@ namespace cryptonote
b.nonce = nonce;
// Miner Block Header Signing
if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && b.major_version < HF_VERSION_P2POOL)
if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG)
{
// tx key derivation
crypto::key_derivation derivation;
@ -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

@ -1411,50 +1411,45 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std:
// valid output types
bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height, uint8_t hf_version)
{
bool hasValidSig = false
// Miner Block Header Signing
if (hf_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && hf_version < HF_VERSION_P2POOL)
{
// 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 (b.vote > 2)
{
if (hf_version >= HF_VERSION_P2POOL && b.miner_tx.vout.size() > MIN_MINER_OUTPUTS) {
LOG_PRINT_L3("Miner transaction has enough outputs, it doesn't need a valid signature")
} else {
// Check tx signature
// 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))
{
}
// 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 {
} else {
LOG_PRINT_L1("Miner signature is good");
LOG_PRINT_L1("Vote: " << b.vote);
}
}
if (hf_version >= HF_VERSION_P2POOL)
{
if (b.miner_tx.vout.size() < MIN_MINER_OUTPUTS)
{
MWARNING("Coinbase transaction must have more than " << MIN_MINER_OUTPUTS << " outputs");
return false;
}
for (const auto &o: b.miner_tx.vout)
{
CHECK_AND_ASSERT_MES(o.target.type() == typeid(txout_to_key), false, "Wrong txout type: " << o.target.type().name() << ", expected txout_to_key in transaction id=" << get_transaction_hash(b.miner_tx));
if (hf_version < HF_VERSION_P2POOL) {
LOG_PRINT_L1("Vote: " << b.vote);
}
}
}
}

View file

@ -2203,10 +2203,12 @@ namespace cryptonote
return false;
}
b.nonce = req.starting_nonce;
if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && b.major_version < HF_VERSION_P2POOL)
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

@ -900,10 +900,12 @@ namespace rpc
header.minor_version = b.minor_version;
header.timestamp = b.timestamp;
header.nonce = b.nonce;
if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG && b.major_version < HF_VERSION_P2POOL)
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;