Skip to content

Instantly share code, notes, and snippets.

@JackyWYX
Last active May 21, 2020 22:10
Show Gist options
  • Save JackyWYX/0cb57998812fe1b87749e22877ed0a8d to your computer and use it in GitHub Desktop.
Save JackyWYX/0cb57998812fe1b87749e22877ed0a8d to your computer and use it in GitHub Desktop.
#3071_test_log

Feature to be tested

During synchronization process, the client node will ask some of the DNS nodes instead of all of them.

Steps for test

  1. Add some print message in function node.forEachPeer to print out all the nodes being used.
  2. Start node.sh to join mainnet with the customized binary file.
  3. See the log for intended message. Shall see number of DNS nodes being queried shall be 4 for beacon.

Results

  • Add print message as test_diff.batch
  • Run a mainnet node with command
./node.sh -S -z -k 28142f0baf00edd18016d4d9d95f3844d7cff29e613b2a80b9623e1e38a0485c37a13f413499ce48f9bcae69c4d4b289.key -D
  • Got a print log. Please see the file 2.node_print.log
  • The log shows that connected peers are reduced to 4, half of the original dns number, which is expected.
  • Query the latest headers. Node is syncing.
[yx@ip-172-31-37-52 hmy]$ ./hmy blockchain latest-headers
{
  "id": "1",
  "jsonrpc": "2.0",
  "result": {
    "beacon-chain-header": {
      "block-header-hash": "0xc56b6221fd7e215a6762d2aec8a7c6dbcd371af758498148bc7a464a556174b3",
      "block-number": 10066,
      "epoch": 0,
      "shard-id": 0,
      "view-id": 10065
    },
    "shard-chain-header": {
      "block-header-hash": "0x2e20b98ce7a9e21ac156bfad2298db17c85ae0a73a447319571f26abe8e81894",
      "block-number": 7408,
      "epoch": 0,
      "shard-id": 1,
      "view-id": 7407
    }
  }
}

Conclusion

Test passed

diff --git a/api/service/syncing/syncing.go b/api/service/syncing/syncing.go
index d2e5391a..09e0fdd5 100644
--- a/api/service/syncing/syncing.go
+++ b/api/service/syncing/syncing.go
@@ -87,6 +87,7 @@ func (sc *SyncConfig) AddPeer(peer *SyncPeerConfig) {
func (sc *SyncConfig) ForEachPeer(f func(peer *SyncPeerConfig) (brk bool)) {
sc.mtx.RLock()
defer sc.mtx.RUnlock()
+ fmt.Println("During sync processingtotal number of peers:", len(sc.peers))
for _, peer := range sc.peers {
if f(peer) {
break
@@ -233,7 +234,9 @@ func (peerConfig *SyncPeerConfig) GetBlocks(hashes [][]byte) ([][]byte, error) {
func (ss *StateSync) CreateSyncConfig(peers []p2p.Peer, isBeacon bool) error {
// limit the number of dns peers to connect
randSeed := time.Now().UnixNano()
+ fmt.Println("before limit number size:", len(peers))
peers = limitNumPeers(peers, randSeed)
+ fmt.Println("after limit number size:", len(peers))
utils.Logger().Debug().
Int("len", len(peers)).
diff --git a/node/node_syncing.go b/node/node_syncing.go
index 4e34c853..c2f0003e 100644
--- a/node/node_syncing.go
+++ b/node/node_syncing.go
@@ -193,6 +193,7 @@ func (node *Node) DoBeaconSyncing() {
Msg("cannot retrieve beacon syncing peers")
continue
}
+ fmt.Println("create beacon syncing")
if err := node.beaconSync.CreateSyncConfig(peers, true); err != nil {
utils.Logger().Warn().Err(err).Msg("cannot create beacon sync config")
continue
@@ -233,6 +234,7 @@ func (node *Node) doSync(bc *core.BlockChain, worker *worker.Worker, willJoinCon
Msg("cannot retrieve syncing peers")
return
}
+ fmt.Println("create shard syncing")
if err := node.stateSync.CreateSyncConfig(peers, false); err != nil {
utils.Logger().Warn().
Err(err).
Staking mode; node key 28142f0baf00edd18016d4d9d95f3844d7cff29e613b2a80b9623e1e38a0485c37a13f413499ce48f9bcae69c4d4b289; -> shard 1
create beacon syncing
before limit number size: 9
after limit number size: 4
During sync processingtotal number of peers: 4
During sync processingtotal number of peers: 4
During sync processingtotal number of peers: 4
During sync processingtotal number of peers: 4
create shard syncing
before limit number size: 9
after limit number size: 4
During sync processingtotal number of peers: 4
During sync processingtotal number of peers: 4
During sync processingtotal number of peers: 4
During sync processingtotal number of peers: 4
During sync processingtotal number of peers: 4
During sync processingtotal number of peers: 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment