Skip to content

Commit

Permalink
Try #4846:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed Aug 18, 2023
2 parents bfa734e + 01a2145 commit ba024d5
Show file tree
Hide file tree
Showing 29 changed files with 1,444 additions and 138 deletions.
8 changes: 8 additions & 0 deletions cmd/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ func EnsureCLIFlags(cmd *cobra.Command, appCFG *config.Config) error {
elem = reflect.ValueOf(&appCFG.Recovery).Elem()
assignFields(ff, elem, name)

ff = reflect.TypeOf(appCFG.Sync)
elem = reflect.ValueOf(&appCFG.Sync).Elem()
assignFields(ff, elem, name)

ff = reflect.TypeOf(appCFG.FETCH)
elem = reflect.ValueOf(&appCFG.FETCH).Elem()
assignFields(ff, elem, name)

ff = reflect.TypeOf(appCFG.TestConfig)
elem = reflect.ValueOf(&appCFG.TestConfig).Elem()
assignFields(ff, elem, name)
Expand Down
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ func AddCommands(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&cfg.TestConfig.SmesherKey, "testing-smesher-key",
"", "import private smesher key for testing",
)
// TODO remove after sync protocol update
cmd.PersistentFlags().BoolVar(&cfg.Sync.UseNewProtocol, "use-new-opn",
cfg.Sync.UseNewProtocol, "use new opinions sync protocol",
)
// TODO remove after sync protocol update
cmd.PersistentFlags().BoolVar(&cfg.FETCH.ServeNewProtocol, "serve-new-opn",
cfg.FETCH.ServeNewProtocol, "serve new opinions sync protocol",
)

// Bind Flags to config
err := viper.BindPFlags(cmd.PersistentFlags())
Expand Down
1 change: 1 addition & 0 deletions config/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func MainnetConfig() Config {
Interval: time.Minute,
EpochEndFraction: 0.8,
MaxStaleDuration: time.Hour,
UseNewProtocol: true,
Standalone: false,
},
Recovery: checkpoint.DefaultConfig(),
Expand Down
14 changes: 13 additions & 1 deletion fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"
"time"

"github.com/libp2p/go-libp2p/core/protocol"
"golang.org/x/sync/errgroup"

"github.com/spacemeshos/go-spacemesh/codec"
Expand All @@ -28,6 +29,8 @@ const (
meshHashProtocol = "mh/1"
malProtocol = "ml/1"

OpnProtocol = "lp/2"

cacheSize = 1000
)

Expand Down Expand Up @@ -82,6 +85,7 @@ type Config struct {
BatchSize, QueueSize int
RequestTimeout time.Duration // in seconds
MaxRetriesForRequest int
ServeNewProtocol bool `mapstructure:"serve-new-opn"`
}

// DefaultConfig is the default config for the fetch component.
Expand All @@ -93,6 +97,7 @@ func DefaultConfig() Config {
BatchSize: 20,
RequestTimeout: time.Second * time.Duration(10),
MaxRetriesForRequest: 100,
ServeNewProtocol: true,
}
}

Expand Down Expand Up @@ -187,13 +192,16 @@ func NewFetch(cdb *datastore.CachedDB, msh meshProvider, b system.BeaconGetter,
server.WithLog(f.logger),
}
if len(f.servers) == 0 {
h := newHandler(cdb, bs, msh, b, f.logger)
h := newHandler(cdb, bs, msh, b, f.cfg.ServeNewProtocol, f.logger)
f.servers[atxProtocol] = server.New(host, atxProtocol, h.handleEpochInfoReq, srvOpts...)
f.servers[lyrDataProtocol] = server.New(host, lyrDataProtocol, h.handleLayerDataReq, srvOpts...)
f.servers[lyrOpnsProtocol] = server.New(host, lyrOpnsProtocol, h.handleLayerOpinionsReq, srvOpts...)
f.servers[hashProtocol] = server.New(host, hashProtocol, h.handleHashReq, srvOpts...)
f.servers[meshHashProtocol] = server.New(host, meshHashProtocol, h.handleMeshHashReq, srvOpts...)
f.servers[malProtocol] = server.New(host, malProtocol, h.handleMaliciousIDsReq, srvOpts...)
if f.cfg.ServeNewProtocol {
f.servers[OpnProtocol] = server.New(host, OpnProtocol, h.handleLayerOpinionsReq2, srvOpts...)
}
}
return f
}
Expand Down Expand Up @@ -644,3 +652,7 @@ func (f *Fetch) RegisterPeerHashes(peer p2p.Peer, hashes []types.Hash32) {
func (f *Fetch) GetPeers() []p2p.Peer {
return f.host.GetPeers()
}

func (f *Fetch) PeerProtocols(p p2p.Peer) ([]protocol.ID, error) {
return f.host.PeerProtocols(p)
}
29 changes: 17 additions & 12 deletions fetch/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type testFetch struct {
mOpnS *mocks.Mockrequester
mHashS *mocks.Mockrequester
mMHashS *mocks.Mockrequester
mOpn2S *mocks.Mockrequester

mMesh *mocks.MockmeshProvider
mMalH *mocks.MockSyncValidator
Expand All @@ -54,6 +55,7 @@ func createFetch(tb testing.TB) *testFetch {
mOpnS: mocks.NewMockrequester(ctrl),
mHashS: mocks.NewMockrequester(ctrl),
mMHashS: mocks.NewMockrequester(ctrl),
mOpn2S: mocks.NewMockrequester(ctrl),
mMalH: mocks.NewMockSyncValidator(ctrl),
mAtxH: mocks.NewMockSyncValidator(ctrl),
mBallotH: mocks.NewMockSyncValidator(ctrl),
Expand All @@ -64,12 +66,13 @@ func createFetch(tb testing.TB) *testFetch {
mPoetH: mocks.NewMockSyncValidator(ctrl),
}
cfg := Config{
time.Millisecond * time.Duration(2000), // make sure we never hit the batch timeout
3,
3,
1000,
time.Second * time.Duration(3),
3,
BatchTimeout: time.Millisecond * time.Duration(2000), // make sure we never hit the batch timeout
MaxRetriesForPeer: 3,
BatchSize: 3,
QueueSize: 1000,
RequestTimeout: time.Second * time.Duration(3),
MaxRetriesForRequest: 3,
ServeNewProtocol: true,
}
lg := logtest.New(tb)
tf.Fetch = NewFetch(datastore.NewCachedDB(sql.InMemory(), lg), tf.mMesh, nil, nil,
Expand All @@ -83,6 +86,7 @@ func createFetch(tb testing.TB) *testFetch {
lyrOpnsProtocol: tf.mOpnS,
hashProtocol: tf.mHashS,
meshHashProtocol: tf.mMHashS,
OpnProtocol: tf.mOpn2S,
}),
withHost(tf.mh))
tf.Fetch.SetValidators(tf.mAtxH, tf.mPoetH, tf.mBallotH, tf.mBlocksH, tf.mProposalH, tf.mTxBlocksH, tf.mTxProposalH, tf.mMalH)
Expand Down Expand Up @@ -315,12 +319,13 @@ func TestFetch_PeerDroppedWhenMessageResultsInValidationReject(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
cfg := Config{
time.Minute * time.Duration(2000), // make sure we never hit the batch timeout
3,
3,
1000,
time.Second * time.Duration(3),
3,
BatchTimeout: time.Minute * time.Duration(2000), // make sure we never hit the batch timeout
MaxRetriesForPeer: 3,
BatchSize: 3,
QueueSize: 1000,
RequestTimeout: time.Second * time.Duration(3),
MaxRetriesForRequest: 3,
ServeNewProtocol: true,
}
p2pconf := p2p.DefaultConfig()
p2pconf.Listen = "/ip4/127.0.0.1/tcp/0"
Expand Down

0 comments on commit ba024d5

Please sign in to comment.