Skip to content

Commit

Permalink
Fix for consumed_gas calculation after Kathmandu upgrade (#618)
Browse files Browse the repository at this point in the history
* Fix for consumed_gas calculation after Kathmandu upgrade
* Fix lint and tests
* Contributor: AndrewKishino, Effort=1h
* Reviewer: jdsika, Effort=0.5h
  • Loading branch information
AndrewKishino authored Sep 25, 2022
1 parent b9cc98d commit e1c5e4e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/pay/batch_payer.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,17 @@ def simulate_single_operation(self, payment_item, pymnt_amnt, branch, chain_id):
if status == "applied":

# Calculate actual consumed gas amount
consumed_gas = int(op["metadata"]["operation_result"]["consumed_gas"])
consumed_gas = math.ceil(
int(op["metadata"]["operation_result"]["consumed_milligas"]) / 1000
)
if "internal_operation_results" in op["metadata"]:
internal_operation_results = op["metadata"][
"internal_operation_results"
]
for internal_op in internal_operation_results:
consumed_gas += int(internal_op["result"]["consumed_gas"])
consumed_gas += math.ceil(
int(internal_op["result"]["consumed_milligas"]) / 1000
)

# Calculate actual used storage
if "paid_storage_size_diff" in op["metadata"]["operation_result"]:
Expand Down
6 changes: 4 additions & 2 deletions tests/regression/test_attempt_single_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
"metadata": {
"operation_result": {
"status": "applied",
"consumed_gas": "100",
"consumed_milligas": "100000",
"paid_storage_size_diff": "24",
},
"internal_operation_results": [{"result": {"consumed_gas": "40"}}],
"internal_operation_results": [
{"result": {"consumed_milligas": "40000"}}
],
}
}
]
Expand Down
6 changes: 4 additions & 2 deletions tests/regression/test_simulate_single_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
"metadata": {
"operation_result": {
"status": "applied",
"consumed_gas": "100",
"consumed_milligas": "100000",
"paid_storage_size_diff": "24",
},
"internal_operation_results": [{"result": {"consumed_gas": "50"}}],
"internal_operation_results": [
{"result": {"consumed_milligas": "50000"}}
],
}
}
]
Expand Down

0 comments on commit e1c5e4e

Please sign in to comment.