Skip to content

Commit a1dc85c

Browse files
committed
Merge pull request monero-project#9416
ac0af73 rpc: add cumul weight field to block template resp (jeffro256)
2 parents 65cc1f1 + ac0af73 commit a1dc85c

File tree

10 files changed

+31
-24
lines changed

10 files changed

+31
-24
lines changed

src/cryptonote_basic/miner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,10 @@ namespace cryptonote
171171
extra_nonce = m_extra_messages[m_config.current_extra_message_index];
172172
}
173173

174+
uint64_t cumulative_weight;
174175
uint64_t seed_height;
175176
crypto::hash seed_hash;
176-
if(!m_phandler->get_block_template(bl, m_mine_address, di, height, expected_reward, extra_nonce, seed_height, seed_hash))
177+
if(!m_phandler->get_block_template(bl, m_mine_address, di, height, expected_reward, cumulative_weight, extra_nonce, seed_height, seed_hash))
177178
{
178179
LOG_ERROR("Failed to get_block_template(), stopping mining");
179180
return false;

src/cryptonote_basic/miner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace cryptonote
4747
struct i_miner_handler
4848
{
4949
virtual bool handle_block_found(block& b, block_verification_context &bvc) = 0;
50-
virtual bool get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash) = 0;
50+
virtual bool get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, uint64_t &cumulative_weight, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash) = 0;
5151
protected:
5252
~i_miner_handler(){};
5353
};

src/cryptonote_core/blockchain.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ uint64_t Blockchain::get_current_cumulative_block_weight_median() const
15441544
// in a lot of places. That flag is not referenced in any of the code
15451545
// nor any of the makefiles, howeve. Need to look into whether or not it's
15461546
// necessary at all.
1547-
bool Blockchain::create_block_template(block& b, const crypto::hash *from_block, const account_public_address& miner_address, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
1547+
bool Blockchain::create_block_template(block& b, const crypto::hash *from_block, const account_public_address& miner_address, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, uint64_t& cumulative_weight, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
15481548
{
15491549
LOG_PRINT_L3("Blockchain::" << __func__);
15501550
size_t median_weight;
@@ -1571,6 +1571,7 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
15711571
diffic = m_btc_difficulty;
15721572
height = m_btc_height;
15731573
expected_reward = m_btc_expected_reward;
1574+
cumulative_weight = m_btc_cumulative_weight;
15741575
seed_height = m_btc_seed_height;
15751576
seed_hash = m_btc_seed_hash;
15761577
return true;
@@ -1754,7 +1755,7 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
17541755
size_t max_outs = hf_version >= 4 ? 1 : 11;
17551756
bool r = construct_miner_tx(height, median_weight, already_generated_coins, txs_weight, fee, miner_address, b.miner_tx, ex_nonce, max_outs, hf_version);
17561757
CHECK_AND_ASSERT_MES(r, false, "Failed to construct miner tx, first chance");
1757-
size_t cumulative_weight = txs_weight + get_transaction_weight(b.miner_tx);
1758+
cumulative_weight = txs_weight + get_transaction_weight(b.miner_tx);
17581759
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
17591760
MDEBUG("Creating block template: miner tx weight " << get_transaction_weight(b.miner_tx) <<
17601761
", cumulative weight " << cumulative_weight);
@@ -1806,16 +1807,16 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
18061807
#endif
18071808

18081809
if (!from_block)
1809-
cache_block_template(b, miner_address, ex_nonce, diffic, height, expected_reward, seed_height, seed_hash, pool_cookie);
1810+
cache_block_template(b, miner_address, ex_nonce, diffic, height, expected_reward, cumulative_weight, seed_height, seed_hash, pool_cookie);
18101811
return true;
18111812
}
18121813
LOG_ERROR("Failed to create_block_template with " << 10 << " tries");
18131814
return false;
18141815
}
18151816
//------------------------------------------------------------------
1816-
bool Blockchain::create_block_template(block& b, const account_public_address& miner_address, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
1817+
bool Blockchain::create_block_template(block& b, const account_public_address& miner_address, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, uint64_t& cumulative_weight, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
18171818
{
1818-
return create_block_template(b, NULL, miner_address, diffic, height, expected_reward, ex_nonce, seed_height, seed_hash);
1819+
return create_block_template(b, NULL, miner_address, diffic, height, expected_reward, cumulative_weight, ex_nonce, seed_height, seed_hash);
18191820
}
18201821
//------------------------------------------------------------------
18211822
bool Blockchain::get_miner_data(uint8_t& major_version, uint64_t& height, crypto::hash& prev_id, crypto::hash& seed_hash, difficulty_type& difficulty, uint64_t& median_weight, uint64_t& already_generated_coins, std::vector<tx_block_template_backlog_entry>& tx_backlog)
@@ -5607,7 +5608,7 @@ void Blockchain::invalidate_block_template_cache()
56075608
m_btc_valid = false;
56085609
}
56095610

5610-
void Blockchain::cache_block_template(const block &b, const cryptonote::account_public_address &address, const blobdata &nonce, const difficulty_type &diff, uint64_t height, uint64_t expected_reward, uint64_t seed_height, const crypto::hash &seed_hash, uint64_t pool_cookie)
5611+
void Blockchain::cache_block_template(const block &b, const cryptonote::account_public_address &address, const blobdata &nonce, const difficulty_type &diff, uint64_t height, uint64_t expected_reward, uint64_t cumulative_weight, uint64_t seed_height, const crypto::hash &seed_hash, uint64_t pool_cookie)
56115612
{
56125613
MDEBUG("Setting block template cache");
56135614
m_btc = b;
@@ -5616,6 +5617,7 @@ void Blockchain::cache_block_template(const block &b, const cryptonote::account_
56165617
m_btc_difficulty = diff;
56175618
m_btc_height = height;
56185619
m_btc_expected_reward = expected_reward;
5620+
m_btc_cumulative_weight = cumulative_weight;
56195621
m_btc_seed_hash = seed_hash;
56205622
m_btc_seed_height = seed_height;
56215623
m_btc_pool_cookie = pool_cookie;

src/cryptonote_core/blockchain.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ namespace cryptonote
371371
*
372372
* @return true if block template filled in successfully, else false
373373
*/
374-
bool create_block_template(block& b, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
375-
bool create_block_template(block& b, const crypto::hash *from_block, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
374+
bool create_block_template(block& b, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, uint64_t& cumulative_weight, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
375+
bool create_block_template(block& b, const crypto::hash *from_block, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, uint64_t& cumulative_weight, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
376376

377377
/**
378378
* @brief gets data required to create a block template and start mining on it
@@ -1202,6 +1202,7 @@ namespace cryptonote
12021202
uint64_t m_btc_height;
12031203
uint64_t m_btc_pool_cookie;
12041204
uint64_t m_btc_expected_reward;
1205+
uint64_t m_btc_cumulative_weight;
12051206
crypto::hash m_btc_seed_hash;
12061207
uint64_t m_btc_seed_height;
12071208
bool m_btc_valid;
@@ -1594,7 +1595,7 @@ namespace cryptonote
15941595
*
15951596
* At some point, may be used to push an update to miners
15961597
*/
1597-
void cache_block_template(const block &b, const cryptonote::account_public_address &address, const blobdata &nonce, const difficulty_type &diff, uint64_t height, uint64_t expected_reward, uint64_t seed_height, const crypto::hash &seed_hash, uint64_t pool_cookie);
1598+
void cache_block_template(const block &b, const cryptonote::account_public_address &address, const blobdata &nonce, const difficulty_type &diff, uint64_t height, uint64_t expected_reward, uint64_t cumulative_weight, uint64_t seed_height, const crypto::hash &seed_hash, uint64_t pool_cookie);
15981599

15991600
/**
16001601
* @brief sends new block notifications to ZMQ `miner_data` subscribers

src/cryptonote_core/cryptonote_core.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,14 +1468,14 @@ namespace cryptonote
14681468
notify_txpool_event(tx_blobs, epee::to_span(tx_hashes), epee::to_span(txs), just_broadcasted);
14691469
}
14701470
//-----------------------------------------------------------------------------------------------
1471-
bool core::get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
1471+
bool core::get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, uint64_t& cumulative_weight, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
14721472
{
1473-
return m_blockchain_storage.create_block_template(b, adr, diffic, height, expected_reward, ex_nonce, seed_height, seed_hash);
1473+
return m_blockchain_storage.create_block_template(b, adr, diffic, height, expected_reward, cumulative_weight, ex_nonce, seed_height, seed_hash);
14741474
}
14751475
//-----------------------------------------------------------------------------------------------
1476-
bool core::get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
1476+
bool core::get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, uint64_t& cumulative_weight, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
14771477
{
1478-
return m_blockchain_storage.create_block_template(b, prev_block, adr, diffic, height, expected_reward, ex_nonce, seed_height, seed_hash);
1478+
return m_blockchain_storage.create_block_template(b, prev_block, adr, diffic, height, expected_reward, cumulative_weight, ex_nonce, seed_height, seed_hash);
14791479
}
14801480
//-----------------------------------------------------------------------------------------------
14811481
bool core::get_miner_data(uint8_t& major_version, uint64_t& height, crypto::hash& prev_id, crypto::hash& seed_hash, difficulty_type& difficulty, uint64_t& median_weight, uint64_t& already_generated_coins, std::vector<tx_block_template_backlog_entry>& tx_backlog)

src/cryptonote_core/cryptonote_core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ namespace cryptonote
231231
*
232232
* @note see Blockchain::create_block_template
233233
*/
234-
virtual bool get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash) override;
235-
virtual bool get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
234+
virtual bool get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, uint64_t &cumulative_weight, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash) override;
235+
virtual bool get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, uint64_t &cumulative_weight, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
236236

237237
/**
238238
* @copydoc Blockchain::get_miner_data

src/rpc/core_rpc_server.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,10 +1856,10 @@ namespace cryptonote
18561856
return 0;
18571857
}
18581858
//------------------------------------------------------------------------------------------------------------------------------
1859-
bool core_rpc_server::get_block_template(const account_public_address &address, const crypto::hash *prev_block, const cryptonote::blobdata &extra_nonce, size_t &reserved_offset, cryptonote::difficulty_type &difficulty, uint64_t &height, uint64_t &expected_reward, block &b, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, epee::json_rpc::error &error_resp)
1859+
bool core_rpc_server::get_block_template(const account_public_address &address, const crypto::hash *prev_block, const cryptonote::blobdata &extra_nonce, size_t &reserved_offset, cryptonote::difficulty_type &difficulty, uint64_t &height, uint64_t &expected_reward, uint64_t& cumulative_weight, block &b, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, epee::json_rpc::error &error_resp)
18601860
{
18611861
b = boost::value_initialized<cryptonote::block>();
1862-
if(!m_core.get_block_template(b, prev_block, address, difficulty, height, expected_reward, extra_nonce, seed_height, seed_hash))
1862+
if(!m_core.get_block_template(b, prev_block, address, difficulty, height, expected_reward, cumulative_weight, extra_nonce, seed_height, seed_hash))
18631863
{
18641864
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
18651865
error_resp.message = "Internal error: failed to create block template";
@@ -1984,7 +1984,7 @@ namespace cryptonote
19841984
}
19851985
}
19861986
crypto::hash seed_hash, next_seed_hash;
1987-
if (!get_block_template(info.address, req.prev_block.empty() ? NULL : &prev_block, blob_reserve, reserved_offset, wdiff, res.height, res.expected_reward, b, res.seed_height, seed_hash, next_seed_hash, error_resp))
1987+
if (!get_block_template(info.address, req.prev_block.empty() ? NULL : &prev_block, blob_reserve, reserved_offset, wdiff, res.height, res.expected_reward, res.cumulative_weight, b, res.seed_height, seed_hash, next_seed_hash, error_resp))
19881988
return false;
19891989
if (b.major_version >= RX_BLOCK_VERSION)
19901990
{
@@ -3520,9 +3520,9 @@ namespace cryptonote
35203520
crypto::hash seed_hash, next_seed_hash;
35213521
if (!m_rpc_payment->get_info(client, [&](const cryptonote::blobdata &extra_nonce, cryptonote::block &b, uint64_t &seed_height, crypto::hash &seed_hash)->bool{
35223522
cryptonote::difficulty_type difficulty;
3523-
uint64_t height, expected_reward;
3523+
uint64_t height, expected_reward, cumulative_weight;
35243524
size_t reserved_offset;
3525-
if (!get_block_template(m_rpc_payment->get_payment_address(), NULL, extra_nonce, reserved_offset, difficulty, height, expected_reward, b, seed_height, seed_hash, next_seed_hash, error_resp))
3525+
if (!get_block_template(m_rpc_payment->get_payment_address(), NULL, extra_nonce, reserved_offset, difficulty, height, expected_reward, cumulative_weight, b, seed_height, seed_hash, next_seed_hash, error_resp))
35263526
return false;
35273527
return true;
35283528
}, hashing_blob, res.seed_height, seed_hash, top_hash, res.diff, res.credits_per_hash_found, res.credits, res.cookie))

src/rpc/core_rpc_server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ namespace cryptonote
285285
enum invoke_http_mode { JON, BIN, JON_RPC };
286286
template <typename COMMAND_TYPE>
287287
bool use_bootstrap_daemon_if_necessary(const invoke_http_mode &mode, const std::string &command_name, const typename COMMAND_TYPE::request& req, typename COMMAND_TYPE::response& res, bool &r);
288-
bool get_block_template(const account_public_address &address, const crypto::hash *prev_block, const cryptonote::blobdata &extra_nonce, size_t &reserved_offset, cryptonote::difficulty_type &difficulty, uint64_t &height, uint64_t &expected_reward, block &b, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, epee::json_rpc::error &error_resp);
288+
bool get_block_template(const account_public_address &address, const crypto::hash *prev_block, const cryptonote::blobdata &extra_nonce, size_t &reserved_offset, cryptonote::difficulty_type &difficulty, uint64_t &height, uint64_t &expected_reward, uint64_t& cumulative_weight, block &b, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, epee::json_rpc::error &error_resp);
289289
bool check_payment(const std::string &client, uint64_t payment, const std::string &rpc, bool same_ts, std::string &message, uint64_t &credits, std::string &top_hash);
290290

291291
core& m_core;

src/rpc/core_rpc_server_commands_defs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ inline const std::string get_rpc_status(const bool trusted_daemon, const std::st
101101
// advance which version they will stop working with
102102
// Don't go over 32767 for any of these
103103
#define CORE_RPC_VERSION_MAJOR 3
104-
#define CORE_RPC_VERSION_MINOR 15
104+
#define CORE_RPC_VERSION_MINOR 16
105105
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
106106
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
107107

@@ -984,6 +984,7 @@ inline const std::string get_rpc_status(const bool trusted_daemon, const std::st
984984
uint64_t height;
985985
uint64_t reserved_offset;
986986
uint64_t expected_reward;
987+
uint64_t cumulative_weight;
987988
std::string prev_hash;
988989
uint64_t seed_height;
989990
std::string seed_hash;
@@ -999,6 +1000,7 @@ inline const std::string get_rpc_status(const bool trusted_daemon, const std::st
9991000
KV_SERIALIZE(height)
10001001
KV_SERIALIZE(reserved_offset)
10011002
KV_SERIALIZE(expected_reward)
1003+
KV_SERIALIZE_OPT(cumulative_weight, static_cast<uint64_t>(0))
10021004
KV_SERIALIZE(prev_hash)
10031005
KV_SERIALIZE(seed_height)
10041006
KV_SERIALIZE(blocktemplate_blob)

tests/functional_tests/blockchain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def _test_generateblocks(self, blocks):
137137
assert res_getblocktemplate.reserved_offset > 0
138138
assert res_getblocktemplate.prev_hash == res_info.top_block_hash
139139
assert res_getblocktemplate.expected_reward >= 600000000000
140+
assert res_getblocktemplate.cumulative_weight > 0
140141
assert len(res_getblocktemplate.blocktemplate_blob) > 0
141142
assert len(res_getblocktemplate.blockhashing_blob) > 0
142143
assert int(res_getblocktemplate.wide_difficulty, 16) == (res_getblocktemplate.difficulty_top64 << 64) + res_getblocktemplate.difficulty

0 commit comments

Comments
 (0)