BeaconLeader adds IDs

pull/422/head
alok 6 years ago
parent 2cdcd201ef
commit ffd82d035c
  1. 5
      consensus/consensus.go
  2. 38
      node/node.go

@ -27,7 +27,6 @@ import (
"golang.org/x/crypto/sha3"
proto_discovery "github.com/harmony-one/harmony/api/proto/discovery"
proto_node "github.com/harmony-one/harmony/api/proto/node"
)
// Consensus is the main struct with all states and data related to consensus process.
@ -109,8 +108,8 @@ type Consensus struct {
OfflinePeerList []p2p.Peer
//List of nodes related to beaconchain funcs
WaitingNodes []proto_node.Info
ActiveNodes []proto_node.Info
WaitingNodes []common.Address
ActiveNodes []common.Address
}
// BFTBlockInfo send the latest block that was in BFT consensus process as well as its consensusID to state syncing

@ -570,6 +570,44 @@ func (node *Node) RemovePeersHandler() {
}
}
// This function will be used by the beaconLeader
// GetNewStakedNodes gives a list of all nodes that have deposited transaction
func (node *Node) GetNewStakedNodes() ([]common.Address) {
BlocksPerEpoch := 5 //Hardcoded, will take value from core.Blockchain later.
currentHeight := node.blockchain.CurrentBlock().NumberU64()
if currentHeight > BlocksPerEpoch {
prevBlock := currentHeight - BlocksPerEpoch
} else {
prevBlock := 0
}
return node.getNewStakedNodesFromBlockNumToBlockNum(prevBlock,currentHeight)
}
// This function will be used by the beaconLeader
//GetNewStakedNodesFromBlockNumToBlockNum gives a list of all nodes that have deposited transaction
func (node *Node) getNewStakedNodesFromBlockNumToBlockNum (prevBlockNum, toCurrentBlock uint64) ([]common.Address) {
Blockchain := node.Blockchain()
signerType := types.HomesteadSigner{}
newNodesMap = make(map[common.Address]int)
var newNodes []common.Address
for i := prevBlockNum,; i < toCurrentBlock + 1; i++ {
block = Blockchain.GetBlockByNumber(from)
txns = block.Transactions(),
for txn := range txns {
if txn.Value() > 0 { //If value >0 means its a staking deposit transaction
newSender := types.Sender(signerType,txn)
_, isPresent := newNodesMap[newSender]
if !isPresent {
newNodesMap[newSender] = 1
newNodes := append(newNodes, newSender)
}
}
}
}
return newNodes
}
func (node *Node) setupForShardLeader() {
// Register explorer service.
node.serviceManager.RegisterService(service_manager.SupportExplorer, explorer.New(&node.SelfPeer))

Loading…
Cancel
Save