les, les/flowcontrol: implement LES/3 (#19329)
les, les/flowcontrol: implement LES/3
This commit is contained in:
@ -24,6 +24,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/mclock"
|
||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
@ -438,7 +439,7 @@ func TestTransactionStatusLes2(t *testing.T) {
|
||||
config.Journal = ""
|
||||
txpool := core.NewTxPool(config, params.TestChainConfig, chain)
|
||||
pm.txpool = txpool
|
||||
peer, _ := newTestPeer(t, "peer", 2, pm, true)
|
||||
peer, _ := newTestPeer(t, "peer", 2, pm, true, 0)
|
||||
defer peer.close()
|
||||
|
||||
var reqID uint64
|
||||
@ -519,3 +520,51 @@ func TestTransactionStatusLes2(t *testing.T) {
|
||||
test(tx1, false, light.TxStatus{Status: core.TxStatusPending})
|
||||
test(tx2, false, light.TxStatus{Status: core.TxStatusPending})
|
||||
}
|
||||
|
||||
func TestStopResumeLes3(t *testing.T) {
|
||||
db := rawdb.NewMemoryDatabase()
|
||||
clock := &mclock.Simulated{}
|
||||
testCost := testBufLimit / 10
|
||||
pm, err := newTestProtocolManager(false, 0, nil, nil, nil, db, nil, testCost, clock)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create protocol manager: %v", err)
|
||||
}
|
||||
peer, _ := newTestPeer(t, "peer", 3, pm, true, testCost)
|
||||
defer peer.close()
|
||||
|
||||
expBuf := testBufLimit
|
||||
var reqID uint64
|
||||
|
||||
req := func() {
|
||||
reqID++
|
||||
sendRequest(peer.app, GetBlockHeadersMsg, reqID, testCost, &getBlockHeadersData{Origin: hashOrNumber{Hash: common.Hash{1}}, Amount: 1})
|
||||
}
|
||||
|
||||
for i := 1; i <= 5; i++ {
|
||||
// send requests while we still have enough buffer and expect a response
|
||||
for expBuf >= testCost {
|
||||
req()
|
||||
expBuf -= testCost
|
||||
if err := expectResponse(peer.app, BlockHeadersMsg, reqID, expBuf, nil); err != nil {
|
||||
t.Errorf("expected response and failed: %v", err)
|
||||
}
|
||||
}
|
||||
// send some more requests in excess and expect a single StopMsg
|
||||
c := i
|
||||
for c > 0 {
|
||||
req()
|
||||
c--
|
||||
}
|
||||
if err := p2p.ExpectMsg(peer.app, StopMsg, nil); err != nil {
|
||||
t.Errorf("expected StopMsg and failed: %v", err)
|
||||
}
|
||||
// wait until the buffer is recharged by half of the limit
|
||||
wait := testBufLimit / testBufRecharge / 2
|
||||
clock.Run(time.Millisecond * time.Duration(wait))
|
||||
// expect a ResumeMsg with the partially recharged buffer value
|
||||
expBuf += testBufRecharge * wait
|
||||
if err := p2p.ExpectMsg(peer.app, ResumeMsg, expBuf); err != nil {
|
||||
t.Errorf("expected ResumeMsg and failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user