Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 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
7ced027
wip: introduce pebbledb, remove chaindb/badger
EclesioMeloJunior Jul 24, 2023
b657974
chore: enable sync trace logs
EclesioMeloJunior Jul 24, 2023
1b21120
Merge branch 'development' into eclesio/pebbledb
EclesioMeloJunior Jul 26, 2023
820be03
feat: replace chaindb with pebbledb
EclesioMeloJunior Jul 31, 2023
56876bf
Merge branch 'development' into eclesio/pebbledb
EclesioMeloJunior Jul 31, 2023
d422642
chore: fix unchecked error
EclesioMeloJunior Aug 1, 2023
7b14507
Merge branch 'eclesio/pebbledb' of github.com:ChainSafe/gossamer into…
EclesioMeloJunior Aug 1, 2023
4a5b2fc
Merge branch 'development' into eclesio/pebbledb
EclesioMeloJunior Aug 4, 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
11 changes: 9 additions & 2 deletions cmd/gossamer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cd gossamer
### Compile

To put the binary in ./bin, run:

```bash
make build
```
Expand Down Expand Up @@ -62,7 +63,7 @@ The node configuration can be modified in the `config.toml` file.
### Start the node

```bash
gossamer --basepath /tmp/gossamer --key alice
gossamer --basepath /tmp/gossamer --key alice
```

**Note: The `init` command is optional. If the node is not initialised, it will be initialised with the default configuration.**
Expand Down Expand Up @@ -108,19 +109,22 @@ This subcommand provides capabilities that are similar to
[Parity's Subkey utility](https://docs.substrate.io/v3/tools/subkey).

The account command supports following arguments:

- `generate` - generates a new key pair; specify `--scheme ed25519`, `--scheme secp256k1`, or `--scheme sr25519` (default)
- `list` - lists the keys in the Gossamer keystore
- `import` - imports a key from a keystore file
- `import-raw` - imports a raw key from a keystore file

Supported flags:

- `keystore-path` - path to the Gossamer keystore
- `keystore-file` - path to the keystore file
- `chain` - path to the human-readable chain-spec file
- `--scheme` - `ed25519`, `secp256k1`, or `sr25519` (default)
- `--password` - allows the user to provide a password to either encrypt a generated key or unlock the Gossamer keystore

Examples:

- `gossamer account generate --scheme ed25519` - generates an `ed25519` key pair
- `gossamer account list` - lists the keys in the Gossamer keystore
- `gossamer account import --keystore-file keystore.json` - imports a key from a keystore file
Expand All @@ -145,6 +149,7 @@ represent the Gossamer default configuration.
- `--output-path` - path to the file where the compiled chain-spec should be written

Examples:

- `gossamer build-spec --chain chain-spec.json --output-path compiled-chain-spec.json` - compiles a human-readable
chain-spec into a format that Gossamer can consume
- `gossamer build-spec --chain chain-spec.json --raw --output-path compiled-chain-spec.json` - compiles a human-readable
Expand All @@ -166,6 +171,7 @@ of a JSON file. The input for this subcommand can be retrieved from
- `--chain` - path to the human-readable chain-spec file

Examples:

- `gossamer import-state --first-slot 1 --header header.json --state state.json --chain chain-spec.json` - seeds Gossamer
storage with key-value pairs from a JSON file

Expand All @@ -185,6 +191,7 @@ What follows is a list that describes the services and capabilities that inform

#### State

// TODO: update the `State` description to pebble db
This service is a wrapper around an instance of [`chaindb`](https://github.com/ChainSafe/chaindb), a key-value database
that is built on top of [BadgerDB](https://github.com/dgraph-io/badger) from [Dgraph](https://dgraph.io/). The state
service provides storage capabilities for the other Gossamer services - each service is assigned a prefix that is added
Expand Down Expand Up @@ -271,4 +278,4 @@ capabilities are defined in the [dot/telemetry](../../dot/telemetry) package and
The default listening address for Prometheus metrics is `localhost:9876`, and Gossamer allows the user to configure this parameter with the
`--metrics-address` command-line parameter. The Gossamer telemetry server publishes telemetry data that is compatible with
[Polkadot Telemetry](https://github.com/paritytech/substrate-telemetry) and
[its helpful UI](https://telemetry.polkadot.io/).
[its helpful UI](https://telemetry.polkadot.io/).
21 changes: 21 additions & 0 deletions dot/core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"sync"
"time"

"github.com/ChainSafe/gossamer/dot/network"
"github.com/ChainSafe/gossamer/dot/types"
Expand Down Expand Up @@ -100,6 +101,26 @@ func NewService(cfg *Config) (*Service, error) {
// Start starts the core service
func (s *Service) Start() error {
go s.handleBlocksAsync()

go func() {
time.Sleep(30 * time.Second)
header, err := s.blockState.BestBlockHeader()
if err != nil {
panic(err)
}

ba := &network.BlockAnnounceMessage{
ParentHash: header.ParentHash,
Number: header.Number,
StateRoot: header.StateRoot,
ExtrinsicsRoot: header.ExtrinsicsRoot,
Digest: header.Digest,
BestBlock: true,
}

s.net.GossipMessage(ba)
}()

return nil
}

Expand Down
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
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
59 changes: 59 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"
)

// MaxBlocksInResponse is maximum number of block data a BlockResponse message can contain
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,56 @@ func (cm *ConsensusMessage) Hash() (common.Hash, error) {
}
return common.Blake2bHash(encMsg)
}

func NewBlockRequest(startingBlock variadic.Uint32OrHash, amount uint32,
requestedData byte, direction SyncDirection) *BlockRequestMessage {
return &BlockRequestMessage{
RequestedData: requestedData,
StartingBlock: startingBlock,
Direction: direction,
Max: &amount,
}
}

func NewAscendingBlockRequests(startNumber, targetNumber uint, requestedData byte) []*BlockRequestMessage {
if startNumber > targetNumber {
return []*BlockRequestMessage{}
}

diff := targetNumber - startNumber

// start and end block are the same, just request 1 block
if diff == 0 {
return []*BlockRequestMessage{
NewBlockRequest(*variadic.MustNewUint32OrHash(uint32(startNumber)), 1, requestedData, Ascending),
}
}

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] = NewBlockRequest(*start, max, requestedData, Ascending)
startNumber += uint(max)
}

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 := NewAscendingBlockRequests(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 {
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
4 changes: 2 additions & 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 = wazero_runtime.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 Expand Up @@ -325,6 +324,7 @@ func TestStartStopNode(t *testing.T) {
config.ChainSpec = genFile
config.Core.GrandpaAuthority = false
config.Core.BabeAuthority = false
config.Network.MinPeers = 0

err := InitNode(config)
require.NoError(t, err)
Expand Down
Loading