diff --git a/api/service/stagedstreamsync/downloader.go b/api/service/stagedstreamsync/downloader.go index 9fdd2f78f..383447f98 100644 --- a/api/service/stagedstreamsync/downloader.go +++ b/api/service/stagedstreamsync/downloader.go @@ -32,7 +32,7 @@ type ( downloadC chan struct{} closeC chan struct{} ctx context.Context - cancel func() + cancel context.CancelFunc config Config logger zerolog.Logger @@ -70,6 +70,7 @@ func NewDownloader(host p2p.Host, bc core.BlockChain, config Config) *Downloader //TODO: use mem db should be in config file stagedSyncInstance, err := CreateStagedSync(ctx, bc, false, sp, config, logger, config.LogProgress) if err != nil { + cancel() return nil } diff --git a/api/service/stagedstreamsync/staged_stream_sync.go b/api/service/stagedstreamsync/staged_stream_sync.go index 1abd72849..11ad9e8ae 100644 --- a/api/service/stagedstreamsync/staged_stream_sync.go +++ b/api/service/stagedstreamsync/staged_stream_sync.go @@ -65,8 +65,8 @@ type StagedStreamSync struct { inserted int config Config logger zerolog.Logger - status status //TODO: merge this with currentSyncCycle - initSync bool // if sets to true, node start long range syncing + status *status //TODO: merge this with currentSyncCycle + initSync bool // if sets to true, node start long range syncing UseMemDB bool revertPoint *uint64 // used to run stages @@ -294,7 +294,7 @@ func New(ctx context.Context, db: db, protocol: protocol, gbm: nil, - status: status, + status: &status, inserted: 0, config: config, logger: logger, diff --git a/p2p/stream/common/streammanager/interface_test.go b/p2p/stream/common/streammanager/interface_test.go index e308c3aba..033273fd6 100644 --- a/p2p/stream/common/streammanager/interface_test.go +++ b/p2p/stream/common/streammanager/interface_test.go @@ -17,7 +17,7 @@ var _ StreamManager = &streamManager{} var ( myPeerID = makePeerID(0) - testProtoID = sttypes.ProtoID("harmony/sync/unitest/0/1.0.0") + testProtoID = sttypes.ProtoID("harmony/sync/unitest/0/1.0.0/1") ) const ( diff --git a/p2p/stream/common/streammanager/streammanager.go b/p2p/stream/common/streammanager/streammanager.go index 33270e1c7..a34118498 100644 --- a/p2p/stream/common/streammanager/streammanager.go +++ b/p2p/stream/common/streammanager/streammanager.go @@ -410,7 +410,7 @@ func (ss *streamSet) get(id sttypes.StreamID) (sttypes.Stream, bool) { if id == "" { return nil, false } - + st, ok := ss.streams[id] return st, ok } diff --git a/p2p/stream/common/streammanager/streammanager_test.go b/p2p/stream/common/streammanager/streammanager_test.go index 5d82c8585..2b49a5f16 100644 --- a/p2p/stream/common/streammanager/streammanager_test.go +++ b/p2p/stream/common/streammanager/streammanager_test.go @@ -209,7 +209,7 @@ func TestStreamSet_numStreamsWithMinProtoID(t *testing.T) { pid1 = testProtoID numPid1 = 5 - pid2 = sttypes.ProtoID("harmony/sync/unitest/0/1.0.1") + pid2 = sttypes.ProtoID("harmony/sync/unitest/0/1.0.1/1") numPid2 = 10 ) diff --git a/p2p/stream/protocols/sync/protocol_test.go b/p2p/stream/protocols/sync/protocol_test.go index aff6691ec..0e40f6017 100644 --- a/p2p/stream/protocols/sync/protocol_test.go +++ b/p2p/stream/protocols/sync/protocol_test.go @@ -15,16 +15,18 @@ func TestProtocol_Match(t *testing.T) { targetID string exp bool }{ - {"harmony/sync/unitest/0/1.0.1", true}, + {"harmony/sync/unitest/0/1.0.1/1", true}, + {"harmony/sync/unitest/0/1.0.1/0", true}, {"h123456", false}, - {"harmony/sync/unitest/0/0.9.9", false}, - {"harmony/epoch/unitest/0/1.0.1", false}, - {"harmony/sync/mainnet/0/1.0.1", false}, - {"harmony/sync/unitest/1/1.0.1", false}, + {"harmony/sync/unitest/0/0.9.9/1", false}, + {"harmony/epoch/unitest/0/1.0.1/1", false}, + {"harmony/sync/mainnet/0/1.0.1/1", false}, + {"harmony/sync/unitest/1/1.0.1/1", false}, } for i, test := range tests { p := &Protocol{ + beaconNode: true, config: Config{ Network: "unitest", ShardID: 0, diff --git a/p2p/stream/types/utils.go b/p2p/stream/types/utils.go index bd8c6144a..86eb88218 100644 --- a/p2p/stream/types/utils.go +++ b/p2p/stream/types/utils.go @@ -49,8 +49,12 @@ type ProtoSpec struct { // ToProtoID convert a ProtoSpec to ProtoID. func (spec ProtoSpec) ToProtoID() ProtoID { + var versionStr string + if spec.Version != nil { + versionStr = spec.Version.String() + } s := fmt.Sprintf(ProtoIDFormat, ProtoIDCommonPrefix, spec.Service, - spec.NetworkType, spec.ShardID, spec.Version.String(), bool2int(spec.BeaconNode)) + spec.NetworkType, spec.ShardID, versionStr, bool2int(spec.BeaconNode)) return ProtoID(s) }