From e762ef5904cbf1b66d4e50c711131060a75730fa Mon Sep 17 00:00:00 2001 From: Aaron Blankstein Date: Thu, 8 Apr 2021 11:54:10 -0500 Subject: [PATCH] fix: better deserialization error handling --- CHANGELOG.md | 8 +- Cargo.lock | 228 ---------------------------------- README.md | 17 +++ src/vm/types/serialization.rs | 6 +- 4 files changed, 26 insertions(+), 233 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72ea630b9..3de265b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +and this project adheres to the versioning scheme outlined in the [README.md](README.md). + +## [2.0.10.0.1] + +This is a low-priority hotfix release to address a bug in the deserialization logic. The +chainstate directory of 2.0.10.0.1 is compatible with 2.0.10. This release also begins the +usage of the versioning scheme outlined in the [README.md](README.md). ## [2.0.10] diff --git a/Cargo.lock b/Cargo.lock index 6d2bbab8c..fdb265ba3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,7 +237,6 @@ version = "0.0.1" dependencies = [ "assert-json-diff", "chrono", - "criterion", "curve25519-dalek", "ed25519-dalek", "integer-sqrt", @@ -282,18 +281,6 @@ dependencies = [ "slab", ] -[[package]] -name = "bstr" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" -dependencies = [ - "lazy_static", - "memchr", - "regex-automata", - "serde", -] - [[package]] name = "buf_redux" version = "0.8.4" @@ -338,15 +325,6 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" -[[package]] -name = "cast" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" -dependencies = [ - "rustc_version", -] - [[package]] name = "cc" version = "1.0.66" @@ -378,17 +356,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "clap" -version = "2.33.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" -dependencies = [ - "bitflags", - "textwrap", - "unicode-width", -] - [[package]] name = "clear_on_drop" version = "0.2.4" @@ -459,42 +426,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "criterion" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70daa7ceec6cf143990669a04c7df13391d55fb27bd4079d252fca774ba244d8" -dependencies = [ - "atty", - "cast", - "clap", - "criterion-plot", - "csv", - "itertools", - "lazy_static", - "num-traits", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_cbor", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e022feadec601fba1649cfa83586381a4ad31c6bf3a9ab7d408118b05dd9889d" -dependencies = [ - "cast", - "itertools", -] - [[package]] name = "crossbeam-channel" version = "0.4.3" @@ -553,28 +484,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "csv" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279" -dependencies = [ - "bstr", - "csv-core", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" -dependencies = [ - "memchr", -] - [[package]] name = "curve25519-dalek" version = "2.0.0" @@ -653,12 +562,6 @@ dependencies = [ "sha2 0.8.2", ] -[[package]] -name = "either" -version = "1.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" - [[package]] name = "encoding_rs" version = "0.8.23" @@ -897,12 +800,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "half" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" - [[package]] name = "hashbrown" version = "0.9.1" @@ -1084,15 +981,6 @@ dependencies = [ "libc", ] -[[package]] -name = "itertools" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "0.4.6" @@ -1413,12 +1301,6 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" -[[package]] -name = "oorandom" -version = "11.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a170cebd8021a008ea92e4db85a72f80b35df514ec664b296fdcbb654eac0b2c" - [[package]] name = "opaque-debug" version = "0.2.3" @@ -1577,18 +1459,6 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" -[[package]] -name = "plotters" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d1685fbe7beba33de0330629da9d955ac75bd54f33d7b79f9a895590124f6bb" -dependencies = [ - "js-sys", - "num-traits", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "ppv-lite86" version = "0.2.8" @@ -1848,31 +1718,6 @@ dependencies = [ "rand_core 0.3.1", ] -[[package]] -name = "rayon" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f02856753d04e03e26929f820d0a0a337ebe71f849801eea335d464b349080" -dependencies = [ - "autocfg 1.0.0", - "crossbeam-deque", - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e92e15d89083484e11353891f1af602cc661426deb9564c298b270c726973280" -dependencies = [ - "crossbeam-deque", - "crossbeam-queue", - "crossbeam-utils", - "lazy_static", - "num_cpus", -] - [[package]] name = "rdrand" version = "0.4.0" @@ -1911,15 +1756,6 @@ dependencies = [ "thread_local", ] -[[package]] -name = "regex-automata" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" -dependencies = [ - "byteorder", -] - [[package]] name = "regex-syntax" version = "0.6.18" @@ -2072,15 +1908,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - [[package]] name = "schannel" version = "0.1.19" @@ -2179,16 +2006,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde_cbor" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" -dependencies = [ - "half", - "serde", -] - [[package]] name = "serde_derive" version = "1.0.114" @@ -2528,15 +2345,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.20" @@ -2620,16 +2428,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11eeaa68267376df2aacbaaed9b0092544ebbc897cd59f61e81a1105fbaf102e" -[[package]] -name = "tinytemplate" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d3dc76004a03cec1c5932bca4cdc2e39aaa798e3f82363dd94f9adf6098c12f" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "tinyvec" version = "0.3.3" @@ -2802,12 +2600,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" - [[package]] name = "unicode-xid" version = "0.2.1" @@ -2861,17 +2653,6 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" -[[package]] -name = "walkdir" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" -dependencies = [ - "same-file", - "winapi 0.3.9", - "winapi-util", -] - [[package]] name = "want" version = "0.3.0" @@ -3030,15 +2811,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/README.md b/README.md index b563985a9..f60a58aa4 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,23 @@ according to the following rubric: - **Medium Priority**. Any fix for an issue that could cause miners to waste funds - **Low Priority**. Any fix for an issue that could deny service to individual nodes +## Versioning + +This repository uses a 5 part version number. + +``` +X.Y.Z.A.n + +X = 2 and does not change in practice unless there’s another Stacks 2.0 type event +Y increments on consensus-breaking changes +Z increments on non-consensus-breaking changes that require a fresh chainstate (akin to semantic MAJOR) +A increments on non-consensus-breaking changes that do not require a fresh chainstate, but introduce new features (akin to semantic MINOR) +n increments on patches and hot-fixes (akin to semantic PATCH) +``` + +For example, a node operator running version `2.0.10.0.0` would not need to wipe and refresh their chainstate +to upgrade to `2.0.10.1.0` or `2.0.10.0.1`. However, upgrading to `2.0.11.0.0` would require a new chainstate. + ## Roadmap - [x] [SIP 001: Burn Election](https://github.com/stacksgov/sips/blob/main/sips/sip-001/sip-001-burn-election.md) diff --git a/src/vm/types/serialization.rs b/src/vm/types/serialization.rs index e1ed18ad5..2e025a2b1 100644 --- a/src/vm/types/serialization.rs +++ b/src/vm/types/serialization.rs @@ -342,8 +342,7 @@ impl Value { r.read_exact(&mut data[..])?; - // can safely unwrap, because the buffer length was _already_ checked. - Ok(Value::buff_from(data).unwrap()) + Value::buff_from(data).map_err(|_| "Bad buffer".into()) } TypePrefix::BoolTrue => { check_match!(expected_type, TypeSignature::BoolType)?; @@ -517,8 +516,7 @@ impl Value { r.read_exact(&mut data[..])?; - // can safely unwrap, because the string length was _already_ checked. - Ok(Value::string_ascii_from_bytes(data).unwrap()) + Value::string_ascii_from_bytes(data).map_err(|_| "Bad string".into()) } TypePrefix::StringUTF8 => { let mut total_len = [0; 4];