You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: mechanism to calculate last settled block by not using metadata (#838)
## 🔄 Changes Summary
This PR introduces a new interface called `CertificateQuerier` which,
for now, has only one function called `GetLastSettledCertificateToBlock`
which calculates the last settled block from a previously settled
certificate.
This will be used on the validator, to calculate what was the last
settled block, so we can figure out from which block a new certificate
that is being verified is built.
It will also be used on startup from scratch, when `aggsender` syncs its
state with `agglayer`, so we can save the `ToBlock` of the last settled
certificate in the `db`.
The motivation behind this PR is to not use the `Metadata` field on the
certificate, since it will not be signed by the proposer and validators,
hence, it can be faked, but deduce the block range from other
certificate data.
## How the last settled block is calculated
The last settled block in the `CertificateQuerier` is calculated like
this:
- First it will check the `NewLocalExitRoot` field on the certificate,
if it is not the first `empty` LER, meaning, there were some bridge
exits in the certificate, or in certificates before it, it will get the
block num on which the `NewLocalExitRoot` hash was added on `L2` by
calling the `L2 bridge syncer`.
- Secondly, it will call the `agglayer` endpoint to get the latest
settled imported bridge exit. Note that this PR added only the endpoint
sceleton, since this is not yet implemented on `agglayer`. This endpoint
will return the `GlobalIndex` of the last settled imported bridge exit
(claim), and we will use that to get the claim from the `L2 bridge
syncer` since `GlobalIndex` is unique per claim.
- Thirdly, it will ping the `AggchainFEP` rollup contract to get the
last settled `L2` block from it (which is gotten from the `aggchain
proof` in the `FEP` certificates). If the network is not `FEP` this call
will just return 0.
- At the end, it will compare the 3 blocks gotten in previous steps, and
choose the max value from it.
We need all three values because, PP certificates can either contain
only bridge exits, or only imported bridge exits, and FEP certificates
can be empty.
**IMPORTANT NOTE**: This code is not used anywhere. It will be used in
subsequent PRs.
## ⚠️ Breaking Changes
NA
## 📋 Config Updates
NA
## ✅ Testing
- 🤖 **Automatic**: aggkit CI
0 commit comments