mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
Add New ODR Message
This commit is contained in:
parent
5a2daff8b4
commit
aa13265d90
1 changed files with 54 additions and 0 deletions
|
|
@ -564,3 +564,57 @@ func (db *readTraceDB) Has(key []byte) (bool, error) {
|
|||
_, err := db.Get(key)
|
||||
return err == nil, nil
|
||||
}
|
||||
|
||||
type TxStatusRequest light.TxStatusRequest
|
||||
|
||||
// GetCost returns the cost of the given ODR request according to the serving
|
||||
// peer's cost table (implementation of LesOdrRequest)
|
||||
func (r *TxStatusRequest) GetCost(peer *peer) uint64 {
|
||||
return peer.GetRequestCost(GetTxStatusMsg, 1)
|
||||
}
|
||||
|
||||
// CanSend tells if a certain peer is suitable for serving the given request
|
||||
func (r *TxStatusRequest) CanSend(peer *peer) bool {
|
||||
if peer.version == lpv1 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Request sends an ODR request to the LES network (implementation of LesOdrRequest)
|
||||
func (r *TxStatusRequest) Request(reqID uint64, peer *peer) error {
|
||||
peer.Log().Debug("Requesting transaction status corresponding block", "TxHash", r.TxHash)
|
||||
return peer.RequestTxStatus(reqID, r.GetCost(peer), []common.Hash{r.TxHash})
|
||||
}
|
||||
|
||||
// Valid processes an ODR request reply message from the LES network
|
||||
// returns true and stores results in memory if the message was a valid reply
|
||||
// to the request (implementation of LesOdrRequest)
|
||||
func (r *TxStatusRequest) Validate(db ethdb.Database, msg *Msg) error {
|
||||
log.Debug("Validating transaction status corresponding block", "TxHash", r.TxHash)
|
||||
|
||||
// Ensure we have a correct message with a single block receipt
|
||||
if msg.MsgType != MsgTxStatus {
|
||||
return errInvalidMessageType
|
||||
}
|
||||
|
||||
if len(msg.Obj.([]txStatus)) != 1 {
|
||||
return errInvalidEntryCount
|
||||
}
|
||||
|
||||
//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
|
||||
|
||||
//Need support verify through pending transactions
|
||||
//Share your ideas!
|
||||
|
||||
status := msg.Obj.([]txStatus)[0]
|
||||
|
||||
r.TxStatus = status.Status
|
||||
r.TxEntry = status.Lookup
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue