Skip to content

Commit

Permalink
chore: rename network parameter for second bridge config
Browse files Browse the repository at this point in the history
  • Loading branch information
wwestgarth committed Mar 26, 2024
1 parent 888fa51 commit 96f8ff8
Show file tree
Hide file tree
Showing 14 changed files with 865 additions and 865 deletions.
4 changes: 2 additions & 2 deletions core/client/eth/secondary_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

type SecondaryClient struct {
ETHClient
ethConfig *types.SecondaryEthereumConfig
ethConfig *types.EVMChainConfig

// this is all just to prevent spamming the infura just
// to get the last height of the blockchain
Expand All @@ -60,7 +60,7 @@ func SecondaryDial(ctx context.Context, cfg Config) (*SecondaryClient, error) {
}, nil
}

func (c *SecondaryClient) UpdateEthereumConfig(ctx context.Context, ethConfig *types.SecondaryEthereumConfig) error {
func (c *SecondaryClient) UpdateEthereumConfig(ctx context.Context, ethConfig *types.EVMChainConfig) error {
if c == nil {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions core/evtforward/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (e *Engine) SetupSecondaryEthereumEngine(
client ethereum.Client,
forwarder ethereum.Forwarder,
config ethereum.Config,
ethCfg *types.SecondaryEthereumConfig,
ethCfg *types.EVMChainConfig,
assets ethereum.Assets,
) error {
if e.log.IsDebug() {
Expand Down Expand Up @@ -270,7 +270,7 @@ func (e *NoopEngine) SetupSecondaryEthereumEngine(
_ ethereum.Client,
_ ethereum.Forwarder,
_ ethereum.Config,
_ *types.SecondaryEthereumConfig,
_ *types.EVMChainConfig,
_ ethereum.Assets,
) error {
if e.log.IsDebug() {
Expand Down
2 changes: 1 addition & 1 deletion core/netparams/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func defaultNetParams() map[string]value {
MustUpdate(`{"configs":[{"network_id":"100","chain_id":"100","confirmations":3,"name":"Gnosis Chain", "block_interval": 3}, {"network_id":"42161","chain_id":"42161","confirmations":3,"name":"Arbitrum One", "block_interval": 50}]}`),
BlockchainsPrimaryEthereumConfig: NewJSON(&proto.EthereumConfig{}, types.CheckUntypedEthereumConfig).Mutable(true).
MustUpdate(`{"network_id": "XXX", "chain_id": "XXX", "collateral_bridge_contract": { "address": "0xXXX" }, "confirmations": 3, "staking_bridge_contract": { "address": "0xXXX", "deployment_block_height": 0}, "token_vesting_contract": { "address": "0xXXX", "deployment_block_height": 0 }, "multisig_control_contract": { "address": "0xXXX", "deployment_block_height": 0 }}`),
BlockchainsSecondaryEthereumConfig: NewJSON(&proto.SecondaryEthereumConfig{}, types.CheckUntypedSecondaryEthereumConfig).Mutable(true).
BlockchainsEVMChainConfig: NewJSON(&proto.EVMChainConfig{}, types.CheckUntypedEVMChainConfig).Mutable(true).
MustUpdate(`{"network_id": "XXX", "chain_id": "XXX", "collateral_bridge_contract": { "address": "0xXXX" }, "confirmations": 3, "multisig_control_contract": {"address": "0xXXX", "deployment_block_height": 0}}`),

ValidatorsEpochLength: NewDuration(gte1s, lte255h).Mutable(true).MustUpdate("24h0m0s"),
Expand Down
8 changes: 4 additions & 4 deletions core/netparams/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ const (
SpamProtectionUpdateProfileMinFunds = "spam.protection.updatePartyProfile.min.funds"

// blockchain specifics?
BlockchainsPrimaryEthereumConfig = "blockchains.ethereumConfig"
BlockchainsSecondaryEthereumConfig = "blockchains.secondaryEthereumConfig"
BlockchainsEthereumL2Configs = "blockchains.ethereumRpcAndEvmCompatDataSourcesConfig"
BlockchainsPrimaryEthereumConfig = "blockchains.ethereumConfig"
BlockchainsEVMChainConfig = "blockchains.evmChainConfig"
BlockchainsEthereumL2Configs = "blockchains.ethereumRpcAndEvmCompatDataSourcesConfig"

// length of epoch in seconds.
ValidatorsEpochLength = "validators.epoch.length"
Expand Down Expand Up @@ -376,7 +376,7 @@ var AllKeys = map[string]struct{}{
GovernanceProposalReferralProgramMinProposerBalance: {},
GovernanceProposalReferralProgramMinVoterBalance: {},
BlockchainsPrimaryEthereumConfig: {},
BlockchainsSecondaryEthereumConfig: {},
BlockchainsEVMChainConfig: {},
MarketLiquidityProvisionShapesMaxSize: {},
MarketProbabilityOfTradingTauScaling: {},
MarketMinProbabilityOfTradingForLPOrders: {},
Expand Down
2 changes: 1 addition & 1 deletion core/netparams/netparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
// a list of network parameter which cannot be updated.
updateDisallowed = []string{
BlockchainsPrimaryEthereumConfig,
BlockchainsSecondaryEthereumConfig,
BlockchainsEVMChainConfig,
}
)

Expand Down
6 changes: 3 additions & 3 deletions core/netparams/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func (s *Store) LoadState(ctx context.Context, pl *types.Payload) ([]types.State
// TODO use a UpgradeFrom tag when we know which versions we will upgrade from
if vgcontext.InProgressUpgrade(ctx) {
haveConfig := false
secondaryChainConfig := &vegapb.SecondaryEthereumConfig{}
if err := s.GetJSONStruct(BlockchainsSecondaryEthereumConfig, secondaryChainConfig); err == nil {
secondaryChainConfig := &vegapb.EVMChainConfig{}
if err := s.GetJSONStruct(BlockchainsEVMChainConfig, secondaryChainConfig); err == nil {
haveConfig = secondaryChainConfig.ChainId != ""
}

Expand All @@ -162,7 +162,7 @@ func (s *Store) LoadState(ctx context.Context, pl *types.Payload) ([]types.State
if !ok {
panic("Missing secondary ethereum configuration")
}
if err := s.UpdateOptionalValidation(ctx, BlockchainsSecondaryEthereumConfig, secondaryEthConf, false, false); err != nil {
if err := s.UpdateOptionalValidation(ctx, BlockchainsEVMChainConfig, secondaryEthConf, false, false); err != nil {
return nil, err
}
}
Expand Down
8 changes: 4 additions & 4 deletions core/processor/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ func (app *App) ensureConfig() {
_ = app.gov.OnChainIDUpdate(primaryChainID)
_ = app.exec.OnChainIDUpdate(primaryChainID)

secondaryChainConfig := &proto.SecondaryEthereumConfig{}
if err := app.netp.GetJSONStruct(netparams.BlockchainsSecondaryEthereumConfig, secondaryChainConfig); err != nil {
secondaryChainConfig := &proto.EVMChainConfig{}
if err := app.netp.GetJSONStruct(netparams.BlockchainsEVMChainConfig, secondaryChainConfig); err != nil {
return
}
secondaryChainID, err := strconv.ParseUint(secondaryChainConfig.ChainId, 10, 64)
Expand Down Expand Up @@ -2723,8 +2723,8 @@ func (app *App) OnBlockchainPrimaryEthereumConfigUpdate(_ context.Context, conf
return app.gov.OnChainIDUpdate(cID)
}

func (app *App) OnBlockchainSecondaryEthereumConfigUpdate(_ context.Context, conf any) error {
cfg, err := types.SecondaryEthereumConfigFromUntypedProto(conf)
func (app *App) OnBlockchainEVMChainConfigUpdate(_ context.Context, conf any) error {
cfg, err := types.EVMChainConfigFromUntypedProto(conf)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions core/protocol/all_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,9 @@ func (svcs *allServices) setupNetParameters(powWatchers []netparams.WatchParam)
},
},
{
Param: netparams.BlockchainsSecondaryEthereumConfig,
Param: netparams.BlockchainsEVMChainConfig,
Watcher: func(ctx context.Context, cfg interface{}) error {
ethCfg, err := types.SecondaryEthereumConfigFromUntypedProto(cfg)
ethCfg, err := types.EVMChainConfigFromUntypedProto(cfg)
if err != nil {
return fmt.Errorf("invalid secondary ethereum configuration: %w", err)
}
Expand Down Expand Up @@ -931,13 +931,13 @@ func (svcs *allServices) setupNetParameters(powWatchers []netparams.WatchParam)
},
},
{
Param: netparams.BlockchainsSecondaryEthereumConfig,
Param: netparams.BlockchainsEVMChainConfig,
Watcher: func(_ context.Context, cfg interface{}) error {
// nothing to do if not a validator
if !svcs.conf.HaveEthClient() {
return nil
}
ethCfg, err := types.SecondaryEthereumConfigFromUntypedProto(cfg)
ethCfg, err := types.EVMChainConfigFromUntypedProto(cfg)
if err != nil {
return fmt.Errorf("invalid secondary ethereum configuration: %w", err)
}
Expand Down Expand Up @@ -979,9 +979,9 @@ func (svcs *allServices) setupNetParameters(powWatchers []netparams.WatchParam)
},
},
{
Param: netparams.BlockchainsSecondaryEthereumConfig,
Param: netparams.BlockchainsEVMChainConfig,
Watcher: func(_ context.Context, cfg interface{}) error {
ethCfg, err := types.SecondaryEthereumConfigFromUntypedProto(cfg)
ethCfg, err := types.EVMChainConfigFromUntypedProto(cfg)
if err != nil {
return fmt.Errorf("invalid secondary ethereum configuration: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion core/protocol/engines.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
type EventForwarderEngine interface {
ReloadConf(evtforward.Config)
SetupEthereumEngine(evtfwdeth.Client, evtfwdeth.Forwarder, evtfwdeth.Config, *types.EthereumConfig, evtfwdeth.Assets) error
SetupSecondaryEthereumEngine(evtfwdeth.Client, evtfwdeth.Forwarder, evtfwdeth.Config, *types.SecondaryEthereumConfig, evtfwdeth.Assets) error
SetupSecondaryEthereumEngine(evtfwdeth.Client, evtfwdeth.Forwarder, evtfwdeth.Config, *types.EVMChainConfig, evtfwdeth.Assets) error
Start()
Stop()

Expand Down
4 changes: 2 additions & 2 deletions core/protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ func New(
Watcher: proto.App.OnBlockchainPrimaryEthereumConfigUpdate,
},
netparams.WatchParam{
Param: netparams.BlockchainsSecondaryEthereumConfig,
Watcher: proto.App.OnBlockchainSecondaryEthereumConfigUpdate,
Param: netparams.BlockchainsEVMChainConfig,
Watcher: proto.App.OnBlockchainEVMChainConfigUpdate,
},
)

Expand Down
44 changes: 22 additions & 22 deletions core/types/ethereum_secondary.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,34 @@ import (
proto "code.vegaprotocol.io/vega/protos/vega"
)

type SecondaryEthereumConfig struct {
type EVMChainConfig struct {
chainID string
networkID string
confirmations uint64
collateralBridge EthereumContract
multiSigControl EthereumContract
}

func SecondaryEthereumConfigFromUntypedProto(v interface{}) (*SecondaryEthereumConfig, error) {
cfg, err := toSecondaryEthereumConfigProto(v)
func EVMChainConfigFromUntypedProto(v interface{}) (*EVMChainConfig, error) {
cfg, err := toEVMChainConfigProto(v)
if err != nil {
return nil, fmt.Errorf("couldn't convert untyped proto to SecondaryEthereumConfig proto: %w", err)
return nil, fmt.Errorf("couldn't convert untyped proto to EVMChainConfig proto: %w", err)
}

ethConfig, err := SecondaryConfigFromProto(cfg)
if err != nil {
return nil, fmt.Errorf("couldn't build SecondaryEthereumConfig: %w", err)
return nil, fmt.Errorf("couldn't build EVMChainConfig: %w", err)
}

return ethConfig, nil
}

func SecondaryConfigFromProto(cfgProto *proto.SecondaryEthereumConfig) (*SecondaryEthereumConfig, error) {
if err := CheckSecondaryEthereumConfig(cfgProto); err != nil {
func SecondaryConfigFromProto(cfgProto *proto.EVMChainConfig) (*EVMChainConfig, error) {
if err := CheckEVMChainConfig(cfgProto); err != nil {
return nil, fmt.Errorf("invalid second ethereum configuration: %w", err)
}

cfg := &SecondaryEthereumConfig{
cfg := &EVMChainConfig{
chainID: cfgProto.ChainId,
networkID: cfgProto.NetworkId,
confirmations: uint64(cfgProto.Confirmations),
Expand All @@ -65,39 +65,39 @@ func SecondaryConfigFromProto(cfgProto *proto.SecondaryEthereumConfig) (*Seconda
return cfg, nil
}

func (c *SecondaryEthereumConfig) ChainID() string {
func (c *EVMChainConfig) ChainID() string {
return c.chainID
}

func (c *SecondaryEthereumConfig) NetworkID() string {
func (c *EVMChainConfig) NetworkID() string {
return c.networkID
}

func (c *SecondaryEthereumConfig) Confirmations() uint64 {
func (c *EVMChainConfig) Confirmations() uint64 {
return c.confirmations
}

func (c *SecondaryEthereumConfig) CollateralBridge() EthereumContract {
func (c *EVMChainConfig) CollateralBridge() EthereumContract {
return c.collateralBridge
}

func (c *SecondaryEthereumConfig) MultiSigControl() EthereumContract {
func (c *EVMChainConfig) MultiSigControl() EthereumContract {
return c.multiSigControl
}

// CheckUntypedSecondaryEthereumConfig verifies the `v` parameter is a proto.SecondaryEthereumConfig
// CheckUntypedEVMChainConfig verifies the `v` parameter is a proto.EVMChainConfig
// struct and check if it's valid.
func CheckUntypedSecondaryEthereumConfig(v interface{}, _ interface{}) error {
cfg, err := toSecondaryEthereumConfigProto(v)
func CheckUntypedEVMChainConfig(v interface{}, _ interface{}) error {
cfg, err := toEVMChainConfigProto(v)
if err != nil {
return err
}

return CheckSecondaryEthereumConfig(cfg)
return CheckEVMChainConfig(cfg)
}

// CheckSecondaryEthereumConfig verifies the proto.SecondaryEthereumConfig is valid.
func CheckSecondaryEthereumConfig(cfgProto *proto.SecondaryEthereumConfig) error {
// CheckEVMChainConfig verifies the proto.EVMChainConfig is valid.
func CheckEVMChainConfig(cfgProto *proto.EVMChainConfig) error {
if len(cfgProto.NetworkId) == 0 {
return ErrMissingNetworkID
}
Expand Down Expand Up @@ -126,10 +126,10 @@ func CheckSecondaryEthereumConfig(cfgProto *proto.SecondaryEthereumConfig) error
return nil
}

func toSecondaryEthereumConfigProto(v interface{}) (*proto.SecondaryEthereumConfig, error) {
cfg, ok := v.(*proto.SecondaryEthereumConfig)
func toEVMChainConfigProto(v interface{}) (*proto.EVMChainConfig, error) {
cfg, ok := v.(*proto.EVMChainConfig)
if !ok {
return nil, fmt.Errorf("type %q is not a SecondaryEthereumConfig proto", vgreflect.TypeName(v))
return nil, fmt.Errorf("type %q is not a EVMChainConfig proto", vgreflect.TypeName(v))
}
return cfg, nil
}
4 changes: 2 additions & 2 deletions core/validators/erc20multisig/erc20multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func NewERC20MultisigTopology(
})
} else {
_ = netp.Watch(netparams.WatchParam{
Param: netparams.BlockchainsSecondaryEthereumConfig,
Param: netparams.BlockchainsEVMChainConfig,
Watcher: func(_ context.Context, cfg interface{}) error {
ethCfg, err := types.SecondaryEthereumConfigFromUntypedProto(cfg)
ethCfg, err := types.EVMChainConfigFromUntypedProto(cfg)
if err != nil {
return fmt.Errorf("ERC20 multisig didn't receive a valid Ethereum configuration: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions protos/sources/vega/vega.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ message EthereumConfig {
string network_id = 1;
// Chain ID of this Ethereum network.
string chain_id = 2;
//// Contract configuration of the collateral bridge contract for this Ethereum network.
// Contract configuration of the collateral bridge contract for this Ethereum network.
EthereumContractConfig collateral_bridge_contract = 3;
// Number of block confirmations to wait to consider an Ethereum transaction trusted.
// An Ethereum block is trusted when there are at least "n" blocks confirmed by the
Expand All @@ -1561,13 +1561,13 @@ message EthereumConfig {
EthereumContractConfig multisig_control_contract = 7;
}

// Secondary Ethereum configuration details.
message SecondaryEthereumConfig {
// EVM Chain configuration details.
message EVMChainConfig {
// Network ID of this EVM compatible network.
string network_id = 1;
// Chain ID of this EVM compatible network.
string chain_id = 2;
//// Contract configuration of the collateral bridge contract for this EVM compatible network.
// Contract configuration of the collateral bridge contract for this EVM compatible network.
EthereumContractConfig collateral_bridge_contract = 3;
// Number of block confirmations to wait to consider an EVM compatible chain transaction trusted.
// An EVM compatible chain block is trusted when there are at least "n" blocks confirmed by the
Expand Down
Loading

0 comments on commit 96f8ff8

Please sign in to comment.