Skip to content
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

RFQ Relayer: configure chain confirmations #2967

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions services/rfq/relayer/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/synapsecns/sanguine/ethergo/listener"
"github.com/synapsecns/sanguine/ethergo/submitter"
"github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge"
"github.com/synapsecns/sanguine/services/rfq/relayer/relconfig"
"github.com/synapsecns/sanguine/services/rfq/relayer/reldb"
)

Expand All @@ -30,21 +31,28 @@ type Chain struct {
}

// NewChain creates a new chain.
func NewChain(ctx context.Context, chainClient client.EVM, addr common.Address, chainListener listener.ContractListener, ts submitter.TransactionSubmitter) (*Chain, error) {
bridge, err := fastbridge.NewFastBridgeRef(addr, chainClient)
func NewChain(ctx context.Context, cfg relconfig.Config, chainClient client.EVM, chainListener listener.ContractListener, ts submitter.TransactionSubmitter) (*Chain, error) {
chainID, err := chainClient.ChainID(ctx)
if err != nil {
return nil, fmt.Errorf("could not get chain id: %w", err)
Comment on lines +35 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Consider caching the chain ID to avoid repeated calls to chainClient.ChainID(ctx).

}
addr, err := cfg.GetRFQAddress(int(chainID.Int64()))
if err != nil {
return nil, fmt.Errorf("could not get rfq address: %w", err)
Comment on lines +39 to +41
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Ensure cfg.GetRFQAddress handles all possible edge cases for chain ID mappings.

}
bridge, err := fastbridge.NewFastBridgeRef(common.HexToAddress(addr), chainClient)
if err != nil {
return nil, fmt.Errorf("could not create bridge contract: %w", err)
}
chainID, err := chainClient.ChainID(ctx)
confirmations, err := cfg.GetConfirmations(int(chainID.Int64()))
if err != nil {
return nil, fmt.Errorf("could not get chain id: %w", err)
return nil, fmt.Errorf("could not get confirmations: %w", err)
Comment on lines +47 to +49
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check: Validate that cfg.GetConfirmations returns a reasonable default if the value is not set.

}
return &Chain{
ChainID: uint32(chainID.Int64()),
Bridge: bridge,
Client: chainClient,
// TODO: configure
Confirmations: 1,
ChainID: uint32(chainID.Int64()),
Bridge: bridge,
Client: chainClient,
Confirmations: confirmations,
listener: chainListener,
submitter: ts,
}, nil
Expand Down
4 changes: 2 additions & 2 deletions services/rfq/relayer/relapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewRelayerAPI(
}

chains := make(map[uint32]*chain.Chain)
for chainID, chainCfg := range cfg.Chains {
for chainID := range cfg.Chains {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check: Consider validating the chain configuration before iterating over it to catch potential misconfigurations early.

chainClient, err := omniRPCClient.GetChainClient(ctx, chainID)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Check if chainClient is nil before proceeding to avoid dereferencing a nil pointer.

if err != nil {
return nil, fmt.Errorf("could not create omnirpc client: %w", err)
Expand All @@ -80,7 +80,7 @@ func NewRelayerAPI(
if err != nil {
return nil, fmt.Errorf("could not get chain listener: %w", err)
}
chains[uint32(chainID)], err = chain.NewChain(ctx, chainClient, common.HexToAddress(chainCfg.RFQAddress), chainListener, submitter)
chains[uint32(chainID)], err = chain.NewChain(ctx, cfg, chainClient, chainListener, submitter)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Ensure NewChain handles the entire configuration object correctly to avoid potential issues.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Ensure NewChain handles the entire configuration object correctly to avoid potential issues.

if err != nil {
return nil, fmt.Errorf("could not create chain: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions services/rfq/relayer/service/statushandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,7 @@ func (r *Relayer) chainIDToChain(ctx context.Context, chainID uint32) (*chain.Ch
return nil, fmt.Errorf("could not get origin client: %w", err)
}

//nolint: wrapcheck
rfqAddr, err := r.cfg.GetRFQAddress(id)
if err != nil {
return nil, fmt.Errorf("could not get rfq address: %w", err)
}
chain, err := chain.NewChain(ctx, chainClient, common.HexToAddress(rfqAddr), r.chainListeners[id], r.submitter)
chain, err := chain.NewChain(ctx, r.cfg, chainClient, r.chainListeners[id], r.submitter)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Ensure the configuration object includes all necessary parameters previously fetched separately.

if err != nil {
return nil, fmt.Errorf("could not create chain: %w", err)
}
Expand Down
Loading