Skip to content

Commit

Permalink
Merge pull request #196 from eqlabs/fix_l2_reorg
Browse files Browse the repository at this point in the history
Fix L2 reorg
  • Loading branch information
Mirko-von-Leipzig committed Mar 14, 2022
2 parents d7bfc57 + 8c1d180 commit ebd7cf1
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 16 deletions.
221 changes: 211 additions & 10 deletions crates/pathfinder/resources/contracts/core_impl.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
{
"indexed": true,
"internalType": "uint256",
"name": "from_address",
"name": "fromAddress",
"type": "uint256"
},
{
"indexed": true,
"internalType": "address",
"name": "to_address",
"name": "toAddress",
"type": "address"
},
{
Expand All @@ -30,13 +30,13 @@
{
"indexed": true,
"internalType": "address",
"name": "from_address",
"name": "fromAddress",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "to_address",
"name": "toAddress",
"type": "uint256"
},
{
Expand Down Expand Up @@ -67,13 +67,13 @@
{
"indexed": true,
"internalType": "uint256",
"name": "from_address",
"name": "fromAddress",
"type": "uint256"
},
{
"indexed": true,
"internalType": "address",
"name": "to_address",
"name": "toAddress",
"type": "address"
},
{
Expand All @@ -92,13 +92,13 @@
{
"indexed": true,
"internalType": "address",
"name": "from_address",
"name": "fromAddress",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "to_address",
"name": "toAddress",
"type": "uint256"
},
{
Expand Down Expand Up @@ -226,11 +226,126 @@
"name": "LogStateUpdate",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "fromAddress",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "toAddress",
"type": "uint256"
},
{
"indexed": true,
"internalType": "uint256",
"name": "selector",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256[]",
"name": "payload",
"type": "uint256[]"
},
{
"indexed": false,
"internalType": "uint256",
"name": "nonce",
"type": "uint256"
}
],
"name": "MessageToL2Canceled",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "fromAddress",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "toAddress",
"type": "uint256"
},
{
"indexed": true,
"internalType": "uint256",
"name": "selector",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256[]",
"name": "payload",
"type": "uint256[]"
},
{
"indexed": false,
"internalType": "uint256",
"name": "nonce",
"type": "uint256"
}
],
"name": "MessageToL2CancellationStarted",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "toAddress",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "selector",
"type": "uint256"
},
{
"internalType": "uint256[]",
"name": "payload",
"type": "uint256[]"
},
{
"internalType": "uint256",
"name": "nonce",
"type": "uint256"
}
],
"name": "cancelL1ToL2Message",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "configHash",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "from_address",
"name": "fromAddress",
"type": "uint256"
},
{
Expand Down Expand Up @@ -328,6 +443,25 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "msgHash",
"type": "bytes32"
}
],
"name": "l1ToL2MessageCancellations",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "l1ToL2MessageNonce",
Expand Down Expand Up @@ -379,6 +513,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "messageCancellationDelay",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "programHash",
Expand Down Expand Up @@ -409,7 +556,7 @@
"inputs": [
{
"internalType": "uint256",
"name": "to_address",
"name": "toAddress",
"type": "uint256"
},
{
Expand All @@ -434,6 +581,32 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "newConfigHash",
"type": "uint256"
}
],
"name": "setConfigHash",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "delayInSeconds",
"type": "uint256"
}
],
"name": "setMessageCancellationDelay",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -506,6 +679,34 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "toAddress",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "selector",
"type": "uint256"
},
{
"internalType": "uint256[]",
"name": "payload",
"type": "uint256[]"
},
{
"internalType": "uint256",
"name": "nonce",
"type": "uint256"
}
],
"name": "startL1ToL2MessageCancellation",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "stateBlockNumber",
Expand Down
4 changes: 2 additions & 2 deletions crates/pathfinder/src/state/sync/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn sync(
DownloadBlock::AtHead => tokio::time::sleep(Duration::from_secs(5)).await,
DownloadBlock::Reorg => {
let some_head = head.unwrap();
reorg(some_head, &tx_event, &sequencer)
head = reorg(some_head, &tx_event, &sequencer)
.await
.context("L2 reorg")?;

Expand All @@ -83,7 +83,7 @@ pub async fn sync(

if let Some(some_head) = head {
if some_head.1 != block.parent_block_hash {
reorg(some_head, &tx_event, &sequencer)
head = reorg(some_head, &tx_event, &sequencer)
.await
.context("L2 reorg")?;

Expand Down
7 changes: 3 additions & 4 deletions crates/pathfinder/src/storage/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,17 @@ impl ContractCodeTable {
pub struct ContractsTable {}

impl ContractsTable {
/// Insert a contract into the table.
///
/// Fails if the contract address is already populated.
/// Insert a contract into the table, does nothing if the contract already exists.
///
/// Note that [hash](ContractHash) must reference a contract stored in [ContractCodeTable].
pub fn insert(
transaction: &Transaction,
address: ContractAddress,
hash: ContractHash,
) -> anyhow::Result<()> {
// A contract may be deployed multiple times due to L2 reorgs, so we ignore all after the first.
transaction.execute(
r"INSERT INTO contracts (address, hash) VALUES (:address, :hash)",
r"INSERT OR IGNORE INTO contracts (address, hash) VALUES (:address, :hash)",
named_params! {
":address": &address.0.to_be_bytes()[..],
":hash": &hash.0.to_be_bytes()[..],
Expand Down

0 comments on commit ebd7cf1

Please sign in to comment.