Browse Source

rpc: Add `TotalGasUsed` to `block_results` response (#6615)

Closes #6551 

Simple PR to add the total gas used in the block by adding the gas used in all the transactions. 
This adds a `TotalGasUsed` field to `coretypes.ResultBlockResults`.

Its my first PR to the repo so let me know if there is anything I am missing!

@fedekunze In case you want to take a look
pull/6609/head
crypto-facs 3 years ago
committed by GitHub
parent
commit
10d174adcc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 4 deletions
  1. +2
    -1
      CHANGELOG_PENDING.md
  2. +6
    -0
      rpc/core/blocks.go
  3. +4
    -3
      rpc/core/blocks_test.go
  4. +1
    -0
      rpc/core/types/responses.go
  5. +3
    -0
      rpc/openapi/openapi.yaml

+ 2
- 1
CHANGELOG_PENDING.md View File

@ -126,6 +126,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
- [p2p/pex] \#6509 Improve addrBook.hash performance (@cuonglm) - [p2p/pex] \#6509 Improve addrBook.hash performance (@cuonglm)
- [consensus/metrics] \#6549 Change block_size gauge to a histogram for better observability over time (@marbar3778) - [consensus/metrics] \#6549 Change block_size gauge to a histogram for better observability over time (@marbar3778)
- [statesync] \#6587 Increase chunk priority and re-request chunks that don't arrive (@cmwaters) - [statesync] \#6587 Increase chunk priority and re-request chunks that don't arrive (@cmwaters)
- [rpc] \#6615 Add TotalGasUsed to block_results response (@crypto-facs)
### BUG FIXES ### BUG FIXES
@ -134,5 +135,5 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
- [blockchain/v1] \#5711 Fix deadlock (@melekes) - [blockchain/v1] \#5711 Fix deadlock (@melekes)
- [evidence] \#6375 Fix bug with inconsistent LightClientAttackEvidence hashing (cmwaters) - [evidence] \#6375 Fix bug with inconsistent LightClientAttackEvidence hashing (cmwaters)
- [rpc] \#6507 fix RPC client doesn't handle url's without ports (@JayT106) - [rpc] \#6507 fix RPC client doesn't handle url's without ports (@JayT106)
- [statesync] \#6463 Adds Reverse Sync feature to fetch historical light blocks after state sync in order to verify any evidence (@cmwaters)
- [statesync] \#6463 Adds Reverse Sync feature to fetch historical light blocks after state sync in order to verify any evidence (@cmwaters)
- [fastsync] \#6590 Update the metrics during fast-sync (@JayT106) - [fastsync] \#6590 Update the metrics during fast-sync (@JayT106)

+ 6
- 0
rpc/core/blocks.go View File

@ -161,9 +161,15 @@ func (env *Environment) BlockResults(ctx *rpctypes.Context, heightPtr *int64) (*
return nil, err return nil, err
} }
var totalGasUsed int64
for _, tx := range results.GetDeliverTxs() {
totalGasUsed += tx.GetGasUsed()
}
return &ctypes.ResultBlockResults{ return &ctypes.ResultBlockResults{
Height: height, Height: height,
TxsResults: results.DeliverTxs, TxsResults: results.DeliverTxs,
TotalGasUsed: totalGasUsed,
BeginBlockEvents: results.BeginBlock.Events, BeginBlockEvents: results.BeginBlock.Events,
EndBlockEvents: results.EndBlock.Events, EndBlockEvents: results.EndBlock.Events,
ValidatorUpdates: results.EndBlock.ValidatorUpdates, ValidatorUpdates: results.EndBlock.ValidatorUpdates,


+ 4
- 3
rpc/core/blocks_test.go View File

@ -72,9 +72,9 @@ func TestBlockchainInfo(t *testing.T) {
func TestBlockResults(t *testing.T) { func TestBlockResults(t *testing.T) {
results := &tmstate.ABCIResponses{ results := &tmstate.ABCIResponses{
DeliverTxs: []*abci.ResponseDeliverTx{ DeliverTxs: []*abci.ResponseDeliverTx{
{Code: 0, Data: []byte{0x01}, Log: "ok"},
{Code: 0, Data: []byte{0x02}, Log: "ok"},
{Code: 1, Log: "not ok"},
{Code: 0, Data: []byte{0x01}, Log: "ok", GasUsed: 10},
{Code: 0, Data: []byte{0x02}, Log: "ok", GasUsed: 5},
{Code: 1, Log: "not ok", GasUsed: 0},
}, },
EndBlock: &abci.ResponseEndBlock{}, EndBlock: &abci.ResponseEndBlock{},
BeginBlock: &abci.ResponseBeginBlock{}, BeginBlock: &abci.ResponseBeginBlock{},
@ -97,6 +97,7 @@ func TestBlockResults(t *testing.T) {
{100, false, &ctypes.ResultBlockResults{ {100, false, &ctypes.ResultBlockResults{
Height: 100, Height: 100,
TxsResults: results.DeliverTxs, TxsResults: results.DeliverTxs,
TotalGasUsed: 15,
BeginBlockEvents: results.BeginBlock.Events, BeginBlockEvents: results.BeginBlock.Events,
EndBlockEvents: results.EndBlock.Events, EndBlockEvents: results.EndBlock.Events,
ValidatorUpdates: results.EndBlock.ValidatorUpdates, ValidatorUpdates: results.EndBlock.ValidatorUpdates,


+ 1
- 0
rpc/core/types/responses.go View File

@ -62,6 +62,7 @@ type ResultCommit struct {
type ResultBlockResults struct { type ResultBlockResults struct {
Height int64 `json:"height"` Height int64 `json:"height"`
TxsResults []*abci.ResponseDeliverTx `json:"txs_results"` TxsResults []*abci.ResponseDeliverTx `json:"txs_results"`
TotalGasUsed int64 `json:"total_gas_used"`
BeginBlockEvents []abci.Event `json:"begin_block_events"` BeginBlockEvents []abci.Event `json:"begin_block_events"`
EndBlockEvents []abci.Event `json:"end_block_events"` EndBlockEvents []abci.Event `json:"end_block_events"`
ValidatorUpdates []abci.ValidatorUpdate `json:"validator_updates"` ValidatorUpdates []abci.ValidatorUpdate `json:"validator_updates"`


+ 3
- 0
rpc/openapi/openapi.yaml View File

@ -1666,6 +1666,9 @@ components:
codespace: codespace:
type: string type: string
example: "ibc" example: "ibc"
total_gas_used:
type: string
example: "100"
begin_block_events: begin_block_events:
type: array type: array
nullable: true nullable: true


Loading…
Cancel
Save