Skip to content
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

Dispute game trusted operation #55

Merged
merged 6 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ dependencies = [
[[package]]
name = "ajuna-common"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"frame-support",
"parity-scale-codec",
Expand All @@ -136,7 +136,7 @@ dependencies = [
[[package]]
name = "ajuna-primitives"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"sp-core",
"sp-runtime",
Expand All @@ -145,7 +145,7 @@ dependencies = [
[[package]]
name = "ajuna-solo-runtime"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"ajuna-common",
"ajuna-primitives",
Expand All @@ -156,6 +156,7 @@ dependencies = [
"frame-system-rpc-runtime-api",
"log 0.4.17",
"orml-vesting",
"pallet-ajuna-awesome-avatars",
"pallet-ajuna-board",
"pallet-ajuna-gameregistry",
"pallet-ajuna-matchmaker",
Expand Down Expand Up @@ -4212,10 +4213,24 @@ version = "6.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435"

[[package]]
name = "pallet-ajuna-awesome-avatars"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"ajuna-common",
"frame-support",
"frame-system",
"parity-scale-codec",
"scale-info",
"sp-runtime",
"sp-std 4.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.20)",
]

[[package]]
name = "pallet-ajuna-board"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"ajuna-common",
"dot4gravity",
Expand All @@ -4231,7 +4246,7 @@ dependencies = [
[[package]]
name = "pallet-ajuna-gameregistry"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"ajuna-common",
"frame-benchmarking",
Expand All @@ -4248,7 +4263,7 @@ dependencies = [
[[package]]
name = "pallet-ajuna-matchmaker"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"ajuna-common",
"frame-support",
Expand All @@ -4261,7 +4276,7 @@ dependencies = [
[[package]]
name = "pallet-ajuna-runner"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"ajuna-common",
"frame-support",
Expand Down Expand Up @@ -5848,7 +5863,7 @@ dependencies = [
[[package]]
name = "sgx-externalities"
version = "0.4.0"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#d061243c60097e37139854b450aede9003cff1c3"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#9340fd182070ab2b3b7dbc479c0e2da92274b1b2"
dependencies = [
"derive_more",
"environmental",
Expand All @@ -5863,7 +5878,7 @@ dependencies = [
[[package]]
name = "sgx-runtime"
version = "0.8.0"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#d061243c60097e37139854b450aede9003cff1c3"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#9340fd182070ab2b3b7dbc479c0e2da92274b1b2"
dependencies = [
"frame-executive",
"frame-support",
Expand Down Expand Up @@ -6536,7 +6551,7 @@ dependencies = [
[[package]]
name = "sp-io"
version = "6.0.0"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#d061243c60097e37139854b450aede9003cff1c3"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#9340fd182070ab2b3b7dbc479c0e2da92274b1b2"
dependencies = [
"environmental",
"futures 0.3.21",
Expand Down
11 changes: 9 additions & 2 deletions app-libs/stf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub use sgx_runtime::{Balance, Index};

use codec::{Compact, Decode, Encode};
use derive_more::Display;
use itp_types::BlockNumber;
use sp_core::{crypto::AccountId32, ed25519, sr25519, Pair, H256};
use sp_runtime::{traits::Verify, MultiSignature};
use std::{collections::BTreeSet, string::String};
Expand All @@ -58,8 +59,12 @@ pub type SgxGameTurn = pallet_ajuna_board::dot4gravity::Turn;
pub type Coordinates = pallet_ajuna_board::dot4gravity::Coordinates;
pub type Side = pallet_ajuna_board::dot4gravity::Side;

pub type SgxGameBoardStruct =
pallet_ajuna_board::BoardGame<SgxBoardId, SgxGameState, BoundedVec<AccountId, MaxPlayers>>;
pub type SgxGameBoardStruct = pallet_ajuna_board::BoardGame<
SgxBoardId,
SgxGameState,
BoundedVec<AccountId, MaxPlayers>,
BlockNumber,
>;

pub struct SgxWinningBoard {
pub winner: AccountId,
Expand Down Expand Up @@ -207,6 +212,7 @@ pub enum TrustedCall {
board_new_game(AccountId, SgxBoardId, BTreeSet<AccountId>),
board_play_turn(AccountId, SgxGameTurn),
board_finish_game(AccountId, SgxBoardId),
board_dispute_game(AccountId, SgxBoardId),
}

impl TrustedCall {
Expand All @@ -219,6 +225,7 @@ impl TrustedCall {
TrustedCall::board_new_game(account, _, _) => account,
TrustedCall::board_play_turn(account, _) => account,
TrustedCall::board_finish_game(account, _) => account,
TrustedCall::board_dispute_game(account, _) => account,
}
}

Expand Down
9 changes: 9 additions & 0 deletions app-libs/stf/src/stf_sgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ impl Stf {
.map_err(|e| StfError::Dispatch(format!("{:?}", e.error)))?;
Ok(())
},
TrustedCall::board_dispute_game(sender, board_id) => {
let origin = sgx_runtime::Origin::signed(sender.clone());
debug!("board disputed ({:x?}, {:?})", sender.encode(), board_id);
sgx_runtime::AjunaBoardCall::<Runtime>::dispute_game { board_id }
.dispatch_bypass_filter(origin.clone())
.map_err(|e| StfError::Dispatch(format!("{:?}", e.error)))?;
Ok(())
},
}?;
increment_nonce(&sender);
Ok(())
Expand Down Expand Up @@ -311,6 +319,7 @@ impl Stf {
TrustedCall::board_new_game(_, _, _) => debug!("No storage updates needed..."),
TrustedCall::board_play_turn(_, _) => debug!("No storage updates needed..."),
TrustedCall::board_finish_game(_, _) => debug!("No storage updates needed..."),
TrustedCall::board_dispute_game(_, _) => debug!("No storage updates needed..."),
};
key_hashes
}
Expand Down
29 changes: 27 additions & 2 deletions cli/src/trusted_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::{
};
use codec::Decode;
use ita_stf::{
Coordinates, Index, KeyPair, SgxGameBoardStruct, SgxGameTurn, Side, TrustedCall, TrustedGetter,
TrustedOperation,
Coordinates, Index, KeyPair, SgxBoardId, SgxGameBoardStruct, SgxGameTurn, Side, TrustedCall,
TrustedGetter, TrustedOperation,
};
use log::*;
use my_node_runtime::Balance;
Expand Down Expand Up @@ -144,6 +144,14 @@ pub enum TrustedCommands {
/// Player's incognito AccountId in ss58check format
player: String,
},

/// Dispute a board
Dispute {
/// Player's incognito AccountId in ss58check format
player: String,
/// The board id
board_id: ita_stf::SgxBoardId,
},
}

pub struct SideCommand(Side);
Expand Down Expand Up @@ -188,6 +196,8 @@ pub fn match_trusted_commands(cli: &Cli, trusted_args: &TrustedArgs) {
TrustedCommands::DropStone { player, side, n } =>
play_turn(cli, trusted_args, player, SgxGameTurn::DropStone(((*side).0, *n))),
TrustedCommands::GetBoard { player } => get_board(cli, trusted_args, player),
TrustedCommands::Dispute { player, board_id } =>
dispute_game(cli, trusted_args, player, board_id),
}
}

Expand Down Expand Up @@ -329,3 +339,18 @@ fn get_board(cli: &Cli, trusted_args: &TrustedArgs, arg_player: &str) {
println!("could not fetch board");
};
}

fn dispute_game(cli: &Cli, trusted_args: &TrustedArgs, arg_player: &str, board_id: &SgxBoardId) {
let player = get_pair_from_str(trusted_args, arg_player);
println!("player ss58 is {}", player.public().to_ss58check());

println!("send trusted call dispute-game from {} for board {:?}", player.public(), board_id);
let (mrenclave, shard) = get_identifiers(trusted_args);
let nonce = get_layer_two_nonce!(player, cli, trusted_args);

let top: TrustedOperation = TrustedCall::board_dispute_game(player.public().into(), *board_id)
.sign(&KeyPair::Sr25519(player), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);

let _ = perform_operation(cli, trusted_args, &top);
}
2 changes: 1 addition & 1 deletion core-primitives/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sp_runtime::{
};
use std::vec::Vec;
use substrate_api_client::{
AssetTipExtrinsicParams, AssetTipExtrinsicParamsBuilder, AssetTip, SubstrateDefaultSignedExtra,
AssetTip, AssetTipExtrinsicParams, AssetTipExtrinsicParamsBuilder, SubstrateDefaultSignedExtra,
UncheckedExtrinsicV4,
};

Expand Down
14 changes: 7 additions & 7 deletions enclave-runtime/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ dependencies = [
[[package]]
name = "ajuna-common"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"frame-support",
"parity-scale-codec",
Expand Down Expand Up @@ -2150,7 +2150,7 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "pallet-ajuna-board"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"ajuna-common",
"dot4gravity",
Expand All @@ -2165,7 +2165,7 @@ dependencies = [
[[package]]
name = "pallet-ajuna-gameregistry"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"ajuna-common",
"frame-support",
Expand All @@ -2181,7 +2181,7 @@ dependencies = [
[[package]]
name = "pallet-ajuna-matchmaker"
version = "0.1.0"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#028534df8156c49171b4119fac50cdf455f5b576"
source = "git+https://github.com/ajuna-network/Ajuna?rev=polkadot-v0.9.20-dev#de79911ca4190ad5ae01e41bab99d823cc1bf967"
dependencies = [
"ajuna-common",
"frame-support",
Expand Down Expand Up @@ -2961,7 +2961,7 @@ dependencies = [
[[package]]
name = "sgx-externalities"
version = "0.4.0"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#d061243c60097e37139854b450aede9003cff1c3"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#9340fd182070ab2b3b7dbc479c0e2da92274b1b2"
dependencies = [
"derive_more",
"environmental",
Expand All @@ -2976,7 +2976,7 @@ dependencies = [
[[package]]
name = "sgx-runtime"
version = "0.8.0"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#d061243c60097e37139854b450aede9003cff1c3"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#9340fd182070ab2b3b7dbc479c0e2da92274b1b2"
dependencies = [
"frame-executive",
"frame-support",
Expand Down Expand Up @@ -3494,7 +3494,7 @@ dependencies = [
[[package]]
name = "sp-io"
version = "6.0.0"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#d061243c60097e37139854b450aede9003cff1c3"
source = "git+https://github.com/ajuna-network/sgx-runtime?rev=polkadot-v0.9.20-dev#9340fd182070ab2b3b7dbc479c0e2da92274b1b2"
dependencies = [
"environmental",
"hash-db",
Expand Down