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

Payment api v2 #1468

Merged
merged 10 commits into from
Jan 27, 2023
Merged

Payment api v2 #1468

merged 10 commits into from
Jan 27, 2023

Conversation

Harrm
Copy link
Contributor

@Harrm Harrm commented Jan 12, 2023

Referenced issues

resolves #1449

Description of the Change

  • Fix encoding of RuntimeDispatchInfo
  • Introduce version 2 of payment_queryInfo RPC with addition of a new data structure for extrinsic weight.

It is worth noticing that version 2 is actually not yet used in Polkadot and Rococo, so it was not tested on a living network.

Benefits

  • Working payment_queryInfo RPC

Possible Drawbacks

  • None expected

@Harrm Harrm marked this pull request as ready for review January 17, 2023 18:51
@Harrm Harrm requested review from turuslan and xDimon January 18, 2023 13:18
@Harrm Harrm self-assigned this Jan 18, 2023
core/api/service/payment/requests/query_info.hpp Outdated Show resolved Hide resolved
core/runtime/runtime_api/impl/transaction_payment_api.cpp Outdated Show resolved Hide resolved
core/runtime/runtime_api/impl/transaction_payment_api.cpp Outdated Show resolved Hide resolved
core/primitives/runtime_dispatch_info.hpp Outdated Show resolved Hide resolved
core/scale/big_fixed_integers.hpp Show resolved Hide resolved
core/scale/big_fixed_integers.hpp Show resolved Hide resolved
Stream &operator>>(Stream &stream, Compact<N> &compact) {
scale::CompactInteger n;
stream >> n;
compact.number = n.convert_to<N>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it truncate or throw (e.g. 0x1_00u16 -> u8 or -1 -> u8)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made alias types for boost multiprecision numbers checked.

Copy link
Contributor

Choose a reason for hiding this comment

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

Multiprecision and standard integers behave differently.
(-1).convert_to<AnyUnsignedType> // good, std::range_error
(1 << 128).convert_to<u128> // good, std::range_error
(1 << 8).convert_to<u8> // bad, truncated

core/scale/big_fixed_integers.hpp Outdated Show resolved Hide resolved
core/scale/big_fixed_integers.hpp Outdated Show resolved Hide resolved
Comment on lines 138 to 153
for (size_t i = 0; i < BigIntegerTraits<N>::BIT_SIZE; i += 8) {
fixed.number |= N(stream.nextByte()) << i;
}
return stream;
}

template <typename Stream,
typename N,
typename = std::enable_if_t<Stream::is_encoder_stream>,
typename = std::enable_if_t<BigIntegerTraits<N>::value>>
Stream &operator<<(Stream &stream, EncodeAsFixed<N> fixed) {
constexpr size_t bits = BigIntegerTraits<N>::BIT_SIZE;
for (N i = 0; i < bits; i += 8) {
stream << fixed & 0xFF;
fixed >>= 8;
}
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 export_bits and import_bits functions.
Example of custom output iterator.

Maybe remove BIT_SIZE if it's not used elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The documentation was rather unclear about the exact format the bits are imported in (but in practice it's the correct lsb order) so I avoided it. However now these functions are used for all kinds of integers, not just from boost multiprecision.

Copy link
Contributor

Choose a reason for hiding this comment

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

They accept chunk_bit_width and bool lsb_or_msb.

BigIntegerTraits is only implemented for multiprecision types.
Standard integers are already encoded as fixed.

core/common/CMakeLists.txt Outdated Show resolved Hide resolved
core/primitives/runtime_dispatch_info.hpp Outdated Show resolved Hide resolved
core/runtime/runtime_api/impl/transaction_payment_api.cpp Outdated Show resolved Hide resolved
@Harrm Harrm requested review from turuslan and xDimon January 26, 2023 16:21
@Harrm Harrm requested a review from turuslan January 27, 2023 08:38
@Harrm Harrm merged commit aa34f26 into master Jan 27, 2023
@Harrm Harrm deleted the feature/payment-api-v2 branch January 27, 2023 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update payment query info
3 participants