From e5b14b0a71d4d70402830635a673ea4dcf53cb59 Mon Sep 17 00:00:00 2001 From: vsmk98 Date: Wed, 15 May 2019 15:59:46 +0800 Subject: [PATCH] permission: code clean up. removal of unnecessary code. --- accounts/abi/bind/doc.md | 7 -- cmd/bootnode/main.go | 4 +- cmd/geth/main.go | 2 +- docs/orgkey.md | 176 ------------------------------------ eth/backend.go | 2 - eth/handler.go | 1 - eth/sync.go | 1 + internal/web3ext/web3ext.go | 3 + node/node.go | 1 - p2p/discover/udp.go | 16 +--- p2p/discover/udp_test.go | 3 +- p2p/server.go | 14 +-- params/quorum.go | 7 -- 13 files changed, 11 insertions(+), 226 deletions(-) delete mode 100644 accounts/abi/bind/doc.md delete mode 100644 docs/orgkey.md diff --git a/accounts/abi/bind/doc.md b/accounts/abi/bind/doc.md deleted file mode 100644 index 0479e5639..000000000 --- a/accounts/abi/bind/doc.md +++ /dev/null @@ -1,7 +0,0 @@ -# Abigen with Quorum - -Abigen is a source code generator that converts quorum abi definitions into type-safe Go packages. In addition to the original capabilities provided by Ethereum described [here](https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts) Quorum abigen also supports deploying private transactions. - -PrivateFrom and PrivateFor fields have been added to the *bind.TransactOpts type which allows users to specify the public keys of the Constellation identity used to send and receive transactions. - -When using the PrivateFrom and PrivateFor fields, the "PRIVATE_CONFIG" environment variable must be set to point to the running constellation node's .ipc file and this node much match the public key set in the PrivateFrom field. If not, deploying the private contract will fail. \ No newline at end of file diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go index f66040ed3..32f7d63be 100644 --- a/cmd/bootnode/main.go +++ b/cmd/bootnode/main.go @@ -118,8 +118,6 @@ func main() { } } - var knownNodes []*enode.Node - if *runv5 { if _, err := discv5.ListenUDP(nodeKey, conn, "", restrictList); err != nil { utils.Fatalf("%v", err) @@ -131,7 +129,7 @@ func main() { PrivateKey: nodeKey, NetRestrict: restrictList, } - if _, err := discover.ListenUDP(conn, ln, cfg, knownNodes); err != nil { + if _, err := discover.ListenUDP(conn, ln, cfg); err != nil { utils.Fatalf("%v", err) } } diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 27b73b599..1c19e6149 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -408,7 +408,7 @@ func startQuorumPermissionService(ctx *cli.Context, stack *node.Node) { utils.Fatalf("Failed to start Quorum Permission contract service %v", err) } - rpcClient, err := stack.Attach() /**/ + rpcClient, err := stack.Attach() if err != nil { utils.Fatalf("Unable to connect to the node: %v", err) } diff --git a/docs/orgkey.md b/docs/orgkey.md deleted file mode 100644 index 6ceee4bf2..000000000 --- a/docs/orgkey.md +++ /dev/null @@ -1,176 +0,0 @@ -# Transaction Manager key management at Organization level -For sending private transactions in Quorum, the individual transaction manager (Tessera or Constellation) public keys have to be mentioned in the `privateFor` attribute. If the private transaction is intended for multiple nodes, this sometimes becomes challenging to manage. This feature allows multiple transaction manager keys to be grouped under a single organization name. The organization name can then be used in `privateFor` attribute instead of individual transaction manager keys. - -Further this feature allows to define a hierarchy of master organization and multiple sub organizations under the master org. e.g. There can be a master org "ABC" having 10 nodes and hence 10 keys. However there may be subset of nodes which are participating in various private transactions. These subsets can be set up as suborgs with in the master org with each suborg having a distincy identifier. While sending the private transaction, the suborg identifier can be give as a part of `privateFor` attribute. - -## Set up -Organization level key management is managed by a smart contract [Clusterkeys.sol](../controls/cluster/Clusterkeys.sol). The precompiled smart contract is deployed at address `0x000000000000000000022` in network bootup process. The binding of the precompiled byte code with the address is in `genesis.json`. - -## APIs for organization level key management -### quorumOrgMgmt.addMasterOrg -* Input: saster org id and transaction object. The master org name has to be unique -* Output: status of operation -* Example: -``` -> quorumOrgMgmt.addMasterOrg("ABC", {from:eth.accounts[0]}) -{ - msg: "Action completed successfully", - status: true -} -``` -### quorumOrgMgmt.addSubOrg -* Input: Sub org id, master org id for the sub org and transaction object. The sub org name is unique across master organizations -* Output: status of operation -* Example: -``` -> quorumOrgMgmt.addSubOrg("ENTITY1", "ABC", {from: eth.accounts[0]}) -{ - msg: "Action completed successfully", - status: true -} -``` -### quorumOrgMgmt.addVoter -Before any keys can be added to a sub org id, voters need to be added at master org level to which the sub org is linked. This API is used for adding a voter to the master org. Only an account with full access can add an account as voter. Further the account being added as voter account should have at least transact permission. -* Input: master org id, voter account id, transaction object -* Output: status of operation -* Example: -``` -> quorumOrgMgmt.addVoter("ABC", eth.accounts[0], {from: eth.accounts[0]}) -{ - msg: "Action completed successfully", - status: true -} -``` -### quorumOrgMgmt.removeVoter -This API is used for removing a voter to the master org. Only an account with full access can perform this activity. -* Input: master org id, voter account id, transaction object -* Output: status of operation -* Example: -``` -> quorumOrgMgmt.removeVoter("ABC", eth.accounts[0], {from: eth.accounts[0]}) -{ - msg: "Action completed successfully", - status: true -} -``` -### quorumOrgMgmt.getOrgVoterList -* Input: master org id -* Output: list of voters accounts for the master org -* Example: -``` -> quorumOrgMgmt.getOrgVoterList("ABC") -["0xed9d02e382b34818e88B88a309c7fe71E65f419d"] -``` -### quorumOrgMgmt.addOrgKey -For adding a key to a sub org, there should be valid voters at master org level to which the sub org belongs. Further the key should not be in use in any of the other master orgs. Onec the key is added successfully, it goes into pending approval status and awaits approval from voters at master org level. -* Input: sub org id, transaction manager public key, transaction object -* Output: status of the operation -* Example: -``` -> quorumOrgMgmt.addOrgKey("ENTITY1", "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=", {from:eth.accounts[0]}) -{ - msg: "Action completed successfully", - status: true -} -> quorumOrgMgmt.addOrgKey("ENTITY1", "1iTZde/ndBHvzhcl7V68x44Vx7pl8nwx9LqnM/AfJUg=", {from: eth.accounts[0]}) -{ - msg: "Key already in use in another master organization", - status: false -} -``` -### quorumOrgMgmt.getPendingOpDetails -* Input: sub org id -* Output: pending operation(add/delete), key -* Example: -``` -> quorumOrgMgmt.getPendingOpDetails("ENTITY1") -{ - pendingKey: "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=", - pendingOp: "Add" -} -``` -### quorumOrgMgmt.approvePendingOp -Any valid voter account at master org level can invoke this API to approve the pending key add/delete operation. -* Input: sub org id -* Output: status of the activity -* Example: -``` -> quorumOrgMgmt.approvePendingOp("ENTITY1", {from:eth.accounts[0]}) -{ - msg: "Action completed successfully", - status: true -} -``` -### quorumOrgMgmt.orgKeyInfo -* Input: none -* Output: list of all master org ids, sub org ids and keys at each sub org id level -* Example: -``` -> quorumOrgMgmt.orgKeyInfo -[{ - masterOrgId: "FFF", - subOrgId: "FFF1", - subOrgKeyList: [] -}, { - masterOrgId: "DEF", - subOrgId: "ENTITY3", - subOrgKeyList: ["1iTZde/ndBHvzhcl7V68x44Vx7pl8nwx9LqnM/AfJUg="] -}, { - masterOrgId: "ABC", - subOrgId: "ENTITY1", - subOrgKeyList: ["BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo="] -}, { - masterOrgId: "ABC", - subOrgId: "ENTITY2", - subOrgKeyList: ["QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=", "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo"] -}] -``` - -## Sending private transaction to sub orgs -Using [simplestore.sol](https://github.com/jpmorganchase/quorum-examples/blob/master/examples/7nodes/simplestorage.sol) as example, if one has to deploy this as a private contract between node1 and node2 - the deployment command will be as below: -``` -a = eth.accounts[0] -web3.eth.defaultAccount = a; - -var abi = [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initVal","type":"uint256"}],"payable":false,"type":"constructor"}]; - -var bytecode = "0x6060604052341561000f57600080fd5b604051602080610149833981016040528080519060200190919050505b806000819055505b505b610104806100456000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632a1afcd914605157806360fe47b11460775780636d4ce63c146097575b600080fd5b3415605b57600080fd5b606160bd565b6040518082815260200191505060405180910390f35b3415608157600080fd5b6095600480803590602001909190505060c3565b005b341560a157600080fd5b60a760ce565b6040518082815260200191505060405180910390f35b60005481565b806000819055505b50565b6000805490505b905600a165627a7a72305820d5851baab720bba574474de3d09dbeaabc674a15f4dd93b974908476542c23f00029"; - -var simpleContract = web3.eth.contract(abi); -var simple = simpleContract.new(42, {from:web3.eth.accounts[0], data: bytecode, gas: 0x47b760, privateFor: ["QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc="]}, function(e, contract) { - if (e) { - console.log("err creating contract", e); - } - else { - if (!contract.address) { - console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined..."); - } else { - console.log("Contract mined! Address: " + contract.address); - console.log(contract); - } - } -}); -``` -In the above deployment call, the transaction manager key of node2 is passed as a part of the `privateFor` argument. Now the privateFor attribute will accepts the distinct sub org identifir. The deployment script with `privateFor` value as sub org is as showb below: -``` -a = eth.accounts[0] -web3.eth.defaultAccount = a; - -var abi = [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initVal","type":"uint256"}],"payable":false,"type":"constructor"}]; - -var bytecode = "0x6060604052341561000f57600080fd5b604051602080610149833981016040528080519060200190919050505b806000819055505b505b610104806100456000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632a1afcd914605157806360fe47b11460775780636d4ce63c146097575b600080fd5b3415605b57600080fd5b606160bd565b6040518082815260200191505060405180910390f35b3415608157600080fd5b6095600480803590602001909190505060c3565b005b341560a157600080fd5b60a760ce565b6040518082815260200191505060405180910390f35b60005481565b806000819055505b50565b6000805490505b905600a165627a7a72305820d5851baab720bba574474de3d09dbeaabc674a15f4dd93b974908476542c23f00029"; - -var simpleContract = web3.eth.contract(abi); -var simple = simpleContract.new(42, {from:web3.eth.accounts[0], data: bytecode, gas: 0x47b760, privateFor: ["ENTITY1"]}, function(e, contract) { - if (e) { - console.log("err creating contract", e); - } else { - if (!contract.address) { - console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined..."); - } else { - console.log("Contract mined! Address: " + contract.address); - console.log(contract); - } - } -}); -``` diff --git a/eth/backend.go b/eth/backend.go index 9a8d2dc34..6610ea9b3 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -286,8 +286,6 @@ func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainCo func (s *Ethereum) APIs() []rpc.API { apis := ethapi.GetAPIs(s.APIBackend) - //TODO add perm service - // Append any APIs exposed explicitly by the consensus engine apis = append(apis, s.engine.APIs(s.BlockChain())...) diff --git a/eth/handler.go b/eth/handler.go index 2620da9a5..5800d7ec0 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -236,7 +236,6 @@ func (pm *ProtocolManager) Start(maxPeers int) { // start sync handlers go pm.syncer() - go pm.txsyncLoop() } diff --git a/eth/sync.go b/eth/sync.go index 7d43b7d6a..9de7bc922 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -200,6 +200,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) { return } } + // Run the sync cycle, and disable fast sync if we've went past the pivot block if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil { return diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 0214b590f..47bc5bae6 100755 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -711,6 +711,9 @@ web3._extend({ const Raft_JS = ` web3._extend({ property: 'raft', + methods: + [ + ], properties: [ new web3._extend.Property({ diff --git a/node/node.go b/node/node.go index 3117e807c..b45c4882c 100644 --- a/node/node.go +++ b/node/node.go @@ -271,7 +271,6 @@ func (n *Node) startRPC(services map[reflect.Type]Service) error { for _, service := range services { apis = append(apis, service.APIs()...) } - // Start the various API endpoints, terminating all in case of errors if err := n.startInProc(apis); err != nil { return err diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index ee4e56fd5..cb1e67387 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -237,17 +237,15 @@ type Config struct { } // ListenUDP returns a new table that listens for UDP packets on laddr. -func ListenUDP(c conn, ln *enode.LocalNode, cfg Config, knownNodes []*enode.Node) (*Table, error) { - - tab, _, err := newUDP(c, ln, cfg, knownNodes) +func ListenUDP(c conn, ln *enode.LocalNode, cfg Config) (*Table, error) { + tab, _, err := newUDP(c, ln, cfg) if err != nil { return nil, err } return tab, nil } -func newUDP(c conn, ln *enode.LocalNode, cfg Config, knownNodes []*enode.Node) (*Table, *udp, error) { - +func newUDP(c conn, ln *enode.LocalNode, cfg Config) (*Table, *udp, error) { udp := &udp{ conn: c, priv: cfg.PrivateKey, @@ -262,14 +260,6 @@ func newUDP(c conn, ln *enode.LocalNode, cfg Config, knownNodes []*enode.Node) ( if err != nil { return nil, nil, err } - - // prepopulate nodes database with the known nodes - if nodesLen := len(knownNodes); nodesLen > 0 { - log.Info("Adding predefined nodes to node database", "count", nodesLen) - //k := knownNodes[0] - tab.stuff(wrapNodes(knownNodes)) - } - udp.tab = tab udp.wg.Add(2) diff --git a/p2p/discover/udp_test.go b/p2p/discover/udp_test.go index 937d5a1cb..84c3dd16f 100644 --- a/p2p/discover/udp_test.go +++ b/p2p/discover/udp_test.go @@ -61,7 +61,6 @@ type udpTest struct { sent [][]byte localkey, remotekey *ecdsa.PrivateKey remoteaddr *net.UDPAddr - knownNodes []*enode.Node } func newUDPTest(t *testing.T) *udpTest { @@ -74,7 +73,7 @@ func newUDPTest(t *testing.T) *udpTest { } db, _ := enode.OpenDB("") ln := enode.NewLocalNode(db, test.localkey) - test.table, test.udp, _ = newUDP(test.pipe, ln, Config{PrivateKey: test.localkey}, test.knownNodes) + test.table, test.udp, _ = newUDP(test.pipe, ln, Config{PrivateKey: test.localkey}) // Wait for initial refresh so the table doesn't send unexpected findnode. <-test.table.initDone return test diff --git a/p2p/server.go b/p2p/server.go index 4fa579574..38f73289d 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -109,10 +109,6 @@ type Config struct { // allowed to connect, even above the peer limit. TrustedNodes []*enode.Node - // KnownNodes contains a list of nodes that are used to pre-populate the - // node database. - KnownNodes []*enode.Node - // Connectivity can be restricted to certain IP networks. // If this option is set to a non-nil value, only hosts which match one of the // IP networks contained in the list are considered. @@ -540,14 +536,6 @@ func (srv *Server) setupDiscovery() error { // Discovery V4 var unhandled chan discover.ReadPacket var sconn *sharedUDPConn - - knownNodes := append([]*enode.Node(nil), srv.KnownNodes...) - if srv.EnableNodePermission { - knownNodes = append(knownNodes, ParsePermissionedNodes(srv.DataDir)...) - } - - srv.KnownNodes = knownNodes - if !srv.NoDiscovery { if srv.DiscoveryV5 { unhandled = make(chan discover.ReadPacket, 100) @@ -559,7 +547,7 @@ func (srv *Server) setupDiscovery() error { Bootnodes: srv.BootstrapNodes, Unhandled: unhandled, } - ntab, err := discover.ListenUDP(conn, srv.localnode, cfg, knownNodes) + ntab, err := discover.ListenUDP(conn, srv.localnode, cfg) if err != nil { return err } diff --git a/params/quorum.go b/params/quorum.go index b16e14a07..7eaae3b33 100644 --- a/params/quorum.go +++ b/params/quorum.go @@ -1,12 +1,5 @@ package params -import "github.com/ethereum/go-ethereum/common" - -var ( - QuorumPermissionsContract = common.Address{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32} - QuorumPrivateKeyManagementContract = common.Address{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34} -) - const ( PERMISSIONED_CONFIG = "permissioned-nodes.json" BLACKLIST_CONFIG = "disallowed-nodes.json"