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

Feat/eng 483 create jobs #19

Merged
merged 16 commits into from
Jul 25, 2018
Merged

Feat/eng 483 create jobs #19

merged 16 commits into from
Jul 25, 2018

Conversation

gjgd
Copy link
Contributor

@gjgd gjgd commented Jul 24, 2018

https://transmute.atlassian.net/browse/ENG-483

  • Job manager
    • Added category to Mineral struct (either Compute or Storage)
    • Added submitJob function
  • DPOS
    • Provider.status was redundant with the containsProvider() function. Removed Provider.status and replaced it with providerStatus that uses containsProvider to determine if Provider is Registered or Unregistered

@gjgd gjgd requested review from eolszewski and OR13 July 24, 2018 20:27
@coveralls
Copy link

coveralls commented Jul 24, 2018

Pull Request Test Coverage Report for Build 127

  • 26 of 26 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 122: 0.0%
Covered Lines: 94
Relevant Lines: 94

💛 - Coveralls

@@ -5,21 +5,69 @@ import "zeppelin-solidity/contracts/math/SafeMath.sol";
contract JobManager {
using SafeMath for uint;

enum MineralCategory { Null, Compute, Storage }

Choose a reason for hiding this comment

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

Why do we have a Null category here? Seems unnecessary - the default can be Compute or Storage without any problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My idea was to use this to check if a mineral exists for that index.
Given that it is not possible to create a Mineral with Null category, or update it to have Null category, the only way it has Null category is that it does not exist (see mineralIsValid function).

However I like your idea of storing the address who submitted the mineral. This would provide a cleaner way to check if the mineral exists. Will do that

} else if (_category == uint(MineralCategory.Storage)) {
mc = MineralCategory.Storage;
} else {
revert();

Choose a reason for hiding this comment

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

Yeah, given that you both cannot create a mineral with category Null and cannot update a mineral to have category Null, I would say that this enum option can be removed.


function mineralIsValid(uint _mineralId) public view returns (bool) {
Mineral memory m = minerals[_mineralId];
return m.category != MineralCategory.Null;

Choose a reason for hiding this comment

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

This code does not permit that a mineral to have a Null category. I would update this to verify that a mineral does in fact exist for that index and that maybe that there isn't already a job associated with it.

Naturally, this will be a bidding process with the best priced job winning (we'd think), but we'll assume first-come, first-serve for simplicity purposes, now.

Ex:

Mineral memory m = minerals[_mineralId];
return m.id < numberOfMinerals && m.jobId == 0

I would also call this something like - mineralIsAvailable or something along those lines given that the point is to make sure we can create a job for it. Whenever you create a mineral, the default value of '0' will be assigned to the jobId and index jobs starting from 1.

p.pricePerStorageMineral = _pricePerStorageMineral;
p.pricePerComputeMineral = _pricePerComputeMineral;
p.blockRewardCut = _blockRewardCut;
p.feeShare = _feeShare;
}

function resignAsProvider(address _provider) internal {
require(providers[_provider].status != ProviderStatus.Unregistered);
require(providerStatus(_provider) != ProviderStatus.Unregistered);

Choose a reason for hiding this comment

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

I feel like this should check to ensure that the provider is Registered vs not Unregistered, for readability purposes.

@@ -112,14 +110,15 @@ contract TransmuteDPOS is TransmuteToken, RoundManager, ProviderPool {
Provider storage p = providers[_provider];
// A delegator is only allowed to bond to himself (in which case he wants to be a Provider)
// or to a Registered Provider
require(_provider == msg.sender || p.status == ProviderStatus.Registered);
ProviderStatus pStatus = providerStatus(_provider);
require(_provider == msg.sender || pStatus == ProviderStatus.Registered);

Choose a reason for hiding this comment

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

Why have a temp variable here and not just use the function in the equality check like you did on line 102?

it('should fail if category is not MINERAL_COMPUTE or MINERAL_STORAGE', async () => {
await assertFail( jm.submitMineral("test", 0) );
await jm.submitMineral("test", MINERAL_COMPUTE);
await jm.submitMineral("test", MINEARL_STORAGE);

Choose a reason for hiding this comment

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

MINERAL_STORAGE*

require('truffle-test-utils').init();

contract('JobManager', accounts => {

let jm;
const MINERAL_COMPUTE = 1;

Choose a reason for hiding this comment

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

These will need to be updated to 0 and 1


it('should accept no name for Mineral', async () => {
const mineralId = (await jm.numberOfMinerals.call()).toNumber();
await jm.submitMineral("", MINERAL_COMPUTE);

Choose a reason for hiding this comment

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

We should probably be associating minerals with the users who submitted them and requiring a non-empty string for a name. If I had created a few minerals, how I would I be able to search them with this architecture?

});
});

it('should accept no name for Mineral', async () => {

Choose a reason for hiding this comment

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

I don't agree with permitting this to be the case. Explanation below.

const mineralId = (await jm.numberOfMinerals.call()).toNumber();
await jm.submitMineral("", MINERAL_COMPUTE);
const mineral = await jm.minerals.call(mineralId);
let [name, _] = mineral;

Choose a reason for hiding this comment

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

_ is not a reasonable name for a variable.

@gjgd gjgd merged commit 7483331 into master Jul 25, 2018
@gjgd gjgd deleted the feat/ENG-483-create-jobs branch July 25, 2018 15:33
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

3 participants