-
Notifications
You must be signed in to change notification settings - Fork 3
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 schema entities and mappings to process set node operational status protobuf message #19
base: main
Are you sure you want to change the base?
Conversation
…us protobuf message
schema/events.graphql
Outdated
|
||
type DistributionNodeOperationalStatusSetEvent { | ||
"Distribution bucket operator" | ||
bucketOperator: DistributionBucketOperator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this field should be required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
src/mappings/storage/metadata.ts
Outdated
@@ -60,6 +67,9 @@ export async function processStorageOperatorMetadata( | |||
if (isSet(metadataUpdate.location)) { | |||
processNodeLocationMetadata(operatorMetadata, metadataUpdate.location) | |||
} | |||
if (isSet(metadataUpdate.operationalStatus)) { | |||
processNodeOperationalStatusMetadata('worker', undefined, metadataUpdate.operationalStatus) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to pass the current status as the second argument so worker is not able to override the lead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Addressed
src/mappings/storage/metadata.ts
Outdated
@@ -121,6 +203,9 @@ export async function processDistributionOperatorMetadata( | |||
if (isSet(metadataUpdate.location)) { | |||
processNodeLocationMetadata(operatorMetadata, metadataUpdate.location) | |||
} | |||
if (isSet(metadataUpdate.operationalStatus)) { | |||
processNodeOperationalStatusMetadata('worker', undefined, metadataUpdate.operationalStatus) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
src/mappings/storage/utils.ts
Outdated
.getById(`${workingGroup}-${meta.workerId}`) | ||
|
||
if (!maybeWorker) { | ||
return invalidMetadata( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We return invalidMetadata
here but processNodeOperationalStatusMetadata
in mappings/storage/metadata.ts
only calls it, should we be consistent about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the return is just to break the function, alternatively we could just do
invalidMetadata()
return
src/mappings/storage/utils.ts
Outdated
`The storage bucket ${bucketId} is not active` | ||
) | ||
// If the actor is a worker, check if the worker is the operator of the storage bucket | ||
} else if (actor && storageBucket.operatorStatus.workerId !== actor.runtimeId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this check will ensure that regular worker can only update status of their own bucket and not somebody's elses. Should we also add a check for when the lead is the actor that ensures the meta.bucketId
and meta.workerId
matches storageBucket.operatorStatus.workerId
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, there is no validation currently to check meta.workerId = bucket.operatorStatus.workerId
. So the drawback of the lack of this validation is that in the case of lead remark the operation would be performed even though meta.bucketId
and meta.workerId
do not match for any bucket, so, mappings are just looking for any valid meta.bucketId
and set the status on that, (Simply ignoring what is the value of meta.workerId
). And this is fine for the Lead context I think.
const metadataEntity = | ||
(await overlay.getRepository(StorageBucketOperatorMetadata).getById(bucketId)) || | ||
overlay | ||
.getRepository(StorageBucketOperatorMetadata) | ||
.new({ id: bucketId, storageBucketId: bucketId }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, .new()
call is sync and doesn't need await?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, it just creates in-memory objects, which are scheduled to be saved on DB later.
src/mappings/storage/utils.ts
Outdated
const operationalStatusSetEvent = new StorageNodeOperationalStatusSetEvent({ | ||
...genericEventFields(overlay, block, indexInBlock, extrinsicHash), | ||
storageBucket: storageBucket.id, | ||
operationalStatus: metadataEntity.nodeOperationalStatus || undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we are emitting metadataEntity.nodeOperationalStatus
, will this be already updated value after call to processNodeOperationalStatusMetadata
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be set on the line.
metadataEntity.nodeOperationalStatus = processNodeOperationalStatusMetadata(
But I just noticed that this StorageNodeOperationalStatusSetEvent
evet is being emitted regardless of the outcome of the processNodeOperationalStatusMetadata
.
So, I have changed the implementation only to emit the event when the status changes.
src/mappings/storage/utils.ts
Outdated
SetNodeOperationalStatus, | ||
`The distribution bucket operator ${distributionOperatorId} does not exist` | ||
) | ||
} else if (actor && operator.workerId !== actor.runtimeId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question about the condition as above for storage
d9716de
to
692abf5
Compare
@zeeshanakram3 |
required for Joystream/joystream#4765