-
Notifications
You must be signed in to change notification settings - Fork 996
feat(state/core_accessor): add fee estimator #4087
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"github.com/celestiaorg/go-header/sync" | ||
|
||
"github.com/celestiaorg/celestia-node/header" | ||
"github.com/celestiaorg/celestia-node/nodebuilder/core" | ||
modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud" | ||
"github.com/celestiaorg/celestia-node/nodebuilder/p2p" | ||
"github.com/celestiaorg/celestia-node/share/eds/byzantine" | ||
|
@@ -23,13 +24,14 @@ func coreAccessor( | |
fraudServ libfraud.Service[*header.ExtendedHeader], | ||
network p2p.Network, | ||
client *grpc.ClientConn, | ||
address core.EstimatorAddress, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are using core.EstimatorAddress only from the core config:
|
||
) ( | ||
*state.CoreAccessor, | ||
Module, | ||
*modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader], | ||
error, | ||
) { | ||
ca, err := state.NewCoreAccessor(keyring, string(keyname), sync, client, network.String()) | ||
ca, err := state.NewCoreAccessor(keyring, string(keyname), sync, client, network.String(), string(address)) | ||
|
||
sBreaker := &modfraud.ServiceBreaker[*state.CoreAccessor, *header.ExtendedHeader]{ | ||
Service: ca, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,8 +36,7 @@ const ( | |
|
||
var ( | ||
ErrInvalidAmount = errors.New("state: amount must be greater than zero") | ||
|
||
log = logging.Logger("state") | ||
log = logging.Logger("state") | ||
) | ||
|
||
// CoreAccessor implements service over a gRPC connection | ||
|
@@ -63,6 +62,7 @@ type CoreAccessor struct { | |
coreConn *grpc.ClientConn | ||
network string | ||
|
||
estimator *estimator | ||
// these fields are mutatable and thus need to be protected by a mutex | ||
lock sync.Mutex | ||
lastPayForBlob int64 | ||
|
@@ -83,6 +83,7 @@ func NewCoreAccessor( | |
getter libhead.Head[*header.ExtendedHeader], | ||
conn *grpc.ClientConn, | ||
network string, | ||
estimatorAddress string, | ||
) (*CoreAccessor, error) { | ||
// create verifier | ||
prt := merkle.DefaultProofRuntime() | ||
|
@@ -106,6 +107,7 @@ func NewCoreAccessor( | |
prt: prt, | ||
coreConn: conn, | ||
network: network, | ||
estimator: &estimator{estimatorAddress: estimatorAddress, defaultClientConn: conn}, | ||
} | ||
return ca, nil | ||
} | ||
|
@@ -136,12 +138,17 @@ func (ca *CoreAccessor) Start(ctx context.Context) error { | |
if err != nil { | ||
return fmt.Errorf("querying minimum gas price: %w", err) | ||
} | ||
|
||
err = ca.estimator.Start(ctx) | ||
if err != nil { | ||
log.Warn("state: failed to connect to estimator endpoint", "err", err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should actually return an error here bc the only time err is returned from estimator.Start is if grpc conn fails to be created which is an actual err. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
return nil | ||
} | ||
|
||
func (ca *CoreAccessor) Stop(context.Context) error { | ||
func (ca *CoreAccessor) Stop(ctx context.Context) error { | ||
ca.cancel() | ||
return nil | ||
return ca.estimator.Stop(ctx) | ||
} | ||
|
||
// SubmitPayForBlob builds, signs, and synchronously submits a MsgPayForBlob with additional | ||
|
@@ -176,7 +183,7 @@ func (ca *CoreAccessor) SubmitPayForBlob( | |
for i, blob := range libBlobs { | ||
blobSizes[i] = uint32(len(blob.Data())) | ||
} | ||
gas = estimateGasForBlobs(blobSizes) | ||
gas = ca.estimator.estimateGasForBlobs(blobSizes) | ||
} | ||
|
||
gasPrice := cfg.GasPrice() | ||
|
@@ -574,22 +581,6 @@ func (ca *CoreAccessor) submitMsg( | |
} | ||
|
||
txConfig := make([]user.TxOption, 0) | ||
gas := cfg.GasLimit() | ||
|
||
if gas == 0 { | ||
gas, err = estimateGas(ctx, client, msg) | ||
if err != nil { | ||
return nil, fmt.Errorf("estimating gas: %w", err) | ||
} | ||
} | ||
|
||
gasPrice := cfg.GasPrice() | ||
if gasPrice == DefaultGasPrice { | ||
gasPrice = ca.minGasPrice | ||
} | ||
|
||
txConfig = append(txConfig, user.SetGasLimitAndGasPrice(gas, gasPrice)) | ||
|
||
if cfg.FeeGranterAddress() != "" { | ||
granter, err := parseAccAddressFromString(cfg.FeeGranterAddress()) | ||
if err != nil { | ||
|
@@ -598,7 +589,20 @@ func (ca *CoreAccessor) submitMsg( | |
txConfig = append(txConfig, user.SetFeeGranter(granter)) | ||
} | ||
|
||
gasPrice, gas, err := ca.estimator.estimate(ctx, cfg, client, msg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if gasPrice < ca.getMinGasPrice() { | ||
gasPrice = ca.getMinGasPrice() | ||
} | ||
txConfig = append(txConfig, user.SetGasLimitAndGasPrice(gas, gasPrice)) | ||
|
||
resp, err := client.SubmitTx(ctx, []sdktypes.Msg{msg}, txConfig...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return convertToSdkTxResponse(resp), err | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]