3

I wanted to access Ethereum Transaction Trie using LevelDB, but it's working only for Block 0, for any other block it's not given me any data. Just wondering how does web3.eth.getTransaction() works internally: Here is the code:

const Trie1 = require ('merkle-patricia-tree').SecureTrie
const { Account, BN, bufferToHex, rlp } = require ('ethereumjs-util') ;
var levelup = require('levelup');
var leveldown = require('leveldown');
const gethDbPath = '/Users/AK/gethDataDir/geth/chaindata'
const db = new levelup(leveldown(gethDbPath))
async function test() {
    const txnRoot = '0x51736d42e0e8fe95c3e609e5e5fb70da476613d24b5cd0d710d68190649c39f4'
    const txnRootBuffer = Buffer.from(txnRoot.slice(2), 'hex')
    const trie1 = new Trie1(db,txnRootBuffer)
    const stream = trie1.createReadStream()
    stream.on('data', (data) => {
        console.log(`key: ${bufferToHex(data.key)}`)
        console.log(`Value: ${bufferToHex(rlp.decode(data.value))}`)
      })
      .on('end', () => {
        console.log('1111--->>> Finished')
    })
  }
  test() ;

Below is the transaction I am trying to access the levelDB directly. I tried almost all combinations like TxnRoot, TxnHash, with or without Kecak256 etc

{ difficulty: 149904, extraData: "0xd983010a10846765746888676f312e31372e368664617277696e", gasLimit: 2770332, gasUsed: 21000, hash: "0xa98255eed7b9a16b30013b8cabf8adf07def8cb772ba9d3110f72a97fd351ad7", logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", miner: "0x3f457dd6c71534bc7955c29b6a097cf39b96bfd7", mixHash: "0x366ff733fc9e2768595a25299edec785688deb4c8fe2d53543b860e8ee0724fc", nonce: "0x24bc70e55ec61f1d", number: 284, parentHash: "0x17d0dee586ef5064cfcd835e4c40d34f6a5683449cd3a1a1f0f705a2bab6a938", receiptsRoot: "0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2", sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", size: 647, stateRoot: "0xb2ae3c859e0873667bdc088217be87cab1fed2a068e9e6baa124922915c83419", timestamp: 1654920279, totalDifficulty: 39858713, transactions: ["0x50a949ef9cab9d8edad24d8b6b33b3023ef499a6f43aabd8db1a7db85daf68f7"], transactionsRoot: "0x51736d42e0e8fe95c3e609e5e5fb70da476613d24b5cd0d710d68190649c39f4", uncles: [] }

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • I have tried on all sorts of clients Light Client, Full Synced Client (in progress syncing) and my own private blockchain cloned GETH (difficulty = 1 client) everywhere I am able to access only Block 0 and not even Block 1. I am following - https://github.com/tpmccallum/ethereum_database_research_and_testing/blob/master/leveldb/leveldb.md – Shishir Singh Jun 12 '22 at 04:24

1 Answers1

-1

I believe it's your use of SecureTrie for transanstion trie instead of Trie. Transaction and Receipts trie aren't hashed like State and Storage are. I had the same issue go look at my code https://ethereum.stackexchange.com/questions/130716/prove-transactionhash-of-block-using-ethereumjs-tx-and-merkle-patricia-tree

  • no idea why this got down voted. Did you try replacing `const Trie1 = require ('merkle-patricia-tree').SecureTrie`. with `const Trie1 = require ('merkle-patricia-tree').Trie` ? `SecureTrie` and `Trie` yield different results as SecureTrie hashes keys when putting data – Andreas Dilaveris Aug 25 '22 at 12:27