From 7092f10837877443737ec4ffacd3210e07ad6afa Mon Sep 17 00:00:00 2001 From: drk Date: Thu, 16 May 2024 17:28:02 -0500 Subject: [PATCH] implemented get header for libp2p --- p2p/node/api.go | 2 +- quai/interface.go | 2 ++ quai/p2p_backend.go | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/p2p/node/api.go b/p2p/node/api.go index 9729fe7096..ea30606aaf 100644 --- a/p2p/node/api.go +++ b/p2p/node/api.go @@ -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 { diff --git a/quai/interface.go b/quai/interface.go index df5cf391fc..4de62d2a6e 100644 --- a/quai/interface.go +++ b/quai/interface.go @@ -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 diff --git a/quai/p2p_backend.go b/quai/p2p_backend.go index 6969804272..ed28892deb 100644 --- a/quai/p2p_backend.go +++ b/quai/p2p_backend.go @@ -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 {