Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add common types used by storage provider #44

Closed
wants to merge 2 commits into from

Conversation

aidan46
Copy link
Contributor

@aidan46 aidan46 commented May 24, 2024

Description

Add common lib for types used by different pallets. The common library will be extended when needed. This commit adds types that the storage provider pallet needs.

Implementation

All types have been documented in the code.
Types added:

  • ActorID -> Identifier for Actors.
  • Cid -> Identifier for a CID.
  • MinerId -> Tuple struct holding u32 identifying a miner.
  • Address -> Defines the protocol and data payload conversion from either a public key or a value.
  • Payload -> The data of the Address.
  • DelegatedAddress -> A "delegated" (f4) address.

The AccountIdConversion trait has been added to implement conversion between AccountId and other types. This trait has been implemented for MinerID.

Fixes #42

@aidan46 aidan46 self-assigned this May 24, 2024
@aidan46 aidan46 added the enhancement New feature or request label May 24, 2024
@aidan46 aidan46 linked an issue May 24, 2024 that may be closed by this pull request
aidan46 added 2 commits May 24, 2024 14:49
Add `common` lib for types used by different pallets. The `common`
library will be extended when needed. This commit adds types that the
storage provider pallet needs.

All types have been documented in the code.
Types added:
- `ActorID` -> Identifier for Actors.
- `Cid` -> Identifier for a CID.
- `MinerId` -> Tuple struct holding u32 identifying a miner.
- `Address` -> Defines the protocol and data payload conversion from
  either a public key or a value.
- `Payload` -> The data of the `Address`.
- `DelegatedAddress` -> A "delegated" (f4) address.

The `AccountIdConversion` trait has been added to implement conversion
between `AccountId` and other types. This trait has been implemented for
`MinerID`.
Copy link
Contributor

@th7nder th7nder left a comment

Choose a reason for hiding this comment

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

I just don't understand a lot about this PR, honestly :(

/// f0: ID protocol address.
ID(u64),
/// f1: SECP256K1 key address, 20 byte hash of PublicKey.
Secp256k1([u8; PAYLOAD_HASH_LEN]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need those addresses, payloads etc?
I thought that in Substrate, we only utilize like AccountId address which identifies an account and is the basis of the interaction with blockchain and is enough.

Those abstractions seem like a Filecoin only stuff which we don't need in our implementation.

pub mod registered_proof;

/// Identifier for Actors, includes builtin and initialized actors
pub type ActorID = u64;
Copy link
Contributor

Choose a reason for hiding this comment

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

There are no actors in substrate, are we trying to introduce them?

// Code modified from https://github.com/paritytech/polkadot/blob/rococo-v1/parachain/src/primitives.rs
/// Format is b"miner" ++ encode(minerId) ++ 00.... where 00... is indefinite trailing
/// zeroes to fill AccountId.
impl<T: Encode + Decode> AccountIdConversion<T> for MinerId {
Copy link
Contributor

Choose a reason for hiding this comment

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

How can we from the (conceptual point of view) create an AccountId from MinerId?
AccountId in Substrate is something like this.

While I can see a way, where we could convert an AccountId to a Miner, and the other way round using a Pallet and some state on a blockchain, I don't think it's possible doing it 'raw'.

pub type ActorID = u64;

/// Identifier for a CID
pub type Cid = String;
Copy link
Member

Choose a reason for hiding this comment

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

In storage we are currently using Cid from the rust-cid crate. Maybe it could also be used here

struct TrailingZeroInput<'a>(&'a [u8]);

impl<'a> codec::Input for TrailingZeroInput<'a> {
fn remaining_len(&mut self) -> Result<Option<usize>, CodecError> {
Copy link
Member

Choose a reason for hiding this comment

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

This always returns Ok(None). If implementation needs to yet be done. It might be better to leave the todo!() macro

@aidan46
Copy link
Contributor Author

aidan46 commented May 26, 2024

I will close this PR because during pallet implementation we will identify the common types used and place them in primitives/.

@aidan46 aidan46 closed this May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Add common types library
3 participants