Skip to content

Commit 164faea

Browse files
authored
Merge pull request #139 from getamis/feature/gossip_enable
consensus: enable gossip network
2 parents f6857a3 + 2e6316c commit 164faea

File tree

5 files changed

+11
-76
lines changed

5 files changed

+11
-76
lines changed

consensus/istanbul/backend.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ type Backend interface {
5858
// the given validator
5959
CheckSignature(data []byte, addr common.Address, sig []byte) error
6060

61-
// GetProposer returns the proposer of the given block height
62-
GetProposer(number uint64) common.Address
63-
6461
// LastProposal retrieves latest committed proposal and the address of proposer
6562
LastProposal() (Proposal, common.Address)
6663
}

consensus/istanbul/backend/handler_test.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ import (
2020
"testing"
2121

2222
"github.com/ethereum/go-ethereum/common"
23-
"github.com/ethereum/go-ethereum/consensus"
2423
"github.com/ethereum/go-ethereum/consensus/istanbul"
25-
"github.com/ethereum/go-ethereum/core/state"
26-
"github.com/ethereum/go-ethereum/core/types"
2724
"github.com/ethereum/go-ethereum/p2p"
2825
"github.com/ethereum/go-ethereum/rlp"
29-
"github.com/ethereum/go-ethereum/rpc"
3026
lru "github.com/hashicorp/golang-lru"
3127
)
3228

@@ -74,64 +70,3 @@ func makeMsg(msgcode uint64, data interface{}) p2p.Msg {
7470
size, r, _ := rlp.EncodeToReader(data)
7571
return p2p.Msg{Code: msgcode, Size: uint32(size), Payload: r}
7672
}
77-
78-
type MockIstanbulEngine struct{}
79-
80-
func (m *MockIstanbulEngine) Author(header *types.Header) (common.Address, error) {
81-
return common.Address{}, nil
82-
}
83-
84-
func (m *MockIstanbulEngine) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error {
85-
return nil
86-
}
87-
88-
func (m *MockIstanbulEngine) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) {
89-
abort := make(chan struct{})
90-
results := make(chan error, len(headers))
91-
go func() {
92-
for _ = range headers {
93-
results <- nil
94-
}
95-
}()
96-
return abort, results
97-
}
98-
99-
func (m *MockIstanbulEngine) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
100-
return nil
101-
}
102-
103-
func (m *MockIstanbulEngine) VerifySeal(chain consensus.ChainReader, header *types.Header) error {
104-
return nil
105-
}
106-
107-
func (m *MockIstanbulEngine) Prepare(chain consensus.ChainReader, header *types.Header) error {
108-
return nil
109-
}
110-
111-
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) {
112-
return nil, nil
113-
}
114-
115-
func (m *MockIstanbulEngine) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error) {
116-
return nil, nil
117-
}
118-
119-
func (m *MockIstanbulEngine) APIs(chain consensus.ChainReader) []rpc.API {
120-
return []rpc.API{}
121-
}
122-
123-
func (m *MockIstanbulEngine) HandleMsg(addr common.Address, data []byte) error {
124-
return nil
125-
}
126-
127-
func (m *MockIstanbulEngine) NewChainHead(block *types.Block) error {
128-
return nil
129-
}
130-
131-
func (m *MockIstanbulEngine) Start(chain consensus.ChainReader, inserter func(types.Blocks) (int, error)) error {
132-
return nil
133-
}
134-
135-
func (m *MockIstanbulEngine) Stop() error {
136-
return nil
137-
}

consensus/istanbul/core/handler.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,19 @@ func (c *core) handleEvents() {
9595
c.storeRequestMsg(r)
9696
}
9797
case istanbul.MessageEvent:
98-
c.handleMsg(ev.Payload)
98+
if err := c.handleMsg(ev.Payload); err == nil {
99+
c.backend.Gossip(c.valSet, ev.Payload)
100+
}
99101
case backlogEvent:
100102
// No need to check signature for internal messages
101-
c.handleCheckedMsg(ev.msg, ev.src)
102-
103+
if err := c.handleCheckedMsg(ev.msg, ev.src); err == nil {
104+
p, err := ev.msg.Payload()
105+
if err != nil {
106+
c.logger.Warn("Get message payload failed", "err", err)
107+
continue
108+
}
109+
c.backend.Gossip(c.valSet, p)
110+
}
103111
}
104112
case _, ok := <-c.timeoutSub.Chan():
105113
if !ok {

consensus/istanbul/core/preprepare.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ func (c *core) handlePreprepare(msg *message, src istanbul.Validator) error {
5656
}
5757

5858
// Ensure we have the same view with the PRE-PREPARE message
59-
// If it is old message, see if we need to broadcast COMMIT
6059
if err := c.checkMessage(msgPreprepare, preprepare.View); err != nil {
6160
return err
6261
}

consensus/istanbul/core/testbackend_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ func (self *testSystemBackend) NewRequest(request istanbul.Proposal) {
138138
})
139139
}
140140

141-
func (self *testSystemBackend) GetProposer(number uint64) common.Address {
142-
return common.Address{}
143-
}
144-
145141
func (self *testSystemBackend) LastProposal() (istanbul.Proposal, common.Address) {
146142
return makeBlock(1), common.Address{}
147143
}

0 commit comments

Comments
 (0)