Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - drop support for old sync and other legacy code #5021

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ See [RELEASE](./RELEASE.md) for workflow instructions.
A new config `poet-request-timeout` has been added, that defines the timeout for requesting PoET proofs.
It defaults to 9 minutes so there is enough time to retry if the request fails.

Config option and flag `p2p-disable-legacy-discovery` and `disable-dht` have been dropped. DHT has been the
only p2p discovery mechanism since release v1.1.2.

Support for old certificate sync protocol is dropped. This update is incompatible with v1.0.x series.

### Highlights

### Features

### Improvements
* [#5021](https://github.com/spacemeshos/go-spacemesh/pull/5021) Drop support for old certificate sync protocol.

## v1.1.5

Expand Down Expand Up @@ -53,7 +59,7 @@ to set lower expected latency in the network, eventually reducing layer time.

### Improvements

* [#4879](https://github.com/spacemeshos/go-spacemesh/pull/4795) Makes majority calculation weighted for optimistic filtering.
* [#4879](https://github.com/spacemeshos/go-spacemesh/pull/4879) Makes majority calculation weighted for optimistic filtering.
The network will start using the new algorithm at layer 18_000 (2023-09-14 20:00:00 +0000 UTC)
* [#4923](https://github.com/spacemeshos/go-spacemesh/pull/4923) Faster ballot eligibility validation. Improves sync speed.
* [#4934](https://github.com/spacemeshos/go-spacemesh/pull/4934) Ensure state is synced before participating in tortoise consensus.
Expand Down
6 changes: 1 addition & 5 deletions blocks/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,10 @@ func getProposalMetadata(
if err != nil {
return nil, err
}
upgrade := lid.Uint32() >= types.OpUpgradeLayer()
total := 0
for _, p := range proposals {
key := p.MeshHash
cnt := 1
if upgrade {
cnt = len(p.EligibilityProofs)
}
cnt := len(p.EligibilityProofs)
total += cnt
if _, ok := meshHashes[key]; !ok {
meshHashes[key] = &meshState{
Expand Down
9 changes: 2 additions & 7 deletions blocks/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,9 @@ func Test_getProposalMetadata(t *testing.T) {
}
require.NoError(t, layers.SetMeshHash(cdb, lid-1, hash2))

types.SetOpUpgradeLayer(lid.Uint32() + 1)
// only 5 / 10 proposals has the same state, threshold is 70
// only 5 / 10 proposals has the same state
// eligibility wise 40 / 55 has the same state
md, err := getProposalMetadata(context.Background(), lg, cdb, cfg, lid, props)
require.NoError(t, err)
require.False(t, md.optFilter)
// eligibility wise 40 / 55 has the same state, threshold is 70
types.SetOpUpgradeLayer(0)
md, err = getProposalMetadata(context.Background(), lg, cdb, cfg, lid, props)
require.NoError(t, err)
require.True(t, md.optFilter)
}
33 changes: 1 addition & 32 deletions bootstrap/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -420,33 +419,6 @@ func validateData(cfg Config, update *Update) (*VerifiedUpdate, error) {
return verified, nil
}

func renameLegacyFile(fs afero.Fs, path string) string {
var idx int
for _, suffix := range []string{SuffixBoostrap, SuffixBeacon, SuffixActiveSet} {
if strings.HasSuffix(path, suffix) {
return path
}
}
for _, suffix := range []string{SuffixBoostrap, SuffixBeacon, SuffixActiveSet} {
idx = strings.Index(path, fmt.Sprintf("-%s-", suffix))
if idx > -1 {
break
}
}
if idx < 0 {
return ""
}
newPath := path[:idx+suffixLen+1]
if exists, _ := afero.Exists(fs, newPath); exists {
_ = fs.Remove(path)
return ""
}
if err := fs.Rename(path, newPath); err != nil {
return ""
}
return newPath
}

func load(fs afero.Fs, cfg Config, current types.EpochID) ([]*VerifiedUpdate, error) {
dir := bootstrapDir(cfg.DataDir)
_, err := fs.Stat(dir)
Expand All @@ -465,10 +437,7 @@ func load(fs afero.Fs, cfg Config, current types.EpochID) ([]*VerifiedUpdate, er
return nil, fmt.Errorf("read epoch dir %v: %w", dir, err)
}
for _, f := range files {
persisted := renameLegacyFile(fs, filepath.Join(edir, f.Name()))
if persisted == "" {
continue
}
persisted := filepath.Join(edir, f.Name())
data, err := afero.ReadFile(fs, persisted)
if err != nil {
return nil, fmt.Errorf("read bootstrap file %v: %w", persisted, err)
Expand Down
91 changes: 0 additions & 91 deletions bootstrap/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,97 +122,6 @@ func checkUpdate4(t *testing.T, got *bootstrap.VerifiedUpdate) {

type checkFunc func(*testing.T, *bootstrap.VerifiedUpdate)

func TestLoad_BackwardCompatible(t *testing.T) {
epoch := 2
tcs := []struct {
desc string
filenames []string
persisted, suffix string
}{
{
desc: "legacy timestamp bootstrap",
filenames: []string{"epoch-2-update-bs-2023-08-10T06-00-08", "epoch-2-update-bs-2023-08-10T08-00-09"},
persisted: "epoch-2-update-bs",
suffix: bootstrap.SuffixBoostrap,
},
{
desc: "legacy timestamp beacon",
filenames: []string{"epoch-2-update-bc-2023-08-10T06-00-08", "epoch-2-update-bc-2023-08-10T08-00-09"},
persisted: "epoch-2-update-bc",
suffix: bootstrap.SuffixBeacon,
},
{
desc: "legacy timestamp active set",
filenames: []string{"epoch-2-update-as-2023-08-10T06-00-08", "epoch-2-update-as-2023-08-10T08-00-09"},
persisted: "epoch-2-update-as",
suffix: bootstrap.SuffixActiveSet,
},
{
desc: "legacy timestamp huh",
filenames: []string{"epoch-2-update-huh-2023-08-10T06-00-08"},
},
{
desc: "bootstrap",
filenames: []string{"epoch-2-update-bs"},
persisted: "epoch-2-update-bs",
suffix: bootstrap.SuffixBoostrap,
},
{
desc: "beacon",
filenames: []string{"epoch-2-update-bc"},
persisted: "epoch-2-update-bc",
suffix: bootstrap.SuffixBeacon,
},
{
desc: "active set",
filenames: []string{"epoch-2-update-as"},
persisted: "epoch-2-update-as",
suffix: bootstrap.SuffixActiveSet,
},
}
for _, tc := range tcs {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()

cfg := bootstrap.DefaultConfig()
fs := afero.NewMemMapFs()
persistDir := filepath.Join(cfg.DataDir, bootstrap.DirName)
for _, file := range tc.filenames {
path := filepath.Join(persistDir, strconv.Itoa(epoch), file)
require.NoError(t, fs.MkdirAll(path, 0o700))
require.NoError(t, afero.WriteFile(fs, path, []byte(update2), 0o400))
}
mc := bootstrap.NewMocklayerClock(gomock.NewController(t))
mc.EXPECT().CurrentLayer().Return(current.FirstLayer())
updater := bootstrap.New(
mc,
bootstrap.WithConfig(cfg),
bootstrap.WithLogger(logtest.New(t)),
bootstrap.WithFilesystem(fs),
)
require.NoError(t, updater.Load(context.Background()))
if tc.suffix != "" {
require.True(t, updater.Downloaded(types.EpochID(epoch), tc.suffix))
} else {
require.False(t, updater.Downloaded(types.EpochID(epoch), bootstrap.SuffixBoostrap))
require.False(t, updater.Downloaded(types.EpochID(epoch), bootstrap.SuffixActiveSet))
require.False(t, updater.Downloaded(types.EpochID(epoch), bootstrap.SuffixBeacon))
}
if tc.persisted != "" {
edir := filepath.Join(persistDir, strconv.Itoa(epoch))
exists, err := afero.Exists(fs, filepath.Join(edir, tc.persisted))
require.NoError(t, err)
require.True(t, exists)
all, err := afero.ReadDir(fs, edir)
require.NoError(t, err)
require.Len(t, all, 1)
require.Equal(t, tc.persisted, all[0].Name())
}
})
}
}

func TestLoad(t *testing.T) {
tcs := []struct {
desc string
Expand Down
9 changes: 0 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func AddCommands(cmd *cobra.Command) {
cfg.P2P.AdvertiseAddress, "libp2p address with identity (example: /dns4/bootnode.spacemesh.io/tcp/5003)")
cmd.PersistentFlags().BoolVar(&cfg.P2P.Bootnode, "p2p-bootnode", cfg.P2P.Bootnode,
"gossipsub and discovery will be running in a mode suitable for bootnode")
cmd.PersistentFlags().BoolVar(&cfg.P2P.DisableLegacyDiscovery, "p2p-disable-legacy-discovery", cfg.P2P.DisableLegacyDiscovery, "custom legacy discovery is disabled")
cmd.PersistentFlags().BoolVar(&cfg.P2P.PrivateNetwork, "p2p-private-network", cfg.P2P.PrivateNetwork, "discovery will work in private mode. mostly useful for testing, don't set in public networks")
/** ======================== TIME Flags ========================== **/

Expand Down Expand Up @@ -270,14 +269,6 @@ 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
11 changes: 0 additions & 11 deletions common/types/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ var (

// EmptyLayerHash is the layer hash for an empty layer.
EmptyLayerHash = Hash32{}

// layer at which optimistic filtering majority calculation is upgraded.
opUpgradeLayer uint32
)

// SetLayersPerEpoch sets global parameter of layers per epoch, all conversions from layer to epoch use this param.
Expand All @@ -30,14 +27,6 @@ func SetLayersPerEpoch(layers uint32) {
SetEffectiveGenesis(layers*2 - 1)
}

func SetOpUpgradeLayer(layer uint32) {
opUpgradeLayer = layer
}

func OpUpgradeLayer() uint32 {
return opUpgradeLayer
}

func SetEffectiveGenesis(layer uint32) {
atomic.StoreUint32(&effectiveGenesis, layer)
}
Expand Down
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ type BaseConfig struct {
ProfilerURL string `mapstructure:"profiler-url"`

LayerDuration time.Duration `mapstructure:"layer-duration"`
LegacyLayer uint32 `mapstructure:"legacy-layer"`
LayerAvgSize uint32 `mapstructure:"layer-average-size"`
LayersPerEpoch uint32 `mapstructure:"layers-per-epoch"`

Expand Down
8 changes: 2 additions & 6 deletions config/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ func MainnetConfig() Config {
DatabaseConnections: 16,
NetworkHRP: "sm",

LayerDuration: 5 * time.Minute,
LayerAvgSize: 50,
// NOTE(dshulyak) this is only used to stop atx grading in hare.
// we should refactor that too.
LegacyLayer: 8180,
LayerDuration: 5 * time.Minute,
LayerAvgSize: 50,
LayersPerEpoch: 4032,

TxsPerProposal: 700, // https://github.com/spacemeshos/go-spacemesh/issues/4559
Expand Down Expand Up @@ -139,7 +136,6 @@ func MainnetConfig() Config {
Interval: time.Minute,
EpochEndFraction: 0.8,
MaxStaleDuration: time.Hour,
UseNewProtocol: true,
Standalone: false,
GossipDuration: 50 * time.Second,
},
Expand Down
1 change: 0 additions & 1 deletion config/presets/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func testnet() config.Config {
Interval: time.Minute,
EpochEndFraction: 0.8,
MaxStaleDuration: time.Hour,
UseNewProtocol: true,
GossipDuration: 50 * time.Second,
},
Recovery: checkpoint.DefaultConfig(),
Expand Down
13 changes: 3 additions & 10 deletions fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ import (
const (
atxProtocol = "ax/1"
lyrDataProtocol = "ld/1"
lyrOpnsProtocol = "lp/1"
hashProtocol = "hs/1"
meshHashProtocol = "mh/1"
malProtocol = "ml/1"

OpnProtocol = "lp/2"
OpnProtocol = "lp/2"

cacheSize = 1000
)
Expand Down Expand Up @@ -85,7 +83,6 @@ 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 @@ -97,7 +94,6 @@ func DefaultConfig() Config {
BatchSize: 20,
RequestTimeout: time.Second * time.Duration(10),
MaxRetriesForRequest: 100,
ServeNewProtocol: true,
}
}

Expand Down Expand Up @@ -192,16 +188,13 @@ 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.cfg.ServeNewProtocol, f.logger)
h := newHandler(cdb, bs, msh, b, 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...)
}
f.servers[OpnProtocol] = server.New(host, OpnProtocol, h.handleLayerOpinionsReq2, srvOpts...)
}
return f
}
Expand Down
5 changes: 0 additions & 5 deletions fetch/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type testFetch struct {
mMalS *mocks.Mockrequester
mAtxS *mocks.Mockrequester
mLyrS *mocks.Mockrequester
mOpnS *mocks.Mockrequester
mHashS *mocks.Mockrequester
mMHashS *mocks.Mockrequester
mOpn2S *mocks.Mockrequester
Expand All @@ -53,7 +52,6 @@ func createFetch(tb testing.TB) *testFetch {
mMalS: mocks.NewMockrequester(ctrl),
mAtxS: mocks.NewMockrequester(ctrl),
mLyrS: mocks.NewMockrequester(ctrl),
mOpnS: mocks.NewMockrequester(ctrl),
mHashS: mocks.NewMockrequester(ctrl),
mMHashS: mocks.NewMockrequester(ctrl),
mOpn2S: mocks.NewMockrequester(ctrl),
Expand All @@ -74,7 +72,6 @@ func createFetch(tb testing.TB) *testFetch {
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 @@ -85,7 +82,6 @@ func createFetch(tb testing.TB) *testFetch {
malProtocol: tf.mMalS,
atxProtocol: tf.mAtxS,
lyrDataProtocol: tf.mLyrS,
lyrOpnsProtocol: tf.mOpnS,
hashProtocol: tf.mHashS,
meshHashProtocol: tf.mMHashS,
OpnProtocol: tf.mOpn2S,
Expand Down Expand Up @@ -365,7 +361,6 @@ func TestFetch_PeerDroppedWhenMessageResultsInValidationReject(t *testing.T) {
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