diff --git a/identitychain/identityblock.go b/identitychain/identityblock.go index b1f72df4f..46be703fe 100644 --- a/identitychain/identityblock.go +++ b/identitychain/identityblock.go @@ -30,6 +30,11 @@ func (b *IdentityBlock) Serialize() []byte { return result.Bytes() } +//Get Identities +func (b *IdentityBlock) GetIdentities() []*waitnode.WaitNode { + return b.Identities +} + // DeserializeBlock deserializes a block func DeserializeBlock(d []byte) *IdentityBlock { var block IdentityBlock diff --git a/identitychain/identitychain.go b/identitychain/identitychain.go index c92193d61..359c079a8 100644 --- a/identitychain/identitychain.go +++ b/identitychain/identitychain.go @@ -16,20 +16,50 @@ var identityPerBlock = 100000 // IdentityChain (Blockchain) keeps Identities per epoch, currently centralized! type IdentityChain struct { - Identities []*IdentityBlock - PendingIdentities []*waitnode.WaitNode - log log.Logger - Peer p2p.Peer + Identities []*IdentityBlock + PendingIdentities []*waitnode.WaitNode + log log.Logger + Peer p2p.Peer + SelectedIdentitites []*waitnode.WaitNode + EpochNum int + PeerToShardMap map[p2p.Peer]int + ShardLeaderMap map[int]p2p.Peer + PubKey string + CurrentEpochStartTime int64 + NumberOfShards int + NumberOfNodesInShard int +} + +func seekRandomNumber(EpochNum int, SelectedIdentitites []*waitnode.WaitNode) int { + return 10 } //GlobalBlockchainConfig stores global level blockchain configurations. type GlobalBlockchainConfig struct { - NumberOfShards int - EpochTimeSecs int16 + NumberOfShards int + EpochTimeSecs int16 + MaxNodesInShard int +} + +//Shard +func (IDC *IdentityChain) Shard() { + num := seekRandomNumber(IDC.EpochNum, IDC.SelectedIdentitites) + fmt.Println(num) +} + +// SelectIds +func (IDC *IdentityChain) SelectIds() { + selectNumber := IDC.NumberOfNodesInShard - len(IDC.Identities) + IB := IDC.GetLatestBlock() + currentIDS := IB.GetIdentities() + pending := IDC.PendingIdentities[:selectNumber] + IDC.SelectedIdentitites = append(currentIDS, pending...) + IDC.PendingIdentities = []*waitnode.WaitNode{} } -func (IDC *IdentityChain) shard() { - return +//Checks how many new shards we need. Currently we say 0. +func needNewShards() int { + return 0 } // GetLatestBlock gests the latest block at the end of the chain