提交 1fa844aa 编写于 作者: J Jeffrey Wilcke

Merge pull request #702 from ethersphere/frontier/blockpool

blockpool stability fixes:
此差异已折叠。
...@@ -3,19 +3,12 @@ package blockpool ...@@ -3,19 +3,12 @@ package blockpool
import ( import (
"testing" "testing"
"time" "time"
"github.com/ethereum/go-ethereum/blockpool/test"
) )
func init() {
test.LogInit()
}
// using the mock framework in blockpool_util_test // using the mock framework in blockpool_util_test
// we test various scenarios here // we test various scenarios here
func TestPeerWithKnownBlock(t *testing.T) { func TestPeerWithKnownBlock(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.refBlockChain[0] = nil blockPoolTester.refBlockChain[0] = nil
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
...@@ -31,7 +24,6 @@ func TestPeerWithKnownBlock(t *testing.T) { ...@@ -31,7 +24,6 @@ func TestPeerWithKnownBlock(t *testing.T) {
} }
func TestPeerWithKnownParentBlock(t *testing.T) { func TestPeerWithKnownParentBlock(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.initRefBlockChain(1) blockPoolTester.initRefBlockChain(1)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
...@@ -50,7 +42,6 @@ func TestPeerWithKnownParentBlock(t *testing.T) { ...@@ -50,7 +42,6 @@ func TestPeerWithKnownParentBlock(t *testing.T) {
} }
func TestSimpleChain(t *testing.T) { func TestSimpleChain(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(2) blockPoolTester.initRefBlockChain(2)
...@@ -70,7 +61,6 @@ func TestSimpleChain(t *testing.T) { ...@@ -70,7 +61,6 @@ func TestSimpleChain(t *testing.T) {
} }
func TestChainConnectingWithParentHash(t *testing.T) { func TestChainConnectingWithParentHash(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(3) blockPoolTester.initRefBlockChain(3)
...@@ -90,7 +80,6 @@ func TestChainConnectingWithParentHash(t *testing.T) { ...@@ -90,7 +80,6 @@ func TestChainConnectingWithParentHash(t *testing.T) {
} }
func TestMultiSectionChain(t *testing.T) { func TestMultiSectionChain(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(5) blockPoolTester.initRefBlockChain(5)
...@@ -113,7 +102,6 @@ func TestMultiSectionChain(t *testing.T) { ...@@ -113,7 +102,6 @@ func TestMultiSectionChain(t *testing.T) {
} }
func TestNewBlocksOnPartialChain(t *testing.T) { func TestNewBlocksOnPartialChain(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(7) blockPoolTester.initRefBlockChain(7)
...@@ -146,7 +134,6 @@ func TestNewBlocksOnPartialChain(t *testing.T) { ...@@ -146,7 +134,6 @@ func TestNewBlocksOnPartialChain(t *testing.T) {
} }
func TestPeerSwitchUp(t *testing.T) { func TestPeerSwitchUp(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(7) blockPoolTester.initRefBlockChain(7)
...@@ -174,7 +161,6 @@ func TestPeerSwitchUp(t *testing.T) { ...@@ -174,7 +161,6 @@ func TestPeerSwitchUp(t *testing.T) {
} }
func TestPeerSwitchDownOverlapSectionWithoutRootBlock(t *testing.T) { func TestPeerSwitchDownOverlapSectionWithoutRootBlock(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(6) blockPoolTester.initRefBlockChain(6)
...@@ -200,7 +186,6 @@ func TestPeerSwitchDownOverlapSectionWithoutRootBlock(t *testing.T) { ...@@ -200,7 +186,6 @@ func TestPeerSwitchDownOverlapSectionWithoutRootBlock(t *testing.T) {
} }
func TestPeerSwitchDownOverlapSectionWithRootBlock(t *testing.T) { func TestPeerSwitchDownOverlapSectionWithRootBlock(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(6) blockPoolTester.initRefBlockChain(6)
...@@ -227,7 +212,6 @@ func TestPeerSwitchDownOverlapSectionWithRootBlock(t *testing.T) { ...@@ -227,7 +212,6 @@ func TestPeerSwitchDownOverlapSectionWithRootBlock(t *testing.T) {
} }
func TestPeerSwitchDownDisjointSection(t *testing.T) { func TestPeerSwitchDownDisjointSection(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(3) blockPoolTester.initRefBlockChain(3)
...@@ -254,7 +238,6 @@ func TestPeerSwitchDownDisjointSection(t *testing.T) { ...@@ -254,7 +238,6 @@ func TestPeerSwitchDownDisjointSection(t *testing.T) {
} }
func TestPeerSwitchBack(t *testing.T) { func TestPeerSwitchBack(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(8) blockPoolTester.initRefBlockChain(8)
...@@ -270,7 +253,7 @@ func TestPeerSwitchBack(t *testing.T) { ...@@ -270,7 +253,7 @@ func TestPeerSwitchBack(t *testing.T) {
go peer2.serveBlockHashes(6, 5, 4) go peer2.serveBlockHashes(6, 5, 4)
peer2.serveBlocks(4, 5) // section partially complete peer2.serveBlocks(4, 5) // section partially complete
peer1.AddPeer() // peer1 is promoted as best peer peer1.AddPeer() // peer1 is promoted as best peer
go peer1.serveBlocks(10, 11) // peer1.serveBlocks(10, 11) //
peer1.serveBlockHashes(11, 10) // only gives useless results peer1.serveBlockHashes(11, 10) // only gives useless results
blockPool.RemovePeer("peer1") // peer1 disconnects blockPool.RemovePeer("peer1") // peer1 disconnects
go peer2.serveBlockHashes(4, 3, 2, 1, 0) // tests that asking for hashes from 4 is remembered go peer2.serveBlockHashes(4, 3, 2, 1, 0) // tests that asking for hashes from 4 is remembered
...@@ -284,7 +267,6 @@ func TestPeerSwitchBack(t *testing.T) { ...@@ -284,7 +267,6 @@ func TestPeerSwitchBack(t *testing.T) {
} }
func TestForkSimple(t *testing.T) { func TestForkSimple(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(9) blockPoolTester.initRefBlockChain(9)
...@@ -320,7 +302,6 @@ func TestForkSimple(t *testing.T) { ...@@ -320,7 +302,6 @@ func TestForkSimple(t *testing.T) {
} }
func TestForkSwitchBackByNewBlocks(t *testing.T) { func TestForkSwitchBackByNewBlocks(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(11) blockPoolTester.initRefBlockChain(11)
...@@ -351,8 +332,8 @@ func TestForkSwitchBackByNewBlocks(t *testing.T) { ...@@ -351,8 +332,8 @@ func TestForkSwitchBackByNewBlocks(t *testing.T) {
go peer1.serveBlockHashes(11, 10, 9) go peer1.serveBlockHashes(11, 10, 9)
go peer1.serveBlocks(9, 10) go peer1.serveBlocks(9, 10)
// time.Sleep(1 * time.Second) // time.Sleep(1 * time.Second)
go peer1.serveBlocks(3, 7) // tests that block requests on earlier fork are remembered go peer1.serveBlocks(3, 7) // tests that block requests on earlier fork are remembered
go peer1.serveBlockHashes(2, 1) // tests that hash request from root of connecting chain section (added by demoted peer) is remembered go peer1.serveBlockHashes(2, 1, 0) // tests that hash request from root of connecting chain section (added by demoted peer) is remembered
peer1.serveBlocks(0, 1) peer1.serveBlocks(0, 1)
blockPool.Wait(waitTimeout) blockPool.Wait(waitTimeout)
...@@ -367,7 +348,6 @@ func TestForkSwitchBackByNewBlocks(t *testing.T) { ...@@ -367,7 +348,6 @@ func TestForkSwitchBackByNewBlocks(t *testing.T) {
} }
func TestForkSwitchBackByPeerSwitchBack(t *testing.T) { func TestForkSwitchBackByPeerSwitchBack(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(9) blockPoolTester.initRefBlockChain(9)
...@@ -411,7 +391,6 @@ func TestForkSwitchBackByPeerSwitchBack(t *testing.T) { ...@@ -411,7 +391,6 @@ func TestForkSwitchBackByPeerSwitchBack(t *testing.T) {
} }
func TestForkCompleteSectionSwitchBackByPeerSwitchBack(t *testing.T) { func TestForkCompleteSectionSwitchBackByPeerSwitchBack(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(9) blockPoolTester.initRefBlockChain(9)
...@@ -429,16 +408,17 @@ func TestForkCompleteSectionSwitchBackByPeerSwitchBack(t *testing.T) { ...@@ -429,16 +408,17 @@ func TestForkCompleteSectionSwitchBackByPeerSwitchBack(t *testing.T) {
peer1.AddPeer() peer1.AddPeer()
go peer1.serveBlocks(8, 9) go peer1.serveBlocks(8, 9)
go peer1.serveBlockHashes(9, 8, 7) go peer1.serveBlockHashes(9, 8, 7)
peer1.serveBlocks(3, 7, 8) // make sure this section is complete peer1.serveBlocks(3, 7, 8) // make sure this section is complete
time.Sleep(1 * time.Second) // // time.Sleep(2 * time.Second) //
go peer1.serveBlockHashes(7, 3, 2) // block 3/7 is section boundary peer1.serveBlockHashes(7, 3, 2) // block 3/7 is section boundary
peer1.serveBlocks(2, 3) // partially complete sections block 2 missing peer1.serveBlocks(2, 3) // partially complete sections block 2 missing
peer2.AddPeer() // peer2.AddPeer() //
go peer2.serveBlocks(5, 6) // go peer2.serveBlocks(5, 6) //
go peer2.serveBlockHashes(6, 5, 4, 3, 2) // peer2 forks on block 3 go peer2.serveBlockHashes(6, 5, 4, 3, 2) // peer2 forks on block 3
time.Sleep(100 * time.Millisecond) //
peer2.serveBlocks(2, 3, 4, 5) // block 2 still missing. peer2.serveBlocks(2, 3, 4, 5) // block 2 still missing.
blockPool.RemovePeer("peer2") // peer2 disconnects, peer1 is promoted again as best peer blockPool.RemovePeer("peer2") // peer2 disconnects, peer1 is promoted again as best peer
go peer1.serveBlockHashes(2, 1, 0) // go peer1.serveBlockHashes(2, 1) //
peer1.serveBlocks(0, 1, 2) peer1.serveBlocks(0, 1, 2)
blockPool.Wait(waitTimeout) blockPool.Wait(waitTimeout)
......
...@@ -17,6 +17,7 @@ func TestBlockPoolConfig(t *testing.T) { ...@@ -17,6 +17,7 @@ func TestBlockPoolConfig(t *testing.T) {
test.CheckInt("BlockBatchSize", c.BlockBatchSize, blockBatchSize, t) test.CheckInt("BlockBatchSize", c.BlockBatchSize, blockBatchSize, t)
test.CheckInt("BlocksRequestRepetition", c.BlocksRequestRepetition, blocksRequestRepetition, t) test.CheckInt("BlocksRequestRepetition", c.BlocksRequestRepetition, blocksRequestRepetition, t)
test.CheckInt("BlocksRequestMaxIdleRounds", c.BlocksRequestMaxIdleRounds, blocksRequestMaxIdleRounds, t) test.CheckInt("BlocksRequestMaxIdleRounds", c.BlocksRequestMaxIdleRounds, blocksRequestMaxIdleRounds, t)
test.CheckInt("NodeCacheSize", c.NodeCacheSize, nodeCacheSize, t)
test.CheckDuration("BlockHashesRequestInterval", c.BlockHashesRequestInterval, blockHashesRequestInterval, t) test.CheckDuration("BlockHashesRequestInterval", c.BlockHashesRequestInterval, blockHashesRequestInterval, t)
test.CheckDuration("BlocksRequestInterval", c.BlocksRequestInterval, blocksRequestInterval, t) test.CheckDuration("BlocksRequestInterval", c.BlocksRequestInterval, blocksRequestInterval, t)
test.CheckDuration("BlockHashesTimeout", c.BlockHashesTimeout, blockHashesTimeout, t) test.CheckDuration("BlockHashesTimeout", c.BlockHashesTimeout, blockHashesTimeout, t)
...@@ -29,7 +30,7 @@ func TestBlockPoolConfig(t *testing.T) { ...@@ -29,7 +30,7 @@ func TestBlockPoolConfig(t *testing.T) {
func TestBlockPoolOverrideConfig(t *testing.T) { func TestBlockPoolOverrideConfig(t *testing.T) {
test.LogInit() test.LogInit()
blockPool := &BlockPool{Config: &Config{}, chainEvents: &event.TypeMux{}} blockPool := &BlockPool{Config: &Config{}, chainEvents: &event.TypeMux{}}
c := &Config{128, 32, 1, 0, 300 * time.Millisecond, 100 * time.Millisecond, 90 * time.Second, 0, 30 * time.Second, 30 * time.Second, 4 * time.Second} c := &Config{128, 32, 1, 0, 500, 300 * time.Millisecond, 100 * time.Millisecond, 90 * time.Second, 0, 30 * time.Second, 30 * time.Second, 4 * time.Second}
blockPool.Config = c blockPool.Config = c
blockPool.Start() blockPool.Start()
...@@ -37,6 +38,7 @@ func TestBlockPoolOverrideConfig(t *testing.T) { ...@@ -37,6 +38,7 @@ func TestBlockPoolOverrideConfig(t *testing.T) {
test.CheckInt("BlockBatchSize", c.BlockBatchSize, 32, t) test.CheckInt("BlockBatchSize", c.BlockBatchSize, 32, t)
test.CheckInt("BlocksRequestRepetition", c.BlocksRequestRepetition, blocksRequestRepetition, t) test.CheckInt("BlocksRequestRepetition", c.BlocksRequestRepetition, blocksRequestRepetition, t)
test.CheckInt("BlocksRequestMaxIdleRounds", c.BlocksRequestMaxIdleRounds, blocksRequestMaxIdleRounds, t) test.CheckInt("BlocksRequestMaxIdleRounds", c.BlocksRequestMaxIdleRounds, blocksRequestMaxIdleRounds, t)
test.CheckInt("NodeCacheSize", c.NodeCacheSize, 500, t)
test.CheckDuration("BlockHashesRequestInterval", c.BlockHashesRequestInterval, 300*time.Millisecond, t) test.CheckDuration("BlockHashesRequestInterval", c.BlockHashesRequestInterval, 300*time.Millisecond, t)
test.CheckDuration("BlocksRequestInterval", c.BlocksRequestInterval, 100*time.Millisecond, t) test.CheckDuration("BlocksRequestInterval", c.BlocksRequestInterval, 100*time.Millisecond, t)
test.CheckDuration("BlockHashesTimeout", c.BlockHashesTimeout, 90*time.Second, t) test.CheckDuration("BlockHashesTimeout", c.BlockHashesTimeout, 90*time.Second, t)
......
...@@ -4,14 +4,12 @@ import ( ...@@ -4,14 +4,12 @@ import (
"testing" "testing"
"time" "time"
"github.com/ethereum/go-ethereum/blockpool/test"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/pow" "github.com/ethereum/go-ethereum/pow"
) )
func TestInvalidBlock(t *testing.T) { func TestInvalidBlock(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(2) blockPoolTester.initRefBlockChain(2)
...@@ -41,7 +39,6 @@ func TestInvalidBlock(t *testing.T) { ...@@ -41,7 +39,6 @@ func TestInvalidBlock(t *testing.T) {
func TestVerifyPoW(t *testing.T) { func TestVerifyPoW(t *testing.T) {
t.Skip() // :FIXME: t.Skip() // :FIXME:
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(3) blockPoolTester.initRefBlockChain(3)
...@@ -88,7 +85,6 @@ func TestVerifyPoW(t *testing.T) { ...@@ -88,7 +85,6 @@ func TestVerifyPoW(t *testing.T) {
func TestUnrequestedBlock(t *testing.T) { func TestUnrequestedBlock(t *testing.T) {
t.Skip() // :FIXME: t.Skip() // :FIXME:
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPool.Start() blockPool.Start()
...@@ -108,7 +104,6 @@ func TestUnrequestedBlock(t *testing.T) { ...@@ -108,7 +104,6 @@ func TestUnrequestedBlock(t *testing.T) {
} }
func TestErrInsufficientChainInfo(t *testing.T) { func TestErrInsufficientChainInfo(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPool.Config.BlockHashesTimeout = 100 * time.Millisecond blockPool.Config.BlockHashesTimeout = 100 * time.Millisecond
blockPool.Start() blockPool.Start()
...@@ -128,8 +123,6 @@ func TestErrInsufficientChainInfo(t *testing.T) { ...@@ -128,8 +123,6 @@ func TestErrInsufficientChainInfo(t *testing.T) {
} }
func TestIncorrectTD(t *testing.T) { func TestIncorrectTD(t *testing.T) {
t.Skip("skipping TD check until network is healthy")
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(3) blockPoolTester.initRefBlockChain(3)
...@@ -156,9 +149,6 @@ func TestIncorrectTD(t *testing.T) { ...@@ -156,9 +149,6 @@ func TestIncorrectTD(t *testing.T) {
} }
func TestSkipIncorrectTDonFutureBlocks(t *testing.T) { func TestSkipIncorrectTDonFutureBlocks(t *testing.T) {
// t.Skip() // @zelig this one requires fixing for the TD
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(3) blockPoolTester.initRefBlockChain(3)
...@@ -195,31 +185,40 @@ func TestSkipIncorrectTDonFutureBlocks(t *testing.T) { ...@@ -195,31 +185,40 @@ func TestSkipIncorrectTDonFutureBlocks(t *testing.T) {
} }
func TestPeerSuspension(t *testing.T) { func TestPeerSuspension(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPool.Config.PeerSuspensionInterval = 100 * time.Millisecond blockPool.Config.PeerSuspensionInterval = 100 * time.Millisecond
blockPool.Start() blockPool.Start()
peer1 := blockPoolTester.newPeer("peer1", 1, 3) peer1 := blockPoolTester.newPeer("peer1", 3, 3)
peer1.AddPeer() peer1.AddPeer()
blockPool.peers.peerError("peer1", 0, "")
bestpeer, _ := blockPool.peers.getPeer("peer1") bestpeer, _ := blockPool.peers.getPeer("peer1")
if bestpeer == nil {
t.Errorf("peer1 not best peer")
return
}
peer1.serveBlocks(2, 3)
blockPool.peers.peerError("peer1", 0, "")
bestpeer, _ = blockPool.peers.getPeer("peer1")
if bestpeer != nil { if bestpeer != nil {
t.Errorf("peer1 not removed on error") t.Errorf("peer1 not removed on error")
return
} }
peer1.AddPeer() peer1.AddPeer()
bestpeer, _ = blockPool.peers.getPeer("peer1") bestpeer, _ = blockPool.peers.getPeer("peer1")
if bestpeer != nil { if bestpeer != nil {
t.Errorf("peer1 not removed on reconnect") t.Errorf("peer1 not removed on reconnect")
return
} }
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
peer1.AddPeer() peer1.AddPeer()
bestpeer, _ = blockPool.peers.getPeer("peer1") bestpeer, _ = blockPool.peers.getPeer("peer1")
if bestpeer == nil { if bestpeer == nil {
t.Errorf("peer1 not connected after PeerSuspensionInterval") t.Errorf("peer1 not connected after PeerSuspensionInterval")
return
} }
// blockPool.Wait(waitTimeout)
blockPool.Stop() blockPool.Stop()
} }
此差异已折叠。
package blockpool package blockpool
import ( import (
"flag"
"math/big" "math/big"
"testing" "testing"
"time" "time"
"github.com/ethereum/go-ethereum/blockpool/test"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
)
var (
_ = flag.Set("alsologtostderr", "true")
// _ = flag.Set("log_dir", ".")
_ = flag.Set("v", "5")
) )
// the actual tests // the actual tests
func TestAddPeer(t *testing.T) { func TestAddPeer(t *testing.T) {
test.LogInit() glog.V(logger.Error).Infoln("logging...")
hashPool, blockPool, blockPoolTester := newTestBlockPool(t) hashPool, blockPool, blockPoolTester := newTestBlockPool(t)
peer0 := blockPoolTester.newPeer("peer0", 1, 1) peer0 := blockPoolTester.newPeer("peer0", 2, 2)
peer1 := blockPoolTester.newPeer("peer1", 2, 2) peer1 := blockPoolTester.newPeer("peer1", 4, 4)
peer2 := blockPoolTester.newPeer("peer2", 3, 3) peer2 := blockPoolTester.newPeer("peer2", 6, 6)
var bestpeer *peer var bestpeer *peer
blockPool.Start() blockPool.Start()
...@@ -25,127 +32,149 @@ func TestAddPeer(t *testing.T) { ...@@ -25,127 +32,149 @@ func TestAddPeer(t *testing.T) {
// pool // pool
best := peer0.AddPeer() best := peer0.AddPeer()
if !best { if !best {
t.Errorf("peer0 (TD=1) not accepted as best") t.Errorf("peer0 (TD=2) not accepted as best")
return
} }
if blockPool.peers.best.id != "peer0" { if blockPool.peers.best.id != "peer0" {
t.Errorf("peer0 (TD=1) not set as best") t.Errorf("peer0 (TD=2) not set as best")
return
} }
peer0.serveBlocks(1, 2)
best = peer2.AddPeer() best = peer2.AddPeer()
if !best { if !best {
t.Errorf("peer2 (TD=3) not accepted as best") t.Errorf("peer2 (TD=6) not accepted as best")
return
} }
if blockPool.peers.best.id != "peer2" { if blockPool.peers.best.id != "peer2" {
t.Errorf("peer2 (TD=3) not set as best") t.Errorf("peer2 (TD=6) not set as best")
return
} }
peer2.waitBlocksRequests(3) peer2.serveBlocks(5, 6)
best = peer1.AddPeer() best = peer1.AddPeer()
if best { if best {
t.Errorf("peer1 (TD=2) accepted as best") t.Errorf("peer1 (TD=4) accepted as best")
return
} }
if blockPool.peers.best.id != "peer2" { if blockPool.peers.best.id != "peer2" {
t.Errorf("peer2 (TD=3) not set any more as best") t.Errorf("peer2 (TD=6) not set any more as best")
return
} }
if blockPool.peers.best.td.Cmp(big.NewInt(int64(3))) != 0 { if blockPool.peers.best.td.Cmp(big.NewInt(int64(6))) != 0 {
t.Errorf("peer1 TD not set") t.Errorf("peer2 TD=6 not set")
return
} }
peer2.td = 4 peer2.td = 8
peer2.currentBlock = 4 peer2.currentBlock = 8
best = peer2.AddPeer() best = peer2.AddPeer()
if !best { if !best {
t.Errorf("peer2 (TD=4) not accepted as best") t.Errorf("peer2 (TD=8) not accepted as best")
return
} }
if blockPool.peers.best.id != "peer2" { if blockPool.peers.best.id != "peer2" {
t.Errorf("peer2 (TD=4) not set as best") t.Errorf("peer2 (TD=8) not set as best")
return
} }
if blockPool.peers.best.td.Cmp(big.NewInt(int64(4))) != 0 { if blockPool.peers.best.td.Cmp(big.NewInt(int64(8))) != 0 {
t.Errorf("peer2 TD not updated") t.Errorf("peer2 TD = 8 not updated")
return
} }
peer2.waitBlocksRequests(4)
peer1.td = 3 peer1.td = 6
peer1.currentBlock = 3 peer1.currentBlock = 6
best = peer1.AddPeer() best = peer1.AddPeer()
if best { if best {
t.Errorf("peer1 (TD=3) should not be set as best") t.Errorf("peer1 (TD=6) should not be set as best")
return
} }
if blockPool.peers.best.id == "peer1" { if blockPool.peers.best.id == "peer1" {
t.Errorf("peer1 (TD=3) should not be set as best") t.Errorf("peer1 (TD=6) should not be set as best")
return
} }
bestpeer, best = blockPool.peers.getPeer("peer1") bestpeer, best = blockPool.peers.getPeer("peer1")
if bestpeer.td.Cmp(big.NewInt(int64(3))) != 0 { if bestpeer.td.Cmp(big.NewInt(int64(6))) != 0 {
t.Errorf("peer1 TD should be updated") t.Errorf("peer1 TD=6 should be updated")
return
} }
blockPool.RemovePeer("peer2") blockPool.RemovePeer("peer2")
bestpeer, best = blockPool.peers.getPeer("peer2") bestpeer, best = blockPool.peers.getPeer("peer2")
if bestpeer != nil { if bestpeer != nil {
t.Errorf("peer2 not removed") t.Errorf("peer2 not removed")
return
} }
if blockPool.peers.best.id != "peer1" { if blockPool.peers.best.id != "peer1" {
t.Errorf("existing peer1 (TD=3) should be set as best peer") t.Errorf("existing peer1 (TD=6) should be set as best peer")
return
} }
peer1.waitBlocksRequests(3)
blockPool.RemovePeer("peer1") blockPool.RemovePeer("peer1")
bestpeer, best = blockPool.peers.getPeer("peer1") bestpeer, best = blockPool.peers.getPeer("peer1")
if bestpeer != nil { if bestpeer != nil {
t.Errorf("peer1 not removed") t.Errorf("peer1 not removed")
return
} }
if blockPool.peers.best.id != "peer0" { if blockPool.peers.best.id != "peer0" {
t.Errorf("existing peer0 (TD=1) should be set as best peer") t.Errorf("existing peer0 (TD=2) should be set as best peer")
return
} }
peer0.waitBlocksRequests(1)
blockPool.RemovePeer("peer0") blockPool.RemovePeer("peer0")
bestpeer, best = blockPool.peers.getPeer("peer0") bestpeer, best = blockPool.peers.getPeer("peer0")
if bestpeer != nil { if bestpeer != nil {
t.Errorf("peer1 not removed") t.Errorf("peer0 not removed")
return
} }
// adding back earlier peer ok // adding back earlier peer ok
peer0.currentBlock = 3 peer0.currentBlock = 5
peer0.td = 5
best = peer0.AddPeer() best = peer0.AddPeer()
if !best { if !best {
t.Errorf("peer0 (TD=1) should be set as best") t.Errorf("peer0 (TD=5) should be set as best")
return
} }
if blockPool.peers.best.id != "peer0" { if blockPool.peers.best.id != "peer0" {
t.Errorf("peer0 (TD=1) should be set as best") t.Errorf("peer0 (TD=5) should be set as best")
return
} }
peer0.waitBlocksRequests(3) peer0.serveBlocks(4, 5)
hash := hashPool.IndexesToHashes([]int{0})[0] hash := hashPool.IndexesToHashes([]int{6})[0]
newblock := &types.Block{Td: common.Big3, HeaderHash: hash} newblock := &types.Block{Td: big.NewInt(int64(6)), HeaderHash: hash}
blockPool.chainEvents.Post(core.ChainHeadEvent{newblock}) blockPool.chainEvents.Post(core.ChainHeadEvent{newblock})
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
if blockPool.peers.best != nil { if blockPool.peers.best != nil {
t.Errorf("no peer should be ahead of self") t.Errorf("no peer should be ahead of self")
return
} }
best = peer1.AddPeer() best = peer1.AddPeer()
if blockPool.peers.best != nil { if blockPool.peers.best != nil {
t.Errorf("still no peer should be ahead of self") t.Errorf("after peer1 (TD=6) still no peer should be ahead of self")
return
} }
best = peer2.AddPeer() best = peer2.AddPeer()
if !best { if !best {
t.Errorf("peer2 (TD=4) not accepted as best") t.Errorf("peer2 (TD=8) not accepted as best")
return
} }
blockPool.RemovePeer("peer2") blockPool.RemovePeer("peer2")
if blockPool.peers.best != nil { if blockPool.peers.best != nil {
t.Errorf("no peer should be ahead of self") t.Errorf("no peer should be ahead of self")
return
} }
blockPool.Stop() blockPool.Stop()
} }
func TestPeerPromotionByTdOnBlock(t *testing.T) { func TestPeerPromotionByTdOnBlock(t *testing.T) {
test.LogInit()
_, blockPool, blockPoolTester := newTestBlockPool(t) _, blockPool, blockPoolTester := newTestBlockPool(t)
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(4) blockPoolTester.initRefBlockChain(4)
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
) )
/* /*
...@@ -88,7 +90,7 @@ func (self *BlockPool) newSection(nodes []*node) *section { ...@@ -88,7 +90,7 @@ func (self *BlockPool) newSection(nodes []*node) *section {
self.set(n.hash, entry) self.set(n.hash, entry)
} }
plog.DebugDetailf("[%s] setup section process", sectionhex(sec)) glog.V(logger.Detail).Infof("[%s] setup section process", sectionhex(sec))
go sec.run() go sec.run()
return sec return sec
...@@ -132,13 +134,13 @@ func (self *section) addSectionToBlockChain(p *peer) { ...@@ -132,13 +134,13 @@ func (self *section) addSectionToBlockChain(p *peer) {
} }
self.bp.lock.Unlock() self.bp.lock.Unlock()
plog.Debugf("[%s] insert %v blocks [%v/%v] into blockchain", sectionhex(self), len(blocks), hex(blocks[0].Hash()), hex(blocks[len(blocks)-1].Hash())) glog.V(logger.Debug).Infof("[%s] insert %v blocks [%v/%v] into blockchain", sectionhex(self), len(blocks), hex(blocks[0].Hash()), hex(blocks[len(blocks)-1].Hash()))
err := self.bp.insertChain(blocks) err := self.bp.insertChain(blocks)
if err != nil { if err != nil {
self.invalid = true self.invalid = true
self.bp.peers.peerError(n.blockBy, ErrInvalidBlock, "%v", err) self.bp.peers.peerError(n.blockBy, ErrInvalidBlock, "%v", err)
plog.Warnf("invalid block %x", n.hash) glog.V(logger.Error).Infof("invalid block %x", n.hash)
plog.Warnf("penalise peers %v (hash), %v (block)", n.hashBy, n.blockBy) glog.V(logger.Error).Infof("penalise peers %v (hash), %v (block)", n.hashBy, n.blockBy)
// or invalid block and the entire chain needs to be removed // or invalid block and the entire chain needs to be removed
self.removeChain() self.removeChain()
...@@ -146,7 +148,6 @@ func (self *section) addSectionToBlockChain(p *peer) { ...@@ -146,7 +148,6 @@ func (self *section) addSectionToBlockChain(p *peer) {
// check tds // check tds
self.bp.wg.Add(1) self.bp.wg.Add(1)
go func() { go func() {
plog.DebugDetailf("checking td")
self.bp.checkTD(nodes...) self.bp.checkTD(nodes...)
self.bp.wg.Done() self.bp.wg.Done()
}() }()
...@@ -159,15 +160,15 @@ func (self *section) addSectionToBlockChain(p *peer) { ...@@ -159,15 +160,15 @@ func (self *section) addSectionToBlockChain(p *peer) {
if child := self.bp.getChild(self); child != nil { if child := self.bp.getChild(self); child != nil {
select { select {
case <-child.offC: case <-child.offC:
plog.DebugDetailf("[%s] add complete child section [%s] to the blockchain", sectionhex(self), sectionhex(child)) glog.V(logger.Detail).Infof("[%s] add complete child section [%s] to the blockchain", sectionhex(self), sectionhex(child))
case child.poolRootC <- p: case child.poolRootC <- p:
plog.DebugDetailf("[%s] add incomplete child section [%s] to the blockchain", sectionhex(self), sectionhex(child)) glog.V(logger.Detail).Infof("[%s] add incomplete child section [%s] to the blockchain", sectionhex(self), sectionhex(child))
} }
child.addSectionToBlockChain(p) child.addSectionToBlockChain(p)
} else { } else {
plog.DebugDetailf("[%s] no child section in pool", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] no child section in pool", sectionhex(self))
} }
plog.DebugDetailf("[%s] section completely inserted to blockchain - remove", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] section completely inserted to blockchain - remove", sectionhex(self))
// complete sections are removed. if called from within section process, // complete sections are removed. if called from within section process,
// this must run in its own go routine to avoid deadlock // this must run in its own go routine to avoid deadlock
self.remove() self.remove()
...@@ -216,7 +217,7 @@ LOOP: ...@@ -216,7 +217,7 @@ LOOP:
if self.peer != nil { if self.peer != nil {
name = self.peer.id name = self.peer.id
} }
plog.DebugDetailf("[%s] peer <%s> active: %v", sectionhex(self), name, self.active) glog.V(logger.Detail).Infof("[%s] peer <%s> active: %v", sectionhex(self), name, self.active)
// global quit from blockpool // global quit from blockpool
case <-self.bp.quit: case <-self.bp.quit:
...@@ -239,30 +240,30 @@ LOOP: ...@@ -239,30 +240,30 @@ LOOP:
// peer quit or demoted, put section in idle mode // peer quit or demoted, put section in idle mode
case <-self.idleC: case <-self.idleC:
// peer quit or demoted, put section in idle mode // peer quit or demoted, put section in idle mode
plog.Debugf("[%s] peer <%s> quit or demoted", sectionhex(self), self.peer.id) glog.V(logger.Debug).Infof("[%s] peer <%s> quit or demoted", sectionhex(self), self.peer.id)
self.switchOff() self.switchOff()
self.idleC = nil self.idleC = nil
// timebomb - if section is not complete in time, nuke the entire chain // timebomb - if section is not complete in time, nuke the entire chain
case <-self.suicideTimer: case <-self.suicideTimer:
self.removeChain() self.removeChain()
plog.Debugf("[%s] timeout. (%v total attempts): missing %v/%v/%v...suicide", sectionhex(self), self.blocksRequests, self.missing, self.lastMissing, self.depth) glog.V(logger.Debug).Infof("[%s] timeout. (%v total attempts): missing %v/%v/%v...suicide", sectionhex(self), self.blocksRequests, self.missing, self.lastMissing, self.depth)
self.suicideTimer = nil self.suicideTimer = nil
break LOOP break LOOP
// closing suicideC triggers section suicide: removes section nodes from pool and terminates section process // closing suicideC triggers section suicide: removes section nodes from pool and terminates section process
case <-self.suicideC: case <-self.suicideC:
plog.DebugDetailf("[%s] quit", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] quit", sectionhex(self))
break LOOP break LOOP
// alarm for checking blocks in the section // alarm for checking blocks in the section
case <-self.blocksRequestTimer: case <-self.blocksRequestTimer:
plog.DebugDetailf("[%s] alarm: block request time", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] alarm: block request time", sectionhex(self))
self.processC = self.missingC self.processC = self.missingC
// alarm for checking parent of the section or sending out hash requests // alarm for checking parent of the section or sending out hash requests
case <-self.blockHashesRequestTimer: case <-self.blockHashesRequestTimer:
plog.DebugDetailf("[%s] alarm: hash request time", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] alarm: hash request time", sectionhex(self))
self.blockHashesRequest() self.blockHashesRequest()
// activate this section process with a peer // activate this section process with a peer
...@@ -283,15 +284,13 @@ LOOP: ...@@ -283,15 +284,13 @@ LOOP:
case n, ok := <-self.processC: case n, ok := <-self.processC:
// channel closed, first iteration finished // channel closed, first iteration finished
if !ok && !self.initialised { if !ok && !self.initialised {
plog.DebugDetailf("[%s] section initalised: missing %v/%v/%v", sectionhex(self), self.missing, self.lastMissing, self.depth) glog.V(logger.Detail).Infof("[%s] section initalised: missing %v/%v/%v", sectionhex(self), self.missing, self.lastMissing, self.depth)
self.initialised = true self.initialised = true
self.processC = nil self.processC = nil
// self.processC = make(chan *node, self.missing)
self.checkRound() self.checkRound()
checking = false checking = false
break break
} }
// plog.DebugDetailf("[%s] section proc step %v: missing %v/%v/%v", sectionhex(self), self.step, self.missing, self.lastMissing, self.depth)
if !checking { if !checking {
self.step = 0 self.step = 0
self.missing = 0 self.missing = 0
...@@ -322,19 +321,19 @@ LOOP: ...@@ -322,19 +321,19 @@ LOOP:
// if node has got block (received via async AddBlock call from protocol) // if node has got block (received via async AddBlock call from protocol)
if self.step == self.lastMissing { if self.step == self.lastMissing {
// current root of the pool // current root of the pool
plog.DebugDetailf("[%s] received block for current pool root %s", sectionhex(self), hex(n.hash)) glog.V(logger.Detail).Infof("[%s] received block for current pool root %s", sectionhex(self), hex(n.hash))
self.addSectionToBlockChain(self.peer) self.addSectionToBlockChain(self.peer)
} }
} else { } else {
if (self.parentHash == common.Hash{}) && n == self.bottom { if (self.parentHash == common.Hash{}) && n == self.bottom {
self.parentHash = block.ParentHash() self.parentHash = block.ParentHash()
plog.DebugDetailf("[%s] got parent head block hash %s...checking", sectionhex(self), hex(self.parentHash)) glog.V(logger.Detail).Infof("[%s] got parent head block hash %s...checking", sectionhex(self), hex(self.parentHash))
self.blockHashesRequest() self.blockHashesRequest()
} }
} }
} }
if self.initialised && self.step == self.lastMissing { if self.initialised && self.step == self.lastMissing {
plog.DebugDetailf("[%s] check if new blocks arrived (attempt %v): missing %v/%v/%v", sectionhex(self), self.blocksRequests, self.missing, self.lastMissing, self.depth) glog.V(logger.Detail).Infof("[%s] check if new blocks arrived (attempt %v): missing %v/%v/%v", sectionhex(self), self.blocksRequests, self.missing, self.lastMissing, self.depth)
self.checkRound() self.checkRound()
checking = false checking = false
} }
...@@ -347,7 +346,7 @@ LOOP: ...@@ -347,7 +346,7 @@ LOOP:
self.bp.wg.Done() self.bp.wg.Done()
} }
plog.DebugDetailf("[%s] section process terminated: %v blocks retrieved (%v attempts), hash requests complete on root (%v attempts).", sectionhex(self), self.depth, self.blocksRequests, self.blockHashesRequests) glog.V(logger.Detail).Infof("[%s] section process terminated: %v blocks retrieved (%v attempts), hash requests complete on root (%v attempts).", sectionhex(self), self.depth, self.blocksRequests, self.blockHashesRequests)
} }
...@@ -369,7 +368,7 @@ func (self *section) switchOn(newpeer *peer) { ...@@ -369,7 +368,7 @@ func (self *section) switchOn(newpeer *peer) {
newp = newpeer.id newp = newpeer.id
} }
plog.DebugDetailf("[%s] active mode <%s> -> <%s>", sectionhex(self), oldp, newp) glog.V(logger.Detail).Infof("[%s] active mode <%s> -> <%s>", sectionhex(self), oldp, newp)
} }
// activate section with current peer // activate section with current peer
...@@ -411,7 +410,7 @@ func (self *section) switchOff() { ...@@ -411,7 +410,7 @@ func (self *section) switchOff() {
if oldpeer != nil { if oldpeer != nil {
oldp = oldpeer.id oldp = oldpeer.id
} }
plog.DebugDetailf("[%s] idle mode peer <%s> -> <> (%v total attempts): missing %v/%v/%v", sectionhex(self), oldp, self.blocksRequests, self.missing, self.lastMissing, self.depth) glog.V(logger.Detail).Infof("[%s] idle mode peer <%s> -> <> (%v total attempts): missing %v/%v/%v", sectionhex(self), oldp, self.blocksRequests, self.missing, self.lastMissing, self.depth)
self.active = false self.active = false
self.peer = nil self.peer = nil
...@@ -462,19 +461,15 @@ func (self *section) blockHashesRequest() { ...@@ -462,19 +461,15 @@ func (self *section) blockHashesRequest() {
if parentSection == nil { if parentSection == nil {
// only link to new parent if not switching peers // only link to new parent if not switching peers
// this protects against synchronisation issue where during switching
// a demoted peer's fork will be chosen over the best peer's chain
// because relinking the correct chain (activateChain) is overwritten here in
// demoted peer's section process just before the section is put to idle mode
if (self.parentHash != common.Hash{}) { if (self.parentHash != common.Hash{}) {
if parent := self.bp.get(self.parentHash); parent != nil { if parent := self.bp.get(self.parentHash); parent != nil {
parentSection = parent.section parentSection = parent.section
plog.DebugDetailf("[%s] blockHashesRequest: parent section [%s] linked\n", sectionhex(self), sectionhex(parentSection)) glog.V(logger.Detail).Infof("[%s] blockHashesRequest: parent section [%s] linked\n", sectionhex(self), sectionhex(parentSection))
link(parentSection, self) link(parentSection, self)
} else { } else {
if self.bp.hasBlock(self.parentHash) { if self.bp.hasBlock(self.parentHash) {
self.poolRoot = true self.poolRoot = true
plog.DebugDetailf("[%s] blockHashesRequest: parentHash known ... inserting section in blockchain", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] blockHashesRequest: parentHash known ... inserting section in blockchain", sectionhex(self))
self.addSectionToBlockChain(self.peer) self.addSectionToBlockChain(self.peer)
self.blockHashesRequestTimer = nil self.blockHashesRequestTimer = nil
self.blockHashesRequestsComplete = true self.blockHashesRequestsComplete = true
...@@ -488,15 +483,15 @@ func (self *section) blockHashesRequest() { ...@@ -488,15 +483,15 @@ func (self *section) blockHashesRequest() {
if parentSection != nil { if parentSection != nil {
// activate parent section with this peer // activate parent section with this peer
// but only if not during switch mode // but only if not during switch mode
plog.DebugDetailf("[%s] parent section [%s] activated\n", sectionhex(self), sectionhex(parentSection)) glog.V(logger.Detail).Infof("[%s] parent section [%s] activated\n", sectionhex(self), sectionhex(parentSection))
self.bp.activateChain(parentSection, self.peer, self.peer.switchC, nil) self.bp.activateChain(parentSection, self.peer, self.peer.switchC, nil)
// if not root of chain, switch off // if not root of chain, switch off
plog.DebugDetailf("[%s] parent found, hash requests deactivated (after %v total attempts)\n", sectionhex(self), self.blockHashesRequests) glog.V(logger.Detail).Infof("[%s] parent found, hash requests deactivated (after %v total attempts)\n", sectionhex(self), self.blockHashesRequests)
self.blockHashesRequestTimer = nil self.blockHashesRequestTimer = nil
self.blockHashesRequestsComplete = true self.blockHashesRequestsComplete = true
} else { } else {
self.blockHashesRequests++ self.blockHashesRequests++
plog.DebugDetailf("[%s] hash request on root (%v total attempts)\n", sectionhex(self), self.blockHashesRequests) glog.V(logger.Detail).Infof("[%s] hash request on root (%v total attempts)\n", sectionhex(self), self.blockHashesRequests)
self.peer.requestBlockHashes(self.bottom.hash) self.peer.requestBlockHashes(self.bottom.hash)
self.blockHashesRequestTimer = time.After(self.bp.Config.BlockHashesRequestInterval) self.blockHashesRequestTimer = time.After(self.bp.Config.BlockHashesRequestInterval)
} }
...@@ -508,12 +503,12 @@ func (self *section) blockHashesRequest() { ...@@ -508,12 +503,12 @@ func (self *section) blockHashesRequest() {
func (self *section) checkRound() { func (self *section) checkRound() {
if self.missing == 0 { if self.missing == 0 {
// no missing blocks // no missing blocks
plog.DebugDetailf("[%s] section checked: got all blocks. process complete (%v total blocksRequests): missing %v/%v/%v", sectionhex(self), self.blocksRequests, self.missing, self.lastMissing, self.depth) glog.V(logger.Detail).Infof("[%s] section checked: got all blocks. process complete (%v total blocksRequests): missing %v/%v/%v", sectionhex(self), self.blocksRequests, self.missing, self.lastMissing, self.depth)
self.blocksRequestsComplete = true self.blocksRequestsComplete = true
self.blocksRequestTimer = nil self.blocksRequestTimer = nil
} else { } else {
// some missing blocks // some missing blocks
plog.DebugDetailf("[%s] section checked: missing %v/%v/%v", sectionhex(self), self.missing, self.lastMissing, self.depth) glog.V(logger.Detail).Infof("[%s] section checked: missing %v/%v/%v", sectionhex(self), self.missing, self.lastMissing, self.depth)
self.blocksRequests++ self.blocksRequests++
pos := self.missing % self.bp.Config.BlockBatchSize pos := self.missing % self.bp.Config.BlockBatchSize
if pos == 0 { if pos == 0 {
...@@ -529,7 +524,7 @@ func (self *section) checkRound() { ...@@ -529,7 +524,7 @@ func (self *section) checkRound() {
self.idle++ self.idle++
// too many idle rounds // too many idle rounds
if self.idle >= self.bp.Config.BlocksRequestMaxIdleRounds { if self.idle >= self.bp.Config.BlocksRequestMaxIdleRounds {
plog.DebugDetailf("[%s] block requests had %v idle rounds (%v total attempts): missing %v/%v/%v\ngiving up...", sectionhex(self), self.idle, self.blocksRequests, self.missing, self.lastMissing, self.depth) glog.V(logger.Detail).Infof("[%s] block requests had %v idle rounds (%v total attempts): missing %v/%v/%v\ngiving up...", sectionhex(self), self.idle, self.blocksRequests, self.missing, self.lastMissing, self.depth)
self.removeChain() self.removeChain()
} }
} else { } else {
...@@ -558,7 +553,7 @@ func link(parent *section, child *section) { ...@@ -558,7 +553,7 @@ func link(parent *section, child *section) {
if exChild != nil && exChild != child { if exChild != nil && exChild != child {
if child != nil { if child != nil {
// if child is nil it is not a real fork // if child is nil it is not a real fork
plog.DebugDetailf("[%s] chain fork [%s] -> [%s]", sectionhex(parent), sectionhex(exChild), sectionhex(child)) glog.V(logger.Detail).Infof("[%s] chain fork [%s] -> [%s]", sectionhex(parent), sectionhex(exChild), sectionhex(child))
} }
exChild.parent = nil exChild.parent = nil
} }
...@@ -568,7 +563,7 @@ func link(parent *section, child *section) { ...@@ -568,7 +563,7 @@ func link(parent *section, child *section) {
if exParent != nil && exParent != parent { if exParent != nil && exParent != parent {
if parent != nil { if parent != nil {
// if parent is nil it is not a real fork, but suicide delinking section // if parent is nil it is not a real fork, but suicide delinking section
plog.DebugDetailf("[%s] chain reverse fork [%s] -> [%s]", sectionhex(child), sectionhex(exParent), sectionhex(parent)) glog.V(logger.Detail).Infof("[%s] chain reverse fork [%s] -> [%s]", sectionhex(child), sectionhex(exParent), sectionhex(parent))
} }
exParent.child = nil exParent.child = nil
} }
...@@ -583,7 +578,7 @@ func link(parent *section, child *section) { ...@@ -583,7 +578,7 @@ func link(parent *section, child *section) {
caller must hold chain lock caller must hold chain lock
*/ */
func (self *BlockPool) splitSection(parent *section, entry *entry) { func (self *BlockPool) splitSection(parent *section, entry *entry) {
plog.DebugDetailf("[%s] split section at fork", sectionhex(parent)) glog.V(logger.Detail).Infof("[%s] split section at fork", sectionhex(parent))
parent.deactivate() parent.deactivate()
waiter := make(chan bool) waiter := make(chan bool)
parent.wait(waiter) parent.wait(waiter)
...@@ -606,14 +601,14 @@ func (self *BlockPool) linkSections(nodes []*node, parent, child *section) (sec ...@@ -606,14 +601,14 @@ func (self *BlockPool) linkSections(nodes []*node, parent, child *section) (sec
// and launch section process fetching block and further hashes // and launch section process fetching block and further hashes
if len(nodes) > 0 { if len(nodes) > 0 {
sec = self.newSection(nodes) sec = self.newSection(nodes)
plog.Debugf("[%s]->[%s](%v)->[%s] new chain section", sectionhex(parent), sectionhex(sec), len(nodes), sectionhex(child)) glog.V(logger.Debug).Infof("[%s]->[%s](%v)->[%s] new chain section", sectionhex(parent), sectionhex(sec), len(nodes), sectionhex(child))
link(parent, sec) link(parent, sec)
link(sec, child) link(sec, child)
} else { } else {
if parent != nil && child != nil { if parent != nil && child != nil {
// now this can only happen if we allow response to hash request to include <from> hash // now this can only happen if we allow response to hash request to include <from> hash
// in this case we just link parent and child (without needing root block of child section) // in this case we just link parent and child (without needing root block of child section)
plog.Debugf("[%s]->[%s] connecting known sections", sectionhex(parent), sectionhex(child)) glog.V(logger.Debug).Infof("[%s]->[%s] connecting known sections", sectionhex(parent), sectionhex(child))
link(parent, child) link(parent, child)
} }
} }
...@@ -624,10 +619,10 @@ func (self *section) activate(p *peer) { ...@@ -624,10 +619,10 @@ func (self *section) activate(p *peer) {
self.bp.wg.Add(1) self.bp.wg.Add(1)
select { select {
case <-self.offC: case <-self.offC:
plog.DebugDetailf("[%s] completed section process. cannot activate for peer <%s>", sectionhex(self), p.id) glog.V(logger.Detail).Infof("[%s] completed section process. cannot activate for peer <%s>", sectionhex(self), p.id)
self.bp.wg.Done() self.bp.wg.Done()
case self.controlC <- p: case self.controlC <- p:
plog.DebugDetailf("[%s] activate section process for peer <%s>", sectionhex(self), p.id) glog.V(logger.Detail).Infof("[%s] activate section process for peer <%s>", sectionhex(self), p.id)
} }
} }
...@@ -641,16 +636,16 @@ func (self *section) remove() { ...@@ -641,16 +636,16 @@ func (self *section) remove() {
select { select {
case <-self.offC: case <-self.offC:
close(self.suicideC) close(self.suicideC)
plog.DebugDetailf("[%s] remove: suicide", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] remove: suicide", sectionhex(self))
case <-self.suicideC: case <-self.suicideC:
plog.DebugDetailf("[%s] remove: suicided already", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] remove: suicided already", sectionhex(self))
default: default:
plog.DebugDetailf("[%s] remove: suicide", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] remove: suicide", sectionhex(self))
close(self.suicideC) close(self.suicideC)
} }
self.unlink() self.unlink()
self.bp.remove(self) self.bp.remove(self)
plog.DebugDetailf("[%s] removed section.", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] removed section.", sectionhex(self))
} }
...@@ -661,7 +656,7 @@ func (self *section) removeChain() { ...@@ -661,7 +656,7 @@ func (self *section) removeChain() {
child := self.child child := self.child
self.bp.chainLock.RUnlock() self.bp.chainLock.RUnlock()
plog.DebugDetailf("[%s] remove chain", sectionhex(self)) glog.V(logger.Detail).Infof("[%s] remove chain", sectionhex(self))
self.remove() self.remove()
if child != nil { if child != nil {
child.removeChain() child.removeChain()
......
...@@ -51,7 +51,6 @@ func checkStatus(t *testing.T, bp *BlockPool, syncing bool, expected []int) (err ...@@ -51,7 +51,6 @@ func checkStatus(t *testing.T, bp *BlockPool, syncing bool, expected []int) (err
got := getStatusValues(s) got := getStatusValues(s)
for i, v := range expected { for i, v := range expected {
err = test.CheckInt(statusFields[i], got[i], v, t) err = test.CheckInt(statusFields[i], got[i], v, t)
// fmt.Printf("%v: %v (%v)\n", statusFields[i], got[i], v)
if err != nil { if err != nil {
return return
} }
...@@ -60,9 +59,6 @@ func checkStatus(t *testing.T, bp *BlockPool, syncing bool, expected []int) (err ...@@ -60,9 +59,6 @@ func checkStatus(t *testing.T, bp *BlockPool, syncing bool, expected []int) (err
} }
func TestBlockPoolStatus(t *testing.T) { func TestBlockPoolStatus(t *testing.T) {
t.Skip() // :FIXME:
test.LogInit()
var err error var err error
n := 3 n := 3
for n > 0 { for n > 0 {
...@@ -86,19 +82,17 @@ func testBlockPoolStatus(t *testing.T) (err error) { ...@@ -86,19 +82,17 @@ func testBlockPoolStatus(t *testing.T) (err error) {
blockPoolTester.blockChain[0] = nil blockPoolTester.blockChain[0] = nil
blockPoolTester.initRefBlockChain(12) blockPoolTester.initRefBlockChain(12)
blockPoolTester.refBlockChain[3] = []int{4, 7} blockPoolTester.refBlockChain[3] = []int{4, 7}
delete(blockPoolTester.refBlockChain, 6) blockPoolTester.refBlockChain[5] = []int{10}
blockPoolTester.refBlockChain[6] = []int{11}
blockPoolTester.refBlockChain[9] = []int{6}
delete(blockPoolTester.refBlockChain, 10)
blockPool.Start() blockPool.Start()
blockPoolTester.tds = make(map[int]int) peer1 := blockPoolTester.newPeer("peer1", 9, 9)
blockPoolTester.tds[9] = 1 peer2 := blockPoolTester.newPeer("peer2", 10, 10)
blockPoolTester.tds[11] = 3 peer3 := blockPoolTester.newPeer("peer3", 11, 11)
blockPoolTester.tds[6] = 2 peer4 := blockPoolTester.newPeer("peer4", 9, 9)
peer1 := blockPoolTester.newPeer("peer1", 1, 9)
peer2 := blockPoolTester.newPeer("peer2", 2, 6)
peer3 := blockPoolTester.newPeer("peer3", 3, 11)
peer4 := blockPoolTester.newPeer("peer4", 1, 9)
peer2.blocksRequestsMap = peer1.blocksRequestsMap peer2.blocksRequestsMap = peer1.blocksRequestsMap
var expected []int var expected []int
...@@ -124,119 +118,112 @@ func testBlockPoolStatus(t *testing.T) (err error) { ...@@ -124,119 +118,112 @@ func testBlockPoolStatus(t *testing.T) (err error) {
} }
peer1.serveBlockHashes(9, 8, 7, 3, 2) peer1.serveBlockHashes(9, 8, 7, 3, 2)
expected = []int{6, 5, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0} expected = []int{5, 5, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer1.serveBlocks(3, 7, 8) peer1.serveBlocks(3, 7, 8)
expected = []int{6, 5, 3, 3, 0, 1, 0, 0, 1, 1, 1, 1, 0} expected = []int{5, 5, 3, 3, 0, 1, 0, 0, 1, 1, 1, 1, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer1.serveBlocks(2, 3) peer1.serveBlocks(2, 3)
expected = []int{6, 5, 4, 4, 0, 1, 0, 0, 1, 1, 1, 1, 0} expected = []int{5, 5, 4, 4, 0, 1, 0, 0, 1, 1, 1, 1, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer4.AddPeer() peer4.AddPeer()
expected = []int{6, 5, 4, 4, 0, 2, 0, 0, 2, 2, 1, 1, 0} expected = []int{5, 5, 4, 4, 0, 2, 0, 0, 2, 2, 1, 1, 0}
err = checkStatus(nil, blockPool, true, expected)
if err != nil {
return
}
peer4.sendBlockHashes(12, 11)
expected = []int{6, 5, 4, 4, 0, 2, 0, 0, 2, 2, 1, 1, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer2.AddPeer() peer2.AddPeer()
expected = []int{6, 5, 4, 4, 0, 3, 0, 0, 3, 3, 1, 2, 0} expected = []int{5, 5, 4, 4, 0, 3, 0, 0, 3, 3, 1, 2, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer2.serveBlocks(5, 6) peer2.serveBlocks(5, 10)
peer2.serveBlockHashes(6, 5, 4, 3, 2) peer2.serveBlockHashes(10, 5, 4, 3, 2)
expected = []int{10, 8, 5, 5, 0, 3, 1, 0, 3, 3, 2, 2, 0} expected = []int{8, 8, 5, 5, 0, 3, 1, 0, 3, 3, 2, 2, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer2.serveBlocks(2, 3, 4) peer2.serveBlocks(2, 3, 4)
expected = []int{10, 8, 6, 6, 0, 3, 1, 0, 3, 3, 2, 2, 0} expected = []int{8, 8, 6, 6, 0, 3, 1, 0, 3, 3, 2, 2, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
blockPool.RemovePeer("peer2") blockPool.RemovePeer("peer2")
expected = []int{10, 8, 6, 6, 0, 3, 1, 0, 3, 2, 2, 2, 0} expected = []int{8, 8, 6, 6, 0, 3, 1, 0, 3, 2, 2, 2, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer1.serveBlockHashes(2, 1, 0) peer1.serveBlockHashes(2, 1, 0)
expected = []int{11, 9, 6, 6, 0, 3, 1, 0, 3, 2, 2, 2, 0} expected = []int{9, 9, 6, 6, 0, 3, 1, 0, 3, 2, 2, 2, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer1.serveBlocks(1, 2) peer1.serveBlocks(1, 2)
expected = []int{11, 9, 7, 7, 0, 3, 1, 0, 3, 2, 2, 2, 0} expected = []int{9, 9, 7, 7, 0, 3, 1, 0, 3, 2, 2, 2, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer1.serveBlocks(4, 5) peer1.serveBlocks(4, 5)
expected = []int{11, 9, 8, 8, 0, 3, 1, 0, 3, 2, 2, 2, 0} expected = []int{9, 9, 8, 8, 0, 3, 1, 0, 3, 2, 2, 2, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer3.AddPeer() peer3.AddPeer()
expected = []int{11, 9, 8, 8, 0, 4, 1, 0, 4, 3, 2, 3, 0} expected = []int{9, 9, 8, 8, 0, 4, 1, 0, 4, 3, 2, 3, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer3.serveBlocks(10, 11) peer3.serveBlocks(6, 11)
expected = []int{12, 9, 9, 9, 0, 4, 1, 0, 4, 3, 3, 3, 0} expected = []int{10, 9, 9, 9, 0, 4, 1, 0, 4, 3, 3, 3, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer3.serveBlockHashes(11, 10, 9) peer3.serveBlockHashes(11, 6, 9)
expected = []int{14, 11, 9, 9, 0, 4, 1, 0, 4, 3, 3, 3, 0} expected = []int{11, 11, 9, 9, 0, 4, 1, 0, 4, 3, 3, 3, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer4.sendBlocks(11, 12) peer4.sendBlocks(11, 12)
expected = []int{14, 11, 9, 9, 0, 4, 1, 0, 4, 3, 4, 3, 1} expected = []int{11, 11, 9, 9, 0, 4, 1, 0, 4, 3, 4, 3, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
} }
peer3.serveBlocks(9, 10) peer3.serveBlocks(9, 6)
expected = []int{14, 11, 10, 10, 0, 4, 1, 0, 4, 3, 4, 3, 1} expected = []int{11, 11, 10, 10, 0, 4, 1, 0, 4, 3, 4, 3, 0}
err = checkStatus(nil, blockPool, true, expected) err = checkStatus(nil, blockPool, true, expected)
if err != nil { if err != nil {
return return
...@@ -245,10 +232,11 @@ func testBlockPoolStatus(t *testing.T) (err error) { ...@@ -245,10 +232,11 @@ func testBlockPoolStatus(t *testing.T) (err error) {
peer3.serveBlocks(0, 1) peer3.serveBlocks(0, 1)
blockPool.Wait(waitTimeout) blockPool.Wait(waitTimeout)
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
blockPool.Stop()
expected = []int{14, 3, 11, 3, 8, 4, 1, 8, 4, 3, 4, 3, 1} expected = []int{11, 3, 11, 3, 8, 4, 1, 8, 4, 3, 4, 3, 0}
err = checkStatus(nil, blockPool, false, expected) err = checkStatus(nil, blockPool, false, expected)
blockPool.Stop()
if err != nil { if err != nil {
return return
} }
......
...@@ -473,6 +473,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { ...@@ -473,6 +473,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
} }
if IsParentErr(err) && self.futureBlocks.Has(block.ParentHash()) { if IsParentErr(err) && self.futureBlocks.Has(block.ParentHash()) {
block.SetQueued(true)
self.futureBlocks.Push(block) self.futureBlocks.Push(block)
stats.queued++ stats.queued++
continue continue
......
...@@ -69,7 +69,7 @@ func (self *Errors) New(code int, format string, params ...interface{}) *Error { ...@@ -69,7 +69,7 @@ func (self *Errors) New(code int, format string, params ...interface{}) *Error {
func (self Error) Error() (message string) { func (self Error) Error() (message string) {
if len(message) == 0 { if len(message) == 0 {
self.message = fmt.Sprintf("[%s] %s", self.Package, self.Name) self.message = fmt.Sprintf("[%s] ERROR: %s", self.Package, self.Name)
if self.format != "" { if self.format != "" {
self.message += ": " + fmt.Sprintf(self.format, self.params...) self.message += ": " + fmt.Sprintf(self.format, self.params...)
} }
...@@ -81,15 +81,8 @@ func (self Error) Log(v glog.Verbose) { ...@@ -81,15 +81,8 @@ func (self Error) Log(v glog.Verbose) {
if v { if v {
v.Infoln(self) v.Infoln(self)
} }
//log.Sendln(self.level, self)
} }
/*
func (self Error) Log(log *logger.Logger) {
log.Sendln(self.level, self)
}
*/
/* /*
err.Fatal() is true if err's severity level is 0 or 1 (logger.ErrorLevel or logger.Silence) err.Fatal() is true if err's severity level is 0 or 1 (logger.ErrorLevel or logger.Silence)
*/ */
......
...@@ -28,7 +28,7 @@ func testErrors() *Errors { ...@@ -28,7 +28,7 @@ func testErrors() *Errors {
func TestErrorMessage(t *testing.T) { func TestErrorMessage(t *testing.T) {
err := testErrors().New(0, "zero detail %v", "available") err := testErrors().New(0, "zero detail %v", "available")
message := fmt.Sprintf("%v", err) message := fmt.Sprintf("%v", err)
exp := "[TEST] zero: zero detail available" exp := "[TEST] ERROR: zero: zero detail available"
if message != exp { if message != exp {
t.Errorf("error message incorrect. expected %v, got %v", exp, message) t.Errorf("error message incorrect. expected %v, got %v", exp, message)
} }
......
...@@ -299,7 +299,7 @@ func (self *ethProtocol) handle() error { ...@@ -299,7 +299,7 @@ func (self *ethProtocol) handle() error {
// to simplify backend interface adding a new block // to simplify backend interface adding a new block
// uses AddPeer followed by AddBlock only if peer is the best peer // uses AddPeer followed by AddBlock only if peer is the best peer
// (or selected as new best peer) // (or selected as new best peer)
if best, _ := self.blockPool.AddPeer(request.TD, hash, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect); best { if _, suspended := self.blockPool.AddPeer(request.TD, hash, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect); !suspended {
self.blockPool.AddBlock(request.Block, self.id) self.blockPool.AddBlock(request.Block, self.id)
} }
...@@ -384,11 +384,9 @@ func (self *ethProtocol) sendStatus() error { ...@@ -384,11 +384,9 @@ func (self *ethProtocol) sendStatus() error {
} }
func (self *ethProtocol) protoErrorDisconnect(err *errs.Error) { func (self *ethProtocol) protoErrorDisconnect(err *errs.Error) {
//err.Log(self.peer.Logger)
err.Log(glog.V(logger.Info)) err.Log(glog.V(logger.Info))
/* if err.Fatal() {
if err.Fatal() { self.peer.Disconnect(p2p.DiscSubprotocolError)
self.peer.Disconnect(p2p.DiscSubprotocolError) }
}
*/
} }
...@@ -19,20 +19,20 @@ The comment from glog.go introduces the ideas: ...@@ -19,20 +19,20 @@ The comment from glog.go introduces the ideas:
Error, Fatal, plus formatting variants such as Infof. It Error, Fatal, plus formatting variants such as Infof. It
also provides V-style logging controlled by the -v and also provides V-style logging controlled by the -v and
-vmodule=file=2 flags. -vmodule=file=2 flags.
Basic examples: Basic examples:
glog.Info("Prepare to repel boarders") glog.Info("Prepare to repel boarders")
glog.Fatalf("Initialization failed: %s", err) glog.Fatalf("Initialization failed: %s", err)
See the documentation for the V function for an explanation See the documentation for the V function for an explanation
of these examples: of these examples:
if glog.V(2) { if glog.V(2) {
glog.Info("Starting transaction...") glog.Info("Starting transaction...")
} }
glog.V(2).Infoln("Processed", nItems, "elements") glog.V(2).Infoln("Processed", nItems, "elements")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册