Commit e75369bb authored by Michael de Hoog's avatar Michael de Hoog

Rename chain to opstack

parent 0f83dda8
......@@ -75,7 +75,7 @@ func (conf *Config) Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort
} else {
return nil, nil, fmt.Errorf("no TCP port to put in discovery record")
}
dat := ChainENRData{
dat := OpStackENRData{
chainID: rollupCfg.L2ChainID.Uint64(),
version: 0,
}
......@@ -167,18 +167,18 @@ func enrToAddrInfo(r *enode.Node) (*peer.AddrInfo, *crypto.Secp256k1PublicKey, e
}, pub, nil
}
// The discovery ENRs are just key-value lists, and we filter them by records tagged with the "chain" key,
// The discovery ENRs are just key-value lists, and we filter them by records tagged with the "opstack" key,
// and then check the chain ID and version.
type ChainENRData struct {
type OpStackENRData struct {
chainID uint64
version uint64
}
func (o *ChainENRData) ENRKey() string {
return "chain"
func (o *OpStackENRData) ENRKey() string {
return "opstack"
}
func (o *ChainENRData) EncodeRLP(w io.Writer) error {
func (o *OpStackENRData) EncodeRLP(w io.Writer) error {
out := make([]byte, 2*binary.MaxVarintLen64)
offset := binary.PutUvarint(out, o.chainID)
offset += binary.PutUvarint(out[offset:], o.version)
......@@ -187,13 +187,13 @@ func (o *ChainENRData) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, out)
}
func (o *ChainENRData) DecodeRLP(s *rlp.Stream) error {
func (o *OpStackENRData) DecodeRLP(s *rlp.Stream) error {
b, err := s.Bytes()
if err != nil {
return fmt.Errorf("failed to decode outer ENR entry: %w", err)
}
// We don't check the byte length: the below readers are limited, and the ENR itself has size limits.
// Future "optimism" entries may contain additional data, and will be tagged with a newer version etc.
// Future "opstack" entries may contain additional data, and will be tagged with a newer version etc.
r := bytes.NewReader(b)
chainID, err := binary.ReadUvarint(r)
if err != nil {
......@@ -208,15 +208,15 @@ func (o *ChainENRData) DecodeRLP(s *rlp.Stream) error {
return nil
}
var _ enr.Entry = (*ChainENRData)(nil)
var _ enr.Entry = (*OpStackENRData)(nil)
func FilterEnodes(log log.Logger, cfg *rollup.Config) func(node *enode.Node) bool {
return func(node *enode.Node) bool {
var dat ChainENRData
var dat OpStackENRData
err := node.Load(&dat)
// if the entry does not exist, or if it is invalid, then ignore the node
if err != nil {
log.Debug("discovered node record has no chain info", "node", node.ID(), "err", err)
log.Debug("discovered node record has no opstack info", "node", node.ID(), "err", err)
return false
}
// check chain ID matches
......@@ -347,7 +347,7 @@ func (n *NodeP2P) DiscoveryProcess(ctx context.Context, log log.Logger, cfg *rol
log.Info("stopped peer discovery")
return // no ctx error, expected close
case found := <-randomNodesCh:
var dat ChainENRData
var dat OpStackENRData
if err := found.Load(&dat); err != nil { // we already filtered on chain ID and version
continue
}
......@@ -362,7 +362,7 @@ func (n *NodeP2P) DiscoveryProcess(ctx context.Context, log log.Logger, cfg *rol
// Tag the peer, we'd rather have the connection manager prune away old peers,
// or peers on different chains, or anyone we have not seen via discovery.
// There is no tag score decay yet, so just set it to 42.
n.ConnectionManager().TagPeer(info.ID, fmt.Sprintf("chain-%d-%d", dat.chainID, dat.version), 42)
n.ConnectionManager().TagPeer(info.ID, fmt.Sprintf("opstack-%d-%d", dat.chainID, dat.version), 42)
log.Debug("discovered peer", "peer", info.ID, "nodeID", found.ID(), "addr", info.Addrs[0])
case <-connectTicker.C:
connected := n.Host().Network().Peers()
......
......@@ -47,7 +47,7 @@ func (p *Prepared) Host(log log.Logger, reporter metrics.Reporter) (host.Host, e
// Discovery creates a disc-v5 service. Returns nil, nil, nil if discovery is disabled.
func (p *Prepared) Discovery(log log.Logger, rollupCfg *rollup.Config, tcpPort uint16) (*enode.LocalNode, *discover.UDPv5, error) {
if p.LocalNode != nil {
dat := ChainENRData{
dat := OpStackENRData{
chainID: rollupCfg.L2ChainID.Uint64(),
version: 0,
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment