mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Update to parity-scale-codec (#3232)
* WIP: update codec * WIP * compiling * WIP * rename parity-scale-codec to codec * WIP * fix * remove old comments * use published crates * fix expected error msg * bump version * fmt and fix * remove old comment * fix wrong decoding impl * implement encode like for structures * undo removal of old pending changes * trailingzeroinput * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com> * update codec * fmt * version is 1.0.0 * show more error * fmt
This commit is contained in:
committed by
Bastian Köcher
parent
a0d442333f
commit
4ed67e03a4
@@ -35,7 +35,6 @@ mod pruning;
|
||||
|
||||
use std::fmt;
|
||||
use parking_lot::RwLock;
|
||||
use parity_codec as codec;
|
||||
use codec::Codec;
|
||||
use std::collections::{VecDeque, HashMap, hash_map::Entry};
|
||||
use noncanonical::NonCanonicalOverlay;
|
||||
@@ -71,7 +70,7 @@ pub enum Error<E: fmt::Debug> {
|
||||
/// Database backend error.
|
||||
Db(E),
|
||||
/// `Codec` decoding error.
|
||||
Decoding,
|
||||
Decoding(codec::Error),
|
||||
/// Trying to canonicalize invalid block.
|
||||
InvalidBlock,
|
||||
/// Trying to insert block with invalid number.
|
||||
@@ -82,11 +81,17 @@ pub enum Error<E: fmt::Debug> {
|
||||
DiscardingPinned,
|
||||
}
|
||||
|
||||
impl<E: fmt::Debug> From<codec::Error> for Error<E> {
|
||||
fn from(x: codec::Error) -> Self {
|
||||
Error::Decoding(x)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: fmt::Debug> fmt::Debug for Error<E> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Error::Db(e) => e.fmt(f),
|
||||
Error::Decoding => write!(f, "Error decoding slicable value"),
|
||||
Error::Decoding(e) => write!(f, "Error decoding slicable value: {}", e.what()),
|
||||
Error::InvalidBlock => write!(f, "Trying to canonicalize invalid block"),
|
||||
Error::InvalidBlockNumber => write!(f, "Trying to insert block with invalid number"),
|
||||
Error::InvalidParent => write!(f, "Trying to insert block with unknown parent"),
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
use std::fmt;
|
||||
use std::collections::{HashMap, VecDeque, hash_map::Entry};
|
||||
use super::{Error, DBValue, ChangeSet, CommitSet, MetaDb, Hash, to_meta_key};
|
||||
use crate::codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use log::trace;
|
||||
|
||||
const NON_CANONICAL_JOURNAL: &[u8] = b"noncanonical_journal";
|
||||
@@ -116,7 +116,7 @@ impl<BlockHash: Hash, Key: Hash> NonCanonicalOverlay<BlockHash, Key> {
|
||||
let last_canonicalized = db.get_meta(&to_meta_key(LAST_CANONICAL, &()))
|
||||
.map_err(|e| Error::Db(e))?;
|
||||
let last_canonicalized = match last_canonicalized {
|
||||
Some(buffer) => Some(<(BlockHash, u64)>::decode(&mut buffer.as_slice()).ok_or(Error::Decoding)?),
|
||||
Some(buffer) => Some(<(BlockHash, u64)>::decode(&mut buffer.as_slice())?),
|
||||
None => None,
|
||||
};
|
||||
let mut levels = VecDeque::new();
|
||||
@@ -134,7 +134,7 @@ impl<BlockHash: Hash, Key: Hash> NonCanonicalOverlay<BlockHash, Key> {
|
||||
let journal_key = to_journal_key(block, index);
|
||||
match db.get_meta(&journal_key).map_err(|e| Error::Db(e))? {
|
||||
Some(record) => {
|
||||
let record: JournalRecord<BlockHash, Key> = Decode::decode(&mut record.as_slice()).ok_or(Error::Decoding)?;
|
||||
let record: JournalRecord<BlockHash, Key> = Decode::decode(&mut record.as_slice())?;
|
||||
let inserted = record.inserted.iter().map(|(k, _)| k.clone()).collect();
|
||||
let overlay = BlockOverlay {
|
||||
hash: record.hash.clone(),
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
//! The changes are journaled in the DB.
|
||||
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use crate::codec::{Encode, Decode};
|
||||
use codec::{Encode, Decode};
|
||||
use crate::{CommitSet, Error, MetaDb, to_meta_key, Hash};
|
||||
use log::{trace, warn};
|
||||
|
||||
@@ -69,7 +69,7 @@ impl<BlockHash: Hash, Key: Hash> RefWindow<BlockHash, Key> {
|
||||
let last_pruned = db.get_meta(&to_meta_key(LAST_PRUNED, &()))
|
||||
.map_err(|e| Error::Db(e))?;
|
||||
let pending_number: u64 = match last_pruned {
|
||||
Some(buffer) => u64::decode(&mut buffer.as_slice()).ok_or(Error::Decoding)? + 1,
|
||||
Some(buffer) => u64::decode(&mut buffer.as_slice())? + 1,
|
||||
None => 0,
|
||||
};
|
||||
let mut block = pending_number;
|
||||
@@ -86,7 +86,7 @@ impl<BlockHash: Hash, Key: Hash> RefWindow<BlockHash, Key> {
|
||||
let journal_key = to_journal_key(block);
|
||||
match db.get_meta(&journal_key).map_err(|e| Error::Db(e))? {
|
||||
Some(record) => {
|
||||
let record: JournalRecord<BlockHash, Key> = Decode::decode(&mut record.as_slice()).ok_or(Error::Decoding)?;
|
||||
let record: JournalRecord<BlockHash, Key> = Decode::decode(&mut record.as_slice())?;
|
||||
trace!(target: "state-db", "Pruning journal entry {} ({} inserted, {} deleted)", block, record.inserted.len(), record.deleted.len());
|
||||
pruning.import(&record.hash, journal_key, record.inserted.into_iter(), record.deleted);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user