diff options
author | Felföldi Zsolt <zsfelfoldi@gmail.com> | 2019-05-13 19:26:47 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-05-13 19:26:47 +0800 |
commit | f4fb1a18015d88aa7b424709aac346da59edf410 (patch) | |
tree | ad34d256af98e26e87ff45e8882b15c545b1829a | |
parent | 751effa35e1e538093da4e8f5f466202639065a8 (diff) | |
download | go-tangerine-f4fb1a18015d88aa7b424709aac346da59edf410.tar go-tangerine-f4fb1a18015d88aa7b424709aac346da59edf410.tar.gz go-tangerine-f4fb1a18015d88aa7b424709aac346da59edf410.tar.bz2 go-tangerine-f4fb1a18015d88aa7b424709aac346da59edf410.tar.lz go-tangerine-f4fb1a18015d88aa7b424709aac346da59edf410.tar.xz go-tangerine-f4fb1a18015d88aa7b424709aac346da59edf410.tar.zst go-tangerine-f4fb1a18015d88aa7b424709aac346da59edf410.zip |
les: fixed cost table update (#19546)
-rw-r--r-- | les/costtracker.go | 10 | ||||
-rw-r--r-- | les/peer.go | 9 | ||||
-rw-r--r-- | les/peer_test.go | 2 |
3 files changed, 13 insertions, 8 deletions
diff --git a/les/costtracker.go b/les/costtracker.go index 014b888c0..332d73343 100644 --- a/les/costtracker.go +++ b/les/costtracker.go @@ -346,12 +346,14 @@ func (table requestCostTable) getCost(code, amount uint64) uint64 { } // decode converts a cost list to a cost table -func (list RequestCostList) decode() requestCostTable { +func (list RequestCostList) decode(protocolLength uint64) requestCostTable { table := make(requestCostTable) for _, e := range list { - table[e.MsgCode] = &requestCosts{ - baseCost: e.BaseCost, - reqCost: e.ReqCost, + if e.MsgCode < protocolLength { + table[e.MsgCode] = &requestCosts{ + baseCost: e.BaseCost, + reqCost: e.ReqCost, + } } } return table diff --git a/les/peer.go b/les/peer.go index a8aad3cd0..7a163cd1d 100644 --- a/les/peer.go +++ b/les/peer.go @@ -479,7 +479,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis costList = testCostList() } send = send.add("flowControl/MRC", costList) - p.fcCosts = costList.decode() + p.fcCosts = costList.decode(ProtocolLengths[uint(p.version)]) p.fcParams = server.defParams } else { //on client node @@ -571,7 +571,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis } p.fcParams = params p.fcServer = flowcontrol.NewServerNode(params, &mclock.System{}) - p.fcCosts = MRC.decode() + p.fcCosts = MRC.decode(ProtocolLengths[uint(p.version)]) if !p.isOnlyAnnounce { for msgCode := range reqAvgTimeCost { if p.fcCosts[msgCode] == nil { @@ -604,7 +604,10 @@ func (p *peer) updateFlowControl(update keyValueMap) { } var MRC RequestCostList if update.get("flowControl/MRC", &MRC) == nil { - p.fcCosts = MRC.decode() + costUpdate := MRC.decode(ProtocolLengths[uint(p.version)]) + for code, cost := range costUpdate { + p.fcCosts[code] = cost + } } } diff --git a/les/peer_test.go b/les/peer_test.go index c5a7c238c..62adf90fe 100644 --- a/les/peer_test.go +++ b/les/peer_test.go @@ -13,7 +13,7 @@ import ( const ( test_networkid = 10 - protocol_version = 2123 + protocol_version = lpv2 ) var ( |