Skip to content

Commit

Permalink
feat(api): Do not return receipt if tx was not included to the batch (#…
Browse files Browse the repository at this point in the history
…706)

## What ❔

For compatibility with Ethereum, we have to return `Receipt` only if tx
is included in the miniblock. Block hash is not null null.

## Why ❔

For compatibility with Ethereum and for not breaking external clients,
such as Metemask, they do not expect that block hash could be null

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `cargo spellcheck
--cfg=./spellcheck/era.cfg --code 1`.

---------

Signed-off-by: Danil <deniallugo@gmail.com>
Co-authored-by: perekopskiy <mikeson.dp@gmail.com>
Co-authored-by: Roman Brodetski <rb@matterlabs.dev>
Co-authored-by: perekopskiy <53865202+perekopskiy@users.noreply.github.com>
  • Loading branch information
4 people committed Dec 19, 2023
1 parent 8351f25 commit 625d632
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 208 deletions.
46 changes: 23 additions & 23 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ jobs:
- name: Fee projection tests
run: ci_run zk test i fees

- name: Run revert test
run: |
ci_run pkill zksync_server || true
ci_run sleep 2
ci_run zk test i revert
# - name: Run revert test
# run: |
# ci_run pkill zksync_server || true
# ci_run sleep 2
# ci_run zk test i revert

# This test should be the last one as soon as it
# finished bootloader will be different
Expand All @@ -205,7 +205,7 @@ jobs:
run: |
ci_run cat server.log
ci_run cat contract_verifier.log
ci_run cat core/tests/revert-test/revert.log
# ci_run cat core/tests/revert-test/revert.log
ci_run cat core/tests/upgrade-test/upgrade.log
ci_run sccache --show-stats
ci_run cat /tmp/sccache_log.txt
Expand Down Expand Up @@ -285,22 +285,22 @@ jobs:
- name: Run Cross EN Checker
run: ci_run zk run cross-en-checker

- name: Run revert test
run: |
ci_run zk env
ci_run zk env docker
ci_run pkill zksync_server || true
ci_run sleep 2
ci_run zk env
ci_run zk test i revert
# Check that the rollback was performed on the EN
ci_run sleep 20
ci_run grep -q 'Rollback successfully completed' ext-node.log
# Restart the EN
ci_run zk server &>>server.log &
ci_run sleep 30
ZKSYNC_ENV=ext-node-docker ci_run zk external-node &>>ext-node.log &
ci_run sleep 30
# - name: Run revert test
# run: |
# ci_run zk env
# ci_run zk env docker
# ci_run pkill zksync_server || true
# ci_run sleep 2
# ci_run zk env
# ci_run zk test i revert
# # Check that the rollback was performed on the EN
# ci_run sleep 20
# ci_run grep -q 'Rollback successfully completed' ext-node.log
# # Restart the EN
# ci_run zk server &>>server.log &
# ci_run sleep 30
# ZKSYNC_ENV=ext-node-docker ci_run zk external-node &>>ext-node.log &
# ci_run sleep 30

- name: Run upgrade test
run: |
Expand All @@ -312,7 +312,7 @@ jobs:
run: |
ci_run cat server.log
ci_run cat ext-node.log
ci_run cat core/tests/revert-test/revert.log
# ci_run cat core/tests/revert-test/revert.log
ci_run cat core/tests/upgrade-test/upgrade.log
ci_run sccache --show-stats
ci_run cat /tmp/sccache_log.txt
214 changes: 107 additions & 107 deletions core/lib/dal/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,112 @@
},
"query": "\n UPDATE storage\n SET\n value = u.value\n FROM\n UNNEST($1::bytea[], $2::bytea[]) AS u (key, value)\n WHERE\n u.key = hashed_key\n "
},
"02285b8d0bc76c8cfd259872ac24f3670813e5a5356ddcb7ac482a0201d045f7": {
"describe": {
"columns": [
{
"name": "tx_hash",
"ordinal": 0,
"type_info": "Bytea"
},
{
"name": "index_in_block",
"ordinal": 1,
"type_info": "Int4"
},
{
"name": "l1_batch_tx_index",
"ordinal": 2,
"type_info": "Int4"
},
{
"name": "block_number!",
"ordinal": 3,
"type_info": "Int8"
},
{
"name": "error",
"ordinal": 4,
"type_info": "Varchar"
},
{
"name": "effective_gas_price",
"ordinal": 5,
"type_info": "Numeric"
},
{
"name": "initiator_address",
"ordinal": 6,
"type_info": "Bytea"
},
{
"name": "transfer_to?",
"ordinal": 7,
"type_info": "Jsonb"
},
{
"name": "execute_contract_address?",
"ordinal": 8,
"type_info": "Jsonb"
},
{
"name": "tx_format?",
"ordinal": 9,
"type_info": "Int4"
},
{
"name": "refunded_gas",
"ordinal": 10,
"type_info": "Int8"
},
{
"name": "gas_limit",
"ordinal": 11,
"type_info": "Numeric"
},
{
"name": "block_hash",
"ordinal": 12,
"type_info": "Bytea"
},
{
"name": "l1_batch_number?",
"ordinal": 13,
"type_info": "Int8"
},
{
"name": "contract_address?",
"ordinal": 14,
"type_info": "Bytea"
}
],
"nullable": [
false,
true,
true,
true,
true,
true,
false,
null,
null,
true,
false,
true,
false,
true,
false
],
"parameters": {
"Left": [
"Bytea",
"Bytea",
"Bytea"
]
}
},
"query": "\n WITH\n sl AS (\n SELECT\n *\n FROM\n storage_logs\n WHERE\n storage_logs.address = $1\n AND storage_logs.tx_hash = $2\n ORDER BY\n storage_logs.miniblock_number DESC,\n storage_logs.operation_number DESC\n LIMIT\n 1\n )\n SELECT\n transactions.hash AS tx_hash,\n transactions.index_in_block AS index_in_block,\n transactions.l1_batch_tx_index AS l1_batch_tx_index,\n transactions.miniblock_number AS \"block_number!\",\n transactions.error AS error,\n transactions.effective_gas_price AS effective_gas_price,\n transactions.initiator_address AS initiator_address,\n transactions.data -> 'to' AS \"transfer_to?\",\n transactions.data -> 'contractAddress' AS \"execute_contract_address?\",\n transactions.tx_format AS \"tx_format?\",\n transactions.refunded_gas AS refunded_gas,\n transactions.gas_limit AS gas_limit,\n miniblocks.hash AS \"block_hash\",\n miniblocks.l1_batch_number AS \"l1_batch_number?\",\n sl.key AS \"contract_address?\"\n FROM\n transactions\n JOIN miniblocks ON miniblocks.number = transactions.miniblock_number\n LEFT JOIN sl ON sl.value != $3\n WHERE\n transactions.hash = $2\n "
},
"026ab7dd7407f10074a2966b5eac2563a3e061bcc6505d8c295b1b2517f85f1b": {
"describe": {
"columns": [
Expand Down Expand Up @@ -5912,112 +6018,6 @@
},
"query": "\n DELETE FROM basic_witness_input_producer_jobs\n "
},
"6bf641312081de59ae8be08326fc50bd670d8ee9aa7c28eed728dbaa1b8bab25": {
"describe": {
"columns": [
{
"name": "tx_hash",
"ordinal": 0,
"type_info": "Bytea"
},
{
"name": "index_in_block",
"ordinal": 1,
"type_info": "Int4"
},
{
"name": "l1_batch_tx_index",
"ordinal": 2,
"type_info": "Int4"
},
{
"name": "block_number",
"ordinal": 3,
"type_info": "Int8"
},
{
"name": "error",
"ordinal": 4,
"type_info": "Varchar"
},
{
"name": "effective_gas_price",
"ordinal": 5,
"type_info": "Numeric"
},
{
"name": "initiator_address",
"ordinal": 6,
"type_info": "Bytea"
},
{
"name": "transfer_to?",
"ordinal": 7,
"type_info": "Jsonb"
},
{
"name": "execute_contract_address?",
"ordinal": 8,
"type_info": "Jsonb"
},
{
"name": "tx_format?",
"ordinal": 9,
"type_info": "Int4"
},
{
"name": "refunded_gas",
"ordinal": 10,
"type_info": "Int8"
},
{
"name": "gas_limit",
"ordinal": 11,
"type_info": "Numeric"
},
{
"name": "block_hash?",
"ordinal": 12,
"type_info": "Bytea"
},
{
"name": "l1_batch_number?",
"ordinal": 13,
"type_info": "Int8"
},
{
"name": "contract_address?",
"ordinal": 14,
"type_info": "Bytea"
}
],
"nullable": [
false,
true,
true,
true,
true,
true,
false,
null,
null,
true,
false,
true,
false,
true,
false
],
"parameters": {
"Left": [
"Bytea",
"Bytea",
"Bytea"
]
}
},
"query": "\n WITH\n sl AS (\n SELECT\n *\n FROM\n storage_logs\n WHERE\n storage_logs.address = $1\n AND storage_logs.tx_hash = $2\n ORDER BY\n storage_logs.miniblock_number DESC,\n storage_logs.operation_number DESC\n LIMIT\n 1\n )\n SELECT\n transactions.hash AS tx_hash,\n transactions.index_in_block AS index_in_block,\n transactions.l1_batch_tx_index AS l1_batch_tx_index,\n transactions.miniblock_number AS block_number,\n transactions.error AS error,\n transactions.effective_gas_price AS effective_gas_price,\n transactions.initiator_address AS initiator_address,\n transactions.data -> 'to' AS \"transfer_to?\",\n transactions.data -> 'contractAddress' AS \"execute_contract_address?\",\n transactions.tx_format AS \"tx_format?\",\n transactions.refunded_gas AS refunded_gas,\n transactions.gas_limit AS gas_limit,\n miniblocks.hash AS \"block_hash?\",\n miniblocks.l1_batch_number AS \"l1_batch_number?\",\n sl.key AS \"contract_address?\"\n FROM\n transactions\n LEFT JOIN miniblocks ON miniblocks.number = transactions.miniblock_number\n LEFT JOIN sl ON sl.value != $3\n WHERE\n transactions.hash = $2\n "
},
"6c0d03b1fbe6f47546bc34c6b2eab01cb2c55bf86d2c8c99abb1b7ca21cf75c0": {
"describe": {
"columns": [],
Expand Down Expand Up @@ -12129,4 +12129,4 @@
},
"query": "\n SELECT\n l2_to_l1_logs\n FROM\n l1_batches\n WHERE\n number = $1\n "
}
}
}
22 changes: 9 additions & 13 deletions core/lib/dal/src/transactions_web3_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl TransactionsWeb3Dal<'_, '_> {
transactions.hash AS tx_hash,
transactions.index_in_block AS index_in_block,
transactions.l1_batch_tx_index AS l1_batch_tx_index,
transactions.miniblock_number AS block_number,
transactions.miniblock_number AS "block_number!",
transactions.error AS error,
transactions.effective_gas_price AS effective_gas_price,
transactions.initiator_address AS initiator_address,
Expand All @@ -59,12 +59,12 @@ impl TransactionsWeb3Dal<'_, '_> {
transactions.tx_format AS "tx_format?",
transactions.refunded_gas AS refunded_gas,
transactions.gas_limit AS gas_limit,
miniblocks.hash AS "block_hash?",
miniblocks.hash AS "block_hash",
miniblocks.l1_batch_number AS "l1_batch_number?",
sl.key AS "contract_address?"
FROM
transactions
LEFT JOIN miniblocks ON miniblocks.number = transactions.miniblock_number
JOIN miniblocks ON miniblocks.number = transactions.miniblock_number
LEFT JOIN sl ON sl.value != $3
WHERE
transactions.hash = $2
Expand All @@ -78,21 +78,17 @@ impl TransactionsWeb3Dal<'_, '_> {
.fetch_optional(self.storage.conn())
.await?
.map(|db_row| {
let status = match (db_row.block_number, db_row.error) {
(_, Some(_)) => Some(U64::from(0)),
(Some(_), None) => Some(U64::from(1)),
// tx not executed yet
_ => None,
};
let status = db_row.error.map(|_| U64::zero()).unwrap_or_else(U64::one);

let tx_type = db_row.tx_format.map(U64::from).unwrap_or_default();
let transaction_index = db_row.index_in_block.map(U64::from).unwrap_or_default();

let block_hash = db_row.block_hash.map(|bytes| H256::from_slice(&bytes));
let block_hash = H256::from_slice(&db_row.block_hash);
api::TransactionReceipt {
transaction_hash: H256::from_slice(&db_row.tx_hash),
transaction_index,
block_hash,
block_number: db_row.block_number.map(U64::from),
block_number: db_row.block_number.into(),
l1_batch_tx_index: db_row.l1_batch_tx_index.map(U64::from),
l1_batch_number: db_row.l1_batch_number.map(U64::from),
from: H160::from_slice(&db_row.initiator_address),
Expand Down Expand Up @@ -168,7 +164,7 @@ impl TransactionsWeb3Dal<'_, '_> {
.into_iter()
.map(|storage_log| {
let mut log = api::Log::from(storage_log);
log.block_hash = receipt.block_hash;
log.block_hash = Some(receipt.block_hash);
log.l1_batch_number = receipt.l1_batch_number;
log
})
Expand All @@ -181,7 +177,7 @@ impl TransactionsWeb3Dal<'_, '_> {
.into_iter()
.map(|storage_l2_to_l1_log| {
let mut l2_to_l1_log = api::L2ToL1Log::from(storage_l2_to_l1_log);
l2_to_l1_log.block_hash = receipt.block_hash;
l2_to_l1_log.block_hash = Some(receipt.block_hash);
l2_to_l1_log.l1_batch_number = receipt.l1_batch_number;
l2_to_l1_log
})
Expand Down
8 changes: 4 additions & 4 deletions core/lib/types/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ pub struct TransactionReceipt {
pub transaction_index: Index,
/// Hash of the block this transaction was included within.
#[serde(rename = "blockHash")]
pub block_hash: Option<H256>,
pub block_hash: H256,
/// Number of the miniblock this transaction was included within.
#[serde(rename = "blockNumber")]
pub block_number: Option<U64>,
pub block_number: U64,
/// Index of transaction in l1 batch
#[serde(rename = "l1BatchTxIndex")]
pub l1_batch_tx_index: Option<Index>,
Expand Down Expand Up @@ -246,9 +246,9 @@ pub struct TransactionReceipt {
#[serde(rename = "l2ToL1Logs")]
pub l2_to_l1_logs: Vec<L2ToL1Log>,
/// Status: either 1 (success) or 0 (failure).
pub status: Option<U64>,
pub status: U64,
/// State root.
pub root: Option<H256>,
pub root: H256,
/// Logs bloom
#[serde(rename = "logsBloom")]
pub logs_bloom: H2048,
Expand Down

0 comments on commit 625d632

Please sign in to comment.