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

[Don't merge] Update the minimal template to 1.14.0 #12

Closed
wants to merge 1 commit into from
Closed
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
10,395 changes: 0 additions & 10,395 deletions Cargo.lock

This file was deleted.

39 changes: 39 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,43 @@ members = [
resolver = "2"

[workspace.dependencies]
clap = { version = "4.5.3" }
docify = { version = "0.2.8" }
frame = { version = "0.5.0", default-features = false, package = "polkadot-sdk-frame" }
futures = { version = "0.3.30" }
futures-timer = { version = "3.0.2" }
jsonrpsee = { version = "0.23.2" }
minimal-template-runtime = { version = "0.1.0" }
sc-basic-authorship = { version = "0.42.0", default-features = false }
sc-cli = { version = "0.44.0", default-features = false }
sc-client-api = { version = "35.1.0", default-features = false }
sc-consensus = { version = "0.41.0", default-features = false }
sc-consensus-manual-seal = { version = "0.43.0", default-features = false }
sc-executor = { version = "0.39.0", default-features = false }
sc-network = { version = "0.42.0", default-features = false }
sc-offchain = { version = "37.0.0", default-features = false }
sc-rpc-api = { version = "0.41.0", default-features = false }
sc-service = { version = "0.43.0", default-features = false }
sc-telemetry = { version = "22.0.0", default-features = false }
sc-transaction-pool = { version = "35.0.0", default-features = false }
sc-transaction-pool-api = { version = "35.0.0", default-features = false }
serde_json = { version = "1.0.114", default-features = false }
sp-api = { version = "33.0.0", default-features = false }
sp-block-builder = { version = "33.0.0", default-features = false }
sp-blockchain = { version = "35.1.0", default-features = false }
sp-io = { version = "37.0.0", default-features = false }
sp-keyring = { version = "38.0.0", default-features = false }
sp-runtime = { version = "38.0.0", default-features = false }
sp-timestamp = { version = "33.0.0", default-features = false }
substrate-frame-rpc-system = { version = "36.0.0", default-features = false }
substrate-build-script-utils = { version = "11.0.0", default-features = false }
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
scale-info = { version = "2.11.1", default-features = false }
pallet-balances = { version = "37.0.0", default-features = false }
pallet-minimal-template = { version = "0.1.0", default-features = false }
pallet-sudo = { version = "36.0.0", default-features = false }
pallet-timestamp = { version = "35.0.0", default-features = false }
pallet-transaction-payment = { version = "36.0.0", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { version = "36.0.0", default-features = false }
sp-genesis-builder = { version = "0.14.0", default-features = false }
substrate-wasm-builder = { version = "23.0.0", default-features = false }
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM docker.io/paritytech/ci-unified:latest as builder

WORKDIR /polkadot
COPY . /polkadot

RUN cargo fetch
RUN cargo build --locked --release

FROM docker.io/parity/base-bin:latest

COPY --from=builder /polkadot/target/release/minimal-template-node /usr/local/bin

USER root
RUN useradd -m -u 1001 -U -s /bin/sh -d /polkadot polkadot && \
mkdir -p /data /polkadot/.local/share && \
chown -R polkadot:polkadot /data && \
ln -s /data /polkadot/.local/share/polkadot && \
# unclutter and minimize the attack surface
rm -rf /usr/bin /usr/sbin && \
# check if executable works in this container
/usr/local/bin/minimal-template-node --version

USER polkadot

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

ENTRYPOINT ["/usr/local/bin/minimal-template-node"]
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>
102 changes: 95 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,101 @@
# Minimal Template
<div align="center">

This is a minimal template for creating a blockchain using the Polkadot SDK.
# Polkadot SDK's Minimal Template

# Docs
<img height="70px" alt="Polkadot SDK Logo" src="https://github.com/paritytech/polkadot-sdk/raw/master/docs/images/Polkadot_Logo_Horizontal_Pink_White.png#gh-dark-mode-only"/>
<img height="70px" alt="Polkadot SDK Logo" src="https://github.com/paritytech/polkadot-sdk/raw/master/docs/images/Polkadot_Logo_Horizontal_Pink_Black.png#gh-light-mode-only"/>

You can generate and view the [Rust
Docs](https://doc.rust-lang.org/cargo/commands/cargo-doc.html) for this template
with this command:
> This is a minimal template for creating a blockchain based on Polkadot SDK.
>
> This template is automatically updated after releases in the main [Polkadot SDK monorepo](https://github.com/paritytech/polkadot-sdk).

</div>

* 🤏 This template is a minimal (in terms of complexity and the number of components)
template for building a blockchain node.

* 🔧 Its runtime is configured of a single custom pallet as a starting point, and a handful of ready-made pallets
such as a [Balances pallet](https://paritytech.github.io/polkadot-sdk/master/pallet_balances/index.html).

* 👤 The template has no consensus configured - it is best for experimenting with a single node network.

## Template Structure

A Polkadot SDK based project such as this one consists of:

* 💿 a [Node](./node/README.md) - the binary application.
* 🧮 the [Runtime](./runtime/README.md) - the core logic of the blockchain.
* 🎨 the [Pallets](./pallets/README.md) - from which the runtime is constructed.

## Getting Started

* 🦀 The template is using the Rust language.

* 👉 Check the
[Rust installation instructions](https://www.rust-lang.org/tools/install) for your system.

* 🛠️ Depending on your operating system and Rust version, there might be additional
packages required to compile this template - please take note of the Rust compiler output.

### Build

🔨 Use the following command to build the node without launching it:

```sh
cargo doc -p minimal-template --open
cargo build --release
```

🐳 Alternatively, build the docker image:

```sh
docker build . -t polkadot-sdk-minimal-template
```

### Single-Node Development Chain

👤 The following command starts a single-node development chain:

```sh
./target/release/minimal-template-node --dev

# docker version:
docker run --rm polkadot-sdk-minimal-template --dev
```

Development chains:

* 🧹 Do not persist the state.
* 💰 Are preconfigured with a genesis state that includes several prefunded development accounts.
* 🧑‍⚖️ Development accounts are used as `sudo` accounts.

### Connect with the Polkadot-JS Apps Front-End

* 🌐 You can interact with your local node using the
hosted version of the [Polkadot/Substrate
Portal](https://polkadot.js.org/apps/#/explorer?rpc=ws://localhost:9944).

* 🪐 A hosted version is also
available on [IPFS](https://dotapps.io/).

* 🧑‍🔧 You can also find the source code and instructions for hosting your own instance in the
[`polkadot-js/apps`](https://github.com/polkadot-js/apps) repository.

## Contributing

* 🔄 This template is automatically updated after releases in the main [Polkadot SDK monorepo](https://github.com/paritytech/polkadot-sdk).

* ➡️ Any pull requests should be directed to this [source](https://github.com/paritytech/polkadot-sdk/tree/master/templates/minimal).

* 😇 Please refer to the monorepo's
[contribution guidelines](https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CONTRIBUTING.md) and
[Code of Conduct](https://github.com/paritytech/polkadot-sdk/blob/master/docs/contributor/CODE_OF_CONDUCT.md).

## Getting Help

* 🧑‍🏫 To learn about Polkadot in general, [Polkadot.network](https://polkadot.network/) website is a good starting point.

* 🧑‍🔧 For technical introduction, [here](https://github.com/paritytech/polkadot-sdk#-documentation) are
the Polkadot SDK documentation resources.

* 👥 Additionally, there are [GitHub issues](https://github.com/paritytech/polkadot-sdk/issues) and
[Substrate StackExchange](https://substrate.stackexchange.com/).
64 changes: 31 additions & 33 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "minimal-template-node"
description = "A minimal Substrate-based Substrate node, ready for hacking. (polkadot v1.12.0)"
description = "A minimal Substrate-based Substrate node, ready for hacking. (polkadot v1.14.0)"
version = "0.1.0"
license = "MIT-0"
license = "Unlicense"
authors.workspace = true
homepage.workspace = true
repository.workspace = true
Expand All @@ -14,40 +14,38 @@ build = "build.rs"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
clap = { version = "4.5.3", features = ["derive"] }
futures = { version = "0.3.30", features = ["thread-pool"] }
futures-timer = "3.0.1"
jsonrpsee = { version = "0.22", features = ["server"] }
docify = { workspace = true }
clap = { features = ["derive"], workspace = true }
futures = { features = ["thread-pool"], workspace = true }
futures-timer = { workspace = true }
jsonrpsee = { features = ["server"], workspace = true }
serde_json = { workspace = true, default-features = true }
sc-cli = { version = "0.42.0" }
sc-executor = { version = "0.38.0" }
sc-network = { version = "0.40.0" }
sc-service = { version = "0.41.0" }
sc-telemetry = { version = "20.0.0" }
sc-transaction-pool = { version = "34.0.0" }
sc-transaction-pool-api = { version = "34.0.0" }
sc-consensus = { version = "0.39.1" }
sc-consensus-manual-seal = { version = "0.41.0" }
sc-rpc-api = { version = "0.39.0" }
sc-basic-authorship = { version = "0.40.0" }
sc-offchain = { version = "35.0.0" }
sc-client-api = { version = "34.0.0" }
sp-timestamp = { version = "32.0.0" }
sp-keyring = { version = "37.0.0" }
sp-api = { version = "32.0.0" }
sp-blockchain = { version = "34.0.0" }
sp-block-builder = { version = "32.0.0" }
sp-io = { version = "36.0.0" }
sp-runtime = { version = "37.0.0" }
substrate-frame-rpc-system = { version = "34.0.0" }

# Once the native runtime is gone, there should be little to no dependency on FRAME here, and
# certainly no dependency on the runtime.
frame = { version = "0.3.0", package = "polkadot-sdk-frame", features = ["experimental", "runtime"] }
runtime = { package = "minimal-template-runtime", path = "../runtime", version = "0.1.0" }
sc-cli = { version = "0.44.0", workspace = true, default-features = true }
sc-executor = { version = "0.39.0", workspace = true, default-features = true }
sc-network = { version = "0.42.0", workspace = true, default-features = true }
sc-service = { version = "0.43.0", workspace = true, default-features = true }
sc-telemetry = { version = "22.0.0", workspace = true, default-features = true }
sc-transaction-pool = { version = "35.0.0", workspace = true, default-features = true }
sc-transaction-pool-api = { version = "35.0.0", workspace = true, default-features = true }
sc-consensus = { version = "0.41.0", workspace = true, default-features = true }
sc-consensus-manual-seal = { version = "0.43.0", workspace = true, default-features = true }
sc-rpc-api = { version = "0.41.0", workspace = true, default-features = true }
sc-basic-authorship = { version = "0.42.0", workspace = true, default-features = true }
sc-offchain = { version = "37.0.0", workspace = true, default-features = true }
sc-client-api = { version = "35.1.0", workspace = true, default-features = true }
sp-timestamp = { version = "33.0.0", workspace = true, default-features = true }
sp-keyring = { version = "38.0.0", workspace = true, default-features = true }
sp-api = { version = "33.0.0", workspace = true, default-features = true }
sp-blockchain = { version = "35.1.0", workspace = true, default-features = true }
sp-block-builder = { version = "33.0.0", workspace = true, default-features = true }
sp-io = { version = "37.0.0", workspace = true, default-features = true }
sp-runtime = { version = "38.0.0", workspace = true, default-features = true }
substrate-frame-rpc-system = { version = "36.0.0", workspace = true, default-features = true }
frame = { features = ["experimental", "runtime"], workspace = true, default-features = true }
minimal-template-runtime = { version = "0.1.0", workspace = true }

[build-dependencies]
substrate-build-script-utils = { version = "11.0.0" }
substrate-build-script-utils = { version = "11.0.0", workspace = true, default-features = true }

[features]
default = []
18 changes: 18 additions & 0 deletions node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Node

ℹ️ A node - in Polkadot - is a binary executable, whose primary purpose is to execute the [runtime](../runtime/README.md).

🔗 It communicates with other nodes in the network, and aims for
[consensus](https://wiki.polkadot.network/docs/learn-consensus) among them.

⚙️ It acts as a remote procedure call (RPC) server, allowing interaction with the blockchain.

👉 Learn more about the architecture, and a difference between a node and a runtime
[here](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/wasm_meta_protocol/index.html).

👇 Here are the most important files in this node template:

- [`chain_spec.rs`](./src/chain_spec.rs): A chain specification is a source code file that defines the chain's
initial (genesis) state.
- [`service.rs`](./src/service.rs): This file defines the node implementation.
It's a place to configure consensus-related topics. In favor of minimalism, this template has no consensus configured.
6 changes: 3 additions & 3 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use runtime::{BalancesConfig, SudoConfig, WASM_BINARY};
use minimal_template_runtime::{BalancesConfig, SudoConfig, WASM_BINARY};
use sc_service::{ChainType, Properties};
use serde_json::{json, Value};
use sp_keyring::AccountKeyring;

/// This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<()>;
pub type ChainSpec = sc_service::GenericChainSpec;

fn props() -> Properties {
let mut properties = Properties::new();
Expand All @@ -43,7 +43,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
/// Configure initial storage state for FRAME pallets.
fn testnet_genesis() -> Value {
use frame::traits::Get;
use runtime::interface::{Balance, MinimumBalance};
use minimal_template_runtime::interface::{Balance, MinimumBalance};
let endowment = <MinimumBalance as Get<Balance>>::get().max(1) * 1000;
let balances = AccountKeyring::iter()
.map(|a| (a.to_account_id(), endowment))
Expand Down
2 changes: 1 addition & 1 deletion node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl std::str::FromStr for Consensus {
} else if let Some(block_time) = s.strip_prefix("manual-seal-") {
Consensus::ManualSeal(block_time.parse().map_err(|_| "invalid block time")?)
} else {
return Err("incorrect consensus identifier".into())
return Err("incorrect consensus identifier".into());
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ pub fn run() -> sc_cli::Result<()> {
},
Some(Subcommand::ChainInfo(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run::<runtime::interface::OpaqueBlock>(&config))
runner.sync_run(|config| {
cmd.run::<minimal_template_runtime::interface::OpaqueBlock>(&config)
})
},
None => {
let runner = cli.create_runner(&cli.run)?;
Expand Down
5 changes: 3 additions & 2 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
#![warn(missing_docs)]

use jsonrpsee::RpcModule;
use runtime::interface::{AccountId, Nonce, OpaqueBlock};
use minimal_template_runtime::interface::{AccountId, Nonce, OpaqueBlock};
use sc_transaction_pool_api::TransactionPool;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use std::sync::Arc;
use substrate_frame_rpc_system::{System, SystemApiServer};

pub use sc_rpc_api::DenyUnsafe;

Expand All @@ -41,6 +40,7 @@ pub struct FullDeps<C, P> {
pub deny_unsafe: DenyUnsafe,
}

#[docify::export]
/// Instantiate all full RPC extensions.
pub fn create_full<C, P>(
deps: FullDeps<C, P>,
Expand All @@ -57,6 +57,7 @@ where
C::Api: substrate_frame_rpc_system::AccountNonceApi<OpaqueBlock, AccountId, Nonce>,
P: TransactionPool + 'static,
{
use substrate_frame_rpc_system::{System, SystemApiServer};
let mut module = RpcModule::new(());
let FullDeps { client, pool, deny_unsafe } = deps;

Expand Down
Loading
Loading