Skip to content

Commit

Permalink
Merge pull request ethereum#103 from fearlessfe/fix-panic
Browse files Browse the repository at this point in the history
fix: panic
  • Loading branch information
fearlessfe authored May 7, 2024
2 parents e660629 + bb0714d commit e2702a8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
21 changes: 19 additions & 2 deletions p2p/discover/portal_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e2702a8

Please sign in to comment.