mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
28733f2c9e
* clean up config * add discv5 config * add gaz * Merge branch 'master' into configCleanup * Merge refs/heads/master into configCleanup * Merge refs/heads/master into configCleanup * Merge refs/heads/master into configCleanup * Merge refs/heads/master into configCleanup * Merge refs/heads/master into configCleanup * Merge refs/heads/master into configCleanup
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package p2p
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
var attestationSubnetCount = params.BeaconNetworkConfig().AttestationSubnetCount
|
|
|
|
var attSubnetEnrKey = params.BeaconNetworkConfig().AttSubnetKey
|
|
|
|
func intializeAttSubnets(node *enode.LocalNode) *enode.LocalNode {
|
|
bitV := bitfield.NewBitvector64()
|
|
entry := enr.WithEntry(attSubnetEnrKey, bitV.Bytes())
|
|
node.Set(entry)
|
|
return node
|
|
}
|
|
|
|
func retrieveAttSubnets(record *enr.Record) ([]uint64, error) {
|
|
bitV, err := retrieveBitvector(record)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
committeeIdxs := []uint64{}
|
|
for i := uint64(0); i < attestationSubnetCount; i++ {
|
|
if bitV.BitAt(i) {
|
|
committeeIdxs = append(committeeIdxs, i)
|
|
}
|
|
}
|
|
return committeeIdxs, nil
|
|
}
|
|
|
|
func retrieveBitvector(record *enr.Record) (bitfield.Bitvector64, error) {
|
|
bitV := bitfield.NewBitvector64()
|
|
entry := enr.WithEntry(attSubnetEnrKey, &bitV)
|
|
err := record.Load(entry)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return bitV, nil
|
|
}
|