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

Fix (de)serialization of transaction for adding subnet validators #180

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

4tXJ7f
Copy link

@4tXJ7f 4tXJ7f commented Mar 31, 2024

No description provided.

Copy link
Collaborator

@richardpringle richardpringle left a comment

Choose a reason for hiding this comment

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

All tiny change requests. Thanks for the PR!

@@ -342,6 +342,7 @@ fn test_sort_output_owners() {
/// ref. <https://pkg.go.dev/github.com/ava-labs/avalanchego/vms/secp256k1fx#Input>
#[derive(Debug, Serialize, Deserialize, Eq, Clone, Default)]
pub struct Input {
#[serde(rename = "signatureIndices")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit:
Generally, it's probably better to do $[serde(rename_all = "camelCase")] so that you don't have to add this to every new field.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, forgot to mention that you would also need to rename the field to signature_indices.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you don't want to do this, I will still accept the PR

Copy link
Author

Choose a reason for hiding this comment

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

Nit: Generally, it's probably better to do $[serde(rename_all = "camelCase")] so that you don't have to add this to every new field.

Yeah, I've been considering that, but it doesn't quite work for some fields like node_id. Still, may be better to just add it.

pub subnet_auth: key::secp256k1::txs::Input,

/// To be updated after signing.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the skip_serializing_if actually necessary? Will an empty vector break something?

/// ref. <https://pkg.go.dev/github.com/ava-labs/avalanchego/vms/platformvm/txs#Tx.Sign>
/// ref. <https://pkg.go.dev/github.com/ava-labs/avalanchego/utils/crypto#PrivateKeyED25519.SignHash>
pub async fn sign<T: key::secp256k1::SignOnly>(&mut self, signers: Vec<Vec<T>>) -> Result<()> {
pub fn pack(&self) -> Result<packer::Packer> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't seem like there's any reason to change the public API here

Suggested change
pub fn pack(&self) -> Result<packer::Packer> {
fn pack(&self) -> Result<packer::Packer> {

@@ -405,3 +421,153 @@ fn test_add_subnet_validator_tx_serialization_with_one_signer() {
&tx_bytes_with_signatures
));
}

/// RUST_LOG=debug cargo test --package avalanche-types --lib -- platformvm::txs::add_subnet_validator::test_json_deserialize --exact --show-output
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know you're following a pattern, but I'm really not a fan of this. There are clear docs for how to run tests, there's no point in duplicating them and having to change this if we move any files/modules around.

Suggested change
/// RUST_LOG=debug cargo test --package avalanche-types --lib -- platformvm::txs::add_subnet_validator::test_json_deserialize --exact --show-output
/// RUST_LOG=debug cargo test --package avalanche-types --lib -- platformvm::txs::add_subnet_validator::test_json_deserialize --exact --show-output

Comment on lines 440 to 452
"amount": 19999999899000000 as u64,
"locktime": 0,
"threshold": 1
}
}
],
"inputs": [
{
"txID": "CjisYCwF4j7zSyC25MWR21e5xxzJgwdaLEuf7oBXSGpe3oaej",
"outputIndex": 0,
"assetID": "28VTWcsTZ55draGkmjdcS9CFFv4zC3PbvVjkyoqxzNC7Y5msRP",
"fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ",
"input": { "amount": 19999999900000000 as u64, "signatureIndices": [0] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"amount": 19999999899000000 as u64,
"locktime": 0,
"threshold": 1
}
}
],
"inputs": [
{
"txID": "CjisYCwF4j7zSyC25MWR21e5xxzJgwdaLEuf7oBXSGpe3oaej",
"outputIndex": 0,
"assetID": "28VTWcsTZ55draGkmjdcS9CFFv4zC3PbvVjkyoqxzNC7Y5msRP",
"fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ",
"input": { "amount": 19999999900000000 as u64, "signatureIndices": [0] }
"amount": 19999999899000000_u64,
"locktime": 0,
"threshold": 1
}
}
],
"inputs": [
{
"txID": "CjisYCwF4j7zSyC25MWR21e5xxzJgwdaLEuf7oBXSGpe3oaej",
"outputIndex": 0,
"assetID": "28VTWcsTZ55draGkmjdcS9CFFv4zC3PbvVjkyoqxzNC7Y5msRP",
"fxID": "spdxUxVJQbX85MGxMHbKw1sHxMnSqJ3QBzDyDYEP3h6TLuxqQ",
"input": { "amount": 19999999900000000_64, "signatureIndices": [0] }

Copy link
Collaborator

Choose a reason for hiding this comment

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

^

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I was running into issues with _u64, because it somehow still ended up being treated as an i32. With a u64 suffix, it works now.

@@ -21,6 +21,7 @@ pub struct Tx {
pub shares: u32,

/// To be updated after signing.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question: does it matter if we serialize the empty vector?

@4tXJ7f
Copy link
Author

4tXJ7f commented Apr 3, 2024

@richardpringle Thank you for the review! I believe I've addressed all of your comments.

@richardpringle
Copy link
Collaborator

Not sure what's going on with the tests here. Are you running cargo test --all-features locally?

@4tXJ7f
Copy link
Author

4tXJ7f commented Apr 12, 2024

Not sure what's going on with the tests here. Are you running cargo test --all-features locally?

Sorry, there were some places where I didn't update the names. Should be fixed now.

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.

2 participants