Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
substrate
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Radu Popa
substrate
Commits
ffbe6283
Commit
ffbe6283
authored
6 years ago
by
Gav
Browse files
Options
Downloads
Patches
Plain Diff
Fix overflow bug.
parent
3b7e4e02
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/runtime/consensus/src/lib.rs
+10
-0
10 additions, 0 deletions
substrate/runtime/consensus/src/lib.rs
substrate/runtime/democracy/src/vote_threshold.rs
+6
-4
6 additions, 4 deletions
substrate/runtime/democracy/src/vote_threshold.rs
with
16 additions
and
4 deletions
substrate/runtime/consensus/src/lib.rs
+
10
−
0
View file @
ffbe6283
...
@@ -49,6 +49,8 @@ impl<S: codec::Slicable + Default> StorageVec for AuthorityStorageVec<S> {
...
@@ -49,6 +49,8 @@ impl<S: codec::Slicable + Default> StorageVec for AuthorityStorageVec<S> {
pub
const
CODE
:
&
'static
[
u8
]
=
b":code"
;
pub
const
CODE
:
&
'static
[
u8
]
=
b":code"
;
pub
type
KeyValue
=
(
Vec
<
u8
>
,
Vec
<
u8
>
);
pub
trait
Trait
:
system
::
Trait
{
pub
trait
Trait
:
system
::
Trait
{
type
PublicAux
:
RefInto
<
Self
::
AccountId
>
;
type
PublicAux
:
RefInto
<
Self
::
AccountId
>
;
type
SessionKey
:
Parameter
+
Default
;
type
SessionKey
:
Parameter
+
Default
;
...
@@ -61,6 +63,7 @@ decl_module! {
...
@@ -61,6 +63,7 @@ decl_module! {
}
}
pub
enum
PrivCall
{
pub
enum
PrivCall
{
fn
set_code
(
new
:
Vec
<
u8
>
)
=
0
;
fn
set_code
(
new
:
Vec
<
u8
>
)
=
0
;
fn
set_storage
(
items
:
Vec
<
KeyValue
>
)
=
1
;
}
}
}
}
...
@@ -75,6 +78,13 @@ impl<T: Trait> Module<T> {
...
@@ -75,6 +78,13 @@ impl<T: Trait> Module<T> {
storage
::
unhashed
::
put_raw
(
CODE
,
&
new
);
storage
::
unhashed
::
put_raw
(
CODE
,
&
new
);
}
}
/// Set some items of storage.
fn
set_storage
(
items
:
Vec
<
KeyValue
>
)
{
for
i
in
&
items
{
storage
::
unhashed
::
put_raw
(
&
i
.0
,
&
i
.1
);
}
}
/// Report some misbehaviour.
/// Report some misbehaviour.
fn
report_misbehavior
(
_aux
:
&
T
::
PublicAux
,
_report
:
MisbehaviorReport
)
{
fn
report_misbehavior
(
_aux
:
&
T
::
PublicAux
,
_report
:
MisbehaviorReport
)
{
// TODO.
// TODO.
...
...
This diff is collapsed.
Click to expand it.
substrate/runtime/democracy/src/vote_threshold.rs
+
6
−
4
View file @
ffbe6283
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
//! Voting thresholds.
//! Voting thresholds.
use
primitives
::
traits
::
IntegerSquareRoot
;
use
primitives
::
traits
::
{
Zero
,
IntegerSquareRoot
}
;
use
codec
::{
Input
,
Slicable
};
use
codec
::{
Input
,
Slicable
};
use
rstd
::
ops
::{
Add
,
Mul
,
Div
};
use
rstd
::
ops
::{
Add
,
Mul
,
Div
};
...
@@ -58,17 +58,19 @@ pub trait Approved<Balance> {
...
@@ -58,17 +58,19 @@ pub trait Approved<Balance> {
fn
approved
(
&
self
,
approve
:
Balance
,
against
:
Balance
,
electorate
:
Balance
)
->
bool
;
fn
approved
(
&
self
,
approve
:
Balance
,
against
:
Balance
,
electorate
:
Balance
)
->
bool
;
}
}
impl
<
Balance
:
IntegerSquareRoot
+
Ord
+
Add
<
Balance
,
Output
=
Balance
>
+
Mul
<
Balance
,
Output
=
Balance
>
+
Div
<
Balance
,
Output
=
Balance
>
+
Copy
>
Approved
<
Balance
>
for
VoteThreshold
{
impl
<
Balance
:
IntegerSquareRoot
+
Zero
+
Ord
+
Add
<
Balance
,
Output
=
Balance
>
+
Mul
<
Balance
,
Output
=
Balance
>
+
Div
<
Balance
,
Output
=
Balance
>
+
Copy
>
Approved
<
Balance
>
for
VoteThreshold
{
/// Given `approve` votes for and `against` votes against from a total electorate size of
/// Given `approve` votes for and `against` votes against from a total electorate size of
/// `electorate` (`electorate - (approve + against)` are abstainers), then returns true if the
/// `electorate` (`electorate - (approve + against)` are abstainers), then returns true if the
/// overall outcome is in favour of approval.
/// overall outcome is in favour of approval.
fn
approved
(
&
self
,
approve
:
Balance
,
against
:
Balance
,
electorate
:
Balance
)
->
bool
{
fn
approved
(
&
self
,
approve
:
Balance
,
against
:
Balance
,
electorate
:
Balance
)
->
bool
{
let
voters
=
approve
+
against
;
let
voters
=
approve
+
against
;
let
sqrt_voters
=
voters
.integer_sqrt
();
if
sqrt_voters
.is_zero
()
{
return
false
;
}
match
*
self
{
match
*
self
{
VoteThreshold
::
SuperMajorityApprove
=>
VoteThreshold
::
SuperMajorityApprove
=>
voters
.integer_sqrt
()
*
approve
/
electorate
.integer_sqrt
()
>
against
,
approve
/
electorate
.integer_sqrt
()
>
against
/
sqrt_voters
,
VoteThreshold
::
SuperMajorityAgainst
=>
VoteThreshold
::
SuperMajorityAgainst
=>
approve
>
voters
.integer_sqrt
()
*
against
/
electorate
.integer_sqrt
(),
approve
/
sqrt_voters
>
against
/
electorate
.integer_sqrt
(),
VoteThreshold
::
SimpleMajority
=>
approve
>
against
,
VoteThreshold
::
SimpleMajority
=>
approve
>
against
,
}
}
}
}
...
...
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