Merge pull request #713 from u5surf/issue-708

Issue 708
pull/716/head
Leo Chen 6 years ago committed by GitHub
commit 450f5dec97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      api/proto/discovery/pingpong_test.go
  2. 4
      api/proto/node/node_test.go
  3. 2
      api/service/discovery/service.go
  4. 15
      api/service/explorer/service.go
  5. 2
      api/service/syncing/syncing.go
  6. 6
      api/service/syncing/syncing_test.go
  7. 18
      consensus/consensus_validator_test.go
  8. 5
      core/tx_journal.go
  9. 46
      internal/utils/configfile_test.go
  10. 12
      internal/utils/utils_test.go
  11. 7
      node/contract.go
  12. 4
      node/demo_contract.go
  13. 2
      node/node_genesis.go
  14. 2
      node/node_newblock.go
  15. 2
      node/node_syncing.go
  16. 8
      node/node_test.go
  17. 7
      test/p2pchat/chat.go

@ -89,6 +89,9 @@ func TestSerialize(test *testing.T) {
buf2 = pong1.ConstructPongMessage() buf2 = pong1.ConstructPongMessage()
msg2, err := proto.GetMessagePayload(buf2) msg2, err := proto.GetMessagePayload(buf2)
if err != nil {
test.Error("GetMessagePayload Failed!")
}
pong, err := GetPongMessage(msg2) pong, err := GetPongMessage(msg2)
if err != nil { if err != nil {
test.Error("Pong failed!") test.Error("Pong failed!")

@ -55,8 +55,8 @@ func TestConstructTransactionListMessageAccount(t *testing.T) {
func TestConstructRequestTransactionsMessage(t *testing.T) { func TestConstructRequestTransactionsMessage(t *testing.T) {
txIDs := [][]byte{ txIDs := [][]byte{
[]byte{1, 2}, {1, 2},
[]byte{3, 4}, {3, 4},
} }
buf := ConstructRequestTransactionsMessage(txIDs) buf := ConstructRequestTransactionsMessage(txIDs)

@ -103,7 +103,7 @@ func (s *Service) contactP2pPeers() {
case <-tick.C: case <-tick.C:
for g, a := range s.config.Actions { for g, a := range s.config.Actions {
if a == p2p.ActionPause { if a == p2p.ActionPause {
// Recived Pause Message, to reduce the frequency of ping message to every 1 minute // Received Pause Message, to reduce the frequency of ping message to every 1 minute
// TODO (leo) use different timer tick for different group, mainly differentiate beacon and regular shards // TODO (leo) use different timer tick for different group, mainly differentiate beacon and regular shards
// beacon ping could be less frequent than regular shard // beacon ping could be less frequent than regular shard
tick.Stop() tick.Stop()

@ -146,12 +146,19 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) {
} }
db := s.storage.GetDB() db := s.storage.GetDB()
fromInt, err := strconv.Atoi(from) fromInt, err := strconv.Atoi(from)
if err != nil {
json.NewEncoder(w).Encode(data.Blocks)
return
}
var toInt int var toInt int
if to == "" { if to == "" {
bytes, err := db.Get([]byte(BlockHeightKey)) toInt, err = func() (int, error) {
if err == nil { bytes, err := db.Get([]byte(BlockHeightKey))
toInt, err = strconv.Atoi(string(bytes)) if err == nil {
} return strconv.Atoi(string(bytes))
}
return toInt, err
}()
} else { } else {
toInt, err = strconv.Atoi(to) toInt, err = strconv.Atoi(to)
} }

@ -555,7 +555,7 @@ func (peerConfig *SyncPeerConfig) registerToBroadcast(peerHash []byte, ip, port
} }
// RegisterNodeInfo will register node to peers to accept future new block broadcasting // RegisterNodeInfo will register node to peers to accept future new block broadcasting
// return number of successfull registration // return number of successful registration
func (ss *StateSync) RegisterNodeInfo() int { func (ss *StateSync) RegisterNodeInfo() int {
registrationNumber := RegistrationNumber registrationNumber := RegistrationNumber
utils.GetLogInstance().Debug("[SYNC] node registration to peers", utils.GetLogInstance().Debug("[SYNC] node registration to peers",

@ -10,7 +10,7 @@ import (
// Simple test for IncorrectResponse // Simple test for IncorrectResponse
func TestCreateTestSyncPeerConfig(t *testing.T) { func TestCreateTestSyncPeerConfig(t *testing.T) {
client := &downloader.Client{} client := &downloader.Client{}
blockHashes := [][]byte{[]byte{}} blockHashes := [][]byte{{}}
syncPeerConfig := CreateTestSyncPeerConfig(client, blockHashes) syncPeerConfig := CreateTestSyncPeerConfig(client, blockHashes)
assert.Equal(t, client, syncPeerConfig.GetClient(), "error") assert.Equal(t, client, syncPeerConfig.GetClient(), "error")
} }
@ -18,9 +18,9 @@ func TestCreateTestSyncPeerConfig(t *testing.T) {
// Simple test for IncorrectResponse // Simple test for IncorrectResponse
func TestCompareSyncPeerConfigByblockHashes(t *testing.T) { func TestCompareSyncPeerConfigByblockHashes(t *testing.T) {
client := &downloader.Client{} client := &downloader.Client{}
blockHashes1 := [][]byte{[]byte{1, 2, 3}} blockHashes1 := [][]byte{{1, 2, 3}}
syncPeerConfig1 := CreateTestSyncPeerConfig(client, blockHashes1) syncPeerConfig1 := CreateTestSyncPeerConfig(client, blockHashes1)
blockHashes2 := [][]byte{[]byte{1, 2, 4}} blockHashes2 := [][]byte{{1, 2, 4}}
syncPeerConfig2 := CreateTestSyncPeerConfig(client, blockHashes2) syncPeerConfig2 := CreateTestSyncPeerConfig(client, blockHashes2)
// syncPeerConfig1 is less than syncPeerConfig2 // syncPeerConfig1 is less than syncPeerConfig2

@ -79,8 +79,14 @@ func TestProcessMessageValidatorAnnounce(test *testing.T) {
test.Fatalf("Cannot craeate consensus: %v", err) test.Fatalf("Cannot craeate consensus: %v", err)
} }
blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0")
if err != nil {
test.Fatalf("Cannot decode blockByte: %v", err)
}
consensusLeader.block = blockBytes consensusLeader.block = blockBytes
hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053")
if err != nil {
test.Fatalf("Cannot decode hashByte: %v", err)
}
copy(consensusLeader.blockHash[:], hashBytes[:]) copy(consensusLeader.blockHash[:], hashBytes[:])
@ -140,8 +146,14 @@ func TestProcessMessageValidatorPrepared(test *testing.T) {
test.Fatalf("Cannot craeate consensus: %v", err) test.Fatalf("Cannot craeate consensus: %v", err)
} }
blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0")
if err != nil {
test.Fatalf("Cannot decode blockByte: %v", err)
}
consensusLeader.block = blockBytes consensusLeader.block = blockBytes
hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053")
if err != nil {
test.Fatalf("Cannot decode hashByte: %v", err)
}
copy(consensusLeader.blockHash[:], hashBytes[:]) copy(consensusLeader.blockHash[:], hashBytes[:])
@ -216,8 +228,14 @@ func TestProcessMessageValidatorCommitted(test *testing.T) {
test.Fatalf("Cannot craeate consensus: %v", err) test.Fatalf("Cannot craeate consensus: %v", err)
} }
blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0")
if err != nil {
test.Fatalf("Cannot decode blockByte: %v", err)
}
consensusLeader.block = blockBytes consensusLeader.block = blockBytes
hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053")
if err != nil {
test.Fatalf("Cannot decode hashByte: %v", err)
}
copy(consensusLeader.blockHash[:], hashBytes[:]) copy(consensusLeader.blockHash[:], hashBytes[:])

@ -121,10 +121,7 @@ func (journal *txJournal) insert(tx *types.Transaction) error {
if journal.writer == nil { if journal.writer == nil {
return errNoActiveJournal return errNoActiveJournal
} }
if err := rlp.Encode(journal.writer, tx); err != nil { return rlp.Encode(journal.writer, tx)
return err
}
return nil
} }
// rotate regenerates the transaction journal based on the current contents of // rotate regenerates the transaction journal based on the current contents of

@ -9,84 +9,84 @@ import (
func TestReadWalletProfile(t *testing.T) { func TestReadWalletProfile(t *testing.T) {
config := []*WalletProfile{ config := []*WalletProfile{
&WalletProfile{ {
Profile: "default", Profile: "default",
Bootnodes: []string{"127.0.0.1:9000/abcd", "127.0.0.1:9999/daeg"}, Bootnodes: []string{"127.0.0.1:9000/abcd", "127.0.0.1:9999/daeg"},
Shards: 4, Shards: 4,
RPCServer: [][]p2p.Peer{ RPCServer: [][]p2p.Peer{
[]p2p.Peer{ {
p2p.Peer{ {
IP: "127.0.0.4", IP: "127.0.0.4",
Port: "8888", Port: "8888",
}, },
p2p.Peer{ {
IP: "192.168.0.4", IP: "192.168.0.4",
Port: "9876", Port: "9876",
}, },
}, },
[]p2p.Peer{ {
p2p.Peer{ {
IP: "127.0.0.1", IP: "127.0.0.1",
Port: "8888", Port: "8888",
}, },
p2p.Peer{ {
IP: "192.168.0.1", IP: "192.168.0.1",
Port: "9876", Port: "9876",
}, },
}, },
[]p2p.Peer{ {
p2p.Peer{ {
IP: "127.0.0.2", IP: "127.0.0.2",
Port: "8888", Port: "8888",
}, },
p2p.Peer{ {
IP: "192.168.0.2", IP: "192.168.0.2",
Port: "9876", Port: "9876",
}, },
}, },
[]p2p.Peer{ {
p2p.Peer{ {
IP: "127.0.0.3", IP: "127.0.0.3",
Port: "8888", Port: "8888",
}, },
p2p.Peer{ {
IP: "192.168.0.3", IP: "192.168.0.3",
Port: "9876", Port: "9876",
}, },
}, },
}, },
}, },
&WalletProfile{ {
Profile: "testnet", Profile: "testnet",
Bootnodes: []string{"192.168.0.1:9990/abcd", "127.0.0.1:8888/daeg"}, Bootnodes: []string{"192.168.0.1:9990/abcd", "127.0.0.1:8888/daeg"},
Shards: 3, Shards: 3,
RPCServer: [][]p2p.Peer{ RPCServer: [][]p2p.Peer{
[]p2p.Peer{ {
p2p.Peer{ {
IP: "192.168.2.3", IP: "192.168.2.3",
Port: "8888", Port: "8888",
}, },
p2p.Peer{ {
IP: "192.168.192.3", IP: "192.168.192.3",
Port: "9877", Port: "9877",
}, },
}, },
[]p2p.Peer{ {
p2p.Peer{ {
IP: "192.168.2.1", IP: "192.168.2.1",
Port: "8888", Port: "8888",
}, },
p2p.Peer{ {
IP: "192.168.192.1", IP: "192.168.192.1",
Port: "9877", Port: "9877",
}, },
}, },
[]p2p.Peer{ {
p2p.Peer{ {
IP: "192.168.2.2", IP: "192.168.2.2",
Port: "8888", Port: "8888",
}, },
p2p.Peer{ {
IP: "192.168.192.2", IP: "192.168.192.2",
Port: "9877", Port: "9877",
}, },

@ -179,17 +179,17 @@ func TestStringsToPeers(t *testing.T) {
{ {
"127.0.0.1:9000,192.168.192.1:8888,54.32.12.3:9898", "127.0.0.1:9000,192.168.192.1:8888,54.32.12.3:9898",
[]p2p.Peer{ []p2p.Peer{
p2p.Peer{IP: "127.0.0.1", Port: "9000"}, {IP: "127.0.0.1", Port: "9000"},
p2p.Peer{IP: "192.168.192.1", Port: "8888"}, {IP: "192.168.192.1", Port: "8888"},
p2p.Peer{IP: "54.32.12.3", Port: "9898"}, {IP: "54.32.12.3", Port: "9898"},
}, },
}, },
{ {
"a:b,xx:XX,hello:world", "a:b,xx:XX,hello:world",
[]p2p.Peer{ []p2p.Peer{
p2p.Peer{IP: "a", Port: "b"}, {IP: "a", Port: "b"},
p2p.Peer{IP: "xx", Port: "XX"}, {IP: "xx", Port: "XX"},
p2p.Peer{IP: "hello", Port: "world"}, {IP: "hello", Port: "world"},
}, },
}, },
} }

@ -48,7 +48,7 @@ func (node *Node) generateDeployedStakingContractAddress(contractAddress common.
//Correct Way 1: //Correct Way 1:
//node.SendTx(mycontracttx) //node.SendTx(mycontracttx)
//receipts := node.worker.GetCurrentReceipts() //receipts := node.worker.GetCurrentReceipts()
//deployedcontractaddress = recepits[len(receipts)-1].ContractAddress //get the address from the receipt //deployedcontractaddress = receipts[len(receipts)-1].ContractAddress //get the address from the receipt
//Correct Way 2: //Correct Way 2:
//nonce := GetNonce(contractAddress) //nonce := GetNonce(contractAddress)
@ -75,6 +75,11 @@ func (node *Node) QueryStakeInfo() *structs.StakeInfoReturnValue {
state, err := node.blockchain.State() state, err := node.blockchain.State()
if err != nil {
utils.GetLogInstance().Error("Failed to get blockchain state", "error", err)
return nil
}
stakingContractAddress := crypto.CreateAddress(deployerAddress, uint64(0)) stakingContractAddress := crypto.CreateAddress(deployerAddress, uint64(0))
tx := types.NewTransaction( tx := types.NewTransaction(
state.GetNonce(deployerAddress), state.GetNonce(deployerAddress),

@ -130,6 +130,10 @@ func (node *Node) GetResult(priKey string) (players []string, balances []*big.In
demoContractAddress := node.DemoContractAddress demoContractAddress := node.DemoContractAddress
key, err := crypto.HexToECDSA(priKey) key, err := crypto.HexToECDSA(priKey)
if err != nil {
utils.GetLogInstance().Error("Failed to parse private key", "error", err)
}
nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(key.PublicKey)) nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(key.PublicKey))
tx := types.NewTransaction( tx := types.NewTransaction(

@ -63,7 +63,7 @@ func (node *Node) GenesisBlockSetup(db ethdb.Database, shardID uint32, isArchiva
} }
// CreateGenesisAllocWithTestingAddresses create the genesis block allocation that contains deterministically // CreateGenesisAllocWithTestingAddresses create the genesis block allocation that contains deterministically
// generated testing addressess with tokens. This is mostly used for generated simulated transactions in txgen. // generated testing addresses with tokens. This is mostly used for generated simulated transactions in txgen.
// TODO: Remove it later when moving to production. // TODO: Remove it later when moving to production.
func (node *Node) CreateGenesisAllocWithTestingAddresses(numAddress int) core.GenesisAlloc { func (node *Node) CreateGenesisAllocWithTestingAddresses(numAddress int) core.GenesisAlloc {
rand.Seed(0) rand.Seed(0)

@ -58,7 +58,7 @@ func (node *Node) WaitForConsensusReady(readySignal chan struct{}, stopChan chan
node.Worker.CommitTransactions(selectedTxs) node.Worker.CommitTransactions(selectedTxs)
block, err := node.Worker.Commit() block, err := node.Worker.Commit()
if err != nil { if err != nil {
utils.GetLogInstance().Debug("Failed commiting new block", "Error", err) utils.GetLogInstance().Debug("Failed committing new block", "Error", err)
} else { } else {
if node.Consensus.ShardID == 0 { if node.Consensus.ShardID == 0 {
// add new shard state if it's epoch block // add new shard state if it's epoch block

@ -118,7 +118,7 @@ func (node *Node) InitSyncingServer() {
// StartSyncingServer starts syncing server. // StartSyncingServer starts syncing server.
func (node *Node) StartSyncingServer() { func (node *Node) StartSyncingServer() {
utils.GetLogInstance().Info("support_sycning: StartSyncingServer") utils.GetLogInstance().Info("support_syncing: StartSyncingServer")
if node.downloaderServer.GrpcServer == nil { if node.downloaderServer.GrpcServer == nil {
node.downloaderServer.Start(node.SelfPeer.IP, syncing.GetSyncingPort(node.SelfPeer.Port)) node.downloaderServer.Start(node.SelfPeer.IP, syncing.GetSyncingPort(node.SelfPeer.Port))
} }

@ -79,12 +79,12 @@ func TestAddPeers(t *testing.T) {
pubKey2 := pki.GetBLSPrivateKeyFromInt(444).GetPublicKey() pubKey2 := pki.GetBLSPrivateKeyFromInt(444).GetPublicKey()
peers1 := []*p2p.Peer{ peers1 := []*p2p.Peer{
&p2p.Peer{ {
IP: "127.0.0.1", IP: "127.0.0.1",
Port: "8888", Port: "8888",
ConsensusPubKey: pubKey1, ConsensusPubKey: pubKey1,
}, },
&p2p.Peer{ {
IP: "127.0.0.1", IP: "127.0.0.1",
Port: "9999", Port: "9999",
ConsensusPubKey: pubKey2, ConsensusPubKey: pubKey2,
@ -123,13 +123,13 @@ func TestAddBeaconPeer(t *testing.T) {
pubKey2 := bls2.RandPrivateKey().GetPublicKey() pubKey2 := bls2.RandPrivateKey().GetPublicKey()
peers1 := []*p2p.Peer{ peers1 := []*p2p.Peer{
&p2p.Peer{ {
IP: "127.0.0.1", IP: "127.0.0.1",
Port: "8888", Port: "8888",
ConsensusPubKey: pubKey1, ConsensusPubKey: pubKey1,
PeerID: "1234", PeerID: "1234",
}, },
&p2p.Peer{ {
IP: "127.0.0.1", IP: "127.0.0.1",
Port: "9999", Port: "9999",
ConsensusPubKey: pubKey2, ConsensusPubKey: pubKey2,

@ -136,12 +136,17 @@ func main() {
} }
if err != nil { if err != nil {
fmt.Printf("pubsub error: %v", err) fmt.Printf("pub error: %v", err)
panic(err) panic(err)
} }
sub, err := ps.Subscribe("pubsubtestchannel") sub, err := ps.Subscribe("pubsubtestchannel")
if err != nil {
fmt.Printf("sub error: %v", err)
panic(err)
}
go writePubsub(ps) go writePubsub(ps)
go readPubsub(sub) go readPubsub(sub)

Loading…
Cancel
Save