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
deeae6a4
Commit
deeae6a4
authored
5 years ago
by
Wei Tang
Browse files
Options
Downloads
Patches
Plain Diff
beacon: compact_committees_root
parent
965927c0
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
beacon/src/config.rs
+5
-5
5 additions, 5 deletions
beacon/src/config.rs
beacon/src/executive/helpers/accessors.rs
+21
-0
21 additions, 0 deletions
beacon/src/executive/helpers/accessors.rs
with
26 additions
and
5 deletions
beacon/src/config.rs
+
5
−
5
View file @
deeae6a4
...
...
@@ -21,7 +21,7 @@ use serde::{Serialize, Deserialize};
use
crate
::
primitives
::{
H256
,
Uint
,
Signature
,
ValidatorId
};
/// BLS operations
pub
trait
BLSVerification
:
Clone
+
'static
{
pub
trait
BLSVerification
:
Default
+
Clone
+
'static
{
/// Verify BLS signature.
fn
verify
(
pubkey
:
&
ValidatorId
,
message
:
&
H256
,
signature
:
&
Signature
,
domain
:
u64
)
->
bool
;
/// Aggregate BLS public keys.
...
...
@@ -33,7 +33,7 @@ pub trait BLSVerification: Clone + 'static {
}
/// Run bls without any verification.
#[derive(Clone,
PartialEq,
Eq)]
#[derive(
Default,
Clone,
PartialEq,
Eq)]
#[cfg_attr(feature
=
"std"
,
derive(Debug))]
pub
struct
BLSNoVerification
;
...
...
@@ -53,7 +53,7 @@ impl BLSVerification for BLSNoVerification {
}
/// Constants used in beacon block.
pub
trait
Config
:
Clone
+
'static
{
pub
trait
Config
:
Default
+
Clone
+
'static
{
/// Digest hash function.
type
Digest
:
Digest
<
OutputSize
=
typenum
::
U32
>
;
type
MaxValidatorsPerCommittee
:
Unsigned
+
core
::
fmt
::
Debug
+
Clone
+
Eq
+
PartialEq
+
Default
;
...
...
@@ -212,7 +212,7 @@ pub trait Config: Clone + 'static {
}
}
#[derive(Clone,
PartialEq,
Eq)]
#[derive(
Default,
Clone,
PartialEq,
Eq)]
#[cfg_attr(feature
=
"std"
,
derive(Debug))]
#[cfg_attr(feature
=
"serde"
,
derive(Serialize,
Deserialize))]
pub
struct
MinimalConfig
<
BLS
>
(
PhantomData
<
BLS
>
);
...
...
@@ -300,7 +300,7 @@ impl<BLS: BLSVerification> Config for MinimalConfig<BLS> {
}
}
#[derive(Clone,
PartialEq,
Eq)]
#[derive(
Default,
Clone,
PartialEq,
Eq)]
#[cfg_attr(feature
=
"std"
,
derive(Debug))]
#[cfg_attr(feature
=
"serde"
,
derive(Serialize,
Deserialize))]
pub
struct
MainnetConfig
<
BLS
>
(
PhantomData
<
BLS
>
);
...
...
This diff is collapsed.
Click to expand it.
beacon/src/executive/helpers/accessors.rs
+
21
−
0
View file @
deeae6a4
use
crate
::
types
::
*
;
use
crate
::
primitives
::
*
;
use
crate
::{
BeaconState
,
Config
,
Error
,
utils
};
use
vecarray
::
VecArray
;
use
bm_le
::
tree_root
;
use
core
::
cmp
::{
max
,
min
};
impl
<
C
:
Config
>
BeaconState
<
C
>
{
...
...
@@ -165,6 +167,25 @@ impl<C: Config> BeaconState<C> {
offset
/
(
committee_count
/
C
::
slots_per_epoch
()))
}
pub
fn
compact_committees_root
(
&
self
,
epoch
:
Uint
)
->
Result
<
H256
,
Error
>
{
let
mut
committees
=
VecArray
::
<
CompactCommittee
<
C
>
,
C
::
ShardCount
>
::
default
();
let
start_shard
=
self
.start_shard
(
epoch
)
?
;
for
committee_number
in
0
..
self
.committee_count
(
epoch
)
{
let
shard
=
(
start_shard
+
committee_number
)
%
C
::
shard_count
();
for
index
in
self
.crosslink_committee
(
epoch
,
shard
)
?
{
let
validator
=
&
self
.validators
[
index
as
usize
];
committees
[
shard
as
usize
]
.pubkeys
.push
(
validator
.pubkey
.clone
());
let
compact_balance
=
validator
.effective_balance
/
C
::
effective_balance_increment
();
let
compact_validator
=
(
index
<<
16
)
+
(
if
validator
.slashed
{
1
}
else
{
0
}
<<
15
)
+
compact_balance
;
committees
[
shard
as
usize
]
.compact_validators
.append
(
compact_validator
);
}
}
Ok
(
tree_root
::
<
C
::
Digest
,
_
>
(
&
committees
))
}
pub
fn
domain
(
&
self
,
domain_type
:
Uint
,
message_epoch
:
Option
<
Uint
>
)
->
Uint
{
let
epoch
=
message_epoch
.unwrap_or
(
self
.current_epoch
());
let
fork_version
=
if
epoch
<
self
.fork.epoch
{
...
...
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