diff options
author | Zsolt Felfoldi <zsfelfoldi@gmail.com> | 2019-04-10 17:01:54 +0800 |
---|---|---|
committer | Zsolt Felfoldi <zsfelfoldi@gmail.com> | 2019-04-10 19:12:46 +0800 |
commit | c8d8126bd0c4cc091978ba6dc8c656452f97ed4a (patch) | |
tree | 989421730bdf5c62612117abf058629709aa793c /les/peer.go | |
parent | 0de9f32ae8346ece3bbd596291f132385962d0ca (diff) | |
download | go-tangerine-c8d8126bd0c4cc091978ba6dc8c656452f97ed4a.tar go-tangerine-c8d8126bd0c4cc091978ba6dc8c656452f97ed4a.tar.gz go-tangerine-c8d8126bd0c4cc091978ba6dc8c656452f97ed4a.tar.bz2 go-tangerine-c8d8126bd0c4cc091978ba6dc8c656452f97ed4a.tar.lz go-tangerine-c8d8126bd0c4cc091978ba6dc8c656452f97ed4a.tar.xz go-tangerine-c8d8126bd0c4cc091978ba6dc8c656452f97ed4a.tar.zst go-tangerine-c8d8126bd0c4cc091978ba6dc8c656452f97ed4a.zip |
les: check required message types in cost table
Diffstat (limited to 'les/peer.go')
-rw-r--r-- | les/peer.go | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/les/peer.go b/les/peer.go index bf097f666..5072010c5 100644 --- a/les/peer.go +++ b/les/peer.go @@ -168,7 +168,11 @@ func (p *peer) GetRequestCost(msgcode uint64, amount int) uint64 { p.lock.RLock() defer p.lock.RUnlock() - cost := p.fcCosts[msgcode].baseCost + p.fcCosts[msgcode].reqCost*uint64(amount) + costs := p.fcCosts[msgcode] + if costs == nil { + return 0 + } + cost := costs.baseCost + costs.reqCost*uint64(amount) if cost > p.fcServerParams.BufLimit { cost = p.fcServerParams.BufLimit } @@ -189,8 +193,12 @@ func (p *peer) GetTxRelayCost(amount, size int) uint64 { panic(nil) } - cost := p.fcCosts[msgcode].baseCost + p.fcCosts[msgcode].reqCost*uint64(amount) - sizeCost := p.fcCosts[msgcode].baseCost + p.fcCosts[msgcode].reqCost*uint64(size)/txSizeCostLimit + costs := p.fcCosts[msgcode] + if costs == nil { + return 0 + } + cost := costs.baseCost + costs.reqCost*uint64(amount) + sizeCost := costs.baseCost + costs.reqCost*uint64(size)/txSizeCostLimit if sizeCost > cost { cost = sizeCost } @@ -516,6 +524,20 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis p.fcServerParams = params p.fcServer = flowcontrol.NewServerNode(params) p.fcCosts = MRC.decode() + var checkList []uint64 + switch p.version { + case lpv1: + checkList = reqListV1 + case lpv2: + checkList = reqListV2 + default: + panic(nil) + } + for _, msgCode := range checkList { + if p.fcCosts[msgCode] == nil { + return errResp(ErrUselessPeer, "peer does not support message %d", msgCode) + } + } } p.headInfo = &announceData{Td: rTd, Hash: rHash, Number: rNum} |