les: check required message types in cost table
This commit is contained in:
parent
0de9f32ae8
commit
c8d8126bd0
@ -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
|
// handleMsg is invoked whenever an inbound message is received from a remote
|
||||||
// peer. The remote connection is torn down upon returning any error.
|
// peer. The remote connection is torn down upon returning any error.
|
||||||
|
28
les/peer.go
28
les/peer.go
@ -168,7 +168,11 @@ func (p *peer) GetRequestCost(msgcode uint64, amount int) uint64 {
|
|||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
defer p.lock.RUnlock()
|
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 {
|
if cost > p.fcServerParams.BufLimit {
|
||||||
cost = p.fcServerParams.BufLimit
|
cost = p.fcServerParams.BufLimit
|
||||||
}
|
}
|
||||||
@ -189,8 +193,12 @@ func (p *peer) GetTxRelayCost(amount, size int) uint64 {
|
|||||||
panic(nil)
|
panic(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
cost := p.fcCosts[msgcode].baseCost + p.fcCosts[msgcode].reqCost*uint64(amount)
|
costs := p.fcCosts[msgcode]
|
||||||
sizeCost := p.fcCosts[msgcode].baseCost + p.fcCosts[msgcode].reqCost*uint64(size)/txSizeCostLimit
|
if costs == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
cost := costs.baseCost + costs.reqCost*uint64(amount)
|
||||||
|
sizeCost := costs.baseCost + costs.reqCost*uint64(size)/txSizeCostLimit
|
||||||
if sizeCost > cost {
|
if sizeCost > cost {
|
||||||
cost = sizeCost
|
cost = sizeCost
|
||||||
}
|
}
|
||||||
@ -516,6 +524,20 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis
|
|||||||
p.fcServerParams = params
|
p.fcServerParams = params
|
||||||
p.fcServer = flowcontrol.NewServerNode(params)
|
p.fcServer = flowcontrol.NewServerNode(params)
|
||||||
p.fcCosts = MRC.decode()
|
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}
|
p.headInfo = &announceData{Td: rTd, Hash: rHash, Number: rNum}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user