├── .dockerignore
├── .github
├── CODEOWNERS
├── ISSUE_TEMPLATE
│ └── config.yml
├── pull_request_template.md
└── workflows
│ ├── Entitlements.plist
│ ├── chain-spec-snapshot-build.yml
│ ├── runtime-snapshot-build.yml
│ ├── rust.yml
│ ├── rustdoc.yml
│ └── snapshot-build.yml
├── .gitignore
├── CONTRIBUTING.md
├── Cargo.lock
├── Cargo.toml
├── Dockerfile-bootstrap-node
├── Dockerfile-bootstrap-node.aarch64
├── Dockerfile-farmer
├── Dockerfile-farmer.aarch64
├── Dockerfile-node
├── Dockerfile-node.aarch64
├── Dockerfile-runtime
├── README.md
├── crates
├── pallet-domains
│ ├── Cargo.toml
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── tests.rs
│ │ └── weights.rs
├── pallet-feeds
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── feed_processor.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ └── tests.rs
├── pallet-grandpa-finality-verifier
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── chain.rs
│ │ ├── grandpa.rs
│ │ ├── lib.rs
│ │ └── tests
│ │ ├── justification.rs
│ │ ├── keyring.rs
│ │ ├── mock.rs
│ │ └── mod.rs
├── pallet-object-store
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ └── tests.rs
├── pallet-offences-subspace
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ └── tests.rs
├── pallet-rewards
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── default_weights.rs
│ │ └── lib.rs
├── pallet-runtime-configs
│ ├── Cargo.toml
│ └── src
│ │ └── lib.rs
├── pallet-settlement
│ ├── Cargo.toml
│ └── src
│ │ └── lib.rs
├── pallet-subspace
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── benchmarking.rs
│ │ ├── equivocation.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ └── weights.rs
├── pallet-transaction-fees
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── default_weights.rs
│ │ └── lib.rs
├── sc-consensus-fraud-proof
│ ├── Cargo.toml
│ └── src
│ │ └── lib.rs
├── sc-consensus-subspace-rpc
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ └── lib.rs
├── sc-consensus-subspace
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── archiver.rs
│ │ ├── aux_schema.rs
│ │ ├── lib.rs
│ │ ├── notification.rs
│ │ ├── slot_worker.rs
│ │ └── tests.rs
├── sc-subspace-block-relay
│ ├── Cargo.toml
│ └── src
│ │ ├── consensus.rs
│ │ ├── lib.rs
│ │ ├── protocol.rs
│ │ ├── protocol
│ │ └── compact_block.rs
│ │ └── utils.rs
├── sc-subspace-chain-specs
│ ├── Cargo.toml
│ └── src
│ │ ├── lib.rs
│ │ └── utils.rs
├── sp-consensus-subspace
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── digests.rs
│ │ ├── inherents.rs
│ │ ├── lib.rs
│ │ ├── offence.rs
│ │ └── tests.rs
├── sp-domains
│ ├── Cargo.toml
│ └── src
│ │ ├── bundle_election.rs
│ │ ├── fraud_proof.rs
│ │ ├── lib.rs
│ │ ├── merkle_tree.rs
│ │ └── transaction.rs
├── sp-lightclient
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ └── tests.rs
├── sp-objects
│ ├── Cargo.toml
│ └── src
│ │ └── lib.rs
├── sp-settlement
│ ├── Cargo.toml
│ └── src
│ │ └── lib.rs
├── subspace-archiving
│ ├── Cargo.toml
│ ├── README.md
│ ├── benches
│ │ └── archiving.rs
│ ├── src
│ │ ├── archiver.rs
│ │ ├── archiver
│ │ │ └── incremental_record_commitments.rs
│ │ ├── lib.rs
│ │ ├── piece_reconstructor.rs
│ │ └── reconstructor.rs
│ └── tests
│ │ └── integration
│ │ ├── archiver.rs
│ │ ├── main.rs
│ │ ├── piece_reconstruction.rs
│ │ └── reconstructor.rs
├── subspace-core-primitives
│ ├── Cargo.toml
│ ├── README.md
│ ├── benches
│ │ └── kzg.rs
│ └── src
│ │ ├── crypto.rs
│ │ ├── crypto
│ │ ├── kzg.rs
│ │ └── kzg
│ │ │ ├── eth-public-parameters.bin
│ │ │ ├── serde.rs
│ │ │ └── tests.rs
│ │ ├── lib.rs
│ │ ├── objects.rs
│ │ ├── pieces.rs
│ │ ├── pieces
│ │ ├── serde.rs
│ │ └── tests.rs
│ │ ├── segments.rs
│ │ ├── serde.rs
│ │ └── tests.rs
├── subspace-erasure-coding
│ ├── Cargo.toml
│ ├── benches
│ │ └── commitments.rs
│ └── src
│ │ ├── lib.rs
│ │ └── tests.rs
├── subspace-farmer-components
│ ├── Cargo.toml
│ ├── README.md
│ ├── benches
│ │ ├── auditing.rs
│ │ ├── plotting.rs
│ │ ├── proving.rs
│ │ └── reading.rs
│ └── src
│ │ ├── auditing.rs
│ │ ├── file_ext.rs
│ │ ├── lib.rs
│ │ ├── piece_caching.rs
│ │ ├── plotting.rs
│ │ ├── proving.rs
│ │ ├── reading.rs
│ │ ├── sector.rs
│ │ └── segment_reconstruction.rs
├── subspace-farmer
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ ├── bin
│ │ └── subspace-farmer
│ │ │ ├── commands.rs
│ │ │ ├── commands
│ │ │ ├── farm.rs
│ │ │ ├── farm
│ │ │ │ └── dsn.rs
│ │ │ ├── info.rs
│ │ │ └── shared.rs
│ │ │ ├── main.rs
│ │ │ ├── ss58.rs
│ │ │ └── utils.rs
│ │ ├── identity.rs
│ │ ├── lib.rs
│ │ ├── node_client.rs
│ │ ├── node_client
│ │ └── node_rpc_client.rs
│ │ ├── object_mappings.rs
│ │ ├── object_mappings
│ │ └── tests.rs
│ │ ├── reward_signing.rs
│ │ ├── single_disk_plot.rs
│ │ ├── single_disk_plot
│ │ └── piece_reader.rs
│ │ ├── utils.rs
│ │ ├── utils
│ │ ├── farmer_piece_cache.rs
│ │ ├── farmer_piece_getter.rs
│ │ ├── farmer_provider_storage.rs
│ │ ├── node_piece_getter.rs
│ │ ├── parity_db_store.rs
│ │ ├── piece_cache.rs
│ │ ├── piece_validator.rs
│ │ ├── readers_and_pieces.rs
│ │ └── tests.rs
│ │ └── ws_rpc_server.rs
├── subspace-fraud-proof
│ ├── Cargo.toml
│ └── src
│ │ ├── domain_extrinsics_builder.rs
│ │ ├── domain_runtime_code.rs
│ │ ├── invalid_state_transition_proof.rs
│ │ ├── invalid_transaction_proof.rs
│ │ ├── lib.rs
│ │ ├── tests.rs
│ │ └── verifier_api.rs
├── subspace-networking
│ ├── Cargo.toml
│ ├── examples
│ │ ├── announce-piece-complex.rs
│ │ ├── announce-piece.rs
│ │ ├── custom-store.rs
│ │ ├── get-peers-complex.rs
│ │ ├── get-peers.rs
│ │ ├── networking.rs
│ │ └── requests.rs
│ └── src
│ │ ├── behavior.rs
│ │ ├── behavior
│ │ ├── persistent_parameters.rs
│ │ ├── provider_storage.rs
│ │ ├── provider_storage
│ │ │ ├── providers.rs
│ │ │ └── providers
│ │ │ │ └── tests.rs
│ │ └── tests.rs
│ │ ├── bin
│ │ └── subspace-bootstrap-node
│ │ │ └── main.rs
│ │ ├── create.rs
│ │ ├── create
│ │ ├── temporary_bans.rs
│ │ ├── tests.rs
│ │ └── transport.rs
│ │ ├── lib.rs
│ │ ├── node.rs
│ │ ├── node_runner.rs
│ │ ├── request_handlers.rs
│ │ ├── request_handlers
│ │ ├── generic_request_handler.rs
│ │ ├── object_mappings.rs
│ │ ├── peer_info.rs
│ │ ├── piece_announcement.rs
│ │ ├── piece_by_key.rs
│ │ ├── pieces_by_range.rs
│ │ └── segment_header.rs
│ │ ├── request_responses.rs
│ │ ├── request_responses
│ │ └── tests.rs
│ │ ├── reserved_peers.rs
│ │ ├── reserved_peers
│ │ └── handler.rs
│ │ ├── shared.rs
│ │ ├── utils.rs
│ │ └── utils
│ │ ├── multihash.rs
│ │ ├── piece_announcement.rs
│ │ ├── piece_provider.rs
│ │ ├── prometheus.rs
│ │ ├── tests.rs
│ │ ├── unique_record_binary_heap.rs
│ │ └── unique_record_binary_heap
│ │ └── tests.rs
├── subspace-node
│ ├── Cargo.toml
│ ├── README.md
│ ├── build.rs
│ ├── res
│ │ └── chain-spec-raw-devnet.json
│ └── src
│ │ ├── bin
│ │ └── subspace-node.rs
│ │ ├── chain_spec.rs
│ │ ├── chain_spec_utils.rs
│ │ ├── core_domain.rs
│ │ ├── core_domain
│ │ └── core_evm_chain_spec.rs
│ │ ├── import_blocks_from_dsn.rs
│ │ ├── lib.rs
│ │ ├── system_domain.rs
│ │ └── system_domain
│ │ ├── chain_spec.rs
│ │ └── cli.rs
├── subspace-proof-of-space
│ ├── Cargo.toml
│ ├── benches
│ │ └── pos.rs
│ └── src
│ │ ├── chia.rs
│ │ ├── chia_legacy.rs
│ │ ├── chiapos.rs
│ │ ├── chiapos
│ │ ├── constants.rs
│ │ ├── table.rs
│ │ ├── table
│ │ │ ├── tests.rs
│ │ │ └── types.rs
│ │ ├── tables.rs
│ │ ├── tables
│ │ │ └── tests.rs
│ │ ├── tests.rs
│ │ └── utils.rs
│ │ ├── lib.rs
│ │ └── shim.rs
├── subspace-rpc-primitives
│ ├── Cargo.toml
│ └── src
│ │ └── lib.rs
├── subspace-runtime-primitives
│ ├── Cargo.toml
│ └── src
│ │ └── lib.rs
├── subspace-runtime
│ ├── Cargo.toml
│ ├── build.rs
│ ├── src
│ │ ├── domains.rs
│ │ ├── feed_processor.rs
│ │ ├── fees.rs
│ │ ├── lib.rs
│ │ ├── object_mapping.rs
│ │ ├── signed_extensions.rs
│ │ └── weights.rs
│ └── tests
│ │ └── integration
│ │ ├── main.rs
│ │ └── object_mapping.rs
├── subspace-service
│ ├── Cargo.toml
│ └── src
│ │ ├── dsn.rs
│ │ ├── dsn
│ │ ├── import_blocks.rs
│ │ ├── import_blocks
│ │ │ ├── piece_validator.rs
│ │ │ └── segment_headers.rs
│ │ └── node_provider_storage.rs
│ │ ├── lib.rs
│ │ ├── metrics.rs
│ │ ├── piece_cache.rs
│ │ ├── piece_cache
│ │ └── tests.rs
│ │ ├── rpc.rs
│ │ ├── segment_headers.rs
│ │ └── tx_pre_validator.rs
├── subspace-solving
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ └── lib.rs
├── subspace-transaction-pool
│ ├── Cargo.toml
│ └── src
│ │ ├── bundle_validator.rs
│ │ └── lib.rs
├── subspace-verification
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ │ └── lib.rs
└── subspace-wasm-tools
│ ├── Cargo.toml
│ └── src
│ └── lib.rs
├── docs
├── development.md
└── farming.md
├── domains
├── README.md
├── client
│ ├── block-builder
│ │ ├── Cargo.toml
│ │ ├── README.md
│ │ └── src
│ │ │ └── lib.rs
│ ├── block-preprocessor
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ ├── inherents.rs
│ │ │ ├── lib.rs
│ │ │ ├── runtime_api.rs
│ │ │ ├── runtime_api_full.rs
│ │ │ ├── runtime_api_light.rs
│ │ │ └── xdm_verifier.rs
│ ├── consensus-relay-chain
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ ├── import_queue.rs
│ │ │ └── lib.rs
│ ├── cross-domain-message-gossip
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ ├── gossip_worker.rs
│ │ │ ├── lib.rs
│ │ │ └── message_listener.rs
│ ├── domain-executor
│ │ ├── Cargo.toml
│ │ ├── README.md
│ │ └── src
│ │ │ ├── aux_schema.rs
│ │ │ ├── bundle_election_solver.rs
│ │ │ ├── domain_block_processor.rs
│ │ │ ├── domain_bundle_producer.rs
│ │ │ ├── domain_bundle_proposer.rs
│ │ │ ├── domain_worker.rs
│ │ │ ├── fraud_proof.rs
│ │ │ ├── gossip_message_validator.rs
│ │ │ ├── lib.rs
│ │ │ ├── parent_chain.rs
│ │ │ ├── sortition.rs
│ │ │ ├── system_bundle_processor.rs
│ │ │ ├── system_domain_worker.rs
│ │ │ ├── system_executor.rs
│ │ │ ├── system_gossip_message_validator.rs
│ │ │ ├── tests.rs
│ │ │ └── utils.rs
│ ├── eth-service
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ ├── lib.rs
│ │ │ ├── provider.rs
│ │ │ ├── rpc.rs
│ │ │ └── service.rs
│ ├── executor-gossip
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ ├── lib.rs
│ │ │ └── worker.rs
│ └── relayer
│ │ ├── Cargo.toml
│ │ └── src
│ │ ├── lib.rs
│ │ └── worker.rs
├── pallets
│ ├── domain-registry
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ ├── benchmarking.rs
│ │ │ ├── lib.rs
│ │ │ ├── tests.rs
│ │ │ └── weights.rs
│ ├── executive
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ └── lib.rs
│ ├── executor-registry
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ ├── benchmarking.rs
│ │ │ ├── lib.rs
│ │ │ ├── tests.rs
│ │ │ └── weights.rs
│ ├── messenger
│ │ ├── Cargo.toml
│ │ ├── README.md
│ │ └── src
│ │ │ ├── benchmarking.rs
│ │ │ ├── fees.rs
│ │ │ ├── lib.rs
│ │ │ ├── messages.rs
│ │ │ ├── mock.rs
│ │ │ ├── relayer.rs
│ │ │ ├── tests.rs
│ │ │ └── weights.rs
│ └── transporter
│ │ ├── Cargo.toml
│ │ ├── README.md
│ │ └── src
│ │ ├── benchmarking.rs
│ │ ├── lib.rs
│ │ ├── mock.rs
│ │ ├── tests.rs
│ │ └── weights.rs
├── primitives
│ ├── digests
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ └── lib.rs
│ ├── executor-registry
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ └── lib.rs
│ ├── messenger
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ ├── endpoint.rs
│ │ │ ├── lib.rs
│ │ │ ├── messages.rs
│ │ │ └── verification.rs
│ ├── runtime
│ │ ├── Cargo.toml
│ │ └── src
│ │ │ └── lib.rs
│ └── system-runtime
│ │ ├── Cargo.toml
│ │ └── src
│ │ └── lib.rs
├── runtime
│ ├── core-evm
│ │ ├── Cargo.toml
│ │ ├── build.rs
│ │ └── src
│ │ │ ├── lib.rs
│ │ │ ├── precompiles.rs
│ │ │ └── runtime.rs
│ └── system
│ │ ├── Cargo.toml
│ │ ├── build.rs
│ │ └── src
│ │ ├── lib.rs
│ │ └── runtime.rs
├── service
│ ├── Cargo.toml
│ ├── build.rs
│ └── src
│ │ ├── lib.rs
│ │ ├── providers.rs
│ │ ├── rpc.rs
│ │ ├── system_domain.rs
│ │ └── system_domain_tx_pre_validator.rs
└── test
│ ├── primitives
│ ├── Cargo.toml
│ └── src
│ │ └── lib.rs
│ ├── runtime
│ └── system
│ │ ├── Cargo.toml
│ │ ├── build.rs
│ │ └── src
│ │ ├── lib.rs
│ │ └── runtime.rs
│ └── service
│ ├── Cargo.toml
│ └── src
│ ├── chain_spec.rs
│ ├── lib.rs
│ └── system_domain.rs
├── frame-weight-template.hbs
├── orml
├── README.md
└── vesting
│ ├── Cargo.toml
│ ├── README.md
│ └── src
│ ├── default_weight.rs
│ ├── lib.rs
│ ├── mock.rs
│ ├── tests.rs
│ └── weights.rs
├── rust-toolchain.toml
├── rustfmt.toml
└── test
├── subspace-test-client
├── Cargo.toml
└── src
│ ├── chain_spec.rs
│ └── lib.rs
├── subspace-test-runtime
├── Cargo.toml
├── build.rs
└── src
│ └── lib.rs
└── subspace-test-service
├── Cargo.toml
└── src
└── lib.rs
/.dockerignore:
--------------------------------------------------------------------------------
1 | *
2 | !/crates
3 | !/domains
4 | !/orml
5 | !/test
6 | !/Cargo.lock
7 | !/Cargo.toml
8 | !/rust-toolchain.toml
9 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Order matters
2 | # below ones takes precedence over the upper ones
3 |
4 | # Global owners
5 | * @nazar-pc @rg3l3dr
6 |
7 | /crates @liuchengxu @nazar-pc @rg3l3dr
8 | /crates/pallet-* @liuchengxu @nazar-pc @rg3l3dr @vedhavyas
9 | /crates/sp-* @liuchengxu @nazar-pc @rg3l3dr @vedhavyas
10 | /crates/subspace-archiving @liuchengxu @i1i1 @nazar-pc @rg3l3dr
11 | /crates/subspace-farmer @i1i1 @nazar-pc @rg3l3dr
12 | /crates/subspace-networking @nazar-pc @rg3l3dr @shamil-gadelshin
13 | /crates/subspace-runtime* @liuchengxu @nazar-pc @rg3l3dr @vedhavyas
14 | /crates/subspace-solving @i1i1 @liuchengxu @nazar-pc @rg3l3dr
15 | /crates/substrate @nazar-pc @rg3l3dr
16 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: true
2 | contact_links:
3 | - name: Forum for general questions about Subspace
4 | url: https://forum.subspace.network
5 | about: |
6 | If you have a question about protocol or anything else that is not an engineering-level discussion or definitely a
7 | bug, please create a topic on the forum (better yet, search if similar question was already asked). GitHub issues
8 | are for developers.
9 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ### Code contributor checklist:
2 | * [ ] I have read, understood and followed [contributing guide](https://github.com/subspace/subspace/blob/main/CONTRIBUTING.md)
3 |
--------------------------------------------------------------------------------
/.github/workflows/Entitlements.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.apple.security.network.server
7 |
8 |
9 |
10 | com.apple.security.network.client
11 |
12 |
13 |
14 | com.apple.security.files.user-selected.read-write
15 |
16 |
17 |
18 | com.apple.security.cs.allow-unsigned-executable-memory
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.github/workflows/chain-spec-snapshot-build.yml:
--------------------------------------------------------------------------------
1 | # This action enabling building chain spec used in the node build, can be triggered manually or by release creation.
2 | #
3 | # Regular and raw chain specs are built both for releases and for manually triggered runs, uploaded to artifacts and
4 | # assets.
5 | name: Chain spec snapshot build
6 |
7 | on:
8 | workflow_dispatch:
9 | push:
10 | tags:
11 | - 'chain-spec-snapshot-*'
12 | - 'chain-spec-gemini-*'
13 |
14 | jobs:
15 | chains-spec:
16 | runs-on: ubuntu-22.04
17 | permissions:
18 | contents: write
19 | packages: write
20 |
21 | steps:
22 | - name: Build node image
23 | id: build
24 | uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # @v3.2.0
25 | with:
26 | file: Dockerfile-node
27 | push: false
28 |
29 | - name: Generate testnet chain specifications
30 | run: |
31 | docker run --rm -u root ${{ steps.build.outputs.digest }} build-spec --chain gemini-3d-compiled --disable-default-bootnode > chain-spec-gemini-3d.json
32 | docker run --rm -u root ${{ steps.build.outputs.digest }} build-spec --chain gemini-3d-compiled --disable-default-bootnode --raw > chain-spec-raw-gemini-3d.json
33 |
34 | - name: Upload chain specifications to artifacts
35 | uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # @v3.1.1
36 | with:
37 | name: chain-specifications
38 | path: |
39 | chain-spec-gemini-3d.json
40 | chain-spec-raw-gemini-3d.json
41 | if-no-files-found: error
42 |
43 | - name: Upload chain specifications to assets
44 | uses: alexellis/upload-assets@259de5111cb56966d046ced998941e93f91d2c93 # @0.4.0
45 | env:
46 | GITHUB_TOKEN: ${{ github.token }}
47 | with:
48 | asset_paths: '["chain-spec-gemini-3d.json", "chain-spec-raw-gemini-3d.json"]'
49 |
--------------------------------------------------------------------------------
/.github/workflows/runtime-snapshot-build.yml:
--------------------------------------------------------------------------------
1 | # This action enabling building WASM runtime used for forkless runtime upgrades, can be triggered manually or by
2 | # release creation.
3 | #
4 | # WASM bundles are built both for releases and for manually triggered runs, uploaded to artifacts and assets.
5 | name: Runtime snapshot build
6 |
7 | on:
8 | workflow_dispatch:
9 | push:
10 | tags:
11 | - 'runtime-snapshot-*'
12 | - 'runtime-gemini-*'
13 |
14 | jobs:
15 | runtime:
16 | runs-on: ubuntu-22.04
17 | permissions:
18 | contents: write
19 | packages: write
20 |
21 | steps:
22 | - name: Checkout
23 | uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # @v3.1.0
24 |
25 | - name: Build runtime
26 | id: build
27 | uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # @v3.2.0
28 | with:
29 | file: Dockerfile-runtime
30 | push: false
31 |
32 | - name: Extract runtime
33 | run: |
34 | SPEC_VERSION=$(sed -nr 's/.*spec_version: ([0-9]+),/\1/p' crates/subspace-runtime/src/lib.rs)
35 | docker run --rm -u root ${{ steps.build.outputs.digest }} > subspace_runtime-$SPEC_VERSION.compact.compressed.wasm
36 | echo "SPEC_VERSION=$SPEC_VERSION" >> $GITHUB_ENV
37 |
38 | - name: Upload runtime to artifacts
39 | uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # @v3.1.1
40 | with:
41 | name: subspace_runtime
42 | path: |
43 | subspace_runtime-${{ env.SPEC_VERSION }}.compact.compressed.wasm
44 | if-no-files-found: error
45 |
46 | - name: Upload runtime to assets
47 | uses: alexellis/upload-assets@259de5111cb56966d046ced998941e93f91d2c93 # @0.4.0
48 | env:
49 | GITHUB_TOKEN: ${{ github.token }}
50 | with:
51 | asset_paths: '["subspace_runtime-${{ env.SPEC_VERSION }}.compact.compressed.wasm"]'
52 | # Only run for releases
53 | if: github.event_name == 'push' && github.ref_type == 'tag'
54 |
--------------------------------------------------------------------------------
/.github/workflows/rustdoc.yml:
--------------------------------------------------------------------------------
1 | name: rustdoc
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 |
8 | concurrency:
9 | group: rustdoc-${{ github.workflow }}-${{ github.ref }}
10 | cancel-in-progress: true
11 |
12 | env:
13 | CARGO_INCREMENTAL: 0
14 | CARGO_NET_RETRY: 10
15 | RUSTUP_MAX_RETRIES: 10
16 |
17 | jobs:
18 | rustdoc:
19 | runs-on: ubuntu-22.04
20 |
21 | steps:
22 | - name: Checkout repository
23 | uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # @v3.1.0
24 |
25 | - name: Install Protoc
26 | uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # @v1.1.2
27 | with:
28 | repo-token: ${{ secrets.GITHUB_TOKEN }}
29 |
30 | # Build the rust crate docs
31 | - name: Build Documentation
32 | run: cargo doc --all --no-deps --lib
33 | env:
34 | RUSTDOCFLAGS: "-Z unstable-options --enable-index-page"
35 |
36 | - name: Deploy Docs
37 | uses: JamesIves/github-pages-deploy-action@ba1486788b0490a235422264426c45848eac35c6 # @v4.4.1
38 | with:
39 | branch: gh-pages
40 | folder: target/doc
41 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea
2 | /target
3 |
--------------------------------------------------------------------------------
/Dockerfile-bootstrap-node:
--------------------------------------------------------------------------------
1 | FROM ubuntu:20.04
2 |
3 | ARG RUSTC_VERSION=nightly-2023-05-16
4 | ARG PROFILE=production
5 | ARG RUSTFLAGS
6 | # Workaround for https://github.com/rust-lang/cargo/issues/10583
7 | ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
8 | # Incremental compilation here isn't helpful
9 | ENV CARGO_INCREMENTAL=0
10 |
11 | WORKDIR /code
12 |
13 | RUN \
14 | apt-get update && \
15 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
16 | ca-certificates \
17 | protobuf-compiler \
18 | curl \
19 | git \
20 | llvm \
21 | clang \
22 | cmake \
23 | make && \
24 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION
25 |
26 | RUN /root/.cargo/bin/rustup target add wasm32-unknown-unknown
27 |
28 | COPY Cargo.lock /code/Cargo.lock
29 | COPY Cargo.toml /code/Cargo.toml
30 | COPY rust-toolchain.toml /code/rust-toolchain.toml
31 |
32 | COPY crates /code/crates
33 | COPY domains /code/domains
34 | COPY orml /code/orml
35 | COPY test /code/test
36 |
37 | # Up until this line all Rust images in this repo should be the same to share the same layers
38 |
39 | RUN \
40 | /root/.cargo/bin/cargo build \
41 | --locked \
42 | -Z build-std \
43 | --profile $PROFILE \
44 | --bin subspace-bootstrap-node \
45 | --target $(uname -p)-unknown-linux-gnu && \
46 | mv target/*/*/subspace-bootstrap-node subspace-bootstrap-node && \
47 | rm -rf target
48 |
49 | FROM ubuntu:20.04
50 |
51 | COPY --from=0 /code/subspace-bootstrap-node /subspace-bootstrap-node
52 |
53 | USER nobody:nogroup
54 |
55 | ENTRYPOINT ["/subspace-bootstrap-node"]
56 |
--------------------------------------------------------------------------------
/Dockerfile-bootstrap-node.aarch64:
--------------------------------------------------------------------------------
1 | FROM ubuntu:20.04
2 |
3 | ARG RUSTC_VERSION=nightly-2023-05-16
4 | ARG PROFILE=production
5 | ARG RUSTFLAGS
6 | # Workaround for https://github.com/rust-lang/cargo/issues/10583
7 | ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
8 | # Incremental compilation here isn't helpful
9 | ENV CARGO_INCREMENTAL=0
10 |
11 | WORKDIR /code
12 |
13 | RUN \
14 | apt-get update && \
15 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
16 | ca-certificates \
17 | protobuf-compiler \
18 | curl \
19 | git \
20 | llvm \
21 | clang \
22 | cmake \
23 | make && \
24 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION
25 |
26 | RUN /root/.cargo/bin/rustup target add wasm32-unknown-unknown
27 |
28 | COPY Cargo.lock /code/Cargo.lock
29 | COPY Cargo.toml /code/Cargo.toml
30 | COPY rust-toolchain.toml /code/rust-toolchain.toml
31 |
32 | COPY crates /code/crates
33 | COPY domains /code/domains
34 | COPY orml /code/orml
35 | COPY test /code/test
36 |
37 | # Up until this line all Rust images in this repo should be the same to share the same layers
38 |
39 | ENV RUSTFLAGS="${RUSTFLAGS} -C linker=aarch64-linux-gnu-gcc"
40 |
41 | # Dependencies necessary for successful cross-compilation
42 | RUN \
43 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
44 | g++-aarch64-linux-gnu \
45 | gcc-aarch64-linux-gnu \
46 | libc6-dev-arm64-cross
47 |
48 | # TODO: Following package is not necessary on Ubuntu 22.04, but RocksDb compilation fails otherwise on Ubuntu 20.04
49 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends g++-9-multilib
50 |
51 | RUN \
52 | /root/.cargo/bin/cargo build \
53 | --locked \
54 | -Z build-std \
55 | --profile $PROFILE \
56 | --bin subspace-bootstrap-node \
57 | --target aarch64-unknown-linux-gnu && \
58 | mv target/*/*/subspace-bootstrap-node subspace-bootstrap-node && \
59 | rm -rf target
60 |
61 | FROM arm64v8/ubuntu:20.04
62 |
63 | COPY --from=0 /code/subspace-bootstrap-node /subspace-bootstrap-node
64 |
65 | USER nobody:nogroup
66 |
67 | ENTRYPOINT ["/subspace-bootstrap-node"]
68 |
--------------------------------------------------------------------------------
/Dockerfile-farmer:
--------------------------------------------------------------------------------
1 | FROM ubuntu:20.04
2 |
3 | ARG RUSTC_VERSION=nightly-2023-05-16
4 | ARG PROFILE=production
5 | ARG RUSTFLAGS
6 | # Workaround for https://github.com/rust-lang/cargo/issues/10583
7 | ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
8 | # Incremental compilation here isn't helpful
9 | ENV CARGO_INCREMENTAL=0
10 |
11 | WORKDIR /code
12 |
13 | RUN \
14 | apt-get update && \
15 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
16 | ca-certificates \
17 | protobuf-compiler \
18 | curl \
19 | git \
20 | llvm \
21 | clang \
22 | cmake \
23 | make && \
24 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION
25 |
26 | RUN /root/.cargo/bin/rustup target add wasm32-unknown-unknown
27 |
28 | COPY Cargo.lock /code/Cargo.lock
29 | COPY Cargo.toml /code/Cargo.toml
30 | COPY rust-toolchain.toml /code/rust-toolchain.toml
31 |
32 | COPY crates /code/crates
33 | COPY domains /code/domains
34 | COPY orml /code/orml
35 | COPY test /code/test
36 |
37 | # Up until this line all Rust images in this repo should be the same to share the same layers
38 |
39 | RUN \
40 | /root/.cargo/bin/cargo build \
41 | --locked \
42 | -Z build-std \
43 | --profile $PROFILE \
44 | --bin subspace-farmer \
45 | --target $(uname -p)-unknown-linux-gnu && \
46 | mv target/*/*/subspace-farmer subspace-farmer && \
47 | rm -rf target
48 |
49 | FROM ubuntu:20.04
50 |
51 | COPY --from=0 /code/subspace-farmer /subspace-farmer
52 |
53 | RUN mkdir /var/subspace && chown nobody:nogroup /var/subspace
54 |
55 | VOLUME /var/subspace
56 |
57 | USER nobody:nogroup
58 |
59 | ENTRYPOINT ["/subspace-farmer"]
60 |
--------------------------------------------------------------------------------
/Dockerfile-farmer.aarch64:
--------------------------------------------------------------------------------
1 | FROM ubuntu:20.04
2 |
3 | ARG RUSTC_VERSION=nightly-2023-05-16
4 | ARG PROFILE=production
5 | ARG RUSTFLAGS
6 | # Workaround for https://github.com/rust-lang/cargo/issues/10583
7 | ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
8 | # Incremental compilation here isn't helpful
9 | ENV CARGO_INCREMENTAL=0
10 |
11 | WORKDIR /code
12 |
13 | RUN \
14 | apt-get update && \
15 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
16 | ca-certificates \
17 | protobuf-compiler \
18 | curl \
19 | git \
20 | llvm \
21 | clang \
22 | cmake \
23 | make && \
24 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION
25 |
26 | RUN /root/.cargo/bin/rustup target add wasm32-unknown-unknown
27 |
28 | COPY Cargo.lock /code/Cargo.lock
29 | COPY Cargo.toml /code/Cargo.toml
30 | COPY rust-toolchain.toml /code/rust-toolchain.toml
31 |
32 | COPY crates /code/crates
33 | COPY domains /code/domains
34 | COPY orml /code/orml
35 | COPY test /code/test
36 |
37 | # Up until this line all Rust images in this repo should be the same to share the same layers
38 |
39 | ENV RUSTFLAGS="${RUSTFLAGS} -C linker=aarch64-linux-gnu-gcc"
40 |
41 | # Dependencies necessary for successful cross-compilation
42 | RUN \
43 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
44 | g++-aarch64-linux-gnu \
45 | gcc-aarch64-linux-gnu \
46 | libc6-dev-arm64-cross
47 |
48 | # TODO: Following package is not necessary on Ubuntu 22.04, but RocksDb compilation fails otherwise on Ubuntu 20.04
49 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends g++-9-multilib
50 |
51 | RUN \
52 | /root/.cargo/bin/cargo build \
53 | --locked \
54 | -Z build-std \
55 | --profile $PROFILE \
56 | --bin subspace-farmer \
57 | --target aarch64-unknown-linux-gnu && \
58 | mv target/*/*/subspace-farmer subspace-farmer && \
59 | rm -rf target
60 |
61 | FROM arm64v8/ubuntu:20.04
62 |
63 | COPY --from=0 /code/subspace-farmer /subspace-farmer
64 |
65 | RUN mkdir /var/subspace && chown nobody:nogroup /var/subspace
66 |
67 | VOLUME /var/subspace
68 |
69 | USER nobody:nogroup
70 |
71 | ENTRYPOINT ["/subspace-farmer"]
72 |
--------------------------------------------------------------------------------
/Dockerfile-node:
--------------------------------------------------------------------------------
1 | FROM ubuntu:20.04
2 |
3 | ARG RUSTC_VERSION=nightly-2023-05-16
4 | ARG PROFILE=production
5 | ARG RUSTFLAGS
6 | # Workaround for https://github.com/rust-lang/cargo/issues/10583
7 | ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
8 | # Incremental compilation here isn't helpful
9 | ENV CARGO_INCREMENTAL=0
10 |
11 | WORKDIR /code
12 |
13 | RUN \
14 | apt-get update && \
15 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
16 | ca-certificates \
17 | protobuf-compiler \
18 | curl \
19 | git \
20 | llvm \
21 | clang \
22 | cmake \
23 | make && \
24 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION
25 |
26 | RUN /root/.cargo/bin/rustup target add wasm32-unknown-unknown
27 |
28 | COPY Cargo.lock /code/Cargo.lock
29 | COPY Cargo.toml /code/Cargo.toml
30 | COPY rust-toolchain.toml /code/rust-toolchain.toml
31 |
32 | COPY crates /code/crates
33 | COPY domains /code/domains
34 | COPY orml /code/orml
35 | COPY test /code/test
36 |
37 | # Up until this line all Rust images in this repo should be the same to share the same layers
38 |
39 | ARG SUBSTRATE_CLI_GIT_COMMIT_HASH
40 |
41 | RUN \
42 | /root/.cargo/bin/cargo build \
43 | --locked \
44 | -Z build-std \
45 | --profile $PROFILE \
46 | --bin subspace-node \
47 | --target $(uname -p)-unknown-linux-gnu && \
48 | mv target/*/*/subspace-node subspace-node && \
49 | rm -rf target
50 |
51 | FROM ubuntu:20.04
52 |
53 | RUN \
54 | apt-get update && \
55 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates curl && \
56 | apt-get clean && \
57 | rm -rf /var/lib/apt/lists/*
58 |
59 | HEALTHCHECK CMD curl \
60 | -H "Content-Type: application/json" \
61 | -d '{ "id": 1, "jsonrpc": "2.0", "method": "system_health", "params": [] }' \
62 | -f "http://localhost:9933"
63 |
64 | COPY --from=0 /code/subspace-node /subspace-node
65 |
66 | RUN mkdir /var/subspace && chown nobody:nogroup /var/subspace
67 |
68 | VOLUME /var/subspace
69 |
70 | USER nobody:nogroup
71 |
72 | ENTRYPOINT ["/subspace-node"]
73 |
--------------------------------------------------------------------------------
/Dockerfile-node.aarch64:
--------------------------------------------------------------------------------
1 | FROM ubuntu:20.04
2 |
3 | ARG RUSTC_VERSION=nightly-2023-05-16
4 | ARG PROFILE=production
5 | ARG RUSTFLAGS
6 | # Workaround for https://github.com/rust-lang/cargo/issues/10583
7 | ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
8 | # Incremental compilation here isn't helpful
9 | ENV CARGO_INCREMENTAL=0
10 |
11 | WORKDIR /code
12 |
13 | RUN \
14 | apt-get update && \
15 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
16 | ca-certificates \
17 | protobuf-compiler \
18 | curl \
19 | git \
20 | llvm \
21 | clang \
22 | cmake \
23 | make && \
24 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION
25 |
26 | RUN /root/.cargo/bin/rustup target add wasm32-unknown-unknown
27 |
28 | COPY Cargo.lock /code/Cargo.lock
29 | COPY Cargo.toml /code/Cargo.toml
30 | COPY rust-toolchain.toml /code/rust-toolchain.toml
31 |
32 | COPY crates /code/crates
33 | COPY domains /code/domains
34 | COPY orml /code/orml
35 | COPY test /code/test
36 |
37 | # Up until this line all Rust images in this repo should be the same to share the same layers
38 |
39 | ENV RUSTFLAGS="${RUSTFLAGS} -C linker=aarch64-linux-gnu-gcc"
40 |
41 | # Dependencies necessary for successful cross-compilation
42 | RUN \
43 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
44 | g++-aarch64-linux-gnu \
45 | gcc-aarch64-linux-gnu \
46 | libc6-dev-arm64-cross
47 |
48 | RUN \
49 | /root/.cargo/bin/cargo build \
50 | --locked \
51 | -Z build-std \
52 | --profile $PROFILE \
53 | --bin subspace-node \
54 | --target aarch64-unknown-linux-gnu && \
55 | mv target/*/*/subspace-node subspace-node && \
56 | rm -rf target
57 |
58 | ARG SUBSTRATE_CLI_GIT_COMMIT_HASH
59 |
60 | FROM arm64v8/ubuntu:20.04
61 |
62 | RUN \
63 | apt-get update && \
64 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates curl && \
65 | apt-get clean && \
66 | rm -rf /var/lib/apt/lists/*
67 |
68 | HEALTHCHECK CMD curl \
69 | -H "Content-Type: application/json" \
70 | -d '{ "id": 1, "jsonrpc": "2.0", "method": "system_health", "params": [] }' \
71 | -f "http://localhost:9933"
72 |
73 | COPY --from=0 /code/subspace-node /subspace-node
74 |
75 | RUN mkdir /var/subspace && chown nobody:nogroup /var/subspace
76 |
77 | VOLUME /var/subspace
78 |
79 | USER nobody:nogroup
80 |
81 | ENTRYPOINT ["/subspace-node"]
82 |
--------------------------------------------------------------------------------
/Dockerfile-runtime:
--------------------------------------------------------------------------------
1 | FROM ubuntu:20.04
2 |
3 | ARG RUSTC_VERSION=nightly-2023-05-16
4 | ARG PROFILE=production
5 | ARG RUSTFLAGS
6 | # Workaround for https://github.com/rust-lang/cargo/issues/10583
7 | ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
8 | # Incremental compilation here isn't helpful
9 | ENV CARGO_INCREMENTAL=0
10 |
11 | WORKDIR /code
12 |
13 | RUN \
14 | apt-get update && \
15 | DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
16 | ca-certificates \
17 | curl \
18 | git \
19 | llvm \
20 | clang \
21 | cmake \
22 | make && \
23 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION
24 |
25 | RUN /root/.cargo/bin/rustup target add wasm32-unknown-unknown
26 |
27 | COPY Cargo.lock /code/Cargo.lock
28 | COPY Cargo.toml /code/Cargo.toml
29 | COPY rust-toolchain.toml /code/rust-toolchain.toml
30 |
31 | COPY crates /code/crates
32 | COPY domains /code/domains
33 | COPY orml /code/orml
34 | COPY test /code/test
35 |
36 | # Up until this line all Rust images in this repo should be the same to share the same layers
37 |
38 | # TODO: Re-enable cost of storage in future
39 | RUN \
40 | /root/.cargo/bin/cargo build \
41 | --locked \
42 | -Z build-std \
43 | --profile $PROFILE \
44 | --package subspace-runtime \
45 | --features=subspace-runtime/do-not-enforce-cost-of-storage \
46 | --target x86_64-unknown-linux-gnu && \
47 | mv \
48 | target/*/*/wbuild/subspace-runtime/subspace_runtime.compact.compressed.wasm \
49 | subspace_runtime.compact.compressed.wasm && \
50 | rm -rf target
51 |
52 | ENTRYPOINT ["/usr/bin/cat", "subspace_runtime.compact.compressed.wasm"]
53 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Subspace Network Monorepo
2 |
3 | [](https://github.com/subspace/subspace/releases)
4 | [](https://github.com/subspace/subspace/releases/latest)
5 | [](https://github.com/subspace/subspace/actions/workflows/rust.yaml)
6 | [](https://subspace.github.io/subspace)
7 |
8 | This is a mono repository for [Subspace Network](https://subspace.network/) implementation, primarily containing
9 | Subspace node/client using Substrate framework and farmer app implementations.
10 |
11 | ## Repository structure
12 |
13 | The structure of this repository is the following:
14 |
15 | - `crates` contains Subspace-specific Rust crates used to build node and farmer, most are following Substrate naming conventions
16 | - `subspace-node` is an implementation of the node for Subspace protocol
17 | - `subspace-farmer` is a CLI farmer app
18 | - `domains` contains client and runtime code for decoupled execution and domains
19 | - `orml` contains a fork of orml vesting pallet with modified dependencies
20 |
21 | ## How to run
22 |
23 | Please refer to [farming.md](/docs/farming.md) on how to run farmer.
24 |
25 | If you are looking to farm offline, or build from source for development purposes please refer to [development.md](/docs/development.md).
26 |
--------------------------------------------------------------------------------
/crates/pallet-feeds/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "pallet-feeds"
3 | version = "0.1.0"
4 | authors = ["Serge Kovbasiuk "]
5 | edition = "2021"
6 | license = "Apache-2.0"
7 | homepage = "https://subspace.network"
8 | repository = "https://github.com/subspace/subspace"
9 | description = "Subspace node pallet for interacting with storage"
10 | readme = "README.md"
11 |
12 | [package.metadata.docs.rs]
13 | targets = ["x86_64-unknown-linux-gnu"]
14 |
15 | [dependencies]
16 | codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] }
17 | frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
18 | frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
19 | log = { version = "0.4.19", default-features = false }
20 | scale-info = { version = "2.7.0", default-features = false, features = ["derive"] }
21 | sp-core = { version = "21.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
22 | sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
23 | sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
24 | subspace-core-primitives = { version = "0.1.0", default-features = false, path = "../subspace-core-primitives" }
25 |
26 | [dev-dependencies]
27 | serde = "1.0.159"
28 | sp-io = { version = "23.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
29 |
30 | [features]
31 | default = ["std"]
32 | std = [
33 | "codec/std",
34 | "frame-support/std",
35 | "frame-system/std",
36 | "log/std",
37 | "scale-info/std",
38 | "sp-core/std",
39 | "sp-runtime/std",
40 | "sp-std/std",
41 | "subspace-core-primitives/std",
42 | ]
43 | try-runtime = ["frame-support/try-runtime"]
44 |
--------------------------------------------------------------------------------
/crates/pallet-feeds/README.md:
--------------------------------------------------------------------------------
1 | # Pallet Feeds
2 |
3 | License: Apache-2.0
4 |
5 | Pallet feeds provides the interactions with Subspace storage. The main design goal for Feeds is not only to push objects
6 | to the Storage but also to provide a way for the for feed owners to inject some verification logic through `FeedProcessor`
7 | impls.
8 |
9 | ## Calls
10 |
11 | The pallet provides following calls.
12 | 1. Create(permissionless): Creates a new Feed for the caller
13 | 2. Update: Updates the Feeds with some initial data. All the underlying FeedProcessors
14 | will be reinitialized.
15 | 3. Transfer: Transfers a feed from one owner to another
16 | 4. Close: Closes the feed and doesn't accept any new objects
17 | 5. Put: Puts a new object in the Feed. The object is passed to FeedProcessor for verification if any.
18 |
19 |
--------------------------------------------------------------------------------
/crates/pallet-grandpa-finality-verifier/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "pallet-grandpa-finality-verifier"
3 | version = "0.1.0"
4 | authors = ["Vedhavyas Singareddi "]
5 | edition = "2021"
6 | license = "Apache-2.0"
7 | homepage = "https://subspace.network"
8 | repository = "https://github.com/subspace/subspace"
9 | description = "Pallet to verify GRANDPA finality proofs for Substrate based chains"
10 | readme = "README.md"
11 |
12 | [dependencies]
13 | codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false }
14 | finality-grandpa = { version = "0.16.1", default-features = false }
15 | log = { version = "0.4.19", default-features = false }
16 | num-traits = { version = "0.2.15", default-features = false }
17 | scale-info = { version = "2.7.0", default-features = false, features = ["derive"] }
18 | serde = { version = "1.0.159", optional = true }
19 |
20 | # Substrate Dependencies
21 |
22 | frame-support = { git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f", default-features = false }
23 | frame-system = { git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f", default-features = false }
24 | sp-consensus-grandpa = { git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f", default-features = false }
25 | sp-core = { git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f", default-features = false }
26 | sp-runtime = { git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f", default-features = false }
27 | sp-std = { git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f", default-features = false }
28 | sp-trie = { git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f", default-features = false }
29 |
30 | [dev-dependencies]
31 | ed25519-dalek = { version = "1.0", default-features = false, features = ["u64_backend"] }
32 | sp-io = { git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
33 | sp-application-crypto = { git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
34 |
35 | [features]
36 | default = ["std"]
37 | std = [
38 | "codec/std",
39 | "finality-grandpa/std",
40 | "frame-support/std",
41 | "frame-system/std",
42 | "log/std",
43 | "num-traits/std",
44 | "scale-info/std",
45 | "serde",
46 | "sp-consensus-grandpa/std",
47 | "sp-core/std",
48 | "sp-runtime/std",
49 | "sp-std/std",
50 | "sp-trie/std",
51 | ]
52 |
--------------------------------------------------------------------------------
/crates/pallet-grandpa-finality-verifier/README.md:
--------------------------------------------------------------------------------
1 | # pallet-grandpa-finality-verifier
2 | License: Apache-2.0
3 |
4 | GRANDPA finality verifier is used to verify the justifications provided within the substrate based Blocks indexing them on our DSN.
5 |
6 | The pallet provides the following functionality
7 | - provides a basic abstraction over any substrate based chains through `Chain` trait.
8 | - decodes the block and its components.
9 | - verifies the blocks and its justifications using the current authority set the block was produced in
10 | - imports any authority set changes from the header after the verification
11 |
12 | This pallet does not
13 | - verifies or recognizes the forks. So this is left for the admin to reinitialize the chain state after the fork
14 |
--------------------------------------------------------------------------------
/crates/pallet-grandpa-finality-verifier/src/tests/mock.rs:
--------------------------------------------------------------------------------
1 | use frame_support::weights::Weight;
2 | use frame_support::{construct_runtime, parameter_types};
3 | use sp_runtime::testing::{Header, H256};
4 | use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
5 | use sp_runtime::Perbill;
6 |
7 | type AccountId = u64;
8 | pub(crate) type ChainId = u64;
9 | type Block = frame_system::mocking::MockBlock;
10 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
11 |
12 | use crate as grandpa;
13 |
14 | construct_runtime! {
15 | pub struct TestRuntime where
16 | Block = Block,
17 | NodeBlock = Block,
18 | UncheckedExtrinsic = UncheckedExtrinsic,
19 | {
20 | System: frame_system::{Pallet, Call, Config, Storage, Event},
21 | Grandpa: grandpa::{Pallet},
22 | }
23 | }
24 |
25 | parameter_types! {
26 | pub const BlockHashCount: u64 = 250;
27 | pub const MaximumBlockWeight: Weight = Weight::from_parts(1024, 0);
28 | pub const MaximumBlockLength: u32 = 2 * 1024;
29 | pub const AvailableBlockRatio: Perbill = Perbill::one();
30 | }
31 |
32 | impl frame_system::Config for TestRuntime {
33 | type RuntimeOrigin = RuntimeOrigin;
34 | type Index = u64;
35 | type RuntimeCall = RuntimeCall;
36 | type BlockNumber = u64;
37 | type Hash = H256;
38 | type Hashing = BlakeTwo256;
39 | type AccountId = AccountId;
40 | type Lookup = IdentityLookup;
41 | type Header = Header;
42 | type RuntimeEvent = ();
43 | type BlockHashCount = BlockHashCount;
44 | type Version = ();
45 | type PalletInfo = PalletInfo;
46 | type AccountData = ();
47 | type OnNewAccount = ();
48 | type OnKilledAccount = ();
49 | type BaseCallFilter = frame_support::traits::Everything;
50 | type SystemWeightInfo = ();
51 | type DbWeight = ();
52 | type BlockWeights = ();
53 | type BlockLength = ();
54 | type SS58Prefix = ();
55 | type OnSetCode = ();
56 | type MaxConsumers = frame_support::traits::ConstU32<16>;
57 | }
58 |
59 | impl grandpa::Config for TestRuntime {
60 | type ChainId = ChainId;
61 | }
62 |
63 | pub fn run_test(test: impl FnOnce() -> T) -> T {
64 | sp_io::TestExternalities::new(Default::default()).execute_with(test)
65 | }
66 |
--------------------------------------------------------------------------------
/crates/pallet-object-store/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "pallet-object-store"
3 | version = "0.1.0"
4 | authors = ["Nazar Mokrynskyi "]
5 | edition = "2021"
6 | license = "Apache-2.0"
7 | homepage = "https://subspace.network"
8 | repository = "https://github.com/subspace/subspace"
9 | description = "Subspace node pallet for simple objects storage"
10 | readme = "README.md"
11 |
12 | [package.metadata.docs.rs]
13 | targets = ["x86_64-unknown-linux-gnu"]
14 |
15 | [dependencies]
16 | codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] }
17 | frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
18 | frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
19 | hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
20 | log = { version = "0.4.19", default-features = false }
21 | scale-info = { version = "2.7.0", default-features = false, features = ["derive"] }
22 | sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
23 | subspace-core-primitives = { version = "0.1.0", default-features = false, path = "../subspace-core-primitives" }
24 |
25 | [dev-dependencies]
26 | serde = "1.0.159"
27 | sp-core = { version = "21.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
28 | sp-io = { version = "23.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
29 | sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
30 |
31 | [features]
32 | default = ["std"]
33 | std = [
34 | "codec/std",
35 | "frame-support/std",
36 | "frame-system/std",
37 | "hex/std",
38 | "log/std",
39 | "scale-info/std",
40 | "sp-std/std",
41 | "subspace-core-primitives/std",
42 | ]
43 | try-runtime = ["frame-support/try-runtime"]
44 |
--------------------------------------------------------------------------------
/crates/pallet-object-store/README.md:
--------------------------------------------------------------------------------
1 | # Pallet Object Store
2 |
3 | Subspace node pallet for simple objects storage
4 |
5 | License: Apache-2.0
6 |
--------------------------------------------------------------------------------
/crates/pallet-object-store/src/mock.rs:
--------------------------------------------------------------------------------
1 | use frame_support::parameter_types;
2 | use frame_support::traits::{ConstU16, ConstU32, ConstU64};
3 | use sp_core::H256;
4 | use sp_runtime::testing::Header;
5 | use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
6 |
7 | type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
8 | type Block = frame_system::mocking::MockBlock;
9 |
10 | frame_support::construct_runtime!(
11 | pub struct Test where
12 | Block = Block,
13 | NodeBlock = Block,
14 | UncheckedExtrinsic = UncheckedExtrinsic,
15 | {
16 | System: frame_system::{Pallet, Call, Config, Storage, Event},
17 | ObjectStore: crate::{Pallet, Call, Event}
18 | }
19 | );
20 |
21 | impl frame_system::Config for Test {
22 | type BaseCallFilter = frame_support::traits::Everything;
23 | type BlockWeights = ();
24 | type BlockLength = ();
25 | type DbWeight = ();
26 | type RuntimeOrigin = RuntimeOrigin;
27 | type RuntimeCall = RuntimeCall;
28 | type Index = u64;
29 | type BlockNumber = u64;
30 | type Hash = H256;
31 | type Hashing = BlakeTwo256;
32 | type AccountId = u64;
33 | type Lookup = IdentityLookup;
34 | type Header = Header;
35 | type RuntimeEvent = RuntimeEvent;
36 | type BlockHashCount = ConstU64<250>;
37 | type Version = ();
38 | type PalletInfo = PalletInfo;
39 | type AccountData = ();
40 | type OnNewAccount = ();
41 | type OnKilledAccount = ();
42 | type SystemWeightInfo = ();
43 | type SS58Prefix = ConstU16<42>;
44 | type OnSetCode = ();
45 | type MaxConsumers = ConstU32<16>;
46 | }
47 |
48 | parameter_types! {
49 | pub const ExistentialDeposit: u64 = 1;
50 | }
51 |
52 | impl crate::Config for Test {
53 | type RuntimeEvent = RuntimeEvent;
54 | }
55 |
56 | pub fn new_test_ext() -> sp_io::TestExternalities {
57 | let t = frame_system::GenesisConfig::default()
58 | .build_storage::()
59 | .unwrap();
60 |
61 | let mut t: sp_io::TestExternalities = t.into();
62 |
63 | t.execute_with(|| System::set_block_number(1));
64 |
65 | t
66 | }
67 |
--------------------------------------------------------------------------------
/crates/pallet-object-store/src/tests.rs:
--------------------------------------------------------------------------------
1 | use crate::mock::{new_test_ext, ObjectStore, RuntimeEvent, RuntimeOrigin, System, Test};
2 | use frame_support::assert_ok;
3 | use subspace_core_primitives::crypto;
4 |
5 | const ACCOUNT_ID: u64 = 100;
6 |
7 | #[test]
8 | fn can_do_put() {
9 | new_test_ext().execute_with(|| {
10 | let object = vec![1, 2, 3, 4, 5];
11 | let object_id = crypto::blake2b_256_hash(&object);
12 | let object_size = object.len() as u32;
13 |
14 | assert_ok!(ObjectStore::put(RuntimeOrigin::signed(ACCOUNT_ID), object));
15 |
16 | System::assert_last_event(RuntimeEvent::ObjectStore(
17 | crate::Event::::ObjectSubmitted {
18 | who: ACCOUNT_ID,
19 | object_id,
20 | object_size,
21 | },
22 | ));
23 | });
24 | }
25 |
--------------------------------------------------------------------------------
/crates/pallet-offences-subspace/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "pallet-offences-subspace"
3 | version = "0.1.0"
4 | authors = ["Parity Technologies ", "Subspace Labs "]
5 | edition = "2021"
6 | license = "Apache-2.0"
7 | homepage = "https://subspace.network"
8 | repository = "https://github.com/subspace/subspace"
9 | description = "offences-subspace pallet"
10 | readme = "README.md"
11 |
12 | [package.metadata.docs.rs]
13 | targets = ["x86_64-unknown-linux-gnu"]
14 |
15 | [dependencies]
16 | codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] }
17 | frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
18 | frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
19 | log = { version = "0.4.19", default-features = false }
20 | scale-info = { version = "2.7.0", default-features = false, features = ["derive"] }
21 | sp-consensus-subspace = { version = "0.1.0", default-features = false, path = "../sp-consensus-subspace" }
22 | sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
23 | sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
24 |
25 | [dev-dependencies]
26 | sp-io = { version = "23.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
27 | sp-core = { version = "21.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
28 | schnorrkel = "0.9.1"
29 |
30 | [features]
31 | default = ["std"]
32 | std = [
33 | "codec/std",
34 | "frame-support/std",
35 | "frame-system/std",
36 | "log/std",
37 | "scale-info/std",
38 | "sp-consensus-subspace/std",
39 | "sp-runtime/std",
40 | "sp-std/std",
41 | ]
42 | try-runtime = ["frame-support/try-runtime"]
43 |
--------------------------------------------------------------------------------
/crates/pallet-offences-subspace/README.md:
--------------------------------------------------------------------------------
1 | # Offences Module (Subspace variant)
2 |
3 | Tracks reported offences
4 |
5 | License: Apache-2.0
6 |
--------------------------------------------------------------------------------
/crates/pallet-rewards/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "pallet-rewards"
3 | version = "0.1.0"
4 | authors = ["Nazar Mokrynskyi "]
5 | edition = "2021"
6 | license = "Apache-2.0"
7 | homepage = "https://subspace.network"
8 | repository = "https://github.com/subspace/subspace"
9 | description = "Pallet for issuing rewards to block producers"
10 | readme = "README.md"
11 | include = [
12 | "/src",
13 | "/Cargo.toml",
14 | "/README.md",
15 | ]
16 |
17 | [package.metadata.docs.rs]
18 | targets = ["x86_64-unknown-linux-gnu"]
19 |
20 | [dependencies]
21 | codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] }
22 | frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
23 | frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
24 | scale-info = { version = "2.7.0", default-features = false, features = ["derive"] }
25 | sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
26 | subspace-runtime-primitives = { version = "0.1.0", default-features = false, path = "../subspace-runtime-primitives" }
27 |
28 | [features]
29 | default = ["std"]
30 | std = [
31 | "codec/std",
32 | "frame-support/std",
33 | "frame-system/std",
34 | "scale-info/std",
35 | "sp-std/std",
36 | "subspace-runtime-primitives/std",
37 | ]
38 | try-runtime = ["frame-support/try-runtime"]
39 |
--------------------------------------------------------------------------------
/crates/pallet-rewards/README.md:
--------------------------------------------------------------------------------
1 | # Pallet Rewards
2 |
3 | Pallet for issuing rewards to block producers.
4 |
5 | License: Apache-2.0
6 |
--------------------------------------------------------------------------------
/crates/pallet-rewards/src/default_weights.rs:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2021 Subspace Labs, Inc.
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 |
16 | //! Default weights for the Rewards Pallet
17 | //! This file was not auto-generated.
18 |
19 | use frame_support::weights::Weight;
20 |
21 | impl crate::WeightInfo for () {
22 | fn on_initialize() -> Weight {
23 | // TODO: Correct value
24 | Weight::from_parts(1, 0)
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/crates/pallet-runtime-configs/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "pallet-runtime-configs"
3 | version = "0.1.0"
4 | authors = ["Liu-Cheng Xu "]
5 | edition = "2021"
6 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
7 | homepage = "https://subspace.network"
8 | repository = "https://github.com/subspace/subspace"
9 | description = "Pallet for tweaking the runtime configs for multiple network"
10 | include = [
11 | "/src",
12 | "/Cargo.toml",
13 | ]
14 |
15 | [package.metadata.docs.rs]
16 | targets = ["x86_64-unknown-linux-gnu"]
17 |
18 | [dependencies]
19 | codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] }
20 | frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
21 | frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
22 | scale-info = { version = "2.7.0", default-features = false, features = ["derive"] }
23 | sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
24 |
25 | [features]
26 | default = ["std"]
27 | std = [
28 | "codec/std",
29 | "frame-support/std",
30 | "frame-system/std",
31 | "scale-info/std",
32 | "sp-runtime/std",
33 | ]
34 | try-runtime = ["frame-support/try-runtime"]
35 |
--------------------------------------------------------------------------------
/crates/pallet-settlement/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "pallet-settlement"
3 | version = "0.1.0"
4 | authors = ["Subspace Labs "]
5 | edition = "2021"
6 | license = "Apache-2.0"
7 | homepage = "https://subspace.network"
8 | repository = "https://github.com/subspace/subspace"
9 | description = "Subspace receipts pallet"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] }
16 | frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
17 | frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
18 | log = { version = "0.4.19", default-features = false }
19 | scale-info = { version = "2.7.0", default-features = false, features = ["derive"] }
20 | sp-core = { version = "21.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
21 | sp-domains = { version = "0.1.0", default-features = false, path = "../sp-domains" }
22 | sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
23 | sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
24 |
25 | [features]
26 | default = ["std"]
27 | std = [
28 | "frame-support/std",
29 | "frame-system/std",
30 | "log/std",
31 | "sp-core/std",
32 | "sp-domains/std",
33 | "sp-runtime/std",
34 | "sp-std/std",
35 | ]
36 | try-runtime = ["frame-support/try-runtime"]
37 |
--------------------------------------------------------------------------------
/crates/pallet-subspace/README.md:
--------------------------------------------------------------------------------
1 | Subspace consensus pallet.
2 |
3 | This pallet is in many ways complementary to `sc-consensus-subspace`.
4 |
5 | Pallet maintains crucial state required for Subspace Proof-of-Archival-Storage consensus:
6 | * global randomness
7 | * based on c-correlation from
8 | * is used to later derive together with time slot a global challenge
9 | * solution range, which is a range of valid solution for Proof-of-Archival-Storage puzzle
10 | * conceptually similar to work difficulty in Proof-of-Work consensus
11 | * is updated every Era
12 | * inherents for:
13 | * storing segment headers and maintaining mapping from segment index to corresponding segment commitment such that
14 | validity of piece from solution can be checked later
15 | * handling of farmer equivocation (together with `pallet-offences-subspace`) and maintaining list of blocked farmers
16 | (effectively burned plots)
17 |
18 | Pallet also provides handy API for finding block author, block reward address, randomness and some others.
19 |
20 | License: Apache-2.0
21 |
--------------------------------------------------------------------------------
/crates/pallet-transaction-fees/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "pallet-transaction-fees"
3 | version = "0.1.0"
4 | authors = ["Nazar Mokrynskyi "]
5 | edition = "2021"
6 | license = "Apache-2.0"
7 | homepage = "https://subspace.network"
8 | repository = "https://github.com/subspace/subspace"
9 | description = "Pallet for charging and re-distributing transaction fees"
10 | readme = "README.md"
11 | include = [
12 | "/src",
13 | "/Cargo.toml",
14 | "/README.md",
15 | ]
16 |
17 | [package.metadata.docs.rs]
18 | targets = ["x86_64-unknown-linux-gnu"]
19 |
20 | [dependencies]
21 | codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] }
22 | frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
23 | frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
24 | scale-info = { version = "2.7.0", default-features = false, features = ["derive"] }
25 | subspace-runtime-primitives = { version = "0.1.0", default-features = false, path = "../subspace-runtime-primitives" }
26 |
27 | [features]
28 | default = ["std"]
29 | std = [
30 | "codec/std",
31 | "frame-support/std",
32 | "frame-system/std",
33 | "scale-info/std",
34 | "subspace-runtime-primitives/std",
35 | ]
36 | try-runtime = ["frame-support/try-runtime"]
37 |
--------------------------------------------------------------------------------
/crates/pallet-transaction-fees/README.md:
--------------------------------------------------------------------------------
1 | # Pallet Transaction Fees
2 |
3 | Pallet for charging and re-distributing transaction fees.
4 |
5 | License: Apache-2.0
6 |
--------------------------------------------------------------------------------
/crates/pallet-transaction-fees/src/default_weights.rs:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2021 Subspace Labs, Inc.
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 |
16 | //! Default weights for the Rewards Pallet
17 | //! This file was not auto-generated.
18 |
19 | use frame_support::weights::Weight;
20 |
21 | impl crate::WeightInfo for () {
22 | fn on_initialize() -> Weight {
23 | // TODO: Correct value
24 | Weight::from_parts(1, 0)
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/crates/sc-consensus-fraud-proof/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "sc-consensus-fraud-proof"
3 | description = "Subspace fraud proof verification in consensus"
4 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
5 | version = "0.1.0"
6 | authors = ["Liu-Cheng Xu "]
7 | edition = "2021"
8 | include = [
9 | "/src",
10 | "/Cargo.toml",
11 | ]
12 |
13 | [dependencies]
14 | async-trait = "0.1.68"
15 | codec = { package = "parity-scale-codec", version = "3.4.0", features = ["derive"] }
16 | sc-consensus = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
17 | sp-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
18 | sp-consensus = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
19 | sp-domains = { version = "0.1.0", path = "../sp-domains" }
20 | sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
21 | sp-settlement = { version = "0.1.0", path = "../sp-settlement" }
22 | subspace-fraud-proof = { version = "0.1.0", path = "../subspace-fraud-proof" }
23 |
--------------------------------------------------------------------------------
/crates/sc-consensus-subspace-rpc/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "sc-consensus-subspace-rpc"
3 | version = "0.1.0"
4 | authors = ["Parity Technologies ", "Subspace Labs "]
5 | description = "RPC extensions for the Subspace consensus algorithm"
6 | edition = "2021"
7 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
8 | homepage = "https://subspace.network"
9 | repository = "https://github.com/subspace/subspace"
10 | readme = "README.md"
11 |
12 | [package.metadata.docs.rs]
13 | targets = ["x86_64-unknown-linux-gnu"]
14 |
15 | [dependencies]
16 | async-oneshot = "0.5.0"
17 | futures = "0.3.28"
18 | futures-timer = "3.0.2"
19 | jsonrpsee = { version = "0.16.2", features = ["server", "macros"] }
20 | parity-scale-codec = "3.4.0"
21 | parking_lot = "0.12.1"
22 | sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
23 | sc-consensus-subspace = { version = "0.1.0", path = "../sc-consensus-subspace" }
24 | sc-rpc = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
25 | sc-utils = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
26 | sp-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
27 | sp-consensus-subspace = { version = "0.1.0", path = "../sp-consensus-subspace" }
28 | sp-consensus-slots = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
29 | sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
30 | sp-core = { version = "21.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
31 | sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
32 | subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" }
33 | subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
34 | subspace-farmer-components = { version = "0.1.0", path = "../subspace-farmer-components" }
35 | subspace-networking = { version = "0.1.0", path = "../subspace-networking" }
36 | subspace-rpc-primitives = { version = "0.1.0", path = "../subspace-rpc-primitives" }
37 | tracing = "0.1.37"
38 |
--------------------------------------------------------------------------------
/crates/sc-consensus-subspace-rpc/README.md:
--------------------------------------------------------------------------------
1 | RPC api for Subspace Consensus.
2 |
3 | License: GPL-3.0-or-later WITH Classpath-exception-2.0
4 |
--------------------------------------------------------------------------------
/crates/sc-consensus-subspace/README.md:
--------------------------------------------------------------------------------
1 | # Subspace Proof-of-Archival-Storage consensus
2 |
3 | Subspace is a slot-based block production mechanism which uses a Proof-of-Archival-Storage to randomly perform the slot
4 | allocation. On every slot, all the farmers evaluate their disk-based plot. If they have a tag (reflecting a commitment
5 | to a valid encoding) that it is lower than a given threshold (which is proportional to the total space pledged by the
6 | network) they may produce a new block.
7 |
8 | Core inputs to the Proof-of-Archival-Storage, such as global randomness and solution range come from the runtime,
9 | see `pallet-subspace` for details.
10 |
11 | The fork choice rule is weight-based, where weight is derived from the distance between solution proposed in a block and
12 | the local challenge for particular farmer. The heaviest chain (represents a chain with more storage pledged to it)
13 | will be preferred over alternatives or longest chain is in case of a tie.
14 |
15 | For a more in-depth analysis of Subspace consensus can be found in our
16 | [consensus whitepaper](https://subspace.network/news/subspace-network-whitepaper).
17 |
18 | This crate contains following major components:
19 | * worker (`sc-consensus-slots`) for claiming slots (block production)
20 | * block verifier that stateless verification of signature and Proof-of-Space
21 | * block import that verifies Proof-of-Archival-Storage and triggers archiving of the history
22 | * archiver worker triggered by block import that ensures history is archived and segment headers are produced at precisely
23 | the right time before finishing block import
24 |
25 | License: GPL-3.0-or-later WITH Classpath-exception-2.0
26 |
--------------------------------------------------------------------------------
/crates/sc-subspace-block-relay/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "sc-subspace-block-relay"
3 | description = "Block relay implementation"
4 | license = "MIT OR Apache-2.0"
5 | version = "0.1.0"
6 | authors = ["Rahul Subramaniyam "]
7 | edition = "2021"
8 | include = [
9 | "/src",
10 | "/Cargo.toml",
11 | ]
12 |
13 | [dependencies]
14 | async-channel = "1.8.0"
15 | async-trait = "0.1.68"
16 | codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] }
17 | futures = "0.3.28"
18 | lru = "0.10.0"
19 | parking_lot = "0.12.1"
20 | sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
21 | sc-network = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
22 | sc-network-common = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
23 | sc-network-sync = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
24 | sc-service = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f", default-features = false }
25 | sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
26 | sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
27 | thiserror = "1.0.38"
28 | tracing = "0.1.37"
29 |
30 |
--------------------------------------------------------------------------------
/crates/sc-subspace-block-relay/src/protocol.rs:
--------------------------------------------------------------------------------
1 | pub(crate) mod compact_block;
2 |
--------------------------------------------------------------------------------
/crates/sc-subspace-chain-specs/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "sc-subspace-chain-specs"
3 | description = "Chain specification data structures tailored for Subspace"
4 | license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
5 | version = "0.1.0"
6 | authors = ["Nazar Mokrynskyi "]
7 | edition = "2021"
8 | include = [
9 | "/src",
10 | "/Cargo.toml",
11 | "/README.md",
12 | ]
13 |
14 | [dependencies]
15 | sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
16 | sc-service = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f", default-features = false }
17 | sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
18 | serde = "1.0.159"
19 | sp-core = { version = "21.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
20 | sp-runtime = { version = "24.0.0", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
21 |
--------------------------------------------------------------------------------
/crates/sc-subspace-chain-specs/src/lib.rs:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2021 Subspace Labs, Inc.
2 | // SPDX-License-Identifier: GPL-3.0-or-later
3 |
4 | // This program is free software: you can redistribute it and/or modify
5 | // it under the terms of the GNU General Public License as published by
6 | // the Free Software Foundation, either version 3 of the License, or
7 | // (at your option) any later version.
8 |
9 | // This program is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 |
14 | // You should have received a copy of the GNU General Public License
15 | // along with this program. If not, see .
16 |
17 | //! Chain specification data structures tailored for Subspace.
18 |
19 | mod utils;
20 |
21 | pub use utils::SerializableChainSpec;
22 |
23 | use sc_chain_spec::{ChainSpecExtension, NoExtension, RuntimeGenesis};
24 | use sc_service::ChainSpecExtension;
25 | use serde::de::DeserializeOwned;
26 | use serde::{Deserialize, Serialize};
27 |
28 | /// The extensions for the [`ConsensusChainSpec`].
29 | #[derive(Serialize, Deserialize, ChainSpecExtension)]
30 | #[serde(deny_unknown_fields, rename_all = "camelCase")]
31 | #[serde(bound = "")]
32 | pub struct ChainSpecExtensions
33 | where
34 | ExecutionGenesisConfig: RuntimeGenesis + 'static,
35 | Extensions: ChainSpecExtension + DeserializeOwned + Clone + Send + Sync + 'static,
36 | {
37 | /// Chain spec of execution chain.
38 | pub execution_chain_spec: ExecutionChainSpec,
39 | }
40 |
41 | impl Clone
42 | for ChainSpecExtensions
43 | where
44 | ExecutionGenesisConfig: RuntimeGenesis + 'static,
45 | Extensions: ChainSpecExtension + DeserializeOwned + Clone + Send + Sync + 'static,
46 | {
47 | fn clone(&self) -> Self {
48 | Self {
49 | execution_chain_spec: self.execution_chain_spec.clone(),
50 | }
51 | }
52 | }
53 |
54 | /// Specialized `ChainSpec` for the consensus runtime.
55 | pub type ConsensusChainSpec =
56 | SerializableChainSpec>;
57 |
58 | /// Specialized `ChainSpec` for the execution runtime.
59 | pub type ExecutionChainSpec =
60 | SerializableChainSpec;
61 |
--------------------------------------------------------------------------------
/crates/sp-consensus-subspace/README.md:
--------------------------------------------------------------------------------
1 | Primitives for Subspace Consensus. Based on a fork of `sp_consensus_babe`
2 |
3 | License: Apache-2.0
4 |
--------------------------------------------------------------------------------
/crates/sp-domains/src/merkle_tree.rs:
--------------------------------------------------------------------------------
1 | use crate::ExecutorPublicKey;
2 | use blake2::digest::typenum::U32;
3 | use blake2::digest::FixedOutput;
4 | use blake2::{Blake2b, Digest};
5 | use parity_scale_codec::{Decode, Encode};
6 | use rs_merkle::Hasher;
7 | use scale_info::TypeInfo;
8 | use sp_runtime::traits::{BlakeTwo256, Hash};
9 | use sp_std::vec::Vec;
10 | use subspace_core_primitives::Blake2b256Hash;
11 |
12 | /// Merkle tree using [`Blake2b256Algorithm`].
13 | pub type MerkleTree = rs_merkle::MerkleTree;
14 |
15 | /// Merkle proof using [`Blake2b256Algorithm`].
16 | pub type MerkleProof = rs_merkle::MerkleProof;
17 |
18 | /// Merke proof based Witness.
19 | #[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone, Default)]
20 | pub struct Witness {
21 | /// Index of the leaf the proof is for.
22 | pub leaf_index: u32,
23 | /// Merkle proof in bytes.
24 | pub proof: Vec,
25 | /// Number of leaves in the original tree.
26 | pub number_of_leaves: u32,
27 | }
28 |
29 | #[derive(Clone)]
30 | pub struct Blake2b256Algorithm(Blake2b);
31 |
32 | impl Default for Blake2b256Algorithm {
33 | #[inline]
34 | fn default() -> Self {
35 | Self(Blake2b::new())
36 | }
37 | }
38 |
39 | impl Hasher for Blake2b256Algorithm {
40 | type Hash = Blake2b256Hash;
41 |
42 | fn hash(data: &[u8]) -> Blake2b256Hash {
43 | let mut hasher = Blake2b::new();
44 | hasher.update(data);
45 | hasher.finalize_fixed().into()
46 | }
47 | }
48 |
49 | /// Constructs a merkle tree from given authorities.
50 | pub fn authorities_merkle_tree(
51 | authorities: &[(ExecutorPublicKey, StakeWeight)],
52 | ) -> MerkleTree {
53 | let leaves = authorities
54 | .iter()
55 | .map(|x| BlakeTwo256::hash_of(&x.encode()).to_fixed_bytes())
56 | .collect::>();
57 | MerkleTree::from_leaves(&leaves)
58 | }
59 |
60 | #[cfg(test)]
61 | mod tests {
62 | use super::MerkleTree;
63 |
64 | #[test]
65 | fn test_merkle_tree() {
66 | let leaves = [[1u8; 32], [2u8; 32], [3u8; 32], [4u8; 32], [5u8; 32]];
67 |
68 | let merkle_tree = MerkleTree::from_leaves(&leaves);
69 |
70 | let indices_to_prove = (0..leaves.len()).collect::>();
71 | let leaves_to_prove = leaves
72 | .get(0..leaves.len())
73 | .expect("can't get leaves to prove");
74 |
75 | let proof = merkle_tree.proof(&indices_to_prove);
76 | let root = merkle_tree.root().expect("couldn't get the merkle root");
77 |
78 | assert!(proof.verify(root, &indices_to_prove, leaves_to_prove, leaves.len()));
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/crates/sp-domains/src/transaction.rs:
--------------------------------------------------------------------------------
1 | use crate::fraud_proof::FraudProof;
2 | use crate::OpaqueBundle;
3 | use parity_scale_codec::{Decode, Encode};
4 | use scale_info::TypeInfo;
5 | use sp_runtime::traits::{Block as BlockT, NumberFor};
6 | use sp_runtime::transaction_validity::{InvalidTransaction, TransactionValidity};
7 |
8 | /// Custom invalid validity code for the extrinsics in pallet-domains.
9 | #[repr(u8)]
10 | pub enum InvalidTransactionCode {
11 | BundleEquivicationProof = 101,
12 | TrasactionProof = 102,
13 | ExecutionReceipt = 103,
14 | Bundle = 104,
15 | FraudProof = 105,
16 | }
17 |
18 | impl From for InvalidTransaction {
19 | #[inline]
20 | fn from(invalid_code: InvalidTransactionCode) -> Self {
21 | InvalidTransaction::Custom(invalid_code as u8)
22 | }
23 | }
24 |
25 | impl From for TransactionValidity {
26 | #[inline]
27 | fn from(invalid_code: InvalidTransactionCode) -> Self {
28 | InvalidTransaction::Custom(invalid_code as u8).into()
29 | }
30 | }
31 |
32 | /// Object for performing the pre-validation in the transaction pool
33 | /// before calling into the regular `validate_transaction` runtime api.
34 | #[derive(Debug, Decode, Encode, TypeInfo, PartialEq, Eq, Clone)]
35 | pub enum PreValidationObject
36 | where
37 | Block: BlockT,
38 | {
39 | Null,
40 | FraudProof(FraudProof, Block::Hash>),
41 | Bundle(OpaqueBundle, Block::Hash, DomainHash>),
42 | }
43 |
44 | sp_api::decl_runtime_apis! {
45 | /// API for extracting the pre-validation objects in the primary chain transaction pool wrapper.
46 | pub trait PreValidationObjectApi {
47 | /// Extract the pre-validation object from the given extrinsic.
48 | fn extract_pre_validation_object(extrinsics: Block::Extrinsic) -> PreValidationObject;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/crates/sp-lightclient/README.md:
--------------------------------------------------------------------------------
1 | # Light client substrate primitives for Subspace
2 |
--------------------------------------------------------------------------------
/crates/sp-objects/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "sp-objects"
3 | version = "0.1.0"
4 | authors = ["Vedhavyas Singareddi "]
5 | edition = "2021"
6 | license = "Apache-2.0"
7 | homepage = "https://subspace.network"
8 | repository = "https://github.com/subspace/subspace"
9 | description = "Primitives for Objects"
10 | readme = "README.md"
11 |
12 | [package.metadata.docs.rs]
13 | targets = ["x86_64-unknown-linux-gnu"]
14 |
15 | [dependencies]
16 | sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
17 | sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
18 | subspace-core-primitives = { version = "0.1.0", default-features = false, path = "../subspace-core-primitives" }
19 | subspace-runtime-primitives = { version = "0.1.0", default-features = false, path = "../subspace-runtime-primitives" }
20 |
21 | [features]
22 | default = ["std"]
23 | std = [
24 | "sp-api/std",
25 | "sp-std/std",
26 | "subspace-core-primitives/std",
27 | "subspace-runtime-primitives/std",
28 | ]
29 |
--------------------------------------------------------------------------------
/crates/sp-objects/src/lib.rs:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2021 Subspace Labs, Inc.
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 |
16 | //! Primitives for Objects.
17 |
18 | #![cfg_attr(not(feature = "std"), no_std)]
19 |
20 | use sp_std::vec::Vec;
21 | use subspace_core_primitives::objects::BlockObjectMapping;
22 | use subspace_runtime_primitives::Hash;
23 |
24 | sp_api::decl_runtime_apis! {
25 | pub trait ObjectsApi {
26 | /// Returns all the validated object call hashes for a given block
27 | fn validated_object_call_hashes() -> Vec;
28 |
29 | /// Extract block object mapping for a given block
30 | fn extract_block_object_mapping(block: Block, validated_object_calls: Vec) -> BlockObjectMapping;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/crates/sp-settlement/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "sp-settlement"
3 | version = "0.1.0"
4 | authors = ["Liu-Cheng Xu "]
5 | edition = "2021"
6 | license = "Apache-2.0"
7 | homepage = "https://subspace.network"
8 | repository = "https://github.com/subspace/subspace"
9 | description = "Primitives for Receipts"
10 |
11 | [package.metadata.docs.rs]
12 | targets = ["x86_64-unknown-linux-gnu"]
13 |
14 | [dependencies]
15 | codec = { package = "parity-scale-codec", version = "3.1.2", default-features = false }
16 | sp-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
17 | sp-core = { version = "21.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
18 | sp-domains = { version = "0.1.0", default-features = false, path = "../sp-domains" }
19 | sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
20 | sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
21 |
22 | [features]
23 | default = ["std"]
24 | std = [
25 | "codec/std",
26 | "sp-api/std",
27 | "sp-core/std",
28 | "sp-domains/std",
29 | "sp-runtime/std",
30 | "sp-std/std",
31 | ]
32 |
--------------------------------------------------------------------------------
/crates/subspace-archiving/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "subspace-archiving"
3 | description = "Collection of modules used for dealing with archived state of Subspace Network"
4 | license = "Apache-2.0"
5 | version = "0.1.0"
6 | authors = ["Nazar Mokrynskyi "]
7 | edition = "2021"
8 | include = [
9 | "/benches",
10 | "/src",
11 | "/Cargo.toml",
12 | "/README.md",
13 | ]
14 |
15 | [lib]
16 | # Necessary for CLI options to work on benches
17 | bench = false
18 |
19 | [dependencies]
20 | parity-scale-codec = { version = "3.4.0", default-features = false, features = ["derive"] }
21 | rayon = { version = "1.7.0", optional = true }
22 | serde = { version = "1.0.159", optional = true, features = ["derive"] }
23 | subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives", default-features = false }
24 | subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding", default-features = false }
25 | thiserror = { version = "1.0.38", optional = true }
26 |
27 | [dev-dependencies]
28 | criterion = "0.5.1"
29 | rand = { version = "0.8.5", features = ["min_const_gen"] }
30 | subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
31 |
32 | [features]
33 | default = ["std"]
34 | parallel = [
35 | "dep:rayon",
36 | "subspace-core-primitives/parallel",
37 | ]
38 | serde = [
39 | "dep:serde",
40 | "subspace-core-primitives/serde",
41 | ]
42 | std = [
43 | "parity-scale-codec/std",
44 | "parallel",
45 | "serde",
46 | "subspace-core-primitives/std",
47 | "subspace-erasure-coding/std",
48 | "thiserror",
49 | ]
50 |
51 | [[bench]]
52 | name = "archiving"
53 | harness = false
54 |
--------------------------------------------------------------------------------
/crates/subspace-archiving/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbulava/subspace/065dc94762db7e2531594b284daac6bd9f2d7b6e/crates/subspace-archiving/README.md
--------------------------------------------------------------------------------
/crates/subspace-archiving/benches/archiving.rs:
--------------------------------------------------------------------------------
1 | use criterion::{criterion_group, criterion_main, Criterion};
2 | use rand::{thread_rng, Rng};
3 | use subspace_archiving::archiver::Archiver;
4 | use subspace_core_primitives::crypto::kzg;
5 | use subspace_core_primitives::crypto::kzg::Kzg;
6 | use subspace_core_primitives::RecordedHistorySegment;
7 |
8 | fn criterion_benchmark(c: &mut Criterion) {
9 | let mut input = RecordedHistorySegment::new_boxed();
10 | thread_rng().fill(AsMut::<[u8]>::as_mut(input.as_mut()));
11 | let kzg = Kzg::new(kzg::embedded_kzg_settings());
12 | let mut archiver = Archiver::new(kzg).unwrap();
13 |
14 | c.bench_function("segment-archiving", |b| {
15 | b.iter(|| {
16 | archiver.add_block(
17 | AsRef::<[u8]>::as_ref(input.as_ref()).to_vec(),
18 | Default::default(),
19 | );
20 | })
21 | });
22 | }
23 |
24 | criterion_group!(benches, criterion_benchmark);
25 | criterion_main!(benches);
26 |
--------------------------------------------------------------------------------
/crates/subspace-archiving/src/lib.rs:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2021 Subspace Labs, Inc.
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 |
16 | //! Collection of modules used for dealing with archived state of Subspace Network.
17 | #![cfg_attr(not(feature = "std"), no_std)]
18 | #![feature(array_chunks, drain_filter, iter_collect_into, slice_flatten)]
19 |
20 | pub mod archiver;
21 | pub mod piece_reconstructor;
22 | pub mod reconstructor;
23 |
--------------------------------------------------------------------------------
/crates/subspace-archiving/tests/integration/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(assert_matches)]
2 |
3 | mod archiver;
4 | mod piece_reconstruction;
5 | mod reconstructor;
6 |
--------------------------------------------------------------------------------
/crates/subspace-core-primitives/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbulava/subspace/065dc94762db7e2531594b284daac6bd9f2d7b6e/crates/subspace-core-primitives/README.md
--------------------------------------------------------------------------------
/crates/subspace-core-primitives/benches/kzg.rs:
--------------------------------------------------------------------------------
1 | use criterion::{black_box, criterion_group, criterion_main, Criterion};
2 | use subspace_core_primitives::crypto::kzg::{embedded_kzg_settings, Kzg};
3 | use subspace_core_primitives::crypto::Scalar;
4 | use subspace_core_primitives::RawRecord;
5 |
6 | fn criterion_benchmark(c: &mut Criterion) {
7 | let values = (0..RawRecord::SIZE / Scalar::SAFE_BYTES)
8 | .map(|_| Scalar::from(rand::random::<[u8; Scalar::SAFE_BYTES]>()))
9 | .collect::>();
10 |
11 | let kzg = Kzg::new(embedded_kzg_settings());
12 |
13 | c.bench_function("create-polynomial", |b| {
14 | b.iter(|| {
15 | kzg.poly(black_box(&values)).unwrap();
16 | })
17 | });
18 |
19 | c.bench_function("commit", |b| {
20 | let polynomial = kzg.poly(&values).unwrap();
21 | b.iter(|| {
22 | kzg.commit(black_box(&polynomial)).unwrap();
23 | })
24 | });
25 |
26 | let num_values = values.len();
27 |
28 | c.bench_function("create-witness", |b| {
29 | let polynomial = kzg.poly(&values).unwrap();
30 |
31 | b.iter(|| {
32 | kzg.create_witness(black_box(&polynomial), black_box(num_values), black_box(0))
33 | .unwrap();
34 | })
35 | });
36 |
37 | c.bench_function("verify", |b| {
38 | let polynomial = kzg.poly(&values).unwrap();
39 | let commitment = kzg.commit(&polynomial).unwrap();
40 | let index = 0;
41 | let witness = kzg.create_witness(&polynomial, num_values, index).unwrap();
42 | let value = values.first().unwrap();
43 |
44 | b.iter(|| {
45 | kzg.verify(
46 | black_box(&commitment),
47 | black_box(num_values),
48 | black_box(index),
49 | black_box(value),
50 | black_box(&witness),
51 | );
52 | })
53 | });
54 | }
55 |
56 | criterion_group!(benches, criterion_benchmark);
57 | criterion_main!(benches);
58 |
--------------------------------------------------------------------------------
/crates/subspace-core-primitives/src/crypto/kzg/eth-public-parameters.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxbulava/subspace/065dc94762db7e2531594b284daac6bd9f2d7b6e/crates/subspace-core-primitives/src/crypto/kzg/eth-public-parameters.bin
--------------------------------------------------------------------------------
/crates/subspace-core-primitives/src/crypto/kzg/serde.rs:
--------------------------------------------------------------------------------
1 | use serde::de::Error;
2 | use serde::{Deserialize, Deserializer, Serialize, Serializer};
3 |
4 | // Custom wrapper so we don't have to write serialization/deserialization code manually
5 | #[derive(Serialize, Deserialize)]
6 | struct Commitment(#[serde(with = "hex::serde")] pub(super) [u8; 48]);
7 |
8 | impl Serialize for super::Commitment {
9 | fn serialize(&self, serializer: S) -> Result
10 | where
11 | S: Serializer,
12 | {
13 | Commitment(self.to_bytes()).serialize(serializer)
14 | }
15 | }
16 |
17 | impl<'de> Deserialize<'de> for super::Commitment {
18 | fn deserialize(deserializer: D) -> Result
19 | where
20 | D: Deserializer<'de>,
21 | {
22 | let Commitment(bytes) = Commitment::deserialize(deserializer)?;
23 | Self::try_from_bytes(&bytes).map_err(|error| D::Error::custom(format!("{error:?}")))
24 | }
25 | }
26 |
27 | // Custom wrapper so we don't have to write serialization/deserialization code manually
28 | #[derive(Serialize, Deserialize)]
29 | struct Witness(#[serde(with = "hex::serde")] pub(super) [u8; 48]);
30 |
31 | impl Serialize for super::Witness {
32 | fn serialize(&self, serializer: S) -> Result
33 | where
34 | S: Serializer,
35 | {
36 | Witness(self.to_bytes()).serialize(serializer)
37 | }
38 | }
39 |
40 | impl<'de> Deserialize<'de> for super::Witness {
41 | fn deserialize(deserializer: D) -> Result
42 | where
43 | D: Deserializer<'de>,
44 | {
45 | let Witness(bytes) = Witness::deserialize(deserializer)?;
46 | Self::try_from_bytes(&bytes).map_err(|error| D::Error::custom(format!("{error:?}")))
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/crates/subspace-core-primitives/src/crypto/kzg/tests.rs:
--------------------------------------------------------------------------------
1 | use crate::crypto::kzg::{embedded_kzg_settings, Kzg};
2 | use crate::crypto::Scalar;
3 |
4 | #[test]
5 | fn basic() {
6 | let values = (0..8)
7 | .map(|_| Scalar::from(rand::random::<[u8; Scalar::SAFE_BYTES]>()))
8 | .collect::>();
9 |
10 | let kzg = Kzg::new(embedded_kzg_settings());
11 | let polynomial = kzg.poly(&values).unwrap();
12 | let commitment = kzg.commit(&polynomial).unwrap();
13 |
14 | let num_values = values.len();
15 |
16 | for (index, value) in values.iter().enumerate() {
17 | let index = index.try_into().unwrap();
18 |
19 | let witness = kzg.create_witness(&polynomial, num_values, index).unwrap();
20 |
21 | assert!(
22 | kzg.verify(&commitment, num_values, index, value, &witness),
23 | "failed on index {index}"
24 | );
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/crates/subspace-core-primitives/src/pieces/tests.rs:
--------------------------------------------------------------------------------
1 | use crate::pieces::SBucket;
2 | use crate::Record;
3 |
4 | // Statically validate that we can store all possible s-buckets in SBucket data structure
5 | #[test]
6 | fn s_buckets_fit_into_data_structure() {
7 | assert!((SBucket::ZERO..=SBucket(u16::MAX)).count() <= Record::NUM_S_BUCKETS);
8 | }
9 |
--------------------------------------------------------------------------------
/crates/subspace-core-primitives/src/tests.rs:
--------------------------------------------------------------------------------
1 | use crate::crypto::Scalar;
2 | use crate::U256;
3 | use rand::thread_rng;
4 | use rand_core::RngCore;
5 |
6 | #[test]
7 | fn piece_distance_middle() {
8 | assert_eq!(U256::MIDDLE, U256::MAX / 2);
9 | }
10 |
11 | #[test]
12 | fn bytes_scalars_conversion() {
13 | {
14 | let mut bytes = vec![0u8; Scalar::SAFE_BYTES * 16];
15 | thread_rng().fill_bytes(&mut bytes);
16 |
17 | let scalars = bytes
18 | .chunks_exact(Scalar::SAFE_BYTES)
19 | .map(|bytes| {
20 | Scalar::from(
21 | <&[u8; Scalar::SAFE_BYTES]>::try_from(bytes)
22 | .expect("Chunked into correct size; qed"),
23 | )
24 | })
25 | .collect::>();
26 |
27 | {
28 | let mut decoded_bytes = vec![0u8; bytes.len()];
29 | decoded_bytes
30 | .chunks_exact_mut(Scalar::SAFE_BYTES)
31 | .zip(scalars.iter())
32 | .for_each(|(bytes, scalar)| {
33 | bytes.copy_from_slice(&scalar.to_bytes()[..Scalar::SAFE_BYTES]);
34 | });
35 |
36 | assert_eq!(bytes, decoded_bytes);
37 | }
38 |
39 | {
40 | let mut decoded_bytes = vec![0u8; bytes.len()];
41 | decoded_bytes
42 | .chunks_exact_mut(Scalar::SAFE_BYTES)
43 | .zip(scalars.iter())
44 | .for_each(|(bytes, scalar)| {
45 | bytes.copy_from_slice(&scalar.to_bytes()[..Scalar::SAFE_BYTES]);
46 | });
47 |
48 | assert_eq!(bytes, decoded_bytes);
49 | }
50 | }
51 |
52 | {
53 | let bytes = {
54 | let mut bytes = [0u8; Scalar::FULL_BYTES];
55 | bytes[..Scalar::SAFE_BYTES]
56 | .copy_from_slice(&rand::random::<[u8; Scalar::SAFE_BYTES]>());
57 | bytes
58 | };
59 |
60 | {
61 | let scalar = Scalar::try_from(&bytes).unwrap();
62 |
63 | assert_eq!(bytes, scalar.to_bytes());
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/crates/subspace-erasure-coding/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "subspace-erasure-coding"
3 | description = "Polynomial erasure coding implementation used in Subspace Network"
4 | license = "Apache-2.0"
5 | version = "0.1.0"
6 | authors = ["Nazar Mokrynskyi "]
7 | edition = "2021"
8 | include = [
9 | "/src",
10 | "/Cargo.toml",
11 | ]
12 |
13 | [lib]
14 | # Necessary for CLI options to work on benches
15 | bench = false
16 |
17 | [dependencies]
18 | # TODO: Switch to upstream `main` once https://github.com/sifraitech/rust-kzg/pull/204 is merged and blst has upstream no_std support
19 | blst_rust = { git = "https://github.com/subspace/rust-kzg", rev = "1058cc8c8af8461b490dc212c41d7d506a746577", default-features = false }
20 | # TODO: Switch to upstream `main` once https://github.com/sifraitech/rust-kzg/pull/204 is merged and blst has upstream no_std support
21 | kzg = { git = "https://github.com/subspace/rust-kzg", rev = "1058cc8c8af8461b490dc212c41d7d506a746577", default-features = false }
22 | subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives", default-features = false }
23 |
24 | [dev-dependencies]
25 | # TODO: Switch to upstream `main` once https://github.com/sifraitech/rust-kzg/pull/204 is merged and blst has upstream no_std support
26 | blst_rust = { git = "https://github.com/subspace/rust-kzg", rev = "1058cc8c8af8461b490dc212c41d7d506a746577" }
27 | criterion = "0.5.1"
28 | rand = "0.8.5"
29 |
30 | [features]
31 | default = ["std", "parallel"]
32 | std = [
33 | "blst_rust/std",
34 | "kzg/std",
35 | "subspace-core-primitives/std",
36 | ]
37 | parallel = ["blst_rust/parallel"]
38 |
39 | [[bench]]
40 | name = "commitments"
41 | harness = false
42 |
--------------------------------------------------------------------------------
/crates/subspace-erasure-coding/benches/commitments.rs:
--------------------------------------------------------------------------------
1 | use blst_rust::types::g1::FsG1;
2 | use criterion::{black_box, criterion_group, criterion_main, Criterion};
3 | use kzg::G1;
4 | use std::num::NonZeroUsize;
5 | use subspace_core_primitives::crypto::kzg::Commitment;
6 | use subspace_core_primitives::ArchivedHistorySegment;
7 | use subspace_erasure_coding::ErasureCoding;
8 |
9 | fn criterion_benchmark(c: &mut Criterion) {
10 | let num_shards = ArchivedHistorySegment::NUM_PIECES;
11 | let scale = NonZeroUsize::new(num_shards.ilog2() as usize)
12 | .expect("Recorded history segment contains at very least one record; qed");
13 | let ec = ErasureCoding::new(scale).unwrap();
14 |
15 | let source_commitments = (0..num_shards / 2)
16 | .map(|_| Commitment::from(FsG1::rand()))
17 | .collect::>();
18 |
19 | c.bench_function("extend", |b| {
20 | b.iter(|| {
21 | ec.extend_commitments(black_box(&source_commitments))
22 | .unwrap()
23 | })
24 | });
25 | }
26 |
27 | criterion_group!(benches, criterion_benchmark);
28 | criterion_main!(benches);
29 |
--------------------------------------------------------------------------------
/crates/subspace-farmer-components/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "subspace-farmer-components"
3 | description = "Farmer for the Subspace Network Blockchain"
4 | license = "MIT OR Apache-2.0"
5 | version = "0.1.0"
6 | authors = ["Nazar Mokrynskyi "]
7 | edition = "2021"
8 | include = [
9 | "/src",
10 | "/Cargo.toml",
11 | "/README.md",
12 | ]
13 |
14 | [lib]
15 | # Necessary for CLI options to work on benches
16 | bench = false
17 |
18 | [dependencies]
19 | async-trait = "0.1.68"
20 | backoff = { version = "0.4.0", features = ["futures", "tokio"] }
21 | bitvec = "1.0.1"
22 | fs2 = "0.4.3"
23 | futures = "0.3.28"
24 | libc = "0.2.146"
25 | lru = "0.10.0"
26 | parity-scale-codec = "3.4.0"
27 | parking_lot = "0.12.1"
28 | rand = "0.8.5"
29 | rayon = "1.7.0"
30 | schnorrkel = "0.9.1"
31 | serde = { version = "1.0.159", features = ["derive"] }
32 | static_assertions = "1.1.0"
33 | subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" }
34 | subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
35 | subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding" }
36 | subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space", features = ["parallel"] }
37 | subspace-verification = { version = "0.1.0", path = "../subspace-verification" }
38 | thiserror = "1.0.38"
39 | tokio = { version = "1.28.2", features = ["macros", "parking_lot", "rt-multi-thread", "signal", "sync"] }
40 | tracing = "0.1.37"
41 |
42 | [dev-dependencies]
43 | criterion = "0.5.1"
44 | futures = "0.3.28"
45 | memmap2 = "0.7.0"
46 | subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" }
47 | subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space", features = ["chia"] }
48 |
49 | [[bench]]
50 | name = "plotting"
51 | harness = false
52 |
53 | [[bench]]
54 | name = "reading"
55 | harness = false
56 |
57 | [[bench]]
58 | name = "auditing"
59 | harness = false
60 |
61 | [[bench]]
62 | name = "proving"
63 | harness = false
64 |
--------------------------------------------------------------------------------
/crates/subspace-farmer-components/README.md:
--------------------------------------------------------------------------------
1 | # Subspace Farmer Components
2 |
3 | Components of the reference implementation of Subspace Farmer for Subspace Network Blockchain.
4 |
5 | These components are used to implement farmer itself, but can also be used independently if necessary.
6 |
--------------------------------------------------------------------------------
/crates/subspace-farmer-components/src/lib.rs:
--------------------------------------------------------------------------------
1 | #![feature(
2 | array_chunks,
3 | const_option,
4 | const_trait_impl,
5 | int_roundings,
6 | iter_collect_into,
7 | new_uninit,
8 | portable_simd,
9 | slice_flatten,
10 | try_blocks
11 | )]
12 |
13 | //! Components of the reference implementation of Subspace Farmer for Subspace Network Blockchain.
14 | //!
15 | //! These components are used to implement farmer itself, but can also be used independently if necessary.
16 |
17 | pub mod auditing;
18 | pub mod file_ext;
19 | pub mod piece_caching;
20 | pub mod plotting;
21 | pub mod proving;
22 | pub mod reading;
23 | pub mod sector;
24 | mod segment_reconstruction;
25 |
26 | use serde::{Deserialize, Serialize};
27 | use static_assertions::const_assert;
28 | use subspace_core_primitives::{HistorySize, SegmentIndex};
29 |
30 | // Refuse to compile on non-64-bit platforms, offsets may fail on those when converting from u64 to
31 | // usize depending on chain parameters
32 | const_assert!(std::mem::size_of::() >= std::mem::size_of::());
33 |
34 | /// Information about the protocol necessary for farmer operation
35 | #[derive(Debug, Copy, Clone, Serialize, Deserialize)]
36 | #[serde(rename_all = "camelCase")]
37 | pub struct FarmerProtocolInfo {
38 | /// Size of the blockchain history
39 | pub history_size: HistorySize,
40 | /// How many pieces one sector is supposed to contain (max)
41 | pub max_pieces_in_sector: u16,
42 | /// Number of segments after which sector expires
43 | pub sector_expiration: SegmentIndex,
44 | }
45 |
--------------------------------------------------------------------------------
/crates/subspace-farmer-components/src/piece_caching.rs:
--------------------------------------------------------------------------------
1 | use lru::LruCache;
2 | use parking_lot::Mutex;
3 | use std::num::NonZeroUsize;
4 | use std::sync::Arc;
5 | use subspace_core_primitives::{Piece, PieceIndexHash};
6 | use tracing::trace;
7 |
8 | // TODO: Re-think this number
9 | const CACHE_ITEMS_LIMIT: NonZeroUsize =
10 | NonZeroUsize::new(100).expect("Archived history segment contains at very least one piece; qed");
11 |
12 | #[derive(Clone)]
13 | pub struct PieceMemoryCache {
14 | cache: Arc>>,
15 | }
16 | impl Default for PieceMemoryCache {
17 | #[inline]
18 | fn default() -> Self {
19 | Self::new(CACHE_ITEMS_LIMIT)
20 | }
21 | }
22 |
23 | impl PieceMemoryCache {
24 | pub fn new(items_limit: NonZeroUsize) -> Self {
25 | Self {
26 | cache: Arc::new(Mutex::new(LruCache::new(items_limit))),
27 | }
28 | }
29 |
30 | pub fn add_piece(&self, piece_index_hash: PieceIndexHash, piece: Piece) {
31 | self.cache.lock().put(piece_index_hash, piece);
32 | }
33 |
34 | pub fn add_pieces(&self, pieces: Vec<(PieceIndexHash, Piece)>) {
35 | let mut cache = self.cache.lock();
36 |
37 | for (piece_index_hash, piece) in pieces {
38 | cache.put(piece_index_hash, piece);
39 | }
40 | }
41 |
42 | pub fn get_piece(&self, piece_index_hash: &PieceIndexHash) -> Option {
43 | let piece = self.cache.lock().get(piece_index_hash).cloned();
44 |
45 | if piece.is_some() {
46 | trace!(?piece_index_hash, "Piece memory cache hit.");
47 | }
48 |
49 | piece
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/crates/subspace-farmer/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "subspace-farmer"
3 | description = "Farmer for the Subspace Network Blockchain"
4 | license = "MIT OR Apache-2.0"
5 | version = "0.1.0"
6 | authors = ["Nazar Mokrynskyi "]
7 | edition = "2021"
8 | include = [
9 | "/src",
10 | "/Cargo.toml",
11 | "/README.md",
12 | ]
13 |
14 | [dependencies]
15 | anyhow = "1.0.71"
16 | async-trait = "0.1.68"
17 | backoff = { version = "0.4.0", features = ["futures", "tokio"] }
18 | base58 = "0.2.0"
19 | blake2 = "0.10.6"
20 | bytesize = "1.2.0"
21 | clap = { version = "4.2.1", features = ["color", "derive"] }
22 | derive_more = "0.99.17"
23 | dirs = "5.0.1"
24 | event-listener-primitives = "2.0.1"
25 | fdlimit = "0.2"
26 | futures = "0.3.28"
27 | hex = { version = "0.4.3", features = ["serde"] }
28 | jsonrpsee = { version = "0.16.2", features = ["client", "macros", "server"] }
29 | lru = "0.10.0"
30 | memmap2 = "0.7.0"
31 | num-traits = "0.2.15"
32 | parity-db = "0.4.6"
33 | parity-scale-codec = "3.4.0"
34 | parking_lot = "0.12.1"
35 | rand = "0.8.5"
36 | schnorrkel = "0.9.1"
37 | serde = { version = "1.0.159", features = ["derive"] }
38 | serde_json = "1.0.95"
39 | static_assertions = "1.1.0"
40 | std-semaphore = "0.1.0"
41 | ss58-registry = "1.40.0"
42 | subspace-archiving = { version = "0.1.0", path = "../subspace-archiving" }
43 | subspace-erasure-coding = { version = "0.1.0", path = "../subspace-erasure-coding" }
44 | subspace-farmer-components = { version = "0.1.0", path = "../subspace-farmer-components" }
45 | subspace-solving = { version = "0.1.0", path = "../subspace-solving" }
46 | subspace-core-primitives = { version = "0.1.0", path = "../subspace-core-primitives" }
47 | subspace-networking = { version = "0.1.0", path = "../subspace-networking" }
48 | subspace-proof-of-space = { version = "0.1.0", path = "../subspace-proof-of-space", features = ["chia"] }
49 | subspace-rpc-primitives = { version = "0.1.0", path = "../subspace-rpc-primitives" }
50 | substrate-bip39 = "0.4.4"
51 | tempfile = "3.4.0"
52 | thiserror = "1.0.38"
53 | tokio = { version = "1.28.2", features = ["macros", "parking_lot", "rt-multi-thread", "signal"] }
54 | tracing = "0.1.37"
55 | tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
56 | ulid = { version = "1.0.0", features = ["serde"] }
57 | zeroize = "1.6.0"
58 |
59 | # The only triple tested and confirmed as working in `jemallocator` crate is `x86_64-unknown-linux-gnu`
60 | [target.'cfg(all(target_arch = "x86_64", target_vendor = "unknown", target_os = "linux", target_env = "gnu"))'.dependencies]
61 | jemallocator = "0.5.0"
62 |
63 | [dev-dependencies]
64 | rayon = "1.7.0"
65 |
--------------------------------------------------------------------------------
/crates/subspace-farmer/src/bin/subspace-farmer/commands.rs:
--------------------------------------------------------------------------------
1 | mod farm;
2 | mod info;
3 | mod shared;
4 |
5 | pub(crate) use farm::farm_multi_disk;
6 | pub(crate) use info::info;
7 |
--------------------------------------------------------------------------------
/crates/subspace-farmer/src/bin/subspace-farmer/commands/info.rs:
--------------------------------------------------------------------------------
1 | use crate::commands::shared::print_disk_farm_info;
2 | use crate::DiskFarm;
3 |
4 | pub(crate) fn info(disk_farms: Vec) {
5 | for (disk_farm_index, disk_farm) in disk_farms.into_iter().enumerate() {
6 | if disk_farm_index > 0 {
7 | println!();
8 | }
9 |
10 | let DiskFarm { directory, .. } = disk_farm;
11 |
12 | print_disk_farm_info(directory, disk_farm_index);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/crates/subspace-farmer/src/bin/subspace-farmer/commands/shared.rs:
--------------------------------------------------------------------------------
1 | use std::path::PathBuf;
2 | use subspace_farmer::single_disk_plot::{SingleDiskPlot, SingleDiskPlotSummary};
3 |
4 | pub(crate) fn print_disk_farm_info(directory: PathBuf, disk_farm_index: usize) {
5 | println!("Single disk farm {disk_farm_index}:");
6 | match SingleDiskPlot::collect_summary(directory) {
7 | SingleDiskPlotSummary::Found { info, directory } => {
8 | println!(" ID: {}", info.id());
9 | println!(" Genesis hash: 0x{}", hex::encode(info.genesis_hash()));
10 | println!(" Public key: 0x{}", hex::encode(info.public_key()));
11 | println!(" First sector index: {}", info.first_sector_index());
12 | println!(
13 | " Allocated space: {} ({})",
14 | bytesize::to_string(info.allocated_space(), true),
15 | bytesize::to_string(info.allocated_space(), false)
16 | );
17 | println!(" Directory: {}", directory.display());
18 | }
19 | SingleDiskPlotSummary::NotFound { directory } => {
20 | println!(" Plot directory: {}", directory.display());
21 | println!(" No farm found here yet");
22 | }
23 | SingleDiskPlotSummary::Error { directory, error } => {
24 | println!(" Directory: {}", directory.display());
25 | println!(" Failed to open farm info: {error}");
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/crates/subspace-farmer/src/lib.rs:
--------------------------------------------------------------------------------
1 | #![feature(
2 | const_option,
3 | drain_filter,
4 | hash_drain_filter,
5 | impl_trait_in_assoc_type,
6 | io_error_other,
7 | iter_collect_into,
8 | let_chains,
9 | trait_alias,
10 | try_blocks,
11 | type_alias_impl_trait,
12 | type_changing_struct_update
13 | )]
14 |
15 | //! # `subspace-farmer` library implementation overview
16 | //!
17 | //! This library provides droppable/interruptable instances of two processes that can be run in
18 | //! parallel: `plotting` and `farming`.
19 | //!
20 | //! During plotting we create:
21 | //! * a binary plot file, which contains subspace-encoded pieces one after another
22 | //! * a RocksDB commitments database, where key is a tag (first 8 bytes of `hmac(encoding, salt)`)
23 | //! and value is an offset of corresponding encoded piece in the plot (we can do this because all
24 | //! pieces have the same size).
25 | //!
26 | //! In short, for every piece we also store a record with 8-bytes tag and 8-bytes index (+some
27 | //! overhead of RocksDB itself).
28 | //!
29 | //! During farming we receive a global challenge and need to find a solution based on *target* and
30 | //! *solution range*. In order to find solution, we derive *local challenge* and use first 8 bytes
31 | //! (the same as tag size) as our *target* and do range query in RocksDB. For that we interpret
32 | //! *target* as 64-bit big-endian unsigned integer and find all of the keys in tags database that
33 | //! are `target ± ½ * solution range` (while also handing overflow/underflow) when interpreted as
34 | //! 64-bit unsigned integers.
35 |
36 | pub(crate) mod identity;
37 | pub mod node_client;
38 | pub(crate) mod object_mappings;
39 | pub mod reward_signing;
40 | pub mod single_disk_plot;
41 | pub mod utils;
42 | pub mod ws_rpc_server;
43 |
44 | pub use identity::Identity;
45 | pub use jsonrpsee;
46 | pub use node_client::node_rpc_client::NodeRpcClient;
47 | pub use node_client::{Error as RpcClientError, NodeClient};
48 | pub use object_mappings::{ObjectMappingError, ObjectMappings};
49 |
--------------------------------------------------------------------------------
/crates/subspace-farmer/src/node_client.rs:
--------------------------------------------------------------------------------
1 | pub(crate) mod node_rpc_client;
2 |
3 | use async_trait::async_trait;
4 | use futures::Stream;
5 | use std::pin::Pin;
6 | use subspace_core_primitives::{Piece, PieceIndex, SegmentCommitment, SegmentHeader, SegmentIndex};
7 | use subspace_rpc_primitives::{
8 | FarmerAppInfo, RewardSignatureResponse, RewardSigningInfo, SlotInfo, SolutionResponse,
9 | };
10 |
11 | /// To become error type agnostic
12 | pub type Error = Box;
13 |
14 | /// Abstraction of the Node Client
15 | #[async_trait]
16 | pub trait NodeClient: Clone + Send + Sync + 'static {
17 | /// Get farmer app info
18 | async fn farmer_app_info(&self) -> Result;
19 |
20 | /// Subscribe to slot
21 | async fn subscribe_slot_info(
22 | &self,
23 | ) -> Result + Send + 'static>>, Error>;
24 |
25 | /// Submit a slot solution
26 | async fn submit_solution_response(
27 | &self,
28 | solution_response: SolutionResponse,
29 | ) -> Result<(), Error>;
30 |
31 | /// Subscribe to block signing request
32 | async fn subscribe_reward_signing(
33 | &self,
34 | ) -> Result + Send + 'static>>, Error>;
35 |
36 | /// Submit a block signature
37 | async fn submit_reward_signature(
38 | &self,
39 | reward_signature: RewardSignatureResponse,
40 | ) -> Result<(), Error>;
41 |
42 | /// Subscribe to archived segment headers
43 | async fn subscribe_archived_segment_headers(
44 | &self,
45 | ) -> Result + Send + 'static>>, Error>;
46 |
47 | /// Get segment commitments for the segments
48 | async fn segment_commitments(
49 | &self,
50 | segment_indexes: Vec,
51 | ) -> Result>, Error>;
52 |
53 | /// Get segment headers for the segments
54 | async fn segment_headers(
55 | &self,
56 | segment_indexes: Vec,
57 | ) -> Result>, Error>;
58 |
59 | /// Get piece by index.
60 | async fn piece(&self, piece_index: PieceIndex) -> Result