|
|
|
@ -24,7 +24,7 @@ import ( |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common/mclock" |
|
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb" |
|
|
|
|
lps "github.com/ethereum/go-ethereum/les/lespay/server" |
|
|
|
|
vfs "github.com/ethereum/go-ethereum/les/vflux/server" |
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode" |
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/enr" |
|
|
|
|
"github.com/ethereum/go-ethereum/p2p/nodestate" |
|
|
|
@ -100,7 +100,7 @@ func getBalance(pool *clientPool, p *poolTestPeer) (pos, neg uint64) { |
|
|
|
|
if temp { |
|
|
|
|
pool.ns.SetField(p.node, connAddressField, p.freeClientId()) |
|
|
|
|
} |
|
|
|
|
n, _ := pool.ns.GetField(p.node, pool.BalanceField).(*lps.NodeBalance) |
|
|
|
|
n, _ := pool.ns.GetField(p.node, pool.BalanceField).(*vfs.NodeBalance) |
|
|
|
|
pos, neg = n.GetBalance() |
|
|
|
|
if temp { |
|
|
|
|
pool.ns.SetField(p.node, connAddressField, nil) |
|
|
|
@ -138,7 +138,7 @@ func testClientPool(t *testing.T, activeLimit, clientCount, paidCount int, rando |
|
|
|
|
pool.ns.Start() |
|
|
|
|
|
|
|
|
|
pool.setLimits(activeLimit, uint64(activeLimit)) |
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
|
|
|
|
|
// pool should accept new peers up to its connected limit
|
|
|
|
|
for i := 0; i < activeLimit; i++ { |
|
|
|
@ -243,7 +243,7 @@ func TestConnectPaidClient(t *testing.T) { |
|
|
|
|
pool.ns.Start() |
|
|
|
|
defer pool.stop() |
|
|
|
|
pool.setLimits(10, uint64(10)) |
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
|
|
|
|
|
// Add balance for an external client and mark it as paid client
|
|
|
|
|
addBalance(pool, newPoolTestPeer(0, nil).node.ID(), int64(time.Minute)) |
|
|
|
@ -259,7 +259,7 @@ func TestConnectPaidClientToSmallPool(t *testing.T) { |
|
|
|
|
pool.ns.Start() |
|
|
|
|
defer pool.stop() |
|
|
|
|
pool.setLimits(10, uint64(10)) // Total capacity limit is 10
|
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
|
|
|
|
|
// Add balance for an external client and mark it as paid client
|
|
|
|
|
addBalance(pool, newPoolTestPeer(0, nil).node.ID(), int64(time.Minute)) |
|
|
|
@ -278,7 +278,7 @@ func TestConnectPaidClientToFullPool(t *testing.T) { |
|
|
|
|
pool.ns.Start() |
|
|
|
|
defer pool.stop() |
|
|
|
|
pool.setLimits(10, uint64(10)) // Total capacity limit is 10
|
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ { |
|
|
|
|
addBalance(pool, newPoolTestPeer(i, nil).node.ID(), int64(time.Second*20)) |
|
|
|
@ -309,7 +309,7 @@ func TestPaidClientKickedOut(t *testing.T) { |
|
|
|
|
pool.bt.SetExpirationTCs(0, 0) |
|
|
|
|
defer pool.stop() |
|
|
|
|
pool.setLimits(10, uint64(10)) // Total capacity limit is 10
|
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ { |
|
|
|
|
addBalance(pool, newPoolTestPeer(i, kickedCh).node.ID(), 10000000000) // 10 second allowance
|
|
|
|
@ -339,7 +339,7 @@ func TestConnectFreeClient(t *testing.T) { |
|
|
|
|
pool.ns.Start() |
|
|
|
|
defer pool.stop() |
|
|
|
|
pool.setLimits(10, uint64(10)) |
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
if cap, _ := pool.connect(newPoolTestPeer(0, nil)); cap == 0 { |
|
|
|
|
t.Fatalf("Failed to connect free client") |
|
|
|
|
} |
|
|
|
@ -356,7 +356,7 @@ func TestConnectFreeClientToFullPool(t *testing.T) { |
|
|
|
|
pool.ns.Start() |
|
|
|
|
defer pool.stop() |
|
|
|
|
pool.setLimits(10, uint64(10)) // Total capacity limit is 10
|
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ { |
|
|
|
|
pool.connect(newPoolTestPeer(i, nil)) |
|
|
|
@ -386,7 +386,7 @@ func TestFreeClientKickedOut(t *testing.T) { |
|
|
|
|
pool.ns.Start() |
|
|
|
|
defer pool.stop() |
|
|
|
|
pool.setLimits(10, uint64(10)) // Total capacity limit is 10
|
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ { |
|
|
|
|
pool.connect(newPoolTestPeer(i, kicked)) |
|
|
|
@ -428,7 +428,7 @@ func TestPositiveBalanceCalculation(t *testing.T) { |
|
|
|
|
pool.ns.Start() |
|
|
|
|
defer pool.stop() |
|
|
|
|
pool.setLimits(10, uint64(10)) // Total capacity limit is 10
|
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
|
|
|
|
|
addBalance(pool, newPoolTestPeer(0, kicked).node.ID(), int64(time.Minute*3)) |
|
|
|
|
testPriorityConnect(t, pool, newPoolTestPeer(0, kicked), 10, true) |
|
|
|
@ -452,7 +452,7 @@ func TestDowngradePriorityClient(t *testing.T) { |
|
|
|
|
pool.ns.Start() |
|
|
|
|
defer pool.stop() |
|
|
|
|
pool.setLimits(10, uint64(10)) // Total capacity limit is 10
|
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
|
|
|
|
|
p := newPoolTestPeer(0, kicked) |
|
|
|
|
addBalance(pool, p.node.ID(), int64(time.Minute)) |
|
|
|
@ -487,7 +487,7 @@ func TestNegativeBalanceCalculation(t *testing.T) { |
|
|
|
|
pool.ns.Start() |
|
|
|
|
defer pool.stop() |
|
|
|
|
pool.setLimits(10, uint64(10)) // Total capacity limit is 10
|
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1e-3, CapacityFactor: 0, RequestFactor: 1}, lps.PriceFactors{TimeFactor: 1e-3, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1e-3, CapacityFactor: 0, RequestFactor: 1}, vfs.PriceFactors{TimeFactor: 1e-3, CapacityFactor: 0, RequestFactor: 1}) |
|
|
|
|
|
|
|
|
|
for i := 0; i < 10; i++ { |
|
|
|
|
pool.connect(newPoolTestPeer(i, nil)) |
|
|
|
@ -564,7 +564,7 @@ func TestInactiveClient(t *testing.T) { |
|
|
|
|
if p2.cap != 0 { |
|
|
|
|
t.Fatalf("Failed to deactivate peer #2") |
|
|
|
|
} |
|
|
|
|
pool.setDefaultFactors(lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 0}, lps.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 0}) |
|
|
|
|
pool.setDefaultFactors(vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 0}, vfs.PriceFactors{TimeFactor: 1, CapacityFactor: 0, RequestFactor: 0}) |
|
|
|
|
p4 := newPoolTestPeer(4, nil) |
|
|
|
|
addBalance(pool, p4.node.ID(), 1500*int64(time.Second)) |
|
|
|
|
// p1: 1000 p2: 500 p3: 2000 p4: 1500
|
|
|
|
|