Skip to content

Commit

Permalink
feat: unify SYG_DOM variables into a single SYG_CHAINS variable (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 committed Mar 20, 2023
1 parent 2613905 commit 1ae37a0
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 35 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ where ENV variable name reflects properties position in the structure.
For example, if you want to set `Config.RelayerConfig.MpcConfig.Port` this would
translate to ENV variable named `SYG_RELAYER_MPCCONFIG_PORT`.

Each `ChainConfig` is defined as one ENV variable, where its content is JSON configuration for one chain/domain.
Variables are named like this: `SYG_DOM_X` where `X` is domain id.
`ChainConfig` is defined as one ENV variable `SYG_CHAINS`, where its content is JSON configuration for all supported chains and should match
ordering with shared configuration.

## Technical documentation
Each service has a technical documentation inside its repository under `/docs` directory. [Here](/docs/Home.md) you can find technical documentation for relayers.

Additionally, the [general high-level documentation for the entire Sygma system](/docs/general/Arhitecture.md) can be found in this same repository under the `/docs/general` directory.
Additionally, the [general high-level documentation for the entire Sygma system](/docs/general/Arhitecture.md) can be found in this same repository under the `/docs/general` directory.
9 changes: 2 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@ type RawConfig struct {
//
//
// Properties of RelayerConfig are expected to be defined as separate ENV variables
// where ENV variable name reflects properties position in structure. Each ENV variable needs to be prefixed with CBH.
// where ENV variable name reflects properties position in structure. Each ENV variable needs to be prefixed with SYG.
//
// For example, if you want to set Config.RelayerConfig.MpcConfig.Port this would
// translate to ENV variable named CBH_RELAYER_MPCCONFIG_PORT.
//
//
// Each ChainConfig is defined as one ENV variable, where its content is JSON configuration for one chain/domain.
// Variables are named like this: CBH_DOM_X where X is domain id.
//
// translate to ENV variable named SYG_RELAYER_MPCCONFIG_PORT.
func GetConfigFromENV(config *Config) (*Config, error) {
rawConfig, err := loadFromEnv()
if err != nil {
Expand Down
60 changes: 56 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,34 @@ func (s *GetConfigTestSuite) Test_GetConfigFromFile_InvalidPath() {
}

func (s *GetConfigTestSuite) Test_GetConfigFromENV() {
_ = os.Setenv("SYG_DOM_1", "{\n \"id\": 1,\n \"from\": \"0xff93B45308FD417dF303D6515aB04D9e89a750Ca\",\n \"name\": \"evm1\",\n \"type\": \"evm\",\n \"endpoint\": \"ws://evm1-1:8546\",\n \"bridge\": \"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66\",\n \"erc20Handler\": \"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e\",\n \"erc721Handler\": \"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b\",\n \"genericHandler\": \"0xe1588E2c6a002AE93AeD325A910Ed30961874109\",\n \"maxGasPrice\": 20000000000,\n \"blockConfirmations\": 2\n }")
_ = os.Setenv("SYG_DOM_2", "{\n \"id\": 2,\n \"from\": \"0xff93B45308FD417dF303D6515aB04D9e89a750Ca\",\n \"name\": \"evm2\",\n \"type\": \"evm\",\n \"endpoint\": \"ws://evm2-1:8546\",\n \"bridge\": \"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66\",\n \"erc20Handler\": \"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e\",\n \"erc721Handler\": \"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b\",\n \"genericHandler\": \"0xe1588E2c6a002AE93AeD325A910Ed30961874109\",\n \"maxGasPrice\": 20000000000,\n \"blockConfirmations\": 2\n }")
_ = os.Setenv("SYG_CHAINS", `[
{
"id":1,
"from":"0xff93B45308FD417dF303D6515aB04D9e89a750Ca",
"name":"evm1",
"type":"evm",
"endpoint":"ws://evm1-1:8546",
"bridge":"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
"erc20Handler":"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e",
"erc721Handler":"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b",
"genericHandler":"0xe1588E2c6a002AE93AeD325A910Ed30961874109",
"maxGasPrice":20000000000,
"blockConfirmations":2
},
{
"id":2,
"from":"0xff93B45308FD417dF303D6515aB04D9e89a750Ca",
"name":"evm2",
"type":"evm",
"endpoint":"ws://evm2-1:8546",
"bridge":"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
"erc20Handler":"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e",
"erc721Handler":"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b",
"genericHandler":"0xe1588E2c6a002AE93AeD325A910Ed30961874109",
"maxGasPrice":20000000000,
"blockConfirmations":2
}
]`)

_ = os.Setenv("SYG_RELAYER_MPCCONFIG_KEY", "test-pk")
_ = os.Setenv("SYG_RELAYER_MPCCONFIG_KEYSHAREPATH", "/cfg/keyshares/0.keyshare")
Expand Down Expand Up @@ -118,8 +144,34 @@ func (s *GetConfigTestSuite) Test_GetConfigFromENV() {
}

func (s *GetConfigTestSuite) Test_SharedConfigLengthMismatch() {
_ = os.Setenv("SYG_DOM_1", "{\n \"id\": 1,\n \"from\": \"0xff93B45308FD417dF303D6515aB04D9e89a750Ca\",\n \"name\": \"evm1\",\n \"type\": \"evm\",\n \"endpoint\": \"ws://evm1-1:8546\",\n \"bridge\": \"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66\",\n \"erc20Handler\": \"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e\",\n \"erc721Handler\": \"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b\",\n \"genericHandler\": \"0xe1588E2c6a002AE93AeD325A910Ed30961874109\",\n \"maxGasPrice\": 20000000000,\n \"blockConfirmations\": 2\n }")
_ = os.Setenv("SYG_DOM_2", "{\n \"id\": 2,\n \"from\": \"0xff93B45308FD417dF303D6515aB04D9e89a750Ca\",\n \"name\": \"evm2\",\n \"type\": \"evm\",\n \"endpoint\": \"ws://evm2-1:8546\",\n \"bridge\": \"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66\",\n \"erc20Handler\": \"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e\",\n \"erc721Handler\": \"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b\",\n \"genericHandler\": \"0xe1588E2c6a002AE93AeD325A910Ed30961874109\",\n \"maxGasPrice\": 20000000000,\n \"blockConfirmations\": 2\n }")
_ = os.Setenv("SYG_CHAINS", `[
{
"id":1,
"from":"0xff93B45308FD417dF303D6515aB04D9e89a750Ca",
"name":"evm1",
"type":"evm",
"endpoint":"ws://evm1-1:8546",
"bridge":"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
"erc20Handler":"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e",
"erc721Handler":"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b",
"genericHandler":"0xe1588E2c6a002AE93AeD325A910Ed30961874109",
"maxGasPrice":20000000000,
"blockConfirmations":2
},
{
"id":2,
"from":"0xff93B45308FD417dF303D6515aB04D9e89a750Ca",
"name":"evm2",
"type":"evm",
"endpoint":"ws://evm2-1:8546",
"bridge":"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
"erc20Handler":"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e",
"erc721Handler":"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b",
"genericHandler":"0xe1588E2c6a002AE93AeD325A910Ed30961874109",
"maxGasPrice":20000000000,
"blockConfirmations":2
}
]`)

_ = os.Setenv("SYG_RELAYER_MPCCONFIG_KEY", "test-pk")
_ = os.Setenv("SYG_RELAYER_MPCCONFIG_KEYSHAREPATH", "/cfg/keyshares/0.keyshare")
Expand Down
26 changes: 11 additions & 15 deletions config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,22 @@ func loadFromEnv() (RawConfig, error) {
}
rawConfig := c.Config

// load chain configs
index := 1
for {
rawDomainConfig := os.Getenv(fmt.Sprintf("%s_DOM_%d", EnvPrefix, index))
if rawDomainConfig == "" {
break
}
var cc map[string]interface{}
err = json.Unmarshal([]byte(rawDomainConfig), &cc)
if err != nil {
return RawConfig{}, err
}
rawConfig.ChainConfigs = append(rawConfig.ChainConfigs, cc)
index++
err = rawConfig.RelayerConfig.Validate()
if err != nil {
return RawConfig{}, err
}

err = rawConfig.RelayerConfig.Validate()
rawDomainConfig := os.Getenv(fmt.Sprintf("%s_CHAINS", EnvPrefix))
if rawDomainConfig == "" {
return rawConfig, nil
}

var cc []map[string]interface{}
err = json.Unmarshal([]byte(rawDomainConfig), &cc)
if err != nil {
return RawConfig{}, err
}
rawConfig.ChainConfigs = cc

return rawConfig, nil
}
Expand Down
61 changes: 55 additions & 6 deletions config/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,34 @@ func (s *LoadFromEnvTestSuite) Test_ValidChainConfig() {
_ = os.Setenv("SYG_RELAYER_BULLYCONFIG_PINGINTERVAL", "2s")
_ = os.Setenv("SYG_RELAYER_BULLYCONFIG_ELECTIONWAITTIME", "2s")
_ = os.Setenv("SYG_RELAYER_BULLYCONFIG_BULLYWAITTIME", "2s")
_ = os.Setenv("SYG_DOM_1", "{\n \"id\": 1,\n \"from\": \"0xff93B45308FD417dF303D6515aB04D9e89a750Ca\",\n \"name\": \"evm1\",\n \"type\": \"evm\",\n \"endpoint\": \"ws://evm1-1:8546\",\n \"bridge\": \"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66\",\n \"erc20Handler\": \"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e\",\n \"erc721Handler\": \"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b\",\n \"genericHandler\": \"0xe1588E2c6a002AE93AeD325A910Ed30961874109\",\n \"gasLimit\": 9000000,\n \"maxGasPrice\": 20000000000,\n \"blockConfirmations\": 2\n }")
_ = os.Setenv("SYG_DOM_2", "{\n \"id\": 2,\n \"from\": \"0xff93B45308FD417dF303D6515aB04D9e89a750Ca\",\n \"name\": \"evm2\",\n \"type\": \"evm\",\n \"endpoint\": \"ws://evm2-1:8546\",\n \"bridge\": \"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66\",\n \"erc20Handler\": \"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e\",\n \"erc721Handler\": \"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b\",\n \"genericHandler\": \"0xe1588E2c6a002AE93AeD325A910Ed30961874109\",\n \"gasLimit\": 9000000,\n \"maxGasPrice\": 20000000000,\n \"blockConfirmations\": 2\n }")
_ = os.Setenv("SYG_CHAINS", `[
{
"id":1,
"from":"0xff93B45308FD417dF303D6515aB04D9e89a750Ca",
"name":"evm1",
"type":"evm",
"endpoint":"ws://evm1-1:8546",
"bridge":"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
"erc20Handler":"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e",
"erc721Handler":"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b",
"genericHandler":"0xe1588E2c6a002AE93AeD325A910Ed30961874109",
"maxGasPrice":20000000000,
"blockConfirmations":2
},
{
"id":2,
"from":"0xff93B45308FD417dF303D6515aB04D9e89a750Ca",
"name":"evm2",
"type":"evm",
"endpoint":"ws://evm2-1:8546",
"bridge":"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
"erc20Handler":"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e",
"erc721Handler":"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b",
"genericHandler":"0xe1588E2c6a002AE93AeD325A910Ed30961874109",
"maxGasPrice":20000000000,
"blockConfirmations":2
}
]`)

env, err := loadFromEnv()

Expand All @@ -110,7 +136,6 @@ func (s *LoadFromEnvTestSuite) Test_ValidChainConfig() {
"type": "evm",
"bridge": "0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
"erc721Handler": "0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b",
"gasLimit": 9e+06,
"maxGasPrice": 2e+10,
"from": "0xff93B45308FD417dF303D6515aB04D9e89a750Ca",
"name": "evm1",
Expand All @@ -124,7 +149,6 @@ func (s *LoadFromEnvTestSuite) Test_ValidChainConfig() {
"type": "evm",
"bridge": "0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
"erc721Handler": "0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b",
"gasLimit": 9e+06,
"maxGasPrice": 2e+10,
"from": "0xff93B45308FD417dF303D6515aB04D9e89a750Ca",
"name": "evm2",
Expand All @@ -150,8 +174,33 @@ func (s *LoadFromEnvTestSuite) Test_InvalidChainConfig() {
_ = os.Setenv("SYG_RELAYER_BULLYCONFIG_PINGINTERVAL", "2s")
_ = os.Setenv("SYG_RELAYER_BULLYCONFIG_ELECTIONWAITTIME", "2s")
_ = os.Setenv("SYG_RELAYER_BULLYCONFIG_BULLYWAITTIME", "2s")
_ = os.Setenv("SYG_DOM_1", "{\n \"id\": 1,\n \"from\": \"0xff93B45308FD417dF303D6515aB04D9e89a750Ca\",\n \"name\": \"evm1\",\n \"type\": \"evm\",\n \"endpoint\": \"ws://evm1-1:8546\",\n \"bridge\": \"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66\",\n \"erc20Handler\": \"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e\",\n \"erc721Handler\": \"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b\",\n \"genericHandler\": \"0xe1588E2c6a002AE93AeD325A910Ed30961874109\",\n \"gasLimit\": 9000000,\n \"maxGasPrice\": 20000000000,\n \"blockConfirmations\": 2\n }")
_ = os.Setenv("SYG_DOM_2", "{\n \"id\": 2,\n \"from\": \"0xff93B45308FD417dF303D6515aB04D9e89a750Ca\",\n \"name\": \"evm2\",\n \"type\": \"evm\",\n \"endpoint\": \"ws://evm2-1:8546\",\n \"bridge\": \"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66\",\n \"erc20Handler\": \"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e\",\n \"erc721Handler\": \"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b\",\n \"genericHandler\": \"0xe1588E2c6a002AE93AeD325A910Ed30961874109\",\n \"gasLimit\": 9000000,\n \"maxGasPrice\": 20000000000,\n \"blockConfirmations\": 2\n }")
_ = os.Setenv("SYG_CHAINS", `[
{
"id":1,
"from":"0xff93B45308FD417dF303D6515aB04D9e89a750Ca",
"name":"evm1",
"type":"evm",
"endpoint":"ws://evm1-1:8546",
"bridge":"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
"erc20Handler":"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e",
"erc721Handler":"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b",
"genericHandler":"0xe1588E2c6a002AE93AeD325A910Ed30961874109",
"maxGasPrice":20000000000,
"blockConfirmations":2
},
{
"id":2,
"from":"0xff93B45308FD417dF303D6515aB04D9e89a750Ca",
"name":"evm2",
"endpoint":"ws://evm2-1:8546",
"bridge":"0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
"erc20Handler":"0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e",
"erc721Handler":"0x75dF75bcdCa8eA2360c562b4aaDBAF3dfAf5b19b",
"genericHandler":"0xe1588E2c6a002AE93AeD325A910Ed30961874109",
"maxGasPrice":20000000000,
"blockConfirmations":2
}
]`)

_, err := loadFromEnv()

Expand Down

0 comments on commit 1ae37a0

Please sign in to comment.