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
b0a4f34a
Commit
b0a4f34a
authored
5 years ago
by
Wei Tang
Browse files
Options
Downloads
Patches
Plain Diff
beacon: balance and validator init/slash mutators
parent
25b25a0b
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
beacon/src/executive/helpers/mod.rs
+1
-0
1 addition, 0 deletions
beacon/src/executive/helpers/mod.rs
beacon/src/executive/helpers/mutators.rs
+78
-0
78 additions, 0 deletions
beacon/src/executive/helpers/mutators.rs
with
79 additions
and
0 deletions
beacon/src/executive/helpers/mod.rs
+
1
−
0
View file @
b0a4f34a
mod
predicates
;
mod
accessors
;
mod
mutators
;
This diff is collapsed.
Click to expand it.
beacon/src/executive/helpers/mutators.rs
0 → 100644
+
78
−
0
View file @
b0a4f34a
use
crate
::
primitives
::
*
;
use
crate
::{
BeaconState
,
Config
,
Error
,
utils
,
consts
};
use
core
::
cmp
::
max
;
impl
<
C
:
Config
>
BeaconState
<
C
>
{
pub
fn
increase_balance
(
&
mut
self
,
index
:
ValidatorIndex
,
delta
:
Gwei
)
{
self
.balances
[
index
as
usize
]
+=
delta
;
}
pub
fn
decrease_balance
(
&
mut
self
,
index
:
ValidatorIndex
,
delta
:
Gwei
)
{
self
.balances
[
index
as
usize
]
=
self
.balances
[
index
as
usize
]
.saturating_sub
(
delta
);
}
pub
fn
initiate_validator_exit
(
&
mut
self
,
index
:
ValidatorIndex
)
{
if
self
.validators
[
index
as
usize
]
.exit_epoch
!=
consts
::
FAR_FUTURE_EPOCH
{
return
}
let
exit_epochs
=
self
.validators
.iter
()
.map
(|
v
|
v
.exit_epoch
)
.filter
(|
epoch
|
*
epoch
!=
consts
::
FAR_FUTURE_EPOCH
)
.collect
::
<
Vec
<
_
>>
();
let
mut
exit_queue_epoch
=
max
(
exit_epochs
.iter
()
.fold
(
0
,
|
a
,
b
|
max
(
a
,
*
b
)),
utils
::
activation_exit_epoch
::
<
C
>
(
self
.current_epoch
())
);
let
exit_queue_churn
=
self
.validators
.iter
()
.filter
(|
v
|
v
.exit_epoch
==
exit_queue_epoch
)
.count
()
as
u64
;
if
exit_queue_churn
>=
self
.validator_churn_limit
()
{
exit_queue_epoch
+=
1
;
}
let
validator
=
&
mut
self
.validators
[
index
as
usize
];
validator
.exit_epoch
=
exit_queue_epoch
;
validator
.withdrawable_epoch
=
validator
.exit_epoch
+
C
::
min_validator_withdrawability_delay
();
}
pub
fn
slash_validator
(
&
mut
self
,
slashed_index
:
ValidatorIndex
,
whistleblower_index
:
Option
<
ValidatorIndex
>
)
->
Result
<
(),
Error
>
{
let
current_epoch
=
self
.current_epoch
();
self
.initiate_validator_exit
(
slashed_index
);
self
.validators
[
slashed_index
as
usize
]
.slashed
=
true
;
self
.validators
[
slashed_index
as
usize
]
.withdrawable_epoch
=
max
(
self
.validators
[
slashed_index
as
usize
]
.withdrawable_epoch
,
current_epoch
+
C
::
epochs_per_slashings_vector
()
);
let
slashed_balance
=
self
.validators
[
slashed_index
as
usize
]
.effective_balance
;
self
.slashings
[
(
current_epoch
%
C
::
epochs_per_slashings_vector
())
as
usize
]
+=
slashed_balance
;
self
.decrease_balance
(
slashed_index
,
slashed_balance
/
C
::
min_slashing_penalty_quotient
());
let
proposer_index
=
self
.beacon_proposer_index
()
?
;
let
whistleblower_index
=
whistleblower_index
.unwrap_or
(
proposer_index
);
let
whistleblowing_reward
=
slashed_balance
/
C
::
whistleblower_reward_quotient
();
let
proposer_reward
=
whistleblowing_reward
/
C
::
proposer_reward_quotient
();
self
.increase_balance
(
proposer_index
,
proposer_reward
);
self
.increase_balance
(
whistleblower_index
,
whistleblowing_reward
-
proposer_reward
);
Ok
(())
}
}
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