@@ -341,6 +341,7 @@ type serverPeer struct {
341341 onlyAnnounce bool // The flag whether the server sends announcement only.
342342 chainSince , chainRecent uint64 // The range of chain server peer can serve.
343343 stateSince , stateRecent uint64 // The range of state server peer can serve.
344+ serveTxLookup bool // The server peer can serve tx lookups.
344345
345346 // Advertised checkpoint fields
346347 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
628629 if recv .get ("txRelay" , nil ) != nil {
629630 p .onlyAnnounce = true
630631 }
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+
631644 if p .onlyAnnounce && ! p .trusted {
632645 return errResp (ErrUselessPeer , "peer cannot serve requests" )
633646 }
@@ -969,6 +982,20 @@ func (p *clientPeer) freezeClient() {
969982// Handshake executes the les protocol handshake, negotiating version number,
970983// network IDs, difficulties, head and genesis blocks.
971984func (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+ }
972999 // Note: clientPeer.headInfo should contain the last head announced to the client by us.
9731000 // The values announced in the handshake are dummy values for compatibility reasons and should be ignored.
9741001 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
9811008
9821009 // If local ethereum node is running in archive mode, advertise ourselves we have
9831010 // all version state data. Otherwise only recent state is available.
984- stateRecent := uint64 (core .TriesInMemory - 4 )
1011+ stateRecent := uint64 (core .TriesInMemory - blockSafetyMargin )
9851012 if server .archiveMode {
9861013 stateRecent = 0
9871014 }
9881015 * lists = (* lists ).add ("serveRecentState" , stateRecent )
9891016 * lists = (* lists ).add ("txRelay" , nil )
9901017 }
1018+ if p .version >= lpv4 {
1019+ * lists = (* lists ).add ("recentTxLookup" , recentTx )
1020+ }
9911021 * lists = (* lists ).add ("flowControl/BL" , server .defParams .BufLimit )
9921022 * lists = (* lists ).add ("flowControl/MRR" , server .defParams .MinRecharge )
9931023
0 commit comments