Skip to content

Commit

Permalink
Fix off-by-one error in confirmations
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Feb 5, 2023
1 parent 11e50f8 commit 42baa54
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion zebra-rpc/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,9 @@ where
})?;

match response {
zebra_state::ReadResponse::Depth(Some(depth)) => Some(depth.into()),
// Confirmations are one more than the depth.
// Depth is limited by height, so it will never overflow an i64.
zebra_state::ReadResponse::Depth(Some(depth)) => Some(i64::from(depth) + 1),
zebra_state::ReadResponse::Depth(None) => {
Some(NOT_IN_BEST_CHAIN_CONFIRMATIONS)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: block
---
{
"hash": "0007bc227e1c57a4a70e237cad00e7b7ce565155ab49166bc57397a26d339283",
"confirmations": 9,
"confirmations": 10,
"tx": [
"851bf6fbf7a976327817c738c489d7fa657752445430922d94c983c0b9ed4609"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: block
---
{
"hash": "025579869bcf52a989337342f5f57a84f3a28b968f7d6a8307902b065a668d23",
"confirmations": 9,
"confirmations": 10,
"tx": [
"f37e9f691fffb635de0999491d906ee85ba40cd36dae9f6e5911a8277d7c5f75"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: block
---
{
"hash": "0007bc227e1c57a4a70e237cad00e7b7ce565155ab49166bc57397a26d339283",
"confirmations": 9,
"confirmations": 10,
"tx": [
"851bf6fbf7a976327817c738c489d7fa657752445430922d94c983c0b9ed4609"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: block
---
{
"hash": "025579869bcf52a989337342f5f57a84f3a28b968f7d6a8307902b065a668d23",
"confirmations": 9,
"confirmations": 10,
"tx": [
"f37e9f691fffb635de0999491d906ee85ba40cd36dae9f6e5911a8277d7c5f75"
]
Expand Down
4 changes: 2 additions & 2 deletions zebra-rpc/src/methods/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async fn rpc_getblock() {
get_block,
GetBlock::Object {
hash: Some(GetBlockHash(block.hash())),
confirmations: Some((blocks.len() - i - 1).try_into().expect("valid i64")),
confirmations: Some((blocks.len() - i).try_into().expect("valid i64")),
height: None,
tx: block
.transactions
Expand Down Expand Up @@ -195,7 +195,7 @@ async fn rpc_getblock() {
get_block,
GetBlock::Object {
hash: Some(GetBlockHash(block.hash())),
confirmations: Some((blocks.len() - i - 1).try_into().expect("valid i64")),
confirmations: Some((blocks.len() - i).try_into().expect("valid i64")),
height: None,
tx: block
.transactions
Expand Down

0 comments on commit 42baa54

Please sign in to comment.