feat(rpc): get block reward by hash#927
Conversation
| match session.async_get_merging_chain_block_info(request.hash).await { | ||
| Ok(Some(info)) => Ok(GetCurrentBlockColorResponse { blue: info.is_blue }), | ||
| Ok(None) | Err(_) => Err(RpcError::MergerNotFound(request.hash)), | ||
| } | ||
| } |
There was a problem hiding this comment.
async_get_merging_chain_block_info intended to replace async_get_current_block_color. I cannot do full cleanup as a small quick pass as the bridge depends on async_get_current_block_color
There was a problem hiding this comment.
What is the bridge using it for? I would only assume it'd need the info to also determine rewards.
There was a problem hiding this comment.
It's used for nearly the same thing: after submitting a block, to track metrics of accepted block. But the logic looks wrong, after submitting it assumes that block is accepted if it's blue (one time check). So it should be revisited, but it's out of scope of the current task.
Used by:
- rkstratum cpu miner (
bridge\src\rkstratum_cpu_miner.rs): - bridge share handler (
bridge\src\share_handler.rs)
| let queried_blue_index = merging_ghostdag.mergeset_blues.iter().position(|hash| *hash == request.hash).ok_or_else(|| { | ||
| RpcError::General(format!( | ||
| "blue block {} was not found in merging chain block {} mergeset blues", | ||
| request.hash, merging_chain_block_hash | ||
| )) | ||
| })?; |
a9242cf to
ddcb3d7
Compare
ddcb3d7 to
485dd86
Compare
| .checked_add(own_red_reward_output.value) | ||
| .ok_or_else(|| RpcError::General("total reward amount overflowed u64 while adding own red reward".to_string()))?; |
There was a problem hiding this comment.
tempted to simply add
There was a problem hiding this comment.
it should never happen, or there is a reward bug, right?
| .ok_or_else(|| { | ||
| RpcError::General(format!( | ||
| "missing reward output {} in merging chain block {}", | ||
| queried_blue_index, merging_chain_block_hash | ||
| )) | ||
| })? |
There was a problem hiding this comment.
tempted to assume unreachable
| .checked_add(own_red_reward_output.value) | ||
| .ok_or_else(|| RpcError::General("total reward amount overflowed u64 while adding own red reward".to_string()))?; |
|
|
||
| kaspa.initConsolePanicHook(); | ||
|
|
||
| const BLOCK_HASH = |
There was a problem hiding this comment.
Wouldn't this be pruned?
There was a problem hiding this comment.
Yes, but on the other hand, there is no interest (?) into listening for live rewards, i assume an executor of this script will want to put a hash parameter here.
Alternatively, the script could take argument from argv
| match session.async_get_merging_chain_block_info(request.hash).await { | ||
| Ok(Some(info)) => Ok(GetCurrentBlockColorResponse { blue: info.is_blue }), | ||
| Ok(None) | Err(_) => Err(RpcError::MergerNotFound(request.hash)), | ||
| } | ||
| } |
There was a problem hiding this comment.
What is the bridge using it for? I would only assume it'd need the info to also determine rewards.
| let queried_ghostdag = session.async_get_ghostdag_data(request.hash).await?; | ||
| let queried_coinbase = &queried_block.transactions[COINBASE_TRANSACTION_INDEX]; | ||
|
|
||
| // only a chain block has its own red-reward coinbase output, as an exrta output |
There was a problem hiding this comment.
typo: exrta -> extra
|
|
||
| for child in self.get_block_children(hash).unwrap() { | ||
| if visited.insert(child) { | ||
| let blue_work = self.ghostdag_store.get_blue_work(child).unwrap(); |
There was a problem hiding this comment.
better to get the value blue work value from header store
| } | ||
| } | ||
|
|
||
| while let Some(Reverse(SortableBlock { hash: decedent, .. })) = heap.pop() { |
There was a problem hiding this comment.
decedent -> descendant
|
|
||
| for child in self.get_block_children(decedent).unwrap() { | ||
| if visited.insert(child) { | ||
| let blue_work = self.ghostdag_store.get_blue_work(child).unwrap(); |
There was a problem hiding this comment.
use header store to get blue work here
|
|
||
| /// If block hash doesn't exist, returns Err | ||
| /// | ||
| /// For a given block hash, try to find its `MergingBlockContext` |
There was a problem hiding this comment.
This needs to be explained further. What is a MergingBlockContext? Add that documentation here.
Given a block hash, returns its reward information.
Behaviors:
bhas not been merged (orphan), color will be unknownbhas been merged and is part of the red mergeset, color is redbhas been merged and is of the blue mergeset, get total paid reward (subsidy + collected fees)bis a chain block / merging block, get red rewardsUser persona: pool / bridge / solo miner
This is intended to replace complex systems (often inefficient) built on top of current RPC endpoints, specifically:
GetBlocks.Input:
Output:
Example usage in Rust:
Example usage in WASM: