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

fix(dot/sync): rework on bootstrap/tip sync #3227

Merged
merged 188 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
f3eb2eb
wip: implementing a poc around warp sync
EclesioMeloJunior Mar 30, 2023
d7c07ef
chore: include informative logs to debug sync
EclesioMeloJunior Apr 6, 2023
428ff13
chore: enable state trace logs and improve error for unfinalized ance…
EclesioMeloJunior Apr 11, 2023
25b30d5
wip: handle workers results
EclesioMeloJunior Apr 13, 2023
d05fdec
wip: handling workers results
EclesioMeloJunior Apr 13, 2023
6e272a6
chore: start ignoring peers + use `idleTicker` to check the pool
EclesioMeloJunior Apr 14, 2023
39dd7c3
fix: use buffered channel for taskQueue + wip: implementing tip sync
EclesioMeloJunior Apr 15, 2023
fc081e1
chore: enable state/grandpa/digest trace to investigate forced changes
EclesioMeloJunior Apr 17, 2023
7bc8038
chore: making changes to handling forced changes
EclesioMeloJunior Apr 18, 2023
0a27158
chore: reset scheduled changes once a forced change applies
EclesioMeloJunior Apr 18, 2023
bf6bb61
chore: rollback basepath
EclesioMeloJunior Apr 19, 2023
59cbaae
chore: wip tip sync
EclesioMeloJunior Apr 19, 2023
f9ca5a4
wip: tip sync impl
EclesioMeloJunior Apr 24, 2023
f9d7e43
chore: complete tip sync adjusts
EclesioMeloJunior Apr 26, 2023
3ba7e4c
chore: rollback modification on .yml files
EclesioMeloJunior Apr 26, 2023
16e8ee6
chore: rollback modifications to digest pkg
EclesioMeloJunior Apr 26, 2023
3eba164
chore: rollback modification to network pkg
EclesioMeloJunior Apr 26, 2023
c30948a
chore: rollback modifications to auth set changes
EclesioMeloJunior Apr 26, 2023
57f433c
chore: remove `internal/sync` pkg
EclesioMeloJunior Apr 26, 2023
a76c0e9
chore: remove unneeded comments
EclesioMeloJunior Apr 26, 2023
0bd8505
chore: remove unneeded fields from sync worker
EclesioMeloJunior Apr 27, 2023
5102e62
chore: remove dead code + add errors wrappers
EclesioMeloJunior Apr 27, 2023
c13b597
chore: address some points
EclesioMeloJunior Apr 27, 2023
f0c667f
chore: fix missing blocks in ascedingBlockRequests
EclesioMeloJunior May 2, 2023
f3cb072
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior May 2, 2023
2e640ce
chore: delete chainprocessor.go from merge with development
EclesioMeloJunior May 2, 2023
683e331
chore: impl wait/release while validating a worker result
EclesioMeloJunior May 3, 2023
b3d4c8e
wip: tip sync concurrency for bounded requests
EclesioMeloJunior May 5, 2023
c446fc0
wip: bounded requests without blocking the task queue listener
EclesioMeloJunior May 6, 2023
938d001
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior May 6, 2023
c8f47fa
chore: use versioned config data + enable traces
EclesioMeloJunior May 6, 2023
ce40f14
chore: remove state trace
EclesioMeloJunior May 6, 2023
e33c444
chore: revert changes from `westend-local-spec.json`
EclesioMeloJunior May 6, 2023
f00a242
chore: enable trace to `sync` and `digest`
EclesioMeloJunior May 6, 2023
6e3d2d0
chore: enable pprof to staging env
EclesioMeloJunior May 8, 2023
023df2c
chore: use `l.Lock()` instead of `l.RLock()`
EclesioMeloJunior May 8, 2023
0f661de
chore: change the worker_pool
EclesioMeloJunior May 8, 2023
924d172
chore: small fixes to the `executeRequest` method
EclesioMeloJunior May 9, 2023
6b481c1
chore: remove unneeded comment line + improve func name
EclesioMeloJunior May 9, 2023
539e092
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior May 18, 2023
9ae3fcb
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior May 19, 2023
35c9eea
chore: re-written `Test_chainSync_setBlockAnnounce` test
EclesioMeloJunior May 22, 2023
443045c
chore: include a bootstrap sync test with 2 workers
EclesioMeloJunior May 23, 2023
2432324
chore: testing successful sync with workers failing
EclesioMeloJunior May 24, 2023
5c7f983
chore: adjust mocks
EclesioMeloJunior May 24, 2023
17b03b7
chore: avoid ignoring peers whenever we failed to read response bytes
EclesioMeloJunior May 24, 2023
c9d16ce
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior May 25, 2023
0f69520
chore: add export comment to `AllConnectedPeers`
EclesioMeloJunior May 25, 2023
ae202b9
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior May 25, 2023
e780937
chore: improve readability + ignore peers management
EclesioMeloJunior May 29, 2023
4cd4fe5
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior May 29, 2023
ae8b367
chore: make the peer discovery everytime
EclesioMeloJunior May 29, 2023
e1b4bd4
chore: use a resource manager to autoscale outbound requests
EclesioMeloJunior May 30, 2023
a26b845
chore: remove `maxRequestsAllowed` restriction
EclesioMeloJunior May 30, 2023
e978240
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior May 30, 2023
90606ab
chore: remove unneeded deltas on westend chain
EclesioMeloJunior May 30, 2023
795e1b7
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior May 30, 2023
bc88064
chore: addressing comments
EclesioMeloJunior May 30, 2023
9ae5d5a
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior May 30, 2023
3103fdb
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior May 30, 2023
43ba321
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior May 30, 2023
0e33188
chore: reduce number of max peers
EclesioMeloJunior May 30, 2023
6982f2a
chore: make target number clear on `requesting_4_chunks_of_128_plus_3…
EclesioMeloJunior May 31, 2023
22f62d7
chore: remove unneeded `blockAnnounceCh`
EclesioMeloJunior May 31, 2023
35197c5
chore: reduce the amount of blocks synced at same time
EclesioMeloJunior Jun 1, 2023
576bb72
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jun 2, 2023
1b991b3
chore: merge development
EclesioMeloJunior Jun 5, 2023
c73789a
Merge branch 'development' into eclesio/fix-sync-speed
EclesioMeloJunior Jun 5, 2023
d9b5d19
chore: remove unneeded sync files
EclesioMeloJunior Jun 5, 2023
5bc45f9
EclesioMeloJunior Jun 6, 2023
5fb3070
chore: use highest finalized header instead of best block number
EclesioMeloJunior Jun 6, 2023
6ee8b4a
chore: using finalised header to bootstrap sync
EclesioMeloJunior Jun 6, 2023
c7e145b
chore: use a checkpoint header every time we failed to import blocks
EclesioMeloJunior Jun 6, 2023
a6086d6
chore: fix `all goroutines are asleep - deadlock` problem
EclesioMeloJunior Jun 7, 2023
19606f1
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jun 7, 2023
22699e8
chore: fix punishment
EclesioMeloJunior Jun 7, 2023
e0ea946
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jun 16, 2023
845e42e
chore: fix `executeBootstrapSync` tests
EclesioMeloJunior Jun 16, 2023
61c1a51
chore: revert libp2p resource manager additions
EclesioMeloJunior Jun 16, 2023
f415b90
chore: rename `AllConnectedPeers` to `AllConnectedPeersID`
EclesioMeloJunior Jun 16, 2023
fe132b4
chore: move `ErrReceivedEmptyMessage` to errors file
EclesioMeloJunior Jun 16, 2023
1df21a3
chore: rename `<-done` to `<-stop`
EclesioMeloJunior Jun 16, 2023
eeb5118
chore: create `TestSyncWorkerPool_useConnectedPeers` test
EclesioMeloJunior Jun 20, 2023
10dd486
chore: add methods comments
EclesioMeloJunior Jun 20, 2023
9d2b32d
chore: include `TestSyncWorkerPool_newPeer` test
EclesioMeloJunior Jun 20, 2023
e59228a
chore: rename `l` to `mtx`
EclesioMeloJunior Jun 20, 2023
3e7f420
chore: remove unneeded variable
EclesioMeloJunior Jun 20, 2023
1959231
chore: add `TestSyncWorkerPool__listenForRequests_submitRequest` test
EclesioMeloJunior Jun 20, 2023
4ea26dc
chore: add `TestSyncWorkerPool_listenForRequests_busyWorkers` test
EclesioMeloJunior Jun 20, 2023
a2d45d8
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jun 20, 2023
7fc622b
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jun 20, 2023
16de56f
chore: move request message creation to `network` pkg
EclesioMeloJunior Jun 20, 2023
51a78cf
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Jun 20, 2023
3c2b14f
chore: fix tests to use `network.MaxBlockResponseSize`
EclesioMeloJunior Jun 20, 2023
beb7f8f
chore: fix lint warns
EclesioMeloJunior Jun 20, 2023
6d7d564
chore: adding license to `worker_pool_test.go`
EclesioMeloJunior Jun 20, 2023
4096823
chore: remove unneeded else branch
EclesioMeloJunior Jun 21, 2023
060dbc6
chore: fix deepsource warns
EclesioMeloJunior Jun 21, 2023
dc82d93
chore: wip `announced_block_while_in_tip_mode` test
EclesioMeloJunior Jun 21, 2023
057bacb
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jun 21, 2023
4a51be3
chore: add `announced_block_while_in_tip_mode` test
EclesioMeloJunior Jun 21, 2023
3d37f61
chore: add `TestChainSync_validateResponse` test
EclesioMeloJunior Jun 21, 2023
b09cdaa
chore: fix `validateBlockResponse` checks
EclesioMeloJunior Jun 21, 2023
1a56e6d
chore: solve all tests failures
EclesioMeloJunior Jun 22, 2023
0f43ae4
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Jun 22, 2023
2836777
chore: move worker status update from `defer`
EclesioMeloJunior Jun 22, 2023
55ff3f8
chore: solve `lll` lint wanr
EclesioMeloJunior Jun 22, 2023
9ef76cf
chore: improve code coverage by testing failure scenarios
EclesioMeloJunior Jun 22, 2023
7037924
chore: request missing blocks
EclesioMeloJunior Jun 27, 2023
7bbebfd
chore: punish only if is a best block, ignore key not found
EclesioMeloJunior Jul 4, 2023
2a97b9b
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 5, 2023
83a553d
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 5, 2023
990b9c9
chore: add license
EclesioMeloJunior Jul 5, 2023
3c96c08
chore: remove unneeded nil check and fix `lll` lint warn
EclesioMeloJunior Jul 5, 2023
4047178
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Jul 5, 2023
8d712ca
chore: fix `dot/sync` integration tests
EclesioMeloJunior Jul 5, 2023
22bb4cb
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 5, 2023
4a1905e
chore: fix `TestAscendingBlockRequest` test
EclesioMeloJunior Jul 5, 2023
fbaca64
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Jul 5, 2023
9e2acb3
chore: fix `TestNewNode` test
EclesioMeloJunior Jul 6, 2023
1610978
chore: fix `TestStartStopNode` test
EclesioMeloJunior Jul 6, 2023
9f540b9
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 6, 2023
bb6e4d7
chore: include `TestChainSync_BootstrapSync_SucessfulSync_ReceivedPar…
EclesioMeloJunior Jul 6, 2023
4741a28
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Jul 6, 2023
f1f0078
chore: address comments
EclesioMeloJunior Jul 11, 2023
b60486b
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 11, 2023
6ba9c73
chore: solve lint warns
EclesioMeloJunior Jul 11, 2023
268f572
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Jul 11, 2023
bf87577
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 18, 2023
d50c7fc
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 23, 2023
7dc13c0
chore: address comments
EclesioMeloJunior Jul 23, 2023
d677dc1
chore: change to plural
EclesioMeloJunior Jul 25, 2023
39a52d0
chore: use `WaitGroup` and implement stop timeout
EclesioMeloJunior Jul 25, 2023
e20b5d5
chore: change `peerView` to be a value
EclesioMeloJunior Jul 25, 2023
7da5edf
addressing comments
EclesioMeloJunior Jul 25, 2023
e6f4792
chore: bounded request retry with the same peer id
EclesioMeloJunior Jul 25, 2023
075882a
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 25, 2023
703bb43
chore: address lint and deepsource comments
EclesioMeloJunior Jul 25, 2023
e9e8651
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Jul 25, 2023
15e5454
chore: fix race conditions
EclesioMeloJunior Jul 25, 2023
0263c4d
chore: fix integration test
EclesioMeloJunior Jul 25, 2023
5f73d0a
wip: increase test coverage
EclesioMeloJunior Jul 26, 2023
684e34f
chore: introduce a simple check to ensure chain continuity
EclesioMeloJunior Jul 26, 2023
bbe8e07
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 26, 2023
0d0f018
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 26, 2023
0df449a
chore: paralell request stream for each available peer
EclesioMeloJunior Jul 27, 2023
62088eb
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Jul 27, 2023
1bca2c6
chore: remove `sync.Cond`
EclesioMeloJunior Jul 27, 2023
052fd6c
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Jul 27, 2023
0d565d1
chore: recap old implementation with concurrency guard
EclesioMeloJunior Jul 28, 2023
b7ec4bb
chore: dont punish a already punished peer
EclesioMeloJunior Jul 31, 2023
2c70646
chore: implement round-robind worker selection and remove sync.Cond c…
EclesioMeloJunior Aug 1, 2023
8282df8
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Aug 2, 2023
fae2f8d
wip: working on tests
EclesioMeloJunior Aug 2, 2023
1893daf
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Aug 2, 2023
2ea02f1
chore: make punishement without stop worker
EclesioMeloJunior Aug 2, 2023
3bf881a
chore: fix lint
EclesioMeloJunior Aug 2, 2023
01530e1
chore: add license
EclesioMeloJunior Aug 2, 2023
ab39ccc
chore: change to default values to `westend`
EclesioMeloJunior Aug 2, 2023
c6f7c89
chore: fix `chain_sync_test.go`
EclesioMeloJunior Aug 3, 2023
4a8a5a8
chore: include `doResponseGrowsTheChain` tests
EclesioMeloJunior Aug 3, 2023
407a7ed
chore: fix lint warns
EclesioMeloJunior Aug 3, 2023
779d393
chore: fix current tests
EclesioMeloJunior Aug 3, 2023
827e2a7
chore: fix `TestAscendingBlockRequest` to include the start block in …
EclesioMeloJunior Aug 4, 2023
6e3cc99
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Aug 4, 2023
49e0aee
chore: fix lint warn
EclesioMeloJunior Aug 4, 2023
735c461
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Aug 4, 2023
d6416a8
chore: fix `TestAscendingBlockRequest` test failure
EclesioMeloJunior Aug 4, 2023
dfd96b9
chore: remove test to ensure which peer receives task
EclesioMeloJunior Aug 4, 2023
c738d01
chore: remove hidden goroutine `GO-E1007`
EclesioMeloJunior Aug 4, 2023
e2ca0d7
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Aug 7, 2023
90c6658
chore: update `worker_test.go`
EclesioMeloJunior Aug 7, 2023
1e1f0dc
chore: update `zombienet` github action to go1.20
EclesioMeloJunior Aug 7, 2023
224634a
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Aug 7, 2023
c4efd00
chore: start peer worker from block announce
EclesioMeloJunior Aug 8, 2023
edeb27f
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Aug 8, 2023
9c397ef
Merge branch 'development' into eclesio/fix-bootstrap-sync
EclesioMeloJunior Aug 8, 2023
c570e65
chore: address comments
EclesioMeloJunior Aug 8, 2023
5322f6f
Merge branch 'eclesio/fix-bootstrap-sync' of github.com:ChainSafe/gos…
EclesioMeloJunior Aug 8, 2023
aeb4b6e
chore: make `processTask` panics if `queue` channel is blocked to write
EclesioMeloJunior Aug 8, 2023
ec57baf
chore: randomly assign a task to a peer if none is passed
EclesioMeloJunior Aug 9, 2023
fa161b0
chore: fix lint
EclesioMeloJunior Aug 9, 2023
d9dafa5
chore: use `crypto/rand`
EclesioMeloJunior Aug 9, 2023
0c97fe0
chore: make tests work
EclesioMeloJunior Aug 10, 2023
198fb18
chore: fix race conditions
EclesioMeloJunior Aug 10, 2023
75799ff
chore: remove unnused fields and remove unneeded error return
EclesioMeloJunior Aug 10, 2023
ec34fb5
chore: remove redundant return
EclesioMeloJunior Aug 10, 2023
0bac649
chore: fix zombienet test check
EclesioMeloJunior Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions chain/westend/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func DefaultConfig() *cfg.Config {
config.Core.GrandpaAuthority = false
config.Core.Role = 1
config.Network.NoMDNS = false
config.Network.MaxPeers = 128
config.PrometheusExternal = true
config.PrometheusPort = 9876

config.Log.Sync = "trace"
config.Log.Digest = "trace"

config.Pprof.Enabled = true
config.Pprof.ListeningAddress = "0.0.0.0:6060"
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
return config
}
4 changes: 2 additions & 2 deletions dot/network/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (
startDHTTimeout = time.Second * 10
initialAdvertisementTimeout = time.Millisecond
tryAdvertiseTimeout = time.Second * 30
connectToPeersTimeout = time.Minute * 5
connectToPeersTimeout = time.Minute
kanishkatn marked this conversation as resolved.
Show resolved Hide resolved
findPeersTimeout = time.Minute
)

Expand Down Expand Up @@ -183,7 +183,7 @@ func (d *discovery) checkPeerCount() {
case <-d.ctx.Done():
return
case <-ticker.C:
if len(d.h.Network().Peers()) > d.minPeers {
if len(d.h.Network().Peers()) >= d.maxPeers {
continue
}

Expand Down
2 changes: 2 additions & 0 deletions dot/network/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

var (
ErrReceivedEmptyMessage = errors.New("received empty message")

errCannotValidateHandshake = errors.New("failed to validate handshake")
errMessageTypeNotValid = errors.New("message type is not valid")
errInvalidHandshakeForPeer = errors.New("peer previously sent invalid handshake")
Expand Down
82 changes: 82 additions & 0 deletions dot/network/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"github.com/ChainSafe/gossamer/pkg/scale"
)

// maxResponseSize is maximum number of block data a BlockResponse message can contain
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
const MaxBlocksInResponse = 128

type MessageType byte

// Message types for notifications protocol messages. Used internally to map message to protocol.
Expand Down Expand Up @@ -44,6 +47,9 @@ const (
RequestedDataReceipt = byte(4)
RequestedDataMessageQueue = byte(8)
RequestedDataJustification = byte(16)
BootstrapRequestData = RequestedDataHeader +
RequestedDataBody +
RequestedDataJustification
)

var _ Message = (*BlockRequestMessage)(nil)
Expand Down Expand Up @@ -354,3 +360,79 @@ func (cm *ConsensusMessage) Hash() (common.Hash, error) {
}
return common.Blake2bHash(encMsg)
}

// NewSingleBlockRequestMessage returns a request to retrieve a single block
func NewSingleBlockRequestMessage(blockHash common.Hash, requestedData byte) *BlockRequestMessage {
one := uint32(1)
return &BlockRequestMessage{
RequestedData: requestedData,
StartingBlock: *variadic.MustNewUint32OrHash(blockHash),
Direction: Descending,
Max: &one,
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
}
}

// NewDescendingBlockRequest returns a descending block request message
func NewDescendingBlockRequest(blockHash common.Hash, amount uint32, requestedData byte) *BlockRequestMessage {
return &BlockRequestMessage{
RequestedData: requestedData,
StartingBlock: *variadic.MustNewUint32OrHash(blockHash),
Direction: Descending,
Max: &amount,
}
}

func NewAscedingBlockRequests(startNumber, targetNumber uint, requestedData byte) []*BlockRequestMessage {
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
if startNumber > targetNumber {
return []*BlockRequestMessage{}
}
timwu20 marked this conversation as resolved.
Show resolved Hide resolved

diff := targetNumber - startNumber

// start and end block are the same, just request 1 block
if diff == 0 {
one := uint32(1)
return []*BlockRequestMessage{
{
RequestedData: requestedData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(startNumber)),
Direction: Ascending,
Max: &one,
},
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
}
}

numRequests := diff / MaxBlocksInResponse
// we should check if the diff is in the maxResponseSize bounds
// otherwise we should increase the numRequests by one, take this
// example, we want to sync from 0 to 259, the diff is 259
// then the num of requests is 2 (uint(259)/uint(128)) however two requests will
// retrieve only 256 blocks (each request can retrieve a max of 128 blocks), so we should
// create one more request to retrieve those missing blocks, 3 in this example.
missingBlocks := diff % MaxBlocksInResponse
if missingBlocks != 0 {
numRequests++
}

reqs := make([]*BlockRequestMessage, numRequests)
for i := uint(0); i < numRequests; i++ {
max := uint32(MaxBlocksInResponse)

lastIteration := numRequests - 1
if i == lastIteration && missingBlocks != 0 {
max = uint32(missingBlocks)
}

start := variadic.MustNewUint32OrHash(startNumber)

reqs[i] = &BlockRequestMessage{
RequestedData: requestedData,
StartingBlock: *start,
Direction: Ascending,
Max: &max,
}
startNumber += uint(max)
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
}

return reqs
}
119 changes: 119 additions & 0 deletions dot/network/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,122 @@ func TestDecodeConsensusMessage(t *testing.T) {
require.NoError(t, err)
require.Equal(t, encMsg, encodedMessage)
}

func TestAscendingBlockRequest(t *testing.T) {
one := uint32(1)
three := uint32(3)
maxResponseSize := uint32(MaxBlocksInResponse)
cases := map[string]struct {
startNumber, targetNumber uint
expectedBlockRequestMessage []*BlockRequestMessage
}{
"start_greater_than_target": {
startNumber: 10,
targetNumber: 0,
expectedBlockRequestMessage: []*BlockRequestMessage{},
},

"no_difference_between_start_and_target": {
startNumber: 10,
targetNumber: 10,
expectedBlockRequestMessage: []*BlockRequestMessage{
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(10)),
Direction: Ascending,
Max: &one,
},
},
},

"requesting_128_blocks": {
startNumber: 0,
targetNumber: 128,
expectedBlockRequestMessage: []*BlockRequestMessage{
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(0)),
Direction: Ascending,
Max: &maxResponseSize,
},
},
},

"requesting_4_chunks_of_128_blocks": {
startNumber: 0,
targetNumber: 512, // 128 * 4
expectedBlockRequestMessage: []*BlockRequestMessage{
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(0)),
Direction: Ascending,
Max: &maxResponseSize,
},
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(128)),
Direction: Ascending,
Max: &maxResponseSize,
},
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(256)),
Direction: Ascending,
Max: &maxResponseSize,
},
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(384)),
Direction: Ascending,
Max: &maxResponseSize,
},
},
},

"requesting_4_chunks_of_128_plus_3_blocks": {
startNumber: 0,
targetNumber: (128 * 4) + 3,
expectedBlockRequestMessage: []*BlockRequestMessage{
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(0)),
Direction: Ascending,
Max: &maxResponseSize,
},
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(128)),
Direction: Ascending,
Max: &maxResponseSize,
},
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(256)),
Direction: Ascending,
Max: &maxResponseSize,
},
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(384)),
Direction: Ascending,
Max: &maxResponseSize,
},
{
RequestedData: BootstrapRequestData,
StartingBlock: *variadic.MustNewUint32OrHash(uint32(512)),
Direction: Ascending,
Max: &three,
},
},
},
}

for tname, tt := range cases {
tt := tt

t.Run(tname, func(t *testing.T) {
requests := NewAscedingBlockRequests(tt.startNumber, tt.targetNumber, BootstrapRequestData)
require.Equal(t, tt.expectedBlockRequestMessage, requests)
})
}
}
5 changes: 5 additions & 0 deletions dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,11 @@ func (s *Service) NetworkState() common.NetworkState {
}
}

// AllConnectedPeersID returns all the connected to the node instance
func (s *Service) AllConnectedPeersID() []peer.ID {
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
return s.host.p2pHost.Network().Peers()
}

// Peers returns information about connected peers needed for the rpc server
func (s *Service) Peers() []common.PeerInfo {
var peers []common.PeerInfo
Expand Down
6 changes: 0 additions & 6 deletions dot/network/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
package network

import (
"time"

libp2pnetwork "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
)

var (
BlockRequestTimeout = time.Second * 20
)

// handleSyncStream handles streams with the <protocol-id>/sync/2 protocol ID
func (s *Service) handleSyncStream(stream libp2pnetwork.Stream) {
if stream == nil {
Expand Down
3 changes: 1 addition & 2 deletions dot/node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func TestNewNode(t *testing.T) {
initConfig.Account.Key = "alice"
initConfig.Core.Role = common.FullNodeRole
initConfig.Core.WasmInterpreter = wasmer.Name

initConfig.Log.Digest = "critical"

networkConfig := &network.Config{
Expand Down Expand Up @@ -86,7 +85,7 @@ func TestNewNode(t *testing.T) {
assert.NoError(t, err)

mockServiceRegistry := NewMockServiceRegisterer(ctrl)
mockServiceRegistry.EXPECT().RegisterService(gomock.Any()).Times(8)
mockServiceRegistry.EXPECT().RegisterService(gomock.Any()).Times(9)

m := NewMocknodeBuilderIface(ctrl)
m.EXPECT().isNodeInitialised(initConfig.BasePath).Return(nil)
Expand Down
87 changes: 87 additions & 0 deletions dot/rpc/modules/gomock_reflect_2744729207/prog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2023 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only


package main
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved

import (
"encoding/gob"
"flag"
"fmt"
"os"
"path"
"reflect"

"github.com/golang/mock/mockgen/model"

pkg_ "github.com/ChainSafe/gossamer/dot/rpc/modules"
)

var output = flag.String("output", "", "The output file name, or empty to use stdout.")

func main() {
flag.Parse()

its := []struct{
sym string
typ reflect.Type
}{

{ "StorageAPI", reflect.TypeOf((*pkg_.StorageAPI)(nil)).Elem()},

{ "BlockAPI", reflect.TypeOf((*pkg_.BlockAPI)(nil)).Elem()},

{ "NetworkAPI", reflect.TypeOf((*pkg_.NetworkAPI)(nil)).Elem()},

{ "BlockProducerAPI", reflect.TypeOf((*pkg_.BlockProducerAPI)(nil)).Elem()},

{ "TransactionStateAPI", reflect.TypeOf((*pkg_.TransactionStateAPI)(nil)).Elem()},

{ "CoreAPI", reflect.TypeOf((*pkg_.CoreAPI)(nil)).Elem()},

{ "SystemAPI", reflect.TypeOf((*pkg_.SystemAPI)(nil)).Elem()},

{ "BlockFinalityAPI", reflect.TypeOf((*pkg_.BlockFinalityAPI)(nil)).Elem()},

{ "RuntimeStorageAPI", reflect.TypeOf((*pkg_.RuntimeStorageAPI)(nil)).Elem()},

{ "SyncStateAPI", reflect.TypeOf((*pkg_.SyncStateAPI)(nil)).Elem()},

}
pkg := &model.Package{
// NOTE: This behaves contrary to documented behaviour if the
// package name is not the final component of the import path.
// The reflect package doesn't expose the package name, though.
Name: path.Base("github.com/ChainSafe/gossamer/dot/rpc/modules"),
}

for _, it := range its {
intf, err := model.InterfaceFromInterfaceType(it.typ)
if err != nil {
fmt.Fprintf(os.Stderr, "Reflection: %v\n", err)
os.Exit(1)
}
intf.Name = it.sym
pkg.Interfaces = append(pkg.Interfaces, intf)
}

outfile := os.Stdout
if len(*output) != 0 {
var err error
outfile, err = os.Create(*output)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open output file %q", *output)
}
defer func() {
if err := outfile.Close(); err != nil {
fmt.Fprintf(os.Stderr, "failed to close output file %q", *output)
os.Exit(1)
}
}()
}

if err := gob.NewEncoder(outfile).Encode(pkg); err != nil {
fmt.Fprintf(os.Stderr, "gob encode: %v\n", err)
os.Exit(1)
}
}
Loading
Loading