Skip to content

les, p2p/discv5: implement in-protocol payment#20341

Closed
zsfelfoldi wants to merge 25 commits intoethereum:masterfrom
zsfelfoldi:lestalk
Closed

les, p2p/discv5: implement in-protocol payment#20341
zsfelfoldi wants to merge 25 commits intoethereum:masterfrom
zsfelfoldi:lestalk

Conversation

@zsfelfoldi
Copy link
Copy Markdown
Contributor

This is a WIP PR for the in-protocol payment logic. Currently implemented features:

  • a discv5 extension for protocol negotiation ("talkRequest/talkResponse") and a dummy handler for the "les" domain
  • a new clientPool function for calculating the necessary additional amount of token balance in order to fulfill a requested connection/capacity update (the core logic is also deduplicated)

Coming soon:

  • new LES/4 and "LESTALK" UDP messages necessary for payment processing and price negotiation
  • glue logic for the token sale and payment receiver modules

Comment thread les/balance.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add the function description and relative unit tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

func (bt *balanceTracker) budget(targetPriority int64, targetCapacity uint64, after time.Duration)  uint64 {
	current := bt.balanceToPriority(bt.balance)
	if targetPriority >= current {
		if bt.negTimeFactor == 0 {
			return 0
		}
		diff :=  time.Duration(float64(targetPriority - current)/bt.negTimeFactor)
		if diff >= after {
			return 0
		}
		after -= diff
	}
	// We have to cover the connection expense by positive balance.
	if targetPriority >= 0 {
		targetPriority = -1
	}
	budget := uint64(float64(^targetPriority)*float64(targetCapacity) + float64(after)*bt.timeFactor)
	if budget >= maxBalance {
		return math.MaxUint64 // target not reachable
	}
	if budget > bt.balance.pos {
		return budget - bt.balance.pos
	}
	return 0
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just open a question here. So we can only guarantee the idle connection by the budget. However request can also cost a lot. TBH I think request cost should be much higher than connection cost.

So should we consider the estimated request cost when we calculate the budget? Although we can never have a correct number.

Comment thread les/server_handler.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does it mean servers can only receive the UDP packet and then reply?
So in the following scenarios:

  • Client should ask the current token price
  • Client should ask the current balance to determine whether they need to buy more tokens for stable connection

@zsfelfoldi
Copy link
Copy Markdown
Contributor Author

Superseded by #20517

@zsfelfoldi zsfelfoldi closed this Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants