mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
les: fix TxStatus message format
This commit is contained in:
parent
92580d69d3
commit
81d871e103
4 changed files with 12 additions and 9 deletions
|
|
@ -1014,7 +1014,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
for i, stat := range stats {
|
for i, stat := range stats {
|
||||||
if stat.Status == core.TxStatusUnknown {
|
if stat.Status == core.TxStatusUnknown {
|
||||||
if errs := pm.txpool.AddRemotes([]*types.Transaction{req.Txs[i]}); errs[0] != nil {
|
if errs := pm.txpool.AddRemotes([]*types.Transaction{req.Txs[i]}); errs[0] != nil {
|
||||||
stats[i].Error = errs[0]
|
stats[i].Data = []byte(errs[0].Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
stats[i] = pm.txStatus([]common.Hash{hashes[i]})[0]
|
stats[i] = pm.txStatus([]common.Hash{hashes[i]})[0]
|
||||||
|
|
@ -1055,7 +1055,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
p.Log().Trace("Received tx status response")
|
p.Log().Trace("Received tx status response")
|
||||||
var resp struct {
|
var resp struct {
|
||||||
ReqID, BV uint64
|
ReqID, BV uint64
|
||||||
Status []core.TxStatus
|
Status []txStatus
|
||||||
}
|
}
|
||||||
if err := msg.Decode(&resp); err != nil {
|
if err := msg.Decode(&resp); err != nil {
|
||||||
return errResp(ErrDecode, "msg %v: %v", msg, err)
|
return errResp(ErrDecode, "msg %v: %v", msg, err)
|
||||||
|
|
@ -1116,7 +1116,7 @@ func (pm *ProtocolManager) txStatus(hashes []common.Hash) []txStatus {
|
||||||
if stat == core.TxStatusUnknown {
|
if stat == core.TxStatusUnknown {
|
||||||
if block, number, index := core.GetTxLookupEntry(pm.chainDb, hashes[i]); block != (common.Hash{}) {
|
if block, number, index := core.GetTxLookupEntry(pm.chainDb, hashes[i]); block != (common.Hash{}) {
|
||||||
stats[i].Status = core.TxStatusIncluded
|
stats[i].Status = core.TxStatusIncluded
|
||||||
stats[i].Lookup = &core.TxLookupEntry{BlockHash: block, BlockIndex: number, Index: index}
|
stats[i].Data, _ = rlp.EncodeToBytes(core.TxLookupEntry{BlockHash: block, BlockIndex: number, Index: index})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,7 @@ func TestTransactionStatusLes2(t *testing.T) {
|
||||||
|
|
||||||
// test error status by sending an underpriced transaction
|
// test error status by sending an underpriced transaction
|
||||||
tx0, _ := types.SignTx(types.NewTransaction(0, acc1Addr, big.NewInt(10000), params.TxGas, nil, nil), signer, testBankKey)
|
tx0, _ := types.SignTx(types.NewTransaction(0, acc1Addr, big.NewInt(10000), params.TxGas, nil, nil), signer, testBankKey)
|
||||||
test(tx0, true, txStatus{Status: core.TxStatusUnknown, Error: core.ErrUnderpriced})
|
test(tx0, true, txStatus{Status: core.TxStatusUnknown, Data: []byte(core.ErrUnderpriced.Error())})
|
||||||
|
|
||||||
tx1, _ := types.SignTx(types.NewTransaction(0, acc1Addr, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, testBankKey)
|
tx1, _ := types.SignTx(types.NewTransaction(0, acc1Addr, big.NewInt(10000), params.TxGas, big.NewInt(100000000000), nil), signer, testBankKey)
|
||||||
test(tx1, false, txStatus{Status: core.TxStatusUnknown}) // query before sending, should be unknown
|
test(tx1, false, txStatus{Status: core.TxStatusUnknown}) // query before sending, should be unknown
|
||||||
|
|
@ -480,8 +480,12 @@ func TestTransactionStatusLes2(t *testing.T) {
|
||||||
|
|
||||||
// check if their status is included now
|
// check if their status is included now
|
||||||
block1hash := core.GetCanonicalHash(db, 1)
|
block1hash := core.GetCanonicalHash(db, 1)
|
||||||
test(tx1, false, txStatus{Status: core.TxStatusIncluded, Lookup: &core.TxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 0}})
|
|
||||||
test(tx2, false, txStatus{Status: core.TxStatusIncluded, Lookup: &core.TxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 1}})
|
pos0, _ := rlp.EncodeToBytes(core.TxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 0})
|
||||||
|
pos1, _ := rlp.EncodeToBytes(core.TxLookupEntry{BlockHash: block1hash, BlockIndex: 1, Index: 1})
|
||||||
|
|
||||||
|
test(tx1, false, txStatus{Status: core.TxStatusIncluded, Data: pos0})
|
||||||
|
test(tx2, false, txStatus{Status: core.TxStatusIncluded, Data: pos1})
|
||||||
|
|
||||||
// create a reorg that rolls them back
|
// create a reorg that rolls them back
|
||||||
gchain, _ = core.GenerateChain(params.TestChainConfig, chain.GetBlockByNumber(0), ethash.NewFaker(), db, 2, func(i int, block *core.BlockGen) {})
|
gchain, _ = core.GenerateChain(params.TestChainConfig, chain.GetBlockByNumber(0), ethash.NewFaker(), db, 2, func(i int, block *core.BlockGen) {})
|
||||||
|
|
|
||||||
|
|
@ -312,7 +312,7 @@ func (p *peer) RequestTxStatus(reqID, cost uint64, txHashes []common.Hash) error
|
||||||
return sendRequest(p.rw, GetTxStatusMsg, reqID, cost, txHashes)
|
return sendRequest(p.rw, GetTxStatusMsg, reqID, cost, txHashes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendTxStatus sends a batch of transactions to be added to the remote transaction pool.
|
// SendTxs sends a batch of transactions to be added to the remote transaction pool.
|
||||||
func (p *peer) SendTxs(reqID, cost uint64, txs types.Transactions) error {
|
func (p *peer) SendTxs(reqID, cost uint64, txs types.Transactions) error {
|
||||||
p.Log().Debug("Fetching batch of transactions", "count", len(txs))
|
p.Log().Debug("Fetching batch of transactions", "count", len(txs))
|
||||||
switch p.version {
|
switch p.version {
|
||||||
|
|
|
||||||
|
|
@ -224,6 +224,5 @@ type proofsData [][]rlp.RawValue
|
||||||
|
|
||||||
type txStatus struct {
|
type txStatus struct {
|
||||||
Status core.TxStatus
|
Status core.TxStatus
|
||||||
Lookup *core.TxLookupEntry
|
Data []byte // RLP-encoded core.TxLookupEntry or error string
|
||||||
Error error
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue