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. 8
      .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 #!/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 if [ -n "$(gofmt -l .)" ]; then
echo "Go code is not formatted:" echo "Go code is not formatted:"
gofmt -d . gofmt -d .

@ -1,14 +1,18 @@
language: go language: go
go: go:
- master - master
install: install:
- export GOPATH=$HOME/gopath - export GOPATH=$HOME/gopath
- cd $HOME/gopath/src - cd $HOME/gopath/src
- cd github.com/harmony-one/harmony - cd github.com/harmony-one/harmony
- go get -t -v ./... - go get -t -v ./...
- go get -u golang.org/x/lint/golint
- go get gopkg.in/check.v1 - go get gopkg.in/check.v1
- ./.travis.gofmt.sh - ./.travis.gofmt.sh
- go build -v ./... - go build -v ./...
script:
- ./.travis.gofmt.sh
notifications: notifications:
slack: harmonyone:gggCd1QQopsQAW8JYgBWiH7M slack:
harmonyone:gggCd1QQopsQAW8JYgBWiH7M
# secure: RPB3ThYIGuDUidvaWfOA7Hc9x1bDfd5+Y10r7xwY+NGCN3zW86s/GNLpLutI0MWTV9e2CJupHvz5clp8Ktle/tVjLhs6jHQnNV7U8PTWKkL5By6IFVAHN12unMQn/m0RPwqMfdubajXoV51XhbFA/iow/0fqwsd61VdPIuBrlQjy9z7kyVnRLNoGvYjDqKEkJfYVb3qFNFLzD0F7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sPgHFaPciKCA3dJX7t1k/ib9pyR4nc9SZnYw54KMhkAXPIVQ0iy0EpTAH1DNYV6v8zXCwjl+BdkhlY=

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

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

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

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

@ -90,10 +90,10 @@ func (node *Node) NodeHandler(conn net.Conn) {
} }
} }
case proto.Consensus: case proto.Consensus:
if !(node.State == NodeDoingConsensus || node.State == NodeLeader || node.State == NodeReadyForConsensus) { // 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) // 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 // break
} // }
actionType := consensus.ConMessageType(msgType) actionType := consensus.ConMessageType(msgType)
switch actionType { switch actionType {
case consensus.Consensus: case consensus.Consensus:
@ -208,9 +208,9 @@ func (node *Node) NodeHandler(conn net.Conn) {
} }
// Post processing after receiving messsages. // Post processing after receiving messsages.
if node.State == NodeJoinedShard || node.State == NodeReadyForConsensus { // if node.State == NodeJoinedShard || node.State == NodeReadyForConsensus {
go node.DoSyncing() // go node.DoSyncing()
} // }
} }
func (node *Node) transactionMessageHandler(msgPayload []byte) { func (node *Node) transactionMessageHandler(msgPayload []byte) {

@ -1,10 +1,11 @@
package worker package worker
import ( import (
"github.com/harmony-one/harmony/log"
"math/big" "math/big"
"time" "time"
"github.com/harmony-one/harmony/log"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/harmony-one/harmony/consensus" "github.com/harmony-one/harmony/consensus"
@ -38,6 +39,7 @@ type Worker struct {
gasCeil uint64 gasCeil uint64
} }
// SelectTransactionsForNewBlock selects transactions for new block.
func (w *Worker) SelectTransactionsForNewBlock(txs types.Transactions, maxNumTxs int) (types.Transactions, types.Transactions, types.Transactions) { func (w *Worker) SelectTransactionsForNewBlock(txs types.Transactions, maxNumTxs int) (types.Transactions, types.Transactions, types.Transactions) {
if w.current.gasPool == nil { if w.current.gasPool == nil {
w.current.gasPool = new(core.GasPool).AddGas(w.current.header.GasLimit) 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 blockHashes [][]byte
} }
// Log is the temporary log for syncing.
var Log = log.New() var Log = log.New()
// SyncBlockTask is the task struct to sync a specific block. // 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 { for id, blockHash := range configPeer.blockHashes {
if bc.Blocks[id] == nil || !reflect.DeepEqual(bc.Blocks[id].Hash[:], blockHash) { if bc.Blocks[id] == nil || !reflect.DeepEqual(bc.Blocks[id].Hash[:], blockHash) {
ss.stateSyncTaskQueue.Put(SyncBlockTask{index: id, blockHash: blockHash}) ss.stateSyncTaskQueue.Put(SyncBlockTask{index: id, blockHash: blockHash})
// TODO(minhdoan): Check error
} }
} }
break break

Loading…
Cancel
Save