Skip to content

Commit

Permalink
fix: Value assets chain ID using network parameters
Browse files Browse the repository at this point in the history
Non-validator nodes do not have a Ethereum client setup, so we can't use it to value the assets' chain ID.
  • Loading branch information
ValentinTrinque committed Feb 27, 2024
1 parent 59d4aea commit fa2ebae
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 25 deletions.
7 changes: 6 additions & 1 deletion core/assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ type Service struct {
ethToVega map[string]string
isValidator bool

bridgeView ERC20BridgeView
bridgeView ERC20BridgeView
ethereumChainID string
}

func New(
Expand Down Expand Up @@ -462,3 +463,7 @@ func (s *Service) validateAsset(a *Asset) error {

return err
}

func (s *Service) OnEthereumChainIDUpdated(chainID string) {
s.ethereumChainID = chainID
}
1 change: 0 additions & 1 deletion core/assets/erc20/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type ETHClient interface {
CollateralBridgeAddress() ethcommon.Address
CurrentHeight(context.Context) (uint64, error)
ConfirmationsRequired() uint64
ConfiguredChainID() string
}

type ERC20 struct {
Expand Down
4 changes: 0 additions & 4 deletions core/assets/erc20/erc20_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ type testEthClient struct {
bind.ContractBackend
}

func (testEthClient) ConfiguredChainID() string {
return "1"
}

func (testEthClient) HeaderByNumber(context.Context, *big.Int) (*ethtypes.Header, error) {
return nil, nil
}
Expand Down
14 changes: 0 additions & 14 deletions core/assets/erc20/mocks/eth_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/assets/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (s *Service) applyMigrations(ctx context.Context, p *types.Asset) {
// the chain ID they originated from. So, when loaded, assets without a chain
// ID are automatically considered to originate from Ethereum Mainnet.
if erc20 := p.Details.GetERC20(); erc20 != nil && erc20.ChainID == "" {
erc20.ChainID = s.ethClient.ConfiguredChainID()
erc20.ChainID = s.ethereumChainID
// Ensure the assets are updated in the data-node.
s.broker.Send(events.NewAssetEvent(ctx, *p))
}
Expand Down
4 changes: 0 additions & 4 deletions core/client/eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ func Dial(ctx context.Context, cfg Config) (*Client, error) {
return &Client{ETHClient: newEthClientWrapper(ethClient), cfg: cfg}, nil
}

func (c *Client) ConfiguredChainID() string {
return c.ethConfig.ChainID()
}

func (c *Client) UpdateEthereumConfig(ctx context.Context, ethConfig *types.EthereumConfig) error {
if c == nil {
return nil
Expand Down
12 changes: 12 additions & 0 deletions core/protocol/all_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,18 @@ func (svcs *allServices) setupNetParameters(powWatchers []netparams.WatchParam)
return nil
},
},
{
Param: netparams.BlockchainsEthereumConfig,
Watcher: func(_ context.Context, cfg interface{}) error {
ethCfg, err := types.EthereumConfigFromUntypedProto(cfg)
if err != nil {
return fmt.Errorf("invalid ethereum configuration: %w", err)
}

svcs.assets.OnEthereumChainIDUpdated(ethCfg.ChainID())
return nil
},
},
{
Param: netparams.BlockchainsEthereumL2Configs,
Watcher: func(ctx context.Context, cfg interface{}) error {
Expand Down

0 comments on commit fa2ebae

Please sign in to comment.