From ffd82d035ca7101c67201f4529a1306ea2d44983 Mon Sep 17 00:00:00 2001 From: alok Date: Mon, 11 Feb 2019 01:18:07 -0800 Subject: [PATCH] BeaconLeader adds IDs --- consensus/consensus.go | 5 ++--- node/node.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/consensus/consensus.go b/consensus/consensus.go index 70f75af11..501e03833 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.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 diff --git a/node/node.go b/node/node.go index 74cd85d61..7190cf032 100644 --- a/node/node.go +++ b/node/node.go @@ -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))