From bb0714d9a592b04f1cdb73fe906abd1336fe7a4f Mon Sep 17 00:00:00 2001 From: fearlessfe <505380967@qq.com> Date: Mon, 6 May 2024 23:53:09 +0800 Subject: [PATCH] fix: panic --- README.md | 15 ++++++++++++++- cmd/utils/flags.go | 2 +- p2p/discover/portal_protocol.go | 21 +++++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 554b45f4b668..2f90e51d2f3b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![AppVeyor Build (with branch)](https://ci.appveyor.com/api/projects/status/github/optimism-java/shisui?branch=portal&svg=true) [![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://discord.gg/HBAgaHCBuY) -Shisui is an [Ethereum portal client](https://github.com/ethereum/portal-network-specs) written in Go language based [go-ethereum](https://github.com/ethereum/go-ethereum) and [erigon](https://github.com/ledgerwatch/erigon). +Shisui is an [Ethereum portal client](https://github.com/ethereum/portal-network-specs) written in Go language based on [go-ethereum](https://github.com/ethereum/go-ethereum). The name is inspired by Uchiha Shisui from the anime Naruto, who is renowned as "Shisui of the Body Flicker". > **Note:** Shisui is still **under heavy development** and is not yet ready for production use. @@ -39,6 +39,19 @@ Alternatively, you can run the docker image by running docker run -d -p 8545:8545 -p 9009:9009/udp ghcr.io/optimism-java/shisui:latest ``` +### supported options + +* `--rpc.addr` HTTP-RPC server listening addr +* `--rpc.port` HTTP-RPC server listening port(default: `8545`) +* `--data.dir` data dir of where the data file located(default: `./`) +* `--data.capacity` the capacity of the data stored, the unit is MB(default: `10GB`) +* `--udp.addr` protocol UDP server listening interface(default: local ip) +* `--udp.addr` protocol UDP server listening port(default: `9009`) +* `--loglevel` loglevel of portal network, `1` to `5`, from `error` to `trace`(default: `1`) +* `--private.key` private key of p2p node, hex format without `0x` prifix +* `--bootnodes` bootnode of p2p network with ENR format +* `--networks` portal sub networks: history, beacon, state + ### Hardware Requirements Minimum: diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 6ee06212a07a..72d2c47a3445 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1006,7 +1006,7 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server. PortalPrivateKeyFlag = &cli.StringFlag{ Name: "private.key", - Usage: "private key of p2p node, hex format", + Usage: "private key of p2p node, hex format without 0x prifix", Category: flags.PortalNetworkCategory, } diff --git a/p2p/discover/portal_protocol.go b/p2p/discover/portal_protocol.go index 8f47fd59b7f5..47225b46e099 100644 --- a/p2p/discover/portal_protocol.go +++ b/p2p/discover/portal_protocol.go @@ -88,6 +88,8 @@ var ErrNilContentKey = errors.New("content key cannot be nil") var ContentNotFound = storage.ErrContentNotFound +var ErrEmptyResp = errors.New("empty resp") + var MaxDistance = hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") type ContentElement struct { @@ -309,7 +311,11 @@ func (p *PortalProtocol) setupUDPListening() error { } } - p.Log.Trace("send to target data", "ip", target.IP().String(), "port", target.UDP(), "bufLength", len(buf)) + if target == nil { + p.Log.Warn("not fount target node info", "ip", addr.IP.To4().String(), "port", addr.Port, "bufLength", len(buf)) + return 0, fmt.Errorf("not found target node info") + } + p.Log.Trace("send to target data", "ip", addr.IP.To4().String(), "port", addr.Port, "bufLength", len(buf)) _, err := p.DiscV5.TalkRequest(target, string(portalwire.UTPNetwork), buf) return len(buf), err }) @@ -494,6 +500,9 @@ func (p *PortalProtocol) offer(node *enode.Node, offerRequest *OfferRequest) ([] func (p *PortalProtocol) processOffer(target *enode.Node, resp []byte, request *OfferRequest) ([]byte, error) { var err error + if len(resp) == 0 { + return nil, ErrEmptyResp + } if resp[0] != portalwire.ACCEPT { return nil, fmt.Errorf("invalid accept response") } @@ -613,6 +622,10 @@ func (p *PortalProtocol) processOffer(target *enode.Node, resp []byte, request * } func (p *PortalProtocol) processContent(target *enode.Node, resp []byte) (byte, interface{}, error) { + if len(resp) == 0 { + return 0x00, nil, ErrEmptyResp + } + if resp[0] != portalwire.CONTENT { return 0xff, nil, fmt.Errorf("invalid content response") } @@ -678,6 +691,10 @@ func (p *PortalProtocol) processContent(target *enode.Node, resp []byte) (byte, } func (p *PortalProtocol) processNodes(target *enode.Node, resp []byte, distances []uint) ([]*enode.Node, error) { + if len(resp) == 0 { + return nil, ErrEmptyResp + } + if resp[0] != portalwire.NODES { return nil, fmt.Errorf("invalid nodes response") } @@ -731,7 +748,7 @@ func (p *PortalProtocol) filterNodes(target *enode.Node, enrs [][]byte, distance func (p *PortalProtocol) processPong(target *enode.Node, resp []byte) (*portalwire.Pong, error) { if len(resp) == 0 { - return nil, fmt.Errorf("empty resp") + return nil, ErrEmptyResp } if resp[0] != portalwire.PONG { return nil, fmt.Errorf("invalid pong response")