mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
rawdb, eth, ethapi, les, light: Fix "file is not goimported"
This commit is contained in:
parent
c7ef06016a
commit
920731fe99
8 changed files with 29 additions and 29 deletions
|
|
@ -58,13 +58,13 @@ func WriteTxLookupEntries(db DatabaseWriter, block *types.Block) {
|
|||
}
|
||||
|
||||
func WriteTxLookupEntry(db DatabaseWriter, entry *TxLookupEntry, txHash common.Hash) {
|
||||
data, err := rlp.EncodeToBytes(entry)
|
||||
if err != nil {
|
||||
log.Crit("Failed to encode transaction lookup entry", "err", err)
|
||||
}
|
||||
if err := db.Put(txLookupKey(txHash), data); err != nil {
|
||||
log.Crit("Failed to store transaction lookup entry", "err", err)
|
||||
}
|
||||
data, err := rlp.EncodeToBytes(entry)
|
||||
if err != nil {
|
||||
log.Crit("Failed to encode transaction lookup entry", "err", err)
|
||||
}
|
||||
if err := db.Put(txLookupKey(txHash), data); err != nil {
|
||||
log.Crit("Failed to store transaction lookup entry", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteTxLookupEntry removes all transaction data associated with a hash.
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
package eth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"context"
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ type Backend interface {
|
|||
Stats() (pending int, queued int)
|
||||
TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
|
||||
SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
|
||||
TxStatusByHash(ctx context.Context, hash common.Hash) (core.TxStatus, error)
|
||||
TxStatusByHash(ctx context.Context, hash common.Hash) (core.TxStatus, error)
|
||||
|
||||
ChainConfig() *params.ChainConfig
|
||||
CurrentBlock() *types.Block
|
||||
|
|
|
|||
|
|
@ -1109,7 +1109,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
|
||||
p.fcServer.GotReply(resp.ReqID, resp.BV)
|
||||
|
||||
deliverMsg = &Msg{
|
||||
deliverMsg = &Msg{
|
||||
MsgType: MsgTxStatus,
|
||||
ReqID: resp.ReqID,
|
||||
Obj: resp.Status,
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ const (
|
|||
MsgProofsV2
|
||||
MsgHeaderProofs
|
||||
MsgHelperTrieProofs
|
||||
MsgTxStatus
|
||||
MsgTxStatus
|
||||
)
|
||||
|
||||
// Msg encodes a LES message that delivers reply data for a request
|
||||
|
|
|
|||
|
|
@ -610,13 +610,13 @@ func (r *TxStatusRequest) Validate(db ethdb.Database, msg *Msg) error {
|
|||
//We retrieve transaction status, block hash and block index from a full node by a given transaction hash
|
||||
//These information retrieve from full node is lacking of relevant data to verify
|
||||
//My current solution is (Code at odr_util.go):
|
||||
//Only start verification after it's been "included", to proof a transaction is valid:
|
||||
//Retrieve BlockHash/BlockIndex -> Retrieve and verify BlockBody -> Verify given transaction hash whether included
|
||||
//Only start verification after it's been "included", to proof a transaction is valid:
|
||||
//Retrieve BlockHash/BlockIndex -> Retrieve and verify BlockBody -> Verify given transaction hash whether included
|
||||
|
||||
//Need support verify through pending transactions
|
||||
//Share your ideas!
|
||||
//Need support verify through pending transactions
|
||||
//Share your ideas!
|
||||
|
||||
status := msg.Obj.([]txStatus)[0]
|
||||
status := msg.Obj.([]txStatus)[0]
|
||||
|
||||
r.TxStatus = status.Status
|
||||
r.TxEntry = status.Lookup
|
||||
|
|
|
|||
|
|
@ -174,8 +174,8 @@ func (req *BloomRequest) StoreResult(db ethdb.Database) {
|
|||
type TxStatusRequest struct {
|
||||
OdrRequest
|
||||
TxHash common.Hash
|
||||
TxStatus core.TxStatus
|
||||
TxEntry *rawdb.TxLookupEntry
|
||||
TxStatus core.TxStatus
|
||||
TxEntry *rawdb.TxLookupEntry
|
||||
}
|
||||
|
||||
func (req *TxStatusRequest) StoreResult(db ethdb.Database) {
|
||||
|
|
|
|||
|
|
@ -235,35 +235,35 @@ func GetBloomBits(ctx context.Context, odr OdrBackend, bitIdx uint, sectionIdxLi
|
|||
//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 "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
|
||||
// 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 {
|
||||
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)
|
||||
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
|
||||
// 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
|
||||
// Write into database if hash matched, link given hash to verified block hash and index
|
||||
rawdb.WriteTxLookupEntry(odr.Database(), r.TxEntry, r.TxHash)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue