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

Some types and enum variants were not properly json-serializing #4980

Conversation

zajko
Copy link
Contributor

@zajko zajko commented Nov 26, 2024

The types/enum variants that changed:

  • DelegatorKind::Purse(uref_addr) (uref_addr used to json-serialize as array of u8, now it json-serializes as a base16 encoded string of that vec)
  • UnbondKind::DelegatedPurse (uref_addr) (uref_addr used to json-serialize as array of u8, now it json-serializes as a base16 encoded string of that vec)
  • StoredValue::RawBytes(raw_bytes_vec) -> raw_bytes_vec serialized as an array of u8, but based on how we serialize Bytes in StoredValue::ContractWasm::bytes I changed it that it serializes as a string (to be consistent with serialization of Bytes type)

This will affect casper-client-rs and sidecar.

@@ -283,7 +283,7 @@ impl<'a> TransactionV1Builder<'a> {

/// Returns a new `TransactionV1Builder` suitable for building a native change_bid_public_key
/// transaction.
pub fn new_change_bid_public_key<A: Into<U512>>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Piggy backed this fix, this function needs no templating

@zajko
Copy link
Contributor Author

zajko commented Nov 26, 2024

bors r+

casperlabs-bors-ng bot added a commit that referenced this pull request Nov 26, 2024
4980: Some types and enum variants were not properly json-serializing r=zajko a=zajko

The types/enum variants that changed:
* DelegatorKind::Purse(uref_addr) (uref_addr used to json-serialize as array of u8, now it json-serializes as a base16 encoded string of that vec)
* UnbondKind::DelegatedPurse (uref_addr) (uref_addr used to json-serialize as array of u8, now it json-serializes as a base16 encoded string of that vec)
* StoredValue::RawBytes(raw_bytes_vec) -> raw_bytes_vec serialized as an array of u8, but based on how we serialize Bytes in StoredValue::ContractWasm::bytes I changed it that it serializes as a string (to be consistent with serialization of Bytes type)

This will affect casper-client-rs and sidecar.

Co-authored-by: Jakub Zajkowski <[email protected]>
Copy link
Contributor

Build failed:

@zajko
Copy link
Contributor Author

zajko commented Nov 27, 2024

bors r+

Copy link
Contributor

Build succeeded:

@casperlabs-bors-ng casperlabs-bors-ng bot merged commit bf56812 into casper-network:feat-2.0 Nov 27, 2024
3 checks passed
@davidatwhiletrue
Copy link

@zajko @darthsiroftardis , the Write/BidKind key in a TransactionV1 execution results still serializes as an array of bytes. Should this merge have included this type and serialize as a string ?

{
  "key": "bid-addr-032f3fb80d362ad0a922f446915a259c9aaec9ba99292b3e50ff2359c458007309d5226438210d1819e584fa52307ff802f6d53db95badb73ece0022cc3f436a23",
  "kind": {
    "Write": {
      "BidKind": {
        "Delegator": {
          "delegator_kind": {
            "Purse": [
              213,
              34,
              100,
              56,
              33,
              13,
              24,
              25,
              229,
              132,
              250,
              82,
              48,
              127,
              248,
              2,
              246,
              213,
              61,
              185,
              91,
              173,
              183,
              62,
              206,
              0,
              34,
              204,
              63,
              67,
              106,
              35
            ]
          },
          "staked_amount": "800000000000",
          "bonding_purse": "uref-50a2fdb49a324493901ef5df0c729e57f58e183520d0817c536ca7bfcedccd06-007",
          "validator_public_key": "01fed662dc7f1f7af43ad785ba07a8cc05b7a96f9ee69613cfde43bc56bec1140b",
          "vesting_schedule": null
        }
      }
    }
  }
}

@zajko
Copy link
Contributor Author

zajko commented Dec 3, 2024

@davidatwhiletrue Could you give more detail on how you came to this result? Are you using latest feat-2.0 code? I used this code snippet:

    fn x() {
        let rng: &mut _ = &mut TestRng::new();
        let mut effects = Effects::new();
        let delegator_bid = DelegatorBid::locked(
            DelegatorKind::Purse(rng.gen()),
            U512::zero(),
            rng.gen(),
            PublicKey::random(rng),
            21423423234_u64,
        );
        let bid_kind = BidKind::Delegator(Box::new(delegator_bid));
        effects.push(TransformV2::new(
            Key::URef(rng.gen()),
            TransformKindV2::Write(StoredValue::BidKind(bid_kind)),
        ));
        let er2 = ExecutionResultV2 {
            initiator: InitiatorAddr::random(rng),
            error_message: None,
            limit: Gas::new(1),
            consumed: Gas::new(1),
            cost: U512::zero(),
            transfers: vec![],
            size_estimate: 555,
            effects,
        };
        let execution_result = Box::new(ExecutionResult::V2(er2));
        let q = SseData::TransactionProcessed {
            transaction_hash: Box::new(TransactionHash::random(rng)),
            initiator_addr: Box::new(InitiatorAddr::random(rng)),
            timestamp: Timestamp::now(),
            ttl: TimeDiff::from_millis(1234),
            block_hash: Box::new(BlockHash::random(rng)),
            execution_result,
            messages: vec![],
        };
        println!("{}", serde_json::to_string(&q).unwrap());
    }

And got the result:

    "TransactionProcessed": {
        "transaction_hash": {
            "Deploy": "2e5c9f04924fca26d3222851c3720f996a69ef02900650c3d3c827f4693ca2cd"
        },
        "initiator_addr": {
            "PublicKey": "0151d07ecd1c0854a8be124b42dc9d1cd2e0172eee5b37f31b1be2104127932311"
        },
        "timestamp": "2024-12-03T17:46:14.365Z",
        "ttl": "1s 234ms",
        "block_hash": "eda3997d3a4a5d92b4ee921310d8bd754024340cf5629ff00ca6ff733f8f1ad2",
        "execution_result": {
            "Version2": {
                "initiator": {
                    "PublicKey": "01a47b748616c97b93c92319cbf35b938740cd1b4b4f2b1df3cb807f9051768777"
                },
                "error_message": null,
                "limit": "1",
                "consumed": "1",
                "cost": "0",
                "transfers": [],
                "size_estimate": 555,
                "effects": [
                    {
                        "key": "uref-5055edbef6132a9717320f8064d5bea8c2cbb8b3c2f674cacbbaa384df321f84-004",
                        "kind": {
                            "Write": {
                                "BidKind": {
                                    "Delegator": {
                                        "delegator_kind": {
                                            "Purse": "00566af5fdac9a45141d2e75a833c3b9f5f84961307ceb48f82f2b2e3814d3bf"
                                        },
                                        "staked_amount": "0",
                                        "bonding_purse": "uref-792765d9c6820d9f76388fb5fe3fe8c8e8cd9555f3d83caf5d7c08064878a66e-003",
                                        "validator_public_key": "0139925c575b1b06ce5fd1e33de0db2b4f110e1c0f732103064d76c12fe93169ed",
                                        "vesting_schedule": {
                                            "initial_release_timestamp_millis": 21423423234,
                                            "locked_amounts": null
                                        }
                                    }
                                }
                            }
                        }
                    }
                ]
            }
        },
        "messages": []
    }
}

@davidatwhiletrue
Copy link

davidatwhiletrue commented Dec 4, 2024

@zajko , yes, I was using feat-2.0 branch.
Building sidecar from this branch fixes the problem. Thanks.

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.

4 participants