Skip to content

Commit

Permalink
Merge pull request #34 from Chia-Network/signed_active
Browse files Browse the repository at this point in the history
Signed active
  • Loading branch information
aqk authored Sep 19, 2024
2 parents a6fa824 + 186359b commit 870f9f3
Show file tree
Hide file tree
Showing 182 changed files with 20,203 additions and 2,422 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Thanks: clvm_rs' github actions.
name: Build

on:
push:
branches:
- base
- dev
release:
types: [published]
pull_request:
branches:
- '**'

permissions:
id-token: write
contents: read

jobs:
build_and_test:
name: Build code on ${{ matrix.os }} py-${{ matrix.python }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python: [3.8, 3.9, '3.10', 3.11]

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v4
name: Install Python ${{ matrix.python }}
with:
python-version: ${{ matrix.python }}

- name: Update pip
run: |
python -m pip install --upgrade pip
- name: Set up rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable

fmt:
runs-on: ubuntu-20.04
name: cargo fmt
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- name: fmt
run: cargo fmt -- --files-with-diff --check

clippy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true
- name: clippy
run: |
cargo clippy --all --features=sim-tests,simulator -- -D warnings
cargo check --features=sim-tests,simulator --tests
- uses: giraffate/clippy-action@v1
with:
reporter: 'github-pr-review'
github_token: ${{ secrets.GITHUB_TOKEN }}

unit_tests:
runs-on: ubuntu-20.04
name: Unit tests
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: cargo test
run: |
python -m pip install chia-blockchain
# Try tests without sim-tests to ensure we're tracking build failures in that
# configuration. Also it's a lot shorter.
cargo test
cargo test --features=sim-tests
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Run for coverage
run: |
sudo apt-get update
sudo apt-get install lcov -y
rustup component add llvm-tools-preview
cargo install grcov
export RUSTFLAGS="-Cinstrument-coverage"
export LLVM_PROFILE_FILE=$(pwd)/target/clvm_tools_rs-%p-%m.profraw
export CARGO_TARGET_DIR=$(pwd)/target
python -m venv venv
source venv/bin/activate
pip install chia-blockchain
cargo test --release --workspace --features=sim-tests
grcov . --binary-path target -s . --branch --ignore-not-existing --ignore='*/.cargo/*' --ignore='*/tests/*' -o rust_cov.info
python -c 'with open("rust_cov.info") as f: lines = [l for l in f if not (l.startswith("DA:") and int(l.split(",")[1].strip()) >= 2**63)]; open("lcov.info", "w").writelines(lines)'
- name: Upload to Coveralls
uses: coverallsapp/github-action@v2
if: always()
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
with:
path-to-lcov: './lcov.info'
59 changes: 59 additions & 0 deletions .github/workflows/m1-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Run tests on MacOS

on:
push:
branches:
- main
- dev
release:
types: [published]
pull_request:
branches:
- '**'

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}--${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/heads/long_lived/')) && github.sha || '' }}
cancel-in-progress: true

permissions:
id-token: write
contents: read

jobs:
build_wheels:
name: Build wheel on Mac M1
runs-on: [MacOS, ARM64]
strategy:
fail-fast: false

steps:
- uses: Chia-Network/actions/clean-workspace@main

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up rust
run: |
curl https://static.rust-lang.org/rustup/dist/aarch64-apple-darwin/rustup-init.sha256 | awk '{print $1 " *rustup-init"}' > checksum.txt
curl -O https://static.rust-lang.org/rustup/dist/aarch64-apple-darwin/rustup-init
cat checksum.txt
shasum -a 256 -c checksum.txt
- name: Install rust
run: |
chmod +x rustup-init
./rustup-init -y || (echo "Rust is already installed. Exiting..." && exit 2)
rm rustup-init checksum.txt
- name: Set up a venv for chia-blockchain
run: |
python3 -m venv ./test
source ./test/bin/activate
pip install chia-blockchain
- name: Run tests
run: |
source ./test/bin/activate
cargo test --features=sim-tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.hex
55 changes: 55 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[package]
name = "chia_gaming"
version = "0.1.0"
edition = "2021"

[features]
sim-tests = ["dep:pyo3"]
simulator = ["dep:pyo3"]

[dependencies]
clvm_tools_rs = { git = "https://github.com/Chia-Network/clvm_tools_rs.git", rev = "ec75759377791c9b785123d2d3e2457d08ac6621" }
clvmr = { version = "=0.3.2", features = ["pre-eval"] }
serde_json = "1.0"
rand = "0.8.5"
rand_chacha = "0.3.1"
clvm-traits = "0.7.0"
subtle = "2.5.0"
num-bigint = "0.4.4"
num-traits = "0.2.15"
chia-bls = "0.7.0"
clvm-utils = "0.7.0"
lazy_static = "1.4.0"
ff = { version = "0.13.0", features = ["derive"] }
bson = "2.11.0"
sha2 = "0.10.8"
indoc = "2.0.5"
serde = "1.0.203"
hex = "0.4.3"
salvo = "0.64.0"
tokio = { version = "1", features = ["macros"] }
tracing = "0.1"
tracing-subscriber = "0.3"
ctor = "0.2.8"
log = "0.4.22"
env_logger = "0.11.3"
exec = "0.3.1"
pyo3 = { version = "0.20.0", features = ["auto-initialize"], optional = true }

[dev-dependencies]
bls12_381 = { version = "=0.8.0", features = ["experimental"] }

[build-dependencies]
serde = "1.0.203"
toml = "0.8.14"
clvm_tools_rs = { git = "https://github.com/Chia-Network/clvm_tools_rs.git", rev = "ec75759377791c9b785123d2d3e2457d08ac6621" }
clvmr = { version = "=0.3.2", features = ["pre-eval"] }

[lib]
name = "chia_gaming"
crate-type = ["cdylib", "rlib"]

[[bin]]
name = "chia-gaming"
path = "src/cmd/main.rs"
required-features = ["simulator"]
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
## chia-gaming Traits and Structs

Here's a breakdown of the key traits and structs used in the `chia-gaming` project, along with their purposes.

**Common Types:**

* **`CoinID`:** Represents a unique identifier for a coin on the Chia blockchain.
* **`CoinString`:** A structured representation of a coin, containing its parent CoinID, puzzle hash, and amount.
* **`PrivateKey`:** Encapsulates a private key for signing Chia transactions.
* **`PublicKey`:** Encapsulates a public key derived from a `PrivateKey`.
* **`Aggsig`:** Represents an aggregated BLS signature, used in the standard signing scheme for chialisp, but also pressed into a 2-of-2 multi-signature scheme here.
* **`Hash`:** Represents a 32-byte SHA-256 hash.
* **`PuzzleHash`:** Represents the SHA-256 tree hash of a puzzle program.
* **`Puzzle`:** Represents a CLVM program that defines the rules for spending a coin.
* **`Amount`:** Represents a Chia amount in mojos.
* **`Timeout`:** Represents a block height at which a coin will expire if not spent.
* **`GameID`:** A unique identifier for a specific game.
* **`Program`:** A wrapper for CLVM programs in byte format.
* **`Spend`:** Represents a transaction spend, consisting of the puzzle, solution, and signature.
* **`CoinSpend`:** Encapsulates a `CoinString` and a `Spend` to represent a transaction that spends the coin.
* **`SpendBundle`:** A collection of `CoinSpend` objects that can be submitted as a transaction to the Chia blockchain.
* **`CoinCondition`:** Represents a condition that must be fulfilled to spend a coin.
* **`ValidationProgram`:** A CLVM program used for validating game moves.
* **`ValidationInfo`:** Contains the game state and a `ValidationProgram`, used for calculating a validation info hash.
* **`Evidence`:** CLVM data representing proof of cheating.

**Channel Handler:**

* **`ChannelHandlerPrivateKeys`:** Holds the private keys for a player's channel coin, unroll coin, and referee.
* **`ChannelHandlerInitiationData`:** Data used to initiate a state channel, including launcher coin ID, contributions, and public keys of the other player.
* **`ChannelHandlerInitiationResult`:** Returned by the `ChannelHandler` constructor, containing the puzzle hash of the channel coin and the initial channel half signature.
* **`PotatoSignatures`:** Contains half-signed information for sending the potato.
* **`GameStartInfo`:** Contains information for starting a game, including the game ID, initial state, amount, timeout, and game handlers.
* **`ReadableMove`:** A CLVM representation of a game move that can be interpreted by the UI.
* **`ReadableUX`:** A CLVM representation of a game state that can be displayed to the user.
* **`MoveResult`:** Contains the potato signatures and game move details for a successful move.
* **`OnChainGameCoin`:** Represents a game coin that has been moved on-chain.
* **`CoinSpentMoveUp`:** Represents a successful game move that was spent on-chain, containing the game coin spend, the game ID, and the new coin string.
* **`CoinSpentAccept`:** Represents a successful game acceptance that was spent on-chain, containing the game coin spend, the game ID, and the reward coin string.
* **`CoinSpentDisposition`:** Represents the outcome of spending a game coin on-chain.
* **`DispositionResult`:** The result of a `ChannelHandler`'s `channel_coin_spent` method, containing the disposition, skipped game IDs, the contribution adjustment, and any skipped coin IDs.
* **`CoinSpentResult`:** Result of a channel coin spend, providing the reward coin string and the list of new game coins.
* **`ChannelCoinSpentResult`:** Describes the result of spending a channel coin on-chain, providing the unroll transaction, timeout status, and any canceled game IDs.
* **`ChannelCoin`:** Encapsulates the state channel coin.
* **`ChannelCoinInfo`:** Holds a `ChannelCoin` and the amount it represents.
* **`ChannelCoinSpendInfo`:** Holds the solution, conditions, and signature of a channel coin spend.
* **`ChannelHandlerUnrollSpendInfo`:** Contains information required to spend the unroll coin, including the coin's data and the corresponding signatures.
* **`LiveGame`:** Represents a game currently in progress, holding the game ID, the referee maker, and contributions from both players.
* **`PotatoAcceptCachedData`:** Cached data for a potato accept message, used for unrolling.
* **`PotatoMoveCachedData`:** Cached data for a potato move message, used for unrolling.
* **`CachedPotatoRegenerateLastHop`:** Enum representing different types of cached data for potato messages.
* **`HandshakeResult`:** Holds the channel puzzle, amount, and spend information generated during the handshake process.

**Referee:**

* **`RefereeMaker`:** Handles the referee coin and its logic.
* **`GameMoveStateInfo`:** Stores basic information about a move, including the move made, mover share, and maximum move size.
* **`GameMoveDetails`:** Extends `GameMoveStateInfo` with a validation info hash.
* **`GameMoveWireData`:** Contains the puzzle hash for unroll and the `GameMoveDetails` for a move.
* **`OnChainRefereeMove`:** Dynamic arguments for a referee coin spend related to a game move.
* **`OnChainRefereeSlash`:** Dynamic arguments for a referee coin spend related to a slash.
* **`OnChainRefereeSolution`:** Enum representing different types of solutions for the referee coin.
* **`RefereeOnChainTransaction`:** Holds a spend bundle for a referee coin and the resulting reward coin.

**Game Handler:**

* **`GameHandler`:** Represents a game handler, either for a player's turn or the opponent's turn.
* **`MyTurnInputs`:** Contains inputs for a player's turn, including the move, amount, entropy, and information about the last move.
* **`MyTurnResult`:** The result of a player's turn, containing the next game handler, validation program, and other details.
* **`TheirTurnInputs`:** Contains inputs for an opponent's turn, including the amount, state, and move details.
* **`TheirTurnResult`:** The result of an opponent's turn, representing either a move, a slash, or a final move.
* **`MessageInputs`:** Contains inputs for a message handler, including the message, amount, state, move, and mover share.
* **`MessageHandler`:** Handles messages during the game, providing a `run` method to interpret messages.

**Additional:**

* **`DebugGamePrograms`:** A struct containing the debug game's validation programs and game handlers.
* **`RefereeTest`:** A struct used for testing the referee module.
* **`SimulatorEnvironment`:** A structure used in simulations to manage the game, identities, and the simulator instance.
* **`GameAction`:** Represents a possible action within a game simulation.
* **`GameActionResult`:** Represents the outcome of a game action.
* **`OnChainState`:** Enum representing the state of the game, either off-chain or on-chain.
* **`ValidatorMoveArgs`:** Arguments for the validator move query, containing the game move details, mover puzzle, and solution.
* **`CoinDataForReward`:** Data for a coin being used as a reward, containing the coin string.

**Overall, the project is organized around the concept of state channels, where two players interact through a set of coins on the Chia blockchain. The code uses a combination of CLVM programs and Rust code to manage the state channel, referee the games, and handle game logic. The use of traits helps to abstract away dependencies and make the code more modular and reusable.**
12 changes: 0 additions & 12 deletions all-in-list.clinc

This file was deleted.

10 changes: 0 additions & 10 deletions assert.clinc

This file was deleted.

Loading

0 comments on commit 870f9f3

Please sign in to comment.