-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Contract redirection record #694
Comments
Maybe we can iterate all the keys and move these keys to the new one, is faster than Get, Remove and Put. |
I agree Erik, for the current data format.. however, on MPT, the scripthash is just a header, so migration would happen immediately, independent of how many keys are there. So, I think its better to adopt MPT asap. |
How does MPT help migration happen immediately? |
On MPT, storage keys are spread through all the tree (or trie to be precise), so when a change is made on the leaf (value change for example), the root node changes. However, when a change is made on root, no change needs to be propagated down the tree. Our current proposal creates a MPT for every contract, so a scripthash change will just affect the MPT contract root node, a constant-time change O(1). To make things more solid, we can also propose a global MPT node that stores the scripthashes of the existing contracts (with storage capabilities), but even this change would only require a maximum of 20 steps in a near impossible scenario, so it will also be O(1). To finish, even if storage is not affected by migration, perhaps it's nice to leave a proxy from the old contract to the new one, in order to make things easier for users when migrating contracts. In this sense, I fully agree with this proposal. |
@rodoufu we need to prepare a tutorial on MPT for the whole community understand our proposal. We also need to make sure that issue with "other implementations" is effectively resolved. |
@igormcoelho, when you say tutorial, what are you thinking about? |
Some slides, or a medium post... explaining step by step how the proposal will be. The simpler the better :) |
@erikzhang This contract redirection is an amazing idea, just to enforce it here... I always want this feature!! In the case of NEP-5 "frameworks" and contract inheritance this would be very useful, as people may migrate the base, and it will still be accessible: #772 |
Is possible to use leveldb in parallel? is thread safe? |
Yes. |
@erikzhang and @igormcoelho, it is another topic, however, a little bit related, what about a native class that contracts inherits if they are willing to use migrate? |
In fact, it's a connected topic brother... very well remembered, it's fundamental to the concept of redirection here. Perhaps, users should be able to disable redirection when invoking the appcall ( |
In the case of massive migration, it's better to solve this with MPT storages. A single storage key changes the whole storage location @rodoufu (whole storage is moved in O(1) constant time) The proposal by Erik is in fact much deeper (in my opinion), it means that you could invoke some contract, and it "automatically" invoke another one (migrated from the first one).
To implement it, my opinion is to have two different types of calls, one accepting direction, and another that won't accept. There are situations where you must be sure that scripthash matches exactly. Some examples of needed discussion:
|
My opinion in what should happen after redirection (we can discuss over the bullet points):
|
In my opinion we need to know how many information could produce a big delay, because maybe is easier to solve it with multi threads. |
The bottleneck of storage migration lies in the hard disk IO, not the CPU. So multithreading does not solve the problem here. |
Currently, when a smart contract is upgraded, all stored data is migrated to the new contract. If there is a large amount of data in the contract, the workload of the migration will be very large and may cause a DoS attack.
So I proposed a redirection mechanism. Instead of migrating data directly during each contract upgrade, a redirection record is created. When the contract reads the data, it can find the original contract hash based on the redirection record, thus accessing the correct data.
The downside to this is that the old contract cannot be redeployed in the future. But I don't think this will have any effect. Unless a hash collision occurs, this probability is negligible.
The text was updated successfully, but these errors were encountered: