Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
a935f3b3
Commit
a935f3b3
authored
Dec 12, 2023
by
pcw109550
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-chain-ops: Refactor delta checker to Channel Aggregator
parent
d4389749
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
51 deletions
+101
-51
aggregate-channels.sh
op-chain-ops/cmd/check-delta/aggregate-channels.sh
+101
-0
check-delta.sh
op-chain-ops/cmd/check-delta/check-delta.sh
+0
-51
No files found.
op-chain-ops/cmd/check-delta/aggregate-channels.sh
0 → 100755
View file @
a935f3b3
#!/bin/bash
set
-uo
pipefail
# Check if a directory path is provided
# Directory must contain the output of batch_decoder's reassemble command, which are channels in json form
if
[
-z
"
${
1
:-}
"
]
;
then
echo
"Usage:
$0
/path/to/directory"
exit
1
fi
# Check if jq is installed
if
!
command
-v
jq &> /dev/null
;
then
echo
"Error: jq is not installed"
exit
1
fi
directory_path
=
$1
# Check if directory exists and is not empty
if
[
!
-d
"
$directory_path
"
]
||
[
-z
"
$(
ls
-A
"
$directory_path
"
)
"
]
;
then
echo
"Error: Directory does not exist or is empty"
exit
1
fi
invalid_json_count
=
0
invalid_jsons
=()
not_ready_channel_count
=
0
not_ready_channels
=()
ready_channel_count
=
0
span_batch_count
=
0
singular_batch_count
=
0
channels_with_invalid_batches
=()
batch_type_counter_jq_script
=
'reduce .batch_types[] as $batch_type (
{"span_batch_count": 0, "singular_batch_count": 0};
if $batch_type == 1 then
.span_batch_count += 1
else
.singular_batch_count += 1
end) | .span_batch_count, .singular_batch_count'
# Loop over every .json file in the specified directory
for
file
in
"
$directory_path
"
/
*
.json
;
do
# check file is valid json
if
!
jq empty
"
$file
"
2>/dev/null
;
then
((
invalid_json_count++
))
invalid_jsons+
=(
"
$file
"
)
continue
fi
# check channels are ready
if
[
$(
jq
-r
".is_ready"
"
$file
"
)
==
"false"
]
;
then
# not ready channel have no batches so invalid_batches field is always false
((
not_ready_channel_count++
))
not_ready_channels+
=(
"
$file
"
)
continue
else
((
ready_channel_count++
))
fi
# check channels contain invalid batches
if
[
$(
jq
-r
".invalid_batches"
"
$file
"
)
==
"true"
]
;
then
channels_with_invalid_batches+
=(
"
$file
"
)
fi
# count singular batch count and span batch count
jq_result
=
$(
jq
"
$batch_type_counter_jq_script
"
"
$file
"
)
read
span_batch_count_per_channel singular_batch_count_per_channel
<<<
$jq_result
span_batch_count
=
$((
span_batch_count+span_batch_count_per_channel
))
singular_batch_count
=
$((
singular_batch_count+singular_batch_count_per_channel
))
done
# Display the counts
echo
"Singular batch count:
$singular_batch_count
"
echo
"Span batch count:
$span_batch_count
"
echo
"Ready channel count:
$ready_channel_count
"
echo
"Not ready channel count:
$not_ready_channel_count
"
echo
"Invalid json count:
$invalid_json_count
"
# Display the files which are invalid jsons
if
[
${#
invalid_jsons
[@]
}
-gt
0
]
;
then
echo
"Invalid jsons"
printf
'[*] %s\n'
"
${
invalid_jsons
[@]
}
"
else
echo
"All processed channels are valid jsons."
fi
# Display the files which are channels not ready
if
[
${#
not_ready_channels
[@]
}
-gt
0
]
;
then
echo
"Not ready channels"
printf
'[*] %s\n'
"
${
not_ready_channels
[@]
}
"
else
echo
"All processed channels are ready."
fi
# Display the files including invalid batches
if
[
${#
channels_with_invalid_batches
[@]
}
-gt
0
]
;
then
echo
"Channels with invalid batches"
printf
'[*] %s\n'
"
${
channels_with_invalid_batches
[@]
}
"
else
echo
"All processed ready channels contain valid batches."
fi
op-chain-ops/cmd/check-delta/check-delta.sh
deleted
100755 → 0
View file @
d4389749
#!/bin/bash
set
-uo
pipefail
# Check if a directory path is provided
# Directory must contain the output of batch_decoder's reassemble command
if
[
-z
"
${
1
:-}
"
]
;
then
echo
"Usage:
$0
/path/to/directory"
exit
1
fi
# Check if jq is installed
if
!
command
-v
jq &> /dev/null
;
then
echo
"Error: jq is not installed"
exit
1
fi
directory_path
=
$1
# Check if directory exists and is not empty
if
[
!
-d
"
$directory_path
"
]
||
[
-z
"
$(
ls
-A
"
$directory_path
"
)
"
]
;
then
echo
"Error: Directory does not exist or is empty"
exit
1
fi
valid_count
=
0
invalid_count
=
0
invalid_channels
=()
# Loop over every .json file in the specified directory
for
file
in
"
$directory_path
"
/
*
.json
;
do
# If channel is ready, all batches must valid.
# If delta is activated, all batch types must be span batch.
result
=
$(
jq
'if .is_ready then (.invalid_batches == false and all(.batch_types[]; . == 1)) else empty end'
"
$file
"
2>&1
)
if
[[
$result
==
"true"
]]
;
then
((
valid_count++
))
else
# supplied json is invalid or does not satisfy condition
((
invalid_count++
))
invalid_channels+
=(
"
$file
"
)
fi
done
# Display the counts
echo
"Valid count:
$valid_count
"
echo
"Invalid count:
$invalid_count
"
# Display the files that returned invalid results
if
[
${#
invalid_channels
[@]
}
-gt
0
]
;
then
echo
"Channels with invalid results:"
printf
'[*] %s\n'
"
${
invalid_channels
[@]
}
"
else
echo
"All processed channels are valid and contains successfully derived span batches."
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment