-
Notifications
You must be signed in to change notification settings - Fork 1
feat(polymarket): publish source-bound quote runner #423
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0b7309b
feat(polymarket): publish source-bound quote runner (#421)
955f62c
test(ci): account for quote runner artifact (#421)
941ff54
fix(polymarket): preserve runner artifact mode (#421)
9dde34e
Merge remote-tracking branch 'origin/main' into codex/polymarket-quot…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
.github/scripts/polymarket-market-recorder-release-artifact.sh
This file contains hidden or 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,83 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| mode=${1:?expected create or verify} | ||
| release=${2:?expected release directory} | ||
| source_revision=${3:?expected source revision} | ||
| image_digest=${4:?expected image digest} | ||
| manifest="$release/polymarket-market-recorder-release.json" | ||
| binary="$release/new-ploy-runner" | ||
|
|
||
| [[ $source_revision =~ ^[0-9a-f]{40}$ ]] || { | ||
| printf 'invalid source revision: %s\n' "$source_revision" >&2 | ||
| exit 1 | ||
| } | ||
| [[ $image_digest =~ ^sha256:[0-9a-f]{64}$ ]] || { | ||
| printf 'invalid image digest: %s\n' "$image_digest" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| verify_binary() { | ||
| local expected_sha actual_sha | ||
| [[ -f $binary && -x $binary && ! -L $binary ]] | ||
| "$binary" --version | grep -Fqx "new-ploy-runner $source_revision" | ||
| expected_sha=$(awk 'NR == 1 && NF == 2 && $2 == "new-ploy-runner" {print $1}' \ | ||
| "$release/new-ploy-runner.sha256") | ||
| [[ $expected_sha =~ ^[0-9a-f]{64}$ ]] | ||
| actual_sha=$(sha256sum "$binary" | awk '{print $1}') | ||
| [[ $actual_sha == "$expected_sha" ]] | ||
| } | ||
|
|
||
| case "$mode" in | ||
| create) | ||
| [[ -d $release && ! -e $manifest ]] | ||
| [[ -f $binary && -x $binary && ! -L $binary ]] | ||
| "$binary" --version | grep -Fqx "new-ploy-runner $source_revision" | ||
| ( | ||
| cd "$release" | ||
| sha256sum new-ploy-runner > new-ploy-runner.sha256 | ||
| ) | ||
| candidate_sha=$(awk '{print $1}' "$release/new-ploy-runner.sha256") | ||
| jq -S -n \ | ||
| --arg source_revision "$source_revision" \ | ||
| --arg candidate_sha256 "$candidate_sha" \ | ||
| --arg image_digest "$image_digest" \ | ||
| '{schema:"monday.polymarket_market_recorder_release.v1", | ||
| source_revision:$source_revision, | ||
| candidate:{file:"new-ploy-runner",sha256:$candidate_sha256}, | ||
| image_digest:$image_digest, | ||
| platform:{os:"linux",architecture:"amd64"}}' > "$manifest" | ||
| ( | ||
| cd "$release" | ||
| sha256sum polymarket-market-recorder-release.json \ | ||
| > polymarket-market-recorder-release.json.sha256 | ||
| ) | ||
| ;; | ||
| verify) | ||
| expected_files=$'new-ploy-runner\nnew-ploy-runner.sha256\npolymarket-market-recorder-release.json\npolymarket-market-recorder-release.json.sha256' | ||
| actual_files=$(find "$release" -mindepth 1 -maxdepth 1 -print \ | ||
| | sed 's|.*/||' | sort) | ||
| [[ $actual_files == "$expected_files" ]] | ||
| verify_binary | ||
| ( | ||
| cd "$release" | ||
| sha256sum --check --strict polymarket-market-recorder-release.json.sha256 \ | ||
| >/dev/null | ||
| ) | ||
| candidate_sha=$(sha256sum "$binary" | awk '{print $1}') | ||
| jq -e \ | ||
| --arg source_revision "$source_revision" \ | ||
| --arg candidate_sha256 "$candidate_sha" \ | ||
| --arg image_digest "$image_digest" ' | ||
| (keys | sort) == ["candidate", "image_digest", "platform", "schema", "source_revision"] | ||
| and .schema == "monday.polymarket_market_recorder_release.v1" | ||
| and .source_revision == $source_revision | ||
| and .candidate == {file:"new-ploy-runner",sha256:$candidate_sha256} | ||
| and .image_digest == $image_digest | ||
| and .platform == {os:"linux",architecture:"amd64"}' "$manifest" >/dev/null | ||
| ;; | ||
| *) | ||
| printf 'unsupported artifact mode: %s\n' "$mode" >&2 | ||
| exit 2 | ||
| ;; | ||
| esac |
This file contains hidden or 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 hidden or 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
94 changes: 94 additions & 0 deletions
94
deployment/aliyun/test-polymarket-market-recorder-release.sh
This file contains hidden or 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,94 @@ | ||
| #!/usr/bin/env bash | ||
| # Static contract greps intentionally use literal shell expressions. | ||
| # shellcheck disable=SC2016 | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd) | ||
| readonly SCRIPT_DIR | ||
| readonly WORKFLOW="$SCRIPT_DIR/../../.github/workflows/acr-publish.yml" | ||
| readonly ARTIFACT_HELPER="$SCRIPT_DIR/../../.github/scripts/polymarket-market-recorder-release-artifact.sh" | ||
| readonly DOCKERFILE="$SCRIPT_DIR/../../rust_hft/deployment/docker/Dockerfile.polymarket-market-recorder" | ||
| readonly RUNNER="$SCRIPT_DIR/../../rust_hft/prediction-markets/apps/new-ploy-runner/src/main.rs" | ||
|
|
||
| shellcheck "$0" | ||
| test -x "$ARTIFACT_HELPER" | ||
|
|
||
| grep -Fq 'ARG SOURCE_REVISION' "$DOCKERFILE" | ||
| grep -Fq "grep -Eq '^[0-9a-f]{40}$'" "$DOCKERFILE" | ||
| grep -Fq 'MONDAY_SOURCE_REVISION="$SOURCE_REVISION" cargo' "$DOCKERFILE" | ||
|
|
||
| grep -Fq 'option_env!("MONDAY_SOURCE_REVISION")' "$RUNNER" | ||
| grep -Fq 'std::env::args_os()' "$RUNNER" | ||
| grep -Fq 'new-ploy-runner {BUILD_SOURCE_REVISION}' "$RUNNER" | ||
|
|
||
| grep -Fq 'Extract bare-metal Polymarket market recorder' "$WORKFLOW" | ||
| grep -Fq 'polymarket-market-recorder-release-artifact.sh create' "$WORKFLOW" | ||
| grep -Fq 'polymarket-market-recorder-release-artifact.sh verify' "$WORKFLOW" | ||
| grep -Fq 'new-ploy-runner $source_revision' "$ARTIFACT_HELPER" | ||
| grep -Fq 'monday.polymarket_market_recorder_release.v1' "$ARTIFACT_HELPER" | ||
| grep -Fq 'polymarket-market-recorder-linux-amd64-${{ needs.selector.outputs.source_sha }}' "$WORKFLOW" | ||
| grep -Fq 'tar --format=ustar -cf polymarket-market-recorder-linux-amd64.tar' "$WORKFLOW" | ||
| grep -Fq 'path: polymarket-market-recorder-linux-amd64.tar' "$WORKFLOW" | ||
|
|
||
| if [[ ${MONDAY_TEST_RECORDER_IMAGE:-0} == 1 ]]; then | ||
| : "${SOURCE_REVISION:?set SOURCE_REVISION for the image contract test}" | ||
| [[ $SOURCE_REVISION =~ ^[0-9a-f]{40}$ ]] | ||
| for command in docker jq sha256sum tar; do | ||
| command -v "$command" >/dev/null | ||
| done | ||
|
|
||
| tmp_root=$(mktemp -d) | ||
| release_dir="$tmp_root/release" | ||
| mkdir "$release_dir" | ||
| trap 'rm -rf "$tmp_root"' EXIT | ||
| image="monday-polymarket-market-recorder-test:$SOURCE_REVISION" | ||
| docker build --quiet \ | ||
| --build-arg "SOURCE_REVISION=$SOURCE_REVISION" \ | ||
| -f "$DOCKERFILE" \ | ||
| -t "$image" \ | ||
| "$SCRIPT_DIR/../../rust_hft" >/dev/null | ||
| if docker build --quiet \ | ||
| --build-arg SOURCE_REVISION=invalid \ | ||
| -f "$DOCKERFILE" \ | ||
| -t monday-polymarket-market-recorder-invalid-test \ | ||
| "$SCRIPT_DIR/../../rust_hft" >/dev/null 2>&1; then | ||
| printf 'market-recorder image accepted an invalid source revision\n' >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| container_id=$(docker create "$image") | ||
| trap 'docker rm -f "$container_id" >/dev/null 2>&1 || true; rm -rf "$tmp_root"' EXIT | ||
| docker cp "$container_id:/usr/local/bin/new-ploy-runner" \ | ||
| "$release_dir/new-ploy-runner" | ||
| chmod 0755 "$release_dir/new-ploy-runner" | ||
| image_id=$(docker image inspect --format '{{.Id}}' "$image") | ||
| "$ARTIFACT_HELPER" create "$release_dir" "$SOURCE_REVISION" "$image_id" | ||
| "$ARTIFACT_HELPER" verify "$release_dir" "$SOURCE_REVISION" "$image_id" | ||
|
|
||
| archive="$tmp_root/polymarket-market-recorder-linux-amd64.tar" | ||
| transported_release="$tmp_root/transported-release" | ||
| tar --format=ustar -cf "$archive" -C "$release_dir" . | ||
| chmod 0644 "$release_dir/new-ploy-runner" | ||
| mkdir "$transported_release" | ||
| tar -xf "$archive" -C "$transported_release" | ||
| "$ARTIFACT_HELPER" verify \ | ||
| "$transported_release" "$SOURCE_REVISION" "$image_id" | ||
| chmod 0755 "$release_dir/new-ploy-runner" | ||
|
|
||
| cp "$release_dir/polymarket-market-recorder-release.json" \ | ||
| "$tmp_root/release.json.good" | ||
| jq '.source_revision = "0000000000000000000000000000000000000000"' \ | ||
| "$tmp_root/release.json.good" \ | ||
| > "$release_dir/polymarket-market-recorder-release.json" | ||
| ( | ||
| cd "$release_dir" | ||
| sha256sum polymarket-market-recorder-release.json \ | ||
| > polymarket-market-recorder-release.json.sha256 | ||
| ) | ||
| if "$ARTIFACT_HELPER" verify "$release_dir" "$SOURCE_REVISION" "$image_id"; then | ||
| printf 'release verifier accepted the wrong source revision\n' >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| printf 'Polymarket market-recorder release contract tests passed\n' |
This file contains hidden or 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 hidden or 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
14 changes: 13 additions & 1 deletion
14
rust_hft/prediction-markets/apps/new-ploy-runner/src/main.rs
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,16 @@ | ||
| const BUILD_SOURCE_REVISION: &str = match option_env!("MONDAY_SOURCE_REVISION") { | ||
| Some(value) => value, | ||
| None => "unbound-source-revision", | ||
| }; | ||
|
|
||
| #[tokio::main] | ||
| async fn main() { | ||
| ploy_runner_host::run_with_implicit_run_args(std::env::args().collect()).await; | ||
| let args: Vec<String> = std::env::args_os() | ||
|
proerror77 marked this conversation as resolved.
|
||
| .map(|arg| arg.into_string().expect("arguments must be valid UTF-8")) | ||
| .collect(); | ||
| if matches!(args.get(1).map(String::as_str), Some("--version" | "-V")) { | ||
| println!("new-ploy-runner {BUILD_SOURCE_REVISION}"); | ||
| return; | ||
| } | ||
| ploy_runner_host::run_with_implicit_run_args(args).await; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.