Was ist die „Wurzel“ eines Transaktionsbelegs?

web3.eth.getTransactionReceipt gibt ein Objekt mit einer rootEigenschaft zurück und ist derzeit im Wiki nicht dokumentiert .

Result: {
    ...
      "root": "7583254379574ee8eb2943c3ee41582a0041156215e2c7d82e363098c89fe21b",
      "to": "0x91067b439e1be22196a5f64ee61e803670ba5be9",
      "transactionHash": "0xad62c939b2e865f13c61eebcb221d2c9737955e506b69fb624210d3fd4e0035b",
      "transactionIndex": 0
    }
  1. Was ist das root? Es ist nicht dasselbe wie das receiptRootvon web3.eth.getBlock.

  2. Welche Beziehung besteht zwischen diesen Wurzeln?

Antworten (1)

Es ist der Hash der Wurzel des State Trie, während receiptRootes sich um den Hash des Quittungsarrays für einen bestimmten Block handelt.


Wurzel

Darin gibt GetTransactionReceipt()es api.goeine Reihe von Zuordnungen, von denen eine ist:

"root":              common.Bytes2Hex(receipt.PostState),

Betrachtet man receipt.go, PostStateist ein byteArray:

// Receipt represents the results of a transaction.
type Receipt struct {
    // Consensus fields
    PostState         []byte
    CumulativeGasUsed *big.Int
    Bloom             Bloom
    Logs              vm.Logs

Dies wird NewReceipt()auf einen Wert gesetzt, der von übergeben wird state_processor.go:

receipt := types.NewReceipt(statedb.IntermediateRoot().Bytes(), usedGas)

...und IntermediateRoot()ist definiert statedb.goals:

// IntermediateRoot computes the current root hash of the state trie.
// It is called in between transactions to get the root hash that
// goes into transaction receipts.

QuittungRoot

Im block.go:

// The values of TxHash, UncleHash, ReceiptHash and Bloom in header
// are ignored and set to values derived from the given txs, uncles
// and receipts.

Der entsprechende Code in dieser Funktion lautet:

b.header.ReceiptHash = DeriveSha(Receipts(receipts))

Und darin api.go:

"receiptRoot":      b.ReceiptHash(),
Vielen Dank! Es ist der Hash der Wurzel des Zwischenzustandsversuchs , nachdem die bestimmte Transaktion angewendet wurde.