Skip to content

Commit c6f93c3

Browse files
committed
les: add meaningful constants for recentTxIndex handshake field
1 parent 5b6fe05 commit c6f93c3

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

les/peer.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,9 @@ func (p *serverPeer) Handshake(genesis common.Hash, forkid forkid.ID, forkFilter
627627
if err := recv.get("recentTxLookup", &recentTx); err != nil {
628628
return err
629629
}
630-
p.serveTxLookup = recentTx == 0
630+
// Note: in the current version we only consider the tx index service useful
631+
// if it is unlimited. This can be made configurable in the future.
632+
p.serveTxLookup = recentTx == txIndexUnlimited
631633
} else {
632634
p.serveTxLookup = true
633635
}
@@ -974,17 +976,17 @@ func (p *clientPeer) freezeClient() {
974976
// network IDs, difficulties, head and genesis blocks.
975977
func (p *clientPeer) Handshake(td *big.Int, head common.Hash, headNum uint64, genesis common.Hash, forkID forkid.ID, forkFilter forkid.Filter, server *LesServer) error {
976978
recentTx := server.handler.blockchain.TxLookupLimit()
977-
if recentTx > 0 { // 0 means no limit (all txs available)
978-
if recentTx <= blockSafetyMargin {
979-
recentTx = 1 // 1 means tx lookup is not served at all
979+
if recentTx != txIndexUnlimited {
980+
if recentTx < blockSafetyMargin {
981+
recentTx = txIndexDisabled
980982
} else {
981-
recentTx -= blockSafetyMargin
983+
recentTx -= blockSafetyMargin - txIndexRecentOffset
982984
}
983985
}
984986
if server.config.UltraLightOnlyAnnounce {
985-
recentTx = 1
987+
recentTx = txIndexDisabled
986988
}
987-
if recentTx != 0 && p.version < lpv4 {
989+
if recentTx != txIndexUnlimited && p.version < lpv4 {
988990
return errors.New("Cannot serve old clients without a complete tx index")
989991
}
990992
// Note: clientPeer.headInfo should contain the last head announced to the client by us.

les/protocol.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ const (
5151
NetworkId = 1
5252
ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message
5353
blockSafetyMargin = 4 // safety margin applied to block ranges specified relative to head block
54+
55+
txIndexUnlimited = 0 // this value in the "recentTxLookup" handshake field means the entire tx index history is served
56+
txIndexDisabled = 1 // this value means tx index is not served at all
57+
txIndexRecentOffset = 1 // txIndexRecentOffset + N in the handshake field means then tx index of the last N blocks is supported
5458
)
5559

5660
// les protocol message codes

0 commit comments

Comments
 (0)