Files
pezkuwi-subxt/substrate/frame/transaction-storage
Oliver Tale-Yazdi 77321288c3 Fix Substrate features (#14660)
* Fix std, runtime-benchmarks and try-runtime features

zepter lint propagate-feature --feature try-runtime --left-side-feature-missing=ignore --workspace --fix --feature-enables-dep="try-runtime:frame-try-runtime"
zepter lint propagate-feature --feature runtime-benchmarks --left-side-feature-missing=ignore --workspace --fix --feature-enables-dep="runtime-benchmarks:frame-benchmarking"
zepter lint propagate-feature --feature std --left-side-feature-missing=ignore --workspace --fix

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add propagate feature CI check

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test CI by adding an error

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use --locked

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add help msg

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "Test CI by adding an error"

This reverts commit cf4ff6cc0632269b0a109e547686e5e3314b02de.

* Test CI by adding an error

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* No newline in help msg

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "Test CI by adding an error"

This reverts commit 5daa06ada8e01f5bebafb9d1c76804dd79bc1006.

* Test CI by adding an error

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "Test CI by adding an error"

This reverts commit ca15de5729507a564f140a10ec2e87b19516ec4c.

* Fix msg

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert back to master

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Re-do with Zepter v0.7.4

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update Zepter to 0.7.4

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Disable rococo try-runtime check

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

* More review fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
2023-08-01 20:25:59 +00:00
..
2023-08-01 20:25:59 +00:00
2021-08-05 12:07:23 +00:00

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