Skip to content

Commit

Permalink
les: add meaningful constants for recentTxIndex handshake field
Browse files Browse the repository at this point in the history
  • Loading branch information
zsfelfoldi committed Dec 15, 2020
1 parent 5b6fe05 commit c6f93c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 9 additions & 7 deletions les/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,9 @@ func (p *serverPeer) Handshake(genesis common.Hash, forkid forkid.ID, forkFilter
if err := recv.get("recentTxLookup", &recentTx); err != nil {
return err
}
p.serveTxLookup = recentTx == 0
// Note: in the current version we only consider the tx index service useful
// if it is unlimited. This can be made configurable in the future.
p.serveTxLookup = recentTx == txIndexUnlimited
} else {
p.serveTxLookup = true
}
Expand Down Expand Up @@ -974,17 +976,17 @@ func (p *clientPeer) freezeClient() {
// network IDs, difficulties, head and genesis blocks.
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 <= blockSafetyMargin {
recentTx = 1 // 1 means tx lookup is not served at all
if recentTx != txIndexUnlimited {
if recentTx < blockSafetyMargin {
recentTx = txIndexDisabled
} else {
recentTx -= blockSafetyMargin
recentTx -= blockSafetyMargin - txIndexRecentOffset
}
}
if server.config.UltraLightOnlyAnnounce {
recentTx = 1
recentTx = txIndexDisabled
}
if recentTx != 0 && p.version < lpv4 {
if recentTx != txIndexUnlimited && p.version < lpv4 {
return errors.New("Cannot serve old clients without a complete tx index")
}
// Note: clientPeer.headInfo should contain the last head announced to the client by us.
Expand Down
4 changes: 4 additions & 0 deletions les/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ 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

txIndexUnlimited = 0 // this value in the "recentTxLookup" handshake field means the entire tx index history is served
txIndexDisabled = 1 // this value means tx index is not served at all
txIndexRecentOffset = 1 // txIndexRecentOffset + N in the handshake field means then tx index of the last N blocks is supported
)

// les protocol message codes
Expand Down

0 comments on commit c6f93c3

Please sign in to comment.