mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Add Flag for SSZ Encoding (#3256)
* add flag and enum * change help message * linter * add flag * add comment * one more comment * fix panic * preston's comments * add panic
This commit is contained in:
committed by
Preston Van Loon
parent
acb20e269c
commit
79e57e8e8e
@@ -39,6 +39,7 @@ var appFlags = []cli.Flag{
|
||||
cmd.P2PMaxPeers,
|
||||
cmd.P2PPrivKey,
|
||||
cmd.P2PWhitelist,
|
||||
cmd.P2PEncoding,
|
||||
cmd.DataDirFlag,
|
||||
cmd.VerbosityFlag,
|
||||
cmd.EnableTracingFlag,
|
||||
|
||||
@@ -215,6 +215,7 @@ func (b *BeaconNode) registerP2P(ctx *cli.Context) error {
|
||||
MaxPeers: ctx.GlobalUint(cmd.P2PMaxPeers.Name),
|
||||
WhitelistCIDR: ctx.GlobalString(cmd.P2PWhitelist.Name),
|
||||
EnableUPnP: ctx.GlobalBool(cmd.EnableUPnPFlag.Name),
|
||||
Encoding: ctx.GlobalString(cmd.P2PEncoding.Name),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -25,6 +25,9 @@ func TestService_Broadcast(t *testing.T) {
|
||||
p := &Service{
|
||||
host: p1.Host,
|
||||
pubsub: p1.PubSub(),
|
||||
cfg: &Config{
|
||||
Encoding: "ssz",
|
||||
},
|
||||
}
|
||||
|
||||
msg := &testpb.TestSimpleMessage{
|
||||
|
||||
@@ -14,4 +14,5 @@ type Config struct {
|
||||
MaxPeers uint
|
||||
WhitelistCIDR string
|
||||
EnableUPnP bool
|
||||
Encoding string
|
||||
}
|
||||
|
||||
@@ -6,6 +6,12 @@ import (
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
// Defines the different encoding formats
|
||||
const (
|
||||
SSZ = "ssz" // SSZ is SSZ only.
|
||||
SSZSnappy = "ssz-snappy" // SSZSnappy is SSZ with snappy compression.
|
||||
)
|
||||
|
||||
// NetworkEncoding represents an encoder compatible with Ethereum 2.0 p2p.
|
||||
type NetworkEncoding interface {
|
||||
// Decode reads bytes from the reader and decodes it to the provided message.
|
||||
|
||||
@@ -105,8 +105,15 @@ func (s *Service) Status() error {
|
||||
|
||||
// Encoding returns the configured networking encoding.
|
||||
func (s *Service) Encoding() encoder.NetworkEncoding {
|
||||
// TODO(3147): Return based on flag value
|
||||
return &encoder.SszNetworkEncoder{}
|
||||
encoding := s.cfg.Encoding
|
||||
switch encoding {
|
||||
case encoder.SSZ:
|
||||
return &encoder.SszNetworkEncoder{}
|
||||
case encoder.SSZSnappy:
|
||||
return &encoder.SszNetworkEncoder{UseSnappyCompression: true}
|
||||
default:
|
||||
panic("Invalid Network Encoding Flag Provided")
|
||||
}
|
||||
}
|
||||
|
||||
// PubSub returns the p2p pubsub framework.
|
||||
|
||||
@@ -94,6 +94,7 @@ var appHelpFlagGroups = []flagGroup{
|
||||
cmd.P2PWhitelist,
|
||||
cmd.StaticPeers,
|
||||
cmd.EnableUPnPFlag,
|
||||
cmd.P2PEncoding,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -107,6 +107,12 @@ var (
|
||||
"would whitelist connections to peers on your local network only. The default " +
|
||||
"is to accept all connections.",
|
||||
}
|
||||
// P2PEncoding defines the encoding format for p2p messages.
|
||||
P2PEncoding = cli.StringFlag{
|
||||
Name: "p2p-encoding",
|
||||
Usage: "The encoding format of messages sent over the wire. The default is 0, which represents ssz",
|
||||
Value: "ssz",
|
||||
}
|
||||
// ClearDB tells the beacon node to remove any previously stored data at the data directory.
|
||||
ClearDB = cli.BoolFlag{
|
||||
Name: "clear-db",
|
||||
|
||||
Reference in New Issue
Block a user