fix: panic

This commit is contained in:
fearlessfe 2024-05-06 23:53:09 +08:00
parent e660629a78
commit bb0714d9a5
3 changed files with 34 additions and 4 deletions

View file

@ -3,7 +3,7 @@
![AppVeyor Build (with branch)](https://ci.appveyor.com/api/projects/status/github/optimism-java/shisui?branch=portal&svg=true) ![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) [![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". 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. > **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 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 ### Hardware Requirements
Minimum: Minimum:

View file

@ -1006,7 +1006,7 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
PortalPrivateKeyFlag = &cli.StringFlag{ PortalPrivateKeyFlag = &cli.StringFlag{
Name: "private.key", 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, Category: flags.PortalNetworkCategory,
} }

View file

@ -88,6 +88,8 @@ var ErrNilContentKey = errors.New("content key cannot be nil")
var ContentNotFound = storage.ErrContentNotFound var ContentNotFound = storage.ErrContentNotFound
var ErrEmptyResp = errors.New("empty resp")
var MaxDistance = hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") var MaxDistance = hexutil.MustDecode("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
type ContentElement struct { 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) _, err := p.DiscV5.TalkRequest(target, string(portalwire.UTPNetwork), buf)
return len(buf), err 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) { func (p *PortalProtocol) processOffer(target *enode.Node, resp []byte, request *OfferRequest) ([]byte, error) {
var err error var err error
if len(resp) == 0 {
return nil, ErrEmptyResp
}
if resp[0] != portalwire.ACCEPT { if resp[0] != portalwire.ACCEPT {
return nil, fmt.Errorf("invalid accept response") 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) { 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 { if resp[0] != portalwire.CONTENT {
return 0xff, nil, fmt.Errorf("invalid content response") 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) { 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 { if resp[0] != portalwire.NODES {
return nil, fmt.Errorf("invalid nodes response") 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) { func (p *PortalProtocol) processPong(target *enode.Node, resp []byte) (*portalwire.Pong, error) {
if len(resp) == 0 { if len(resp) == 0 {
return nil, fmt.Errorf("empty resp") return nil, ErrEmptyResp
} }
if resp[0] != portalwire.PONG { if resp[0] != portalwire.PONG {
return nil, fmt.Errorf("invalid pong response") return nil, fmt.Errorf("invalid pong response")