Skip to content

Commit

Permalink
feat(cannon): Improved network name overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Sep 29, 2023
1 parent 5f382c6 commit 0a06e23
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
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

0 comments on commit 0a06e23

Please sign in to comment.