eth_getTransactionByHash implementation
Closed this issue · 7 comments
@vpulim Can you please validate my understanding about implementation path for eth_getTransactionByHash.
For "eth_getTransactionByHash." to be implemented , we need transaction Trie to be in DB and its not done yet.
i think even transaction trie will not help. probably all the transactions should be indexed using hash as key . is this a thought in right direction?
@bit-warrior yes, that’s correct. ethereumjs-blockchain will have to be modified to index transactions by hash. Geth stores entries in the database that contain a block hash and the transaction index within that block’s transaction list. These entries are keyed by the transaction hash. We can do something similar.
We should go through all the rpc calls and see what additional indices are needed in the database so we can see what’s missing from ethereumjs-blockchain. Would you be able to take that on?
yes, i will submit a PR for this.
I was looking into the geth code for implementation details to store and retrieve transaction by hash..
func WriteTxLookupEntries(db DatabaseWriter, block *types.Block) {
for i, tx := range block.Transactions() {
entry := TxLookupEntry{
BlockHash: block.Hash(),
BlockIndex: block.NumberU64(),
Index: uint64(i),
}
data, err := rlp.EncodeToBytes(entry)
if err != nil {
log.Crit("Failed to encode transaction lookup entry", "err", err)
}
if err := db.Put(txLookupKey(tx.Hash()), data); err != nil {
log.Crit("Failed to store transaction lookup entry", "err", err)
}
}
}
I found the above code
https://github.com/ethereum/go-ethereum/blob/c134e00e488bf4bfd88689ecf6b91ee351fb77e5/core/rawdb/accessors_indexes.go#L43
index is the above function does not seem to be actual index position on transaction from the block and if not then why are they saving it there.Looks like index position can be found in transaction receipt or there is any another simpler way to get index position.
@bit-warrior maybe i missed something, but it does look like Index
refers to the transaction's position within the block's transaction list. In the code above, the value of Index
is i
which refers to the current index in the for loop which is iterating through all of the block's transactions.
@vpulim Yeah may be , in go implementation while making Block object transactions are inserted in the same order as of transaction index but in this JS implementation transaction index order is not honored. I tried iterating over it and getting the index far off form transaction index.
Closing this for now. Tracking this and other RPC methods in #17