Skip to content

Commit

Permalink
Merge #3770
Browse files Browse the repository at this point in the history
3770: [backport] fix(rpc): return the cycles of the first non-cellbase transaction as cellbase's cycles r=quake a=yangby-cryptape

### What problem does this PR solve?

Backport #3763.

### Check List

Tests

- Unit test
- Integration test
- Manual test (add detailed scripts or steps below)
- No code ci-runs-only: [ quick_checks,linters ]

### Release note

```release-note
Title Only: Include only the PR title in the release note.
```

Co-authored-by: Boyu Yang <[email protected]>
  • Loading branch information
bors[bot] and yangby-cryptape authored Dec 22, 2022
2 parents e2276b3 + 78fc4bd commit f37235a
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions rpc/src/module/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,13 +1890,17 @@ impl ChainRpcImpl {
) -> Result<Option<TransactionWithStatus>> {
let snapshot = self.shared.snapshot();
if let Some(tx_info) = snapshot.get_transaction_info(&tx_hash) {
let cycles = snapshot
.get_block_ext(&tx_info.block_hash)
.and_then(|block_ext| {
block_ext
.cycles
.and_then(|v| v.get(tx_info.index.saturating_sub(1)).copied())
});
let cycles = if tx_info.is_cellbase() {
None
} else {
snapshot
.get_block_ext(&tx_info.block_hash)
.and_then(|block_ext| {
block_ext
.cycles
.and_then(|v| v.get(tx_info.index.saturating_sub(1)).copied())
})
};

return Ok(Some(TransactionWithStatus::with_committed(
None,
Expand Down Expand Up @@ -1929,13 +1933,17 @@ impl ChainRpcImpl {
) -> Result<Option<TransactionWithStatus>> {
let snapshot = self.shared.snapshot();
if let Some((tx, tx_info)) = snapshot.get_transaction_with_info(&tx_hash) {
let cycles = snapshot
.get_block_ext(&tx_info.block_hash)
.and_then(|block_ext| {
block_ext
.cycles
.and_then(|v| v.get(tx_info.index.saturating_sub(1)).copied())
});
let cycles = if tx_info.is_cellbase() {
None
} else {
snapshot
.get_block_ext(&tx_info.block_hash)
.and_then(|block_ext| {
block_ext
.cycles
.and_then(|v| v.get(tx_info.index.saturating_sub(1)).copied())
})
};

return Ok(Some(TransactionWithStatus::with_committed(
Some(tx),
Expand Down

0 comments on commit f37235a

Please sign in to comment.