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 | |
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')
-rw-r--r-- | les/handler.go | 6 | ||||
-rw-r--r-- | les/peer.go | 28 |
2 files changed, 30 insertions, 4 deletions
diff --git a/les/handler.go b/les/handler.go index 19ccbcd2b..2fb2067dd 100644 --- a/les/handler.go +++ b/les/handler.go @@ -324,7 +324,11 @@ func (pm *ProtocolManager) handle(p *peer) error { } } -var reqList = []uint64{GetBlockHeadersMsg, GetBlockBodiesMsg, GetCodeMsg, GetReceiptsMsg, GetProofsV1Msg, SendTxMsg, SendTxV2Msg, GetTxStatusMsg, GetHeaderProofsMsg, GetProofsV2Msg, GetHelperTrieProofsMsg} +var ( + reqList = []uint64{GetBlockHeadersMsg, GetBlockBodiesMsg, GetCodeMsg, GetReceiptsMsg, GetProofsV1Msg, SendTxMsg, SendTxV2Msg, GetTxStatusMsg, GetHeaderProofsMsg, GetProofsV2Msg, GetHelperTrieProofsMsg} + reqListV1 = []uint64{GetBlockHeadersMsg, GetBlockBodiesMsg, GetCodeMsg, GetReceiptsMsg, GetProofsV1Msg, SendTxMsg, GetHeaderProofsMsg} + reqListV2 = []uint64{GetBlockHeadersMsg, GetBlockBodiesMsg, GetCodeMsg, GetReceiptsMsg, SendTxV2Msg, GetTxStatusMsg, GetProofsV2Msg, GetHelperTrieProofsMsg} +) // handleMsg is invoked whenever an inbound message is received from a remote // peer. The remote connection is torn down upon returning any error. 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} |