Disable trieDB ref counting for now.
This commit is contained in:
parent
589ecf10af
commit
fab99e8538
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,6 +11,7 @@ Cargo.lock
|
||||
|
||||
# Generated by Cargo
|
||||
/target/
|
||||
/util/target
|
||||
|
||||
# vim stuff
|
||||
*.swp
|
||||
|
51
src/views.rs
51
src/views.rs
@ -61,6 +61,44 @@ impl<'a> Hashable for TransactionView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// View onto transaction rlp.
|
||||
pub struct AccountView<'a> {
|
||||
rlp: Rlp<'a>
|
||||
}
|
||||
|
||||
impl<'a> AccountView<'a> {
|
||||
/// Creates new view onto block from raw bytes.
|
||||
pub fn new(bytes: &'a [u8]) -> AccountView<'a> {
|
||||
AccountView {
|
||||
rlp: Rlp::new(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates new view onto block from rlp.
|
||||
pub fn new_from_rlp(rlp: Rlp<'a>) -> AccountView<'a> {
|
||||
AccountView {
|
||||
rlp: rlp
|
||||
}
|
||||
}
|
||||
|
||||
/// Return reference to underlaying rlp.
|
||||
pub fn rlp(&self) -> &Rlp<'a> {
|
||||
&self.rlp
|
||||
}
|
||||
|
||||
/// Get the nonce field of the transaction.
|
||||
pub fn nonce(&self) -> U256 { self.rlp.val_at(0) }
|
||||
|
||||
/// Get the gas_price field of the transaction.
|
||||
pub fn balance(&self) -> U256 { self.rlp.val_at(1) }
|
||||
|
||||
/// Get the gas field of the transaction.
|
||||
pub fn storage_root(&self) -> H256 { self.rlp.val_at(2) }
|
||||
|
||||
/// Get the value field of the transaction.
|
||||
pub fn code_hash(&self) -> H256 { self.rlp.val_at(3) }
|
||||
}
|
||||
|
||||
/// View onto block rlp.
|
||||
pub struct BlockView<'a> {
|
||||
rlp: Rlp<'a>
|
||||
@ -97,13 +135,13 @@ impl<'a> BlockView<'a> {
|
||||
}
|
||||
|
||||
/// Return List of transactions in given block.
|
||||
pub fn transaction_views(&self) -> Vec<TransactionView> {
|
||||
self.rlp.at(1).iter().map(|rlp| TransactionView::new_from_rlp(rlp)).collect()
|
||||
pub fn transactions(&self) -> Vec<Transaction> {
|
||||
self.rlp.val_at(1)
|
||||
}
|
||||
|
||||
/// Return List of transactions in given block.
|
||||
pub fn transactions(&self) -> Vec<Transaction> {
|
||||
self.rlp.val_at(1)
|
||||
pub fn transaction_views(&self) -> Vec<TransactionView> {
|
||||
self.rlp.at(1).iter().map(|rlp| TransactionView::new_from_rlp(rlp)).collect()
|
||||
}
|
||||
|
||||
/// Return transaction hashes.
|
||||
@ -116,6 +154,11 @@ impl<'a> BlockView<'a> {
|
||||
self.rlp.val_at(2)
|
||||
}
|
||||
|
||||
/// Return List of transactions in given block.
|
||||
pub fn uncle_views(&self) -> Vec<HeaderView> {
|
||||
self.rlp.at(2).iter().map(|rlp| HeaderView::new_from_rlp(rlp)).collect()
|
||||
}
|
||||
|
||||
/// Return list of uncle hashes of given block.
|
||||
pub fn uncle_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(2).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
|
@ -215,10 +215,14 @@ macro_rules! impl_hash {
|
||||
}
|
||||
impl fmt::Display for $from {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for i in self.0[0..3].iter() {
|
||||
for i in self.0[0..2].iter() {
|
||||
try!(write!(f, "{:02x}", i));
|
||||
}
|
||||
write!(f, "…{:02x}", self.0.last().unwrap())
|
||||
try!(write!(f, "…"));
|
||||
for i in self.0[$size - 4..$size].iter() {
|
||||
try!(write!(f, "{:02x}", i));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,7 +548,7 @@ mod tests {
|
||||
fn hash() {
|
||||
let h = H64([0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef]);
|
||||
assert_eq!(H64::from_str("0123456789abcdef").unwrap(), h);
|
||||
assert_eq!(format!("{}", h), "012345…ef");
|
||||
assert_eq!(format!("{}", h), "0123…89abcdef");
|
||||
assert_eq!(format!("{:?}", h), "0123456789abcdef");
|
||||
assert_eq!(h.hex(), "0123456789abcdef");
|
||||
assert!(h == h);
|
||||
|
@ -70,7 +70,9 @@ impl OverlayDB {
|
||||
let mut ret = 0u32;
|
||||
for i in self.overlay.drain().into_iter() {
|
||||
let (key, (value, rc)) = i;
|
||||
if rc != 0 {
|
||||
// until we figure out state trie pruning, only commit stuff when it has a strictly positive delkta of RCs -
|
||||
// this prevents RCs being reduced to 0 where the DB would pretent that the node had been removed.
|
||||
if rc > 0 {
|
||||
match self.payload(&key) {
|
||||
Some(x) => {
|
||||
let (back_value, back_rc) = x;
|
||||
|
@ -42,7 +42,7 @@ impl<'db> TrieDB<'db> {
|
||||
/// Panics, if `root` does not exist
|
||||
pub fn new(db: &'db HashDB, root: &'db H256) -> Self {
|
||||
if !db.exists(root) {
|
||||
flush(format!("Trie root not found {}", root));
|
||||
flushln!("TrieDB::new({}): Trie root not found!", root);
|
||||
panic!("Trie root not found!");
|
||||
}
|
||||
TrieDB {
|
||||
@ -258,10 +258,7 @@ impl<'a> TrieDBIterator<'a> {
|
||||
node: self.db.get_node(d)
|
||||
});
|
||||
match self.trail.last().unwrap().node {
|
||||
Node::Leaf(n, _) | Node::Extension(n, _) => {
|
||||
println!("Entering. Extend key {:?}, {:?}", self.key_nibbles, n.iter().collect::<Vec<_>>());
|
||||
self.key_nibbles.extend(n.iter());
|
||||
},
|
||||
Node::Leaf(n, _) | Node::Extension(n, _) => { self.key_nibbles.extend(n.iter()); },
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@ -288,11 +285,10 @@ impl<'a> Iterator for TrieDBIterator<'a> {
|
||||
(Status::Exiting, n) => {
|
||||
match n {
|
||||
Node::Leaf(n, _) | Node::Extension(n, _) => {
|
||||
println!("Exiting. Truncate key {:?}, {:?}", self.key_nibbles, n.iter().collect::<Vec<_>>());
|
||||
let l = self.key_nibbles.len();
|
||||
self.key_nibbles.truncate(l - n.len());
|
||||
},
|
||||
Node::Branch(_, _) => { println!("Exit branch. Pop {:?}.", self.key_nibbles); self.key_nibbles.pop(); },
|
||||
Node::Branch(_, _) => { self.key_nibbles.pop(); },
|
||||
_ => {}
|
||||
}
|
||||
self.trail.pop();
|
||||
@ -304,13 +300,13 @@ impl<'a> Iterator for TrieDBIterator<'a> {
|
||||
(Status::At, Node::Branch(_, _)) => self.next(),
|
||||
(Status::AtChild(i), Node::Branch(children, _)) if children[i].len() > 0 => {
|
||||
match i {
|
||||
0 => { println!("Enter first child of branch. Push {:?}.", self.key_nibbles); self.key_nibbles.push(0); },
|
||||
0 => self.key_nibbles.push(0),
|
||||
i => *self.key_nibbles.last_mut().unwrap() = i as u8,
|
||||
}
|
||||
self.descend_next(children[i])
|
||||
},
|
||||
(Status::AtChild(i), Node::Branch(_, _)) => {
|
||||
if i == 0 { println!("Enter first child of branch. Push {:?}.", self.key_nibbles); self.key_nibbles.push(0); }
|
||||
if i == 0 { self.key_nibbles.push(0); }
|
||||
self.next()
|
||||
},
|
||||
_ => panic!() // Should never see Entering or AtChild without a Branch here.
|
||||
|
Loading…
Reference in New Issue
Block a user