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

Fix /transaction/cost api route #5880

Merged
merged 7 commits into from
Feb 16, 2024
Merged

Conversation

miiu96
Copy link
Contributor

@miiu96 miiu96 commented Jan 26, 2024

Reasoning behind the pull request

Proposed changes

  • Set CurrentHeader in the BlockChainHook used for transaction cost computation.

Testing procedure

  • Run a node on devnet on shard 1 with this branch and ensure the cost is computed correctly for the example from the mx-chain-proxy-go GitHub issue

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?

@miiu96 miiu96 self-assigned this Jan 26, 2024
Copy link

codecov bot commented Jan 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3a90de9) 79.95% compared to head (e097862) 79.96%.
Report is 1 commits behind head on rc/v1.7.0.

Additional details and impacted files
@@            Coverage Diff             @@
##           rc/v1.7.0    #5880   +/-   ##
==========================================
  Coverage      79.95%   79.96%           
==========================================
  Files            731      731           
  Lines          96312    96329   +17     
==========================================
+ Hits           77006    77028   +22     
+ Misses         13918    13912    -6     
- Partials        5388     5389    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

sstanculeanu
sstanculeanu previously approved these changes Jan 29, 2024
@iulianpascalau iulianpascalau self-requested a review February 8, 2024 15:27
@@ -91,7 +98,9 @@ func (ate *apiTransactionEvaluator) SimulateTransactionExecution(tx *transaction
ate.mutExecution.Unlock()
}()

return ate.txSimulator.ProcessTx(tx)
currentHeader := ate.blockChain.GetCurrentBlockHeader()
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to treat the situation when the currentHeader is nil and take the genesis block. Otherwise the simulation won't work on the exact first block after the genesis :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -140,8 +149,9 @@ func (ate *apiTransactionEvaluator) simulateTransactionCost(tx *transaction.Tran
}

costResponse := &transaction.CostResponse{}
currentHeader := ate.blockChain.GetCurrentBlockHeader()
Copy link
Contributor

Choose a reason for hiding this comment

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

also here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -407,3 +407,23 @@ func TestApiTransactionEvaluator_ComputeTransactionGasLimit(t *testing.T) {
require.Nil(t, err)
require.True(t, called)
}

func TestApiTransactionEvaluator_GetCurrentHeader(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@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.

Normal allin test: v1.6.15-dev-config-eb2e06c06d -> fix-tx-cost-api-route-rc-98d49f4624

--- Specific errors ---

block hash does not match 1296
wrong nonce in block 650
miniblocks does not match 0
num miniblocks does not match 0
miniblock hash does not match 0
block bodies does not match 0
receipts hash missmatch 0

/------/

--- Statistics ---

Nr. of all ERRORS: 1
Nr. of all WARNS: 350
Nr. of new ERRORS: 1
Nr. of new WARNS: 2
Nr. of PANICS: 0

/------/

--- ERRORS ---

/------/

@iulianpascalau iulianpascalau merged commit 71c9b7f into rc/v1.7.0 Feb 16, 2024
8 checks passed
@iulianpascalau iulianpascalau deleted the fix-tx-cost-api-route-rc branch February 16, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants