Added check to ensure that at least one account is given as a part of genesis.json for initial network to come up

This commit is contained in:
vsmk98 2019-02-07 14:31:19 +08:00
parent 178d7629c4
commit 1f527f7b3b
5 changed files with 47 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@ -101,25 +101,29 @@ contract Permissions {
/* public and external functions */ /* public and external functions */
// view 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 voters // Get number of voters
function getNumberOfVoters() public view returns (uint) function getNumberOfVoters() external view returns (uint)
{ {
return numberOfVoters; return numberOfVoters;
} }
// Get number of valid voters // Get number of valid voters
function getNumberOfValidVoters() public view returns (uint) function getNumberOfValidVoters() external view returns (uint)
{ {
return numberOfValidVoters; return numberOfValidVoters;
} }
// Get voter // Get voter
function getVoter(uint i) public view returns (address _addr, VoterStatus _voterStatus) function getVoter(uint i) external view returns (address _addr, VoterStatus _voterStatus)
{ {
return (voterAcctList[i].voterAcct, voterAcctList[i].voterStatus); return (voterAcctList[i].voterAcct, voterAcctList[i].voterStatus);
} }
// Get number of nodes // Get number of nodes
function getNetworkBootStatus() public view returns (bool) function getNetworkBootStatus() external view returns (bool)
{ {
return networkBoot; return networkBoot;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -443,7 +443,6 @@ func (p *PermissionCtrl) populateInitPermission() error {
GasPrice: big.NewInt(0), GasPrice: big.NewInt(0),
}, },
} }
tx, err := permissionsSession.GetNetworkBootStatus() tx, err := permissionsSession.GetNetworkBootStatus()
if err != nil { if err != nil {
// handle the scenario of no contract code. // handle the scenario of no contract code.
@ -463,6 +462,15 @@ func (p *PermissionCtrl) populateInitPermission() error {
return errors.New("Node started in non-permissioned mode") return errors.New("Node started in non-permissioned mode")
} }
if tx != true { if tx != true {
// Ensure that there is at least one account given as a part of genesis.json
// which will have full access. If not throw a fatal error
// Do not want a network with no access
initAcctCnt, err := permissionsSession.GetInitAccountsCount()
log.Info("SMK-populateInitPermission @471 ", "err", err, "initAcctCnt", initAcctCnt)
if err == nil && initAcctCnt.Cmp(big.NewInt(0)) == 0 {
utils.Fatalf("Permissioned network being brought up with zero accounts having full access. Add accounts as a part of genesis.json and bring up the network")
}
// populate initial account access to full access // populate initial account access to full access
err = p.populateInitAccountAccess(permissionsSession) err = p.populateInitAccountAccess(permissionsSession)
if err != nil { if err != nil {
@ -470,7 +478,7 @@ func (p *PermissionCtrl) populateInitPermission() error {
} }
// populate the initial node list from static-nodes.json // populate the initial node list from static-nodes.json
err := p.populateStaticNodesToContract(permissionsSession) err = p.populateStaticNodesToContract(permissionsSession)
if err != nil { if err != nil {
return err return err
} }