Merge branch 'master' of https://github.com/harmony-one/harmony into HAR-67_libp2p_integration_v2

pull/119/head
Richard Liu 6 years ago
commit bc76946bdb
  1. 5
      .travis.gofmt.sh
  2. 6
      .travis.yml
  3. 4
      consensus/consensus.go
  4. 1
      consensus/consensus_leader.go
  5. 3
      core/state_transition.go
  6. 1
      log/term/terminal_linux.go
  7. 14
      node/node_handler.go
  8. 4
      node/worker/worker.go
  9. 23
      p2p/ida/errors.go
  10. 37
      p2p/ida/ida.go
  11. 77
      p2p/ida/ida_test.go
  12. 25
      p2p/ida/interface.go
  13. 2
      syncing/syncing.go

@ -1,5 +1,10 @@
#!/bin/bash
if [ $(golint ./... | wc | awk '{print $1}') -gt 2 ]; then
echo "Go code is not formatted:"
gofmt -d .
exit 1
fi
if [ -n "$(gofmt -l .)" ]; then
echo "Go code is not formatted:"
gofmt -d .

@ -6,9 +6,13 @@ install:
- cd $HOME/gopath/src
- cd github.com/harmony-one/harmony
- go get -t -v ./...
- go get -u golang.org/x/lint/golint
- go get gopkg.in/check.v1
- ./.travis.gofmt.sh
- go build -v ./...
script:
- ./.travis.gofmt.sh
notifications:
slack: harmonyone:gggCd1QQopsQAW8JYgBWiH7M
slack:
harmonyone:gggCd1QQopsQAW8JYgBWiH7M
# secure: RPB3ThYIGuDUidvaWfOA7Hc9x1bDfd5+Y10r7xwY+NGCN3zW86s/GNLpLutI0MWTV9e2CJupHvz5clp8Ktle/tVjLhs6jHQnNV7U8PTWKkL5By6IFVAHN12unMQn/m0RPwqMfdubajXoV51XhbFA/iow/0fqwsd61VdPIuBrlQjy9z7kyVnRLNoGvYjDqKEkJfYVb3qFNFLzD0F7Y2AgxnezIRjsTLgHzR4owLJYqVMhvTYIV9/vSf1w4UUPzhHyZRESl6bri+a1+g7GxE32OtNwq68xxVeeJcrO/MbjAHHW9V6BW1MjJfYzD5T+7JHIfZOjV2WgzJ7uCkVYztfq+02yOCSWsLNxFVojIDhVFEhhJ6Vd2Zf1otolS7j0svK/qNmShID9q9NAasaI105GsQgtaSPAUGd88J/vyX2ndG1nDOvxmgOo10tZFOnPHW7JnWMybk3PLza8o1ujA7X3JFdvDA8BPP9h6MVP4N7doCQ/n4Crts53HvEWlvcv5sBNu61WYlSTBzf1qNwBKMyN2E0rNubsxKmW8B6jLdWYdlx57nyTRPraNKGE1fnUW5nWRZGax3F1tQRwEfpQMk22qgeUK0RYWsPgHFaPciKCA3dJX7t1k/ib9pyR4nc9SZnYw54KMhkAXPIVQ0iy0EpTAH1DNYV6v8zXCwjl+BdkhlY=

@ -299,6 +299,7 @@ func (consensus *Consensus) UpdatePublicKeys(pubKeys []kyber.Point) int {
return len(consensus.PublicKeys)
}
// NewFaker returns a faker consensus.
func NewFaker() *Consensus {
return &Consensus{}
}
@ -386,11 +387,14 @@ func (consensus *Consensus) SealHash(header *types.Header) (hash common.Hash) {
return hash
}
// Seal is to seal final block.
func (consensus *Consensus) Seal(chain ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
// TODO: implement final block sealing
return nil
}
// Prepare is to prepare ...
// TODO(RJ): fix it.
func (consensus *Consensus) Prepare(chain ChainReader, header *types.Header) error {
// TODO: implement prepare method
return nil

@ -74,7 +74,6 @@ func (consensus *Consensus) WaitForNewBlockAccount(blockChannel chan *types.Bloc
// time.Sleep(500 * time.Millisecond)
data, err := rlp.EncodeToBytes(newBlock)
if err == nil {
consensus.Log.Debug("Sample tx", "tx", newBlock.Transactions()[0])
consensus.ResetState()
consensus.startConsensus(&blockchain.Block{Hash: newBlock.Hash(), AccountBlock: data})
} else {

@ -18,7 +18,6 @@ package core
import (
"errors"
"fmt"
"math"
"math/big"
@ -170,10 +169,8 @@ func (st *StateTransition) preCheck() error {
if st.msg.CheckNonce() {
nonce := st.state.GetNonce(st.msg.From())
if nonce < st.msg.Nonce() {
fmt.Println(nonce, " vs ", st.msg.Nonce())
return ErrNonceTooHigh
} else if nonce > st.msg.Nonce() {
fmt.Println(nonce, " vs ", st.msg.Nonce())
return ErrNonceTooLow
}
}

@ -11,4 +11,5 @@ import "syscall"
const ioctlReadTermios = syscall.TCGETS
// Termios ...
type Termios syscall.Termios

@ -90,10 +90,10 @@ func (node *Node) NodeHandler(conn net.Conn) {
}
}
case proto.Consensus:
if !(node.State == NodeDoingConsensus || node.State == NodeLeader || node.State == NodeReadyForConsensus) {
node.log.Info("This node with ", "peer", node.SelfPeer, "can not join consensus because they are either not noding consensus or not a leader", nil)
break
}
// if !(node.State == NodeDoingConsensus || node.State == NodeLeader || node.State == NodeReadyForConsensus) {
// node.log.Info("This node with ", "peer", node.SelfPeer, "can not join consensus because they are either not noding consensus or not a leader", nil)
// break
// }
actionType := consensus.ConMessageType(msgType)
switch actionType {
case consensus.Consensus:
@ -208,9 +208,9 @@ func (node *Node) NodeHandler(conn net.Conn) {
}
// Post processing after receiving messsages.
if node.State == NodeJoinedShard || node.State == NodeReadyForConsensus {
go node.DoSyncing()
}
// if node.State == NodeJoinedShard || node.State == NodeReadyForConsensus {
// go node.DoSyncing()
// }
}
func (node *Node) transactionMessageHandler(msgPayload []byte) {

@ -1,10 +1,11 @@
package worker
import (
"github.com/harmony-one/harmony/log"
"math/big"
"time"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/consensus"
@ -38,6 +39,7 @@ type Worker struct {
gasCeil uint64
}
// SelectTransactionsForNewBlock selects transactions for new block.
func (w *Worker) SelectTransactionsForNewBlock(txs types.Transactions, maxNumTxs int) (types.Transactions, types.Transactions, types.Transactions) {
if w.current.gasPool == nil {
w.current.gasPool = new(core.GasPool).AddGas(w.current.header.GasLimit)

@ -1,23 +0,0 @@
// Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Package ida errors provides common error types used throughout leveldb.
package ida
import (
"errors"
)
// Common errors.
var (
ErrRaptorImpNotFound = New("raptor implementation: not found")
ErrTimeOut = New("timeout: time's up now")
)
// New returns an error that formats as the given text.
func New(text string) error {
return errors.New(text)
}

@ -1,37 +0,0 @@
package ida
import (
"time"
"github.com/harmony-one/harmony/p2p"
)
// IDAImp implements IDA interface.
type IDAImp struct {
raptorQImp RaptorQ
}
// TakeRaptorQ takes RaptorQ implementation.
func (ida *IDAImp) TakeRaptorQ(raptorQImp RaptorQ) {
ida.raptorQImp = raptorQImp
}
// Process implements very simple IDA logic.
func (ida *IDAImp) Process(msg Message, peers []p2p.Peer, done chan struct{}, timeout time.Duration) error {
if ida.raptorQImp == nil {
return ErrRaptorImpNotFound
}
chunkStream := ida.raptorQImp.Process(msg)
id := 0
for {
select {
case <-done:
return nil
case <-time.After(timeout):
return ErrTimeOut
case chunk := <-chunkStream:
p2p.SendMessage(peers[id], chunk)
id++
}
}
}

@ -1,77 +0,0 @@
package ida
import (
"math/rand"
"testing"
"time"
"github.com/harmony-one/harmony/p2p"
)
var (
a = Symbol{0, 0}
b = Symbol{1, 0}
c = Symbol{0, 1}
d = Symbol{1, 1}
)
type FakeRaptor struct {
symbols []Symbol
done chan struct{}
r *rand.Rand
}
func (raptor *FakeRaptor) Init() {
// raptor.symbols = make([]Symbol, 4)
raptor.symbols = make([]Symbol, 4)
raptor.symbols[0] = make(Symbol, 2)
copy(raptor.symbols[0], a)
raptor.symbols[1] = make(Symbol, 2)
copy(raptor.symbols[1], b)
raptor.symbols[2] = make(Symbol, 2)
copy(raptor.symbols[2], c)
raptor.symbols[3] = make(Symbol, 2)
copy(raptor.symbols[3], d)
raptor.r = rand.New(rand.NewSource(99))
raptor.done = make(chan struct{})
}
func (raptor *FakeRaptor) generate(res chan Symbol) {
for {
select {
case <-raptor.done:
return
default:
i := raptor.r.Intn(4)
res <- raptor.symbols[i]
}
}
}
func (raptor *FakeRaptor) Process(msg Message) chan Symbol {
res := make(chan Symbol)
go raptor.generate(res)
return res
}
func TestShouldReturnErrRaptorImpNotFound(t *testing.T) {
ida := &IDAImp{}
done := make(chan struct{})
err := ida.Process([]byte{}, []p2p.Peer{}, done, time.Second)
if err != ErrRaptorImpNotFound {
t.Fatal("Should return an error")
}
}
func TestSimple(t *testing.T) {
raptor := &FakeRaptor{}
raptor.Init()
// ida := &IDAImp{}
// done := make(chan struct{})
// ida.TakeRaptorQ(raptor)
// err := ida.Process([]byte{}, []p2p.Peer{}, done, time.Second)
// if err == ErrRaptorImpNotFound {
// t.Fatal("Should return an error")
// }
}

@ -1,25 +0,0 @@
package ida
import (
"time"
"github.com/harmony-one/harmony/p2p"
)
// Symbol is produced from a RaptorQ implementation.
type Symbol []byte
// Message is type of general message gopssiped
type Message []byte
// RaptorQ interface.
type RaptorQ interface {
Init()
Process(msg Message) chan Symbol
}
// IDA interface.
type IDA interface {
TakeRaptorQ(raptorQImp *RaptorQ)
Process(msg Message, peers []p2p.Peer, done chan struct{}, timeout time.Duration) error
}

@ -29,6 +29,7 @@ type SyncPeerConfig struct {
blockHashes [][]byte
}
// Log is the temporary log for syncing.
var Log = log.New()
// SyncBlockTask is the task struct to sync a specific block.
@ -264,6 +265,7 @@ func (ss *StateSync) generateStateSyncTaskQueue(bc *blockchain.Blockchain) {
for id, blockHash := range configPeer.blockHashes {
if bc.Blocks[id] == nil || !reflect.DeepEqual(bc.Blocks[id].Hash[:], blockHash) {
ss.stateSyncTaskQueue.Put(SyncBlockTask{index: id, blockHash: blockHash})
// TODO(minhdoan): Check error
}
}
break

Loading…
Cancel
Save