-
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a334b43
Functions: tracking subscriptions
1af8420
Fixing linter issue
d55b93e
Bugfixing
9d352a7
Merge branch 'develop' into functions/subscriptions-tracking
cdd2a47
Merge branch 'develop' into functions/subscriptions-tracking
4530867
Reworking solution
8206cf1
Merge branch 'develop' into functions/subscriptions-tracking
0ab8ee1
Fixed tests
1c2477a
Fixed linter error
793c2c1
Merge branch 'develop' into functions/subscriptions-tracking
77d953c
Merge branch 'develop' into functions/subscriptions-tracking
c5ae2e5
Addressed PR feedback
fa7eb52
Added minimum balance config
19aadcc
Added subscriptions check to gateway
c54e357
Merge branch 'develop' into functions/subscriptions-tracking
a344936
Using assets.Link
13984f9
Fixed template and naming
a235b39
Reverted renaming
ebed8ee
Merge branch 'develop' into functions/subscriptions-tracking
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/assets" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/api" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/common" | ||
|
@@ -21,31 +22,35 @@ 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 | ||
rateLimiter *hc.RateLimiter | ||
subscriptions functions.OnchainSubscriptions | ||
minBalance assets.Link | ||
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. EDIT: ignore |
||
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, minBalance assets.Link, 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, | ||
minBalance: minBalance, | ||
lggr: lggr.Named("FunctionsConnectorHandler"), | ||
}, nil | ||
} | ||
|
||
|
@@ -68,6 +73,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(h.minBalance.ToInt()) < 0 { | ||
h.lggr.Errorw("user subscription has insufficient balance", "id", gatewayId, "address", fromAddr, "balance", balance, "minBalance", h.minBalance) | ||
return | ||
bolekk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
h.lggr.Debugw("handling gateway request", "id", gatewayId, "method", body.Method) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
outdated