-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deployment): add scripts to help find nondeterminism
- Loading branch information
1 parent
6f888ba
commit a1065c0
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#! /usr/bin/env node | ||
// crunch.mjs - crunch a kvstore trace file's writes into TSV | ||
|
||
/* eslint-disable no-continue */ | ||
/* global process,Buffer */ | ||
|
||
import fs from 'fs'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import ReadlineTransform from 'readline-transform'; | ||
|
||
const [TRACE_FILE, LAST_BLOCK_HEIGHT = 0] = process.argv.slice(2); | ||
if (!TRACE_FILE) { | ||
console.error('usage: crunch trace-file [last-block-height]'); | ||
process.exit(1); | ||
} | ||
|
||
const escapeCharCode = c => { | ||
switch (c) { | ||
// backslash-escape the following characters | ||
case 92: | ||
return '\\'; | ||
case 10: | ||
return '\\n'; | ||
case 13: | ||
return '\\r'; | ||
case 9: | ||
return '\\t'; | ||
case 0: | ||
return '\\0'; | ||
default: { | ||
if (c < 0x20 || c > 0x7e) { | ||
return `\\x${c.toString(16).padStart(2, '0')}`; | ||
} | ||
return String.fromCharCode(c); | ||
} | ||
} | ||
}; | ||
|
||
const decode = b64 => { | ||
const b = Buffer.from(b64, 'base64'); | ||
return Array.from(b) | ||
.map(escapeCharCode) | ||
.join(''); | ||
}; | ||
|
||
const main = async () => { | ||
const rl = new ReadlineTransform(); | ||
fs.createReadStream(TRACE_FILE).pipe(rl); | ||
|
||
for await (const line of rl) { | ||
const { operation, key, value, metadata } = JSON.parse(line); | ||
if (operation !== 'write') { | ||
continue; | ||
} | ||
if (metadata && metadata.blockHeight > LAST_BLOCK_HEIGHT) { | ||
break; | ||
} | ||
const decodedKey = decode(key); | ||
if (decodedKey.match(/^\w+\/fwd\/0x[0-9a-f]+$/)) { | ||
// Probably capability module. | ||
continue; | ||
} | ||
|
||
const decodedValue = decode(value); | ||
const obj = { operation, key: decodedKey, value: decodedValue, metadata }; | ||
|
||
// Write a tab-separated line of key, value, metadata. | ||
process.stdout.write( | ||
`${obj.key}\t${obj.value}\t${JSON.stringify(obj.metadata)}\n`, | ||
); | ||
} | ||
}; | ||
|
||
await main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#! /bin/bash | ||
|
||
set -ueo pipefail | ||
|
||
real0=$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}") | ||
thisdir=$(cd "$(dirname -- "$real0")" > /dev/null && pwd -P) | ||
|
||
# unzip deployment-test-results.zip | ||
|
||
for v in 0 1; do | ||
grep -E '"write"' validator$v-kvstore.trace > v$v.write | ||
grep -E '"metadata":null|blockHeight":1,' v$v.write > v$v.write-block1 | ||
"$thisdir/crunch.mjs" validator$v-kvstore.trace > v$v.crunch | ||
sort v$v.crunch > v$v.sorted | ||
done | ||
|
||
diff v0.sorted v1.sorted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17102,6 +17102,11 @@ readdirp@~3.6.0: | |
dependencies: | ||
picomatch "^2.2.1" | ||
|
||
readline-transform@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/readline-transform/-/readline-transform-1.0.0.tgz#3157f97428acaec0f05a5c1ff2c3120f4e6d904b" | ||
integrity sha512-7KA6+N9IGat52d83dvxnApAWN+MtVb1MiVuMR/cf1O4kYsJG+g/Aav0AHcHKsb6StinayfPLne0+fMX2sOzAKg== | ||
|
||
[email protected]: | ||
version "2.2.2" | ||
resolved "https://registry.yarnpkg.com/recursive-readdir/-/recursive-readdir-2.2.2.tgz#9946fb3274e1628de6e36b2f6714953b4845094f" | ||
|