Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
shasper
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository 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
shasper
Commits
4db98365
Commit
4db98365
authored
6 years ago
by
Wei Tang
Browse files
Options
Downloads
Patches
Plain Diff
Handle block vote cache
parent
1ee4a0d9
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
runtime/src/state.rs
+1
-1
1 addition, 1 deletion
runtime/src/state.rs
runtime/src/validation.rs
+26
-1
26 additions, 1 deletion
runtime/src/validation.rs
with
27 additions
and
2 deletions
runtime/src/state.rs
+
1
−
1
View file @
4db98365
...
...
@@ -22,7 +22,7 @@ pub struct ActiveState {
pub
recent_block_hashes
:
Vec
<
H256
>
,
}
#[derive(Encode,
Decode)]
#[derive(Encode,
Decode
,
Default
)]
pub
struct
BlockVoteInfo
{
pub
voter_indices
:
Vec
<
usize
>
,
pub
total_voter_deposits
:
u128
,
...
...
This diff is collapsed.
Click to expand it.
runtime/src/validation.rs
+
26
−
1
View file @
4db98365
use
primitives
::
H256
;
use
runtime_support
::
storage
::
StorageMap
;
use
state
::{
ActiveState
,
CrystallizedState
};
use
state
::{
ActiveState
,
CrystallizedState
,
BlockVoteInfo
};
use
attestation
::
AttestationRecord
;
use
consts
::
CYCLE_LENGTH
;
...
...
@@ -48,3 +48,28 @@ pub fn validate_attestation<JustifiedBlockHashes: StorageMap<u64, H256, Query=Op
attestation
.verify_signatures
(
&
parent_hashes
,
&
pubkeys
);
}
pub
fn
update_block_vote_cache
<
BlockVoteCache
:
StorageMap
<
H256
,
BlockVoteInfo
,
Query
=
Option
<
BlockVoteInfo
>>>
(
slot
:
u64
,
crystallized_state
:
&
CrystallizedState
,
active_state
:
&
ActiveState
,
attestation
:
&
AttestationRecord
)
{
let
parent_hashes
=
active_state
.signed_parent_block_hashes
(
slot
,
attestation
);
let
attestation_indices
=
crystallized_state
.attestation_indices
(
attestation
);
for
parent_hash
in
parent_hashes
{
if
attestation
.oblique_parent_hashes
.contains
(
&
parent_hash
)
{
continue
;
}
let
mut
info
=
BlockVoteCache
::
get
(
&
parent_hash
)
.unwrap_or_default
();
for
(
i
,
index
)
in
attestation_indices
.iter
()
.enumerate
()
{
if
attestation
.attester_bitfield
.has_voted
(
i
)
&&
!
info
.voter_indices
.contains
(
index
)
{
info
.voter_indices
.push
(
*
index
);
info
.total_voter_deposits
+=
crystallized_state
.validators
[
*
index
]
.balance
;
}
}
BlockVoteCache
::
insert
(
parent_hash
,
info
);
}
}
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