Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nucleo
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
blockchain
nucleo
Commits
0b4cb2b4
Commit
0b4cb2b4
authored
6 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:rlegene/bfa
parents
c294fdc9
e83f5ac2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+2
-2
2 additions, 2 deletions
README.md
bin/compile.and.deploy.contract
+0
-0
0 additions, 0 deletions
bin/compile.and.deploy.contract
src/Sealers.sol
+46
-21
46 additions, 21 deletions
src/Sealers.sol
with
48 additions
and
23 deletions
README.md
+
2
−
2
View file @
0b4cb2b4
...
@@ -47,14 +47,14 @@ request: **geth**
...
@@ -47,14 +47,14 @@ request: **geth**
Connects you to your running local geth.
Connects you to your running local geth.
## c
reate
.contract
## c
ompile.and.deploy
.contract
requires:
**geth**
,
**solc**
,
**jq**
requires:
**geth**
,
**solc**
,
**jq**
Compiles and deploys a contract to the blockchain. A local "node1" must already be running and synchronized.
Compiles and deploys a contract to the blockchain. A local "node1" must already be running and synchronized.
Argument 1 is the filename of the contract to compile.
Argument 1 is the filename of the contract to compile.
Example:
`c
reate
.contract src/TimestampAuthority.sol`
Example:
`c
ompile.and.deploy
.contract src/TimestampAuthority.sol`
## tsa-insert.sh
## tsa-insert.sh
requires:
**geth**
requires:
**geth**
...
...
This diff is collapsed.
Click to expand it.
bin/c
reate
.contract
→
bin/c
ompile.and.deploy
.contract
+
0
−
0
View file @
0b4cb2b4
File moved
This diff is collapsed.
Click to expand it.
src/
contract.
Sealers.sol
→
src/Sealers.sol
+
46
−
21
View file @
0b4cb2b4
...
@@ -19,7 +19,7 @@ contract Sealers {
...
@@ -19,7 +19,7 @@ contract Sealers {
address[] public sealers;
address[] public sealers;
Proposal[] public sealerproposals;
Proposal[] public sealerproposals;
event vote( address voter, address victim, bool promotionOrDemotion );
event vote
Cast
( address voter, address victim, bool promotionOrDemotion );
event adminChange( address admin, bool promotionOrDemotion );
event adminChange( address admin, bool promotionOrDemotion );
constructor() public
constructor() public
...
@@ -56,7 +56,7 @@ contract Sealers {
...
@@ -56,7 +56,7 @@ contract Sealers {
// Beware that:
// Beware that:
// 0 = not found.
// 0 = not found.
// 1 = first position.
// 1 = first position.
function _findAddressInList( address[] haystack, address needle ) private
view
returns (uint)
function _findAddressInList( address[] haystack, address needle ) private
pure
returns (uint)
{
{
uint i = haystack.length;
uint i = haystack.length;
while ( i-- > 0 )
while ( i-- > 0 )
...
@@ -130,7 +130,8 @@ contract Sealers {
...
@@ -130,7 +130,8 @@ contract Sealers {
// needs to be removed.
// needs to be removed.
function _trimProposals() private
function _trimProposals() private
{
{
for ( uint i = sealerproposals.length-1; i>=0; i-- )
uint i = sealerproposals.length;
while ( i-- > 0 )
{
{
// If a proposal is more than 30K blocks old, then remove it from the list.
// If a proposal is more than 30K blocks old, then remove it from the list.
if ( sealerproposals[i].votestart + 30000 <= block.number )
if ( sealerproposals[i].votestart + 30000 <= block.number )
...
@@ -138,6 +139,41 @@ contract Sealers {
...
@@ -138,6 +139,41 @@ contract Sealers {
}
}
}
}
// We run through the entire list of proposals, checking if they fulfill the
// requirements. Why the whole list? Because if a sealer is removed, whom has
// not yet voted for a proposal, that proposal may now have achieved majority.
function _promotedemote() private
{
uint prevlength = 0;
// Keep looping over the list until the number of proposals stops changing.
while ( prevlength != sealerproposals.length )
{
uint i = sealerproposals.length;
prevlength = i;
uint majority = sealers.length / 2 + 1;
// Loop over all proposals
while ( i-- > 0 )
{
// If we have enough votes to perform the actual promotion/demotion
if ( sealerproposals[i].voters.length >= majority )
{
// Is it a promotion or a demotion?
if ( sealerproposals[i].promotion )
// Add victim to sealer list
sealers.push( sealerproposals[i].victim );
else
// Remove victim from sealer list
_remove_sealer( sealerproposals[i].victim );
// Send notification
emit adminChange( sealerproposals[i].victim,
sealerproposals[i].promotion );
// Remove the proposal because the voting is complete.
_remove_proposal( i );
}
}
}
}
// Returns an index to the position of the proposal inside matching the [victim,promotion] tuple
// Returns an index to the position of the proposal inside matching the [victim,promotion] tuple
// Beware that:
// Beware that:
// 0 = not found.
// 0 = not found.
...
@@ -181,14 +217,14 @@ contract Sealers {
...
@@ -181,14 +217,14 @@ contract Sealers {
// As per usual, this requires n/2+1 votes.
// As per usual, this requires n/2+1 votes.
// The boolean must be true if you want to add a sealer
// The boolean must be true if you want to add a sealer
// and false if you want to remove one.
// and false if you want to remove one.
function
prom
ote( address victim, bool promotion ) public
function
v
ote( address victim, bool promotion ) public
{
{
if ( ! mayVote(msg.sender, victim, promotion))
if ( ! mayVote(msg.sender, victim, promotion))
revert("That seems redundant or is otherwise not allowed.");
revert("That seems redundant or is otherwise not allowed.");
_trimProposals();
_trimProposals();
// Send notification of the vote
// Send notification of the vote
emit vote( msg.sender, victim, promotion );
emit vote
Cast
( msg.sender, victim, promotion );
uint proppos = promotionIdx( victim, promotion );
uint proppos = promotionIdx( victim, promotion );
if ( proppos == 0 )
if ( proppos == 0 )
...
@@ -202,23 +238,12 @@ contract Sealers {
...
@@ -202,23 +238,12 @@ contract Sealers {
// Add our vote
// Add our vote
sealerproposals[proppos].voters.push( msg.sender );
sealerproposals[proppos].voters.push( msg.sender );
// Stop here if we do not have enough votes to perform the actual promotion/demotion
// See if we're ready to promote/demote anyone, based on the proposals.
if ( sealerproposals[proppos].voters.length < sealers.length/2+1 )
_promotedemote();
return;
// Remove the proposal because the voting is complete.
_remove_proposal( proppos );
// Is it a promotion or a demotion?
if ( promotion )
// Add victim to sealer list
sealers.push( victim );
else
// Remove victim from sealer list
_remove_sealer( victim );
// Send notification
// If we have no more sealers, we have no reason to live.
emit adminChange( victim, promotion );
if ( sealers.length == 0 )
selfdestruct( msg.sender );
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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