polkadot-js / api

Promise and RxJS APIs around Polkadot and Substrate based chains via RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata.
Apache License 2.0
1.07k stars 350 forks source link

Something Wrong with Democracy #4740

Closed AurevoirXavier closed 2 years ago

AurevoirXavier commented 2 years ago
image

Why the standard vote's first param is a bool?

It looks like you are using Vote instead of AccountVote.

https://github.com/paritytech/substrate/blame/master/frame/democracy/src/vote.rs#L70-L76 https://github.com/paritytech/substrate/blame/master/frame/democracy/src/vote.rs#L29-L34

And the call needs AccountVote.

https://github.com/paritytech/substrate/blob/master/frame/democracy/src/lib.rs#L700

jacogr commented 2 years ago

That is the UI rendering component - it doesn't render aye + conviction, it only renders the "aye". (It is a limited override only)

AurevoirXavier commented 2 years ago

That is the UI rendering component - it doesn't render aye + conviction, it only renders the "aye". (It is a limited override only)

I can't vote on my chain. But it was worked a few days ago. https://polkadot.js.org/apps/?rpc=wss://pangolin-rpc.darwinia.network#/democracy

react.01.387c2759.js:2 Uncaught Error: createType(Call):: Call: failed decoding democracy.vote:: Struct: failed on args: {"ref_index":"Compact<u32>","vote":"{\"_enum\":{\"Standard\":\"{\\\"vote\\\":\\\"u8\\\",\\\"balance\\\":\\\"u128\\\"}\",\"Split\":\"{\\\"aye\\\":\\\"u128\\\",\\\"nay\\\":\\\"u128\\\"}\"}}"}:: Struct: failed on vote: {"_enum":{"Standard":"{\"vote\":\"u8\",\"balance\":\"u128\"}","Split":"{\"aye\":\"u128\",\"nay\":\"u128\"}"}}:: Enum(Standard):: Struct: failed on vote: u8:: Assertion failed

I can vote from extrinsic.

image

I check the democracy pallet, I didn't find any new updates. Why Polkadot's component is different from ours?

jacogr commented 2 years ago

In the case of the Substrate-standard AccountVote metadata type path the vote value is aliased to a type that can do the aye + conviction encoding into a single u8 instead of every user having to encode that manually.

It implements the specialized encoding as found in Rust -

/// A number of lock periods, plus a vote, one way or the other.
#[derive(Copy, Clone, Eq, PartialEq, Default, RuntimeDebug, MaxEncodedLen)]
pub struct Vote {
    pub aye: bool,
    pub conviction: Conviction,
}

impl Encode for Vote {
    fn encode_to<T: Output + ?Sized>(&self, output: &mut T) {
        output.push_byte(u8::from(self.conviction) | if self.aye { 0b1000_0000 } else { 0 });
    }
}
jacogr commented 2 years ago

Applied wildcard matching on metadata type names in https://github.com/polkadot-js/api/pull/4741 - however this is a dangerous path, so would need to see the impact. (So it may be reverted if it "breaks the world" due to over-zealous matching)

polkadot-js-bot commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.