Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/vb-is_previous_aggregation-opera…
Browse files Browse the repository at this point in the history
…tion_confirmed' into dvush-new-sc
  • Loading branch information
dvush committed Feb 2, 2021
2 parents 087f920 + f71c62c commit 925e166
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 13 deletions.
26 changes: 13 additions & 13 deletions core/bin/zksync_eth_sender/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,20 @@ impl DatabaseInterface for Database {

async fn is_previous_operation_confirmed(
&self,
_connection: &mut StorageProcessor<'_>,
_op: &ETHOperation,
connection: &mut StorageProcessor<'_>,
op: &ETHOperation,
) -> anyhow::Result<bool> {
// TODO
Ok(true)
// let previous_op = op.id - 1;
// if previous_op < 0 {
// return Ok(true);
// }
//
// Ok(connection
// .ethereum_schema()
// .is_aggregated_op_confirmed(previous_op)
// .await?)
let previous_op = op.id - 1;
if previous_op <= 0 {
return Ok(true);
}

let confirmed = connection
.ethereum_schema()
.is_aggregated_op_confirmed(previous_op)
.await?;

Ok(confirmed)
}

async fn confirm_operation(
Expand Down
62 changes: 62 additions & 0 deletions core/lib/storage/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,68 @@
]
}
},
"72e68d860a956cd99848f609bc4af41f20e84ca528ba01a7dc2dbe95f3fd3af1": {
"query": "SELECT * FROM eth_operations WHERE id = $1",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "nonce",
"type_info": "Int8"
},
{
"ordinal": 2,
"name": "confirmed",
"type_info": "Bool"
},
{
"ordinal": 3,
"name": "raw_tx",
"type_info": "Bytea"
},
{
"ordinal": 4,
"name": "op_type",
"type_info": "Text"
},
{
"ordinal": 5,
"name": "final_hash",
"type_info": "Bytea"
},
{
"ordinal": 6,
"name": "last_deadline_block",
"type_info": "Int8"
},
{
"ordinal": 7,
"name": "last_used_gas_price",
"type_info": "Numeric"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false,
false,
false,
false,
false,
true,
false,
false
]
}
},
"74a5cc4affa23433b5b7834df6dfa1a7a2c5a65f23289de3de5a4f1b93f89c06": {
"query": "SELECT address FROM account_creates WHERE account_id = $1",
"describe": {
Expand Down
18 changes: 18 additions & 0 deletions core/lib/storage/src/ethereum/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,24 @@ impl<'a, 'c> EthereumSchema<'a, 'c> {
Ok(response)
}

/// Returns whether the operation with the given id was confirmed.
/// If the operation with such id does not exist, then it returns Ok(false).
pub async fn is_aggregated_op_confirmed(&mut self, id: i64) -> QueryResult<bool> {
let start = Instant::now();
let confirmed = sqlx::query_as!(
StorageETHOperation,
"SELECT * FROM eth_operations WHERE id = $1",
id
)
.fetch_optional(self.0.conn())
.await?
.map(|op| op.confirmed)
.unwrap_or_default();

metrics::histogram!("sql.ethereum.is_aggregated_op_confirmed", start.elapsed());
Ok(confirmed)
}

/// Retrieves the Ethereum operation ID given the tx hash.
async fn get_eth_op_id(&mut self, hash: &H256) -> QueryResult<i64> {
let start = Instant::now();
Expand Down
1 change: 1 addition & 0 deletions infrastructure/grafana/dashboards/sql_ethereum.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local metrics = [
"sql.ethereum.add_hash_entry",
"sql.ethereum.confirm_eth_tx",
"sql.ethereum.get_eth_op_id",
"sql.ethereum.is_aggregated_op_confirmed",
"sql.ethereum.get_next_nonce",
"sql.ethereum.initialize_eth_data",
"sql.ethereum.load_average_gas_price",
Expand Down

0 comments on commit 925e166

Please sign in to comment.