Skip to content

Commit

Permalink
Merge pull request #139 from getamis/feature/gossip_enable
Browse files Browse the repository at this point in the history
consensus: enable gossip network
  • Loading branch information
markya0616 committed Aug 7, 2017
2 parents f6857a3 + 2e6316c commit 164faea
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 76 deletions.
3 changes: 0 additions & 3 deletions consensus/istanbul/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ type Backend interface {
// the given validator
CheckSignature(data []byte, addr common.Address, sig []byte) error

// GetProposer returns the proposer of the given block height
GetProposer(number uint64) common.Address

// LastProposal retrieves latest committed proposal and the address of proposer
LastProposal() (Proposal, common.Address)
}
65 changes: 0 additions & 65 deletions consensus/istanbul/backend/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/istanbul"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
lru "github.com/hashicorp/golang-lru"
)

Expand Down Expand Up @@ -74,64 +70,3 @@ func makeMsg(msgcode uint64, data interface{}) p2p.Msg {
size, r, _ := rlp.EncodeToReader(data)
return p2p.Msg{Code: msgcode, Size: uint32(size), Payload: r}
}

type MockIstanbulEngine struct{}

func (m *MockIstanbulEngine) Author(header *types.Header) (common.Address, error) {
return common.Address{}, nil
}

func (m *MockIstanbulEngine) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error {
return nil
}

func (m *MockIstanbulEngine) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) {
abort := make(chan struct{})
results := make(chan error, len(headers))
go func() {
for _ = range headers {
results <- nil
}
}()
return abort, results
}

func (m *MockIstanbulEngine) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
return nil
}

func (m *MockIstanbulEngine) VerifySeal(chain consensus.ChainReader, header *types.Header) error {
return nil
}

func (m *MockIstanbulEngine) Prepare(chain consensus.ChainReader, header *types.Header) error {
return nil
}

func (m *MockIstanbulEngine) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
return nil, nil
}

func (m *MockIstanbulEngine) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error) {
return nil, nil
}

func (m *MockIstanbulEngine) APIs(chain consensus.ChainReader) []rpc.API {
return []rpc.API{}
}

func (m *MockIstanbulEngine) HandleMsg(addr common.Address, data []byte) error {
return nil
}

func (m *MockIstanbulEngine) NewChainHead(block *types.Block) error {
return nil
}

func (m *MockIstanbulEngine) Start(chain consensus.ChainReader, inserter func(types.Blocks) (int, error)) error {
return nil
}

func (m *MockIstanbulEngine) Stop() error {
return nil
}
14 changes: 11 additions & 3 deletions consensus/istanbul/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,19 @@ func (c *core) handleEvents() {
c.storeRequestMsg(r)
}
case istanbul.MessageEvent:
c.handleMsg(ev.Payload)
if err := c.handleMsg(ev.Payload); err == nil {
c.backend.Gossip(c.valSet, ev.Payload)
}
case backlogEvent:
// No need to check signature for internal messages
c.handleCheckedMsg(ev.msg, ev.src)

if err := c.handleCheckedMsg(ev.msg, ev.src); err == nil {
p, err := ev.msg.Payload()
if err != nil {
c.logger.Warn("Get message payload failed", "err", err)
continue
}
c.backend.Gossip(c.valSet, p)
}
}
case _, ok := <-c.timeoutSub.Chan():
if !ok {
Expand Down
1 change: 0 additions & 1 deletion consensus/istanbul/core/preprepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (c *core) handlePreprepare(msg *message, src istanbul.Validator) error {
}

// Ensure we have the same view with the PRE-PREPARE message
// If it is old message, see if we need to broadcast COMMIT
if err := c.checkMessage(msgPreprepare, preprepare.View); err != nil {
return err
}
Expand Down
4 changes: 0 additions & 4 deletions consensus/istanbul/core/testbackend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ func (self *testSystemBackend) NewRequest(request istanbul.Proposal) {
})
}

func (self *testSystemBackend) GetProposer(number uint64) common.Address {
return common.Address{}
}

func (self *testSystemBackend) LastProposal() (istanbul.Proposal, common.Address) {
return makeBlock(1), common.Address{}
}
Expand Down

0 comments on commit 164faea

Please sign in to comment.