Skip to content

Commit f4fb1a1

Browse files
zsfelfoldikaralabe
authored andcommitted
les: fixed cost table update (#19546)
1 parent 751effa commit f4fb1a1

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎les/costtracker.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,14 @@ func (table requestCostTable) getCost(code, amount uint64) uint64 {
346346
}
347347

348348
// decode converts a cost list to a cost table
349-
func (list RequestCostList) decode() requestCostTable {
349+
func (list RequestCostList) decode(protocolLength uint64) requestCostTable {
350350
table := make(requestCostTable)
351351
for _, e := range list {
352-
table[e.MsgCode] = &requestCosts{
353-
baseCost: e.BaseCost,
354-
reqCost: e.ReqCost,
352+
if e.MsgCode < protocolLength {
353+
table[e.MsgCode] = &requestCosts{
354+
baseCost: e.BaseCost,
355+
reqCost: e.ReqCost,
356+
}
355357
}
356358
}
357359
return table

‎les/peer.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis
479479
costList = testCostList()
480480
}
481481
send = send.add("flowControl/MRC", costList)
482-
p.fcCosts = costList.decode()
482+
p.fcCosts = costList.decode(ProtocolLengths[uint(p.version)])
483483
p.fcParams = server.defParams
484484
} else {
485485
//on client node
@@ -571,7 +571,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis
571571
}
572572
p.fcParams = params
573573
p.fcServer = flowcontrol.NewServerNode(params, &mclock.System{})
574-
p.fcCosts = MRC.decode()
574+
p.fcCosts = MRC.decode(ProtocolLengths[uint(p.version)])
575575
if !p.isOnlyAnnounce {
576576
for msgCode := range reqAvgTimeCost {
577577
if p.fcCosts[msgCode] == nil {
@@ -604,7 +604,10 @@ func (p *peer) updateFlowControl(update keyValueMap) {
604604
}
605605
var MRC RequestCostList
606606
if update.get("flowControl/MRC", &MRC) == nil {
607-
p.fcCosts = MRC.decode()
607+
costUpdate := MRC.decode(ProtocolLengths[uint(p.version)])
608+
for code, cost := range costUpdate {
609+
p.fcCosts[code] = cost
610+
}
608611
}
609612
}
610613

‎les/peer_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
const (
1515
test_networkid = 10
16-
protocol_version = 2123
16+
protocol_version = lpv2
1717
)
1818

1919
var (

0 commit comments

Comments
 (0)