๐ก
Personal notes to understand the protocol codebase
โฃ
main.go
Upon running the harmony build, the following logic is triggered:
getHarmonyConfiginitializes theHarmonyConfigwith the given flagssetupNodeAndRun- Sets the shard schedule based on its respective network (Mainnet, Testnet, etc.)
- Assuming the node type is
validator,setupStakingNodeAccountis run setupStakingNodeAccount- Loads BLS keys and set the keys to config
- Retrieve the Shard ID statically determined from the consensus key
- Ensure the keys are all in the same shard
- Append each key to
initialAccountswhich are the accounts used when the build is initially deployed - Create
nodeconfig.ConfigTypewhich is the configuration variables for a node off of theHarmonyConfigpreviously configured - Update each network id to be compatible with the Ethereum chain id (Why?)
setupConsensusAndNode- Set up blacklisted addresses, allowed transactions, and local accounts
- Set up database factory
- Set up engine which contains:
- Epoch context cache
- Verified signature cache
- Create a new shard chain collection with the db factory and the engine
- Create the blockchain for the current shard (beacon shard has to be initialized regardless)
- Create a new consensus with the deciders and provided configuration
- Create a new node with all of the above information
node.New() - Creates a node that represents a protocol-participating node in the network
- Instantiate syncing providers by following rules:
- If starting with a localnet or offline, use local sync peers.
- If specified with
--dns=false, use legacy syncing which is syncing through self-discover peers. - Else, use the dns for syncing.
InitConsensusWithValidatorsinitialize shard state from latest epoch and update committee pub keys for consensus- Set block verifier, which is a function to verify the block (account model) they are running consensus on