forked from monero-project/monero
-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New print_sn_state_changes command #727
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2966,5 +2966,100 @@ namespace cryptonote | |
res.checkpoints = db.get_checkpoints_range(req.start_height, req.end_height); | ||
return true; | ||
} | ||
//------------------------------------------------------------------------------------------------------------------------------ | ||
bool core_rpc_server::on_get_service_nodes_state_changes(const COMMAND_RPC_GET_SN_STATE_CHANGES::request& req, COMMAND_RPC_GET_SN_STATE_CHANGES::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx) | ||
{ | ||
using blob_t = cryptonote::blobdata; | ||
using block_pair_t = std::pair<blob_t, block>; | ||
std::vector<block_pair_t> blocks; | ||
|
||
const auto& db = m_core.get_blockchain_storage(); | ||
const uint64_t current_height = db.get_current_blockchain_height(); | ||
|
||
uint64_t end_height; | ||
if (req.end_height == COMMAND_RPC_GET_SN_STATE_CHANGES::HEIGHT_SENTINEL_VALUE) { | ||
end_height = current_height; | ||
} else { | ||
end_height = req.end_height; | ||
} | ||
|
||
if (end_height < req.start_height){ | ||
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM; | ||
error_resp.message = "The provided end_height needs to be higher than start_height"; | ||
return false; | ||
} | ||
|
||
if (!db.get_blocks(req.start_height, end_height - req.start_height + 1, blocks)) { | ||
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR; | ||
error_resp.message = "Could not query block at requested height: " + std::to_string(req.start_height); | ||
return false; | ||
} | ||
|
||
res.start_height = req.start_height; | ||
res.end_height = end_height; | ||
|
||
std::vector<blob_t> blobs; | ||
std::vector<crypto::hash> missed_ids; | ||
for (const auto& block : blocks) | ||
{ | ||
blobs.clear(); | ||
if (!db.get_transactions_blobs(block.second.tx_hashes, blobs, missed_ids)) | ||
{ | ||
MERROR("Could not query block at requested height: " << cryptonote::get_block_height(block.second)); | ||
continue; | ||
} | ||
const uint8_t hard_fork_version = block.second.major_version; | ||
for (const auto& blob : blobs) | ||
{ | ||
cryptonote::transaction tx; | ||
if (!cryptonote::parse_and_validate_tx_from_blob(blob, tx)) | ||
{ | ||
MERROR("tx could not be validated from blob, possibly corrupt blockchain"); | ||
continue; | ||
} | ||
if (tx.type == cryptonote::txtype::state_change) | ||
{ | ||
cryptonote::tx_extra_service_node_state_change state_change; | ||
if (!cryptonote::get_service_node_state_change_from_tx_extra(tx.extra, state_change, hard_fork_version)) | ||
{ | ||
// TODO: This seem to be triggered quite often with hf 11 blocks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably want this log now, just incase, assuming the fix was correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Uncommented and recompiled, the error logs are not printed anymore. |
||
// LOG_ERROR("Could not get state change from tx, possibly corrupt tx, hf_version "<< std::to_string(hard_fork_version)); | ||
continue; | ||
} | ||
|
||
switch(state_change.state) { | ||
case service_nodes::new_state::deregister: | ||
res.total_deregister++; | ||
break; | ||
|
||
case service_nodes::new_state::decommission: | ||
res.total_decommission++; | ||
break; | ||
|
||
case service_nodes::new_state::recommission: | ||
res.total_recommission++; | ||
break; | ||
|
||
case service_nodes::new_state::ip_change_penalty: | ||
res.total_ip_change_penalty++; | ||
break; | ||
|
||
default: | ||
MERROR("Unhandled state in on_get_service_nodes_state_changes"); | ||
break; | ||
} | ||
} | ||
|
||
if (tx.type == cryptonote::txtype::key_image_unlock) | ||
{ | ||
res.total_unlock++; | ||
} | ||
} | ||
} | ||
|
||
res.status = CORE_RPC_STATUS_OK; | ||
return true; | ||
} | ||
|
||
|
||
} // namespace cryptonote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service Node State Changes
End_height here should be -1 if (res.end_height == sentinel) which by default it gets set to the chain height, so the height is the block you are mining for and not a block that already exists in the blockchain.
Otherwise if it's set, you are grabbing the state changes inclusive of the blocks specified so you don't need the -1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed logic to set the end_height to current_height - 1 when the sentinel is set.