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

Extend transaction structure new fields #4930

Merged
merged 9 commits into from
Feb 1, 2023

Conversation

miiu96
Copy link
Contributor

@miiu96 miiu96 commented Jan 31, 2023

Reasoning behind the pull request

  • Add information about the gas used and the fee of a transaction

Proposed changes

Testing procedure

  • Execute some transactions and check the gasUsed and the fee field if are returned by the transaction endpoint of the node and proxy

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2023

Codecov Report

Base: 70.80% // Head: 70.79% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (602e794) compared to base (aa657cb).
Patch coverage: 84.48% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@              Coverage Diff              @@
##           rc/v1.4.0    #4930      +/-   ##
=============================================
- Coverage      70.80%   70.79%   -0.01%     
=============================================
  Files            648      649       +1     
  Lines          85262    85320      +58     
=============================================
+ Hits           60366    60406      +40     
- Misses         20366    20379      +13     
- Partials        4530     4535       +5     
Impacted Files Coverage Δ
node/external/timemachine/fee/feeComputer.go 67.12% <50.00%> (-5.61%) ⬇️
...external/transactionAPI/apiTransactionProcessor.go 79.36% <100.00%> (+0.15%) ⬆️
.../external/transactionAPI/gasUsedAndFeeProcessor.go 100.00% <100.00%> (ø)
heartbeat/monitor/heartbeatMessage.go 90.00% <0.00%> (-7.50%) ⬇️
consensus/broadcast/delayedBroadcast.go 84.81% <0.00%> (-1.41%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

go.mod Outdated
@@ -14,7 +14,7 @@ require (
github.com/google/gops v0.3.18
github.com/gorilla/websocket v1.5.0
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-core-go v1.1.31
github.com/multiversx/mx-chain-core-go v1.1.32-0.20230131083243-ebccba0c240f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proper tag before merging


hasRefund := false
for _, scr := range tx.SmartContractResults {
if scr.IsRefund {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might refactor:

if !scr.IsRefund {
   continue
}
....
break
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, or even better: split in a new function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored.

)

type gasUsedAndFeeProcessor struct {
txFeeCalculator feeComputer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calculator & Computer ? Let's rename to even-out the naming

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


hasRefund := false
for _, scr := range tx.SmartContractResults {
if scr.IsRefund {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, or even better: split in a new function

}

for _, event := range tx.Logs.Events {
if core.WriteLogIdentifier == event.Identifier && !hasRefund {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split in more functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@@ -56,6 +56,39 @@ func NewFeeComputer(args ArgsNewFeeComputer) (*feeComputer, error) {
return computer, nil
}

// ComputeGasUsedAndFeeBasedOnRefundValue computes gas used and fee based on the refund value, at a given epoch
func (computer *feeComputer) ComputeGasUsedAndFeeBasedOnRefundValue(tx *transaction.ApiTransactionResult, refundValue *big.Int) (uint64, *big.Int) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit tests for the new functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@miiu96 miiu96 self-assigned this Jan 31, 2023
if core.WriteLogIdentifier == event.Identifier && !hasRefund {
gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, big.NewInt(0))
tx.GasUsed = gasUsed
tx.Fee = fee.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing return here?

gabi-vuls
gabi-vuls previously approved these changes Feb 1, 2023
Copy link
Collaborator

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System test passed

@@ -14,7 +14,7 @@ require (
github.com/google/gops v0.3.18
github.com/gorilla/websocket v1.5.0
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-core-go v1.1.32-0.20230131083243-ebccba0c240f
github.com/multiversx/mx-chain-core-go v1.1.32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@iulianpascalau iulianpascalau merged commit a73bd8e into rc/v1.4.0 Feb 1, 2023
@iulianpascalau iulianpascalau deleted the extend-tx-api-route-with-new-fields branch February 1, 2023 11:23
@schimih schimih added type:improvement and removed type:feature New feature or request labels Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants