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

added fee in elastic search transactions #2658

Merged
merged 16 commits into from Jan 8, 2021
Merged

Conversation

miiu96
Copy link
Contributor

@miiu96 miiu96 commented Jan 7, 2021

Added fee in transaction that is indexed in elasticsearch database.
Added gasPriceModifer in the api route /network/config

@miiu96 miiu96 self-assigned this Jan 7, 2021
@miiu96 miiu96 changed the title added fee in elastic search transactions [WIP] added fee in elastic search transactions Jan 7, 2021
@miiu96 miiu96 requested a review from sasurobert January 7, 2021 20:56

func (ed *economicsData) computeGasRefund(refundValue *big.Int, gasPrice uint64) uint64 {
gasPriceBig := big.NewInt(0).SetUint64(gasPrice)

Copy link
Contributor

Choose a reason for hiding this comment

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

delete empty line

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.

gasPriceBig := big.NewInt(0).SetUint64(gasPrice)

gasRefund := big.NewInt(0).Div(refundValue, gasPriceBig).Uint64()

Copy link
Contributor

Choose a reason for hiding this comment

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

delete empty line

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.

return true
}
}

return false
}

func isRelayedTx(tx *Transaction) bool {
if strings.HasPrefix(string(tx.Data), "relayedTx") && len(tx.SmartContractResults) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use one line here: return strings.HasPrefix(string(tx.Data), "relayedTx") && len(tx.SmartContractResults) > 0

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.

@@ -159,8 +159,8 @@ func checkDataIndexerParams(arguments *ArgsIndexerFactory) error {
if check.IfNil(arguments.EpochStartNotifier) {
return core.ErrNilEpochStartNotifier
}
if arguments.FeeConfig == nil {
return core.ErrNilFeeConfig
if arguments.TransactionFeeCalculator == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

check.IfNil

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.

if isRelayedTx(tx) {
tx.GasUsed = tx.GasLimit
fee := tdp.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, tx.GasUsed)
transactions[hash].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.

tx instead transactions[hash]

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.

continue
}

transactions[hash].Status = transaction.TxStatusFail.String()
tx.Status = transaction.TxStatusFail.String()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove lines 113-118 and just add this line inside -> if !isRelayedTx(tx), and this way you remove the duplicated code 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.

done.

}

gasRefund := ed.computeGasRefund(refundValue, tx.GetGasPrice())
gasUsed := tx.GetGasLimit() - gasRefund
Copy link
Contributor

Choose a reason for hiding this comment

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

Use safeSub with log

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.


gasRefund := big.NewInt(0).Div(refundValue, gasPriceBig).Uint64()

gasRefund = uint64(ed.GasPriceModifier() * float64(gasRefund))
Copy link
Contributor

Choose a reason for hiding this comment

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

So we will assume that any refunded value would have been used with gas price modifier applied @sasurobert

Copy link
Contributor

Choose a reason for hiding this comment

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

ed.GasPriceModifier return 1.0 when it is disabled

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I know, but I have referred here to all the situations after the flag activation.


gasRefund := big.NewInt(0).Div(refundValue, gasPriceBig).Uint64()

gasRefund = uint64(ed.GasPriceModifier() * float64(gasRefund))
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I know, but I have referred here to all the situations after the flag activation.

Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

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

System tests passed

@LucianMincu LucianMincu merged commit be8136c into development Jan 8, 2021
@LucianMincu LucianMincu deleted the add-fee-in-txs-es branch January 8, 2021 11:30
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.

None yet

4 participants