mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-12-26 00:25:17 +00:00
parent
6c567a04c1
commit
1a244f5154
@ -214,7 +214,7 @@ func NewBlossomSubWithRouter(ctx context.Context, h host.Host, rt PubSubRouter,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewBlossomSubRouter returns a new BlossomSubRouter with custom parameters.
|
// NewBlossomSubRouter returns a new BlossomSubRouter with custom parameters.
|
||||||
func NewBlossomSubRouter(h host.Host, params BlossomSubParams) *BlossomSubRouter {
|
func NewBlossomSubRouter(h host.Host, params BlossomSubParams, addrBook peerstore.AddrBook) *BlossomSubRouter {
|
||||||
return &BlossomSubRouter{
|
return &BlossomSubRouter{
|
||||||
peers: make(map[peer.ID]protocol.ID),
|
peers: make(map[peer.ID]protocol.ID),
|
||||||
mesh: make(map[string]map[peer.ID]struct{}),
|
mesh: make(map[string]map[peer.ID]struct{}),
|
||||||
@ -222,7 +222,7 @@ func NewBlossomSubRouter(h host.Host, params BlossomSubParams) *BlossomSubRouter
|
|||||||
lastpub: make(map[string]int64),
|
lastpub: make(map[string]int64),
|
||||||
gossip: make(map[peer.ID][]*pb.ControlIHave),
|
gossip: make(map[peer.ID][]*pb.ControlIHave),
|
||||||
control: make(map[peer.ID]*pb.ControlMessage),
|
control: make(map[peer.ID]*pb.ControlMessage),
|
||||||
cab: pstoremem.NewAddrBook(),
|
cab: addrBook,
|
||||||
backoff: make(map[string]map[peer.ID]time.Time),
|
backoff: make(map[string]map[peer.ID]time.Time),
|
||||||
peerhave: make(map[peer.ID]int),
|
peerhave: make(map[peer.ID]int),
|
||||||
iasked: make(map[peer.ID]int),
|
iasked: make(map[peer.ID]int),
|
||||||
|
@ -36,5 +36,5 @@ func FormatVersion(version []byte) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetPatchNumber() byte {
|
func GetPatchNumber() byte {
|
||||||
return 0x00
|
return 0x01
|
||||||
}
|
}
|
||||||
|
@ -92,16 +92,17 @@ func (e *MasterClockConsensusEngine) handleSelfTestReport(
|
|||||||
info.DifficultyMetric = report.DifficultyMetric
|
info.DifficultyMetric = report.DifficultyMetric
|
||||||
info.MasterHeadFrame = report.MasterHeadFrame
|
info.MasterHeadFrame = report.MasterHeadFrame
|
||||||
|
|
||||||
if info.Bandwidth <= 1048576 {
|
if info.Bandwidth == 0 {
|
||||||
go func() {
|
go func() {
|
||||||
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Minute)
|
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Minute)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ch := e.pubSub.GetMultiaddrOfPeerStream(ctx, peerID)
|
ch := e.pubSub.GetMultiaddrOfPeerStream(ctx, peerID)
|
||||||
select {
|
select {
|
||||||
case <-ch:
|
case <-ch:
|
||||||
go func() {
|
select {
|
||||||
e.bandwidthTestCh <- peerID
|
case e.bandwidthTestCh <- peerID:
|
||||||
}()
|
default:
|
||||||
|
}
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -116,15 +117,16 @@ func (e *MasterClockConsensusEngine) handleSelfTestReport(
|
|||||||
for i := 0; i < len(proofs); i++ {
|
for i := 0; i < len(proofs); i++ {
|
||||||
proofs[i] = proof[i*516 : (i+1)*516]
|
proofs[i] = proof[i*516 : (i+1)*516]
|
||||||
}
|
}
|
||||||
go func() {
|
select {
|
||||||
e.verifyTestCh <- verifyChallenge{
|
case e.verifyTestCh <- verifyChallenge{
|
||||||
peerID: peerID,
|
peerID: peerID,
|
||||||
challenge: challenge,
|
challenge: challenge,
|
||||||
cores: report.Cores,
|
cores: report.Cores,
|
||||||
increment: report.Increment,
|
increment: report.Increment,
|
||||||
proof: proof,
|
proof: proof,
|
||||||
}
|
}:
|
||||||
}()
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ func NewMasterClockConsensusEngine(
|
|||||||
report: report,
|
report: report,
|
||||||
frameValidationCh: make(chan *protobufs.ClockFrame),
|
frameValidationCh: make(chan *protobufs.ClockFrame),
|
||||||
bandwidthTestCh: make(chan []byte),
|
bandwidthTestCh: make(chan []byte),
|
||||||
verifyTestCh: make(chan verifyChallenge),
|
verifyTestCh: make(chan verifyChallenge, 4),
|
||||||
engineConfig: engineConfig,
|
engineConfig: engineConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,29 +192,14 @@ func (e *MasterClockConsensusEngine) Start() <-chan error {
|
|||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case newFrame := <-e.frameValidationCh:
|
|
||||||
head, err := e.masterTimeReel.Head()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if head.FrameNumber > newFrame.FrameNumber ||
|
|
||||||
newFrame.FrameNumber-head.FrameNumber > 128 {
|
|
||||||
e.logger.Debug(
|
|
||||||
"frame out of range, ignoring",
|
|
||||||
zap.Uint64("number", newFrame.FrameNumber),
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := e.frameProver.VerifyMasterClockFrame(newFrame); err != nil {
|
|
||||||
e.logger.Error("could not verify clock frame", zap.Error(err))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
e.masterTimeReel.Insert(newFrame, false)
|
|
||||||
case peerId := <-e.bandwidthTestCh:
|
case peerId := <-e.bandwidthTestCh:
|
||||||
e.performBandwidthTest(peerId)
|
e.performBandwidthTest(peerId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
case verifyTest := <-e.verifyTestCh:
|
case verifyTest := <-e.verifyTestCh:
|
||||||
e.performVerifyTest(verifyTest)
|
e.performVerifyTest(verifyTest)
|
||||||
}
|
}
|
||||||
@ -398,13 +383,14 @@ func (e *MasterClockConsensusEngine) Start() <-chan error {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
e.logger.Info(
|
if increment%30 == 0 {
|
||||||
"broadcasting self-test info",
|
e.logger.Info(
|
||||||
zap.Uint64("current_frame", e.report.MasterHeadFrame),
|
"broadcasting self-test info",
|
||||||
)
|
zap.Uint64("current_frame", e.report.MasterHeadFrame),
|
||||||
|
)
|
||||||
if err := e.publishMessage(e.filter, e.report); err != nil {
|
if err := e.publishMessage(e.filter, e.report); err != nil {
|
||||||
e.logger.Debug("error publishing message", zap.Error(err))
|
e.logger.Debug("error publishing message", zap.Error(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
skipStore = false
|
skipStore = false
|
||||||
|
@ -227,7 +227,7 @@ func main() {
|
|||||||
fmt.Println("Signature check disabled, skipping...")
|
fmt.Println("Signature check disabled, skipping...")
|
||||||
}
|
}
|
||||||
|
|
||||||
if *memprofile != "" {
|
if *memprofile != "" && *core == 0 {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(5 * time.Minute)
|
time.Sleep(5 * time.Minute)
|
||||||
@ -241,7 +241,7 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
if *cpuprofile != "" {
|
if *cpuprofile != "" && *core == 0 {
|
||||||
f, err := os.Create(*cpuprofile)
|
f, err := os.Create(*cpuprofile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -438,6 +438,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
repair(*configDirectory, node)
|
repair(*configDirectory, node)
|
||||||
|
runtime.GOMAXPROCS(1)
|
||||||
|
|
||||||
if nodeConfig.ListenGRPCMultiaddr != "" {
|
if nodeConfig.ListenGRPCMultiaddr != "" {
|
||||||
srv, err := rpc.NewRPCServer(
|
srv, err := rpc.NewRPCServer(
|
||||||
|
@ -85,6 +85,16 @@ func getPeerID(p2pConfig *config.P2PConfig) peer.ID {
|
|||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type realclock struct{}
|
||||||
|
|
||||||
|
func (rc realclock) Now() time.Time {
|
||||||
|
return time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc realclock) After(d time.Duration) <-chan time.Time {
|
||||||
|
return time.After(d)
|
||||||
|
}
|
||||||
|
|
||||||
func NewBlossomSub(
|
func NewBlossomSub(
|
||||||
p2pConfig *config.P2PConfig,
|
p2pConfig *config.P2PConfig,
|
||||||
peerstore store.Peerstore,
|
peerstore store.Peerstore,
|
||||||
@ -126,7 +136,14 @@ func NewBlossomSub(
|
|||||||
opts = append(opts, libp2p.Identity(privKey))
|
opts = append(opts, libp2p.Identity(privKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
ps, err := pstoreds.NewPeerstore(ctx, peerstore, pstoreds.DefaultOpts())
|
ps, err := pstoreds.NewPeerstore(ctx, peerstore, pstoreds.Options{
|
||||||
|
CacheSize: 120000,
|
||||||
|
MaxProtocols: 1024,
|
||||||
|
GCPurgeInterval: 2 * time.Hour,
|
||||||
|
GCLookaheadInterval: 0,
|
||||||
|
GCInitialDelay: 60 * time.Second,
|
||||||
|
Clock: realclock{},
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -208,7 +225,7 @@ func NewBlossomSub(
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
params := mergeDefaults(p2pConfig)
|
params := mergeDefaults(p2pConfig)
|
||||||
rt := blossomsub.NewBlossomSubRouter(h, params)
|
rt := blossomsub.NewBlossomSubRouter(h, params, ps)
|
||||||
pubsub, err := blossomsub.NewBlossomSubWithRouter(ctx, h, rt, blossomOpts...)
|
pubsub, err := blossomsub.NewBlossomSubWithRouter(ctx, h, rt, blossomOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user