Skip to content

Commit

Permalink
Fix Althea payment normalization
Browse files Browse the repository at this point in the history
Althea L1 will natively use stablecoins like USDC and USDT these are 6
decimal of precision tokens versus DAI and native ETH having 18 decimals
of precision.

This is extermely relevant becuase of the way we encode prices in babel
in wei/byte. Where a wei is 1*10^-18 of a whole token. This provides us
a good range of pricing possibilities. But if we encode in 1 micro token
/ byte and the token being used to price is worth $1 then the minimum
bandwidth price is $1000/gb which is obviously not useful practically.

This means we need to convert from 18 decimal accounting for bandwdith
into 6 decimal accounting for payments on Althea chain. Previously
instead of doing this properly we added 1 micro token to every
conversion operation and in the Althea payment test confirmed one micro
token was sent.

This patch resolves the issue by fixing rounding (no more randomly
adding one unit) and modifying the tests to price banwidth more
realistically, with prices represnting 10-25c a gigabyte versus some
miniscule fraction of that. This means that an actual payment of a
realistic amount can be made in the Althea payments test and confirmed.
  • Loading branch information
jkilpatr committed Apr 9, 2024
1 parent 6dfc530 commit 4d9652b
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 122 deletions.
240 changes: 205 additions & 35 deletions integration_tests/src/five_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,49 +75,51 @@ pub fn five_node_config() -> (NamespaceInfo, HashMap<Namespace, RouteHop>) {
*/
let testa = Namespace {
id: 1,
cost: 25,
// two and a half cents / gb in wei / byte
cost: 25_000_000,
node_type: NodeType::Client {
exit_name: "test_4".to_string(),
},
};
let testb = Namespace {
id: 2,
cost: 500,
// 20 cents / gb in wei / byte
cost: 500_000_000,
node_type: NodeType::Client {
exit_name: "test_4".to_string(),
},
};
let testc = Namespace {
id: 3,
cost: 15,
cost: 15_000_000,
node_type: NodeType::Client {
exit_name: "test_4".to_string(),
},
};
let testd = Namespace {
id: 4,
cost: 10,
cost: 10_000_000,
node_type: NodeType::Exit {
instance_name: "test_4".to_string(),
},
};
let teste = Namespace {
id: 5,
cost: 40,
cost: 40_000_000,
node_type: NodeType::Client {
exit_name: "test_4".to_string(),
},
};
let testf = Namespace {
id: 6,
cost: 20,
cost: 20_000_000,
node_type: NodeType::Client {
exit_name: "test_4".to_string(),
},
};
let testg = Namespace {
id: 7,
cost: 15,
cost: 15_000_000,
node_type: NodeType::Client {
exit_name: "test_4".to_string(),
},
Expand Down Expand Up @@ -152,10 +154,34 @@ pub fn five_node_config() -> (NamespaceInfo, HashMap<Namespace, RouteHop>) {
destination: [
(2, PriceId { price: 0, id: 2 }),
(3, PriceId { price: 0, id: 3 }),
(4, PriceId { price: 35, id: 3 }),
(5, PriceId { price: 15, id: 3 }),
(6, PriceId { price: 15, id: 3 }),
(7, PriceId { price: 45, id: 3 }),
(
4,
PriceId {
price: 35_000_000,
id: 3,
},
),
(
5,
PriceId {
price: 15_000_000,
id: 3,
},
),
(
6,
PriceId {
price: 15_000_000,
id: 3,
},
),
(
7,
PriceId {
price: 45_000_000,
id: 3,
},
),
]
.iter()
.cloned()
Expand All @@ -164,11 +190,35 @@ pub fn five_node_config() -> (NamespaceInfo, HashMap<Namespace, RouteHop>) {
let testb_routes = RouteHop {
destination: [
(1, PriceId { price: 0, id: 1 }),
(3, PriceId { price: 25, id: 1 }),
(
3,
PriceId {
price: 25_000_000,
id: 1,
},
),
(4, PriceId { price: 0, id: 4 }),
(5, PriceId { price: 40, id: 1 }),
(6, PriceId { price: 10, id: 4 }),
(7, PriceId { price: 10, id: 4 }),
(
5,
PriceId {
price: 40_000_000,
id: 1,
},
),
(
6,
PriceId {
price: 10_000_000,
id: 4,
},
),
(
7,
PriceId {
price: 10_000_000,
id: 4,
},
),
]
.iter()
.cloned()
Expand All @@ -177,22 +227,58 @@ pub fn five_node_config() -> (NamespaceInfo, HashMap<Namespace, RouteHop>) {
let testc_routes = RouteHop {
destination: [
(1, PriceId { price: 0, id: 1 }),
(2, PriceId { price: 25, id: 1 }),
(4, PriceId { price: 20, id: 6 }),
(
2,
PriceId {
price: 25_000_000,
id: 1,
},
),
(
4,
PriceId {
price: 20_000_000,
id: 6,
},
),
(5, PriceId { price: 0, id: 5 }),
(6, PriceId { price: 0, id: 6 }),
(7, PriceId { price: 30, id: 6 }),
(
7,
PriceId {
price: 30_000_000,
id: 6,
},
),
]
.iter()
.cloned()
.collect(),
};
let testd_routes = RouteHop {
destination: [
(1, PriceId { price: 35, id: 6 }),
(
1,
PriceId {
price: 35_000_000,
id: 6,
},
),
(2, PriceId { price: 0, id: 2 }),
(3, PriceId { price: 20, id: 6 }),
(5, PriceId { price: 35, id: 6 }),
(
3,
PriceId {
price: 20_000_000,
id: 6,
},
),
(
5,
PriceId {
price: 35_000_000,
id: 6,
},
),
(6, PriceId { price: 0, id: 6 }),
(7, PriceId { price: 0, id: 7 }),
]
Expand All @@ -202,38 +288,122 @@ pub fn five_node_config() -> (NamespaceInfo, HashMap<Namespace, RouteHop>) {
};
let teste_routes = RouteHop {
destination: [
(1, PriceId { price: 15, id: 3 }),
(2, PriceId { price: 40, id: 3 }),
(
1,
PriceId {
price: 15_000_000,
id: 3,
},
),
(
2,
PriceId {
price: 40_000_000,
id: 3,
},
),
(3, PriceId { price: 0, id: 3 }),
(4, PriceId { price: 35, id: 3 }),
(6, PriceId { price: 15, id: 3 }),
(7, PriceId { price: 45, id: 3 }),
(
4,
PriceId {
price: 35_000_000,
id: 3,
},
),
(
6,
PriceId {
price: 15_000_000,
id: 3,
},
),
(
7,
PriceId {
price: 45_000_000,
id: 3,
},
),
]
.iter()
.cloned()
.collect(),
};
let testf_routes = RouteHop {
destination: [
(1, PriceId { price: 15, id: 3 }),
(2, PriceId { price: 10, id: 4 }),
(
1,
PriceId {
price: 15_000_000,
id: 3,
},
),
(
2,
PriceId {
price: 10_000_000,
id: 4,
},
),
(3, PriceId { price: 0, id: 3 }),
(4, PriceId { price: 0, id: 4 }),
(5, PriceId { price: 15, id: 3 }),
(7, PriceId { price: 10, id: 4 }),
(
5,
PriceId {
price: 15_000_000,
id: 3,
},
),
(
7,
PriceId {
price: 10_000_000,
id: 4,
},
),
]
.iter()
.cloned()
.collect(),
};
let testg_routes = RouteHop {
destination: [
(1, PriceId { price: 45, id: 4 }),
(2, PriceId { price: 10, id: 4 }),
(3, PriceId { price: 30, id: 4 }),
(
1,
PriceId {
price: 45_000_000,
id: 4,
},
),
(
2,
PriceId {
price: 10_000_000,
id: 4,
},
),
(
3,
PriceId {
price: 30_000_000,
id: 4,
},
),
(4, PriceId { price: 0, id: 4 }),
(5, PriceId { price: 45, id: 4 }),
(6, PriceId { price: 10, id: 4 }),
(
5,
PriceId {
price: 45_000_000,
id: 4,
},
),
(
6,
PriceId {
price: 10_000_000,
id: 4,
},
),
]
.iter()
.cloned()
Expand Down
Loading

0 comments on commit 4d9652b

Please sign in to comment.