-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Functions: tracking subscriptions #10613
Changes from 11 commits
a334b43
1af8420
d55b93e
9d352a7
cdd2a47
4530867
8206cf1
0ab8ee1
1c2477a
793c2c1
77d953c
c5ae2e5
fa7eb52
19aadcc
c54e357
a344936
13984f9
a235b39
ebed8ee
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"crypto/ecdsa" | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/api" | ||
|
@@ -21,31 +22,33 @@ import ( | |
type functionsConnectorHandler struct { | ||
utils.StartStopOnce | ||
|
||
connector connector.GatewayConnector | ||
signerKey *ecdsa.PrivateKey | ||
nodeAddress string | ||
storage s4.Storage | ||
allowlist functions.OnchainAllowlist | ||
rateLimiter *hc.RateLimiter | ||
lggr logger.Logger | ||
connector connector.GatewayConnector | ||
signerKey *ecdsa.PrivateKey | ||
nodeAddress string | ||
storage s4.Storage | ||
allowlist functions.OnchainAllowlist | ||
subscriptions functions.OnchainSubscriptions | ||
rateLimiter *hc.RateLimiter | ||
lggr logger.Logger | ||
} | ||
|
||
var ( | ||
_ connector.Signer = &functionsConnectorHandler{} | ||
_ connector.GatewayConnectorHandler = &functionsConnectorHandler{} | ||
) | ||
|
||
func NewFunctionsConnectorHandler(nodeAddress string, signerKey *ecdsa.PrivateKey, storage s4.Storage, allowlist functions.OnchainAllowlist, rateLimiter *hc.RateLimiter, lggr logger.Logger) (*functionsConnectorHandler, error) { | ||
if signerKey == nil || storage == nil || allowlist == nil || rateLimiter == nil { | ||
return nil, fmt.Errorf("signerKey, storage, allowlist and rateLimiter must be non-nil") | ||
func NewFunctionsConnectorHandler(nodeAddress string, signerKey *ecdsa.PrivateKey, storage s4.Storage, allowlist functions.OnchainAllowlist, rateLimiter *hc.RateLimiter, subscriptions functions.OnchainSubscriptions, lggr logger.Logger) (*functionsConnectorHandler, error) { | ||
if signerKey == nil || storage == nil || allowlist == nil || rateLimiter == nil || subscriptions == nil { | ||
return nil, fmt.Errorf("signerKey, storage, allowlist, rateLimiter and subscriptions must be non-nil") | ||
} | ||
return &functionsConnectorHandler{ | ||
nodeAddress: nodeAddress, | ||
signerKey: signerKey, | ||
storage: storage, | ||
allowlist: allowlist, | ||
rateLimiter: rateLimiter, | ||
lggr: lggr.Named("FunctionsConnectorHandler"), | ||
nodeAddress: nodeAddress, | ||
signerKey: signerKey, | ||
storage: storage, | ||
allowlist: allowlist, | ||
rateLimiter: rateLimiter, | ||
subscriptions: subscriptions, | ||
lggr: lggr.Named("FunctionsConnectorHandler"), | ||
}, nil | ||
} | ||
|
||
|
@@ -68,6 +71,10 @@ func (h *functionsConnectorHandler) HandleGatewayMessage(ctx context.Context, ga | |
h.lggr.Errorw("request rate-limited", "id", gatewayId, "address", fromAddr) | ||
return | ||
} | ||
if balance, err := h.subscriptions.GetMaxUserBalance(fromAddr); err != nil || balance.Cmp(big.NewInt(0)) == 0 { | ||
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 want to check against a configured minimum balance, not 0. 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 |
||
h.lggr.Errorw("request is not backed with a funded subscription", "id", gatewayId, "address", fromAddr) | ||
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. Also log user balance and min required balance. |
||
return | ||
bolekk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
h.lggr.Debugw("handling gateway request", "id", gatewayId, "method", body.Method) | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Planning to also add to the Gateway handler?
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.
Do you think it needs to be enabled in GW handler too?
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.
I don't think it's a must. But it should be very easy to add there as optional and the more bad requests we can stop in Gateway, the less unnecessary load we put on the nodes.