vote by block

This commit is contained in:
wowario 2021-06-20 08:17:43 +03:00
parent 0871203167
commit daddd7d231
No known key found for this signature in database
GPG Key ID: 793504B449C69220
12 changed files with 91 additions and 0 deletions

View File

@ -462,6 +462,7 @@ namespace cryptonote
crypto::hash prev_id; crypto::hash prev_id;
uint32_t nonce; uint32_t nonce;
crypto::signature signature; crypto::signature signature;
uint16_t vote;
BEGIN_SERIALIZE() BEGIN_SERIALIZE()
VARINT_FIELD(major_version) VARINT_FIELD(major_version)
@ -470,7 +471,10 @@ namespace cryptonote
FIELD(prev_id) FIELD(prev_id)
FIELD(nonce) FIELD(nonce)
if (major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) if (major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG)
{
FIELD(signature) FIELD(signature)
FIELD(vote)
}
END_SERIALIZE() END_SERIALIZE()
}; };

View File

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

View File

@ -101,6 +101,7 @@ namespace cryptonote
const command_line::arg_descriptor<uint16_t> arg_bg_mining_idle_threshold_percentage = {"bg-mining-idle-threshold", "Specify minimum avg idle percentage over lookback interval", miner::BACKGROUND_MINING_DEFAULT_IDLE_THRESHOLD_PERCENTAGE, true}; const command_line::arg_descriptor<uint16_t> arg_bg_mining_idle_threshold_percentage = {"bg-mining-idle-threshold", "Specify minimum avg idle percentage over lookback interval", miner::BACKGROUND_MINING_DEFAULT_IDLE_THRESHOLD_PERCENTAGE, true};
const command_line::arg_descriptor<uint16_t> arg_bg_mining_miner_target_percentage = {"bg-mining-miner-target", "Specify maximum percentage cpu use by miner(s)", miner::BACKGROUND_MINING_DEFAULT_MINING_TARGET_PERCENTAGE, true}; const command_line::arg_descriptor<uint16_t> arg_bg_mining_miner_target_percentage = {"bg-mining-miner-target", "Specify maximum percentage cpu use by miner(s)", miner::BACKGROUND_MINING_DEFAULT_MINING_TARGET_PERCENTAGE, true};
const command_line::arg_descriptor<std::string> arg_spendkey = {"spendkey", "Specify secret spend key used for mining", "", true}; const command_line::arg_descriptor<std::string> arg_spendkey = {"spendkey", "Specify secret spend key used for mining", "", true};
const command_line::arg_descriptor<std::string> arg_vote = {"vote", "Vote for proposals.", "", true};
} }
@ -294,6 +295,7 @@ namespace cryptonote
command_line::add_arg(desc, arg_bg_mining_idle_threshold_percentage); command_line::add_arg(desc, arg_bg_mining_idle_threshold_percentage);
command_line::add_arg(desc, arg_bg_mining_miner_target_percentage); command_line::add_arg(desc, arg_bg_mining_miner_target_percentage);
command_line::add_arg(desc, arg_spendkey); command_line::add_arg(desc, arg_spendkey);
command_line::add_arg(desc, arg_vote);
} }
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
bool miner::init(const boost::program_options::variables_map& vm, network_type nettype) bool miner::init(const boost::program_options::variables_map& vm, network_type nettype)
@ -309,6 +311,25 @@ namespace cryptonote
m_spendkey = spendkey; m_spendkey = spendkey;
m_viewkey = viewkey; m_viewkey = viewkey;
} }
if(!command_line::has_arg(vm, arg_vote))
{
m_int_vote = 0;
} else {
m_vote = command_line::get_arg(vm, arg_vote);
if(m_vote != "yes" && m_vote != "no")
{
LOG_ERROR("Voting format error, only a \"yes\" or \"no\" response is accepted");
return false;
}
if(m_vote == "yes")
{
m_int_vote = 1;
}
if(m_vote == "no")
{
m_int_vote = 2;
}
}
if(command_line::has_arg(vm, arg_extra_messages)) if(command_line::has_arg(vm, arg_extra_messages))
{ {
std::string buff; std::string buff;
@ -607,6 +628,7 @@ namespace cryptonote
crypto::generate_signature(sig_data, output_public_key, eph_secret_key, signature); crypto::generate_signature(sig_data, output_public_key, eph_secret_key, signature);
// amend signature to block header before PoW hashing // amend signature to block header before PoW hashing
b.signature = signature; b.signature = signature;
b.vote = m_int_vote;
} }
crypto::hash h; crypto::hash h;
@ -651,6 +673,14 @@ namespace cryptonote
" //@@@@@@@@@@@@@@@@@// \n" " //@@@@@@@@@@@@@@@@@// \n"
<< ENDL); << ENDL);
MGINFO_GREEN("Awesome, you won a block reward!\n" << get_block_hash(b) << " at height " << height); MGINFO_GREEN("Awesome, you won a block reward!\n" << get_block_hash(b) << " at height " << height);
if (b.vote == 1)
{
MGINFO_GREEN("Your \"YES\" vote has been cast.");
}
if (b.vote == 2)
{
MGINFO_GREEN("Your \"NO\" vote has been cast.");
}
cryptonote::block_verification_context bvc; cryptonote::block_verification_context bvc;
if(!m_phandler->handle_block_found(b, bvc) || !bvc.m_added_to_main_chain) if(!m_phandler->handle_block_found(b, bvc) || !bvc.m_added_to_main_chain)
{ {

View File

@ -138,6 +138,8 @@ namespace cryptonote
account_public_address m_mine_address; account_public_address m_mine_address;
crypto::secret_key m_spendkey; crypto::secret_key m_spendkey;
crypto::secret_key m_viewkey; crypto::secret_key m_viewkey;
std::string m_vote;
uint16_t m_int_vote;
epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval; epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval;
epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval; epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval;
epee::math_helper::once_a_time_seconds<1> m_autodetect_interval; epee::math_helper::once_a_time_seconds<1> m_autodetect_interval;

View File

@ -1428,6 +1428,11 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height,
MWARNING("Wrong txout type"); MWARNING("Wrong txout type");
return false; 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 // keccak hash block header data and check miner signature
// if signature is invalid, reject block // if signature is invalid, reject block
crypto::hash sig_data = get_sig_data(b); crypto::hash sig_data = get_sig_data(b);
@ -1440,6 +1445,7 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height,
return false; return false;
} else { } else {
LOG_PRINT_L1("Miner signature is good"); LOG_PRINT_L1("Miner signature is good");
LOG_PRINT_L1("Vote: " << b.vote);
} }
} }

View File

@ -94,6 +94,7 @@ namespace {
void print_block_header(cryptonote::block_header_response const & header) void print_block_header(cryptonote::block_header_response const & header)
{ {
tools::success_msg_writer() tools::success_msg_writer()
<< "vote: " << header.vote << std::endl
<< "timestamp: " << boost::lexical_cast<std::string>(header.timestamp) << " (" << tools::get_human_readable_timestamp(header.timestamp) << ")" << std::endl << "timestamp: " << boost::lexical_cast<std::string>(header.timestamp) << " (" << tools::get_human_readable_timestamp(header.timestamp) << ")" << std::endl
<< "previous hash: " << header.prev_hash << std::endl << "previous hash: " << header.prev_hash << std::endl
<< "nonce: " << boost::lexical_cast<std::string>(header.nonce) << std::endl << "nonce: " << boost::lexical_cast<std::string>(header.nonce) << std::endl

View File

@ -1953,6 +1953,7 @@ namespace cryptonote
res.blocktemplate_blob = string_tools::buff_to_hex_nodelimer(block_blob); res.blocktemplate_blob = string_tools::buff_to_hex_nodelimer(block_blob);
res.blockhashing_blob = string_tools::buff_to_hex_nodelimer(hashing_blob); res.blockhashing_blob = string_tools::buff_to_hex_nodelimer(hashing_blob);
res.status = CORE_RPC_STATUS_OK; res.status = CORE_RPC_STATUS_OK;
res.vote = 0;
return true; return true;
} }
//------------------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------------------
@ -2260,6 +2261,7 @@ namespace cryptonote
if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG) if (b.major_version >= HF_VERSION_BLOCK_HEADER_MINER_SIG)
{ {
b.signature = {}; b.signature = {};
b.vote = 0;
} }
crypto::hash seed_hash = crypto::null_hash; 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)) if (b.major_version >= RX_BLOCK_VERSION && !epee::string_tools::hex_to_pod(template_res.seed_hash, seed_hash))
@ -2299,6 +2301,7 @@ namespace cryptonote
bool core_rpc_server::fill_block_header_response(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_response& response, bool fill_pow_hash) bool core_rpc_server::fill_block_header_response(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_response& response, bool fill_pow_hash)
{ {
PERF_TIMER(fill_block_header_response); PERF_TIMER(fill_block_header_response);
response.vote = blk.vote;
response.major_version = blk.major_version; response.major_version = blk.major_version;
response.minor_version = blk.minor_version; response.minor_version = blk.minor_version;
response.timestamp = blk.timestamp; response.timestamp = blk.timestamp;

View File

@ -973,6 +973,7 @@ namespace cryptonote
std::string next_seed_hash; std::string next_seed_hash;
blobdata blocktemplate_blob; blobdata blocktemplate_blob;
blobdata blockhashing_blob; blobdata blockhashing_blob;
uint16_t vote;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_PARENT(rpc_response_base) KV_SERIALIZE_PARENT(rpc_response_base)
@ -988,6 +989,7 @@ namespace cryptonote
KV_SERIALIZE(blockhashing_blob) KV_SERIALIZE(blockhashing_blob)
KV_SERIALIZE(seed_hash) KV_SERIALIZE(seed_hash)
KV_SERIALIZE(next_seed_hash) KV_SERIALIZE(next_seed_hash)
KV_SERIALIZE(vote)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };
typedef epee::misc_utils::struct_init<response_t> response; typedef epee::misc_utils::struct_init<response_t> response;
@ -1184,6 +1186,7 @@ namespace cryptonote
std::string pow_hash; std::string pow_hash;
uint64_t long_term_weight; uint64_t long_term_weight;
std::string miner_tx_hash; std::string miner_tx_hash;
uint16_t vote;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(major_version) KV_SERIALIZE(major_version)
@ -1208,6 +1211,7 @@ namespace cryptonote
KV_SERIALIZE(pow_hash) KV_SERIALIZE(pow_hash)
KV_SERIALIZE_OPT(long_term_weight, (uint64_t)0) KV_SERIALIZE_OPT(long_term_weight, (uint64_t)0)
KV_SERIALIZE(miner_tx_hash) KV_SERIALIZE(miner_tx_hash)
KV_SERIALIZE(vote)
END_KV_SERIALIZE_MAP() END_KV_SERIALIZE_MAP()
}; };

View File

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

View File

@ -165,6 +165,7 @@ namespace rpc
crypto::hash prev_id; crypto::hash prev_id;
uint32_t nonce; uint32_t nonce;
crypto::signature signature; crypto::signature signature;
uint16_t vote;
uint64_t height; uint64_t height;
uint64_t depth; uint64_t depth;
crypto::hash hash; crypto::hash hash;

View File

@ -314,6 +314,7 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::b
INSERT_INTO_JSON_OBJECT(dest, prev_id, b.prev_id); INSERT_INTO_JSON_OBJECT(dest, prev_id, b.prev_id);
INSERT_INTO_JSON_OBJECT(dest, nonce, b.nonce); INSERT_INTO_JSON_OBJECT(dest, nonce, b.nonce);
INSERT_INTO_JSON_OBJECT(dest, signature, b.signature); INSERT_INTO_JSON_OBJECT(dest, signature, b.signature);
INSERT_INTO_JSON_OBJECT(dest, vote, b.vote);
INSERT_INTO_JSON_OBJECT(dest, miner_tx, b.miner_tx); INSERT_INTO_JSON_OBJECT(dest, miner_tx, b.miner_tx);
INSERT_INTO_JSON_OBJECT(dest, tx_hashes, b.tx_hashes); INSERT_INTO_JSON_OBJECT(dest, tx_hashes, b.tx_hashes);
@ -334,6 +335,7 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::block& b)
GET_FROM_JSON_OBJECT(val, b.prev_id, prev_id); GET_FROM_JSON_OBJECT(val, b.prev_id, prev_id);
GET_FROM_JSON_OBJECT(val, b.nonce, nonce); GET_FROM_JSON_OBJECT(val, b.nonce, nonce);
GET_FROM_JSON_OBJECT(val, b.signature, signature); GET_FROM_JSON_OBJECT(val, b.signature, signature);
GET_FROM_JSON_OBJECT(val, b.vote, vote);
GET_FROM_JSON_OBJECT(val, b.miner_tx, miner_tx); GET_FROM_JSON_OBJECT(val, b.miner_tx, miner_tx);
GET_FROM_JSON_OBJECT(val, b.tx_hashes, tx_hashes); GET_FROM_JSON_OBJECT(val, b.tx_hashes, tx_hashes);
} }
@ -1080,6 +1082,7 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::r
{ {
dest.StartObject(); dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, vote, response.vote);
INSERT_INTO_JSON_OBJECT(dest, major_version, response.major_version); INSERT_INTO_JSON_OBJECT(dest, major_version, response.major_version);
INSERT_INTO_JSON_OBJECT(dest, minor_version, response.minor_version); INSERT_INTO_JSON_OBJECT(dest, minor_version, response.minor_version);
INSERT_INTO_JSON_OBJECT(dest, timestamp, response.timestamp); INSERT_INTO_JSON_OBJECT(dest, timestamp, response.timestamp);
@ -1101,6 +1104,7 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::BlockHeaderResp
throw WRONG_TYPE("json object"); throw WRONG_TYPE("json object");
} }
GET_FROM_JSON_OBJECT(val, response.vote, vote);
GET_FROM_JSON_OBJECT(val, response.major_version, major_version); GET_FROM_JSON_OBJECT(val, response.major_version, major_version);
GET_FROM_JSON_OBJECT(val, response.minor_version, minor_version); GET_FROM_JSON_OBJECT(val, response.minor_version, minor_version);
GET_FROM_JSON_OBJECT(val, response.timestamp, timestamp); GET_FROM_JSON_OBJECT(val, response.timestamp, timestamp);

34
utils/votes.pl Normal file
View File

@ -0,0 +1,34 @@
# Script gets votes for a block range.
# Run: perl votes.pl 60 300
$IP='127.0.0.1:11181';
$begin=$ARGV[0];
if ($#ARGV == 1 ) { $end=$ARGV[1]; }
open (F,">vote.txt");
for ($i=$begin; $i<$end; $i++) {
$k=qq(-d '{"params":{"height":$i},"jsonrpc":"2.0","id":"test","method":"get_block_header_by_height"}' -H 'Content-Type: application/json');
$k=`curl -s -X POST http://$IP/json_rpc $k`;
$k=~/"vote"\D+(\d+)/sg;
$v=$1;
print F "$v ";
}
close F;
$s = do{local(@ARGV,$/)="vote.txt";<>};
$yes = "1";
$count1 = () = $s =~ /\Q$yes/g;
print "$count1 votes for yes\n";
$no = "2";
$count2 = () = $s =~ /\Q$no/g;
print "$count2 votes for no\n";
$abs = "0";
$count0 = () = $s =~ /\Q$abs/g;
print "$count0 abstained\n";
if ($count1 > $count2) {
print "Computer says... Yes!\n";
} else {
print "Computer says... No!\n";
}