Versioned hash32 (#2672)
This commit is contained in:
parent
c022b29d14
commit
219b22b1f5
|
@ -78,7 +78,7 @@ proc calculateTransactionData(
|
||||||
for i, t in items:
|
for i, t in items:
|
||||||
try:
|
try:
|
||||||
let tx = distinctBase(t)
|
let tx = distinctBase(t)
|
||||||
tr.put(rlp.encode(i), tx)
|
tr.put(rlp.encode(uint64 i), tx)
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
# tr.put interface can raise exception
|
# tr.put interface can raise exception
|
||||||
raiseAssert(e.msg)
|
raiseAssert(e.msg)
|
||||||
|
@ -97,7 +97,7 @@ proc calculateWithdrawalsRoot(items: openArray[WithdrawalV1]): Hash256 {.raises:
|
||||||
address: distinctBase(w.address).to(EthAddress),
|
address: distinctBase(w.address).to(EthAddress),
|
||||||
amount: distinctBase(w.amount),
|
amount: distinctBase(w.amount),
|
||||||
)
|
)
|
||||||
tr.put(rlp.encode(i), rlp.encode(withdrawal))
|
tr.put(rlp.encode(uint64 i), rlp.encode(withdrawal))
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
raiseAssert(e.msg)
|
raiseAssert(e.msg)
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import
|
||||||
|
|
||||||
func validateVersionedHashed(payload: ExecutionPayload,
|
func validateVersionedHashed(payload: ExecutionPayload,
|
||||||
expected: openArray[Web3Hash]): bool =
|
expected: openArray[Web3Hash]): bool =
|
||||||
var versionedHashes: seq[common.Bytes32]
|
var versionedHashes: seq[common.VersionedHash]
|
||||||
for x in payload.transactions:
|
for x in payload.transactions:
|
||||||
let tx = rlp.decode(distinctBase(x), Transaction)
|
let tx = rlp.decode(distinctBase(x), Transaction)
|
||||||
versionedHashes.add tx.versionedHashes
|
versionedHashes.add tx.versionedHashes
|
||||||
|
|
|
@ -41,7 +41,7 @@ const
|
||||||
|
|
||||||
# kzgToVersionedHash implements kzg_to_versioned_hash from EIP-4844
|
# kzgToVersionedHash implements kzg_to_versioned_hash from EIP-4844
|
||||||
proc kzgToVersionedHash*(kzg: kzg.KzgCommitment): VersionedHash =
|
proc kzgToVersionedHash*(kzg: kzg.KzgCommitment): VersionedHash =
|
||||||
result = sha256.digest(kzg.bytes).data.to(Bytes32)
|
result = sha256.digest(kzg.bytes).to(Hash32)
|
||||||
result.data[0] = VERSIONED_HASH_VERSION_KZG
|
result.data[0] = VERSIONED_HASH_VERSION_KZG
|
||||||
|
|
||||||
# pointEvaluation implements point_evaluation_precompile from EIP-4844
|
# pointEvaluation implements point_evaluation_precompile from EIP-4844
|
||||||
|
|
|
@ -1323,8 +1323,7 @@ proc queryLogs(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.
|
||||||
proc queryGasPrice(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
|
proc queryGasPrice(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
|
||||||
let ctx = GraphqlContextRef(ud)
|
let ctx = GraphqlContextRef(ud)
|
||||||
try:
|
try:
|
||||||
{.cast(noSideEffect).}:
|
bigIntNode(calculateMedianGasPrice(ctx.chainDB))
|
||||||
bigIntNode(calculateMedianGasPrice(ctx.chainDB))
|
|
||||||
except CatchableError as em:
|
except CatchableError as em:
|
||||||
err("can't get gasPrice: " & em.msg)
|
err("can't get gasPrice: " & em.msg)
|
||||||
|
|
||||||
|
@ -1332,7 +1331,7 @@ proc queryProtocolVersion(ud: RootRef, params: Args, parent: Node): RespResult {
|
||||||
let ctx = GraphqlContextRef(ud)
|
let ctx = GraphqlContextRef(ud)
|
||||||
for n in ctx.ethNode.capabilities:
|
for n in ctx.ethNode.capabilities:
|
||||||
if n.name == "eth":
|
if n.name == "eth":
|
||||||
return ok(resp(n.version))
|
return bigIntNode(n.version)
|
||||||
err("can't get protocol version")
|
err("can't get protocol version")
|
||||||
|
|
||||||
proc querySyncing(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
|
proc querySyncing(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
|
||||||
|
|
|
@ -448,7 +448,7 @@ method handleAnnouncedTxsHashes*(
|
||||||
ctx: EthWireRef;
|
ctx: EthWireRef;
|
||||||
peer: Peer;
|
peer: Peer;
|
||||||
txTypes: seq[byte];
|
txTypes: seq[byte];
|
||||||
txSizes: openArray[int];
|
txSizes: openArray[uint64];
|
||||||
txHashes: openArray[Hash32];
|
txHashes: openArray[Hash32];
|
||||||
): Result[void, string] =
|
): Result[void, string] =
|
||||||
when extraTraceMessages:
|
when extraTraceMessages:
|
||||||
|
|
|
@ -101,7 +101,7 @@ method handleAnnouncedTxsHashes*(
|
||||||
ctx: EthWireBase;
|
ctx: EthWireBase;
|
||||||
peer: Peer;
|
peer: Peer;
|
||||||
txTypes: seq[byte];
|
txTypes: seq[byte];
|
||||||
txSizes: openArray[int];
|
txSizes: openArray[uint64];
|
||||||
txHashes: openArray[Hash32];
|
txHashes: openArray[Hash32];
|
||||||
): Result[void, string]
|
): Result[void, string]
|
||||||
{.base, gcsafe.} =
|
{.base, gcsafe.} =
|
||||||
|
|
|
@ -148,7 +148,7 @@ p2pProtocol eth68(version = ethVersion,
|
||||||
handshake:
|
handshake:
|
||||||
# User message 0x00: Status.
|
# User message 0x00: Status.
|
||||||
proc status(peer: Peer,
|
proc status(peer: Peer,
|
||||||
ethVersionArg: uint,
|
ethVersionArg: uint64,
|
||||||
networkId: NetworkId,
|
networkId: NetworkId,
|
||||||
totalDifficulty: DifficultyInt,
|
totalDifficulty: DifficultyInt,
|
||||||
bestHash: Hash32,
|
bestHash: Hash32,
|
||||||
|
@ -250,7 +250,7 @@ p2pProtocol eth68(version = ethVersion,
|
||||||
proc newPooledTransactionHashes(
|
proc newPooledTransactionHashes(
|
||||||
peer: Peer,
|
peer: Peer,
|
||||||
txTypes: seq[byte],
|
txTypes: seq[byte],
|
||||||
txSizes: openArray[int],
|
txSizes: openArray[uint64],
|
||||||
txHashes: openArray[Hash32]
|
txHashes: openArray[Hash32]
|
||||||
) =
|
) =
|
||||||
when trEthTraceGossipOk:
|
when trEthTraceGossipOk:
|
||||||
|
|
|
@ -96,7 +96,7 @@ proc calculateTransactionData(
|
||||||
for i, t in items:
|
for i, t in items:
|
||||||
let tx = distinctBase(t)
|
let tx = distinctBase(t)
|
||||||
txSize = txSize + uint64(len(tx))
|
txSize = txSize + uint64(len(tx))
|
||||||
tr.merge(rlp.encode(i), tx).expect "merge data"
|
tr.merge(rlp.encode(uint64 i), tx).expect "merge data"
|
||||||
txHashes.add(txOrHash toFixedBytes(keccakHash(tx)))
|
txHashes.add(txOrHash toFixedBytes(keccakHash(tx)))
|
||||||
let rootHash = tr.state(updateOk = true).expect "hash"
|
let rootHash = tr.state(updateOk = true).expect "hash"
|
||||||
(rootHash, txHashes, txSize)
|
(rootHash, txHashes, txSize)
|
||||||
|
|
|
@ -107,10 +107,10 @@ proc fromJson*(n: JsonNode, name: string, x: var TxType) =
|
||||||
else:
|
else:
|
||||||
x = hexToInt(node.getStr(), int).TxType
|
x = hexToInt(node.getStr(), int).TxType
|
||||||
|
|
||||||
proc fromJson*(n: JsonNode, name: string, x: var seq[Bytes32]) =
|
proc fromJson*[T: Bytes32|Hash32](n: JsonNode, name: string, x: var seq[T]) =
|
||||||
let node = n[name]
|
let node = n[name]
|
||||||
var h: Bytes32
|
var h: T
|
||||||
x = newSeqOfCap[Bytes32](node.len)
|
x = newSeqOfCap[T](node.len)
|
||||||
for v in node:
|
for v in node:
|
||||||
hexToByteArray(v.getStr(), h.data)
|
hexToByteArray(v.getStr(), h.data)
|
||||||
x.add h
|
x.add h
|
||||||
|
|
|
@ -86,7 +86,7 @@ proc tx5(i: int): Transaction =
|
||||||
|
|
||||||
proc tx6(i: int): Transaction =
|
proc tx6(i: int): Transaction =
|
||||||
const
|
const
|
||||||
digest = bytes32"010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014"
|
digest = hash32"010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014"
|
||||||
|
|
||||||
Transaction(
|
Transaction(
|
||||||
txType: TxEip4844,
|
txType: TxEip4844,
|
||||||
|
@ -101,7 +101,7 @@ proc tx6(i: int): Transaction =
|
||||||
|
|
||||||
proc tx7(i: int): Transaction =
|
proc tx7(i: int): Transaction =
|
||||||
const
|
const
|
||||||
digest = bytes32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"
|
digest = hash32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"
|
||||||
|
|
||||||
Transaction(
|
Transaction(
|
||||||
txType: TxEip4844,
|
txType: TxEip4844,
|
||||||
|
@ -117,7 +117,7 @@ proc tx7(i: int): Transaction =
|
||||||
|
|
||||||
proc tx8(i: int): Transaction =
|
proc tx8(i: int): Transaction =
|
||||||
const
|
const
|
||||||
digest = bytes32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"
|
digest = hash32"01624652859a6e98ffc1608e2af0147ca4e86e1ce27672d8d3f3c9d4ffd6ef7e"
|
||||||
|
|
||||||
Transaction(
|
Transaction(
|
||||||
txType: TxEip4844,
|
txType: TxEip4844,
|
||||||
|
|
|
@ -66,7 +66,7 @@ proc fromJson(T: type AccessList, n: JsonNode): AccessList =
|
||||||
|
|
||||||
proc fromJson(T: type VersionedHashes, list: JsonNode): VersionedHashes =
|
proc fromJson(T: type VersionedHashes, list: JsonNode): VersionedHashes =
|
||||||
for x in list:
|
for x in list:
|
||||||
result.add Bytes32.fromHex(x.getStr)
|
result.add VersionedHash.fromHex(x.getStr)
|
||||||
|
|
||||||
template required(T: type, nField: string): auto =
|
template required(T: type, nField: string): auto =
|
||||||
fromJson(T, n[nField])
|
fromJson(T, n[nField])
|
||||||
|
|
|
@ -114,7 +114,7 @@ proc fromJson(T: type seq[Authorization], n: JsonNode, field: string): T =
|
||||||
proc fromJson(T: type VersionedHashes, n: JsonNode, field: string): VersionedHashes =
|
proc fromJson(T: type VersionedHashes, n: JsonNode, field: string): VersionedHashes =
|
||||||
let list = n[field]
|
let list = n[field]
|
||||||
for x in list:
|
for x in list:
|
||||||
result.add Bytes32.fromHex(x.getStr)
|
result.add VersionedHash.fromHex(x.getStr)
|
||||||
|
|
||||||
template `gas=`(tx: var Transaction, x: GasInt) =
|
template `gas=`(tx: var Transaction, x: GasInt) =
|
||||||
tx.gasLimit = x
|
tx.gasLimit = x
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6bd6bae86c437a61bcd6426571204dd7cdb88123
|
Subproject commit 086ac68c8698386949295bf44fecc255d9854322
|
Loading…
Reference in New Issue