* Remove use of trait Store from staking pallet * Remove use of trait Store from bounties pallet * Remove use of trait Store from collective pallet * Remove use of trait Store from babe pallet * Remove use of trait Store from assets pallet * Remove use of trait Store from grandpa pallet * Remove use of trait Store from balances pallet * Remove use of trait Store from authorship pallet * Remove use of trait Store from authority-discovery pallet * Remove use of trait Store from atomic-swap pallet * Remove use of trait Store from sudo pallet * Remove use of trait Store from scheduler pallet * Remove use of trait Store from scored-pool pallet * Remove use of trait Store from society pallet * Remove use of trait Store from lottery pallet * Remove use of trait Store from executive pallet * Remove use of trait Store from democracy pallet * Remove use of trait Store from elections-phragmen pallet * Remove use of trait Store from indices pallet * Remove use of trait Store from identity pallet * Remove use of trait Store from multisig pallet * Remove use of trait Store from merkle-mountain-range pallet * Remove use of trait Store from im-online pallet * Remove use of trait Store from membership pallet * Remove use of trait Store from nicks pallet * Remove use of trait Store from session pallet * Remove use of trait Store from transaction-payment pallet * Remove use of trait Store from utility pallet * Remove use of trait Store from child-bounties pallet * Remove use of trait Store from nis pallet * Remove use of trait Store from nfts pallet * Remove use of trait Store from conviction-voting pallet * Remove use of trait Store from treasury pallet * Remove use of trait Store from vesting pallet * Remove use of trait Store from preimage pallet * Remove use of trait Store from uniques pallet * Remove use of trait Store from ranked-collective pallet * Remove use of trait Store from beefy-mmr pallet * Remove use of trait Store from referenda pallet * Remove use of trait Store from whitelist pallet * Remove use of trait Store from alliance pallet * Remove use of trait Store from nomination-pools pallet * Remove use of trait Store from state-trie-migration pallet * Remove use of trait Store from message-queue pallet * Remove use of trait Store from root-offences pallet * Remove use of trait Store from root-testing pallet * Remove use of trait Store from timestamps pallet * Remove use of trait Store from system pallet * Remove use of trait Store from offences pallet * Remove use of trait Store from recovery pallet * Remove use of trait Store from node-authorization pallet * Remove use of trait Store from proxy pallet * Remove use of trait Store from benchmarking pallet * Remove use of trait Store from bags-list pallet * Add deprecated warning in store_trait * Change warning message * Run cargo fmt * Fix warning and update tests * Remove unnecessary allow deprecated * Remove use of trait Store * Fix mismatch in expected output * Minor update to warning message for deprecation of generate_store with Store trait attribute * Fixes as per review comments * Fixes as per review suggestions * Remove use of Store trait from core-fellowship pallet * Fix type in store_trait.rs * Fixes as pre review comment
Transaction Storage Pallet
Indexes transactions and manages storage proofs.
Allows storing arbitrary data on the chain. Data is automatically removed after StoragePeriod blocks, unless the storage is renewed.
Validators must submit proof of storing a random chunk of data for block N - StoragePeriod when producing block N.
Running a chain
The following describes how to set up a new storage chain.
Start with generating a chain spec.
cargo run --release -- build-spec --chain=local > sc_init.json
Edit the json chain spec file to customise the chain. The storage chain genesis params are configured in the transactionStorage section.
Note that storagePeriod is specified in blocks and changing it also requires code changes at the moment.
Build a raw spec from the init spec.
cargo run --release build-spec --chain=sc_init.json --raw > sc.json
Run a few validator nodes.
cargo run --release -- --chain=sc.json -d /tmp/alice --storage-chain --keep-blocks=100800 --ipfs-server --validator --alice
cargo run --release -- --chain=sc.json -d /tmp/bob --storage-chain --keep-blocks=100800 --ipfs-server --validator --bob
--storage-chain enables transaction indexing.
--keep-blocks=100800 enables block pruning. The value here should be greater or equal than the storage period.
--ipfs-server enables serving stored content over IPFS.
Once the network is started, any other joining nodes need to sync with --sync=fast. Regular sync will fail because block pruning removes old blocks. The chain does not keep full block history.
cargo run --release -- --chain=sc.json -d /tmp/charlie --storage-chain --keep-blocks=100800 --ipfs-server --validator --charlie --sync=fast
Making transactions
To store data use the transactionStorage.store extrinsic. And IPFS CID can be generated from the Blake2-256 hash of the data.
const util_crypto = require('@polkadot/util-crypto');
const keyring_api = require('@polkadot/keyring');
const polkadot_api = require('@polkadot/api');
const fs = require('fs');
const multihash = require('multihashes');
const CID = require('cids')
const wsProvider = new polkadot_api.WsProvider();
const api = await polkadot_api.ApiPromise.create({ provider: wsProvider });
const keyring = new keyring_api.Keyring({ type: "sr25519" });
const alice = keyring.addFromUri("//Alice");
const file = fs.readFileSync('cute_kitten.jpeg');
const hash = util_crypto.blake2AsU8a(file)
const encoded_hash = multihash.encode(hash, 'blake2b-256');
const cid = new CID(1, 'blake2b-256', encoded_hash)
console.log(cid.toString());
const txHash = await api.tx.transactionStorage.store('0x' + file.toString('hex')).signAndSend(alice);
Data can be queried over IPFS
ipfs swarm connect <substrate peer address>
ipfs block get /ipfs/<CID> > kitten.jpeg
To renew data and prevent it from being disposed after the storage period, use transactionStorage.renew(block, index)
where block is the block number of the previous store or renew transction, and index is the index of that transaction in the block.
License: Apache-2.0