@@ -341,6 +341,7 @@ type serverPeer struct {
341
341
onlyAnnounce bool // The flag whether the server sends announcement only.
342
342
chainSince , chainRecent uint64 // The range of chain server peer can serve.
343
343
stateSince , stateRecent uint64 // The range of state server peer can serve.
344
+ serveTxLookup bool // The server peer can serve tx lookups.
344
345
345
346
// Advertised checkpoint fields
346
347
checkpointNumber uint64 // The block height which the checkpoint is registered.
@@ -628,6 +629,18 @@ func (p *serverPeer) Handshake(genesis common.Hash, forkid forkid.ID, forkFilter
628
629
if recv .get ("txRelay" , nil ) != nil {
629
630
p .onlyAnnounce = true
630
631
}
632
+ if p .version >= lpv4 {
633
+ var recentTx uint
634
+ if err := recv .get ("recentTxLookup" , & recentTx ); err != nil {
635
+ return err
636
+ }
637
+ // Note: in the current version we only consider the tx index service useful
638
+ // if it is unlimited. This can be made configurable in the future.
639
+ p .serveTxLookup = recentTx == txIndexUnlimited
640
+ } else {
641
+ p .serveTxLookup = true
642
+ }
643
+
631
644
if p .onlyAnnounce && ! p .trusted {
632
645
return errResp (ErrUselessPeer , "peer cannot serve requests" )
633
646
}
@@ -969,6 +982,20 @@ func (p *clientPeer) freezeClient() {
969
982
// Handshake executes the les protocol handshake, negotiating version number,
970
983
// network IDs, difficulties, head and genesis blocks.
971
984
func (p * clientPeer ) Handshake (td * big.Int , head common.Hash , headNum uint64 , genesis common.Hash , forkID forkid.ID , forkFilter forkid.Filter , server * LesServer ) error {
985
+ recentTx := server .handler .blockchain .TxLookupLimit ()
986
+ if recentTx != txIndexUnlimited {
987
+ if recentTx < blockSafetyMargin {
988
+ recentTx = txIndexDisabled
989
+ } else {
990
+ recentTx -= blockSafetyMargin - txIndexRecentOffset
991
+ }
992
+ }
993
+ if server .config .UltraLightOnlyAnnounce {
994
+ recentTx = txIndexDisabled
995
+ }
996
+ if recentTx != txIndexUnlimited && p .version < lpv4 {
997
+ return errors .New ("Cannot serve old clients without a complete tx index" )
998
+ }
972
999
// Note: clientPeer.headInfo should contain the last head announced to the client by us.
973
1000
// The values announced in the handshake are dummy values for compatibility reasons and should be ignored.
974
1001
p .headInfo = blockInfo {Hash : head , Number : headNum , Td : td }
@@ -981,13 +1008,16 @@ func (p *clientPeer) Handshake(td *big.Int, head common.Hash, headNum uint64, ge
981
1008
982
1009
// If local ethereum node is running in archive mode, advertise ourselves we have
983
1010
// all version state data. Otherwise only recent state is available.
984
- stateRecent := uint64 (core .TriesInMemory - 4 )
1011
+ stateRecent := uint64 (core .TriesInMemory - blockSafetyMargin )
985
1012
if server .archiveMode {
986
1013
stateRecent = 0
987
1014
}
988
1015
* lists = (* lists ).add ("serveRecentState" , stateRecent )
989
1016
* lists = (* lists ).add ("txRelay" , nil )
990
1017
}
1018
+ if p .version >= lpv4 {
1019
+ * lists = (* lists ).add ("recentTxLookup" , recentTx )
1020
+ }
991
1021
* lists = (* lists ).add ("flowControl/BL" , server .defParams .BufLimit )
992
1022
* lists = (* lists ).add ("flowControl/MRR" , server .defParams .MinRecharge )
993
1023
0 commit comments