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

feat(state/core_accessor): add fee estimator #4087

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vgonkivs
Copy link
Member

@vgonkivs vgonkivs commented Feb 4, 2025

This PR enables third-party estimation for the submit transactions in the node(besides PFB). By default, fee estimation relies on the consensus node to which the node is connected. But the user can now provide a non-default endpoint, so the node will query gas price and gas from it. It can be provided via cli(using "core.estimator.address"). The address will be added to the node's config as FeeEstimatorAddress.
Additionally, the user can now provide a maxGasPrice for every submit tx(via max.gas.price flag)- the max price that the user is willing to pay for the transaction. The transaction will not be submitted in case when estimated gas price exceeds the maxGasPrice(default: minGasPrice*100)

@vgonkivs vgonkivs added area:state Related to fetching state and state execution kind:feat Attached to feature PRs labels Feb 4, 2025
@vgonkivs vgonkivs self-assigned this Feb 4, 2025
@vgonkivs vgonkivs force-pushed the fee_estimator branch 2 times, most recently from 90f851c to 7c01a6f Compare February 4, 2025 15:07
@codecov-commenter
Copy link

codecov-commenter commented Feb 13, 2025

Codecov Report

Attention: Patch coverage is 66.89189% with 49 lines in your changes missing coverage. Please review.

Project coverage is 45.14%. Comparing base (2469e7a) to head (6fc589d).
Report is 450 commits behind head on main.

Files with missing lines Patch % Lines
state/estimator.go 54.16% 17 Missing and 5 partials ⚠️
state/tx_config.go 51.61% 15 Missing ⚠️
state/core_access.go 76.00% 4 Missing and 2 partials ⚠️
nodebuilder/core/flags.go 66.66% 3 Missing and 1 partial ⚠️
nodebuilder/state/cmd/state.go 90.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4087      +/-   ##
==========================================
+ Coverage   44.83%   45.14%   +0.30%     
==========================================
  Files         265      309      +44     
  Lines       14620    22660    +8040     
==========================================
+ Hits         6555    10229    +3674     
- Misses       7313    11337    +4024     
- Partials      752     1094     +342     

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

@vgonkivs vgonkivs marked this pull request as ready for review February 13, 2025 16:06
Copy link
Member

@renaynay renaynay left a comment

Choose a reason for hiding this comment

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

The biggest comment rn is just that core_access is super messy 😭 Quite hard to read. Is there anything that can be done to make the code more readable?

func SanitizeAddr(addr string) (string, error) {
original := addr
// NormalizeAddress extracts the host and port, removing unsupported schemes.
func NormalizeAddress(addr string) string {
Copy link
Member

Choose a reason for hiding this comment

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

why does SanitizeAddr not work for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

it additionally cuts the port.
addr = strings.Split(addr, ":")[0]

@@ -23,13 +24,14 @@ func coreAccessor(
fraudServ libfraud.Service[*header.ExtendedHeader],
network p2p.Network,
client *grpc.ClientConn,
address core.EstimatorAddress,
Copy link
Member

Choose a reason for hiding this comment

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

can't you just grab the core cfg there and take from cfg directly instead of supplying individual value to fx?


log = logging.Logger("state")
ErrInvalidAmount = errors.New("state: amount must be greater than zero")
errGasPriceExceedsLimit = errors.New("state: estimated gasPrice exceeds max gasPrice")
Copy link
Member

Choose a reason for hiding this comment

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

why unexported?

Comment on lines +77 to +92
if e.estimatorConn != nil && e.estimatorConn.GetState() != connectivity.Shutdown {
gasPrice, gas, err := signer.QueryGasUsedAndPrice(ctx, e.estimatorConn, priority.toApp(), rawTx)
if err == nil {
return gasPrice, gas, nil
}
log.Warn("failed to query gas used and price from the estimator endpoint.", "err", err)
}

if e.defaultClientConn == nil || e.defaultClientConn.GetState() == connectivity.Shutdown {
return 0, 0, errors.New("connection with the consensus node is dropped")
}

gasPrice, gas, err := signer.QueryGasUsedAndPrice(ctx, e.defaultClientConn, priority.toApp(), rawTx)
if err != nil {
log.Warn("state: failed to query gas used and price from the default endpoint", "err", err)
}
Copy link
Member

Choose a reason for hiding this comment

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

you can unify these to clean it up and just determine which conn to used based on if estimator conn exists.

What err will be returned if you pass a conn where connectivity shutdown to the signer.QueryGasUsedAndPrice? If it's readable (conn is closed) then we cna just return that unwrapped

@@ -136,6 +139,7 @@ func (ca *CoreAccessor) Start(ctx context.Context) error {
if err != nil {
return fmt.Errorf("querying minimum gas price: %w", err)
}
ca.estimator.connect()
Copy link
Member

Choose a reason for hiding this comment

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

Start function could use some cleanup (better organisation w.r.t spacing + order)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:state Related to fetching state and state execution kind:feat Attached to feature PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants