aelf 백서

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 41쪽 중 40쪽

k information after packaging. Request : rpc BlockBroadcastStream ( stream BlockWithTransactions ) returns ( VoidReply ) { } TransactionBroadcastStream ​ Receives forwarded transaction information. Request : rpc TransactionBroadcastStream ( stream aelf.Transaction ) returns ( VoidReply ) { } AnnouncementBroadcastStream ​ Receives block announcements. Request : rpc AnnouncementBroadcastStream ( stream BlockAnnouncement ) returns ( VoidReply ) { } LibAnnouncementBroadcastStream ​ Receives last irreversible block (LIB) announcements. Request : rpc LibAnnouncementBroadcastStream ( stream LibAnnouncement ) returns ( VoidReply ) { } Block Request ​ RequestBlock ​ Requests a single block. Request : rpc RequestBlock ( BlockRequest ) returns ( BlockReply ) { } RequestBlocks ​ Requests multiple blocks. Request : rpc RequestBlocks ( BlocksRequest ) returns ( BlockList ) { } Peer Management ​ Ping ​ Verifies network availability. Request : rpc Ping ( PingRequest ) returns ( PongReply ) { } CheckHealth ​ Performs health checks on peers. Request : rpc CheckHealth ( HealthCheckRequest ) returns ( HealthCheckReply ) { } Introduction Architecture aelf.OS aelf.OS.Core.Network aelf.OS.Network.Grpc Protocol Connection Broadcasting Block Request Peer Management ## /learn/boot-sequence On this page aelf Blockchain Boot Sequence This guide explains how the aelf Blockchain starts from initial nodes and transitions to production nodes through elections, completing the full startup process. Start Initial Nodes ​ To begin the aelf Blockchain, you need to start at least one initial node. It’s recommended to start with 1-5 initial nodes. Follow these steps to start multiple nodes: ​ Setup Initial Nodes: ​ Refer to the "Getting Started" section for detailed steps. This example uses three initial nodes. Election Time Configuration: ​ The default election period is 604800 seconds (7 days). To see election results faster, modify the configuration file appsettings.json to set the PeriodSeconds to a smaller value: appsettings.json { "Consensus" : { "PeriodSeconds" : 604800 } } By following these steps, you can successfully start the aelf Blockchain with initial nodes and prepare for the election of production nodes. Run a Full Node Create an Account for the Full Node ​ To create an account for the full node, use the following command: Terminal aelf-command create You will receive your wallet information, which includes the mnemonic, private key, public key, and address. Here is an example of the output: Terminal AElf [ Info ] : Your wallet info is : AElf [ Info ] : Mnemonic : major clap hurdle hammer push slogan ranch quantum reunion hope enroll repeat AElf [ Info ] : Private Key : 2229945 cf294431183fd1d8101e27b17a1a590d3a1f7f2b9299850b24262ed8a AElf [ Info ] : Public Key : 04 eed00eb009ccd283798e3862781cebd25ed6a4641e0e1b7d0e3b6b59025040679fc4dc0edc9de166bd630c7255188a9aeadfc832fdae0828270f77c6ef267905 AElf [ Info ] : Address : Q3t34SAEsxAQrSQidTRzDonWNTPpSTgH8bqu8pQUGCSWRPdRC Start the Full Node ​ Starting the full node involves similar steps to starting the initial nodes. However, ensure that the InitialMinerList in your configuration file matches the list from the initial node setup. Here is an example configuration: { "InitialMinerList" : [ "0499d3bb14337961c4d338b9729f46b20de8a49ed38e260a5c19a18da569462b44b820e206df8e848185dac6c139f05392c268effe915c147cde422e69514cc927" , "048397dfd9e1035fdd7260329d9492d88824f42917c156aef93fd7c2e3ab73b636f482b8ceb5cb435c556bfa067445a86e6f5c3b44ae6853c7f3dd7052609ed40b" , "041cc962a51e7bbdd829a8855eca8a03fda708fdf31969251321cb31edadd564bf3c6e7ab31b4c1f49f0f206be81dbe68a75c70b293bf9d04d867ee5e415d3bf8a" ] } By following these steps, you can successfully create an account and start your full node, ensuring it is properly configured to participate in the aelf blockchain network. Full node started successfully: ​ After starting the full node, verify its status to ensure it's properly synchronizing with the blockchain. Check Node State ​ To check the current state of the node, use the following command: Terminal aelf-command get-chain-status This command will output the current status of the blockchain. Here's an example of what you might see: { "ChainId" : "AELF" , "Branches" : { "fb749177c2f43db8c7d73ea050240b9f870c40584f044b13e7ec146c460b0eff" : 2449 } , "NotLinkedBlocks" : { } , "LongestChainHeight" : 2449 , "LongestChainHash" : "fb749177c2f43db8c7d73ea050240b9f870c40584f044b13e7ec146c460b0eff" , "GenesisBlockHash" : "ea9c0b026bd638ceb38323eb71174814c95333e39c62936a38c4e01a8f18062e" , "GenesisContractAddress" : "pykr77ft9UUKJZLVq15wCH8PinBSjVRQ12sD1Ayq92mKFsJ1i" , "LastIrreversibleBlockHash" : "66638f538038bd56357f3cf205424e7393c5966830ef0d16a75d4a117847e0bc" , "LastIrreversibleBlockHeight" : 2446 , "BestChainHash" : "fb749177c2f43db8c7d73ea050240b9f870c40584f044b13e7ec146c460b0eff" , "BestChainHeight" : 2449 } Understanding the Output ​ When running a full node on the aelf blockchain network, the following key information is crucial for monitoring and understanding the node's status: ChainId : The identifier of the blockchain. Branches : Current branches in the chain, showing the hash and height. NotLinkedBlocks : Blocks that are not yet linked to the main chain. LongestChainHeight : The height of the longest chain. LongestChainHash : The hash of the longest chain. GenesisBlockHash : The hash of the genesis block. GenesisContractAddress : The address of the genesis contract. LastIrreversibleBlockHash : The hash of the last irreversible block. LastIrreversibleBlockHeight : The height of the last irreversible block. BestChainHash : The hash of the best chain. BestChainHeight : The height of the best chain. The BestChainHeight and LastIrreversibleBlockHeight should be increasing as the full node catches up with the initial nodes. Once the heights match, the node is fully synchronized, and you can proceed with further steps. By following these details, you ensure that your full node is correctly set up and actively participating in the aelf blockchain network. Become a Candidate Node ​ To participate in the election process and become a candidate node, full nodes need to interact with the Election contract. Here's a step-by-step guide: Step 1: Ensure Sufficient Tokens ​ Full nodes must stake mortgage 10W ELF tokens to become candidates. Ensure your node's account has enough tokens. For demonstration purposes, you can transfer tokens from the initial node account to the full node account. Transfer Tokens: ​ aelf-command send AElf.ContractNames.Token Transfer '{"symbol": "ELF", "to": "Q3t34SAEsxAQrSQidTRzDonWNTPpSTgH8bqu8pQUGCSWRPdRC", "amount": "20000000000000"}' Check Balance: ​ aelf - command call AElf . ContractNames . Token GetBalance '{"symbol": "ELF", "owner": "Q3t34SAEsxAQrSQidTRzDonWNTPpSTgH8bqu8pQUGCSWRPdRC"}' Expected Result: ​ { "symbol" : "ELF" , "owner" : "Q3t34SAEsxAQrSQidTRzDonWNTPpSTgH8bqu8pQUGCSWRPdRC" , "balance" : "20000000000000" } This result confirms that the full node account has 20W ELF tokens. Step 2: Announce Candidacy ​ Announce your candidacy using the Election contract. The AnnounceElection transaction requires the admin address to be specified. Announce Election: ​ aelf - command send AElf . ContractNames . Election AnnounceElection '{"value": "Q3t34SAEsxAQrSQidTRzDonWNTPpSTgH8bqu8pQUGCSWRPdRC"}' - a Q3t34SAEsxAQrSQidTRzDonWNTPpSTgH8bqu8pQUGCSWRPdRC Step 3: Verify Candidacy ​ Check the candidate information to confirm that your full node is now a candidate. Check Candidate Information:: ​ aelf - command call AElf . ContractNames . Election GetCandidateInformation '{"value":"04eed00eb009ccd283798e3862781cebd25ed6a4641e0e1b7d0e3b6b59025040679fc4dc0edc9de166bd630c7255188a9aeadfc832fdae0828270f77c6ef267905"}' Expected Result: ​ { "terms" : [ ] , "pubkey" : "04eed00eb009ccd283798e3862781cebd25ed6a4641e0e1b7d0e3b6b59025040679fc4dc0edc9de166bd630c7255188a9aeadfc832fdae0828270f77c6ef267905" , "producedBlocks" : "0" , "missedTimeSlots" : "0" , "continualAppointmentCount" : "0" , "announcementTransactionId" : "8cc8eb5de35e390e4f7964bbdc7edc433498b041647761361903c6165b9f8659" , "isCurrentCandidate" : true } This result indicates that the full node is now a candidate for the election, with the isCurrentCandidate field set to true . By following these steps, your full node can successfully enter the election process and participate as a candidate node in the aelf blockchain network. User vote election To demonstrate user voting in the election, follow these steps to create a user account, transfer tokens to the account, and then vote for a candidate node. Step 1: Create a User Account ​ Create a new user account using the command below: aelf-command create You will receive the following wallet information: AElf [Info]: Your wallet info is : AElf [Info]: Mnemonic : walnut market museum play grunt chuckle hybrid accuse relief misery share meadow AElf [Info]: Private Key : 919a220fac2d80e674a256f2367ac840845f344269f4dcdd56d37460de17f947 AElf [Info]: Public Key : 04794948de40ffda2a6c884d7e6a99bb8e42b8b96b9ee5cc4545da3a1d5f7725eec93de62ddbfb598ef6f04fe52aa310acc7d17abeeea3946622573c4b0b2433ac AElf [Info]: Address : ZBBPU7DMVQ72YBQNmaKTDPKaAkHNzzA3naH5B6kE7cBm8g1ei Step 2: Transfer Tokens to the User Account ​ After the user account is created successfully, we will first transfer some tokens to the account for voting. Transfer Tokens: ​ aelf - command send AElf . ContractNames . Token Transfer '{"symbol": "ELF", "to": "ZBBPU7DMVQ72YBQNmaKTDPKaAkHNzzA3naH5B6kE7cBm8g1ei", "amount": "200000000000"}' Confirm the Balance: ​ aelf - command call AElf . ContractNames . Token GetBalance '{"symbol": "ELF", "owner": "ZBBPU7DMVQ72YBQNmaKTDPKaAkHNzzA3naH5B6kE7cBm8g1ei"}' Expected Result: ​ { "symbol" : "ELF" , "owner" : "ZBBPU7DMVQ72YBQNmaKTDPKaAkHNzzA3naH5B6kE7cBm8g1ei" , "balance" : "200000000000" } This confirms the user account has received the tokens. Step 3: Vote for a Candidate Node ​ Use the Election contract to vote for a candidate node. Here, we vote for the node with the public key 04eed00eb009ccd283798e3862781cebd25ed6a4641e0e1b7d0e3b6b59025040679fc4dc0edc9de166bd630c7255188a9aeadfc832fdae0828270f77c6ef267905 . Cast Vote: ​ aelf - command send AElf . ContractNames . Election Vote '{"candidatePubkey":"04eed00eb009ccd283798e3862781cebd25ed6a4641e0e1b7d0e3b6b59025040679fc4dc0edc9de166bd630c7255188a9aeadfc832fdae0828270f77c6ef267905","amount":2000000000,"endTimestamp":{"seconds":1600271999,"nanos":999000}}' - a ZBBPU7DMVQ72YBQNmaKTDPKaAkHNzzA3naH5B6kE7cBm8g1ei Step 4: Verify the Vote ​ Check the votes received by the candidate node to ensure your vote has been counted. Check Candidate Votes: ​ aelf - command call AElf . ContractNames . Election GetCandidateVote '{"value":"04eed00eb009ccd283798e3862781cebd25ed6a4641e0e1b7d0e3b6b59025040679fc4dc0edc9de166bd630c7255188a9aeadfc832fdae0828270f77c6ef267905"}' Expected Result: ​ { "obtainedActiveVotingRecordIds" : [ "172375e9cee303ce60361aa73d7326920706553e80f4485f97ffefdb904486f1" ] , "obtainedWithdrawnVotingRecordIds" : [ ] , "obtainedActiveVotingRecords" : [ ] , "obtainedWithdrawnVotesRecords" : [ ] , "obtainedActiveVotedVotesAmount" : "2000000000" , "allObtainedVotedVotesAmount" : "2000000000" , "pubkey" : "04eed00eb009ccd283798e3862781cebd25ed6a4641e0e1b7d0e3b6b59025040679fc4dc0edc9de166bd630c7255188a9aeadfc832fdae0828270f77c6ef267905" } This result confirms that the full node has successfully obtained 20 votes from the user account. Become production node In the next election, the candidate nodes with the highest number of votes (up to 17) will automatically be elected as production nodes. You can view the current list of production nodes through the consensus contracts. Viewing the Current Production Nodes ​ To see the current list of production nodes, use the following command: aelf-command call AElf.ContractNames.Consensus GetCurrentMinerPubkeyList '{}' Expected Result: ​ { "pubkeys" : [ "0499d3bb14337961c4d338b9729f46b20de8a49ed38e260a5c19a18da569462b44b820e206df8e848185dac6c139f05392c268effe915c147cde422e69514cc927" , "048397dfd9e1035fdd7260329d9492d88824f42917c156aef93fd7c2e3ab73b636f482b8ceb5cb435c556bfa067445a86e6f5c3b44ae6853c7f3dd7052609ed40b" , "041cc962a51e7bbdd829a8855eca8a03fda708fdf31969251321cb31edadd564bf3c6e7ab31b4c1f49f0f206be81dbe68a75c70b293bf9d04d867ee5e415d3bf8a" , "04eed00eb009ccd283798e3862781cebd25ed6a4641e0e1b7d0e3b6b59025040679fc4dc0edc9de166bd630c7255188a9aeadfc832fdae0828270f77c6ef267905" ] } In this example, the node with the public key 04eed00eb009ccd283798e3862781cebd25ed6a4641e0e1b7d0e3b6b59025040679fc4dc0edc9de166bd630c7255188a9aeadfc832fdae0828270f77c6ef267905 has been elected as a production node. Add more production nodes To add more production nodes, follow these steps: Repeat Steps for Creating Full Nodes: Create additional full nodes by repeating the process described earlier for creating and starting full nodes. Nominate Additional Nodes: Follow the process of nominating these full nodes as candidate nodes and ensure they receive sufficient votes. When the number of initial nodes and candidate nodes exceeds the maximum number of production nodes, the initial nodes will gradually be replaced by the newly elected production nodes. Note that once an initial node is replaced, it cannot run for election again. At this point, the initial node has completed its role in starting the AElf Blockchain. Example Workflow: ​ 1. Create Additional Full Nodes: ​ aelf - command create 2. Transfer Tokens to New Nodes: ​ aelf - command send AElf . ContractNames . Token Transfer '{"symbol": "ELF", "to": "<new_node_address>", "amount": "200000000000"}' 3. Nominate New Nodes as Candidates: ​ aelf - command send AElf . ContractNames . Election AnnounceElection '{"value": "<new_node_address>"}' - a < new_node_address > 4. Vote for New Candidates: ​ aelf - command send AElf . ContractNames . Election Vote '{"candidatePubkey":"<new_node_pubkey>","amount":2000000000,"endTimestamp":{"seconds":<timestamp>,"nanos":999000}}' - a < user_address > By following these steps, you can ensure a smooth transition from initial nodes to production nodes, maintaining the stability and performance of the AElf Blockchain. Start Initial Nodes Follow these steps to start multiple nodes: Create an Account for the Full Node Start the Full Node Full node started successfully: Understanding the Output Become a Candidate Node Step 1: Ensure Sufficient Tokens Step 2: Announce Candidacy Step 3: Verify Candidacy Example Workflow: ## /learn/addresses On this page Address Overview ​ Changes within the aelf blockchain occur through the execution of transactions. An address within aelf identifies a participant in a transaction, either as the sender or the recipient. The sender is denoted as From , while the recipient is denoted as To . From can represent: User Address : Identifies an individual participant. Contract Address : Identifies a smart contract. Virtual Address : Represents a virtual entity within the blockchain. To is exclusively a Contract Address , indicating that the transaction sender intends to execute a specific method within that smart contract. For further details on each type of address in the aelf blockchain, please see below. User Address ​ A User Address in aelf is generated from a unique key pair owned by a real user of the blockchain. Here’s how it works: Key Pair Generation: ​ A User Address is derived from a key pair using the IAElfAsymmetricCipherKeyPair interface. This interface includes public interface IAElfAsymmetricCipherKeyPair { byte [ ] PrivateKey { get ; } byte [ ] PublicKey { get ; } } Currently, aelf blockchain utilizes ECKeyPair for this purpose, similar to many other blockchain systems. Generating a Key Pair: ​ Users can use the aelf-command tool to create a valid ECKeyPair: aelf-command create You will need to provide a valid password. The tool generates a .json file containing the public and private keys, encrypted with your password. Using dApp SDK: ​ For dApp developers, the aelf JavaScript SDK js-sdk ` offers a method based on bip39 for deterministic key pair generation: import Aelf from 'aelf-sdk' ; Aelf . wallet . createNewWallet ( ) ; This method returns an object with the mnemonic, key pair, and address encoded in base58. Generating an Address ​ When you create a new wallet using the aelf-sdk , it will return an object with three important parts: Mnemonic : A phrase used to generate the key pair. Key Pair : Contains the public and private keys. Address : The unique identifier for the wallet. In aelf, we usually encode the address in a format called base58. The address is derived from the public key by taking the first 30 bytes of its double SHA-256 hash. Here's how you can get the address from the public key using the aelf-sdk: import Aelf from 'aelf-sdk' ; const address = Aelf . wallet . getAddressFromPubKey ( pubKey ) ; Address Representation: ​ The User Address in aelf is represented using Protobuf message Address option csharp_namespace = "AElf.Types" ; message Address { bytes value = 1 ; } In summary, a User Address in aleft blockchain is fundamental for identifying users and interacting with the blockchain securely and effectively. Contract Address ​ A Contract Address in aelf blockchain uniquely identifies a Smart Contract. Here’s how it’s created: 1. Calculation Method: ​ A Contract Address is determined during the deployment of a Smart Contract. It’s calculated using a combination of the blockchain's chain id and a *serial number associated with the contract. 2. Implementation: ​ Here’s how you can build a Contract Address in aelf: private static Address BuildContractAddress ( Hash chainId , long serialNumber ) { var hash = HashHelper . ConcatAndCompute ( chainId , HashHelper . ComputeFrom ( serialNumber ) ) ; return Address . FromBytes ( hash . ToByteArray ( ) ) ; } public static Address BuildContractAddress ( int chainId , long serialNumber ) { return BuildContractAddress ( HashHelper . ComputeFrom ( chainId ) , serialNumber ) ; } HashHelper.ConcatAndCompute : Combines the chain id and serial number hashes. Address.FromBytes : Converts the resulting hash into a readable Address format. 3. Usage: ​ Developers deploying Smart Contracts on aelf blockchain use these methods to generate unique Contract Addresses dynamically. In essence, a Contract Address in aelf blockchain ensures each Smart Contract can be uniquely identified and interacted with securely across the network. Contract Virtual Address ​ In the aelf blockchain, every contract has the capability to create additional virtual addresses based on its main Address. These virtual addresses are known as Virtual Addresses . 1. Creation Process: ​ Virtual Addresses are generated by applying a hash function to the main Address of the contract. This process allows contracts to create multiple unique identifiers dynamically. 2. Use Case: ​ For instance, in aelf blockchain, when transferring tokens using the MultiToken contract, both sender and recipient are identified by their respective Addresses. Virtual Addresses extend this functionality by enabling the creation of unique identifiers for specific transactions or actions within a contract. 3. Creation Process: ​ Virtual Addresses are controlled exclusively by the primary contract. This capability allows contracts to manage transactions and funds independently for each user, ensuring secure custody. 4. Utility: ​ Virtual Addresses serve as reliable identifi
프로젝트로 돌아가기