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

Conversation

@dvc94ch
Copy link
Contributor

@dvc94ch dvc94ch commented Jul 20, 2019

Required for #3034 Closes #3150

cc @gavofyork @tomusdrw @cmichi

@dvc94ch dvc94ch added the A3-in_progress Pull request is in progress. No review needed at this stage. label Jul 20, 2019
@dvc94ch dvc94ch requested a review from tomusdrw July 20, 2019 10:24
@dvc94ch dvc94ch added this to the 2.0-k milestone Jul 20, 2019
@dvc94ch dvc94ch force-pushed the dvc-offchain-api branch from 4226ecb to e3b6d7b Compare July 20, 2019 17:17
@dvc94ch dvc94ch added A0-please_review Pull request needs code review. B2-breaksapi and removed A3-in_progress Pull request is in progress. No review needed at this stage. B2-breaksapi labels Jul 20, 2019

/// Returns currently configured authority key.
fn authority_key<TPair: crypto::Pair>(&self) -> Option<TPair>;
fn authority_key(&self, block_id: &BlockId<Block>) -> Option<Self::ConsensusPair>;
Copy link
Member

Choose a reason for hiding this comment

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

it's no worse than at present, so i'll let it pass, but in general i'd prefer to avoid any notion of "authority key" over this API. there should really just be the key store and if you want the Babe, Aura or Grandpa key, then you have to consult that module should implement/use a special off-chain API that allows you to find it.

Copy link
Member

Choose a reason for hiding this comment

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

this is because we already have no single key that could reasonably be considered the "authority key". authorities in polkadot will have:

  • network key
  • babe key
  • grandpa key
  • session-change key
  • controller account key
  • parachain attestation key

they're all equally "authority" keys, yet this API presupposes that there exists only a single one.

fn authority_key(&self, block_id: &BlockId<Block>) -> Option<Self::ConsensusPair>;

/// Returns currently configured finality gadget authority key.
fn fg_authority_key(&self, block_id: &BlockId<Block>) -> Option<Self::FinalityPair>;
Copy link
Member

Choose a reason for hiding this comment

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

same here.

kind: CryptoKind,
},
/// Use the key the block authoring algorithm uses.
AuthorityKey,
Copy link
Member

Choose a reason for hiding this comment

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

this really isn't a thing; the block authoring algorithm won't necessarily use a (single) key. it could be a multi-key system, it could be a PoW system, it could be a hash-chain based system. so i'd prefer to move away from this. that said, as a refactoring it can wait, but please create an issue for it and mark for substrate 2.0 release.

struct Factory {
Block = Block,
ConsensusPair = AuraPair,
FinalityPair = GrandpaPair,
Copy link
Member

Choose a reason for hiding this comment

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

again, not happy about this; i don't want to bake this stuff in; please mark for refactoring ASAP.

Copy link
Member

@gavofyork gavofyork left a comment

Choose a reason for hiding this comment

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

Achieves needed goals, but needs further refactoring for a clean API.

@gavofyork gavofyork added A6-mustntgrumble and removed A0-please_review Pull request needs code review. labels Jul 21, 2019
@cmichi
Copy link
Contributor

cmichi commented Jul 21, 2019

@dvc94ch Thanks, the srml/im-online part looks good to me!

Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Looks sane, although I'm not 100% what we are trying to achieve. Seems that previously the offchain worker code was deciding on the expected crypto type.

Now we have an enum and the matching types are hardcoded in the factory, I think it would be better to give more freedom to the users.
Also I think it might be a good idea to change the underlying API of keystore to actually support the different kinds of keys more explicitly (i.e. finality gadget, session, etc), than simply matching on the expected type and probing all possible options.

If the PR is mostly about refactoring then it's ok, although I think the original plan was also to relax the verify API a bit and have it accept raw public key instead of CryptoKey.


/// Encrypt a piece of data using given crypto key.
///
/// If `key` is `None`, it will attempt to use current authority key of `CryptoKind`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The docs in the entire PR could do with an update too.

.ok_or(())?;
Ok(Key::AuthorityKey(key))
}
CryptoKey::FgAuthorityKey => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Fg is super cryptic, can't we just call it finality_gadget_key?

}
}

enum LocalKey {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd merge the whole enum with Key for simplicity to be honest, but it's a really minor grumble

/// Opaque type for created crypto keys.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
/// Key to use in the offchain worker crypto api.
#[derive(Clone, Copy, PartialEq, Eq)]
Copy link
Contributor

Choose a reason for hiding this comment

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

We need Encode/Decode. Offchain workers users need a way to store that entity between runs.

@gavofyork gavofyork merged commit 5453dd1 into paritytech:master Jul 22, 2019
@gavofyork
Copy link
Member

Merged on the basis that it's urgently needed, is no worse than current, and that it'll be refactored away in the near future.

@gavofyork gavofyork mentioned this pull request Jul 22, 2019
7 tasks
@gnunicorn gnunicorn modified the milestones: 2.1, Polkadot Mar 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants