Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

les: les/4 minimalistic version #21909

Merged
merged 4 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1491,10 +1491,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
CheckExclusive(ctx, LegacyLightServFlag, LightServeFlag, SyncModeFlag, "light")
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
CheckExclusive(ctx, GCModeFlag, "archive", TxLookupLimitFlag)
// todo(rjl493456442) make it available for les server
// Ancient tx indices pruning is not available for les server now
// since light client relies on the server for transaction status query.
CheckExclusive(ctx, LegacyLightServFlag, LightServeFlag, TxLookupLimitFlag)
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
if (ctx.GlobalIsSet(LegacyLightServFlag.Name) || ctx.GlobalIsSet(LightServeFlag.Name)) && ctx.GlobalIsSet(TxLookupLimitFlag.Name) {
log.Warn("LES server cannot serve old transaction status and cannot connect below les/4 protocol version if transaction lookup index is limited")
}
var ks *keystore.KeyStore
if keystores := stack.AccountManager().Backends(keystore.KeyStoreType); len(keystores) > 0 {
ks = keystores[0].(*keystore.KeyStore)
Expand Down
2 changes: 1 addition & 1 deletion les/odr_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func (r *TxStatusRequest) GetCost(peer *serverPeer) uint64 {

// CanSend tells if a certain peer is suitable for serving the given request
func (r *TxStatusRequest) CanSend(peer *serverPeer) bool {
return peer.version >= lpv2
return peer.serveTxLookup
}

// Request sends an ODR request to the LES network (implementation of LesOdrRequest)
Expand Down
30 changes: 29 additions & 1 deletion les/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ type serverPeer struct {
onlyAnnounce bool // The flag whether the server sends announcement only.
chainSince, chainRecent uint64 // The range of chain server peer can serve.
stateSince, stateRecent uint64 // The range of state server peer can serve.
serveTxLookup bool // The server peer can serve tx lookups.

// Advertised checkpoint fields
checkpointNumber uint64 // The block height which the checkpoint is registered.
Expand Down Expand Up @@ -621,6 +622,16 @@ func (p *serverPeer) Handshake(genesis common.Hash, forkid forkid.ID, forkFilter
if recv.get("txRelay", nil) != nil {
p.onlyAnnounce = true
}
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 @@ -962,6 +973,20 @@ func (p *clientPeer) freezeClient() {
// Handshake executes the les protocol handshake, negotiating version number,
// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put these number in the protocol file and use the constants? It's a bit weird to hardcode the number here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry one more nitpicks, can we replace the 1 with a constant? It's better to define in the protocol that 1 means disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if recentTx <= blockSafetyMargin {
recentTx = 1 // 1 means tx lookup is not served at all
} else {
recentTx -= blockSafetyMargin
}
}
if server.config.UltraLightOnlyAnnounce {
recentTx = 1
}
if recentTx != 0 && 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.
// The values announced in the handshake are dummy values for compatibility reasons and should be ignored.
p.headInfo = blockInfo{Hash: head, Number: headNum, Td: td}
Expand All @@ -974,13 +999,16 @@ 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
}
*lists = (*lists).add("serveRecentState", stateRecent)
*lists = (*lists).add("txRelay", nil)
}
if p.version >= lpv4 {
*lists = (*lists).add("recentTxLookup", recentTx)
}
*lists = (*lists).add("flowControl/BL", server.defParams.BufLimit)
*lists = (*lists).add("flowControl/MRR", server.defParams.MinRecharge)

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