Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Remark storage #10698

Merged
merged 6 commits into from
Apr 18, 2022
Merged

Remark storage #10698

merged 6 commits into from
Apr 18, 2022

Conversation

arkpar
Copy link
Member

@arkpar arkpar commented Jan 19, 2022

This PR Implements https://github.com/paritytech/labs/issues/1

Integrate an IPFS server into Substrate. Populate with all data of remark-events seen. Polkadot-js can then very easily use this to upload data, reference them (via hash) in other transactions, and download via hash through general IPFS. Not good for large files, but great for data < 50kB which would otherwise be difficult to utilise on-chain in an integrated experience for Polkadot-js.

Implementation adds a new runtime function System::remark_with_index. Remark bodies are stored in the TRANSACTION column, much like indexed storage chain content. Serving over IPFS is enabled with --ipfs-server

@arkpar arkpar added A0-please_review Pull request needs code review. B7-runtimenoteworthy C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Jan 19, 2022
/// # </weight>
#[pallet::weight(T::SystemWeightInfo::remark_with_event(remark.len() as u32))]
//#[pallet::weight(T::SystemWeightInfo::remark_with_index(remark.len() as u32))]
pub fn remark_with_index(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to have this part of frame-system?

This will bleed into any chain using Substrate, including Polkadot/Kusama.

Copy link
Member Author

@arkpar arkpar Jan 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a standalone chain, but a substrate feature indeed. @gavofyork suggested it should be enabled on kusama and eventually polkadot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but that could also be done by a special pallet.

I mean parachains will then also get this functionality etc. IMO we should not enable this by default everywhere. Yes, everybody could filter the call, but that sounds more like a hack to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I'll move it to a separate pallet.

@arkpar arkpar added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Jan 20, 2022
@stale
Copy link

stale bot commented Feb 19, 2022

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Feb 19, 2022
@arkpar
Copy link
Member Author

arkpar commented Feb 19, 2022

Waiting on #10779

@stale stale bot removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Feb 19, 2022
@arkpar arkpar force-pushed the a-ipfs-remark branch 2 times, most recently from 484cce7 to de84ade Compare March 11, 2022 08:38
@arkpar arkpar added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Mar 15, 2022
@arkpar
Copy link
Member Author

arkpar commented Mar 15, 2022

@bkchr This is ready for review again

+ GetDispatchInfo
+ From<frame_system::Call<Self>>;
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also have a

// Origin that control the ability to index a remark.
type ControlOrigin: frame_support::traits::EnsureOrigin<Self::Origin>;

but I don't think it is necessary at this point.

Copy link
Contributor

@cheme cheme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic looks good, wonder a bit about the naming.

The PR could call system remark internally, but I don't think it is needed, and I really like this better.
Still, we use a different event, and the pallet could be named differently than pallet-remark (to avoid confusion with system remark). But really depends on the directions that the pallet may take.

One point I find interesting, is that this will only serve content as long as state is not pruned, may need to be extended.
A second point is that sp-io transaction host function are now not only for transaction; and could be renamed (as long as no non test runtime uses them), for instance 'offchain_indexed' instead of 'transaction_index', but maybe offchain is also confusing due to other existing offchain substrate functionalities.
Also been wondering if at some point an api that do not put the ipfs content in block could be interesting (would act like here but with content fetched from ipfs).

(I also added myself a TODO to implement Reference and Release for paritydb (I just realized it is missing))

@arkpar
Copy link
Member Author

arkpar commented Mar 16, 2022

Logic looks good, wonder a bit about the naming.

The PR could call system remark internally, but I don't think it is needed, and I really like this better. Still, we use a different event, and the pallet could be named differently than pallet-remark (to avoid confusion with system remark). But really depends on the directions that the pallet may take.

This is supposed to be a new version of the remark function. Eventually System::remark should be deprecated.

One point I find interesting, is that this will only serve content as long as state is not pruned, may need to be extended.

That's not correct. Nothing is saved in the state here. Remarks are stored as block bodies basically. They will be kept around unless block body pruning is enabled.

A second point is that sp-io transaction host function are now not only for transaction; and could be renamed (as long as no non test runtime uses them), for instance 'offchain_indexed' instead of 'transaction_index', but maybe offchain is also confusing due to other existing offchain substrate functionalities.

Host function names are not that important. Besides, I think the name is still relevant. transaction_index refers to the fact that a slice of the transaction data is indexed. Which is still true for remarks.

@cheme
Copy link
Contributor

cheme commented Mar 16, 2022

That's not correct. Nothing is saved in the state here. Remarks are stored as block bodies basically. They will be kept around unless block body pruning is enabled.

👍 yes, I confused block pruning with state pruning while reading.

pub fn store(origin: OriginFor<T>, remark: Vec<u8>) -> DispatchResultWithPostInfo {
ensure!(!remark.is_empty(), Error::<T>::Empty);
let sender = ensure_signed(origin)?;
let content_hash = sp_io::hashing::blake2_256(&remark);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use the T::Hashing for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have now seen it is because of the transaction indexing. But that should have maybe been generic as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hashing scheme has to match the scheme supported by the IPFS bitswap server. The generic parameter would need to be propagated to sc-network module somehow. For not it is hardcoded to blake2

frame/remark/src/lib.rs Outdated Show resolved Hide resolved
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
@stale
Copy link

stale bot commented Apr 18, 2022

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Apr 18, 2022
@arkpar
Copy link
Member Author

arkpar commented Apr 18, 2022

bot merge

@stale stale bot removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Apr 18, 2022
@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot paritytech-processbot bot merged commit 0a7e5ea into master Apr 18, 2022
@paritytech-processbot paritytech-processbot bot deleted the a-ipfs-remark branch April 18, 2022 10:39
godcodehunter pushed a commit to sensoriumxr/substrate that referenced this pull request Jun 22, 2022
* Remark storage

* Fixed benches

* Update frame/remark/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Fixed build

* Fixed build

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
DaviRain-Su pushed a commit to octopus-network/substrate that referenced this pull request Aug 23, 2022
* Remark storage

* Fixed benches

* Update frame/remark/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Fixed build

* Fixed build

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* Remark storage

* Fixed benches

* Update frame/remark/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Fixed build

* Fixed build

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants