Skip to content

Commit

Permalink
feat(en): Remove SyncBlock.root_hash (#633)
Browse files Browse the repository at this point in the history
## What ❔

Removes `root_hash` field from `SyncBlock`.

## Why ❔

It's not used anywhere, set to a dummy value (miniblock hash) and
doesn't make sense in general (state hashes are computed on L1 batch
level, not miniblock level).

## Checklist

- [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] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `cargo spellcheck
--cfg=./spellcheck/era.cfg --code 1`.
  • Loading branch information
slowli committed Dec 11, 2023
1 parent 87c334e commit d4cc6e5
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 132 deletions.
190 changes: 92 additions & 98 deletions core/lib/dal/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5328,6 +5328,98 @@
},
"query": "SELECT id FROM prover_fri_protocol_versions WHERE recursion_circuits_set_vks_hash = $1 AND recursion_leaf_level_vk_hash = $2 AND recursion_node_level_vk_hash = $3 AND recursion_scheduler_level_vk_hash = $4 "
},
"6ad9309a48f387da7d437ba6ed94aa7b6a42813e5ee566104b904f0bee0dfde7": {
"describe": {
"columns": [
{
"name": "number",
"ordinal": 0,
"type_info": "Int8"
},
{
"name": "l1_batch_number!",
"ordinal": 1,
"type_info": "Int8"
},
{
"name": "last_batch_miniblock?",
"ordinal": 2,
"type_info": "Int8"
},
{
"name": "timestamp",
"ordinal": 3,
"type_info": "Int8"
},
{
"name": "l1_gas_price",
"ordinal": 4,
"type_info": "Int8"
},
{
"name": "l2_fair_gas_price",
"ordinal": 5,
"type_info": "Int8"
},
{
"name": "bootloader_code_hash",
"ordinal": 6,
"type_info": "Bytea"
},
{
"name": "default_aa_code_hash",
"ordinal": 7,
"type_info": "Bytea"
},
{
"name": "virtual_blocks",
"ordinal": 8,
"type_info": "Int8"
},
{
"name": "hash",
"ordinal": 9,
"type_info": "Bytea"
},
{
"name": "consensus",
"ordinal": 10,
"type_info": "Jsonb"
},
{
"name": "protocol_version!",
"ordinal": 11,
"type_info": "Int4"
},
{
"name": "fee_account_address?",
"ordinal": 12,
"type_info": "Bytea"
}
],
"nullable": [
false,
null,
null,
false,
false,
false,
true,
true,
false,
false,
true,
true,
false
],
"parameters": {
"Left": [
"Int8"
]
}
},
"query": "SELECT miniblocks.number, COALESCE(miniblocks.l1_batch_number, (SELECT (max(number) + 1) FROM l1_batches)) as \"l1_batch_number!\", (SELECT max(m2.number) FROM miniblocks m2 WHERE miniblocks.l1_batch_number = m2.l1_batch_number) as \"last_batch_miniblock?\", miniblocks.timestamp, miniblocks.l1_gas_price, miniblocks.l2_fair_gas_price, miniblocks.bootloader_code_hash, miniblocks.default_aa_code_hash, miniblocks.virtual_blocks, miniblocks.hash, miniblocks.consensus, miniblocks.protocol_version as \"protocol_version!\", l1_batches.fee_account_address as \"fee_account_address?\" FROM miniblocks LEFT JOIN l1_batches ON miniblocks.l1_batch_number = l1_batches.number WHERE miniblocks.number = $1"
},
"6b53e5cb619c9649d28ae33df6a43e6984e2d9320f894f3d04156a2d1235bb60": {
"describe": {
"columns": [
Expand Down Expand Up @@ -5613,104 +5705,6 @@
},
"query": "SELECT * FROM call_traces WHERE tx_hash IN (SELECT hash FROM transactions WHERE miniblock_number = $1)"
},
"7947dd8e7d6c138146f7ebe6b1e89fcd494b2679ac4e9fcff6aa2b2944aeed50": {
"describe": {
"columns": [
{
"name": "number",
"ordinal": 0,
"type_info": "Int8"
},
{
"name": "l1_batch_number!",
"ordinal": 1,
"type_info": "Int8"
},
{
"name": "last_batch_miniblock?",
"ordinal": 2,
"type_info": "Int8"
},
{
"name": "timestamp",
"ordinal": 3,
"type_info": "Int8"
},
{
"name": "root_hash?",
"ordinal": 4,
"type_info": "Bytea"
},
{
"name": "l1_gas_price",
"ordinal": 5,
"type_info": "Int8"
},
{
"name": "l2_fair_gas_price",
"ordinal": 6,
"type_info": "Int8"
},
{
"name": "bootloader_code_hash",
"ordinal": 7,
"type_info": "Bytea"
},
{
"name": "default_aa_code_hash",
"ordinal": 8,
"type_info": "Bytea"
},
{
"name": "virtual_blocks",
"ordinal": 9,
"type_info": "Int8"
},
{
"name": "hash",
"ordinal": 10,
"type_info": "Bytea"
},
{
"name": "consensus",
"ordinal": 11,
"type_info": "Jsonb"
},
{
"name": "protocol_version!",
"ordinal": 12,
"type_info": "Int4"
},
{
"name": "fee_account_address?",
"ordinal": 13,
"type_info": "Bytea"
}
],
"nullable": [
false,
null,
null,
false,
false,
false,
false,
true,
true,
false,
false,
true,
true,
false
],
"parameters": {
"Left": [
"Int8"
]
}
},
"query": "SELECT miniblocks.number, COALESCE(miniblocks.l1_batch_number, (SELECT (max(number) + 1) FROM l1_batches)) as \"l1_batch_number!\", (SELECT max(m2.number) FROM miniblocks m2 WHERE miniblocks.l1_batch_number = m2.l1_batch_number) as \"last_batch_miniblock?\", miniblocks.timestamp, miniblocks.hash as \"root_hash?\", miniblocks.l1_gas_price, miniblocks.l2_fair_gas_price, miniblocks.bootloader_code_hash, miniblocks.default_aa_code_hash, miniblocks.virtual_blocks, miniblocks.hash, miniblocks.consensus, miniblocks.protocol_version as \"protocol_version!\", l1_batches.fee_account_address as \"fee_account_address?\" FROM miniblocks LEFT JOIN l1_batches ON miniblocks.l1_batch_number = l1_batches.number WHERE miniblocks.number = $1"
},
"79cdb4cdd3c47b3654e6240178985fb4b4420e0634f9482a6ef8169e90200b84": {
"describe": {
"columns": [
Expand Down
17 changes: 7 additions & 10 deletions core/lib/dal/src/models/storage_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use zksync_protobuf::{read_required, ProtoFmt};
use zksync_types::{api::en, Address, L1BatchNumber, MiniblockNumber, Transaction, H160, H256};

#[derive(Debug, Clone, sqlx::FromRow)]
pub struct StorageSyncBlock {
pub(crate) struct StorageSyncBlock {
pub number: i64,
pub l1_batch_number: i64,
pub last_batch_miniblock: Option<i64>,
pub timestamp: i64,
pub root_hash: Option<Vec<u8>>,
// L1 gas price assumed in the corresponding batch
pub l1_gas_price: i64,
// L2 gas price assumed in the corresponding batch
Expand Down Expand Up @@ -48,11 +47,6 @@ impl StorageSyncBlock {
.map(|n| n == self.number)
.unwrap_or(false),
timestamp: self.timestamp.try_into().context("timestamp")?,
root_hash: self
.root_hash
.map(|h| parse_h256(&h))
.transpose()
.context("root_hash")?,
l1_gas_price: self.l1_gas_price.try_into().context("l1_gas_price")?,
l2_fair_gas_price: self
.l2_fair_gas_price
Expand Down Expand Up @@ -106,22 +100,25 @@ pub struct ConsensusBlockFields {
}

impl ConsensusBlockFields {
pub fn decode(src: &en::ConsensusBlockFields) -> anyhow::Result<Self> {
zksync_protobuf::decode(&src.0 .0)
}

pub fn encode(&self) -> en::ConsensusBlockFields {
en::ConsensusBlockFields(zksync_protobuf::encode(self).into())
}
pub fn decode(x: &en::ConsensusBlockFields) -> anyhow::Result<Self> {
zksync_protobuf::decode(&x.0 .0)
}
}

impl ProtoFmt for ConsensusBlockFields {
type Proto = crate::models::proto::ConsensusBlockFields;

fn read(r: &Self::Proto) -> anyhow::Result<Self> {
Ok(Self {
parent: read_required(&r.parent).context("parent")?,
justification: read_required(&r.justification).context("justification")?,
})
}

fn build(&self) -> Self::Proto {
Self::Proto {
parent: Some(self.parent.build()),
Expand Down
Loading

0 comments on commit d4cc6e5

Please sign in to comment.