updated code comments

This commit is contained in:
vsmk98 2019-02-13 12:31:11 +08:00
parent 0b6e64f250
commit b0cd2b5ef2
12 changed files with 123 additions and 186 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,6 @@
pragma solidity ^0.5.3;
contract Clusterkeys {
// Struct for managing the org details
enum Operation {None, Add, Delete}
struct OrgKeyDetails {
@ -16,7 +15,6 @@ contract Clusterkeys {
uint keyCount;
OrgKeyDetails []orgKeys;
mapping (bytes32 => uint) orgKeyIndex;
}
OrgDetails [] private orgList;
mapping(bytes32 => uint) private OrgIndex;
@ -72,42 +70,48 @@ contract Clusterkeys {
event VoterDeleted(string _orgId, address _address);
// functions to test
/* public and external functions */
// view functions
// dummy function called from geth interface to check of the contract is deployed
function checkOrgContractExists() external pure returns (bool){
return true;
}
// returns voter count for a given org
function getOrgVoteCount(string calldata _orgId) external view returns (uint) {
return voteCount[getOrgIndex(_orgId)];
}
// returns pending operation details
function getPendingOp(string calldata _orgId) external view returns (string memory, Operation) {
uint i = getOrgIndex(_orgId);
return (orgList[i].pendingKey, orgList[i].pendingOp);
}
function getVoteStatus(string calldata _orgId) external view returns (bool){
return voteStatus[getOrgIndex(_orgId)][msg.sender];
}
// All internal functions
// returns the voter index
function getVoterIndex(string memory _morgId, address _vAccount) internal view returns (uint)
{
uint morgIndex = getMasterOrgIndex(_morgId);
return masterOrgList[morgIndex].voterIndex[_vAccount] - 1;
}
// returns the org index for the org list
function getOrgIndex(string memory _orgId) internal view returns (uint)
{
return OrgIndex[keccak256(abi.encodePacked(_orgId))] - 1;
}
// returns the voter index for the org from voter list
// returns the master org index for the org from voter list
function getMasterOrgIndex(string memory _orgId) internal view returns (uint)
{
return MasterOrgIndex[keccak256(abi.encodePacked(_orgId))] - 1;
}
// returns the key index for the key usage list
// returns the key index from org key list
function getOrgKeyIndex(uint _orgIndex, string memory _tmKey) internal view returns (uint)
{
return orgList[_orgIndex].orgKeyIndex[keccak256(abi.encodePacked(_tmKey))] - 1;
@ -119,8 +123,8 @@ contract Clusterkeys {
return KeyIndex[keccak256(abi.encodePacked(_tmKey))] - 1;
}
// initialize the voter account votes to false. This will be called when a
// new item is initiated for approval
// initialize the voter account votes to false. This will be called
// when a new item is initiated for approval
function voterInit(string memory _orgId) internal {
uint orgIndex = getOrgIndex(_orgId);
uint morgIndex = getMasterOrgIndex(orgList[orgIndex].morgId);
@ -141,8 +145,8 @@ contract Clusterkeys {
}
}
// checks if enough votes have been cast for the pending operation. If yes
// returns true
// checks if enough votes have been cast for the pending operation.
// If yes returns true
function checkEnoughVotes (string memory _orgId, string memory _morgId) internal view returns (bool) {
uint orgIndex = getOrgIndex(_orgId);
uint morgIndex = getMasterOrgIndex(_morgId);
@ -150,6 +154,7 @@ contract Clusterkeys {
return (voteCount[orgIndex] > masterOrgList[morgIndex].validVoterCount / 2 );
}
// function to update key usage details at master org level for a key
function updateKeyUsage(string memory _tmKey, string memory _morgId, Operation op) internal {
uint keyIndex = getKeyIndex(_tmKey);
keyUsage[keyIndex].pending = false;
@ -214,31 +219,35 @@ contract Clusterkeys {
// All extenal view functions
// Get number of voters
function getNumberOfVoters(string memory _morgId) public view returns (uint)
function getNumberOfVoters(string calldata _morgId) external view returns (uint)
{
return masterOrgList[getMasterOrgIndex(_morgId)].voterCount;
}
// Get voter
function getVoter(string memory _morgId, uint i) public view returns (address _addr, bool _active)
// Get voter details
function getVoter(string calldata _morgId, uint i) external view returns (address _addr, bool _active)
{
uint morgIndex = getMasterOrgIndex(_morgId);
return (masterOrgList[morgIndex].voterList[i].vAccount, masterOrgList[morgIndex].voterList[i].active);
}
// returns the number of orgs
function getNumberOfOrgs() external view returns (uint){
return orgNum;
}
// returns the total number of keys for a given org
function getOrgKeyCount(string calldata _orgId) external view returns (uint){
return orgList[getOrgIndex(_orgId)].orgKeys.length;
}
// returns org key details based on org id and key index
function getOrgKey(string calldata _orgId, uint _keyIndex) external view returns (string memory, bool){
uint orgIndex = getOrgIndex(_orgId);
return (orgList[orgIndex].orgKeys[_keyIndex].tmKey,orgList[orgIndex].orgKeys[_keyIndex].active);
}
// returns org and master org details based on org index
function getOrgInfo(uint _orgIndex) external view returns (string memory, string memory){
return (orgList[_orgIndex].orgId, orgList[_orgIndex].morgId);
}
@ -250,12 +259,12 @@ contract Clusterkeys {
return (!(masterOrgList[morgIndex].voterIndex[account] == 0));
}
// checks if the voter account is already in the voter accounts list for the org
// checks if the voting accounts exists for the org
function checkVotingAccountExists(string calldata _orgId) external view returns (bool)
{
uint orgIndex = getOrgIndex(_orgId);
uint vorgIndex = getMasterOrgIndex(orgList[orgIndex].morgId);
return (masterOrgList[vorgIndex].validVoterCount > 0);
uint morgIndex = getMasterOrgIndex(orgList[orgIndex].morgId);
return (masterOrgList[morgIndex].validVoterCount > 0);
}
// function to check if morg exists

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -20,6 +20,7 @@ type OrgKeyCtrl struct {
km *pbind.Cluster
}
// Creates the controls structure for org key management
func NewOrgKeyCtrl(node *node.Node) (*OrgKeyCtrl, error) {
stateReader, _, err := controls.CreateEthClient(node)
if err != nil {
@ -35,24 +36,27 @@ func NewOrgKeyCtrl(node *node.Node) (*OrgKeyCtrl, error) {
return &OrgKeyCtrl{stateReader, node.GetNodeKey(), km}, nil
}
// This function first adds the node list from permissioned-nodes.json to
// the permissiones contract deployed as a precompile via genesis.json
// starts the org key management services
func (k *OrgKeyCtrl) Start() error {
_, err := pbind.NewClusterFilterer(params.QuorumPrivateKeyManagementContract, k.ethClient)
// check if permissioning contract is there at address. If not return from here
if err != nil {
log.Error("Cluster not enabled for the network : ", "err", err)
return nil
}
// check if permissioning contract is there at address. If not return from here
err = k.checkIfContractExists()
if err != nil {
return err
}
// start the service
k.manageClusterKeys()
return nil
}
// checks if the contract is deployed for org key management
func (k *OrgKeyCtrl) checkIfContractExists() error {
auth := bind.NewKeyedTransactor(k.key)
clusterSession := &pbind.ClusterSession{
@ -68,6 +72,7 @@ func (k *OrgKeyCtrl) checkIfContractExists() error {
},
}
// dummy call to contrat to check if the contract is deployed
_, err := clusterSession.CheckOrgContractExists()
if err != nil {
return err
@ -76,6 +81,8 @@ func (k *OrgKeyCtrl) checkIfContractExists() error {
return nil
}
// in case of geth restart firts checks for historical key update events and
// populates the cache, then starts the key change monitoring service
func (k *OrgKeyCtrl) manageClusterKeys() error {
//call populate nodes to populate the nodes into contract
if err := k.populatePrivateKeys(); err != nil {
@ -87,6 +94,7 @@ func (k *OrgKeyCtrl) manageClusterKeys() error {
}
// populates cache based on the historical key change events.
func (k *OrgKeyCtrl) populatePrivateKeys() error {
cluster, err := pbind.NewClusterFilterer(params.QuorumPrivateKeyManagementContract, k.ethClient)
if err != nil {
@ -122,12 +130,14 @@ func (k *OrgKeyCtrl) populatePrivateKeys() error {
return nil
}
// service to monitor key change events
func (k *OrgKeyCtrl) monitorKeyChanges() {
go k.monitorKeyAdd()
go k.monitorKeyDelete()
}
// monitors for new key added event and updates caches based on the same
func (k *OrgKeyCtrl) monitorKeyAdd() {
cluster, err := pbind.NewClusterFilterer(params.QuorumPrivateKeyManagementContract, k.ethClient)
if err != nil {
@ -153,6 +163,7 @@ func (k *OrgKeyCtrl) monitorKeyAdd() {
}
}
// monitors for new key delete event and updates caches based on the same
func (k *OrgKeyCtrl) monitorKeyDelete() {
cluster, err := pbind.NewClusterFilterer(params.QuorumPrivateKeyManagementContract, k.ethClient)
if err != nil {

View File

@ -12,7 +12,6 @@ contract Permissions {
NodeStatus status;
}
// use an array to store node details
// if we want to list all node one day, mapping is not capable
NodeDetails[] private nodeList;
// use a mapping of enodeid to array index to track node
mapping (bytes32 => uint) private nodeIdToIndex;
@ -30,7 +29,6 @@ contract Permissions {
uint private numFullAccessAccts;
// use an array to store account details
// if we want to list all account one day, mapping is not capable
enum VoterStatus { Active, Inactive }
struct VoterAcctDetails {
address voterAcct;
@ -102,10 +100,12 @@ contract Permissions {
/* public and external functions */
// view functions
// get number of accounts in the init list given as per genesis.json
function getInitAccountsCount() external view returns (uint){
return initialAcctList.length;
}
// get number of accounts in the init list given as per genesis.json
// returns the numbers of accounts which will have full access
function getFullAccessAccountCount() external view returns (uint){
return numFullAccessAccts;
}
@ -120,20 +120,20 @@ contract Permissions {
{
return numberOfValidVoters;
}
// Get voter
// Get voter details given the voter index
function getVoter(uint i) external view returns (address _addr, VoterStatus _voterStatus)
{
return (voterAcctList[i].voterAcct, voterAcctList[i].voterStatus);
}
// Get number of nodes
// Get network boot status
function getNetworkBootStatus() external view returns (bool)
{
return networkBoot;
}
// Get node details given enode Id
function getNodeDetails(string memory enodeId) public view returns (string memory _enodeId, string memory _ipAddrPort, string memory _discPort, string memory _raftPort, NodeStatus _nodeStatus)
function getNodeDetails(string calldata enodeId) external view returns (string memory _enodeId, string memory _ipAddrPort, string memory _discPort, string memory _raftPort, NodeStatus _nodeStatus)
{
uint nodeIndex = getNodeIndex(enodeId);
if (nodeIdToIndex[keccak256(abi.encodePacked(enodeId))] != 0){
@ -143,34 +143,38 @@ contract Permissions {
return (enodeId, "", "", "", NodeStatus.NotInList);
}
}
// Get node details given index
function getNodeDetailsFromIndex(uint nodeIndex) public view returns (string memory _enodeId, string memory _ipAddrPort, string memory _discPort, string memory _raftPort, NodeStatus _nodeStatus)
function getNodeDetailsFromIndex(uint nodeIndex) external view returns (string memory _enodeId, string memory _ipAddrPort, string memory _discPort, string memory _raftPort, NodeStatus _nodeStatus)
{
return (nodeList[nodeIndex].enodeId, nodeList[nodeIndex].ipAddrPort, nodeList[nodeIndex].discPort, nodeList[nodeIndex].raftPort, nodeList[nodeIndex].status);
}
// Get number of nodes
function getNumberOfNodes() public view returns (uint)
function getNumberOfNodes() external view returns (uint)
{
return numberOfNodes;
}
// Get account details given index
function getAccountDetails(uint acctIndex) public view returns (address _acct, AccountAccess _acctAccess)
function getAccountDetails(uint acctIndex) external view returns (address _acct, AccountAccess _acctAccess)
{
return (acctAccessList[acctIndex].acctId, acctAccessList[acctIndex].acctAccess);
}
// Get number of accounts and voting accounts
function getNumberOfAccounts() public view returns (uint)
// Get number of accounts
function getNumberOfAccounts() external view returns (uint)
{
return acctAccessList.length;
}
// Get node status by enode id
function getNodeStatus(string memory _enodeId) public view enodeInList(_enodeId) returns (NodeStatus)
{
return nodeList[getNodeIndex(_enodeId)].status;
}
// checks if the given account is a voter account
function isVoter(address _acctid) external view returns (bool)
{
return ((voterAcctIndex[_acctid] != 0) &&
@ -185,6 +189,7 @@ contract Permissions {
return networkBoot;
}
// initializes the voting status for each voting account to false
function initNodeVoteStatus(uint nodeIndex) internal {
voteCount[nodeIndex] = 0;
for (uint i = 0; i < voterAcctList.length; i++){
@ -194,11 +199,13 @@ contract Permissions {
}
}
// updates the vote status and increses the vote count
function updateVoteStatus(uint nodeIndex) internal {
voteCount[nodeIndex]++;
voteStatus[nodeIndex][msg.sender] = true;
}
// checks if enough votes are received for the approval
function checkEnoughVotes(uint nodeIndex) internal view returns (bool) {
bool approvalStatus = false;
if (voteCount[nodeIndex] > numberOfValidVoters/2){
@ -236,7 +243,7 @@ contract Permissions {
}
}
// Adds a node to the nodeList mapping and emits node added event if successfully and node exists event of node is already present
// Adds a node to the nodeList mapping and emits node approved event if successful
function approveNode(string calldata _enodeId) external canVote
{
require(getNodeStatus(_enodeId) == NodeStatus.PendingApproval, "Node need to be in PendingApproval status");
@ -267,7 +274,7 @@ contract Permissions {
}
}
//deactivates a given Enode and emits the decativation event
//deactivates a given Enode and emits the node decativation event
function deactivateNode(string calldata _enodeId) external canVote
{
require(getNodeStatus(_enodeId) == NodeStatus.PendingDeactivation, "Node need to be in PendingDeactivation status");
@ -275,15 +282,14 @@ contract Permissions {
require(voteStatus[nodeIndex][msg.sender] == false, "Node can not double vote");
// vote node
updateVoteStatus(nodeIndex);
// emit event
// check if node vote reach majority
// check if node vote reachead majority and emit event
if (checkEnoughVotes(nodeIndex)) {
nodeList[nodeIndex].status = NodeStatus.Deactivated;
emit NodeDeactivated(nodeList[nodeIndex].enodeId, nodeList[nodeIndex].ipAddrPort, nodeList[nodeIndex].discPort, nodeList[nodeIndex].raftPort);
}
}
// Propose node for blacklisting
// Propose activation of a deactivated node
function proposeNodeActivation(string calldata _enodeId) external
{
if (checkVotingAccountExist()){
@ -298,7 +304,7 @@ contract Permissions {
}
}
//deactivates a given Enode and emits the decativation event
// Activates a given Enode and emits the node activated event
function activateNode(string calldata _enodeId) external canVote
{
require(getNodeStatus(_enodeId) == NodeStatus.PendingActivation, "Node need to be in PendingActivation status");
@ -306,8 +312,7 @@ contract Permissions {
require(voteStatus[nodeIndex][msg.sender] == false, "Node can not double vote");
// vote node
updateVoteStatus(nodeIndex);
// emit event
// check if node vote reach majority
// check if node vote reachead majority and emit event
if (checkEnoughVotes(nodeIndex)) {
nodeList[nodeIndex].status = NodeStatus.Approved;
emit NodeActivated(nodeList[nodeIndex].enodeId, nodeList[nodeIndex].ipAddrPort, nodeList[nodeIndex].discPort, nodeList[nodeIndex].raftPort);
@ -335,7 +340,6 @@ contract Permissions {
prependingStatus[nodeIndex] = NodeStatus.NotInList;
nodeIndex = numberOfNodes;
}
// add voting status, numberOfNodes is the index of current proposed node
initNodeVoteStatus(nodeIndex);
// emit event
emit NodePendingBlacklist(_enodeId);
@ -373,6 +377,8 @@ contract Permissions {
emit PendingOperationCancelled(_enodeId);
}
// sets the account access to full access for the initial list of accounts
// given as a part of genesis.json
function initAccounts() external
{
require(networkBoot == false, "network accounts already boot up");
@ -387,7 +393,7 @@ contract Permissions {
}
}
// Checks if the Node is already added. If yes then returns true
// updates accounts access
function updateAccountAccess(address _address, AccountAccess _accountAccess) external
{
// Check if account already exists
@ -411,7 +417,7 @@ contract Permissions {
emit AccountAccessModified(_address, _accountAccess);
}
// Add voting account
// Add voting account to the network
function addVoter(address _address) external
{
uint vId = getVoterIndex(_address);
@ -428,7 +434,8 @@ contract Permissions {
numberOfValidVoters ++;
}
}
// Remove voting account
// Remove voting account from the network
function removeVoter(address _address) external
{
uint vId = getVoterIndex(_address);
@ -438,39 +445,33 @@ contract Permissions {
}
}
function getVoteStatus(string memory _enodeId, address _address) public view returns (bool){
uint nodeIndex = getNodeIndex(_enodeId);
return voteStatus[nodeIndex][_address];
}
// returns total voter count and number of valid voter count
function getVoterCount() public view returns (uint, uint)
{
return (numberOfVoters,numberOfValidVoters);
}
function getVoteCount(string memory _enodeId) public view returns (uint)
{
uint nodeIndex = getNodeIndex(_enodeId);
return voteCount[nodeIndex];
}
/* private functions */
// Returns the node index based on enode id
function getNodeIndex(string memory _enodeId) internal view returns (uint)
{
return nodeIdToIndex[keccak256(abi.encodePacked(_enodeId))] - 1;
}
/* private functions */
// Returns the account index based on account id
function getAcctIndex(address _acct) internal view returns (uint)
{
return acctToIndex[_acct] - 1;
}
/* private functions */
// Returns the voter index based on account id
function getVoterIndex(address _acct) internal view returns (uint)
{
return voterAcctIndex[_acct] - 1;
}
// checks if voting account exists
function checkVotingAccountExist() internal view returns (bool)
{
return (!(numberOfValidVoters == 0));

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -85,7 +85,7 @@ func (p *PermissionCtrl) Start() error {
return nil
}
// This functions updates the initial values for the network
// Sets the initial values for the network
func (p *PermissionCtrl) init() error {
// populate the initial list of permissioned nodes and account accesses
if err := p.populateInitPermission(); err != nil {
@ -100,13 +100,6 @@ func (p *PermissionCtrl) init() error {
// set the default access to ReadOnly
types.SetDefaultAccess()
// call populates the node details from contract to KnownNodes
// this is not required as the permissioned node info is persisted at
// file level
// if err := p.populatePermissionedNodes(); err != nil {
// return err
// }
return nil
}
@ -116,7 +109,7 @@ func (p *PermissionCtrl) manageNodePermissions() {
//monitor for new nodes addition via smart contract
go p.monitorNewNodeAdd()
//monitor for nodes deletiin via smart contract
//monitor for nodes deletion via smart contract
go p.monitorNodeDeactivation()
//monitor for nodes activation from deactivation status
@ -126,7 +119,7 @@ func (p *PermissionCtrl) manageNodePermissions() {
go p.monitorNodeBlacklisting()
}
// This functions listens on the channel for new node approval via smart contract and
// Listens on the channel for new node approval via smart contract and
// adds the same into permissioned-nodes.json
func (p *PermissionCtrl) monitorNewNodeAdd() {
ch := make(chan *pbind.PermissionsNodeApproved, 1)
@ -148,8 +141,8 @@ func (p *PermissionCtrl) monitorNewNodeAdd() {
}
}
// This functions listens on the channel for new node approval via smart contract and
// adds the same into permissioned-nodes.json
// Listens on the channel for new node deactivation via smart contract
// and removes the same from permissioned-nodes.json
func (p *PermissionCtrl) monitorNodeDeactivation() {
ch := make(chan *pbind.PermissionsNodeDeactivated)
@ -170,8 +163,8 @@ func (p *PermissionCtrl) monitorNodeDeactivation() {
}
}
// This function listnes on the channel for any node blacklisting event via smart contract
// and adds the same disallowed-nodes.json
// Listnes on the channel for any node activation via smart contract
// and adds the same permissioned-nodes.json
func (p *PermissionCtrl) monitorNodeActivation() {
ch := make(chan *pbind.PermissionsNodeActivated, 1)
@ -192,7 +185,7 @@ func (p *PermissionCtrl) monitorNodeActivation() {
}
}
// This functions listens on the channel for node blacklisting via smart contract and
// Listens on the channel for node blacklisting via smart contract and
// adds the same into disallowed-nodes.json
func (p *PermissionCtrl) monitorNodeBlacklisting() {
ch := make(chan *pbind.PermissionsNodeBlacklisted)
@ -216,7 +209,7 @@ func (p *PermissionCtrl) monitorNodeBlacklisting() {
}
}
//this function populates the new node information into the permissioned-nodes.json file
// Populates the new node information into the permissioned-nodes.json file
func (p *PermissionCtrl) updatePermissionedNodes(enodeId, ipAddrPort, discPort, raftPort string, operation NodeOperation) {
log.Debug("updatePermissionedNodes", "DataDir", p.dataDir, "file", PERMISSIONED_CONFIG)
@ -270,7 +263,7 @@ func (p *PermissionCtrl) updatePermissionedNodes(enodeId, ipAddrPort, discPort,
mu.Unlock()
}
//this function populates the black listed node information into the permissioned-nodes.json file
//this function populates the black listed node information into the disallowed-nodes.json file
func (p *PermissionCtrl) updateDisallowedNodes(nodeBlacklistEvent *pbind.PermissionsNodeBlacklisted) {
log.Debug("updateDisallowedNodes", "DataDir", p.dataDir, "file", BLACKLIST_CONFIG)
@ -324,8 +317,7 @@ func (p *PermissionCtrl) manageAccountPermissions() {
return
}
// populates the nodes list from permissioned-nodes.json into the permissions
// smart contract
// populates the nodes list from permissioned-nodes.json into the permissions smart contract
func (p *PermissionCtrl) populatePermissionedNodes() error {
opts := &bind.FilterOpts{}
pastAddEvent, err := p.pm.PermissionsFilterer.FilterNodeApproved(opts)
@ -354,8 +346,7 @@ func (p *PermissionCtrl) populatePermissionedNodes() error {
return nil
}
// populates the nodes list from permissioned-nodes.json into the permissions
// smart contract
// populates the account permissions cache from past account access update events
func (p *PermissionCtrl) populateAcctPermissions() error {
opts := &bind.FilterOpts{}
pastEvents, err := p.pm.PermissionsFilterer.FilterAccountAccessModified(opts)
@ -373,8 +364,7 @@ func (p *PermissionCtrl) populateAcctPermissions() error {
return nil
}
// Monitors permissions changes at acount level and uodate the global permissions
// map with the same
// Monitors permissions changes at acount level and uodate the account permissions cache
func (p *PermissionCtrl) monitorAccountPermissions() {
ch := make(chan *pbind.PermissionsAccountAccessModified)
@ -430,8 +420,10 @@ func (p *PermissionCtrl) formatEnodeId(enodeId, ipAddrPort, discPort, raftPort s
return newEnodeId
}
//populates the nodes list from permissioned-nodes.json into the permissions
//smart contract
// Thus function checks if the its the initial network boot up and if yes
// populates the initial network enode details from static-nodes.json into
// smart contracts. Sets the accounts access to full access for the initial
// initial list of accounts as given in genesis.json file
func (p *PermissionCtrl) populateInitPermission() error {
auth := bind.NewKeyedTransactor(p.key)
permissionsSession := &pbind.PermissionsSession{
@ -523,7 +515,8 @@ func (p *PermissionCtrl) populateStaticNodesToContract(permissionsSession *pbind
return nil
}
// Reads the acount from geth keystore and grants full access to these accounts
// Invokes the initAccounts function of smart contract to set the initial
// set of accounts access to full access
func (p *PermissionCtrl) populateInitAccountAccess(permissionsSession *pbind.PermissionsSession) error {
_, err := permissionsSession.InitAccounts()
if err != nil {
@ -533,7 +526,7 @@ func (p *PermissionCtrl) populateInitAccountAccess(permissionsSession *pbind.Per
return nil
}
// update network boot status to true
// updates network boot status to true
func (p *PermissionCtrl) updateNetworkStatus(permissionsSession *pbind.PermissionsSession) error {
nonce := p.eth.TxPool().Nonce(permissionsSession.TransactOpts.From)
permissionsSession.TransactOpts.Nonce = new(big.Int).SetUint64(nonce)

View File

@ -263,6 +263,7 @@ func (s *QuorumControlsAPI) PermissionNodeList() []nodeStatus {
return nodeStatArr
}
// Returns the list of permissioned accounts and access type of each
func (s *QuorumControlsAPI) PermissionAccountList() []accountInfo {
if !s.permEnabled {
acctInfoArr := make([]accountInfo, 1)
@ -293,6 +294,7 @@ func (s *QuorumControlsAPI) PermissionAccountList() []accountInfo {
return acctInfoArr
}
// Returns the list of voters for node management
func (s *QuorumControlsAPI) VoterList() []string {
if !s.permEnabled {
voterArr := make([]string, 1)
@ -394,22 +396,22 @@ func (s *QuorumControlsAPI) ApproveNodeDeactivation(nodeId string, txa ethapi.Se
return s.executePermAction(ApproveNodeDeactivation, txArgs{nodeId: nodeId, txa: txa})
}
// DeactivateNode requests a node to get deactivated
// ActivateNode requests a deactivated node to get activated
func (s *QuorumControlsAPI) ProposeNodeActivation(nodeId string, txa ethapi.SendTxArgs) ExecStatus {
return s.executePermAction(ProposeNodeActivation, txArgs{nodeId: nodeId, txa: txa})
}
// ApproveDeactivateNode approves a node to get deactivated
// ApproveNodeActivation approves a node to get activated back
func (s *QuorumControlsAPI) ApproveNodeActivation(nodeId string, txa ethapi.SendTxArgs) ExecStatus {
return s.executePermAction(ApproveNodeActivation, txArgs{nodeId: nodeId, txa: txa})
}
// DeactivateNode requests a node to get deactivated
// Request a node to be blacklisted
func (s *QuorumControlsAPI) ProposeNodeBlacklisting(nodeId string, txa ethapi.SendTxArgs) ExecStatus {
return s.executePermAction(ProposeNodeBlacklisting, txArgs{nodeId: nodeId, txa: txa})
}
// ApproveDeactivateNode approves a node to get deactivated
// Approves blacklisting of a node proposed for blacklisting
func (s *QuorumControlsAPI) ApproveNodeBlacklisting(nodeId string, txa ethapi.SendTxArgs) ExecStatus {
return s.executePermAction(ApproveNodeBlacklisting, txArgs{nodeId: nodeId, txa: txa})
}
@ -424,21 +426,22 @@ func (s *QuorumControlsAPI) AddMasterOrg(morgId string, txa ethapi.SendTxArgs) E
return s.executeOrgKeyAction(AddMasterOrg, txArgs{txa: txa, morgId: morgId})
}
// RemoveOrgKey removes an org key combination from the org key map
// AddSubOrg ass a sub org to the master org
func (s *QuorumControlsAPI) AddSubOrg(orgId string, morgId string, txa ethapi.SendTxArgs) ExecStatus {
return s.executeOrgKeyAction(AddSubOrg, txArgs{txa: txa, orgId: orgId, morgId: morgId})
}
// AddOrgKey adds an org key combination to the org key map
// AddOrgVoter adds voter account to a master org
func (s *QuorumControlsAPI) AddOrgVoter(morgId string, acctId common.Address, txa ethapi.SendTxArgs) ExecStatus {
return s.executeOrgKeyAction(AddOrgVoter, txArgs{txa: txa, morgId: morgId, acctId: acctId})
}
// RemoveOrgKey removes an org key combination from the org key map
// RemoveOrgVoter removes voter account to a master org
func (s *QuorumControlsAPI) RemoveOrgVoter(morgId string, acctId common.Address, txa ethapi.SendTxArgs) ExecStatus {
return s.executeOrgKeyAction(RemoveOrgVoter, txArgs{txa: txa, morgId: morgId, acctId: acctId})
}
// AddOrgKey adds an org key to the org id
func (s *QuorumControlsAPI) AddOrgKey(orgId string, tmKey string, txa ethapi.SendTxArgs) ExecStatus {
return s.executeOrgKeyAction(AddOrgKey, txArgs{txa: txa, orgId: orgId, tmKey: tmKey})
}
@ -448,15 +451,17 @@ func (s *QuorumControlsAPI) RemoveOrgKey(orgId string, tmKey string, txa ethapi.
return s.executeOrgKeyAction(RemoveOrgKey, txArgs{txa: txa, orgId: orgId, tmKey: tmKey})
}
// RemoveOrgKey removes an org key combination from the org key map
// ApprovePendingOp approves any key add or delete activity
func (s *QuorumControlsAPI) ApprovePendingOp(orgId string, txa ethapi.SendTxArgs) ExecStatus {
return s.executeOrgKeyAction(ApprovePendingOp, txArgs{txa: txa, orgId: orgId})
}
// SetAccountAccess sets the account access to the given type
func (s *QuorumControlsAPI) SetAccountAccess(acct common.Address, access uint8, txa ethapi.SendTxArgs) ExecStatus {
return s.executePermAction(SetAccountAccess, txArgs{acctId: acct, accessType: access, txa: txa})
}
// returns node details given the enode id
func getNodeDetailsFromEnode(nodeId string) (string, string, string, string, error) {
node, err := discover.ParseNode(nodeId)
if err != nil {
@ -473,8 +478,7 @@ func getNodeDetailsFromEnode(nodeId string) (string, string, string, string, err
return enodeID, discPort, raftPort, ipAddrPort, nil
}
// checks if the input node details for approval is matching with details stored
// in contract
// checks if the input node details for approval is matching with details stored in contract
func checkNodeDetails(ps *pbind.PermissionsSession, nodeId string, action PermAction) (error, ExecStatus) {
enodeID, discPort, raftPort, ipAddrPort, err := getNodeDetailsFromEnode(nodeId)
@ -544,6 +548,7 @@ func checkNodeDetails(ps *pbind.PermissionsSession, nodeId string, action PermAc
return nil, ExecSuccess
}
// performs all necessary validation before the request can be processed
func (s *QuorumControlsAPI) validateOpDetails(ps *pbind.PermissionsSession, enodeID string, from common.Address, action PermAction) (error, ExecStatus) {
// check if the input node is fine
@ -718,6 +723,7 @@ func (s *QuorumControlsAPI) executePermAction(action PermAction, args txArgs) Ex
return ExecSuccess
}
// returns the voter list for a given organization
func (s *QuorumControlsAPI) GetOrgVoterList(morgId string) []string {
if !s.orgEnabled {
voterArr := make([]string, 1)
@ -745,6 +751,7 @@ func (s *QuorumControlsAPI) GetOrgVoterList(morgId string) []string {
return voterArr
}
// returns the master org, org and linked key details
func (s *QuorumControlsAPI) OrgKeyInfo() []orgInfo {
if !s.orgEnabled {
orgInfoArr := make([]orgInfo, 1)
@ -955,19 +962,14 @@ func (s *QuorumControlsAPI) validateAccount(from common.Address) (accounts.Walle
func checkVoterExists(ps *pbind.PermissionsSession) bool {
tx, err := ps.GetNumberOfValidVoters()
log.Debug("number of voters", "count", tx)
if err == nil && tx.Cmp(big.NewInt(0)) > 0 {
return true
}
return false
return (err == nil && tx.Cmp(big.NewInt(0)) > 0)
}
// checks if any accounts is a valid voter to approve the action
func checkIsVoter(ps *pbind.PermissionsSession, acctId common.Address) bool {
tx, err := ps.IsVoter(acctId)
if err == nil && tx {
return true
}
return false
return (err == nil && tx)
}
// newPermSession creates a new permission contract session

View File

@ -72,7 +72,6 @@ func AddOrgKey(orgId string, key string) {
OrgKeyMap.Add(orgId, &OrgStruct{OrgId: orgId, Keys: []string{key}})
}
// deletes org key details from cache
func DeleteOrgKey(orgId string, key string) {
if val, ok := OrgKeyMap.Get(orgId); ok {