Simulating a BP node
Description: A guide for simulating a block producer (BP) election and running BP nodes in a local environment within the aelf blockchain ecosystem.
Purpose: To instruct developers on how to set up, configure, and manage multiple nodes, participate in BP elections, and perform key operations for local environment simulations.
Set up a Full Node
To simulate BP nodes in a local environment, you need to set up at least three nodes, as a single node cannot become a BP. BP elections occur every 7 days, but for this tutorial, we'll change the term to 120 seconds. Follow the steps below:
-
Find the
appsettings.json
file in/.../src/AElf.Launcher
and configure the public keys of the three nodes:appsettings.json"Consensus": {
"InitialMinerList": [
"04884d9563b3b67a5*****526dd489e3805211cba710d956718*****",
"045670526219d7315*****8629891b0617ab605e646ae78961c*****",
"046a5913eae5fee3d*****3826beb2b7109b5141679a1927338*****"
],
"MiningInterval": 4000,
"StartTimestamp": 0,
"PeriodSeconds": 120,
"MinerIncreaseInterval": 31536000
} -
Change
PeriodSeconds
from 604800 to 120 for a 2-minute election term. -
Shut down nodes and delete all Redis data. Restart your multi-nodes.
Become a Candidate Node
-
Stake 100,000 ELF to join the node election. Ensure you have enough balance by checking with:
Terminalaelf-command call AElf.ContractNames.Token GetBalance '{"symbol": "ELF", "owner": "YOUR_ADDRESS"}'
-
If balance < 100,005 ELF, transfer ELF tokens using:
Terminalaelf-command send AElf.ContractNames.Token Transfer '{"symbol": "ELF", "to": "YOUR_ADDRESS", "amount": "10000000000000"}'
-
Announce your candidacy:
Terminalaelf-command send AElf.ContractNames.Election AnnounceElection '{"value": "YOUR_ADDRESS"}' -a YOUR_ADDRESS
-
Check candidate information:
Terminalaelf-command call AElf.ContractNames.Election GetCandidateInformation '{"value":"YOUR_PUBLIC_KEY"}'
Users Vote for Nodes
-
Create a user account:
Terminalaelf-command create
-
Transfer ELF to the new account for voting (e.g., 2000 ELF):
Terminalaelf-command send AElf.ContractNames.Token Transfer '{"symbol": "ELF", "to": "USER_ADDRESS", "amount": "200000000000"}'
-
Check balance of the new account:
Terminalaelf-command call AElf.ContractNames.Token GetBalance '{"symbol": "ELF", "owner": "USER_ADDRESS"}'
-
Vote for the candidate node (e.g., 20 ELF):
Terminalaelf-command send AElf.ContractNames.Election Vote '{"candidatePubkey":"CANDIDATE_PUBLIC_KEY","amount":2000000000,"endTimestamp":{"seconds":1600271999,"nanos":999000}}' -a USER_ADDRESS
-
Check candidate votes:
Terminalaelf-command call AElf.ContractNames.Election GetCandidateVote '{"value":"CANDIDATE_PUBLIC_KEY"}'
Become a BP
The top 2N+1 candidate nodes are elected as BPs in the next term. Get the list of current BPs:
aelf-command call AElf.ContractNames.Consensus GetCurrentMinerPubkeyList '{}'
Add More BPs
Repeat the steps to add more BPs. No need to edit appsettings.json
again. When candidate nodes exceed the max BPs, they replace genesis nodes, which cannot participate in elections again.
Proceed to contract deployment and DApp development guides for more details.