Skip to content

Commit

Permalink
implemented get header for libp2p
Browse files Browse the repository at this point in the history
  • Loading branch information
kiltsonfire authored and Djadih committed May 20, 2024
1 parent 8a091d3 commit 7092f10
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion p2p/node/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (p *P2PNode) GetBlockHashByNumber(number *big.Int, location common.Location
}

func (p *P2PNode) GetHeader(hash common.Hash, location common.Location) *types.WorkObject {
panic("TODO: implement")
return p.consensus.GetHeader(hash, location)
}

func (p *P2PNode) GetTrieNode(hash common.Hash, location common.Location) *trie.TrieNodeResponse {
Expand Down
2 changes: 2 additions & 0 deletions quai/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type ConsensusAPI interface {

LookupBlockHashByNumber(*big.Int, common.Location) *common.Hash

GetHeader(common.Hash, common.Location) *types.WorkObject

// Asks the consensus backend to lookup a trie node by hash and location,
// and return the data in the trie node.
GetTrieNode(hash common.Hash, location common.Location) *trie.TrieNodeResponse
Expand Down
10 changes: 10 additions & 0 deletions quai/p2p_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ func (qbe *QuaiBackend) LookupBlockHashByNumber(number *big.Int, location common
}
}

func (qbe *QuaiBackend) GetHeader(hash common.Hash, location common.Location) *types.WorkObject {
backend := *qbe.GetBackend(location)
if backend == nil {
log.Global.Error("no backend found")
return nil
}
header, _ := backend.HeaderByHash(context.Background(), hash)
return header
}

func (qbe *QuaiBackend) ProcessingState(location common.Location) bool {
backend := *qbe.GetBackend(location)
if backend == nil {
Expand Down

0 comments on commit 7092f10

Please sign in to comment.