@@ -38,6 +38,8 @@ const (
3838
3939 // headerTopicSuffix is added after namespace to create pubsub topic for block header gossiping.
4040 headerTopicSuffix = "-header"
41+
42+ fraudProofTopicSuffix = "-fraudProof"
4143)
4244
4345// Client is a P2P client, implemented with libp2p.
@@ -60,6 +62,9 @@ type Client struct {
6062 headerGossiper * Gossiper
6163 headerValidator GossipValidator
6264
65+ fraudProofGossiper * Gossiper
66+ fraudProofValidator GossipValidator
67+
6368 // cancel is used to cancel context passed to libp2p functions
6469 // it's required because of discovery.Advertise call
6570 cancel context.CancelFunc
@@ -138,6 +143,7 @@ func (c *Client) Close() error {
138143 return multierr .Combine (
139144 c .txGossiper .Close (),
140145 c .headerGossiper .Close (),
146+ c .fraudProofGossiper .Close (),
141147 c .dht .Close (),
142148 c .host .Close (),
143149 )
@@ -165,6 +171,17 @@ func (c *Client) SetHeaderValidator(validator GossipValidator) {
165171 c .headerValidator = validator
166172}
167173
174+ // GossipHeader sends a fraud proof to the P2P network.
175+ func (c * Client ) GossipFraudProof (ctx context.Context , fraudProof []byte ) error {
176+ c .logger .Debug ("Gossiping fraud proof" , "len" , len (fraudProof ))
177+ return c .fraudProofGossiper .Publish (ctx , fraudProof )
178+ }
179+
180+ // SetFraudProofValidator sets the callback function, that will be invoked after a fraud proof is received from P2P network.
181+ func (c * Client ) SetFraudProofValidator (validator GossipValidator ) {
182+ c .fraudProofValidator = validator
183+ }
184+
168185func (c * Client ) Addrs () []multiaddr.Multiaddr {
169186 return c .host .Addrs ()
170187}
@@ -316,6 +333,13 @@ func (c *Client) setupGossiping(ctx context.Context) error {
316333 }
317334 go c .headerGossiper .ProcessMessages (ctx )
318335
336+ c .fraudProofGossiper , err = NewGossiper (c .host , ps , c .getFraudProofTopic (), c .logger ,
337+ WithValidator (c .fraudProofValidator ))
338+ if err != nil {
339+ return err
340+ }
341+ go c .fraudProofGossiper .ProcessMessages (ctx )
342+
319343 return nil
320344}
321345
@@ -356,3 +380,7 @@ func (c *Client) getTxTopic() string {
356380func (c * Client ) getHeaderTopic () string {
357381 return c .getNamespace () + headerTopicSuffix
358382}
383+
384+ func (c * Client ) getFraudProofTopic () string {
385+ return c .getNamespace () + fraudProofTopicSuffix
386+ }
0 commit comments