-
Notifications
You must be signed in to change notification settings - Fork 33
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] fix duplicate cctp configs #2801
Comments
To resolve the issue of duplicate CCTP configs in RFQ, follow these steps:
# shared_config.yml
omnirpc_url: 'https://rpc.interop-staging.com'
signer:
type: File
file: /tmp/test-signer
rfq_url: 'http://localhost:8080'
!include shared_config.yml
tokens:
421614:
- '0x858355dAe73bc0FA4AB220e5296cfAa77e99900e'
11155111:
- '0x858355dAe73bc0FA4AB220e5296cfAa77e99900e'
bridges:
421614:
address: '0x58dBd847C0CBFc9a4B9942847124BFC3589c70aA'
11155111:
address: '0x6EBdE77d635496Dea99364E0DA18ad8A1AFA9F27'
database:
type: 'sqlite'
dsn: '/tmp/relayer'
quotable_tokens:
421614-0x858355dAe73bc0FA4AB220e5296cfAa77e99900e:
- 11155111-0x858355dAe73bc0FA4AB220e5296cfAa77e99900e
11155111-0x858355dAe73bc0FA4AB220e5296cfAa77e99900e:
- 421614-0x858355dAe73bc0FA4AB220e5296cfAa77e99900e
package config
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/ImVexed/fasturl"
submitterConfig "github.com/synapsecns/sanguine/ethergo/submitter/config"
"github.com/davecgh/go-spew/spew"
"github.com/jftuga/ellipsis"
ethConfig "github.com/synapsecns/sanguine/ethergo/signer/config"
"github.com/synapsecns/sanguine/services/cctp-relayer/types"
"gopkg.in/yaml.v2"
)
// Config is used to configure an Executor agent.
type Config struct {
Port uint16 `yaml:"port"`
Host string `yaml:"host"`
CircleAPIURl string `yaml:"circle_api_url"`
CCTPType string `yaml:"cctp_type"`
Chains ChainConfigs `yaml:"chains"`
BaseOmnirpcURL string `yaml:"base_omnirpc_url"`
Signer ethConfig.SignerConfig `yaml:"unbonded_signer"`
RetryIntervalMS int `yaml:"retry_interval_ms"`
HTTPBackoffMaxElapsedTimeMs int `yaml:"http_backoff_max_elapsed_time_ms"`
SubmitterConfig submitterConfig.Config `yaml:"submitter_config"`
ScreenerAPIUrl string `yaml:"screener_api_url"`
}
func (c *Config) IsValid(ctx context.Context) (ok bool, err error) {
if ok, err = c.Chains.IsValid(ctx); !ok {
return false, err
}
if c.BaseOmnirpcURL == "" {
return false, fmt.Errorf("rpc url cannot be empty")
}
if _, err := fasturl.ParseURL(c.BaseOmnirpcURL); err != nil {
return false, fmt.Errorf("rpc url is invalid: %w", err)
}
if _, err := c.Chains.IsValid(ctx); err != nil {
return false, fmt.Errorf(fmt.Errorf("could not validate chains: %w", err).Error())
}
if ok, err = c.Signer.IsValid(ctx); !ok {
return false, fmt.Errorf("unbonded signer is invalid: %w", err)
}
return true, nil
}
func (c Config) Encode() ([]byte, error) {
output, err := yaml.Marshal(&c)
if err != nil {
return nil, fmt.Errorf("could not unmarshall config %s: %w", ellipsis.Shorten(spew.Sdump(c), 20), err)
}
return output, nil
}
func DecodeConfig(filePath string) (cfg Config, err error) {
input, err := os.ReadFile(filepath.Clean(filePath))
if err != nil {
return Config{}, fmt.Errorf("failed to read file: %w", err)
}
err = yaml.Unmarshal(input, &cfg)
if err != nil {
return Config{}, fmt.Errorf("could not unmarshall config %s: %w", ellipsis.Shorten(string(input), 30), err)
}
return cfg, nil
}
const defaultCCTPType = types.SynapseMessageType
func (c Config) GetCCTPType() (types.MessageType, error) {
switch c.CCTPType {
case "synapse":
return types.SynapseMessageType, nil
case "circle":
return types.CircleMessageType, nil
default:
if len(c.CCTPType) == 0 {
return defaultCCTPType, nil
}
return 0, fmt.Errorf("invalid cctp method: %s", c.CCTPType)
}
}
func (c Config) GetChainConfig(chainID uint32) (cfg ChainConfig, err error) {
for _, chainCfg := range c.Chains {
if chainCfg.ChainID == chainID {
return chainCfg, nil
}
}
return cfg, fmt.Errorf("chain config not found for chain id: %d", chainID)
}
package config_test
import (
"github.com/Flaque/filet"
"github.com/brianvoe/gofakeit/v6"
. "github.com/stretchr/testify/assert"
"github.com/synapsecns/sanguine/ethergo/mocks"
ethConfig "github.com/synapsecns/sanguine/ethergo/signer/config"
"github.com/synapsecns/sanguine/ethergo/signer/wallet"
"github.com/synapsecns/sanguine/services/cctp-relayer/config"
)
func configFixture(c ConfigSuite) config.Config {
chainIDA := gofakeit.Uint32()
chainIDB := chainIDA + 1
testWallet, err := wallet.FromRandom()
Nil(c.T(), err)
return config.Config{
Chains: config.ChainConfigs{
config.ChainConfig{
ChainID: chainIDA,
CCTPAddress: mocks.MockAddress().String(),
},
config.ChainConfig{
ChainID: chainIDB,
CCTPAddress: mocks.MockAddress().String(),
},
},
BaseOmnirpcURL: gofakeit.URL(),
Signer: ethConfig.SignerConfig{
Type: ethConfig.FileType.String(),
File: filet.TmpFile(c.T(), "", testWallet.PrivateKeyHex()).Name(),
},
HTTPBackoffMaxElapsedTimeMs: int(gofakeit.Int64()),
}
}
func (c ConfigSuite) TestConfigEncodeDecode() {
testConfig := configFixture(c)
encodedConfig, err := testConfig.Encode()
Nil(c.T(), err)
file := filet.TmpFile(c.T(), "", string(encodedConfig))
decodedConfig, err := config.DecodeConfig(file.Name())
Nil(c.T(), err)
ok, err := decodedConfig.IsValid(c.GetTestContext())
Nil(c.T(), err)
True(c.T(), ok)
} This will consolidate the duplicated configurations and ensure both RFQ and CCTP use the shared settings. References/services/rfq/config.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The current CCTP config duplication w/ rfq is pretty unusable. Currently:
are duplicated
The text was updated successfully, but these errors were encountered: