Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Use serde_json to export hardcoded sync #11601

Merged
merged 1 commit into from
Apr 6, 2020

Conversation

marktoda
Copy link

@marktoda marktoda commented Apr 4, 2020

The exported hardcoded sync was previously generating invalid JSON, with
the CHT list ending in a trailing comma. In order to remedy this, this
commit uses serde_json to serialize the SpecHardcodedSync struct
into valid JSON.

Fixes #11415

@marktoda
Copy link
Author

marktoda commented Apr 4, 2020

Example hardcoded sync generated with this commit:

{
  "header": "f90212a0f5c969f08ef1f8bfbbd2a57684736a16c6a162abf51910e88b22b22d18381426a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794005e288d713a5fb3d7c9cf1b43810a98688c7223a02b2436e6e50172a038462e46a9952e25912cdd57731dfe2abc6bd8985485c31aa00adbf48cdfda2c299bdc6afb90b2c718f77b5e5e046d9e106c2eb2335dec9b13a0a88c51bfaeb08845dd44c47b88489e5d4c6d145292d4b608c3d0fad8e23a4a81b9010018d1293d0d002108090024800204487408032dc104000032210040c28a13504156106c2118842e7040fac002170481394e80e2430801840ae8a1732280280020010800108638a08a1132d6f84491551326bb2c03304060ad0027d3a1a53cb03c7438674012044430040b4a6088a80c4aa400016610822490b540a63050811a481027c94662502644708462040005448300a5255942621a405014034ca45004044c1708081d2c03c9344029b662810c7404208acd9801680205076a84100bf4c1ee184642006402134f0a1900803637500a0456c281198052b1491656505263808668293cb5202a700049200240106b02491a8020c930c9d0010a100408c02cdc8707cd156f146e188395980183984a388397fdb4845e88229191707079652d786e706f6f6c2e636e2f5838a064065dc4a3a52b233cbc9fa16ea17d69501c51b5397a0b9f85dafb213ef5f11288f710f8bc003b5344",
  "totalDifficulty": "14835544454137159221048",
  "CHTs": [
    "0x0eb474b7721727204978e92e27d31cddff56471911e424a4c8271c35f9c982cc",
    "0xe10e94515fb5ffb7ffa9bf50db4a959b3f50c2ff75e0b8bd5f5e038749e52a11",
    "0x816e7463af7b5d2fcb804ba55f09e8452182b0ba6c995a34e144245d76333d55",
    "0x3793af64c1ddc07ab61b2ba120034d91c02183ff788f07d3120fd4e6a48305b5",
    "0x14c6106a17e041032210bfa0ca80d11860a1c6d95175d55eff39f97b8d8acded",
    "0x396f832bfa3a9c494e9245471f0e65552613d87b6fe62128103590d95de72c2d",
    "0xb060979f095c170a776b2b50a1e2ab0ffea80f6e522753fa36ad6f106ee32e9f",
    "0x8f452e7cbd8a333ed04d819a143a8d3a75fe8c58418e7fc420bb2a717c0d4d2f",
    "0x37fe1b0cf156bfc07571569af210540be753777903a308d5707538fffed75b59",
    "0x6f0561d017cfc123b3f0d37b044e4f7231516b8731a1cab89afb569238643c33",
    "0x3c1740c410a88c60fe8ccdc44e0ef2cf7f7314818dbf1648c01d0d94fbffc211",
    "0xfb98115a7d6df8aaa40115f883014fe97300869bc016648e918fbf2df9608d41",
    "0xef1099ab5ca4b79369048678d3ba78122fc081b00b6fd0f6907302a260d58266",
    "0x969575f411dd78fdc5b4def0331fc93702029cc3c78851331a0f47dd0faae70b",
    "0x9e53053e362be51c0fd25eaafd9e7c5c969d9f2ce8db4b3d4d830cbff347b0c8",
    ...
     "0x6b4ec62f8f95beca8c6bd0d25a8b9debf1b59b729fa31abc5ad3e17d76477872",
    "0x816c2c3b83858b377156dc8e2f88b907ff06190a22fc7e00007c4b25fd608f94",
    "0xfd72be02b6cdc046ea3942cf0ffd09e67efc9266b5129d29e8ead942abd50230",
    "0x7be66a44651819b33c78dc8c81a6f8f5ad7faf22d5cd255cc55c93635027a5d3",
    "0xc8982f24a647cba8aa25444bfeef73ab140d4fce05a75e82d59a987ac67e5ed2",
    "0xf0eefd002bcc938d31733caa8d978eab2035c6f28727f446f93939223414f207"
  ]
}

Copy link
Collaborator

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

lgtm, thanks! :)

ethcore/spec/src/spec.rs Outdated Show resolved Hide resolved
@marktoda marktoda force-pushed the marktoda-11415-fix-cht-json branch from d6284dc to de9baca Compare April 5, 2020 17:57
@marktoda marktoda requested a review from niklasad1 April 5, 2020 18:43
Copy link
Collaborator

@ordian ordian left a comment

Choose a reason for hiding this comment

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

Looks good.

Comment on lines 268 to 286
impl Serialize for SpecHardcodedSync {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut serialized = serializer.serialize_struct("SpecHardcodedSync", 3)?;

let header_str = format!("{:x}", self.header);
serialized.serialize_field("header", &header_str)?;

let total_difficulty_str = format!("{:?}", self.total_difficulty);
serialized.serialize_field("totalDifficulty", &total_difficulty_str)?;

serialized.serialize_field("CHTs", &self.chts)?;
serialized.end()
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would use a derived implementation for serde with custom attributes like
https://serde.rs/field-attrs.html#rename
https://serde.rs/field-attrs.html#serialize_with
as it's more future-proof e.g. when adding new fields.
But it'll probably be also more code, so it's fine as is.

Copy link
Author

Choose a reason for hiding this comment

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

Ah good idea -- it didn't turn out to even be too much more code. Added in latest update

ethcore/spec/src/spec.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this.

@marktoda marktoda force-pushed the marktoda-11415-fix-cht-json branch 6 times, most recently from 9448819 to 10d6ca7 Compare April 5, 2020 21:09
The exported hardcoded sync was previously generating invalid JSON, with
the CHT list ending in a trailing comma. In order to remedy this, this
commit uses serde_json to serialize the SpecHardcodedSync struct
into valid JSON.

Fixes openethereum#11415
@marktoda marktoda force-pushed the marktoda-11415-fix-cht-json branch from 10d6ca7 to c866ada Compare April 5, 2020 22:10
@ordian ordian merged commit b683c22 into openethereum:master Apr 6, 2020
@marktoda marktoda deleted the marktoda-11415-fix-cht-json branch April 6, 2020 15:44
dvdplm added a commit that referenced this pull request Apr 14, 2020
* master: (25 commits)
  Update .gitmodules (#11628)
  ethcore/res: activate ecip-1088 phoenix on classic (#11598)
  Upgrade parity-common deps to latest (#11620)
  Fix Goerli syncing (#11604)
  deps: switch to upstream ctrlc (#11617)
  Deduplicating crate dependencies (part 3 of n) (#11614)
  Deduplicating crate dependencies (part 2 of n, `slab`) (#11613)
  Actually save ENR on creation and modification (#11602)
  Activate POSDAO on xDai chain and update bootnodes (#11610)
  Activate on-chain randomness in POA Core (#11609)
  Deduplicating crate dependencies (part 1 of n) (#11606)
  Update enodes for POA Sokol (#11611)
  Remove .git folder from dogerignore file so vergen library can get build date and commit hash in the binary generatio vergen library can get build date and commit hash in the binary generation (#11608)
  Reduced gas cost for static calls made to precompiles EIP2046/1352 (#11583)
  [easy] `ethcore-bloom-journal` was renamed to `accounts-bloom` (#11605)
  Use serde_json to export hardcoded sync (#11601)
  Node Discovery v4 ENR Extension (EIP-868) (#11540)
  Fix compile warnings (#11595)
  Update version to 3.0.0-alpha.1 (#11592)
  ethcore/res: bump canon fork hash for mordor and kotti testnets (#11584)
  ...
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.

[export hardcoded sync]: CHTs is invalid JSON
4 participants