func GetValidatorHash(s *primitives.State) chainhash.Hash {
	committeesPerShard := make(map[uint64]primitives.ShardAndCommittee)

	for _, slotAssignment := range s.ShardAndCommitteeForSlots {
		for _, committee := range slotAssignment {
			committeesPerShard[committee.Shard] = committee
		}
	}

	validatorMsgs := make(map[chainhash.Hash][32]byte, 0)
	for shardID, committee := range committeesPerShard {
		for idx, valIdx := range committee.Committee {
			val := s.ValidatorRegistry[valIdx]

			var key [16]byte
			binary.BigEndian.PutUint64(key[:], shardID)
			binary.BigEndian.PutUint64(key[8:], uint64(idx))

			k := chainhash.HashH(key[:])

			validatorMsgs[k] = chainhash.HashH(val.Pubkey[:])
		}
	}

	t := csmt.NewTree(csmt.NewInMemoryTreeDB())
	_ = t.Update(func(tx csmt.TreeTransactionAccess) error {
		for key, pkh := range validatorMsgs {
			if err := tx.Set(key, pkh); err != nil {
				return err
			}
		}
		return nil
	})

	h, _ := t.Hash()

	return h
}
// GetValidatorHash gets the merkle root for all currently registered validators.
GetValidatorHash gets the merkle root for all currently registered validators.
// GetValidatorHash gets the merkle root for all currently registered validators .
func GetValidatorHash(s *primitives.State) chainhash.Hash {
	committeesPerShard := make(map[uint64]primitives.ShardAndCommittee)
	for _, slotAssignment := range s.ShardAndCommitteeForSlots {
		for _, committee := range slotAssignment {
			committeesPerShard[committee.Shard] = committee
		}
	}
	validatorMsgs := make(map[chainhash.Hash][32]byte, 0)
	for shardID, committee := range committeesPerShard {
		for idx, valIdx := range committee.Committee {
			val := s.ValidatorRegistry[valIdx]
			var key [16]byte
			binary.BigEndian.PutUint64(key[:], shardID)
			binary.BigEndian.PutUint64(key[8:], uint64(idx))
			k := chainhash.HashH(key[:])
			validatorMsgs[k] = chainhash.HashH(val.Pubkey[:])
		}
	}
	t := csmt.NewTree(csmt.NewInMemoryTreeDB())
	_ = t.Update(func(tx csmt.TreeTransactionAccess) error {
		for key, pkh := range validatorMsgs {
			if err := tx.Set(key, pkh); err != nil {
				return err
			}
		}
		return nil
	})
	h, _ := t.Hash()
	return h
}
func GetValidatorHash ( s * primitives . State ) chainhash . Hash { committeesPerShard := make ( map [ uint64 ] primitives . ShardAndCommittee ) for _ , slotAssignment := range s . ShardAndCommitteeForSlots { for _ , committee := range slotAssignment { committeesPerShard [ committee . Shard ] = committee } } validatorMsgs := make ( map [ chainhash . Hash ] [ 32 ] byte , 0 ) for shardID , committee := range committeesPerShard { for idx , valIdx := range committee . Committee { val := s . ValidatorRegistry [ valIdx ] var key [ 16 ] byte binary . BigEndian . PutUint64 ( key [ : ] , shardID ) binary . BigEndian . PutUint64 ( key [ 8 : ] , uint64 ( idx ) ) k := chainhash . HashH ( key [ : ] ) validatorMsgs [ k ] = chainhash . HashH ( val . Pubkey [ : ] ) } } t := csmt . NewTree ( csmt . NewInMemoryTreeDB ( ) ) _ = t . Update ( func ( tx csmt . TreeTransactionAccess ) error { for key , pkh := range validatorMsgs { if err := tx . Set ( key , pkh ) ; err != nil { return err } } return nil } ) h , _ := t . Hash ( ) return h }
GetValidatorHash gets the merkle root for all currently registered validators.
GetValidatorHash gets the merkle root for all currently registered validators .