https://www.cnblogs.com/sumingk/articles/9097996.html
The last article introduced the construction of get node of private chain in Yitaifang. This article introduced the construction of enterprise application alliance chain, using parity wallet as service node to realize multi-node construction of alliance chain.
I. parity consensus POA
Students who understand block chains should have heard of POW and POS consensus algorithms. What is the working principle of parity's poa? The full name of Poa is Proof of Authority, which is the proof of working rights and interests.
The characteristics of poa:
- Unlike PoW (Proof-of-Work), which needs to solve mathematical problems to generate blocks, PoA relies on preset Authority nodes to generate blocks.
- The number of Authority node s can be set as required.
- You can specify the time at which a block is generated, such as five seconds after the transaction is received.
- Ordinary Ethereum node s can also connect to PoA Chain, initiate transactions, contracts, etc.
- It can be applied in enterprises to build alliance chain of multi-enterprises.
II. parity download and installation
parity github: https://github.com/paritytech/parity
parity download address: https://github.com/paritytech/parity/releases
Select stable version Parity 1.10.4-stable
Download the corresponding binary files according to your own version of linux system
Ubununtu 16.04 x64 I use here
1.wget https://d1h4xl4cr1h0mo.cloudfront.net/v1.10.4/x86_64-unknown-linux-gnu/parity#download
2.chmod 775 parity # modify executable file
3. / parity - V # Check parity version
If v1.10.4 version information is displayed, the installation is successful
Configuration of genesis-spec.json Block
>$ mkdir parity
>$ cd parity
>$vim genesis-spec.json
{ "name": "DemoPoA", "engine": { "authorityRound": { "params": { "stepDuration": "2", "validators" : { "list": [] } } } }, "params": { "gasLimitBoundDivisor": "0x400", "maximumExtraDataSize": "0x20", "minGasLimit": "0x1388", "networkID" : "0x2323" }, "genesis": { "seal": { "authorityRound": { "step": "0x0", "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } }, "difficulty": "0x10000", "gasLimit": "0x12a05f200" }, "accounts": { "0x0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } }, "0x0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } }, "0x0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } }, "0x0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } }, "0x6a67f9275dfe3abac6fd5525dec804551cbb7f00": { "balance": "1000000000000000000000000" }, "0xd62de1cbcf85253b776305ab45fd85367187bc29": { "balance": "1000000000000000000000000" } } }
Name: Genesis document name
engine: Node engine, where the verifier address is added to the list by writing the verifier to death
params: Network ID Alliance Chain Node ID
Accounts: Initialize accounts
Friendship Tip: For more detailed configuration, refer to parity wiki: https://wiki.parity.io/Chain-specification
IV. Adding Node Profile
>$ vim node1.toml
[parity]
Chain = Genesis-spec.json # Genesis Block File
Base_path= "parity 0"# Create the parity 0 folder, representing the first node
[network]
port = 30300 Network Port
[rpc]
Port = 8540 RPC request port
APIs = ["web3", "eth", "net", "personal", "parity", "parity", "parity_set", "traces", "rpc", "parity_accounts"] # supported RPC requests
# Interface = 192.168.1.175"# Default rpc request address
[ui]
Port = 8180 parity UI web ports
hosts = ["all"]
[account]
password = ["node.pwds"] node parity 0 password
[websockets]
port = 8456
[ipc]
disable = true # does not support ipc access
[mining]
engine_signer = "0x005C6F320C425675bAE78BcF693AE2e6d63e9853" # Miner's address
reseal_on_txs = "none"
5. Create User Name Password Storage File
> touch node. PWDs (create node miner password)
>$ vim node.pwds
123
6. Creating Node Association Files
> Touch reserved Peers. eNode (temporarily created, added when creating the first node)
7. Creating Initialized Users
>$ ./parity account new --config node0.toml
8. Modify genesis-spec.json to add a verifier
{ "name": "DemoPoA", "engine": { "authorityRound": { "params": { "stepDuration": "2", "validators" : { "list": ["0x6a67f9275dfe3abac6fd5525dec804551cbb7f00"]
} } } }, "params": { "gasLimitBoundDivisor": "0x400", "maximumExtraDataSize": "0x20", "minGasLimit": "0x1388", "networkID" : "0x2323" }, "genesis": { "seal": { "authorityRound": { "step": "0x0", "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } }, "difficulty": "0x10000", "gasLimit": "0x12a05f200" }, "accounts": { "0x0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } }, "0x0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } }, "0x0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } }, "0x0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } }, "0x6a67f9275dfe3abac6fd5525dec804551cbb7f00": { "balance": "1000000000000000000000000" }, "0x6a67f9275dfe3abac6fd5525dec804551cbb7f00": { "balance": "1000000000000000000000000" }
}
}
9. Modify configuration nodes
10. Start parity
>$ ./parity --config node1.toml
At present, a parity node has been built.
11. Using contract management node verifier (dynamic contract management)
The following is the complete genesis-spec.json file configuration
{ "name": "DemoPoA", "engine": { "authorityRound": { "params": { "stepDuration": "5", "validators": { "safeContract":"0x0000000000000000000000000000000000000005" } } } }, "params": { "gasLimitBoundDivisor": "0x0400", "maximumExtraDataSize": "0x20", "minGasLimit": "0x1388", "networkID": "0x2323" }, "genesis": { "seal": { "authorityRound": { "step": "0x0", "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } }, "difficulty": "0x20000", "gasLimit": "0x5B8D80" }, "accounts": { "0x0000000000000000000000000000000000000001": { "balance": "1", "builtin": { "name": "ecrecover", "pricing": { "linear": { "base": 3000, "word": 0 } } } }, "0x0000000000000000000000000000000000000002": { "balance": "1", "builtin": { "name": "sha256", "pricing": { "linear": { "base": 60, "word": 12 } } } }, "0x0000000000000000000000000000000000000003": { "balance": "1", "builtin": { "name": "ripemd160", "pricing": { "linear": { "base": 600, "word": 120 } } } }, "0x0000000000000000000000000000000000000004": { "balance": "1", "builtin": { "name": "identity", "pricing": { "linear": { "base": 15, "word": 3 } } } }, "0x00A7135cf451B2463517D11e0cE88013042e0a28": { "balance": "80000000000000000000000" }, "0x0000000000000000000000000000000000000005":{ "balance": "1", "constructor":"0x606060405260008054600160a060020a0319169055341561001f57600080fd5b6020604051908101604052725c6f320c425675bae78bcf693ae2e6d63e9853815261004e906002906001610131565b5061006464010000000061017a61006982021704565b6101ff565b600554600090819060ff161561007e57600080fd5b600091505b60025482101561010357600280548390811061009b57fe5b600091825260209091200154600160a060020a03169050604080519081016040908152600182526020808301859052600160a060020a03841660009081526004909152208151815460ff19169015151781556020820151600191820155929092019150610083565b6005805460ff1916600190811790915560028054610122929190610198565b50506003805460ff1916905550565b828054828255906000526020600020908101928215610188579160200282015b828111156101885782518254600160a060020a031916600160a060020a039190911617825560209290920191600190910190610151565b506101949291506101d8565b5090565b8280548282559060005260206000209081019282156101885760005260206000209182015b828111156101885782548255916001019190600101906101bd565b6101fc91905b80821115610194578054600160a060020a03191681556001016101de565b90565b61073c8061020e6000396000f3006060604052600436106100775763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166305c81865811461007c578063170f92911461009157806340a141ff146100c35780634d238c8e146100e25780637528621114610101578063b7ab4db514610114575b600080fd5b341561008757600080fd5b61008f61017a565b005b341561009c57600080fd5b6100a7600435610242565b604051600160a060020a03909116815260200160405180910390f35b34156100ce57600080fd5b61008f600160a060020a036004351661026a565b34156100ed57600080fd5b61008f600160a060020a03600435166103b7565b341561010c57600080fd5b61008f610464565b341561011f57600080fd5b61012761052f565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561016657808201518382015260200161014e565b505050509050019250505060405180910390f35b600554600090819060ff161561018f57600080fd5b600091505b6002548210156102145760028054839081106101ac57fe5b600091825260209091200154600160a060020a03169050604080519081016040908152600182526020808301859052600160a060020a03841660009081526004909152208151815460ff19169015151781556020820151600191820155929092019150610194565b6005805460ff191660019081179091556002805461023392919061063a565b50506003805460ff1916905550565b600180548290811061025057fe5b600091825260209091200154600160a060020a0316905081565b600160a060020a03811660009081526004602052604081205481908190849060ff16156103b057600160a060020a038516600090815260046020526040902060010154600280549195506000198201945090849081106102c657fe5b60009182526020909120015460028054600160a060020a0390921693508391869081106102ef57fe5b6000918252602080832091909101805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a039485161790559184168152600490915260409020600101849055600280548490811061034657fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19169055600280549061037f90600019830161068a565b50600160a060020a03851660009081526004602052604081206001810191909155805460ff191690556103b0610598565b5050505050565b600160a060020a038116600090815260046020526040902054819060ff1615156104605760028054600160a060020a03841660009081526004602052604090206001908101829055810161040b838261068a565b506000918252602080832091909101805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03861690811790915582526004905260409020805460ff19166001179055610460610598565b5050565b60005433600160a060020a039081169116141580610484575060035460ff165b1561048e57600080fd5b6002805461049e9160019161063a565b506003805460ff191660019081179091557f8564cd629b15f47dc310d45bcbfc9bcf5420b0d51bf0659a16c67f91d27632539060405160208082528254908201819052819060408201908490801561051f57602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610501575b50509250505060405180910390a1565b6105376106b3565b600180548060200260200160405190810160405280929190818152602001828054801561058d57602002820191906000526020600020905b8154600160a060020a0316815260019091019060200180831161056f575b505050505090505b90565b60035460ff1615156105a957600080fd5b6003805460ff191690556000194301407f55252fa6eee4741b4e24a74a70e9c11fd2c2281df8d6ea13126ff845f7825c89600260405160208082528254908201819052819060408201908490801561062a57602002820191906000526020600020905b8154600160a060020a0316815260019091019060200180831161060c575b50509250505060405180910390a2565b82805482825590600052602060002090810192821561067a5760005260206000209182015b8281111561067a57825482559160010191906001019061065f565b506106869291506106c5565b5090565b8154818355818115116106ae576000838152602090206106ae9181019083016106f6565b505050565b60206040519081016040526000815290565b61059591905b8082111561068657805473ffffffffffffffffffffffffffffffffffffffff191681556001016106cb565b61059591905b8082111561068657600081556001016106fc5600a165627a7a72305820e802334540c1fab99433710f3e01f32156cca8fb5321c2d69963ee71a09b944b0029" } } }
The following are contracts for dynamic management of validators
pragma solidity ^0.4.15; contract ValidatorSet { event InitiateChange(bytes32 indexed _parent_hash, address[] _new_set); function getValidators() public constant returns (address[] _validators); function finalizeChange() public; } contract MajorityList is ValidatorSet { event ChangeFinalized(address[] current_set); struct ValidatorStatus { bool isValidator; uint index; } address SYSTEM_ADDRESS = 0x0000000000000000000000000000000000000000; address[] public validatorsList; address[] pendingList; bool finalized; mapping(address => ValidatorStatus) validatorsStatus; bool private initialized; function MajorityList() public { pendingList = [0x005C6F320C425675bAE78BcF693AE2e6d63e9853]; initializeValidators(); } modifier uninitialized() { if (initialized) { revert();} _; } modifier when_finalized() { if (!finalized) { revert();} _; } modifier only_system_and_not_finalized() { if (msg.sender != SYSTEM_ADDRESS || finalized) { revert(); } _; } modifier is_validator(address someone) { if (validatorsStatus[someone].isValidator) { _; } } modifier is_not_validator(address someone) { if (!validatorsStatus[someone].isValidator) { _; } } function initializeValidators() public uninitialized { for (uint j = 0; j < pendingList.length; j++) { address validator = pendingList[j]; validatorsStatus[validator] = ValidatorStatus({ isValidator: true, index: j }); } initialized = true; validatorsList = pendingList; finalized = false; } function initiateChange() private when_finalized { finalized = false; emit InitiateChange(block.blockhash(block.number - 1), pendingList); } function finalizeChange() public only_system_and_not_finalized { validatorsList = pendingList; finalized = true; emit ChangeFinalized(validatorsList); } function addValidator(address validator) public is_not_validator(validator){ validatorsStatus[validator].index = pendingList.length; pendingList.push(validator); validatorsStatus[validator].isValidator = true; initiateChange(); } function removeValidator(address validator) public is_validator(validator){ uint removedIndex = validatorsStatus[validator].index; uint lastIndex = pendingList.length-1; address lastValidator = pendingList[lastIndex]; pendingList[removedIndex] = lastValidator; validatorsStatus[lastValidator].index = removedIndex; delete pendingList[lastIndex]; pendingList.length--; validatorsStatus[validator].index = 0; validatorsStatus[validator].isValidator = false; initiateChange(); } function getValidators() public constant returns (address[]) { return validatorsList; } }
This part of the code has been changed to accommodate parity deployment.
Several Ways to Get Contract Binary File bytecode
1. If parity can already start the UI interface, deployment contracts (it is possible that parity wallets cannot be compiled)
2. Binary files can be obtained by compiling mist wallet built with last article get: https://www.cnblogs.com/sumingk/articles/9030469.html
I'm using a Mist wallet to compile the contract here, and sometimes the contract for parity node deployment never loads.
12. Edit reservedPeers.enode file and add node information
To add more than one parity, you need to add the other eNode in reservedPeers.enode
Start node. / parity -- config node 1. toml