mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
light: Update light/odr_util.go
This commit is contained in:
parent
6501c1917c
commit
6d7d5ccd49
1 changed files with 39 additions and 0 deletions
|
|
@ -230,3 +230,42 @@ func GetBloomBits(ctx context.Context, odr OdrBackend, bitIdx uint, sectionIdxLi
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GetTxStatus requests full nodes to retrieve the status of transaction corresponding to the hash.
|
||||||
|
//Message of the LES/2 protocol version (LPV2)
|
||||||
|
func GetTxStatus(ctx context.Context, odr OdrBackend, txHash common.Hash) (core.TxStatus, error) {
|
||||||
|
|
||||||
|
// Return "Included" status if query success from database
|
||||||
|
bHash, bIndex, _ := rawdb.ReadTxLookupEntry(odr.Database(), txHash)
|
||||||
|
if bHash != (common.Hash{}) {
|
||||||
|
return core.TxStatusIncluded, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send on-demand request message
|
||||||
|
r := &TxStatusRequest{TxHash: txHash}
|
||||||
|
if err := odr.Retrieve(ctx, r); err != nil {
|
||||||
|
return core.TxStatusUnknown, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.TxStatus != core.TxStatusIncluded {
|
||||||
|
return r.TxStatus, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Another on-demand request message for retrieve block body, verify block body internally
|
||||||
|
bHash, bIndex, _ = r.TxEntry.BlockHash, r.TxEntry.BlockIndex, r.TxEntry.Index
|
||||||
|
bBody, err := GetBody(ctx, odr, bHash, bIndex)
|
||||||
|
if err != nil {
|
||||||
|
return r.TxStatus, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to find matched transaction by given hash, verifying transaction by given hash whether exist
|
||||||
|
for _, tx := range bBody.Transactions {
|
||||||
|
if tx.Hash() == r.TxHash {
|
||||||
|
// Write into database if hash matched, link given hash to verified block hash and index
|
||||||
|
rawdb.WriteTxLookupEntry(odr.Database(), r.TxEntry, r.TxHash)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.TxStatus, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue