mirror of https://github.com/poanetwork/quorum.git
Contract changes to remove canLead
This commit is contained in:
parent
1557f0ee2b
commit
efda58b5a5
|
@ -10,7 +10,6 @@ contract Permissions {
|
||||||
string ipAddrPort;
|
string ipAddrPort;
|
||||||
string discPort;
|
string discPort;
|
||||||
string raftPort;
|
string raftPort;
|
||||||
bool canLead;
|
|
||||||
NodeStatus status;
|
NodeStatus status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,32 +30,44 @@ contract Permissions {
|
||||||
// valid vote count
|
// valid vote count
|
||||||
mapping (uint => uint) private voteCount;
|
mapping (uint => uint) private voteCount;
|
||||||
|
|
||||||
// node permission events
|
// node permission events for new node propose
|
||||||
event NewNodeProposed(string _enodeId);
|
event NodeProposed(string _enodeId);
|
||||||
event VoteNodeApproval(string _enodeId, address _accountAddress);
|
|
||||||
event NodeApproved(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort);
|
event NodeApproved(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort);
|
||||||
|
event VoteNodeApproval(string _enodeId, address _accountAddress);
|
||||||
|
|
||||||
|
// node permission events for node decativation
|
||||||
event NodePendingDeactivation (string _enodeId);
|
event NodePendingDeactivation (string _enodeId);
|
||||||
event VoteNodeDeactivation(string _enodeId, address _accountAddress);
|
|
||||||
event NodeDeactivated(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort);
|
event NodeDeactivated(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort);
|
||||||
event NodePendingBlacklisting(string _enodeId);
|
event VoteNodeDeactivation(string _enodeId, address _accountAddress);
|
||||||
event VoteNodeBlacklisting(string _enodeId, address _accountAddress);
|
|
||||||
|
// node permission events for node blacklist
|
||||||
|
event NodePendingBlacklist(string _enodeId);
|
||||||
event NodeBlacklisted(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort);
|
event NodeBlacklisted(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort);
|
||||||
|
event VoteNodeBlacklist(string _enodeId, address _accountAddress);
|
||||||
|
|
||||||
// account permission events
|
// account permission events
|
||||||
event AccountAccessModified(address _address, AccountAccess _access);
|
event AccountAccessModified(address _address, AccountAccess _access);
|
||||||
|
|
||||||
|
// events related to voting accounts for majority voting
|
||||||
event NoVotingAccount();
|
event NoVotingAccount();
|
||||||
event VoterAdded(address _address);
|
event VoterAdded(address _address);
|
||||||
event VoterRemoved(address _address);
|
event VoterRemoved(address _address);
|
||||||
|
|
||||||
|
// Checks if the given enode exists
|
||||||
modifier enodeInList(string _enodeId)
|
modifier enodeInList(string _enodeId)
|
||||||
{
|
{
|
||||||
require(nodeIdToIndex[keccak256(abi.encodePacked(_enodeId))] != 0, "Enode is not in the list");
|
require(nodeIdToIndex[keccak256(abi.encodePacked(_enodeId))] != 0, "Enode is not in the list");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if the given enode does not exists
|
||||||
modifier enodeNotInList(string _enodeId)
|
modifier enodeNotInList(string _enodeId)
|
||||||
{
|
{
|
||||||
require(nodeIdToIndex[keccak256(abi.encodePacked(_enodeId))] == 0, "Enode is in the list");
|
require(nodeIdToIndex[keccak256(abi.encodePacked(_enodeId))] == 0, "Enode is in the list");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if the account can vote
|
||||||
modifier canVote()
|
modifier canVote()
|
||||||
{
|
{
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
|
@ -71,7 +82,6 @@ contract Permissions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* public and external functions */
|
/* public and external functions */
|
||||||
|
|
||||||
// view functions
|
// view functions
|
||||||
|
|
||||||
// Get number of nodes
|
// Get number of nodes
|
||||||
|
@ -122,20 +132,20 @@ contract Permissions {
|
||||||
// state change functions
|
// state change functions
|
||||||
|
|
||||||
// propose a new node to the network
|
// propose a new node to the network
|
||||||
function proposeNode(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort, bool _canLead) external enodeNotInList(_enodeId)
|
function proposeNode(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort) external enodeNotInList(_enodeId)
|
||||||
{
|
{
|
||||||
if (checkVotingAccountExist()){
|
if (checkVotingAccountExist()){
|
||||||
// increment node number, add node to the list
|
// increment node number, add node to the list
|
||||||
numberOfNodes++;
|
numberOfNodes++;
|
||||||
nodeIdToIndex[keccak256(abi.encodePacked(_enodeId))] = numberOfNodes;
|
nodeIdToIndex[keccak256(abi.encodePacked(_enodeId))] = numberOfNodes;
|
||||||
nodeList.push(NodeDetails(_enodeId, _ipAddrPort,_discPort, _raftPort, _canLead, NodeStatus.PendingApproval));
|
nodeList.push(NodeDetails(_enodeId, _ipAddrPort,_discPort, _raftPort, NodeStatus.PendingApproval));
|
||||||
// add voting status, numberOfNodes is the index of current proposed node
|
// add voting status, numberOfNodes is the index of current proposed node
|
||||||
for (uint i = 0; i < accountList.length; i++){
|
for (uint i = 0; i < accountList.length; i++){
|
||||||
voteStatus[numberOfNodes][accountList[i]] = false;
|
voteStatus[numberOfNodes][accountList[i]] = false;
|
||||||
}
|
}
|
||||||
voteCount[numberOfNodes] = 0;
|
voteCount[numberOfNodes] = 0;
|
||||||
// emit event
|
// emit event
|
||||||
emit NewNodeProposed(_enodeId);
|
emit NodeProposed(_enodeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +165,7 @@ contract Permissions {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Propose a node for deactivation from network
|
// Propose a node for deactivation from network
|
||||||
function ProposeDeactivation(string _enodeId) external enodeInList(_enodeId)
|
function proposeDeactivation(string _enodeId) external enodeInList(_enodeId)
|
||||||
{
|
{
|
||||||
if (checkVotingAccountExist()){
|
if (checkVotingAccountExist()){
|
||||||
require(getNodeStatus(_enodeId) == NodeStatus.Approved, "Node need to be in Approved status");
|
require(getNodeStatus(_enodeId) == NodeStatus.Approved, "Node need to be in Approved status");
|
||||||
|
@ -172,7 +182,7 @@ contract Permissions {
|
||||||
}
|
}
|
||||||
|
|
||||||
//deactivates a given Enode and emits the decativation event
|
//deactivates a given Enode and emits the decativation event
|
||||||
function DeactivateNode(string _enodeId) external canVote
|
function deactivateNode(string _enodeId) external canVote
|
||||||
{
|
{
|
||||||
require(getNodeStatus(_enodeId) == NodeStatus.PendingDeactivation, "Node need to be in PendingDeactivation status");
|
require(getNodeStatus(_enodeId) == NodeStatus.PendingDeactivation, "Node need to be in PendingDeactivation status");
|
||||||
uint nodeIndex = getNodeIndex(_enodeId);
|
uint nodeIndex = getNodeIndex(_enodeId);
|
||||||
|
@ -187,7 +197,7 @@ contract Permissions {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Propose node for blacklisting
|
// Propose node for blacklisting
|
||||||
function ProposeNodeBlacklisting(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort) external
|
function proposeNodeBlacklisting(string _enodeId, string _ipAddrPort, string _discPort, string _raftPort) external
|
||||||
{
|
{
|
||||||
if (checkVotingAccountExist()){
|
if (checkVotingAccountExist()){
|
||||||
uint nodeIndex;
|
uint nodeIndex;
|
||||||
|
@ -200,7 +210,7 @@ contract Permissions {
|
||||||
// increment node number, add node to the list
|
// increment node number, add node to the list
|
||||||
numberOfNodes++;
|
numberOfNodes++;
|
||||||
nodeIdToIndex[keccak256(abi.encodePacked(_enodeId))] = numberOfNodes;
|
nodeIdToIndex[keccak256(abi.encodePacked(_enodeId))] = numberOfNodes;
|
||||||
nodeList.push(NodeDetails(_enodeId, _ipAddrPort,_discPort, _raftPort, false, NodeStatus.PendingBlacklisting));
|
nodeList.push(NodeDetails(_enodeId, _ipAddrPort,_discPort, _raftPort, NodeStatus.PendingBlacklisting));
|
||||||
nodeIndex = numberOfNodes;
|
nodeIndex = numberOfNodes;
|
||||||
}
|
}
|
||||||
// add voting status, numberOfNodes is the index of current proposed node
|
// add voting status, numberOfNodes is the index of current proposed node
|
||||||
|
@ -209,12 +219,12 @@ contract Permissions {
|
||||||
}
|
}
|
||||||
voteCount[nodeIndex] = 0;
|
voteCount[nodeIndex] = 0;
|
||||||
// emit event
|
// emit event
|
||||||
emit NodePendingBlacklisting(_enodeId);
|
emit NodePendingBlacklist(_enodeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Approve node blacklisting
|
//Approve node blacklisting
|
||||||
function BlacklistNode(string _enodeId) external canVote
|
function blacklistNode(string _enodeId) external canVote
|
||||||
{
|
{
|
||||||
require(getNodeStatus(_enodeId) == NodeStatus.PendingBlacklisting, "Node need to be in PendingBlacklisting status");
|
require(getNodeStatus(_enodeId) == NodeStatus.PendingBlacklisting, "Node need to be in PendingBlacklisting status");
|
||||||
uint nodeIndex = getNodeIndex(_enodeId);
|
uint nodeIndex = getNodeIndex(_enodeId);
|
||||||
|
@ -223,7 +233,7 @@ contract Permissions {
|
||||||
voteStatus[nodeIndex][msg.sender] = true;
|
voteStatus[nodeIndex][msg.sender] = true;
|
||||||
voteCount[nodeIndex]++;
|
voteCount[nodeIndex]++;
|
||||||
// emit event
|
// emit event
|
||||||
emit VoteNodeBlacklisting(_enodeId, msg.sender);
|
emit VoteNodeBlacklist(_enodeId, msg.sender);
|
||||||
// check if node vote reach majority
|
// check if node vote reach majority
|
||||||
checkNodeBlacklisting(_enodeId);
|
checkNodeBlacklisting(_enodeId);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue