diff --git a/cl/rpc/rpc.go b/cl/rpc/rpc.go index da61b993965..7d72c3d95ac 100644 --- a/cl/rpc/rpc.go +++ b/cl/rpc/rpc.go @@ -272,3 +272,15 @@ func (b *BeaconRpcP2P) SetStatus(finalizedRoot libcommon.Hash, finalizedEpoch ui }) return err } + +func (b *BeaconRpcP2P) PropagateBlock(block *cltypes.SignedBeaconBlock) error { + encoded, err := block.EncodeSSZ(nil) + if err != nil { + return err + } + _, err = b.sentinel.PublishGossip(b.ctx, &sentinel.GossipData{ + Data: encoded, + Type: sentinel.GossipType_BeaconBlockGossipType, + }) + return err +} diff --git a/cmd/sentinel/sentinel/gossip.go b/cmd/sentinel/sentinel/gossip.go index 01e7a08e0fd..ba0502e72a5 100644 --- a/cmd/sentinel/sentinel/gossip.go +++ b/cmd/sentinel/sentinel/gossip.go @@ -19,7 +19,6 @@ import ( "fmt" "sync" - "github.com/ledgerwatch/erigon/common" "github.com/ledgerwatch/log/v3" pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/libp2p/go-libp2p/core/peer" @@ -102,9 +101,10 @@ func (s *GossipSubscription) do(ctx context.Context, sub *pubsub.Subscription, t if msg.GetFrom() == s.host { return } - if err := s.topic.Publish(ctx, common.CopyBytes(msg.Data)); err != nil { - return - } s.ch <- msg } } + +func (g *GossipSubscription) Publish(data []byte) error { + return g.topic.Publish(g.ctx, data) +} diff --git a/cmd/sentinel/sentinel/sentinel.go b/cmd/sentinel/sentinel/sentinel.go index 1b9914ea9bd..9e58625f409 100644 --- a/cmd/sentinel/sentinel/sentinel.go +++ b/cmd/sentinel/sentinel/sentinel.go @@ -270,3 +270,7 @@ func (s *Sentinel) Host() host.Host { func (s *Sentinel) Peers() *peers.Peers { return s.peers } + +func (s *Sentinel) GossipManager() *GossipManager { + return s.subManager +} diff --git a/cmd/sentinel/sentinel/service/service.go b/cmd/sentinel/sentinel/service/service.go index 29dbea812db..e6e005c743b 100644 --- a/cmd/sentinel/sentinel/service/service.go +++ b/cmd/sentinel/sentinel/service/service.go @@ -44,6 +44,32 @@ func (s *SentinelServer) BanPeer(_ context.Context, p *sentinelrpc.Peer) (*senti return &sentinelrpc.EmptyMessage{}, nil } +func (s *SentinelServer) PublishGossip(_ context.Context, msg *sentinelrpc.GossipData) (*sentinelrpc.EmptyMessage, error) { + manager := s.sentinel.GossipManager() + // Snappify payload before sending it to gossip + compressedData := utils.CompressSnappy(msg.Data) + var subscription *sentinel.GossipSubscription + + switch msg.Type { + case sentinelrpc.GossipType_BeaconBlockGossipType: + subscription = manager.GetMatchingSubscription(string(sentinel.BeaconBlockTopic)) + case sentinelrpc.GossipType_AggregateAndProofGossipType: + subscription = manager.GetMatchingSubscription(string(sentinel.BeaconAggregateAndProofTopic)) + case sentinelrpc.GossipType_VoluntaryExitGossipType: + subscription = manager.GetMatchingSubscription(string(sentinel.VoluntaryExitTopic)) + case sentinelrpc.GossipType_ProposerSlashingGossipType: + subscription = manager.GetMatchingSubscription(string(sentinel.ProposerSlashingTopic)) + case sentinelrpc.GossipType_AttesterSlashingGossipType: + subscription = manager.GetMatchingSubscription(string(sentinel.AttesterSlashingTopic)) + default: + return &sentinelrpc.EmptyMessage{}, nil + } + if subscription == nil { + return &sentinelrpc.EmptyMessage{}, nil + } + return &sentinelrpc.EmptyMessage{}, subscription.Publish(compressedData) +} + func (s *SentinelServer) SubscribeGossip(_ *sentinelrpc.EmptyMessage, stream sentinelrpc.Sentinel_SubscribeGossipServer) error { // first of all subscribe ch, subId, err := s.gossipNotifier.addSubscriber() diff --git a/go.mod b/go.mod index 99b7752b575..2db845b769f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon go 1.19 require ( - github.com/ledgerwatch/erigon-lib v0.0.0-20230325072849-9f1fc3dd0d0c + github.com/ledgerwatch/erigon-lib v0.0.0-20230327103053-23fe5e817bfa github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 github.com/ledgerwatch/log/v3 v3.7.0 github.com/ledgerwatch/secp256k1 v1.0.0 diff --git a/go.sum b/go.sum index 1f98220efcb..1589b5090bd 100644 --- a/go.sum +++ b/go.sum @@ -519,8 +519,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= -github.com/ledgerwatch/erigon-lib v0.0.0-20230325072849-9f1fc3dd0d0c h1:Ba+HaeqlyMLlN/HzDsYw8IXyzkN+IJabAiP2jV3OvVE= -github.com/ledgerwatch/erigon-lib v0.0.0-20230325072849-9f1fc3dd0d0c/go.mod h1:CkP5qnLv68u1AAHHamS7TBgPmlPBn0aVcPrHi7njrIU= +github.com/ledgerwatch/erigon-lib v0.0.0-20230327103053-23fe5e817bfa h1:2d7REYLaoY5tqhdP4qH6P7QNl7SbNO7JjTEUMq5x7s4= +github.com/ledgerwatch/erigon-lib v0.0.0-20230327103053-23fe5e817bfa/go.mod h1:JCt4IGL5ZAS1XGTFgSs2RSOxiTw3XX5PrkKjwhiI8Mo= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3 h1:tfzawK1gIIgRjVZeANXOr0Ziu+kqCIBuKMe0TXfl5Aw= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230306083105-1391330d62a3/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=