Skip to content
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

Store contract ID->hash mapping and allow to iterate over contracts #2803

Closed
roman-khimov opened this issue Aug 9, 2022 · 5 comments · Fixed by #2807
Closed

Store contract ID->hash mapping and allow to iterate over contracts #2803

roman-khimov opened this issue Aug 9, 2022 · 5 comments · Fixed by #2807
Labels
Discussion Initial issue state - proposed but not yet accepted

Comments

@roman-khimov
Copy link
Contributor

Summary or problem description

  1. 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).
  2. There are requests like List all deployed contracts/tokens? 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?

  1. Store ID->hash mapping in the ContractManagement contract, it doesn't need a lot of storage space.
  2. Provide getContractByID(id integer) method that will return contract's state corresponding to ID (or just a hash).
  3. Provide listContracts (or listNonNative) method that will return an iterator with contract hashes in deployment order (by ID).
  4. 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
@roman-khimov roman-khimov added the Discussion Initial issue state - proposed but not yet accepted label Aug 9, 2022
@Jim8y
Copy link
Contributor

Jim8y commented Aug 9, 2022

One map store active contracts and another for destroyed contracts?

@erikzhang
Copy link
Member

this.Hash = Helper.GetContractHash(UInt160.Zero, 0, Name);

The hash of a native contract is determined by its name and should not change.

@roman-khimov
Copy link
Contributor Author

roman-khimov commented Aug 10, 2022

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.

@realloc
Copy link

realloc commented Aug 10, 2022

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 =)

roman-khimov added a commit to roman-khimov/neo that referenced this issue Aug 22, 2022
That probably is the lighest design possible, store and retrieve hashes
only. But it can be expanded to return full contract state (getContractByID,
for example) and probably even iterate over contract states.

Fixes neo-project#2803.
roman-khimov added a commit to roman-khimov/neo that referenced this issue Aug 22, 2022
That probably is the lighest design possible, store and retrieve hashes
only. But it can be expanded to return full contract state (getContractByID,
for example) and probably even iterate over contract states.

Fixes neo-project#2803.
@superboyiii
Copy link
Member

I think it makes sense!

shargon added a commit that referenced this issue Sep 5, 2022
* Native: store ID->hash map in ContractManagement, add iterator

That probably is the lighest design possible, store and retrieve hashes
only. But it can be expanded to return full contract state (getContractByID,
for example) and probably even iterate over contract states.

Fixes #2803.

* ContractManagement: rework GetContractHash into GetContractById

* ContractManagement: fix GetContractById comment

* Update ContractManagement.cs

* Update ContractManagement.cs

* Update src/Neo/SmartContract/Native/ContractManagement.cs

Co-authored-by: Shargon <[email protected]>

Co-authored-by: Erik Zhang <[email protected]>
Co-authored-by: Shargon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Initial issue state - proposed but not yet accepted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants