-
Notifications
You must be signed in to change notification settings - Fork 38
Add CCTP rebalancing to RFQ relayer #2073
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 59 commits
3a73d21
6664fd9
91017b7
f7d56f2
cbf01e7
512fb30
536f227
1e9e1d6
708eab0
eabdda0
1f7c3a3
44be2b3
d2acc79
4ad03dc
7c0cf7e
fda6f90
4db711f
06e8e57
6b38ba5
90a63e6
6c70e96
3d561b0
e5868de
eca3b63
383ece0
0095c7c
58c8a7f
5aeb2c5
baab066
752763b
ab90a63
989c2d5
73e027d
a4e308c
03891fb
c9ca663
81cfc79
3a6ea21
42f24ce
ed841c8
628733d
efaf3bd
1e7175f
5c99c21
8fcfbcb
88de62a
ce32aa9
819dd14
5f4486b
c8f2c67
b7dd419
53e8129
2e33da3
45c2ad9
ba58876
4febe40
000549f
ceb8479
19dc080
085ac5e
782b869
6195502
07dbaeb
7a9a30b
f2d7ab8
cd760c2
4055168
7ff3b2a
d91525a
ecbdc0e
edeeb0e
5743f58
d8deade
e1296a4
edae452
ab2a9ab
996a82b
93a1e04
b0f9d22
3285fe6
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 |
|---|---|---|
|
|
@@ -4,21 +4,20 @@ import ( | |
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "math/big" | ||
| "time" | ||
|
|
||
| "github.com/ethereum/go-ethereum" | ||
| "github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/core/types" | ||
| "github.com/ipfs/go-log" | ||
| "github.com/jpillora/backoff" | ||
| "github.com/synapsecns/sanguine/core/metrics" | ||
| "github.com/synapsecns/sanguine/ethergo/client" | ||
| "github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge" | ||
| "github.com/synapsecns/sanguine/services/rfq/relayer/reldb" | ||
| "go.opentelemetry.io/otel/attribute" | ||
| "go.opentelemetry.io/otel/trace" | ||
| "golang.org/x/sync/errgroup" | ||
| "math/big" | ||
| "time" | ||
| ) | ||
|
|
||
| // ContractListener listens for chain events and calls HandleLog. | ||
|
|
@@ -37,11 +36,12 @@ type ContractListener interface { | |
| type HandleLog func(ctx context.Context, log types.Log) error | ||
|
|
||
| type chainListener struct { | ||
| client client.EVM | ||
| contract *fastbridge.FastBridgeRef | ||
| store reldb.Service | ||
|
dwasse marked this conversation as resolved.
|
||
| handler metrics.Handler | ||
| backoff *backoff.Backoff | ||
| client client.EVM | ||
| address common.Address | ||
| initialBlock uint64 | ||
| store reldb.Service | ||
| handler metrics.Handler | ||
| backoff *backoff.Backoff | ||
| // IMPORTANT! These fields cannot be used until they has been set. They are NOT | ||
| // set in the constructor | ||
| startBlock, chainID, latestBlock uint64 | ||
|
|
@@ -52,18 +52,14 @@ type chainListener struct { | |
| var logger = log.Logger("chainlistener-logger") | ||
|
|
||
| // NewChainListener creates a new chain listener. | ||
| func NewChainListener(omnirpcClient client.EVM, store reldb.Service, address common.Address, handler metrics.Handler) (ContractListener, error) { | ||
| fastBridge, err := fastbridge.NewFastBridgeRef(address, omnirpcClient) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("could not create fast bridge contract: %w", err) | ||
| } | ||
|
|
||
| func NewChainListener(omnirpcClient client.EVM, store reldb.Service, address common.Address, initialBlock uint64, handler metrics.Handler) (ContractListener, error) { | ||
|
Contributor
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. let's move this/the test to ethergo and import if we can
Contributor
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 mention this b/c I've recreated this exact file twice in
Collaborator
Author
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. Did this here: 4febe40 Now lives in |
||
| return &chainListener{ | ||
| handler: handler, | ||
| store: store, | ||
| client: omnirpcClient, | ||
| contract: fastBridge, | ||
| backoff: newBackoffConfig(), | ||
| handler: handler, | ||
| address: address, | ||
| initialBlock: initialBlock, | ||
| store: store, | ||
| client: omnirpcClient, | ||
| backoff: newBackoffConfig(), | ||
| }, nil | ||
| } | ||
|
|
||
|
|
@@ -91,13 +87,12 @@ func (c *chainListener) Listen(ctx context.Context, handler HandleLog) (err erro | |
| if err != nil { | ||
| logger.Warn(err) | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| func (c *chainListener) Address() common.Address { | ||
| return c.contract.Address() | ||
| return c.address | ||
| } | ||
|
|
||
| func (c *chainListener) LatestBlock() uint64 { | ||
|
|
@@ -125,9 +120,8 @@ func (c *chainListener) doPoll(parentCtx context.Context, handler HandleLog) (er | |
| } | ||
|
|
||
| // Check if latest block is the same as start block (for chains with slow block times) | ||
|
|
||
| if c.latestBlock == c.startBlock { | ||
| return | ||
| return nil | ||
| } | ||
|
|
||
| // Handle if the listener is more than one get logs range behind the head | ||
|
|
@@ -164,7 +158,7 @@ func (c *chainListener) doPoll(parentCtx context.Context, handler HandleLog) (er | |
| } | ||
|
|
||
| func (c chainListener) getMetadata(parentCtx context.Context) (startBlock, chainID uint64, err error) { | ||
| var deployBlock, lastIndexed uint64 | ||
| var lastIndexed uint64 | ||
| ctx, span := c.handler.Tracer().Start(parentCtx, "getMetadata") | ||
|
|
||
| defer func() { | ||
|
|
@@ -174,16 +168,6 @@ func (c chainListener) getMetadata(parentCtx context.Context) (startBlock, chain | |
| // TODO: consider some kind of backoff here in case rpcs are down at boot. | ||
| // this becomes more of an issue as we add more chains | ||
| g, ctx := errgroup.WithContext(ctx) | ||
| g.Go(func() error { | ||
|
dwasse marked this conversation as resolved.
|
||
| deployBlock, err := c.contract.DeployBlock(&bind.CallOpts{Context: ctx}) | ||
| if err != nil { | ||
| return fmt.Errorf("could not get deploy block: %w", err) | ||
| } | ||
|
|
||
| startBlock = deployBlock.Uint64() | ||
| return nil | ||
| }) | ||
|
|
||
| g.Go(func() error { | ||
| // TODO: one thing I've been going back and forth on is whether or not this method should be chain aware | ||
| // passing in the chain ID would allow us to pull everything directly from the config, but be less testable | ||
|
|
@@ -213,8 +197,10 @@ func (c chainListener) getMetadata(parentCtx context.Context) (startBlock, chain | |
| return 0, 0, fmt.Errorf("could not get metadata: %w", err) | ||
| } | ||
|
|
||
| if lastIndexed > deployBlock { | ||
| if lastIndexed > c.startBlock { | ||
| startBlock = lastIndexed | ||
| } else { | ||
| startBlock = c.initialBlock | ||
| } | ||
|
|
||
| return startBlock, chainID, nil | ||
|
|
@@ -233,6 +219,6 @@ func (c chainListener) buildFilterQuery(fromBlock, toBlock uint64) ethereum.Filt | |
| return ethereum.FilterQuery{ | ||
| FromBlock: new(big.Int).SetUint64(fromBlock), | ||
| ToBlock: new(big.Int).SetUint64(toBlock), | ||
| Addresses: []common.Address{c.contract.Address()}, | ||
| Addresses: []common.Address{c.address}, | ||
| } | ||
| } | ||
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.
Tip
Codebase Verification
The verification process revealed that while one usage of
NewTestChainListenerinsuite_test.gohas been correctly updated to include both theAddressandInitialBlockfields, another usage has been updated to include only theAddressfield, omitting theInitialBlockfield. This indicates that not all references and usages ofNewTestChainListenerthroughout the test suite have been updated accordingly to pass the correct arguments, as required by the modifications in theTestChainListenerArgsstruct.Analysis chain
The
NewTestChainListenerfunction has been updated to initialize achainListenerwith the newAddressandInitialBlockfields. This change is consistent and necessary due to the modifications in theTestChainListenerArgsstruct. It's important to ensure that all references and usages ofNewTestChainListenerthroughout the test suite are updated accordingly to pass the correct arguments.Scripts Executed
The following scripts were executed for the analysis:
Script:
Length of output: 384
Script:
Length of output: 479