general fixes

This commit is contained in:
Cassandra Heart 2023-09-10 18:29:17 -05:00
parent 19bd01e184
commit 5073df60fc
No known key found for this signature in database
GPG Key ID: 6352152859385958
4 changed files with 45 additions and 0 deletions

View File

@ -170,6 +170,17 @@ func (e *MasterClockConsensusEngine) Start() <-chan error {
e.state = consensus.EngineStateCollecting e.state = consensus.EngineStateCollecting
go func() {
for {
e.logger.Info(
"peers in store",
zap.Int("peer_store_count", e.pubSub.GetPeerstoreCount()),
zap.Int("network_peer_count", e.pubSub.GetNetworkPeersCount()),
)
time.Sleep(10 * time.Second)
}
}()
go func() { go func() {
for e.state < consensus.EngineStateStopping { for e.state < consensus.EngineStateStopping {
var err error var err error

View File

@ -28,6 +28,7 @@ type BlossomSub struct {
logger *zap.Logger logger *zap.Logger
peerID peer.ID peerID peer.ID
bitmaskMap map[string]*blossomsub.Bitmask bitmaskMap map[string]*blossomsub.Bitmask
h host.Host
} }
var _ PubSub = (*BlossomSub)(nil) var _ PubSub = (*BlossomSub)(nil)
@ -107,6 +108,7 @@ func NewBlossomSub(
logger, logger,
peerID, peerID,
make(map[string]*blossomsub.Bitmask), make(map[string]*blossomsub.Bitmask),
h,
} }
} }
@ -258,6 +260,14 @@ func initDHT(
return kademliaDHT return kademliaDHT
} }
func (b *BlossomSub) GetPeerstoreCount() int {
return len(b.h.Peerstore().Peers())
}
func (b *BlossomSub) GetNetworkPeersCount() int {
return len(b.h.Network().Peers())
}
func discoverPeers( func discoverPeers(
p2pConfig *config.P2PConfig, p2pConfig *config.P2PConfig,
ctx context.Context, ctx context.Context,
@ -276,6 +286,7 @@ func discoverPeers(
if err != nil { if err != nil {
panic(err) panic(err)
} }
for peer := range peerChan { for peer := range peerChan {
if peer.ID == h.ID() { if peer.ID == h.ID() {
continue continue

View File

@ -10,5 +10,7 @@ type PubSub interface {
Subscribe(bitmask []byte, handler func(message *pb.Message) error, raw bool) Subscribe(bitmask []byte, handler func(message *pb.Message) error, raw bool)
Unsubscribe(bitmask []byte, raw bool) Unsubscribe(bitmask []byte, raw bool)
GetPeerID() []byte GetPeerID() []byte
GetPeerstoreCount() int
GetNetworkPeersCount() int
GetRandomPeer(bitmask []byte) ([]byte, error) GetRandomPeer(bitmask []byte) ([]byte, error)
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/binary" "encoding/binary"
"github.com/cockroachdb/pebble" "github.com/cockroachdb/pebble"
"github.com/iden3/go-iden3-crypto/poseidon"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -131,6 +132,16 @@ func (p *PebbleMasterClockIterator) Value() (*protobufs.ClockFrame, error) {
frame.Input = value[4 : len(value)-516] frame.Input = value[4 : len(value)-516]
frame.Output = value[len(value)-516:] frame.Output = value[len(value)-516:]
previousSelectorBytes := [516]byte{}
copy(previousSelectorBytes[:], frame.Input[:516])
parent, err := poseidon.HashBytes(previousSelectorBytes[:])
if err != nil {
return nil, errors.Wrap(err, "get master clock frame iterator value")
}
frame.ParentSelector = parent.Bytes()
return frame, nil return frame, nil
} }
@ -415,6 +426,16 @@ func (p *PebbleClockStore) GetMasterClockFrame(
frame.Input = value[4 : len(value)-516] frame.Input = value[4 : len(value)-516]
frame.Output = value[len(value)-516:] frame.Output = value[len(value)-516:]
previousSelectorBytes := [516]byte{}
copy(previousSelectorBytes[:], frame.Input[:516])
parent, err := poseidon.HashBytes(previousSelectorBytes[:])
if err != nil {
return nil, errors.Wrap(err, "get master clock frame")
}
frame.ParentSelector = parent.Bytes()
return frame, nil return frame, nil
} }