mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
fix skip snapshot block (#178)
This commit is contained in:
parent
e9a4601de4
commit
f98d513f88
3 changed files with 16 additions and 14 deletions
|
|
@ -20,7 +20,7 @@ type broadcastSyncInfoFn func(*types.SyncInfo)
|
|||
type chainHeightFn func() uint64
|
||||
|
||||
type Bfter struct {
|
||||
gapNumber uint64
|
||||
epoch uint64
|
||||
|
||||
blockChainReader consensus.ChainReader
|
||||
broadcastCh chan interface{}
|
||||
|
|
@ -59,8 +59,8 @@ func New(broadcasts BroadcastFns, blockChainReader *core.BlockChain, chainHeight
|
|||
}
|
||||
|
||||
// Create this function to avoid massive test change
|
||||
func (b *Bfter) InitGapNumber() {
|
||||
b.gapNumber = b.blockChainReader.Config().XDPoS.Gap
|
||||
func (b *Bfter) InitEpochNumber() {
|
||||
b.epoch = b.blockChainReader.Config().XDPoS.Epoch
|
||||
}
|
||||
|
||||
func (b *Bfter) SetConsensusFuns(engine consensus.Engine) {
|
||||
|
|
@ -113,7 +113,7 @@ func (b *Bfter) Timeout(peer string, timeout *types.Timeout) error {
|
|||
log.Debug("Receive Timeout", "timeout", timeout)
|
||||
|
||||
gapNum := timeout.GapNumber
|
||||
if dist := int64(gapNum) - int64(b.chainHeight()); dist < -int64(b.gapNumber)*2 || dist > int64(b.gapNumber)*2 { // times 2 is to avoid miscalculation on cross epoch case
|
||||
if dist := int64(gapNum) - int64(b.chainHeight()); dist < -int64(b.epoch)*2 || dist > int64(b.epoch)*2 { // times 2 is to avoid cross epoch case, ex: timeout block between 901 to 1799, gapnumber is 450
|
||||
log.Debug("Discarded propagated timeout, too far away", "peer", peer, "gapNumber", gapNum, "hash", timeout.Hash, "distance", dist)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ func makeVotes(n int) []types.Vote {
|
|||
var votes []types.Vote
|
||||
for i := 0; i < n; i++ {
|
||||
votes = append(votes, types.Vote{
|
||||
ProposedBlockInfo: &types.BlockInfo{Number: big.NewInt(1)},
|
||||
ProposedBlockInfo: &types.BlockInfo{Number: big.NewInt(1350)},
|
||||
Signature: []byte{byte(i)},
|
||||
GapNumber: 0,
|
||||
GapNumber: 450,
|
||||
})
|
||||
}
|
||||
return votes
|
||||
|
|
@ -44,12 +44,12 @@ func newTester() *bfterTester {
|
|||
blockChain := &core.BlockChain{}
|
||||
blockChain.SetConfig(params.TestXDPoSMockChainConfig)
|
||||
chainHeight := func() uint64 {
|
||||
return 1
|
||||
return 1351
|
||||
}
|
||||
|
||||
tester := &bfterTester{}
|
||||
tester.bfter = New(broadcasts, blockChain, chainHeight)
|
||||
tester.bfter.InitGapNumber()
|
||||
tester.bfter.InitEpochNumber()
|
||||
tester.bfter.SetConsensusFuns(testConsensus)
|
||||
tester.bfter.broadcastCh = make(chan interface{})
|
||||
tester.bfter.Start()
|
||||
|
|
@ -140,7 +140,7 @@ func TestBoardcastButNotProcessDisqualifiedVotes(t *testing.T) {
|
|||
atomic.AddUint32(&broadcastCounter, 1)
|
||||
}
|
||||
|
||||
vote := types.Vote{ProposedBlockInfo: &types.BlockInfo{Number: big.NewInt(1)}}
|
||||
vote := types.Vote{ProposedBlockInfo: &types.BlockInfo{Number: big.NewInt(1350)}}
|
||||
tester.bfter.Vote(peerID, &vote)
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
|
@ -194,7 +194,7 @@ func TestBoardcastButNotProcessDisqualifiedSyncInfo(t *testing.T) {
|
|||
atomic.AddUint32(&broadcastCounter, 1)
|
||||
}
|
||||
|
||||
syncInfo := types.SyncInfo{HighestQuorumCert: &types.QuorumCert{ProposedBlockInfo: &types.BlockInfo{Number: big.NewInt(1)}}}
|
||||
syncInfo := types.SyncInfo{HighestQuorumCert: &types.QuorumCert{ProposedBlockInfo: &types.BlockInfo{Number: big.NewInt(1350)}}}
|
||||
tester.bfter.SyncInfo(peerID, &syncInfo)
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
|
@ -281,7 +281,7 @@ func TestSyncInfoHandler(t *testing.T) {
|
|||
atomic.AddUint32(&broadcastCounter, 1)
|
||||
}
|
||||
|
||||
syncInfo := types.SyncInfo{HighestQuorumCert: &types.QuorumCert{ProposedBlockInfo: &types.BlockInfo{Number: big.NewInt(1)}}}
|
||||
syncInfo := types.SyncInfo{HighestQuorumCert: &types.QuorumCert{ProposedBlockInfo: &types.BlockInfo{Number: big.NewInt(1350)}}}
|
||||
tester.bfter.SyncInfo(peerID, &syncInfo)
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
|
@ -312,7 +312,7 @@ func TestTooFarVotes(t *testing.T) {
|
|||
atomic.AddUint32(&broadcastCounter, 1)
|
||||
}
|
||||
|
||||
tester.bfter.chainHeight = func() uint64 { return 100 }
|
||||
tester.bfter.chainHeight = func() uint64 { return 10000 }
|
||||
|
||||
votes := makeVotes(numberVotes)
|
||||
for _, vote := range votes {
|
||||
|
|
@ -349,7 +349,9 @@ func TestTooFarTimeout(t *testing.T) {
|
|||
atomic.AddUint32(&broadcastCounter, 1)
|
||||
}
|
||||
|
||||
timeoutMsg := &types.Timeout{GapNumber: 10000}
|
||||
tester.bfter.chainHeight = func() uint64 { return 2400 }
|
||||
|
||||
timeoutMsg := &types.Timeout{GapNumber: 450}
|
||||
|
||||
err := tester.bfter.Timeout(peerID, timeoutMsg)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne
|
|||
}
|
||||
manager.bft = bft.New(broadcasts, blockchain, heighter)
|
||||
if blockchain.Config().XDPoS != nil {
|
||||
manager.bft.InitGapNumber()
|
||||
manager.bft.InitEpochNumber()
|
||||
manager.bft.SetConsensusFuns(engine)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue