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

Currency primary key #910

Closed
kilrau opened this issue Apr 26, 2019 · 4 comments · Fixed by #1055
Closed

Currency primary key #910

kilrau opened this issue Apr 26, 2019 · 4 comments · Fixed by #1055
Assignees
Labels
database Database related issues P1 top priority

Comments

@kilrau
Copy link
Contributor

kilrau commented Apr 26, 2019

How to generically set a unique primary key for coins & ERC20 tokens to prevent intentionally or unintentionally tricking a trading partner into thinking my contract is WETH on xud p2p message layer, even though it's not. Swaps will fail in the end, but that would be annoying.

Short-term:
Use token contract address as unique identifier for ERC20.

Long-term:
A way might be to call getinfo from lnd/raiden and use this as chain id. Token chains like ethereum additionally need the token address (#897) to be part of the primary key.

@kilrau kilrau added the database Database related issues label Apr 26, 2019
@kilrau kilrau added this to the 1.0.0-sprint.15 milestone Apr 26, 2019
@kilrau kilrau assigned ghost , sangaman and kilrau Apr 26, 2019
@kilrau kilrau changed the title [Discussion] Coin primary key [Discussion] Currency primary key Apr 27, 2019
@ghost ghost mentioned this issue May 7, 2019
@kilrau
Copy link
Contributor Author

kilrau commented May 7, 2019

Related: #893, let's discuss it after milestone 15

@kilrau kilrau modified the milestones: 1.0.0-sprint.15, 1.0.0, post-1.0.0 May 8, 2019
@kilrau kilrau added the P1 top priority label May 8, 2019
@kilrau kilrau changed the title [Discussion] Currency primary key Currency primary key May 8, 2019
@kilrau kilrau mentioned this issue May 8, 2019
29 tasks
@kilrau
Copy link
Contributor Author

kilrau commented May 8, 2019

If you are convinced by our code, that swapping the wrong token address can never happen, I suggest to move this to post-1.0.0 @erkarl

@kilrau kilrau removed their assignment May 21, 2019
@kilrau
Copy link
Contributor Author

kilrau commented May 21, 2019

As per call @sangaman , define details today since these are breaking changes which we want to have in 1.0.0

@kilrau kilrau modified the milestones: post-1.0.0, 1.0.0-beta Jun 7, 2019
@kilrau
Copy link
Contributor Author

kilrau commented Jun 7, 2019

Mistakenly had this in post-1.0.0

@kilrau kilrau removed this from the 1.0.0-beta milestone Jun 11, 2019
@kilrau kilrau assigned sangaman and unassigned sangaman and ghost Jun 11, 2019
sangaman added a commit that referenced this issue Jun 24, 2019
At a high level, this adds a concept of a token identifier for each
currency supported by xud that is consistent across the entire network.

"BTC" can mean mainnet tokens or testnet tokens (or simnet, etc...) and
can even be misconfigured to point to the LTC lightning network.
Meanwhile, Raiden ERC20 tokens refer to a particular token contract, and
there's no guarantee that peers won't be using different (and therefore
incompatible) contracts for the same currency such as WETH.

Here, we use an identifier to ensure peers are referring to the same
token as we are. For currencies that use lnd, the token identifier is
determined dynamically using the `chain` and `network` returned by lnd
on a `GetInfo` call. For example, BTC mainnet would be "bitcoin-mainnet"
and LTC testnet would be "litecoin-testnet". For currencies that use
Raiden, we use the token contract address as the identifier.

These token identifiers are shared with peers during the handshake and
on any subsequent node state updates. The p2p messaging format is
changed to accommodate this. This also drops static node values like
the `nodePubKey` and `version` from the node state p2p message, as these
values can not change mid-session for a peer.

A future improvement may be to detect and support discrepancies in the
currency symbol used by a peer for the same token. For example, a
peer that advertises "XBT" with a token identifier of "bitcoin-mainnet"
should be compatible with our "BTC" that also is identified as
"bitcoin-mainnet". This is not included in this commit as it would
require further refactoring and complexity.

Another follow-up may be creating a test suite for the `Peer` class or
refactoring it to move logic elsewhere (along with tests for that logic).
There is some logic around handling node state updates where information
regarding the peer's supported currencies may change that is currently
not tested.

Closes #910.

BREAKING CHANGE: Changed p2p messaging structure for `SessionInit`
and `NodeStateUpdate` packets.
sangaman added a commit that referenced this issue Jun 24, 2019
At a high level, this adds a concept of a token identifier for each
currency supported by xud that is consistent across the entire network.

"BTC" can mean mainnet tokens or testnet tokens (or simnet, etc...) and
can even be misconfigured to point to the LTC lightning network.
Meanwhile, Raiden ERC20 tokens refer to a particular token contract, and
there's no guarantee that peers won't be using different (and therefore
incompatible) contracts for the same currency such as WETH.

Here, we use an identifier to ensure peers are referring to the same
token as we are. For currencies that use lnd, the token identifier is
determined dynamically using the `chain` and `network` returned by lnd
on a `GetInfo` call. For example, BTC mainnet would be "bitcoin-mainnet"
and LTC testnet would be "litecoin-testnet". For currencies that use
Raiden, we use the token contract address as the identifier.

These token identifiers are shared with peers during the handshake and
on any subsequent node state updates. The p2p messaging format is
changed to accommodate this. This also drops static node values like
the `nodePubKey` and `version` from the node state p2p message, as these
values can not change mid-session for a peer.

A future improvement may be to detect and support discrepancies in the
currency symbol used by a peer for the same token. For example, a
peer that advertises "XBT" with a token identifier of "bitcoin-mainnet"
should be compatible with our "BTC" that also is identified as
"bitcoin-mainnet". This is not included in this commit as it would
require further refactoring and complexity.

Another follow-up may be creating a test suite for the `Peer` class or
refactoring it to move logic elsewhere (along with tests for that logic).
There is some logic around handling node state updates where information
regarding the peer's supported currencies may change that is currently
not tested.

Closes #910.

BREAKING CHANGE: Changed p2p messaging structure for `SessionInit`
and `NodeStateUpdate` packets.
sangaman added a commit that referenced this issue Jun 24, 2019
At a high level, this adds a concept of a token identifier for each
currency supported by xud that is consistent across the entire network.

"BTC" can mean mainnet tokens or testnet tokens (or simnet, etc...) and
can even be misconfigured to point to the LTC lightning network.
Meanwhile, Raiden ERC20 tokens refer to a particular token contract, and
there's no guarantee that peers won't be using different (and therefore
incompatible) contracts for the same currency such as WETH.

Here, we use an identifier to ensure peers are referring to the same
token as we are. For currencies that use lnd, the token identifier is
determined dynamically using the `chain` and `network` returned by lnd
on a `GetInfo` call. For example, BTC mainnet would be "bitcoin-mainnet"
and LTC testnet would be "litecoin-testnet". For currencies that use
Raiden, we use the token contract address as the identifier.

These token identifiers are shared with peers during the handshake and
on any subsequent node state updates. The p2p messaging format is
changed to accommodate this. This also drops static node values like
the `nodePubKey` and `version` from the node state p2p message, as these
values can not change mid-session for a peer.

A future improvement may be to detect and support discrepancies in the
currency symbol used by a peer for the same token. For example, a
peer that advertises "XBT" with a token identifier of "bitcoin-mainnet"
should be compatible with our "BTC" that also is identified as
"bitcoin-mainnet". This is not included in this commit as it would
require further refactoring and complexity.

Another follow-up may be creating a test suite for the `Peer` class or
refactoring it to move logic elsewhere (along with tests for that logic).
There is some logic around handling node state updates where information
regarding the peer's supported currencies may change that is currently
not tested.

Closes #910.

BREAKING CHANGE: Changed p2p messaging structure for `SessionInit`
and `NodeStateUpdate` packets.
sangaman added a commit that referenced this issue Jun 25, 2019
At a high level, this adds a concept of a token identifier for each
currency supported by xud that is consistent across the entire network.

"BTC" can mean mainnet tokens or testnet tokens (or simnet, etc...) and
can even be misconfigured to point to the LTC lightning network.
Meanwhile, Raiden ERC20 tokens refer to a particular token contract, and
there's no guarantee that peers won't be using different (and therefore
incompatible) contracts for the same currency such as WETH.

Here, we use an identifier to ensure peers are referring to the same
token as we are. For currencies that use lnd, the token identifier is
determined dynamically using the `chain` and `network` returned by lnd
on a `GetInfo` call. For example, BTC mainnet would be "bitcoin-mainnet"
and LTC testnet would be "litecoin-testnet". For currencies that use
Raiden, we use the token contract address as the identifier.

These token identifiers are shared with peers during the handshake and
on any subsequent node state updates. The p2p messaging format is
changed to accommodate this. This also drops static node values like
the `nodePubKey` and `version` from the node state p2p message, as these
values can not change mid-session for a peer.

A future improvement may be to detect and support discrepancies in the
currency symbol used by a peer for the same token. For example, a
peer that advertises "XBT" with a token identifier of "bitcoin-mainnet"
should be compatible with our "BTC" that also is identified as
"bitcoin-mainnet". This is not included in this commit as it would
require further refactoring and complexity.

Another follow-up may be creating a test suite for the `Peer` class or
refactoring it to move logic elsewhere (along with tests for that logic).
There is some logic around handling node state updates where information
regarding the peer's supported currencies may change that is currently
not tested.

Closes #910.

BREAKING CHANGE: Changed p2p messaging structure for `SessionInit`
and `NodeStateUpdate` packets.
sangaman added a commit that referenced this issue Jun 28, 2019
At a high level, this adds a concept of a token identifier for each
currency supported by xud that is consistent across the entire network.

"BTC" can mean mainnet tokens or testnet tokens (or simnet, etc...) and
can even be misconfigured to point to the LTC lightning network.
Meanwhile, Raiden ERC20 tokens refer to a particular token contract, and
there's no guarantee that peers won't be using different (and therefore
incompatible) contracts for the same currency such as WETH.

Here, we use an identifier to ensure peers are referring to the same
token as we are. For currencies that use lnd, the token identifier is
determined dynamically using the `chain` and `network` returned by lnd
on a `GetInfo` call. For example, BTC mainnet would be "bitcoin-mainnet"
and LTC testnet would be "litecoin-testnet". For currencies that use
Raiden, we use the token contract address as the identifier.

These token identifiers are shared with peers during the handshake and
on any subsequent node state updates. The p2p messaging format is
changed to accommodate this. This also drops static node values like
the `nodePubKey` and `version` from the node state p2p message, as these
values can not change mid-session for a peer.

A future improvement may be to detect and support discrepancies in the
currency symbol used by a peer for the same token. For example, a
peer that advertises "XBT" with a token identifier of "bitcoin-mainnet"
should be compatible with our "BTC" that also is identified as
"bitcoin-mainnet". This is not included in this commit as it would
require further refactoring and complexity.

Another follow-up may be creating a test suite for the `Peer` class or
refactoring it to move logic elsewhere (along with tests for that logic).
There is some logic around handling node state updates where information
regarding the peer's supported currencies may change that is currently
not tested.

Closes #910.

BREAKING CHANGE: Changed p2p messaging structure for `SessionInit`
and `NodeStateUpdate` packets.
sangaman added a commit that referenced this issue Jun 28, 2019
At a high level, this adds a concept of a token identifier for each
currency supported by xud that is consistent across the entire network.

"BTC" can mean mainnet tokens or testnet tokens (or simnet, etc...) and
can even be misconfigured to point to the LTC lightning network.
Meanwhile, Raiden ERC20 tokens refer to a particular token contract, and
there's no guarantee that peers won't be using different (and therefore
incompatible) contracts for the same currency such as WETH.

Here, we use an identifier to ensure peers are referring to the same
token as we are. For currencies that use lnd, the token identifier is
determined dynamically using the `chain` and `network` returned by lnd
on a `GetInfo` call. For example, BTC mainnet would be "bitcoin-mainnet"
and LTC testnet would be "litecoin-testnet". For currencies that use
Raiden, we use the token contract address as the identifier.

These token identifiers are shared with peers during the handshake and
on any subsequent node state updates. The p2p messaging format is
changed to accommodate this. This also drops static node values like
the `nodePubKey` and `version` from the node state p2p message, as these
values can not change mid-session for a peer.

A future improvement may be to detect and support discrepancies in the
currency symbol used by a peer for the same token. For example, a
peer that advertises "XBT" with a token identifier of "bitcoin-mainnet"
should be compatible with our "BTC" that also is identified as
"bitcoin-mainnet". This is not included in this commit as it would
require further refactoring and complexity.

Another follow-up may be creating a test suite for the `Peer` class or
refactoring it to move logic elsewhere (along with tests for that logic).
There is some logic around handling node state updates where information
regarding the peer's supported currencies may change that is currently
not tested.

Closes #910.

BREAKING CHANGE: Changed p2p messaging structure for `SessionInit`
and `NodeStateUpdate` packets.
sangaman added a commit that referenced this issue Jun 28, 2019
At a high level, this adds a concept of a token identifier for each
currency supported by xud that is consistent across the entire network.

"BTC" can mean mainnet tokens or testnet tokens (or simnet, etc...) and
can even be misconfigured to point to the LTC lightning network.
Meanwhile, Raiden ERC20 tokens refer to a particular token contract, and
there's no guarantee that peers won't be using different (and therefore
incompatible) contracts for the same currency such as WETH.

Here, we use an identifier to ensure peers are referring to the same
token as we are. For currencies that use lnd, the token identifier is
determined dynamically using the `chain` and `network` returned by lnd
on a `GetInfo` call. For example, BTC mainnet would be "bitcoin-mainnet"
and LTC testnet would be "litecoin-testnet". For currencies that use
Raiden, we use the token contract address as the identifier.

These token identifiers are shared with peers during the handshake and
on any subsequent node state updates. The p2p messaging format is
changed to accommodate this. This also drops static node values like
the `nodePubKey` and `version` from the node state p2p message, as these
values can not change mid-session for a peer.

A future improvement may be to detect and support discrepancies in the
currency symbol used by a peer for the same token. For example, a
peer that advertises "XBT" with a token identifier of "bitcoin-mainnet"
should be compatible with our "BTC" that also is identified as
"bitcoin-mainnet". This is not included in this commit as it would
require further refactoring and complexity.

Another follow-up may be creating a test suite for the `Peer` class or
refactoring it to move logic elsewhere (along with tests for that logic).
There is some logic around handling node state updates where information
regarding the peer's supported currencies may change that is currently
not tested.

Closes #910.

BREAKING CHANGE: Changed p2p messaging structure for `SessionInit`
and `NodeStateUpdate` packets.
sangaman added a commit that referenced this issue Jun 28, 2019
At a high level, this adds a concept of a token identifier for each
currency supported by xud that is consistent across the entire network.

"BTC" can mean mainnet tokens or testnet tokens (or simnet, etc...) and
can even be misconfigured to point to the LTC lightning network.
Meanwhile, Raiden ERC20 tokens refer to a particular token contract, and
there's no guarantee that peers won't be using different (and therefore
incompatible) contracts for the same currency such as WETH.

Here, we use an identifier to ensure peers are referring to the same
token as we are. For currencies that use lnd, the token identifier is
determined dynamically using the `chain` and `network` returned by lnd
on a `GetInfo` call. For example, BTC mainnet would be "bitcoin-mainnet"
and LTC testnet would be "litecoin-testnet". For currencies that use
Raiden, we use the token contract address as the identifier.

These token identifiers are shared with peers during the handshake and
on any subsequent node state updates. The p2p messaging format is
changed to accommodate this. This also drops static node values like
the `nodePubKey` and `version` from the node state p2p message, as these
values can not change mid-session for a peer.

A future improvement may be to detect and support discrepancies in the
currency symbol used by a peer for the same token. For example, a
peer that advertises "XBT" with a token identifier of "bitcoin-mainnet"
should be compatible with our "BTC" that also is identified as
"bitcoin-mainnet". This is not included in this commit as it would
require further refactoring and complexity.

Another follow-up may be creating a test suite for the `Peer` class or
refactoring it to move logic elsewhere (along with tests for that logic).
There is some logic around handling node state updates where information
regarding the peer's supported currencies may change that is currently
not tested.

Closes #910.

BREAKING CHANGE: Changed p2p messaging structure for `SessionInit`
and `NodeStateUpdate` packets.
sangaman added a commit that referenced this issue Jul 1, 2019
At a high level, this adds a concept of a token identifier for each
currency supported by xud that is consistent across the entire network.

"BTC" can mean mainnet tokens or testnet tokens (or simnet, etc...) and
can even be misconfigured to point to the LTC lightning network.
Meanwhile, Raiden ERC20 tokens refer to a particular token contract, and
there's no guarantee that peers won't be using different (and therefore
incompatible) contracts for the same currency such as WETH.

Here, we use an identifier to ensure peers are referring to the same
token as we are. For currencies that use lnd, the token identifier is
determined dynamically using the `chain` and `network` returned by lnd
on a `GetInfo` call. For example, BTC mainnet would be "bitcoin-mainnet"
and LTC testnet would be "litecoin-testnet". For currencies that use
Raiden, we use the token contract address as the identifier.

These token identifiers are shared with peers during the handshake and
on any subsequent node state updates. The p2p messaging format is
changed to accommodate this. This also drops static node values like
the `nodePubKey` and `version` from the node state p2p message, as these
values can not change mid-session for a peer.

A future improvement may be to detect and support discrepancies in the
currency symbol used by a peer for the same token. For example, a
peer that advertises "XBT" with a token identifier of "bitcoin-mainnet"
should be compatible with our "BTC" that also is identified as
"bitcoin-mainnet". This is not included in this commit as it would
require further refactoring and complexity.

Another follow-up may be creating a test suite for the `Peer` class or
refactoring it to move logic elsewhere (along with tests for that logic).
There is some logic around handling node state updates where information
regarding the peer's supported currencies may change that is currently
not tested.

Closes #910.

BREAKING CHANGE: Changed p2p messaging structure for `SessionInit`
and `NodeStateUpdate` packets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Database related issues P1 top priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants