diff --git a/Dockerfile.portal b/Dockerfile.portal index 872d4d9ee0..919eac60db 100644 --- a/Dockerfile.portal +++ b/Dockerfile.portal @@ -1,13 +1,13 @@ -FROM golang:1.20.13 as builder +FROM --platform=linux/amd64 golang:1.20.13 as builder WORKDIR /app COPY . . - +RUN go env -w GOPROXY=https://goproxy.cn,direct RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build ./cmd/hive/main.go -FROM ubuntu:22.04 +FROM --platform=linux/amd64 ubuntu:22.04 COPY --from=builder /app/main /usr/local/bin/app diff --git a/cmd/hive/main.go b/cmd/hive/main.go index 3470d3041b..74e57dde5f 100644 --- a/cmd/hive/main.go +++ b/cmd/hive/main.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/p2p/discover" + "github.com/ethereum/go-ethereum/p2p/discover/portalwire" "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/portalnetwork/storage/sqlite" "github.com/ethereum/go-ethereum/rpc" @@ -61,7 +62,7 @@ func main() { contentQueue := make(chan *discover.ContentElement, 50) - protocol, err := discover.NewPortalProtocol(config, "history", privateKey, contentStorage, contentQueue) + protocol, err := discover.NewPortalProtocol(config, string(portalwire.HistoryNetwork), privateKey, contentStorage, contentQueue) if err != nil { panic(err) diff --git a/p2p/discover/portal_protocol.go b/p2p/discover/portal_protocol.go index 2a892a5e13..c0e2dc82cf 100644 --- a/p2p/discover/portal_protocol.go +++ b/p2p/discover/portal_protocol.go @@ -241,7 +241,7 @@ func (p *PortalProtocol) Start() error { } p.DiscV5.RegisterTalkHandler(p.protocolId, p.handleTalkRequest) - p.DiscV5.RegisterTalkHandler(portalwire.UTPNetwork, p.handleUtpTalkRequest) + p.DiscV5.RegisterTalkHandler(string(portalwire.UTPNetwork), p.handleUtpTalkRequest) go p.table.loop() @@ -307,7 +307,7 @@ func (p *PortalProtocol) setupUDPListening() (*net.UDPConn, error) { } p.log.Trace("send to target data", "ip", target.IP().String(), "port", target.UDP(), "bufLength", len(buf)) - _, err := p.DiscV5.TalkRequest(target, portalwire.UTPNetwork, buf) + _, err := p.DiscV5.TalkRequest(target, string(portalwire.UTPNetwork), buf) return len(buf), err }) diff --git a/p2p/discover/portal_protocol_test.go b/p2p/discover/portal_protocol_test.go index 07af0009dd..a5cd1e60b1 100644 --- a/p2p/discover/portal_protocol_test.go +++ b/p2p/discover/portal_protocol_test.go @@ -47,7 +47,7 @@ func setupLocalPortalNode(addr string, bootNodes []*enode.Node) (*PortalProtocol } contentQueue := make(chan *ContentElement, 50) - portalProtocol, err := NewPortalProtocol(conf, portalwire.HistoryNetwork, newkey(), &MockStorage{db: make(map[string][]byte)}, contentQueue) + portalProtocol, err := NewPortalProtocol(conf, string(portalwire.HistoryNetwork), newkey(), &MockStorage{db: make(map[string][]byte)}, contentQueue) if err != nil { return nil, err } @@ -75,8 +75,11 @@ func TestPortalWireProtocolUdp(t *testing.T) { assert.NoError(t, err) time.Sleep(10 * time.Second) - node1Addr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8777") - node2Addr, _ := utp.ResolveUTPAddr("utp", "127.0.0.1:8778") + udpAddrStr1 := fmt.Sprintf("%s:%d", node1.localNode.Node().IP(), node1.localNode.Node().UDP()) + udpAddrStr2 := fmt.Sprintf("%s:%d", node2.localNode.Node().IP(), node2.localNode.Node().UDP()) + + node1Addr, _ := utp.ResolveUTPAddr("utp", udpAddrStr1) + node2Addr, _ := utp.ResolveUTPAddr("utp", udpAddrStr2) cid := uint32(12) cliSendMsgWithCid := "there are connection id : 12!" diff --git a/p2p/discover/portalwire/messages.go b/p2p/discover/portalwire/messages.go index f996be6f4d..a97be1d5af 100644 --- a/p2p/discover/portalwire/messages.go +++ b/p2p/discover/portalwire/messages.go @@ -2,18 +2,6 @@ package portalwire //go:generate sszgen --path p2p/discover/portalwire/messages.go --exclude-objs BlockHeaderProof,PortalReceipts -// Protocol IDs for the portal protocol. -const ( - StateNetwork = "0x500a" - HistoryNetwork = "0x500b" - TxGossipNetwork = "0x500c" - HeaderGossipNetwork = "0x500d" - CanonicalIndicesNetwork = "0x500e" - BeaconLightClientNetwork = "0x501a" - UTPNetwork = "0x757470" - Rendezvous = "0x72656e" -) - // Message codes for the portal protocol. const ( PING byte = 0x00 @@ -50,6 +38,18 @@ const ( PerContentKeyOverhead = 4 ) +// Protocol IDs for the portal protocol. +var ( + StateNetwork = []byte{0x50, 0x0a} + HistoryNetwork = []byte{0x50, 0x0b} + TxGossipNetwork = []byte{0x50, 0x0c} + HeaderGossipNetwork = []byte{0x50, 0x0d} + CanonicalIndicesNetwork = []byte{0x50, 0x0e} + BeaconLightClientNetwork = []byte{0x50, 0x1a} + UTPNetwork = []byte{0x75, 0x74, 0x70} + Rendezvous = []byte{0x72, 0x65, 0x6e} +) + type ContentKV struct { ContentKey []byte Content []byte diff --git a/portalnetwork/history/history_network_test.go b/portalnetwork/history/history_network_test.go index ad616662ea..112444cdd8 100644 --- a/portalnetwork/history/history_network_test.go +++ b/portalnetwork/history/history_network_test.go @@ -353,7 +353,7 @@ func genHistoryNetwork(addr string, bootNodes []*enode.Node) (*HistoryNetwork, e panic("couldn't generate key: " + err.Error()) } - portalProtocol, err := discover.NewPortalProtocol(conf, portalwire.HistoryNetwork, key, &MockStorage{db: make(map[string][]byte)}, contentQueue) + portalProtocol, err := discover.NewPortalProtocol(conf, string(portalwire.HistoryNetwork), key, &MockStorage{db: make(map[string][]byte)}, contentQueue) if err != nil { return nil, err }