mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-11 14:33:52 +00:00
internal/ethapi :: Fix : newRPCTransactionFromBlockIndex
This commit is contained in:
parent
79718d7445
commit
a85370115e
2 changed files with 18 additions and 14 deletions
|
|
@ -1363,6 +1363,7 @@ func (bc *BlockChain) WriteBlockAndSetHead(block *types.Block, receipts []*types
|
||||||
// the chain mutex to be held.
|
// the chain mutex to be held.
|
||||||
func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
|
func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
|
||||||
var stateSyncLogs []*types.Log
|
var stateSyncLogs []*types.Log
|
||||||
|
|
||||||
if stateSyncLogs, err = bc.writeBlockWithState(block, receipts, logs, state); err != nil {
|
if stateSyncLogs, err = bc.writeBlockWithState(block, receipts, logs, state); err != nil {
|
||||||
return NonStatTy, err
|
return NonStatTy, err
|
||||||
}
|
}
|
||||||
|
|
@ -1371,6 +1372,7 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NonStatTy, err
|
return NonStatTy, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if reorg {
|
if reorg {
|
||||||
// Reorganise the chain if the parent is not the head block
|
// Reorganise the chain if the parent is not the head block
|
||||||
if block.ParentHash() != currentBlock.Hash() {
|
if block.ParentHash() != currentBlock.Hash() {
|
||||||
|
|
@ -1378,6 +1380,7 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
|
||||||
return NonStatTy, err
|
return NonStatTy, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = CanonStatTy
|
status = CanonStatTy
|
||||||
} else {
|
} else {
|
||||||
status = SideStatTy
|
status = SideStatTy
|
||||||
|
|
|
||||||
|
|
@ -1457,27 +1457,28 @@ func newRPCPendingTransaction(tx *types.Transaction, current *types.Header, conf
|
||||||
func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig, db ethdb.Database) *RPCTransaction {
|
func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig, db ethdb.Database) *RPCTransaction {
|
||||||
txs := b.Transactions()
|
txs := b.Transactions()
|
||||||
|
|
||||||
if index >= uint64(len(txs)+1) {
|
borReceipt := rawdb.ReadBorReceipt(db, b.Hash(), b.NumberU64(), config)
|
||||||
return nil
|
if borReceipt != nil {
|
||||||
}
|
if borReceipt.TxHash != (common.Hash{}) {
|
||||||
|
borTx, _, _, _ := rawdb.ReadBorTransactionWithBlockHash(db, borReceipt.TxHash, b.Hash())
|
||||||
// If the index out of the range of transactions defined in block body, it means that the transaction is a bor state sync transaction, and we need to fetch it from the database
|
if borTx != nil {
|
||||||
if index == uint64(len(txs)) {
|
txs = append(txs, borTx)
|
||||||
borReceipt := rawdb.ReadBorReceipt(db, b.Hash(), b.NumberU64(), config)
|
|
||||||
if borReceipt != nil {
|
|
||||||
tx, _, _, _ := rawdb.ReadBorTransaction(db, borReceipt.TxHash)
|
|
||||||
|
|
||||||
if tx != nil {
|
|
||||||
txs = append(txs, tx)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the index is still out of the range after checking bor state sync transaction, it means that the transaction index is invalid
|
|
||||||
if index >= uint64(len(txs)) {
|
if index >= uint64(len(txs)) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index, b.BaseFee(), config)
|
|
||||||
|
rpcTx := newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index, b.BaseFee(), config)
|
||||||
|
|
||||||
|
// If the transaction is a bor transaction, we need to set the hash to the derived bor tx hash. BorTx is always the last index.
|
||||||
|
if borReceipt != nil && int(index) == len(txs)-1 {
|
||||||
|
rpcTx.Hash = borReceipt.TxHash
|
||||||
|
}
|
||||||
|
|
||||||
|
return rpcTx
|
||||||
}
|
}
|
||||||
|
|
||||||
// newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.
|
// newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue