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

fix(cannon): Improve network name overrides #214

Merged
merged 6 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions pkg/cannon/ethereum/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func NewBeaconNode(ctx context.Context, name string, config *Config, log logrus.

metadata := services.NewMetadataService(log, node)

if config.OverrideNetworkName != "" {
metadata.OverrideNetworkName(config.OverrideNetworkName)
}

svcs := []services.Service{
&metadata,
}
Expand Down
24 changes: 18 additions & 6 deletions pkg/cannon/ethereum/services/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type MetadataService struct {
beacon beacon.Node
log logrus.FieldLogger

Network *networks.Network
overrideNetworkName string
Network *networks.Network

Genesis *v1.Genesis
Spec *state.Spec
Expand All @@ -35,14 +36,21 @@ type MetadataService struct {

func NewMetadataService(log logrus.FieldLogger, sbeacon beacon.Node) MetadataService {
return MetadataService{
beacon: sbeacon,
log: log.WithField("module", "cannon/ethereum/metadata"),
Network: &networks.Network{Name: networks.NetworkNameNone},
onReadyCallbacks: []func(context.Context) error{},
mu: sync.Mutex{},
overrideNetworkName: "",
beacon: sbeacon,
log: log.WithField("module", "cannon/ethereum/metadata"),
Network: &networks.Network{Name: networks.NetworkNameNone},
onReadyCallbacks: []func(context.Context) error{},
mu: sync.Mutex{},
}
}

func (m *MetadataService) OverrideNetworkName(name string) {
m.log.WithField("name", name).Info("Overriding network name")

m.overrideNetworkName = name
}

func (m *MetadataService) Start(ctx context.Context) error {
go func() {
operation := func() error {
Expand Down Expand Up @@ -153,6 +161,10 @@ func (m *MetadataService) DeriveNetwork(_ context.Context) error {

network := networks.DeriveFromGenesisRoot(xatuethv1.RootAsString(m.Genesis.GenesisValidatorsRoot))

if m.overrideNetworkName != "" {
network.Name = networks.NetworkName(m.overrideNetworkName)
}

if network.Name != m.Network.Name {
m.log.WithFields(logrus.Fields{
"name": network.Name,
Expand Down
1 change: 1 addition & 0 deletions pkg/networks/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var NetworkGenesisRoots = map[string]uint64{
"0x4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95": 1,
"0x043db0d9a83813551ee2f33450d23797757d430911a9320530ad8a0eabc43efb": 5,
"0xd8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b8078": 11155111,
"0x0ea3f6f9515823b59c863454675fefcd1d8b4f2dbe454db166206a41fda060a0": 17000,
}

var NetworkIds = map[uint64]NetworkName{
Expand Down
Loading