diff --git a/acceptance-tests/tests/simple-permissioning-smart-contract/README.md b/acceptance-tests/tests/simple-permissioning-smart-contract/README.md index 5258c4f1fc..40dc739ed5 100644 --- a/acceptance-tests/tests/simple-permissioning-smart-contract/README.md +++ b/acceptance-tests/tests/simple-permissioning-smart-contract/README.md @@ -123,3 +123,15 @@ Compiling ./contracts/SimplePermissioning.sol... 10 passing (1s) ``` + +##Permissioning Contract Updating Steps +Should these contracts require updating, please ensure that the compiled bytecode in the Permissioning acceptance tests genesis file has been updated with the new bytecode. + +One simple update procedure is as follows: +1. Load existing contract in [Remix IDE](https://remix.ethereum.org/). +2. Enable the _"SOLIDITY COMPILER"_ plugin. +3. Make required changes. +4. Compile contract (_"Enable optimization"_ disabled.) +5. Click the _"Compilation Details"_ button. +6. Navigate to the _"RUNTIME BYTECODE"_ section and copy the value for the _"object"_ key. +7. Paste this text as the value for the _"code"_ key in the relevant genesis file. \ No newline at end of file diff --git a/acceptance-tests/tests/simple-permissioning-smart-contract/contracts/SimpleNodePermissioning.sol b/acceptance-tests/tests/simple-permissioning-smart-contract/contracts/SimpleNodePermissioning.sol index 0e5a2108c0..334cf959c5 100644 --- a/acceptance-tests/tests/simple-permissioning-smart-contract/contracts/SimpleNodePermissioning.sol +++ b/acceptance-tests/tests/simple-permissioning-smart-contract/contracts/SimpleNodePermissioning.sol @@ -24,7 +24,7 @@ contract SimpleNodePermissioning { } function enodeAllowed(bytes32 sourceEnodeHigh, bytes32 sourceEnodeLow, bytes16 sourceEnodeIp, uint16 sourceEnodePort) public view returns (bool){ - bytes memory key = computeKey(sourceEnodeHigh, sourceEnodeLow, sourceEnodeIp, sourceEnodePort); + bytes memory key = computeKey(sourceEnodeHigh, sourceEnodeLow, sourceEnodeIp); Enode storage whitelistSource = whitelist[key]; if (whitelistSource.enodeHost > 0) { return true; @@ -32,15 +32,17 @@ contract SimpleNodePermissioning { } function addEnode(bytes32 enodeHigh, bytes32 enodeLow, bytes16 enodeIp, uint16 enodePort) public { Enode memory newEnode = Enode(enodeHigh, enodeLow, enodeIp, enodePort); - bytes memory key = computeKey(enodeHigh, enodeLow, enodeIp, enodePort); + bytes memory key = computeKey(enodeHigh, enodeLow, enodeIp); whitelist[key] = newEnode; } function removeEnode(bytes32 enodeHigh, bytes32 enodeLow, bytes16 enodeIp, uint16 enodePort) public { - bytes memory key = computeKey(enodeHigh, enodeLow, enodeIp, enodePort); + bytes memory key = computeKey(enodeHigh, enodeLow, enodeIp); Enode memory zeros = Enode(bytes32(0), bytes32(0), bytes16(0), 0); whitelist[key] = zeros; } - function computeKey(bytes32 enodeHigh, bytes32 enodeLow, bytes16 enodeIp, uint16 enodePort) public pure returns (bytes memory) { - return abi.encode(enodeHigh, enodeLow, enodeIp, enodePort); + function computeKey(bytes32 enodeHigh, bytes32 enodeLow, bytes16 enodeIp) public pure returns (bytes memory) { + // enodePort has been removed to aid acceptance tests with random node ports + // This method is not used in production code + return abi.encode(enodeHigh, enodeLow, enodeIp); } } diff --git a/acceptance-tests/tests/simple-permissioning-smart-contract/test/test-node-permissioning.js b/acceptance-tests/tests/simple-permissioning-smart-contract/test/test-node-permissioning.js index 2af60d3452..7b0b135939 100644 --- a/acceptance-tests/tests/simple-permissioning-smart-contract/test/test-node-permissioning.js +++ b/acceptance-tests/tests/simple-permissioning-smart-contract/test/test-node-permissioning.js @@ -19,12 +19,12 @@ contract('Permissioning: Nodes', () => { }); it('Should compute key', async () => { - let key1 = await proxy.computeKey(node1High, node1Low, node1Host, node1Port); - let key2 = await proxy.computeKey(node1High, node1Low, node1Host, node1Port); + let key1 = await proxy.computeKey(node1High, node1Low, node1Host); + let key2 = await proxy.computeKey(node1High, node1Low, node1Host); assert.equal(key1, key2, "computed keys should be the same"); - let key3 = await proxy.computeKey(node1High, node1Low, node1Host, node2Port); - assert(key3 != key2, "keys for different ports should be different"); + let key3 = await proxy.computeKey(node2High, node2Low, node2Host); + assert(key3 != key2, "computed keys for different nodes should be different"); }); it('Should add a node to the whitelist and then permit that node', async () => { @@ -54,6 +54,5 @@ contract('Permissioning: Nodes', () => { permitted = await proxy.connectionAllowed(node1High, node1Low, node1Host, node1Port, node2High, node2Low, node2Host, node2Port); assert.equal(permitted, '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'expected source disallowed since it was removed'); - }); }); diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningAcceptanceTest.java index 31cc78fe7d..9e806a3235 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningAcceptanceTest.java @@ -95,4 +95,14 @@ public class NodeSmartContractPermissioningAcceptanceTest permissionedNode.verify(admin.addPeer(forbiddenNode)); permissionedNode.verify(net.awaitPeerCount(3)); } + + @Test + public void onChainPermissioningWhitelistShouldPersistAcrossRestarts() { + permissionedCluster.stop(); + permissionedCluster.start(bootnode, forbiddenNode, allowedNode, permissionedNode); + + permissionedNode.verify(nodeIsAllowed(allowedNode)); + permissionedNode.verify(nodeIsAllowed(bootnode)); + permissionedNode.verify(nodeIsAllowed(permissionedNode)); + } } diff --git a/acceptance-tests/tests/src/test/resources/permissioning/simple_permissioning_genesis.json b/acceptance-tests/tests/src/test/resources/permissioning/simple_permissioning_genesis.json index 681a8755ec..0d8508e7b9 100644 --- a/acceptance-tests/tests/src/test/resources/permissioning/simple_permissioning_genesis.json +++ b/acceptance-tests/tests/src/test/resources/permissioning/simple_permissioning_genesis.json @@ -34,7 +34,7 @@ "0x0000000000000000000000000000000000009999": { "comment": "Simple node permissioning smart contract", "balance": "0", - "code": "608060405260043610610067576000357c01000000000000000000000000000000000000000000000000000000009004806312eef3631461006c5780633600f60d146100f45780633620b1df1461016457806378a402d514610228578063aab2f5eb14610311575b600080fd5b34801561007857600080fd5b506100da6004803603608081101561008f57600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190505050610381565b604051808215151515815260200191505060405180910390f35b34801561010057600080fd5b506101626004803603608081101561011757600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190505050610467565b005b34801561017057600080fd5b50610212600480360361010081101561018857600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff1690602001909291905050506105a9565b6040518082815260200191505060405180910390f35b34801561023457600080fd5b506102966004803603608081101561024b57600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff16906020019092919050505061062e565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102d65780820151818401526020810190506102bb565b50505050905090810190601f1680156103035780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561031d57600080fd5b5061037f6004803603608081101561033457600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff1690602001909291905050506106a0565b005b600060606103918686868661062e565b9050600080826040518082805190602001908083835b6020831015156103cc57805182526020820191506020810190506020830392506103a7565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902090506000700100000000000000000000000000000000028160020160009054906101000a9004700100000000000000000000000000000000026fffffffffffffffffffffffffffffffff1916111561045c5760019250505061045f565b50505b949350505050565b61046f6107ff565b608060405190810160405280868152602001858152602001846fffffffffffffffffffffffffffffffff191681526020018361ffff16815250905060606104b88686868661062e565b9050816000826040518082805190602001908083835b6020831015156104f357805182526020820191506020810190506020830392506104ce565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600082015181600001556020820151816001015560408201518160020160006101000a8154816fffffffffffffffffffffffffffffffff02191690837001000000000000000000000000000000009004021790555060608201518160020160106101000a81548161ffff021916908361ffff160217905550905050505050505050565b60006105b789898989610381565b80156105cb57506105ca85858585610381565b5b156105fb577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001029050610622565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60010290505b98975050505050505050565b60608484848460405160200180858152602001848152602001836fffffffffffffffffffffffffffffffff19166fffffffffffffffffffffffffffffffff191681526020018261ffff1661ffff1681526020019450505050506040516020818303038152906040529050949350505050565b60606106ae8585858561062e565b90506106b86107ff565b60806040519081016040528060006001028152602001600060010281526020016000700100000000000000000000000000000000026fffffffffffffffffffffffffffffffff19168152602001600061ffff168152509050806000836040518082805190602001908083835b6020831015156107495780518252602082019150602081019050602083039250610724565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600082015181600001556020820151816001015560408201518160020160006101000a8154816fffffffffffffffffffffffffffffffff02191690837001000000000000000000000000000000009004021790555060608201518160020160106101000a81548161ffff021916908361ffff160217905550905050505050505050565b608060405190810160405280600080191681526020016000801916815260200160006fffffffffffffffffffffffffffffffff19168152602001600061ffff168152509056fea165627a7a72305820c18b04628b7fa30a0188fb4ede3466f5d013b403793835501df6055a155b9c420029", + "code": "608060405234801561001057600080fd5b50600436106100575760003560e01c806312eef3631461005c5780633600f60d146100d75780633620b1df1461013a5780639b7ca65c146101f1578063aab2f5eb146102bf575b600080fd5b6100bd6004803603608081101561007257600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190505050610322565b604051808215151515815260200191505060405180910390f35b610138600480360360808110156100ed57600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff1690602001909291905050506103e5565b005b6101db600480360361010081101561015157600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190505050610512565b6040518082815260200191505060405180910390f35b6102446004803603606081101561020757600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190505050610597565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610284578082015181840152602081019050610269565b50505050905090810190601f1680156102b15780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610320600480360360808110156102d557600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff1690602001909291905050506105f8565b005b60006060610331868686610597565b9050600080826040518082805190602001908083835b6020831061036a5780518252602082019150602081019050602083039250610347565b6001836020036101000a03801982511681845116808217855250505050505090500191505090815260200160405180910390209050600060801b8160020160009054906101000a900460801b6fffffffffffffffffffffffffffffffff191611156103da576001925050506103dd565b50505b949350505050565b6103ed610730565b6040518060800160405280868152602001858152602001846fffffffffffffffffffffffffffffffff191681526020018361ffff1681525090506060610434868686610597565b9050816000826040518082805190602001908083835b6020831061046d578051825260208201915060208101905060208303925061044a565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600082015181600001556020820151816001015560408201518160020160006101000a8154816fffffffffffffffffffffffffffffffff021916908360801c021790555060608201518160020160106101000a81548161ffff021916908361ffff160217905550905050505050505050565b600061052089898989610322565b8015610534575061053385858585610322565b5b15610564577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60001b905061058b565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60001b90505b98975050505050505050565b606083838360405160200180848152602001838152602001826fffffffffffffffffffffffffffffffff19166fffffffffffffffffffffffffffffffff19168152602001935050505060405160208183030381529060405290509392505050565b6060610605858585610597565b905061060f610730565b60405180608001604052806000801b81526020016000801b8152602001600060801b6fffffffffffffffffffffffffffffffff19168152602001600061ffff168152509050806000836040518082805190602001908083835b6020831061068b5780518252602082019150602081019050602083039250610668565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600082015181600001556020820151816001015560408201518160020160006101000a8154816fffffffffffffffffffffffffffffffff021916908360801c021790555060608201518160020160106101000a81548161ffff021916908361ffff160217905550905050505050505050565b6040518060800160405280600080191681526020016000801916815260200160006fffffffffffffffffffffffffffffffff19168152602001600061ffff168152509056fea265627a7a72315820c75d434bbb0c9d4ddeddeebe0af1f6a1ba5e70a72a5cfb7a7629a2fc63005c1964736f6c63430005110032", "storage": {} }, "0x0000000000000000000000000000000000008888": {