neo
neo copied to clipboard
Store contract ID->hash mapping and allow to iterate over contracts
Summary or problem description
- Some private chains like NeoFS sidechain have well-known IDs for non-native contracts, but their hashes can change from one network to another (because contracts change over time).
- There are requests like neo-project/neo-modules#748 that have a need to iterate over contracts, but the best way to do it is using historic deployment order which is closely tied to contract's ID.
Do you have any solution you want to propose?
- Store ID->hash mapping in the
ContractManagement
contract, it doesn't need a lot of storage space. - Provide
getContractByID(id integer)
method that will return contract's state corresponding to ID (or just a hash). - Provide
listContracts
(orlistNonNative
) method that will return an iterator with contract hashes in deployment order (by ID). - Extend
getcontractstate
RPC with the ability to request contracts by ID.
Neo Version
- Neo 3
Where in the software does this update applies to?
- Native contracts
- RPC (HTTP)
- SDK
One map store active contracts and another for destroyed contracts?
https://github.com/neo-project/neo/blob/28ab45a6eca51bacadfa2b84c27f445b40e50a24/src/Neo/SmartContract/Native/NativeContract.cs#L144
The hash of a native contract is determined by its name and should not change.
One map store active contracts and another for destroyed contracts?
Well, there could be some deactivation flag stored, although we already block destroyed contracts now. Not sure about that, active ones are the most interesting to me.
The hash of a native contract is determined by its name and should not change.
This issue is specifically about non-native ones. Consider NeoFS chain, it has NNS contract deployed there as the contract number 1, that's the policy, but it differs from chain to chain. Also, contract iterator is a useful thing to have.
We need this feature to improve the NeoFS deployment in testing/on-prem environment.
We want to pre-generate signed transactions to update settings in Sidechain contracts and use them directly, without the need to have access to Alphabet private keys from the CI environment.
Can also be considered a security improvement =)
I think it makes sense!