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

Incremental namespace #15

Merged
merged 20 commits into from
Mar 11, 2021
Merged

Incremental namespace #15

merged 20 commits into from
Mar 11, 2021

Conversation

brickpop
Copy link
Contributor

@brickpop brickpop commented Mar 5, 2021

This pull requests adapts the smart contracts to be ready for future flexible parameterization needs.

Summary of changes:

  • The results methods of Processes is now part of the new Results smart contract (future ERC3k work)
  • The Namespaces contract is now simply a central registry for Processes contracts to self register
  • What was the Namespaces contract now is called Genesis, and it acts as a central registry where we define Chains (genesis, validators, oracles)
  • The namespace field is no longer part of a process settings/status. Is it a global contract setting.
  • Splitting lib/index.ts into separate files for more maintainable exports

Now:

  • When a process contract is deployed, it calls the register() method on the Namespaces contract, and receives a unique namespaceId as a result
  • When a Processes contract is deployed, its address should be set on the (already existing) Results contract
  • When an oracle publishes results on the Results contract, the contract will jump to the Processes contract it has defined and will set the given processId as completed (Status.RESULTS)

Main tasks

  • Typescript bindings adapted
  • Testing adapted and expanded
  • Readme updated
  • Deploy script updated

// Full list for exhaustive retrieval
bytes[] validatorList; // Public key array
address[] oracleList; // Oracles allowed to submit processes to the Vochain and publish results on the process contract
// Bool mapping for fast checking
Copy link
Member

@jordipainan jordipainan Mar 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally do not like having:

  • Array of validators
  • Mapping of validators
  • Array of oracles
  • Mapping of oracles

Btw, I trust your criteria and given the time constrains this is fine for me. But I would like to see how big the improvement is for having the data duplication and method complexity increased justified.

Copy link
Contributor Author

@brickpop brickpop Mar 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally it would be a mapping, but the problem is than mappings cannot be iterated or retrieved all at once.

Initially it was an array, and it was good for add and remove operations. However, it was bad for isOracle and isValidator since a for loop was needed to search within the array, in addition to the keccak256 of each array item. These methods are used when setting the results on chain and triggering binding actions.

The goal of adding a (redundant) mapping was to have isOracle and isValidator with constant cost, instead of linear. It is marginally more expensive to add an oracle/validator, but this is a one time operation. And from then on, all reads become much cheaper.

emit ChainRegistered(chainCount);
newChainId = chainCount;

chainCount = chainCount + 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not chainCount++; ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some languages where ident++ is discouraged/disallowed, because it may have an ambiguous behavior when combined in complex instructions. I thought Solidity to be the case, although it seems that it is actually possible to use it like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thought the same but I tested it and it is not that kind of complex operation, it is fine having ++ and +=1 and I think is cleaner.

* Registers the (processes) contract calling this function into a new namespace, assigning it to the given chainId.
* Returns the new namespace ID that has been registered
*/
function register() public override returns (uint32 result) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see this function a bit problematic. I was about to write some solutions that came up to my mind but maybe it is better to tackle afterwards. But .. what about having this function payable and a fee that increments as the same msg.sender registers namespaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure on how useful it can be to disincentivize upgrading the processes contract. Registering a processes instance has no implications for us and network fees disincentivize sending useless transactions with the gas fees.

The only issue would be that a spammer could bump the namespace numbers artificially, but he/she would be burning ether for no real benefit.

.oracles[currentLength - 1];
namespaces[namespace].oracles.pop();
// The mapping starts at index 1
namespaceCount = namespaceCount + 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before with ++ :)

@brickpop brickpop merged commit 11eadd8 into main Mar 11, 2021
@brickpop brickpop deleted the incremental-namespace branch March 11, 2021 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants