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

Add GSN to BasicAdapter, fix calculating number of registered darknodes after a Registry upgrade #86

Merged
merged 15 commits into from Mar 19, 2020

Conversation

0x31
Copy link
Contributor

@0x31 0x31 commented Mar 16, 2020

Note - Solidity's VSCode extension now comes with a source code formatter, so there's a lot of style-only changes. See below for the specific changes.

DarknodeRegistry update

Problem Description

The DarknodeRegistry contract currently keeps track of the number of darknodes registered in the previous, current and next epoch. However, this is independent of its Store contract which holds the registration state of each darknode. If a new Registry is used against an existing Store, these numbers are out of sync.

Solution

When the DarknodeRegistry is linked to a Store, is syncs its darknode counts.

The main change to DarknodeRegistry can be found here:

https://github.com/renproject/darknode-sol/pull/86/files#diff-b69098100468efec280620252f903886R716-R742

function getDarknodeCountFromEpochs(
bool _includePreviousEpoch,
bool _includeCurrentEpoch,
bool _includeNextEpoch
) private view returns (uint256) {
// Begin with the first node in the list
uint256 n = 0;
address next = store.begin();
// Iterate until all registered Darknodes have been collected
while (true) {
if (next == address(0)) {
break;
}
if (
(_includePreviousEpoch && isRegisteredInPreviousEpoch(next)) ||
(_includeCurrentEpoch && isRegistered(next)) ||
(_includeNextEpoch &&
((isRegistered(next) && !isPendingDeregistration(next)) ||
isPendingRegistration(next)))
) {
n += 1;
}
next = store.next(next);
}
return n;
}

function claimStoreOwnership() external {
store.claimOwnership();
// Sync state with new store.
// Note: numDarknodesPreviousEpoch is set to 0 for a newly deployed DNR.
numDarknodesPreviousEpoch = getDarknodeCountFromEpochs(
true,
false,
false
);
numDarknodes = getDarknodeCountFromEpochs(false, true, false);
numDarknodesNextEpoch = getDarknodeCountFromEpochs(false, false, true);
}

Add GSN to Basic Adapter

The BasicAdapter contract is an example adapter, and this PR adds GSN support to it. This involves inheriting from GSNRecipient and implementing acceptRelayedCall. Currently, it accepts all relayed calls.


interface IInShifter {
// function status(bytes32) external returns (bool);
Copy link
Contributor

Choose a reason for hiding this comment

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

If it is left commented out, it either needs a comment explaining why it has been left here, or it should be removed.

contracts/Protocol/ProtocolStorage.sol Show resolved Hide resolved
contracts/Protocol/ProtocolLogic.sol Show resolved Hide resolved
contracts/DarknodeRegistry/DarknodeRegistry.sol Outdated Show resolved Hide resolved
contracts/DarknodeRegistry/DarknodeRegistry.sol Outdated Show resolved Hide resolved
@0x31 0x31 changed the base branch from master to staging March 18, 2020 05:13
@0x31 0x31 changed the base branch from staging to master March 18, 2020 05:49
@loongy
Copy link
Contributor

loongy commented Mar 19, 2020

@noiach coveralls reports that tests are missing for transferOwnership in the ProtocolLogic contract. Please add some tests for that, and then we can go ahead and merge.

@0x31
Copy link
Contributor Author

0x31 commented Mar 19, 2020

I think that's the coverage for master.

See https://coveralls.io/github/renproject/darknode-sol?branch=feat/adapter-with-gsn

@0x31
Copy link
Contributor Author

0x31 commented Mar 19, 2020

Coverage dropped (-0.08%) because of some GSN functions in an example contract that aren't tested.

Copy link
Contributor

@loongy loongy left a comment

Choose a reason for hiding this comment

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

Ok, thanks!

@loongy loongy merged commit 3ec7d69 into master Mar 19, 2020
@loongy loongy deleted the feat/adapter-with-gsn branch March 19, 2020 00:45
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.

None yet

2 participants