Skip to content
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

fix: get genesis block proposal may panic #1554

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions core/api/src/jsonrpc/impl/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,20 @@ impl<Adapter: APIAdapter + 'static> AxonRpcServer for AxonRpcImpl<Adapter> {
}

async fn get_proposal_by_number(&self, block_number: U256) -> RpcResult<Proposal> {
let block_number = block_number.as_u64();
let prev_block = self
.adapter
.get_block_by_number(Context::new(), Some(block_number - 1))
.await
.map_err(|e| RpcError::Internal(e.to_string()))?
.ok_or_else(|| RpcError::Internal("prev block not found".to_string()))?;
let block_number = block_number.low_u64();
yangby-cryptape marked this conversation as resolved.
Show resolved Hide resolved

let prev_state_root = if block_number == 0 {
H256::default()
} else {
self.adapter
.get_block_by_number(Context::new(), Some(block_number - 1))
.await
.map_err(|e| RpcError::Internal(e.to_string()))?
.ok_or_else(|| RpcError::Internal("prev block not found".to_string()))?
.header
.state_root
};

let block = self
.adapter
.get_block_by_number(Context::new(), Some(block_number))
Expand All @@ -76,7 +83,7 @@ impl<Adapter: APIAdapter + 'static> AxonRpcServer for AxonRpcImpl<Adapter> {

Ok(Proposal::new_with_state_root(
&block.header,
prev_block.header.state_root,
prev_state_root,
block.tx_hashes,
))
}
Expand Down
Loading