Skip to content

add schema entities and mappings to process set node operational status protobuf message#19

Open
zeeshanakram3 wants to merge 9 commits into
Joystream:mainfrom
zeeshanakram3:process_set_node_operational_status_protobuf_message
Open

add schema entities and mappings to process set node operational status protobuf message#19
zeeshanakram3 wants to merge 9 commits into
Joystream:mainfrom
zeeshanakram3:process_set_node_operational_status_protobuf_message

Conversation

@zeeshanakram3

Copy link
Copy Markdown
Collaborator

@kdembler kdembler self-assigned this Mar 1, 2024
Comment thread schema/events.graphql Outdated

type DistributionNodeOperationalStatusSetEvent {
"Distribution bucket operator"
bucketOperator: DistributionBucketOperator

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed

Comment thread src/mappings/storage/metadata.ts Outdated
processNodeLocationMetadata(operatorMetadata, metadataUpdate.location)
}
if (isSet(metadataUpdate.operationalStatus)) {
processNodeOperationalStatusMetadata('worker', undefined, metadataUpdate.operationalStatus)

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. Addressed

Comment thread src/mappings/storage/metadata.ts Outdated
processNodeLocationMetadata(operatorMetadata, metadataUpdate.location)
}
if (isSet(metadataUpdate.operationalStatus)) {
processNodeOperationalStatusMetadata('worker', undefined, metadataUpdate.operationalStatus)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed

Comment thread src/mappings/storage/utils.ts Outdated
.getById(`${workingGroup}-${meta.workerId}`)

if (!maybeWorker) {
return invalidMetadata(

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Collaborator Author

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 

Comment thread 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) {

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Collaborator Author

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.

Comment on lines +269 to +273
const metadataEntity =
(await overlay.getRepository(StorageBucketOperatorMetadata).getById(bucketId)) ||
overlay
.getRepository(StorageBucketOperatorMetadata)
.new({ id: bucketId, storageBucketId: bucketId })

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread src/mappings/storage/utils.ts Outdated
const operationalStatusSetEvent = new StorageNodeOperationalStatusSetEvent({
...genericEventFields(overlay, block, indexInBlock, extrinsicHash),
storageBucket: storageBucket.id,
operationalStatus: metadataEntity.nodeOperationalStatus || undefined,

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread src/mappings/storage/utils.ts Outdated
SetNodeOperationalStatus,
`The distribution bucket operator ${distributionOperatorId} does not exist`
)
} else if (actor && operator.workerId !== actor.runtimeId) {

Copy link
Copy Markdown
Collaborator

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

@zeeshanakram3 zeeshanakram3 requested a review from kdembler March 20, 2024 12:04
@zeeshanakram3 zeeshanakram3 force-pushed the process_set_node_operational_status_protobuf_message branch from d9716de to 692abf5 Compare March 27, 2024 03:25
@kdembler

kdembler commented Mar 27, 2024

Copy link
Copy Markdown
Collaborator

@zeeshanakram3 build fails nvm, found Joystream/joystream#4793 (comment)

@kdembler kdembler requested a review from dobertRowneySr June 27, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Review

Development

Successfully merging this pull request may close these issues.

2 participants