prysm-pulse/beacon-chain/sync/decode_pubsub.go
Preston Van Loon 961dd21554 Use libp2p gossipsub upstream validator framework (#4318)
* add reject all pubsub validator to stop automatic propagation of messages
* gaz
* Merge branch 'master' of github.com:prysmaticlabs/prysm into pubsub-validator
* refactor p2p validator pipeline
* add sanity check
* Merge branch 'pubsub-validator' of github.com:prysmaticlabs/prysm into pubsub-validator
* fixed up test
* rem
* gaz
* Merge refs/heads/master into pubsub-validator
* fix from self test
* ensure validator data is set
* resolve todo
* Merge refs/heads/master into pubsub-validator
* gaz
* Merge refs/heads/master into pubsub-validator
* Merge branch 'pubsub-validator' of github.com:prysmaticlabs/prysm into pubsub-validator
* Merge refs/heads/master into pubsub-validator
* remove all of the 'from self' logic. filed https://github.com/libp2p/go-libp2p-pubsub/issues/250
* Merge branch 'pubsub-validator' of github.com:prysmaticlabs/prysm into pubsub-validator
* gaz
* update comment
* Merge refs/heads/master into pubsub-validator
* rename "VaidatorData"
* Merge branch 'pubsub-validator' of github.com:prysmaticlabs/prysm into pubsub-validator
* refactor
* one more bit of refactoring
* Update beacon-chain/sync/validate_beacon_attestation.go

Co-Authored-By: terence tsao <terence@prysmaticlabs.com>
* skip validation on self messages, add @nisdas feedback to increment failure counter
* Merge branch 'pubsub-validator' of github.com:prysmaticlabs/prysm into pubsub-validator
* remove flakey
2019-12-20 03:18:08 +00:00

29 lines
728 B
Go

package sync
import (
"errors"
"fmt"
"strings"
"github.com/gogo/protobuf/proto"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
)
func (r *Service) decodePubsubMessage(msg *pubsub.Message) (proto.Message, error) {
if msg == nil || msg.TopicIDs == nil || len(msg.TopicIDs) == 0 {
return nil, errors.New("nil pubsub message")
}
topic := msg.TopicIDs[0]
topic = strings.TrimSuffix(topic, r.p2p.Encoding().ProtocolSuffix())
base, ok := p2p.GossipTopicMappings[topic]
if !ok {
return nil, fmt.Errorf("no message mapped for topic %s", topic)
}
m := proto.Clone(base)
if err := r.p2p.Encoding().Decode(msg.Data, m); err != nil {
return nil, err
}
return m, nil
}