Skip to content

Commit

Permalink
Merge branch 'main' into kcoxe-add-fork-visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshOrndorff committed Dec 15, 2023
2 parents 92115f3 + c73e5ec commit a9d4bb6
Show file tree
Hide file tree
Showing 10 changed files with 817 additions and 489 deletions.
979 changes: 676 additions & 303 deletions Cargo.lock

Large diffs are not rendered by default.

89 changes: 44 additions & 45 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,47 @@ academy-pow-runtime = { path = "../runtime" }
multi-pow = { default-features = false, path = "../multi-pow" }

# Polkadot SDK Dependencies
frame-executive = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
frame-support = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
frame-system = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
frame-system-rpc-runtime-api = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-balances = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-contracts = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-contracts-primitives = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-insecure-randomness-collective-flip = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-sudo = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-timestamp = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-transaction-payment = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-transaction-payment-rpc = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
pallet-transaction-payment-rpc-runtime-api = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sc-basic-authorship = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-cli = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sc-client-api = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-consensus = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-consensus-manual-seal = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-consensus-pow = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-executor = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-network = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-rpc-api = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-service = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sc-telemetry = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-transaction-pool = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-transaction-pool-api = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sp-api = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-block-builder = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-blockchain = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sp-consensus = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sp-consensus-pow = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-core = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-inherents = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-io = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-keystore = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sp-offchain = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-runtime = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-session = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-std = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-timestamp = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
sp-transaction-pool = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-version = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
substrate-build-script-utils = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
substrate-frame-rpc-system = { branch = "release-polkadot-v1.3.0", git = "https://github.com/paritytech/polkadot-sdk" }
substrate-wasm-builder = { branch = "release-polkadot-v1.3.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
frame-executive = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
frame-support = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
frame-system = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
frame-system-rpc-runtime-api = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-balances = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-contracts = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-insecure-randomness-collective-flip = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-timestamp = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-transaction-payment = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
pallet-transaction-payment-rpc = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
pallet-transaction-payment-rpc-runtime-api = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sc-basic-authorship = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-cli = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sc-client-api = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-consensus = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-consensus-manual-seal = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-consensus-pow = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-executor = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-network = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-rpc-api = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-service = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sc-telemetry = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-transaction-pool = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sc-transaction-pool-api = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sp-api = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-block-builder = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-blockchain = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sp-consensus = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sp-consensus-pow = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-core = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-genesis-builder = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-inherents = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-io = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-keystore = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sp-offchain = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-runtime = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-session = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-std = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-timestamp = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
sp-transaction-pool = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
sp-version = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
substrate-build-script-utils = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
substrate-frame-rpc-system = { branch = "release-polkadot-v1.5.0", git = "https://github.com/paritytech/polkadot-sdk" }
substrate-wasm-builder = { branch = "release-polkadot-v1.5.0", default-features = false, git = "https://github.com/paritytech/polkadot-sdk" }
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN useradd -m -u 1000 -U -s /bin/sh -d /node-dev node-dev && \

USER node-dev

EXPOSE 30333 9933 9944 9615
EXPOSE 30333 9944 9615
VOLUME ["/chain-data"]

ENTRYPOINT ["/usr/local/bin/academy-pow"]
8 changes: 4 additions & 4 deletions multi-pow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ name = "multi-pow"
version = "3.0.0"

[dependencies]
md5 = "0.7.0"
parity-scale-codec = { version = "3.6.1", features = [ "derive" ], default-features = false }
scale-info = { version = "2.1.2", features = [ "derive" ], default-features = false }
sha3 = { version = "0.10.1", default-features = false, optional = true }
md5 = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
sha3 = { workspace = true, optional = true }

sc-client-api = { optional = true, workspace = true }
sc-consensus-pow = { optional = true, workspace = true }
Expand Down
39 changes: 21 additions & 18 deletions multi-pow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sc_consensus_pow::{Error, PowAlgorithm};
#[cfg(feature = "std")]
use sha3::{Digest, Keccak256, Sha3_256};
#[cfg(feature = "std")]
use sp_api::{HeaderT, ProvideRuntimeApi};
use sp_api::{ProvideRuntimeApi};
#[cfg(feature = "std")]
use sp_consensus_pow::DifficultyApi;
#[cfg(feature = "std")]
Expand All @@ -35,7 +35,7 @@ use sp_core::{H256, U256};
#[cfg(feature = "std")]
use sp_runtime::generic::BlockId;
#[cfg(feature = "std")]
use sp_runtime::traits::Block as BlockT;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};

/// A struct that represents a difficulty threshold.
/// Unlike a normal PoW algorithm this struct has a separate threshold for each hash
Expand All @@ -58,10 +58,14 @@ pub struct Threshold {
pub keccak: U256,
}

// This trait is not fully baked in the Substrate PoW code, so I will not use it for now.
// This trait does not seem to be fully baked in the Substrate PoW code
// But we do need some kind of sinsible impl here so the node can import blocks.
// so I will not use it for now.
impl TotalDifficulty for Threshold {
fn increment(&mut self, _: Threshold) {
unimplemented!()
fn increment(&mut self, other: Threshold) {
self.md5 += other.md5;
self.sha3 += other.sha3;
self.keccak += other.keccak;
}
}

Expand Down Expand Up @@ -110,8 +114,8 @@ pub fn multi_hash_meets_difficulty(hash: &MultiHash, difficulty: Threshold) -> b
/// `RawSeal` type.
#[derive(Clone, PartialEq, Eq, Encode, Decode, Debug)]
pub struct Seal {
pub difficulty: Threshold,
pub work: MultiHash,
pub difficulty: Threshold,
pub nonce: U256,
}

Expand Down Expand Up @@ -217,10 +221,8 @@ where

// This is where we handle forks on the verification side.
// We will still need to handle it in the mining algorithm somewhere.
// Option 1) have the "normal" mining algo try each hash in order for each nonce
// and disable it there.
// Option 2) make the miner configure what algo they mine manually with their cli.
let parent_number = match parent_id {
// Currently we make the miner configure what algo they mine manually with their cli.
let _parent_number = match parent_id {
BlockId::Hash(h) => *self
.client
.header(*h)
Expand All @@ -230,18 +232,19 @@ where
BlockId::Number(n) => *n,
};

// When we are ready to do a fork, this is where to do it.
// Declare a threshold height at which to perform a fork
let fork_height: <<B as BlockT>::Header as HeaderT>::Number = 7900u32.into();
// let fork_height: <<B as BlockT>::Header as HeaderT>::Number = 7900u32.into();

// To begin with we only allow md5 hashes for our pow
// After the fork height this check is skipped so all the hashes become valid
if parent_number > fork_height {
match seal.work.algo {
SupportedHashes::Md5 => {return Ok(false)},
SupportedHashes::Sha3 => (),
SupportedHashes::Keccak => (),
}
}
// if parent_number > fork_height {
// match seal.work.algo {
// SupportedHashes::Md5 => {return Ok(false)},
// SupportedHashes::Sha3 => (),
// SupportedHashes::Keccak => (),
// }
// }

// See whether the hash meets the difficulty requirement. If not, fail fast.
if !multi_hash_meets_difficulty(&seal.work, difficulty) {
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ hex = { workspace = true }
log = { workspace = true }
parity-scale-codec = { workspace = true }
rand = { workspace = true }
serde_json = "1.0.108"
sha3 = { workspace = true }
jsonrpsee = { workspace = true }

Expand Down
Loading

0 comments on commit a9d4bb6

Please sign in to comment.