-
Notifications
You must be signed in to change notification settings - Fork 31
Bandwidth payments #9
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
Merged
Merged
Changes from 25 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
6a057a2
Add missing test
markspanbroek b8e5f19
Fix warnings
markspanbroek 9fb50a3
Remove duplicate requirement
markspanbroek 3daa26f
Add package nim-nitro
markspanbroek 8e1995a
Workaround no longer necessary
markspanbroek bd68f2c
Remove deprecated libp2p import
markspanbroek e55ac4e
Add nitro wallet to BitswapNetwork
markspanbroek 59e19ef
Add package questionable
markspanbroek 3a9066a
protobuf message for bandwidth pricing
markspanbroek 70473aa
Add package upraises
markspanbroek ac2c7c2
Ensure that encoding of pricing doesn't raise
markspanbroek c78b460
protobuf message for state channel updates
markspanbroek 8465660
Fix tests on 32 bit platforms
markspanbroek 06766f2
Move pricing and payments into bitswap protobuf message
markspanbroek c5ee2d3
Fix typo
markspanbroek acaa372
Add handler for pricing messages
markspanbroek 0491558
Add handler for payment messages
markspanbroek 1afdf7a
Broadcast pricing
markspanbroek d0aec00
Broadcast payment
markspanbroek ba41405
Exchange pricing when connecting to new peer
markspanbroek a95e4b0
Remove dead code
markspanbroek 6eabd82
Revert "Add nitro wallet to BitswapNetwork"
markspanbroek 835357b
Add nitro wallet to BitswapEngine
markspanbroek 670b9fb
Move peer context into its own module
markspanbroek fd5d370
Update to latest versions of nitro and questionable
markspanbroek b75eed2
Add proc to engine that pays peers for bytes
markspanbroek 6535fd8
Engine sends payments for received blocks
markspanbroek a1deed8
Fix build failure on 32 bit platforms
markspanbroek 56995dc
Update to latest versions of nitro and questionable
markspanbroek 254bca9
Use reference semantics for wallets
markspanbroek 4b716d2
Receive payments for blocks that were sent
markspanbroek 10cef2d
Hard-code asset address
markspanbroek 4a21d30
Add pricing to block presence messages
markspanbroek ddbe304
Add block prices to peer context
markspanbroek a7698e1
Update to version 0.9.1 of questionable
markspanbroek fae61fb
Simplify test
markspanbroek 57894f0
Simplify
markspanbroek 6bc537d
Send block prices
markspanbroek 5488ef0
Pay per-block price instead of per-peer price
markspanbroek 66d5172
Remove debt ratio
markspanbroek b3fbe89
Remove double bookkeeping in peerHave and peerPrices
markspanbroek 8ef6787
Replace pricing exchange by account exchange
markspanbroek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import std/sequtils | ||
| import pkg/libp2p | ||
| import pkg/chronos | ||
| import pkg/questionable | ||
| import ./protobuf/bitswap | ||
| import ./protobuf/payments | ||
|
|
||
| type | ||
| BitswapPeerCtx* = ref object of RootObj | ||
| id*: PeerID | ||
| peerHave*: seq[Cid] # remote peers have lists | ||
| peerWants*: seq[Entry] # remote peers want lists | ||
| bytesSent*: int # bytes sent to remote | ||
| bytesRecv*: int # bytes received from remote | ||
| exchanged*: int # times peer has exchanged with us | ||
| lastExchange*: Moment # last time peer has exchanged with us | ||
| pricing*: ?Pricing # optional bandwidth price for this peer | ||
|
|
||
| proc contains*(a: openArray[BitswapPeerCtx], b: PeerID): bool = | ||
| ## Convenience method to check for peer prepense | ||
| ## | ||
|
|
||
| a.anyIt( it.id == b ) | ||
|
|
||
| proc debtRatio*(b: BitswapPeerCtx): float = | ||
| b.bytesSent / (b.bytesRecv + 1) | ||
|
|
||
| proc `<`*(a, b: BitswapPeerCtx): bool = | ||
| a.debtRatio < b.debtRatio | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import pkg/protobuf_serialization | ||
| import pkg/stew/byteutils | ||
| import pkg/nitro | ||
| import pkg/questionable | ||
| import pkg/upraises | ||
| import ./bitswap | ||
|
|
||
| export PricingMessage | ||
| export StateChannelUpdate | ||
|
|
||
| export nitro | ||
|
|
||
| push: {.upraises: [].} | ||
|
|
||
| type | ||
| Pricing* = object | ||
| address*: EthAddress | ||
| asset*: EthAddress | ||
| price*: UInt256 | ||
|
|
||
| func init*(_: type PricingMessage, pricing: Pricing): PricingMessage = | ||
| PricingMessage( | ||
| address: @(pricing.address.toArray), | ||
| asset: @(pricing.asset.toArray), | ||
| price: @(pricing.price.toBytesBE) | ||
| ) | ||
|
|
||
| func parse(_: type EthAddress, bytes: seq[byte]): ?EthAddress = | ||
| var address: array[20, byte] | ||
| if bytes.len != address.len: | ||
| return EthAddress.none | ||
| for i in 0..<address.len: | ||
| address[i] = bytes[i] | ||
| EthAddress(address).some | ||
|
|
||
| func parse(_: type UInt256, bytes: seq[byte]): ?UInt256 = | ||
| if bytes.len > 32: | ||
| return UInt256.none | ||
| UInt256.fromBytesBE(bytes).some | ||
|
|
||
| func init*(_: type Pricing, message: PricingMessage): ?Pricing = | ||
| let address = EthAddress.parse(message.address) | ||
| let asset = EThAddress.parse(message.asset) | ||
| let price = UInt256.parse(message.price) | ||
| if address.isNone or asset.isNone or price.isNone: | ||
| return Pricing.none | ||
| Pricing(address: address.get, asset: asset.get, price: price.get).some | ||
|
|
||
| func init*(_: type StateChannelUpdate, state: SignedState): StateChannelUpdate = | ||
| StateChannelUpdate(update: state.toJson.toBytes) | ||
|
|
||
| proc init*(_: type SignedState, update: StateChannelUpdate): ?SignedState = | ||
| SignedState.fromJson(string.fromBytes(update.update)) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.