• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Révisionb37eb8733855495baf0b3c8a5dccaa6bef1f9eaf (tree)
l'heure2019-07-25 15:48:06
Auteuriczc <iczcalan@gmai...>
Commitericzc

Message de Log

Merge branch 'feature_consensusreward' of https://github.com/Bytom/vapor into feature_consensusreward

Change Summary

Modification

--- a/netsync/chainmgr/fast_sync.go
+++ b/netsync/chainmgr/fast_sync.go
@@ -7,18 +7,21 @@ import (
77
88 "github.com/vapor/errors"
99 "github.com/vapor/netsync/peers"
10+ "github.com/vapor/p2p/security"
1011 "github.com/vapor/protocol/bc"
1112 "github.com/vapor/protocol/bc/types"
1213 )
1314
1415 var (
15- maxNumOfSkeletonPerSync = uint64(10)
16- numOfBlocksSkeletonGap = maxNumOfBlocksPerMsg
17- maxNumOfBlocksPerSync = numOfBlocksSkeletonGap * maxNumOfSkeletonPerSync
18- fastSyncPivotGap = uint64(64)
19- minGapStartFastSync = uint64(128)
20-
21- errNoSyncPeer = errors.New("can't find sync peer")
16+ minSizeOfSyncSkeleton = 2
17+ maxSizeOfSyncSkeleton = 11
18+ numOfBlocksSkeletonGap = maxNumOfBlocksPerMsg
19+ maxNumOfBlocksPerSync = numOfBlocksSkeletonGap * uint64(maxSizeOfSyncSkeleton-1)
20+ fastSyncPivotGap = uint64(64)
21+ minGapStartFastSync = uint64(128)
22+
23+ errNoSyncPeer = errors.New("can't find sync peer")
24+ errSkeletonSize = errors.New("fast sync skeleton size wrong")
2225 )
2326
2427 type fastSync struct {
@@ -88,6 +91,11 @@ func (fs *fastSync) createFetchBlocksTasks(stopBlock *types.Block) ([]*fetchBloc
8891 return nil, errors.New("No main skeleton found")
8992 }
9093
94+ if len(mainSkeleton) < minSizeOfSyncSkeleton || len(mainSkeleton) > maxSizeOfSyncSkeleton {
95+ fs.peers.ProcessIllegal(fs.mainSyncPeer.ID(), security.LevelMsgIllegal, errSkeletonSize.Error())
96+ return nil, errSkeletonSize
97+ }
98+
9199 // collect peers that match the skeleton of the primary sync peer
92100 fs.msgFetcher.addSyncPeer(fs.mainSyncPeer.ID())
93101 delete(skeletonMap, fs.mainSyncPeer.ID())
--- a/netsync/chainmgr/fast_sync_test.go
+++ b/netsync/chainmgr/fast_sync_test.go
@@ -80,19 +80,19 @@ func TestFastBlockSync(t *testing.T) {
8080 os.RemoveAll(tmp)
8181 }()
8282
83- maxNumOfSkeletonPerSync = 10
83+ maxSizeOfSyncSkeleton = 11
8484 numOfBlocksSkeletonGap = 10
85- maxNumOfBlocksPerSync = maxNumOfSkeletonPerSync * maxNumOfSkeletonPerSync
85+ maxNumOfBlocksPerSync = numOfBlocksSkeletonGap * uint64(maxSizeOfSyncSkeleton-1)
8686 fastSyncPivotGap = uint64(5)
8787 minGapStartFastSync = uint64(6)
8888
8989 defer func() {
90- maxNumOfSkeletonPerSync = 10
90+ maxSizeOfSyncSkeleton = 11
9191 numOfBlocksSkeletonGap = maxNumOfBlocksPerMsg
92- maxNumOfBlocksPerSync = maxNumOfSkeletonPerSync * maxNumOfSkeletonPerSync
92+ maxNumOfBlocksPerSync = numOfBlocksSkeletonGap * uint64(maxSizeOfSyncSkeleton-1)
9393 fastSyncPivotGap = uint64(64)
9494 minGapStartFastSync = uint64(128)
95-
95+ requireHeadersTimeout = 30 * time.Second
9696 }()
9797
9898 baseChain := mockBlocks(nil, 300)
@@ -139,6 +139,13 @@ func TestFastBlockSync(t *testing.T) {
139139 want: baseChain[:5],
140140 err: nil,
141141 },
142+ {
143+ syncTimeout: 0 * time.Second,
144+ aBlocks: baseChain[:50],
145+ bBlocks: baseChain[:301],
146+ want: baseChain[:50],
147+ err: errSkeletonSize,
148+ },
142149 }
143150
144151 for i, c := range cases {
@@ -156,6 +163,7 @@ func TestFastBlockSync(t *testing.T) {
156163 a.blockKeeper.syncPeer = a.peers.GetPeer("test node B")
157164 a.blockKeeper.fastSync.setSyncPeer(a.blockKeeper.syncPeer)
158165
166+ requireHeadersTimeout = c.syncTimeout
159167 if err := a.blockKeeper.fastSync.process(); errors.Root(err) != c.err {
160168 t.Errorf("case %d: got %v want %v", i, err, c.err)
161169 }
Afficher sur ancien navigateur de dépôt.