@@ -11,6 +11,7 @@ import (
1111 "sync"
1212 "time"
1313
14+ "github.com/libp2p/go-libp2p/core/peer"
1415 "github.com/mr-tron/base58"
1516 "github.com/pkg/errors"
1617 "go.uber.org/zap"
@@ -62,6 +63,7 @@ type MasterClockConsensusEngine struct {
6263 report * protobufs.SelfTestReport
6364 frameValidationCh chan * protobufs.ClockFrame
6465 bandwidthTestCh chan []byte
66+ verifyTestCh chan verifyChallenge
6567 currentReceivingSyncPeers int
6668 currentReceivingSyncPeersMx sync.Mutex
6769}
@@ -126,6 +128,7 @@ func NewMasterClockConsensusEngine(
126128 report : report ,
127129 frameValidationCh : make (chan * protobufs.ClockFrame ),
128130 bandwidthTestCh : make (chan []byte ),
131+ verifyTestCh : make (chan verifyChallenge ),
129132 }
130133
131134 e .addPeerManifestReport (e .pubSub .GetPeerID (), report )
@@ -186,6 +189,8 @@ func (e *MasterClockConsensusEngine) Start() <-chan error {
186189 e .masterTimeReel .Insert (newFrame , false )
187190 case peerId := <- e .bandwidthTestCh :
188191 e .performBandwidthTest (peerId )
192+ case verifyTest := <- e .verifyTestCh :
193+ e .performVerifyTest (verifyTest )
189194 }
190195 }
191196 }()
@@ -355,6 +360,34 @@ func (e *MasterClockConsensusEngine) Stop(force bool) <-chan error {
355360 return errChan
356361}
357362
363+ type verifyChallenge struct {
364+ peerID []byte
365+ challenge []byte
366+ timestamp int64
367+ difficultyMetric int64
368+ proofs [][]byte
369+ }
370+
371+ func (e * MasterClockConsensusEngine ) performVerifyTest (
372+ challenge verifyChallenge ,
373+ ) {
374+ if ! e .frameProver .VerifyChallengeProof (
375+ challenge .challenge ,
376+ challenge .timestamp ,
377+ challenge .difficultyMetric ,
378+ challenge .proofs ,
379+ ) {
380+ e .logger .Warn (
381+ "received invalid proof from peer" ,
382+ zap .String ("peer_id" , peer .ID (challenge .peerID ).String ()),
383+ )
384+ e .pubSub .SetPeerScore (challenge .peerID , - 1000 )
385+ } else {
386+ info := e .peerInfoManager .GetPeerInfo (challenge .peerID )
387+ info .LastSeen = time .Now ().UnixMilli ()
388+ }
389+ }
390+
358391func (e * MasterClockConsensusEngine ) performBandwidthTest (peerID []byte ) {
359392 result := e .pubSub .GetMultiaddrOfPeer (peerID )
360393 if result == "" {
0 commit comments