mirror of https://github.com/poanetwork/quorum.git
added checks to validate that the contract code is existing at the address
This commit is contained in:
parent
94aa2382ce
commit
4d6cf6da77
|
@ -374,7 +374,7 @@ func startQuorumPermissionService(ctx *cli.Context, stack *node.Node) {
|
|||
quorumApis = []string{"quorumNodeMgmt", "quorumAcctMgmt"}
|
||||
|
||||
} else {
|
||||
log.Error("Failed to start Quorum Permission contract service: %v", err)
|
||||
log.Error("Failed to start Quorum Permission contract service", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -383,9 +383,13 @@ func startQuorumPermissionService(ctx *cli.Context, stack *node.Node) {
|
|||
if err != nil {
|
||||
log.Warn("Failed to start quorum Org key management service", "err", err)
|
||||
} else {
|
||||
kc.Start()
|
||||
log.Trace("Key management service started")
|
||||
quorumApis = append(quorumApis, "quorumOrgMgmt")
|
||||
err = kc.Start()
|
||||
if err == nil {
|
||||
log.Trace("Key management service started")
|
||||
quorumApis = append(quorumApis, "quorumOrgMgmt")
|
||||
} else {
|
||||
log.Error("Failed to start Quorum Org key management contract service", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
rpcClient, err := stack.Attach()
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -48,6 +48,9 @@ contract Clusterkeys {
|
|||
|
||||
|
||||
// functions to test
|
||||
function checkOrgContractExists() external pure returns (bool){
|
||||
return true;
|
||||
}
|
||||
function getOrgVoteCount(string _orgId) external view returns (uint) {
|
||||
return voteCount[getOrgIndex(_orgId)];
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,9 @@
|
|||
package cluster
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
|
@ -13,6 +16,8 @@ import (
|
|||
|
||||
type OrgKeyCtrl struct {
|
||||
ethClient *ethclient.Client
|
||||
key *ecdsa.PrivateKey
|
||||
km *pbind.Cluster
|
||||
}
|
||||
|
||||
func NewOrgKeyCtrl(node *node.Node) (*OrgKeyCtrl, error) {
|
||||
|
@ -21,7 +26,13 @@ func NewOrgKeyCtrl(node *node.Node) (*OrgKeyCtrl, error) {
|
|||
log.Error("Unable to create ethereum client for cluster check : ", "err", err)
|
||||
return nil, err
|
||||
}
|
||||
return &OrgKeyCtrl{stateReader}, nil
|
||||
// check if permissioning contract is there at address. If not return from here
|
||||
km, err := pbind.NewCluster(params.QuorumPrivateKeyManagementContract, stateReader)
|
||||
if err != nil {
|
||||
log.Error("Permissions not enabled for the network : ", "err", err)
|
||||
return nil, err
|
||||
}
|
||||
return &OrgKeyCtrl{stateReader, node.GetNodeKey(), km}, nil
|
||||
}
|
||||
|
||||
// This function first adds the node list from permissioned-nodes.json to
|
||||
|
@ -34,8 +45,35 @@ func (k *OrgKeyCtrl) Start() error {
|
|||
log.Error("Cluster not enabled for the network : ", "err", err)
|
||||
return nil
|
||||
}
|
||||
err = k.checkIfContractExists()
|
||||
if (err != nil ){
|
||||
return err
|
||||
}
|
||||
k.manageClusterKeys()
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
func(k *OrgKeyCtrl) checkIfContractExists() error {
|
||||
auth := bind.NewKeyedTransactor(k.key)
|
||||
clusterSession := &pbind.ClusterSession{
|
||||
Contract: k.km,
|
||||
CallOpts: bind.CallOpts{
|
||||
Pending: true,
|
||||
},
|
||||
TransactOpts: bind.TransactOpts{
|
||||
From: auth.From,
|
||||
Signer: auth.Signer,
|
||||
GasLimit: 4700000,
|
||||
GasPrice: big.NewInt(0),
|
||||
},
|
||||
}
|
||||
|
||||
_, err := clusterSession.CheckOrgContractExists()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *OrgKeyCtrl) manageClusterKeys() error {
|
||||
|
@ -59,6 +97,10 @@ func (k *OrgKeyCtrl) populatePrivateKeys() error {
|
|||
opts := &bind.FilterOpts{}
|
||||
pastAddEvents, err := cluster.FilterOrgKeyAdded(opts)
|
||||
|
||||
if err != nil && err.Error() == "no contract code at given address" {
|
||||
return err
|
||||
}
|
||||
|
||||
recExists := true
|
||||
for recExists {
|
||||
recExists = pastAddEvents.Next()
|
||||
|
|
|
@ -444,7 +444,11 @@ func (p *PermissionCtrl) populateInitPermission() error {
|
|||
|
||||
tx, err := permissionsSession.GetNetworkBootStatus()
|
||||
if err != nil {
|
||||
log.Warn("Failed to udpate network boot status ", "err", err)
|
||||
// handle the scenario of no contract code.
|
||||
if err.Error() == "no contract code at given address"{
|
||||
return err
|
||||
}
|
||||
log.Warn("Failed to retrieve network boot status ", "err", err)
|
||||
}
|
||||
|
||||
if tx && !p.permissionedMode {
|
||||
|
|
Loading…
Reference in New Issue