good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 55904950 authored by Alex Sharov's avatar Alex Sharov Committed by GitHub
Browse files

enr discovery (#1690)

parent 7222cdd6
No related branches found
No related tags found
No related merge requests found
......@@ -646,12 +646,13 @@ func (ss *SentryServerImpl) SendMessageToAll(ctx context.Context, req *proto_sen
}
func (ss *SentryServerImpl) SetStatus(_ context.Context, statusData *proto_sentry.StatusData) (*emptypb.Empty, error) {
genesisHash := gointerfaces.ConvertH256ToHash(statusData.ForkData.Genesis)
ss.lock.Lock()
defer ss.lock.Unlock()
init := ss.statusData == nil
if init {
var err error
genesisHash := gointerfaces.ConvertH256ToHash(statusData.ForkData.Genesis)
ss.p2pServer, err = p2pServer(ss.ctx, ss, genesisHash, ss.natSetting, ss.port, ss.staticPeers, ss.discovery, ss.netRestrict)
if err != nil {
return &empty.Empty{}, err
......@@ -661,6 +662,8 @@ func (ss *SentryServerImpl) SetStatus(_ context.Context, statusData *proto_sentr
return &empty.Empty{}, fmt.Errorf("could not start server: %w", err)
}
}
genesisHash = gointerfaces.ConvertH256ToHash(statusData.ForkData.Genesis)
ss.p2pServer.LocalNode().Set(eth.CurrentENREntryFromForks(statusData.ForkData.Forks, genesisHash, statusData.MaxBlock))
ss.statusData = statusData
return &empty.Empty{}, nil
}
......
......@@ -43,14 +43,21 @@ func (e enrEntry) ENRKey() string {
// head events and updates the requested node record whenever a fork is passed.
func StartENRUpdater(chainConfig *params.ChainConfig, genesisHash common.Hash, events *remotedbserver.Events, ln *enode.LocalNode) {
events.AddHeaderSubscription(func(h *types.Header) error {
ln.Set(currentENREntry(chainConfig, genesisHash, h.Number.Uint64()))
ln.Set(CurrentENREntry(chainConfig, genesisHash, h.Number.Uint64()))
return nil
})
}
// currentENREntry constructs an `eth` ENR entry based on the current state of the chain.
func currentENREntry(chainConfig *params.ChainConfig, genesisHash common.Hash, headHeight uint64) *enrEntry {
// CurrentENREntry constructs an `eth` ENR entry based on the current state of the chain.
func CurrentENREntry(chainConfig *params.ChainConfig, genesisHash common.Hash, headHeight uint64) *enrEntry {
return &enrEntry{
ForkID: forkid.NewID(chainConfig, genesisHash, headHeight),
}
}
// CurrentENREntryFromForks constructs an `eth` ENR entry based on the current state of the chain.
func CurrentENREntryFromForks(forks []uint64, genesisHash common.Hash, headHeight uint64) *enrEntry {
return &enrEntry{
ForkID: forkid.NewIDFromForks(forks, genesisHash, headHeight),
}
}
......@@ -115,7 +115,7 @@ func MakeProtocols(backend Backend, network uint64, dnsdisc enode.Iterator, chai
PeerInfo: func(id enode.ID) interface{} {
return backend.PeerInfo(id)
},
Attributes: []enr.Entry{currentENREntry(chainConfig, genesisHash, headHeight)},
Attributes: []enr.Entry{CurrentENREntry(chainConfig, genesisHash, headHeight)},
DialCandidates: dnsdisc,
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment