-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block n's MMR delta corresponds to block n-1's chain root #133
Comments
That is the correct behavior. The block needs to be created so that the MMR can be updated, meaning when the block is produced only the MMR of the previous block is available. Having the latest MMR in the block header would mean the structures are self referential (which doesn't work because of hashing). related issue: #114 |
I think there is something off in the interplay between:
According to the snippet pasted by @igamigo - the MMR is kind of running 1 block behind where it should be (i.e., at block 1666 we get MMR root that we should have gotten at block 1665). |
It seems like the issue is that
Investigating... |
So I believe the issue could be tracked to this line. When starting the node, the genesis block is first loaded to the DB (if not present from before) and after that, all corresponding worker threads are spawned. When the thread that handles the state is loaded, it initializes the state Mmr with DB data which means on startup the chain root of the state Mmr will have the genesis block. When it's time to build block number 1, I drafted a PR (#134) mainly to test consistency with the client and it seems to work fine with those changes. This approach however causes state sync to fail when the only block in the chain is the genesis block. It's also a change that likely reaches some other parts of the protocol with which I am not familiar. I could have some wrong assumptions with this but talking to @bobbinth it seems that in general, for block N we want the Mmr to contain a forest of N-1, which was not what was happening anyway. |
Great find! Indeed the error was in the store. I've addressed it slightly differently in #135 - I think it solves the problem in a slightly simpler way. |
(Related to 0xPolygonMiden/miden-base#305)
In the client, we make requests to the sync state endpoint in order to retrieve newer blocks and apply changes to the local partial MMR.
It currently looks like incoming block data from the node follows this pattern: Block$n$ 's MMR delta corresponds to block $n-1$ 's chain root. As a consequence of this, any time we try to execute a transaction the prologue's check will fail because we provide block $n$ 's chain root but the latest MMR peaks will only ever match block $n-1$ 's chain root.
Here's an example when doing a state sync on 2 subsequent blocks from the client:
The text was updated successfully, but these errors were encountered: