Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Implement SIP9 #136

Merged
merged 25 commits into from May 3, 2018
Merged

Implement SIP9 #136

merged 25 commits into from May 3, 2018

Conversation

braydonf
Copy link
Contributor

@braydonf braydonf commented Oct 19, 2017

@braydonf braydonf mentioned this pull request Oct 23, 2017
6 tasks
@braydonf braydonf changed the title [WIP] Implement SIP9 Implement SIP9 Nov 20, 2017
token: {
type: String,
required: false,
unique: true

Choose a reason for hiding this comment

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

The token is generated by the farmer rmd160sha256(crypto.randomBytes(512)).

Over time the farmer will generate the same token more than once. 160bit random is no garanty. Unique constraint violation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True that 160bit is not as much as 256bits, however it's still huge. 160bit hashes are used for pay-to-public-key hash for Bitcoin transactions, and issues have been raised before and addressed with segwit updates, but the attack is still very impractical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ethereum nodeIDs are also 160bits

Copy link

Choose a reason for hiding this comment

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

Bitcoin has only 900K unique addresses. The same address can be generated twice.

The storj network is different. Every farmer will "brute force token generation" 24/7. My farmer is generating 50K tokens per month. Lets say we have only 10K active farmer. A total of 500M brute force tokens per month. Even if the chance is very low we have to deal with so many tokens that I would expect a few collisions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would take roughly 243,583,606,200,000,000,000,000,000,000,000,000,000 years to have collision at that rate. There are 2 ^ 160 possible tokens with 160 bits. Furthermore there isn't a restriction on length, and it could be 32 bytes instead of 20 bytes (another topic).

@braydonf
Copy link
Contributor Author

Rebased on latest master

Braydon Fuller added 16 commits April 18, 2018 18:40
- Have users be an array. Mirror storage events of a shard that multiple users
  have uploaded will have multiple users interested. This will provide an ability
  to track how long the mirror should be held. When one user deletes the shard,
  the user will be removed from the storage event. When there is only one user
  the storeEnd will be updated to terminate the storage of the shard.
- Seperate user and client, thus it's possible to have a client and user
  for mirror actions, so that it's possible to query storage events of mirrors
  by a user.
- Mirrors will be created without a user and only a client
- Queries can fold all storage events based on the hash and determine all users and storage time frames
Braydon Fuller added 3 commits April 18, 2018 18:40
```
z = 0.9999 // target percentage
y = 5 // number of nodes
z = 0.841510681 // node percentage
--------
1 - ((1 - x) ^ y) = z
--------
1 = z + ((1 - x) ^ y)
--------
1 - z = (1 - x) ^ y
--------
(1 - z) ^ 1/y = 1 - x
--------
1 - ((1 - z) ^ 1/y) = x
--------
```

Meeting notes:
https://github.com/Storj/dev-meetings/blob/master/2017-12-06-summary.md
@braydonf
Copy link
Contributor Author

braydonf commented May 1, 2018

Found a potential issue with the unknownRate calculation where the totalRate is using bytes and the unknownRate is not using bytes.

See https://github.com/storj/service-storage-models/pull/136/files#diff-6cde9fa75ac789afe7ff15f670cfc049R434 compared to https://github.com/storj/service-storage-models/pull/136/files#diff-6cde9fa75ac789afe7ff15f670cfc049R461

Braydon Fuller added 5 commits May 2, 2018 10:41
This is to make sure that the cron service is able to not repeat
proccessing over storage events that have already been processed.
While this doesn't cause an issue with resolving the event, it will
contribute to incorrect rates of reports being saved to the user,
in the case that an event is process more than one time.
We were already updating both timestamps at the same time anyways so
having two values was unnecessary.
ContactSchema.methods.resetTimeoutRate = function() {
const now = Date.now();
const window = 259200000; // 72 hours
if (this.lastTimeout < now - window) {

Choose a reason for hiding this comment

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

Date.now() is expensive. How about this:
if (this.timeoutRate && this.lastTimeout < Date.now() - window)

That should call Date.now() only if the farmer has a timeoutRate that could be reset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated.

@braydonf
Copy link
Contributor Author

braydonf commented May 2, 2018

Okay, ready for round of testing.

@navillasa navillasa merged commit d68e043 into storj-archived:master May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants