Skip to content

Commit

Permalink
Merge pull request #5189 from mnaamani/qn-hotfix-channel-remarks
Browse files Browse the repository at this point in the history
QueryNode: handle invalid protobuf message decoding
  • Loading branch information
kdembler authored Sep 18, 2024
2 parents dabaa45 + e54fe01 commit e4f3204
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion query-node/mappings/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "query-node-mappings",
"version": "2.4.1",
"version": "2.4.2",
"description": "Mappings for hydra-processor",
"main": "lib/src/index.js",
"license": "MIT",
Expand Down
17 changes: 11 additions & 6 deletions query-node/mappings/src/content/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
ChannelMetadata,
ChannelModeratorRemarked,
ChannelOwnerRemarked,
IChannelModeratorRemarked,
IChannelOwnerRemarked,
IMakeChannelPayment,
} from '@joystream/metadata-protobuf'
import { DataObjectId } from '@joystream/types/primitives'
Expand Down Expand Up @@ -312,9 +314,9 @@ export async function content_ChannelOwnerRemarked(ctx: EventContext & StoreCont
return unimplementedError('Unsupported content actor type')
}

const metadata = ChannelOwnerRemarked.decode(message.toU8a(true))
const metadata = deserializeMetadata(ChannelOwnerRemarked, message)
const contentActor = getContentActor(channel.ownerMember, channel.ownerCuratorGroup)
const metaprotocolTxResult = await processOwnerRemark(store, event, channel, contentActor, metadata)
const metaprotocolTxResult = await processOwnerRemark(store, event, channel, contentActor, metadata ?? {})

if (metaprotocolTxResult instanceof MetaprotocolTransactionSuccessful) {
await saveMetaprotocolTransactionSuccessful(store, event, metaprotocolTxResult)
Expand All @@ -331,9 +333,9 @@ export async function content_ChannelAgentRemarked(ctx: EventContext & StoreCont
// load channel
const channel = await getChannelOrFail(store, channelId.toString())

const metadata = ChannelModeratorRemarked.decode(message.toU8a(true))
const metadata = deserializeMetadata(ChannelModeratorRemarked, message)
const contentActor = await convertContentActor(store, moderator)
const metaprotocolTxResult = await processModeratorRemark(store, event, channel, contentActor, metadata)
const metaprotocolTxResult = await processModeratorRemark(store, event, channel, contentActor, metadata ?? {})

if (metaprotocolTxResult instanceof MetaprotocolTransactionSuccessful) {
await saveMetaprotocolTransactionSuccessful(store, event, metaprotocolTxResult)
Expand Down Expand Up @@ -382,7 +384,7 @@ async function processOwnerRemark(
event: SubstrateEvent,
channel: Channel,
contentActor: typeof ContentActor,
decodedMessage: ChannelOwnerRemarked
decodedMessage: DecodedMetadataObject<IChannelOwnerRemarked>
): Promise<MetaprotocolTransactionSuccessful | MetaprotocolTxError> {
const metaprotocolTransactionSuccessful = new MetaprotocolTransactionSuccessful()
if (decodedMessage.pinOrUnpinComment) {
Expand Down Expand Up @@ -450,8 +452,11 @@ async function processModeratorRemark(
event: SubstrateEvent,
channel: Channel,
contentActor: typeof ContentActor,
decodedMessage: ChannelModeratorRemarked
decodedMessage: DecodedMetadataObject<IChannelModeratorRemarked>
): Promise<MetaprotocolTransactionSuccessful | MetaprotocolTxError> {
// if (!decodedMessage) {
// return MetaprotocolTxError.InvalidMetadata
// }
const metaprotocolTransactionSuccessful = new MetaprotocolTransactionSuccessful()
if (decodedMessage.moderateComment) {
const commentOrError = await processModerateCommentMessage(
Expand Down
8 changes: 4 additions & 4 deletions query-node/mappings/src/content/commentAndReaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ export async function processModerateCommentMessage(
event: SubstrateEvent,
channelOwnerOrCurator: typeof ContentActor,
channel: Channel,
message: IModerateComment
message: DecodedMetadataObject<IModerateComment>
): Promise<Comment | MetaprotocolTxError> {
const { commentId, rationale } = message

Expand Down Expand Up @@ -606,7 +606,7 @@ export async function processPinOrUnpinCommentMessage(
store: DatabaseManager,
event: SubstrateEvent,
channel: Channel,
message: IPinOrUnpinComment
message: DecodedMetadataObject<IPinOrUnpinComment>
): Promise<Comment | MetaprotocolTxError> {
const { commentId, option } = message

Expand Down Expand Up @@ -647,7 +647,7 @@ export async function processBanOrUnbanMemberFromChannelMessage(
store: DatabaseManager,
event: SubstrateEvent,
channel: Channel,
message: IBanOrUnbanMemberFromChannel
message: DecodedMetadataObject<IBanOrUnbanMemberFromChannel>
): Promise<Membership | MetaprotocolTxError> {
const { memberId, option } = message

Expand Down Expand Up @@ -689,7 +689,7 @@ export async function processVideoReactionsPreferenceMessage(
store: DatabaseManager,
event: SubstrateEvent,
channel: Channel,
message: IVideoReactionsPreference
message: DecodedMetadataObject<IVideoReactionsPreference>
): Promise<Channel | MetaprotocolTxError> {
const { videoId, option } = message

Expand Down
2 changes: 1 addition & 1 deletion query-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "query-node-root",
"version": "2.4.1",
"version": "2.4.2",
"description": "GraphQL server and mappings. Generated with ♥ by Hydra-CLI",
"scripts": {
"build": "./build.sh",
Expand Down

0 comments on commit e4f3204

Please sign in to comment.