Skip to content

Commit

Permalink
fix: some portal-hive test err
Browse files Browse the repository at this point in the history
1. add history prifix for json rpc method
2. fix deleteEnr and recursiveFindContent in rpc-compact test
  • Loading branch information
fearlessfe authored and GrapeBaBa committed Jan 29, 2024
1 parent 3936f0b commit c5bf27a
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions p2p/discover/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/holiman/uint256"
)

// json-rpc spec
// https://playground.open-rpc.org/?schemaUrl=https://raw.githubusercontent.com/ethereum/portal-network-specs/assembled-spec/jsonrpc/openrpc.json&uiSchema%5BappBar%5D%5Bui:splitView%5D=false&uiSchema%5BappBar%5D%5Bui:input%5D=false&uiSchema%5BappBar%5D%5Bui:examplesDropdown%5D=false
type DiscV5API struct {
DiscV5 *UDPv5
}
Expand Down Expand Up @@ -214,7 +216,7 @@ func (p *PortalAPI) NodeInfo() *NodeInfo {
}
}

func (p *PortalAPI) RoutingTableInfo() *RoutingTableInfo {
func (p *PortalAPI) HistoryRoutingTableInfo() *RoutingTableInfo {
n := p.portalProtocol.localNode.Node()

closestNodes := p.portalProtocol.table.Nodes()
Expand Down Expand Up @@ -279,7 +281,7 @@ func (p *PortalAPI) HistoryDeleteEnr(nodeId string) (bool, error) {

n := p.portalProtocol.table.getNode(id)
if n == nil {
return false, errors.New("record not in local routing table")
return false, nil
}

p.portalProtocol.table.delete(wrapNode(n))
Expand All @@ -301,7 +303,7 @@ func (p *PortalAPI) HistoryLookupEnr(nodeId string) (string, error) {
return enr.String(), nil
}

func (p *PortalAPI) Ping(enr string) (*PortalPongResp, error) {
func (p *PortalAPI) HistoryPing(enr string) (*PortalPongResp, error) {
n, err := enode.Parse(enode.ValidSchemes, enr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -330,7 +332,7 @@ func (p *PortalAPI) Ping(enr string) (*PortalPongResp, error) {
}, nil
}

func (p *PortalAPI) FindNodes(enr string, distances []uint) ([]string, error) {
func (p *PortalAPI) HistoryFindNodes(enr string, distances []uint) ([]string, error) {
n, err := enode.Parse(enode.ValidSchemes, enr)
if err != nil {
return nil, err
Expand All @@ -348,7 +350,7 @@ func (p *PortalAPI) FindNodes(enr string, distances []uint) ([]string, error) {
return enrs, nil
}

func (p *PortalAPI) FindContent(enr string, contentKey string) (interface{}, error) {
func (p *PortalAPI) HistoryFindContent(enr string, contentKey string) (interface{}, error) {
n, err := enode.Parse(enode.ValidSchemes, enr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -387,7 +389,7 @@ func (p *PortalAPI) FindContent(enr string, contentKey string) (interface{}, err
}
}

func (p *PortalAPI) Offer(enr string, contentKey string, contentValue string) (string, error) {
func (p *PortalAPI) HistoryOffer(enr string, contentKey string, contentValue string) (string, error) {
n, err := enode.Parse(enode.ValidSchemes, enr)
if err != nil {
return "", err
Expand Down Expand Up @@ -440,6 +442,12 @@ func (p *PortalAPI) HistoryRecursiveFindContent(contentKeyHex string) (*ContentI
return nil, err
}
content, utpTransfer, err := p.portalProtocol.ContentLookup(contentKey)
if errors.Is(err, storage.ErrContentNotFound) {
return &ContentInfo{
Content: "0x",
UtpTransfer: false,
}, nil
}
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -485,3 +493,13 @@ func (p *PortalAPI) HistoryStore(contentKeyHex string, contextHex string) (bool,
}
return true, nil
}

// TODO
func (p *PortalAPI) HistoryGossip() {

}

// TODO
func (p *PortalAPI) HistoryTraceRecursiveFindContent(contentKeyHex string) {

}

0 comments on commit c5bf27a

Please sign in to comment.