From 4d9bc6153ab605310f266564b20d9f488a5be6cb Mon Sep 17 00:00:00 2001 From: fearlessfe <505380967@qq.com> Date: Sat, 7 Dec 2024 12:10:07 +0800 Subject: [PATCH 1/2] fix: findNodes err and add build images ci --- .github/workflows/image.yaml | 43 +++++++++++++++++++++++++++++++++++ Dockerfile | 7 +++--- portalwire/portal_protocol.go | 11 +++++---- 3 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/image.yaml diff --git a/.github/workflows/image.yaml b/.github/workflows/image.yaml new file mode 100644 index 0000000..10010c4 --- /dev/null +++ b/.github/workflows/image.yaml @@ -0,0 +1,43 @@ +name: shisui latest image + +on: + push: + branches: [main] + +defaults: + run: + shell: bash + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + push_image_to_github: + name: Push Docker image to Github + runs-on: ubuntu-latest + permissions: write-all + steps: + - name: Check out the repo + uses: actions/checkout@v4 + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile.portal + push: true + tags: ${{ env.REGISTRY }}/${{ github.repository }}:latest diff --git a/Dockerfile b/Dockerfile index e65815f..706f49b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,13 @@ -FROM --platform=linux/amd64 golang:1.23 as builder +FROM golang:1.23 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/shisui/main.go + RUN make shisui -FROM --platform=linux/amd64 ubuntu:22.04 +FROM ubuntu:22.04 COPY --from=builder /app/build/bin/shisui /usr/local/bin/app diff --git a/portalwire/portal_protocol.go b/portalwire/portal_protocol.go index 25ee448..00b4489 100644 --- a/portalwire/portal_protocol.go +++ b/portalwire/portal_protocol.go @@ -315,10 +315,11 @@ func (p *PortalProtocol) setupDiscV5AndTable() error { } cfg := discover.Config{ - PrivateKey: p.PrivateKey, - NetRestrict: p.NetRestrict, - Bootnodes: p.BootstrapNodes, - Log: p.Log, + PrivateKey: p.PrivateKey, + NetRestrict: p.NetRestrict, + Bootnodes: p.BootstrapNodes, + Log: p.Log, + NoFindnodeLivenessCheck: true, } p.table, err = discover.NewTable(p, p.localNode.Database(), cfg) @@ -970,7 +971,7 @@ func (p *PortalProtocol) handleFindNodes(fromAddr *net.UDPAddr, request *FindNod enrs := p.truncateNodes(nodes, maxPayloadSize, enrOverhead) nodesMsg := &Nodes{ - Total: 1, + Total: uint8(len(enrs)), Enrs: enrs, } From 99e6a62b9a076a341e8091010290f65735987029 Mon Sep 17 00:00:00 2001 From: fearlessfe <505380967@qq.com> Date: Sun, 8 Dec 2024 11:59:34 +0800 Subject: [PATCH 2/2] fix: use AddFoundNode method replace AddInboundNode --- portalwire/portal_protocol.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/portalwire/portal_protocol.go b/portalwire/portal_protocol.go index 00b4489..76e63d0 100644 --- a/portalwire/portal_protocol.go +++ b/portalwire/portal_protocol.go @@ -280,7 +280,7 @@ func (p *PortalProtocol) RoutingTableInfo() [][]string { } func (p *PortalProtocol) AddEnr(n *enode.Node) { - added := p.table.AddInboundNode(n) + added := p.table.AddFoundNode(n, true) if !added { p.Log.Warn("add node failed", "id", n.ID(), "ip", n.IPAddr()) return @@ -315,11 +315,10 @@ func (p *PortalProtocol) setupDiscV5AndTable() error { } cfg := discover.Config{ - PrivateKey: p.PrivateKey, - NetRestrict: p.NetRestrict, - Bootnodes: p.BootstrapNodes, - Log: p.Log, - NoFindnodeLivenessCheck: true, + PrivateKey: p.PrivateKey, + NetRestrict: p.NetRestrict, + Bootnodes: p.BootstrapNodes, + Log: p.Log, } p.table, err = discover.NewTable(p, p.localNode.Database(), cfg) @@ -971,7 +970,9 @@ func (p *PortalProtocol) handleFindNodes(fromAddr *net.UDPAddr, request *FindNod enrs := p.truncateNodes(nodes, maxPayloadSize, enrOverhead) nodesMsg := &Nodes{ - Total: uint8(len(enrs)), + // https://github.com/ethereum/portal-network-specs/blob/master/portal-wire-protocol.md + // total: The total number of Nodes response messages being sent. Currently fixed to only 1 response message. + Total: 1, Enrs: enrs, }