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

Resource accounting implementation #1898

Merged
merged 14 commits into from
Apr 4, 2024
Merged

Conversation

corrideat
Copy link
Member

No description provided.

@corrideat corrideat changed the title Add and verify attribution information Resource accounting implementation Mar 27, 2024
Copy link

cypress bot commented Mar 27, 2024

Passing run #2038 ↗︎

0 110 8 0 Flakiness 0

Details:

Merge 77eedec into dfe3a13...
Project: group-income Commit: 195fd818b8 ℹ️
Status: Passed Duration: 10:44 💡
Started: Apr 4, 2024 9:46 AM Ended: Apr 4, 2024 9:57 AM

Review all test suite changes for PR #1898 ↗︎

Copy link

socket-security bot commented Mar 28, 2024

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: npm/@chelonia/[email protected]

View full report↗︎

backend/routes.js Outdated Show resolved Hide resolved
@corrideat corrideat force-pushed the accounting-implementation branch from a8c6997 to f6dcac8 Compare March 29, 2024 10:50
@corrideat corrideat force-pushed the accounting-implementation branch from f6dcac8 to 63c6642 Compare March 29, 2024 10:55
@corrideat corrideat marked this pull request as ready for review April 2, 2024 09:19
@corrideat corrideat force-pushed the accounting-implementation branch from 14b15bd to 7fb549a Compare April 2, 2024 09:22
backend/auth.js Outdated Show resolved Hide resolved
backend/routes.js Outdated Show resolved Hide resolved
@@ -287,6 +355,91 @@ route.GET('/file/{hash}', {
return h.response(blobOrString).etag(hash)
})

route.POST('/deleteFile/{hash}', {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment above this line something to the effect of, "allow file deletion, and allow either the bearer of the deletion token or the file owner to delete it" ?

Comment on lines +426 to +428
await sbp('chelonia/db/delete', hash)
await sbp('chelonia/db/delete', `_private_owner_${hash}`)
await sbp('chelonia/db/delete', `_private_size_${hash}`)
Copy link
Member

Choose a reason for hiding this comment

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

Should these also be done atomically in a queue? If not, can you add a comment explaining why there's an exception for them?

Comment on lines +500 to +516
// b is a hash of a random public key (`g^r`) with secret key `r`,
// which is used by the requester to commit to that particular `r`
b: Joi.string().required()
},
{
r: Joi.string().required(), // what r is
s: Joi.string().required(), // what s is
// `r` is the value used to derive `b` (in this case, it's the public
// key `g^r`)
r: Joi.string().required(),
// `s` is an opaque (to the client) value that was earlier returned by
// the server
s: Joi.string().required(),
// `sig` is an opaque (to the client) value returned by the server
// to validate the request (ensuring that (`r`, `s`) come from a
// previous request
sig: Joi.string().required(),
// `Eh` is the Eh = E_{S_A + S_C}(h), where S_A and S_C are salts and
// h = H\_{S_A}(P)
Copy link
Member

Choose a reason for hiding this comment

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

Nice!! Thanks for updating these! 😄

Comment on lines +531 to +536
// This ensures that only the owner of the contract can set a salt for it,
// closing a small window of opportunity(*) during which an attacker could
// potentially lock out a new user from their account by registering a
// different salt.
// (*) This is right between the moment an OP_CONTRACT is sent and the
// time this endpoint is called, which should follow almost immediately after.
Copy link
Member

Choose a reason for hiding this comment

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

Nice comment! 👍

Comment on lines +180 to +192
{
id: SAKid,
name: '#sak',
purpose: ['sak'],
ringLevel: 0,
permissions: [],
allowedActions: [],
meta: {
private: {
content: SAKs
}
},
data: SAKp
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we make sure that the #sak has proper permissions before the server allows it to be registered?

I.e. verify ringLevel: 0 and permissions: []?

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly, although this isn't the place to check that.

}
// If the request didn't succeed, report it
if (!time.ok) throw new Error('Error fetching server time')
const serverTime = (new Date(await time.text())).valueOf()
Copy link
Member

Choose a reason for hiding this comment

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

If it takes 200 ms for our request to get to the server, and 200ms to get the response, by the time we get the response from the server, the time we receive from the server will be 200ms old. So we should add 200ms to the time received from the server.

We can estimate this time by doing (requestTimeElapsed - newMonotonicBase) / 2

Comment on lines 3 to 4
let wallBase = Date.now()
let monotonicBase = performance.now()
Copy link
Member

Choose a reason for hiding this comment

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

Could you add comments here explaining what wallBase and monotonicBase mean? These terms might be confusing to people (as they are confusing to me)

Comment on lines +68 to +69
// Tolerate up to a 10ms difference
if (difference > 10) {
Copy link
Member

Choose a reason for hiding this comment

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

10ms seems rather small... how often would this get called?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is called locally and the difference should typically be 0, unless the local date has been adjusted for some reason.

}

export default (sbp('sbp/selectors/register', {
'chelonia/private/startClockSync': function () {
Copy link
Member

Choose a reason for hiding this comment

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

How difficult would it be to adapt this code to support multiple different servers? For federation it would be necessary to be sync'd to each server on which we are monitoring/interacting with contracts.

Copy link
Member Author

Choose a reason for hiding this comment

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

For this particular code, probably not so much. The issue is that currently there's only a single connectionURL. The changes needed here would depend on how multiple server URLs are handled.

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

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

Nicely done @corrideat!! Very impressive!!! LGTM 💪

@taoeffect taoeffect merged commit f001029 into master Apr 4, 2024
4 checks passed
@taoeffect taoeffect deleted the accounting-implementation branch April 4, 2024 09:58
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