-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
p2p accounting #17951
p2p accounting #17951
Conversation
Maybe I am missing something, but it seems we are introducing a bunch of interfaces ( I am afraid that without concrete implementations we might be choosing the wrong abstractions. The simulation tests kinda show how these |
} | ||
|
||
//record some metrics | ||
func (ah *Accounting) doMetrics(price int64, size uint32, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better name for this would be bookkeeping
or something like this. doMetrics
sounds like we are not keeping financial records, but rather measuring for the purpose of monitoring the system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but rather measuring for the purpose of monitoring the system.
This is in fact what we are doing here
c4d088c
to
01470a7
Compare
This PR introduces the first phase of p2p accounting for message exchange, which forms the basis for swarm's incentivization layer and accounting.
This current implementation only does the accounting part, no cryptoeconomic features are implemented yet (price negotiation, claim settling, etc.). This means this implementation just keeps track of how many units are exchanged between nodes and maintains a balance with them.
Basic design:
p2p/protocols/accounting.go
defines the basic interfaces:Balance
defines the actual accounting interface. It only has anAdd
function. This function will be called with a peer instance and an amount. If the amount is negative, then the local node is being debited, if it is positive, the local node is being credited.Prices
is an interface that defines how prices are being expected. Every accounted protocol should provide an implementation, and return a Price structure for every message for which it requires accounting. This struct contains aValue uint64
field, which represents the price for that message. ThePerBytes bool
field specifies if the message needs accounting based on the message size, and thePayer Payer
field defines who is to be charged for a message, if either aSender
or theReceiver
.An accounted protocol needs to provide a
Hook
inside itsSpec
, where it defines its messages. TheHook
contains aBalance
and aPrices
interface, which allows the messaging infrastructure to transparently do the accounting.