Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
parity-test-sync
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
parity-test-sync
Commits
18a6090c
Commit
18a6090c
authored
9 years ago
by
Marek Kotewicz
Browse files
Options
Downloads
Patches
Plain Diff
fixed trie_hash panic when he was processing duplicates
parent
706428ac
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/triehash.rs
+15
-7
15 additions, 7 deletions
src/triehash.rs
with
15 additions
and
7 deletions
src/triehash.rs
+
15
−
7
View file @
18a6090c
...
@@ -32,12 +32,12 @@ pub fn ordered_trie_root(input: Vec<Vec<u8>>) -> H256 {
...
@@ -32,12 +32,12 @@ pub fn ordered_trie_root(input: Vec<Vec<u8>>) -> H256 {
.into_iter
()
.into_iter
()
.fold
(
BTreeMap
::
new
(),
|
mut
acc
,
vec
|
{
.fold
(
BTreeMap
::
new
(),
|
mut
acc
,
vec
|
{
let
len
=
acc
.len
();
let
len
=
acc
.len
();
acc
.insert
(
as_nibbles
(
&
rlp
::
encode
(
&
len
)
)
,
vec
);
acc
.insert
(
rlp
::
encode
(
&
len
),
vec
);
acc
acc
})
})
// then move them to a vector
// then move them to a vector
.into_iter
()
.into_iter
()
.map
(|
p
|
p
)
.map
(|
(
k
,
v
)|
(
as_nibbles
(
&
k
),
v
)
)
.collect
();
.collect
();
gen_trie_root
(
gen_input
)
gen_trie_root
(
gen_input
)
...
@@ -62,11 +62,17 @@ pub fn ordered_trie_root(input: Vec<Vec<u8>>) -> H256 {
...
@@ -62,11 +62,17 @@ pub fn ordered_trie_root(input: Vec<Vec<u8>>) -> H256 {
/// assert_eq!(trie_root(v), H256::from_str(root).unwrap());
/// assert_eq!(trie_root(v), H256::from_str(root).unwrap());
/// }
/// }
/// ```
/// ```
pub
fn
trie_root
(
mut
input
:
Vec
<
(
Vec
<
u8
>
,
Vec
<
u8
>
)
>
)
->
H256
{
pub
fn
trie_root
(
input
:
Vec
<
(
Vec
<
u8
>
,
Vec
<
u8
>
)
>
)
->
H256
{
input
.sort
();
let
gen_input
=
input
let
gen_input
=
input
// first put elements into btree to sort them and to remove duplicates
.into_iter
()
.into_iter
()
.map
(|(
k
,
v
)|
(
as_nibbles
(
&
k
),
v
))
.fold
(
BTreeMap
::
new
(),
|
mut
acc
,
(
k
,
v
)
|
{
acc
.insert
(
k
,
v
);
acc
})
// then move them to a vector
.into_iter
()
.map
(|(
k
,
v
)|
(
as_nibbles
(
&
k
),
v
)
)
.collect
();
.collect
();
gen_trie_root
(
gen_input
)
gen_trie_root
(
gen_input
)
...
@@ -139,6 +145,7 @@ fn as_nibbles(bytes: &[u8]) -> Vec<u8> {
...
@@ -139,6 +145,7 @@ fn as_nibbles(bytes: &[u8]) -> Vec<u8> {
fn
hash256rlp
(
input
:
&
[(
Vec
<
u8
>
,
Vec
<
u8
>
)],
pre_len
:
usize
,
stream
:
&
mut
RlpStream
)
{
fn
hash256rlp
(
input
:
&
[(
Vec
<
u8
>
,
Vec
<
u8
>
)],
pre_len
:
usize
,
stream
:
&
mut
RlpStream
)
{
let
inlen
=
input
.len
();
let
inlen
=
input
.len
();
//println!("input: {:?}", input);
// in case of empty slice, just append empty data
// in case of empty slice, just append empty data
if
inlen
==
0
{
if
inlen
==
0
{
stream
.append_empty_data
();
stream
.append_empty_data
();
...
@@ -167,6 +174,7 @@ fn hash256rlp(input: &[(Vec<u8>, Vec<u8>)], pre_len: usize, stream: &mut RlpStre
...
@@ -167,6 +174,7 @@ fn hash256rlp(input: &[(Vec<u8>, Vec<u8>)], pre_len: usize, stream: &mut RlpStre
cmp
::
min
(
key
.shared_prefix_len
(
&
k
),
acc
)
cmp
::
min
(
key
.shared_prefix_len
(
&
k
),
acc
)
});
});
println!
(
"shared_prefix: {}, prefix_len: {}"
,
shared_prefix
,
pre_len
);
// if shared prefix is higher than current prefix append its
// if shared prefix is higher than current prefix append its
// new part of the key to the stream
// new part of the key to the stream
// then recursively append suffixes of all items who had this key
// then recursively append suffixes of all items who had this key
...
@@ -192,8 +200,8 @@ fn hash256rlp(input: &[(Vec<u8>, Vec<u8>)], pre_len: usize, stream: &mut RlpStre
...
@@ -192,8 +200,8 @@ fn hash256rlp(input: &[(Vec<u8>, Vec<u8>)], pre_len: usize, stream: &mut RlpStre
// cout how many successive elements have same next nibble
// cout how many successive elements have same next nibble
let
len
=
match
begin
<
input
.len
()
{
let
len
=
match
begin
<
input
.len
()
{
true
=>
input
[
begin
..
]
.iter
()
true
=>
input
[
begin
..
]
.iter
()
.
map
(|
pair
|
pair
.0
[
pre_len
]
)
.
take_while
(|
pair
|
{
println!
(
"{:?}"
,
pair
.0
);
pair
.0
[
pre_len
]
==
i
})
.count
(),
.take_while
(|
&
q
|
q
==
i
)
.count
(),
//
.take_while(|&q| q == i).count(),
false
=>
0
false
=>
0
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment