-
Notifications
You must be signed in to change notification settings - Fork 32
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
Offchain usdc #112
Offchain usdc #112
Changes from 24 commits
f478a01
7a883b7
5468713
1a7b5a9
1577e56
2ac5879
8c2250f
0f2e9eb
bb5b50e
f738579
a523911
256c29f
68a70d5
addbdbb
b7f2f81
0ef66b3
239b7ca
8029d4c
6e31124
0e80c67
7be78f6
142a6d1
50a59b2
acfeef5
d00da8c
e4f6b07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -489,6 +489,22 @@ func (o *ORM) SelectIndexedLogsByBlockRangeFilter(start, end int64, address comm | |
return logs, nil | ||
} | ||
|
||
func (o *ORM) SelectIndexedLogsByTxHash(eventSig common.Hash, txHash common.Hash, qopts ...pg.QOpt) ([]Log, error) { | ||
q := o.q.WithOpts(qopts...) | ||
var logs []Log | ||
err := q.Select(&logs, ` | ||
SELECT * FROM evm.logs | ||
WHERE evm.logs.evm_chain_id = $1 | ||
AND tx_hash = $2 | ||
AND event_sig = $3 | ||
ORDER BY (evm.logs.block_number, evm.logs.log_index)`, | ||
utils.NewBig(o.chainID), txHash.Bytes(), eventSig.Bytes()) | ||
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. Note: Make sure query is properly hitting indexes. 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. Yep, please make sure it doesn't hurt db performance, I described how to create a simple test on a local machine and test it 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. Probably we miss the index for Example on my local machine Sort (cost=575.91..575.92 rows=1 width=297) (actual time=213.647..259.292 rows=100000 loops=1)
Sort Key: (ROW(block_number, log_index))
Sort Method: external merge Disk: 31240kB
-> Index Scan using idx_evm_logs_ordered_by_block_and_created_at on logs (cost=0.55..575.90 rows=1 width=297) (actual time=0.070..89.148 rows=100000 loops=1)
Index Cond: ((evm_chain_id = '1'::numeric) AND (event_sig = '\xa32c5f1d88735034143171f18fbb4d447fbbe0fbf4c98733d54092a081ba5d2a'::bytea))
Filter: (tx_hash = '\xbb0f07700587fee22c5863ed75a5e05b68fcac4763449a582987fa4e8e9a2d0f'::bytea) |
||
if err != nil { | ||
return nil, err | ||
} | ||
return logs, nil | ||
} | ||
|
||
func validateTopicIndex(index int) error { | ||
// Only topicIndex 1 through 3 is valid. 0 is the event sig and only 4 total topics are allowed | ||
if !(index == 1 || index == 2 || index == 3) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
"strconv" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
|
@@ -15,6 +16,7 @@ import ( | |
libocr2 "github.com/smartcontractkit/libocr/offchainreporting2plus" | ||
|
||
relaylogger "github.com/smartcontractkit/chainlink-relay/pkg/logger" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/contractutil" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/hashlib" | ||
|
@@ -34,6 +36,8 @@ import ( | |
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers" | ||
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/observability" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/tokendata" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/tokendata/usdc" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/promwrapper" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/pg" | ||
) | ||
|
@@ -110,12 +114,19 @@ func NewExecutionServices(lggr logger.Logger, jb job.Job, chainSet evm.LegacyCha | |
"sourceChain", ChainName(int64(chainId)), | ||
"destChain", ChainName(destChainID)) | ||
|
||
sourceChainEventClient := ccipdata.NewLogPollerReader(sourceChain.LogPoller(), execLggr, sourceChain.Client()) | ||
|
||
tokenDataProviders, err := getTokenDataProviders(pluginConfig, offRampConfig.OnRamp, sourceChainEventClient) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not get token data providers") | ||
} | ||
|
||
wrappedPluginFactory := NewExecutionReportingPluginFactory( | ||
ExecutionPluginConfig{ | ||
lggr: execLggr, | ||
sourceLP: sourceChain.LogPoller(), | ||
destLP: destChain.LogPoller(), | ||
sourceReader: ccipdata.NewLogPollerReader(sourceChain.LogPoller(), execLggr, sourceChain.Client()), | ||
sourceReader: sourceChainEventClient, | ||
destReader: ccipdata.NewLogPollerReader(destChain.LogPoller(), execLggr, destChain.Client()), | ||
onRamp: onRamp, | ||
offRamp: offRamp, | ||
|
@@ -126,6 +137,7 @@ func NewExecutionServices(lggr logger.Logger, jb job.Job, chainSet evm.LegacyCha | |
sourceClient: sourceChain.Client(), | ||
destGasEstimator: destChain.GasEstimator(), | ||
leafHasher: hashlib.NewLeafHasher(offRampConfig.SourceChainSelector, offRampConfig.ChainSelector, onRamp.Address(), hashlib.NewKeccakCtx()), | ||
tokenDataProviders: tokenDataProviders, | ||
}) | ||
|
||
err = wrappedPluginFactory.UpdateLogPollerFilters(utils.ZeroAddress, qopts...) | ||
|
@@ -161,8 +173,41 @@ func NewExecutionServices(lggr logger.Logger, jb job.Job, chainSet evm.LegacyCha | |
return []job.ServiceCtx{job.NewServiceAdapter(oracle)}, nil | ||
} | ||
|
||
func getExecutionPluginSourceLpChainFilters(onRamp, priceRegistry common.Address) []logpoller.Filter { | ||
return []logpoller.Filter{ | ||
func getTokenDataProviders(pluginConfig ccipconfig.ExecutionPluginJobSpecConfig, onRampAddress common.Address, sourceChainEventClient *ccipdata.LogPollerReader) (map[common.Address]tokendata.Reader, error) { | ||
tokenDataProviders := make(map[common.Address]tokendata.Reader) | ||
|
||
if pluginConfig.USDCConfig.AttestationAPI != "" { | ||
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. nit could invert this to avoid nesting i.e. if == "" early return. Maybe also want an info log indicating we're proceeding without USDC config to speed up debugging? 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. I was imagining this function to do setup for all future token data providers, therefore having an if for each. With just usdc in mind it makes sense flipping |
||
err := pluginConfig.USDCConfig.ValidateUSDCConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
attestationURI, err2 := url.ParseRequestURI(pluginConfig.USDCConfig.AttestationAPI) | ||
if err2 != nil { | ||
return nil, errors.Wrap(err2, "failed to parse USDC attestation API") | ||
} | ||
|
||
tokenDataProviders[pluginConfig.USDCConfig.SourceTokenAddress] = tokendata.NewCachedReader( | ||
usdc.NewUSDCTokenDataReader( | ||
sourceChainEventClient, | ||
pluginConfig.USDCConfig.SourceTokenAddress, | ||
pluginConfig.USDCConfig.SourceMessageTransmitterAddress, | ||
onRampAddress, | ||
attestationURI, | ||
), | ||
) | ||
} | ||
|
||
return tokenDataProviders, nil | ||
} | ||
|
||
func getExecutionPluginSourceLpChainFilters(onRamp, priceRegistry common.Address, tokenDataProviders map[common.Address]tokendata.Reader) []logpoller.Filter { | ||
var filters []logpoller.Filter | ||
for _, provider := range tokenDataProviders { | ||
filters = append(filters, provider.GetSourceLogPollerFilters()...) | ||
} | ||
|
||
return append(filters, []logpoller.Filter{ | ||
{ | ||
Name: logpoller.FilterName(EXEC_CCIP_SENDS, onRamp.String()), | ||
EventSigs: []common.Hash{abihelpers.EventSignatures.SendRequested}, | ||
|
@@ -178,7 +223,7 @@ func getExecutionPluginSourceLpChainFilters(onRamp, priceRegistry common.Address | |
EventSigs: []common.Hash{abihelpers.EventSignatures.FeeTokenRemoved}, | ||
Addresses: []common.Address{priceRegistry}, | ||
}, | ||
} | ||
}...) | ||
} | ||
|
||
func getExecutionPluginDestLpChainFilters(commitStore, offRamp, priceRegistry common.Address) []logpoller.Filter { | ||
|
@@ -264,7 +309,7 @@ func UnregisterExecPluginLpFilters(ctx context.Context, spec *job.OCR2OracleSpec | |
return errors.Wrap(err, "failed loading onRamp") | ||
} | ||
|
||
return unregisterExecutionPluginLpFilters(ctx, sourceChain.LogPoller(), destChain.LogPoller(), offRamp, offRampConfig, sourceOnRamp, sourceChain.Client(), qopts...) | ||
return unregisterExecutionPluginLpFilters(ctx, sourceChain.LogPoller(), destChain.LogPoller(), offRamp, offRampConfig, sourceOnRamp, sourceChain.Client(), pluginConfig, qopts...) | ||
} | ||
|
||
func unregisterExecutionPluginLpFilters( | ||
|
@@ -275,6 +320,7 @@ func unregisterExecutionPluginLpFilters( | |
destOffRampConfig evm_2_evm_offramp.EVM2EVMOffRampStaticConfig, | ||
sourceOnRamp evm_2_evm_onramp.EVM2EVMOnRampInterface, | ||
sourceChainClient client.Client, | ||
pluginConfig ccipconfig.ExecutionPluginJobSpecConfig, | ||
qopts ...pg.QOpt) error { | ||
destOffRampDynCfg, err := destOffRamp.GetDynamicConfig(&bind.CallOpts{Context: ctx}) | ||
if err != nil { | ||
|
@@ -286,9 +332,15 @@ func unregisterExecutionPluginLpFilters( | |
return err | ||
} | ||
|
||
if err := logpollerutil.UnregisterLpFilters( | ||
// SourceChainEventClient can be nil because it is not used in unregisterExecutionPluginLpFilters | ||
tokenDataProviders, err := getTokenDataProviders(pluginConfig, destOffRampConfig.OnRamp, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = logpollerutil.UnregisterLpFilters( | ||
sourceLP, | ||
getExecutionPluginSourceLpChainFilters(destOffRampConfig.OnRamp, onRampDynCfg.PriceRegistry), | ||
getExecutionPluginSourceLpChainFilters(destOffRampConfig.OnRamp, onRampDynCfg.PriceRegistry, tokenDataProviders), | ||
qopts..., | ||
); err != nil { | ||
return 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.
Make sure to backport these changes to the main repo