Skip to content

Commit

Permalink
EIP-4844: switch tx.rlpHash usage to tx.binaryHash
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Jan 21, 2023
1 parent 25510ee commit 01ed2f9
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 20 deletions.
3 changes: 0 additions & 3 deletions nimbus/core/executor/process_transaction.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ proc processTransactionImpl(
## Modelled after `https://eips.ethereum.org/EIPS/eip-1559#specification`_
## which provides a backward compatible framwork for EIP1559.

#trace "Sender", sender
#trace "txHash", rlpHash = ty.rlpHash

let
roDB = vmState.readOnlyStateDB
baseFee256 = header.eip1559BaseFee(fork)
Expand Down
2 changes: 1 addition & 1 deletion nimbus/core/tx_pool/tx_item.nim
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ proc hash*(item: TxItemRef): Hash =

proc itemID*(tx: Transaction): Hash256 =
## Getter, transaction ID
tx.rlpHash
tx.binaryHash

# core/types/transaction.go(297): func (tx *Transaction) Cost() *big.Int {
proc cost*(tx: Transaction): UInt256 =
Expand Down
4 changes: 2 additions & 2 deletions nimbus/db/db_chain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ proc persistTransactions*(db: ChainDBRef, blockNumber:
for idx, tx in transactions:
let
encodedTx = rlp.encode(tx.removeNetworkPayload)
txHash = rlpHash(tx) # beware EIP-4844
txHash = binaryHash(tx) # beware EIP-4844
txKey: TransactionKey = (blockNumber, idx)
trie.put(rlp.encode(idx), encodedTx)
db.db.put(transactionHashToBlockKey(txHash).toOpenArray, rlp.encode(txKey))
Expand Down Expand Up @@ -220,7 +220,7 @@ iterator getBlockTransactionHashes*(db: ChainDBRef, blockHeader: BlockHeader): H
## by the given block header.
for encodedTx in db.getBlockTransactionData(blockHeader.txRoot):
let tx = rlp.decode(encodedTx, Transaction)
yield rlpHash(tx) # beware EIP-4844
yield binaryHash(tx) # beware EIP-4844

proc getTransactionCount*(chain: ChainDBRef, txRoot: Hash256): int =
var trie = initHexaryTrie(chain.db, txRoot)
Expand Down
4 changes: 2 additions & 2 deletions nimbus/graphql/ethapi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ const logProcs = {
proc txHash(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
let
tx = TxNode(parent)
txHash = rlpHash(tx.tx)
txHash = binaryHash(tx.tx) # beware EIP-4844
resp(txHash)

proc txNonce(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
Expand Down Expand Up @@ -1224,7 +1224,7 @@ proc sendRawTransaction(ud: RootRef, params: Args, parent: Node): RespResult {.a
try:
let data = hexToSeqByte(params[0].val.stringVal)
let tx = decodeTx(data) # we want to know if it is a valid tx blob
let txHash = rlpHash(tx) # beware EIP-4844
let txHash = binaryHash(tx) # beware EIP-4844
resp(txHash)
except Exception as em:
return err("failed to process raw transaction")
Expand Down
2 changes: 1 addition & 1 deletion nimbus/rpc/filters.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ proc deriveLogs*(header: BlockHeader, transactions: seq[Transaction], receipts:
removed: false,
logIndex: some(encodeQuantity(uint32(logIndex))),
transactionIndex: some(encodeQuantity(uint32(i))),
transactionHash: some(transactions[i].rlpHash),
transactionHash: some(transactions[i].binaryHash),
blockHash: some(header.blockHash),
blockNumber: some(encodeQuantity(header.blockNumber)),
address: log.address,
Expand Down
4 changes: 2 additions & 2 deletions nimbus/rpc/p2p.nim
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ proc setupEthRpc*(
signedTx = signTransaction(tx, acc.privateKey, com.chainId, eip155)

txPool.add(signedTx)
result = rlpHash(signedTx).ethHashStr
result = binaryHash(signedTx).ethHashStr

server.rpc("eth_sendRawTransaction") do(data: HexDataStr) -> EthHashStr:
## Creates new message call transaction or a contract creation for signed transactions.
Expand All @@ -270,7 +270,7 @@ proc setupEthRpc*(
signedTx = decodeTx(txBytes)

txPool.add(signedTx)
result = rlpHash(signedTx).ethHashStr
result = binaryHash(signedTx).ethHashStr

server.rpc("eth_call") do(call: EthCall, quantityTag: string) -> HexDataStr:
## Executes a new message call immediately without creating a transaction on the block chain.
Expand Down
4 changes: 2 additions & 2 deletions nimbus/rpc/rpc_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ proc populateTransactionObject*(tx: Transaction, header: BlockHeader, txIndex: i
result.`from` = tx.getSender()
result.gas = encodeQuantity(tx.gasLimit.uint64)
result.gasPrice = encodeQuantity(tx.gasPrice.uint64)
result.hash = tx.rlpHash
result.hash = tx.binaryHash
result.input = tx.payload
result.nonce = encodeQuantity(tx.nonce.uint64)
result.to = some(tx.destination)
Expand Down Expand Up @@ -183,7 +183,7 @@ proc populateBlockObject*(header: BlockHeader, chain: ChainDBRef, fullTx: bool,

proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction,
txIndex: int, header: BlockHeader, fork: EVMFork): ReceiptObject =
result.transactionHash = tx.rlpHash
result.transactionHash = tx.binaryHash
result.transactionIndex = encodeQuantity(txIndex.uint)
result.blockHash = header.hash
result.blockNumber = encodeQuantity(header.blockNumber)
Expand Down
4 changes: 2 additions & 2 deletions nimbus/sync/handlers/eth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ proc fetchTransactions(ctx: EthWireRef, reqHashes: seq[Hash256], peer: Peer): Fu

# Remove from pending list regardless if tx is in result
for tx in txs.transactions:
let txHash = rlpHash(tx)
let txHash = binaryHash(tx)
ctx.pending.excl txHash

ctx.txPool.add(txs.transactions)
Expand Down Expand Up @@ -468,7 +468,7 @@ method handleAnnouncedTxs*(ctx: EthWireRef, peer: Peer, txs: openArray[Transacti

var txHashes = newSeqOfCap[Hash256](txs.len)
for tx in txs:
txHashes.add rlpHash(tx)
txHashes.add binaryHash(tx)

ctx.addToKnownByPeer(txHashes, peer)
ctx.txPool.add(txs)
Expand Down
7 changes: 2 additions & 5 deletions nimbus/sync/protocol/les_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,7 @@ p2pProtocol les(version = lesVersion,

var results: seq[TransactionStatusMsg]
for t in transactions:
let hash = t.rlpHash # TODO: this is not optimal, we can compute
# the hash from the request bytes.
# The RLP module can offer a helper Hashed[T]
# to make this easy.
let hash = t.binaryHash
var s = ctx.getTransactionStatus(hash)
if s.status == TransactionStatus.Unknown:
ctx.addTransactions([t])
Expand All @@ -479,7 +476,7 @@ p2pProtocol les(version = lesVersion,

var results: seq[TransactionStatusMsg]
for t in transactions:
results.add ctx.getTransactionStatus(t.rlpHash)
results.add ctx.getTransactionStatus(t.binaryHash)
await response.send(updateBV(), results)

proc txStatus(
Expand Down

0 comments on commit 01ed2f9

Please sign in to comment.