Skip to content

Commit

Permalink
les: more small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zsfelfoldi committed Dec 10, 2020
1 parent 07b3296 commit 5b6fe05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions les/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,15 @@ func (p *serverPeer) Handshake(genesis common.Hash, forkid forkid.ID, forkFilter
if recv.get("txRelay", nil) != nil {
p.onlyAnnounce = true
}
var recentTx uint
p.serveTxLookup = recv.get("recentTxLookup", &recentTx) != nil || recentTx == 0
if p.version >= lpv4 {
var recentTx uint
if err := recv.get("recentTxLookup", &recentTx); err != nil {
return err
}
p.serveTxLookup = recentTx == 0
} else {
p.serveTxLookup = true
}

if p.onlyAnnounce && !p.trusted {
return errResp(ErrUselessPeer, "peer cannot serve requests")
Expand Down Expand Up @@ -968,10 +975,10 @@ func (p *clientPeer) freezeClient() {
func (p *clientPeer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis common.Hash, forkID forkid.ID, forkFilter forkid.Filter, server *LesServer) error {
recentTx := server.handler.blockchain.TxLookupLimit()
if recentTx > 0 { // 0 means no limit (all txs available)
if recentTx <= 3 {
if recentTx <= blockSafetyMargin {
recentTx = 1 // 1 means tx lookup is not served at all
} else {
recentTx -= 3 // safety margin
recentTx -= blockSafetyMargin
}
}
if server.config.UltraLightOnlyAnnounce {
Expand All @@ -992,7 +999,7 @@ func (p *clientPeer) Handshake(td *big.Int, head common.Hash, headNum uint64, ge

// If local ethereum node is running in archive mode, advertise ourselves we have
// all version state data. Otherwise only recent state is available.
stateRecent := uint64(core.TriesInMemory - 4)
stateRecent := uint64(core.TriesInMemory - blockSafetyMargin)
if server.archiveMode {
stateRecent = 0
}
Expand Down
1 change: 1 addition & 0 deletions les/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var ProtocolLengths = map[uint]uint64{lpv2: 22, lpv3: 24, lpv4: 24}
const (
NetworkId = 1
ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message
blockSafetyMargin = 4 // safety margin applied to block ranges specified relative to head block
)

// les protocol message codes
Expand Down

0 comments on commit 5b6fe05

Please sign in to comment.