Skip to content

Instantly share code, notes, and snippets.

View rjl493456442's full-sized avatar
🐢

rjl493456442

🐢
View GitHub Profile

Abstract flow control model

Now LES protocol uses token bucket for throttling as the flow control mechanism. Basically the mechanism is:

  • Each les client will be assigned a capacity which represents the allowance of les client to use les server resources

    • Free client will be assigned a minimal capacity
    • Paid client can be assigned a higher capacity
  • Each request will be metered, the cost mostly depends on the serving time

P2P payment network setup strategies

Client pays first

  • Light client gets a slot for 3 minute free trial
  • Light client choose to pay, make the deposit and then send the first payment
  • Whenever the light client is almost out of balance, server will send him a message to get the second payment in order to keep the slot!
    • If light client rejects to pay, it will lose the slot very soon since there is already negative balance accumulated, then it basically has to wait a few hours to get another connection slot
    • If light client accepts to pay, it will reown the slot for the next a few hours based on the amount it pays.
  • All in all, it's Pay before delivery business model

Payment channel instructions

Initiailize your clef configurations

Initialization

note: you need to create 2 separate config directories for both client and server.

clef init --configdir <config_path>
pragma solidity ^0.5.12;
/**
* @title AccountBook
* @author Gary Rong<garyrong@ethereum.org>
* @dev Implementation of the account book which les server can use to
* @dev process micropayments from customers.
*/
contract AccountBook {
/*
`{"id": 1, "method": "admin_subscribe", "params": ["peerEvents"]}`
`cat request.json - | nc -U /home/user/.ethereum/geth.ipc`
@rjl493456442
rjl493456442 / payment.md
Last active November 8, 2019 06:13
In-built micropayment for LES

In-built micropayment for LES

Clients are allowed for free-trial connection from the server. Since server needs to win the reputation before earning money from clients.

During the connection, server can always send some announcements to clients via LNR. Basically LNR can include arbitrary information necessary, e.g. current price(wei per token), remaining free-trial time, service token contract address.

Regarding the remaining free-trial time, it doesn't mean: (1) free clients are still guarantee to keep connection at that much time. (2) free clients will be kicked out after the free-trial. It only shows that free client with very high chance to be kicked out after free-trial.

By the way, do we need to consider a minimal free-trial connection time? During this time, connection are promised.

@rjl493456442
rjl493456442 / payment.md
Created November 8, 2019 05:55
In-built micropayment for LES

In-built micropayment for LES

Clients are allowed for free-trial connection from the server. Since server needs to win the reputation

before earning money from clients.

During the connection, server can always send some announcements to clients via LNR. Basically LNR

can include arbitrary information necessary, e.g. current price(wei per token), remaining free-trial time, service token contract address.

Capacity of les server
1. Serve headers
serve_header_since: 0x1000000
2. Serve chain
1. body(txs and uncles)
2. receipts(logs)
serve_chain_since: 0x1000000
{
"name": "istanbul",
"dataDir": "istanbul",
"engine": {
"Ethash": {
"params": {
"minimumDifficulty": "0x20000",
"difficultyBoundDivisor": "0x800",
"durationLimit": "0xd",
"blockReward": {
@rjl493456442
rjl493456442 / lesfetcher.go
Created October 17, 2019 07:22
les fetcher
// Copyright 2019 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of