Merge branch 'v1.2.4-beta-candidate' of github.com:maticnetwork/bor into v1.2.4-beta-candidate

This commit is contained in:
Arpit Temani 2024-01-30 13:17:09 +05:30
commit 9ca58d452f
2 changed files with 25 additions and 21 deletions

View file

@ -15,7 +15,8 @@
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
// bootnode runs a bootstrap node for the Ethereum Discovery Protocol. // bootnode runs a bootstrap node for the Ethereum Discovery Protocol.
package main // Keep package as bootnode during upstram merge.
package bootnode
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
@ -34,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/netutil" "github.com/ethereum/go-ethereum/p2p/netutil"
) )
// nolint
func main() { func main() {
var ( var (
listenAddr = flag.String("addr", ":30301", "listen address") listenAddr = flag.String("addr", ":30301", "listen address")
@ -213,3 +215,12 @@ func doPortMapping(natm nat.Interface, ln *enode.LocalNode, addr *net.UDPAddr) *
return extaddr return extaddr
} }
// Implemented separate functions so that there are minimal conflicts during upstream merge
func PrintNotice(nodeKey *ecdsa.PublicKey, addr net.UDPAddr) {
printNotice(nodeKey, addr)
}
func DoPortMapping(natm nat.Interface, ln *enode.LocalNode, addr *net.UDPAddr) *net.UDPAddr {
return doPortMapping(natm, ln, addr)
}

View file

@ -13,6 +13,7 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/ethereum/go-ethereum/cmd/bootnode"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/internal/cli/flagset" "github.com/ethereum/go-ethereum/internal/cli/flagset"
@ -213,33 +214,25 @@ func (b *BootnodeCommand) Run(args []string) int {
} }
conn, err := net.ListenUDP("udp", addr) conn, err := net.ListenUDP("udp", addr)
if err != nil { if err != nil {
b.UI.Error(fmt.Sprintf("failed to listen udp addr '%s': %v", b.listenAddr, err)) b.UI.Error(fmt.Sprintf("failed to listen udp addr '%s': %v", b.listenAddr, err))
return 1 return 1
} }
defer conn.Close()
realaddr := conn.LocalAddr().(*net.UDPAddr)
if natm != nil {
if !realaddr.IP.IsLoopback() {
go nat.Map(natm, nil, "udp", realaddr.Port, realaddr.Port, "ethereum discovery")
}
if ext, err := natm.ExternalIP(); err == nil {
// nolint: govet
realaddr = &net.UDPAddr{IP: ext, Port: realaddr.Port}
}
}
n := enode.NewV4(&nodeKey.PublicKey, addr.IP, addr.Port, addr.Port)
b.UI.Info(n.String())
if b.dryRun {
return 0
}
db, _ := enode.OpenDB("") db, _ := enode.OpenDB("")
ln := enode.NewLocalNode(db, nodeKey) ln := enode.NewLocalNode(db, nodeKey)
listenerAddr := conn.LocalAddr().(*net.UDPAddr)
if natm != nil {
natAddr := bootnode.DoPortMapping(natm, ln, listenerAddr)
if natAddr != nil {
listenerAddr = natAddr
}
}
bootnode.PrintNotice(&nodeKey.PublicKey, *listenerAddr)
cfg := discover.Config{ cfg := discover.Config{
PrivateKey: nodeKey, PrivateKey: nodeKey,
Log: log.Root(), Log: log.Root(),