Perp: Drop client order id from LeafNodes (#323)

This saves 8 bytes and only the FillEvents, FillLogs were populated from
the data.
This commit is contained in:
Christian Kamm 2022-12-08 19:55:32 +01:00 committed by GitHub
parent 3e7f5487b7
commit 450007d34b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 14 additions and 64 deletions

View File

@ -130,7 +130,6 @@ pub fn perp_consume_events(ctx: Context<PerpConsumeEvents>, limit: usize) -> Res
seq_num: fill.seq_num,
maker: fill.maker,
maker_order_id: fill.maker_order_id,
maker_client_order_id: fill.maker_client_order_id,
maker_fee: fill.maker_fee.to_bits(),
maker_timestamp: fill.maker_timestamp,
taker: fill.taker,

View File

@ -100,7 +100,6 @@ pub struct FillLog {
pub maker: Pubkey,
pub maker_order_id: u128,
pub maker_client_order_id: u64,
pub maker_fee: i128,
// Timestamp of when the maker order was placed; copied over from the LeafNode

View File

@ -811,6 +811,7 @@ impl<
side: Side,
order_tree: BookSideOrderTree,
order: &LeafNode,
client_order_id: u64,
) -> Result<()> {
let mut perp_account = self.perp_position_mut(perp_market_index)?;
match side {
@ -827,7 +828,7 @@ impl<
oo.market = perp_market_index;
oo.side_and_tree = SideAndOrderTree::new(side, order_tree).into();
oo.id = order.key;
oo.client_id = order.client_order_id;
oo.client_id = client_order_id;
Ok(())
}

View File

@ -180,7 +180,6 @@ impl<'a> Orderbook<'a> {
event_queue.header.seq_num,
best_opposing.node.owner,
best_opposing.node.key,
best_opposing.node.client_order_id,
market.maker_fee,
best_opposing.node.timestamp,
*mango_account_pk,
@ -259,7 +258,6 @@ impl<'a> Orderbook<'a> {
order_id,
*mango_account_pk,
book_base_quantity,
order.client_order_id,
now_ts,
PostOrderType::Limit, // TODO: Support order types? needed?
order.time_in_force,
@ -284,6 +282,7 @@ impl<'a> Orderbook<'a> {
side,
order_tree_target,
&new_order,
order.client_order_id,
)?;
}

View File

@ -164,19 +164,8 @@ mod tests {
let mut order_tree = new_order_tree(order_tree_type);
let mut root_fixed = OrderTreeRoot::zeroed();
let mut root_pegged = OrderTreeRoot::zeroed();
let new_leaf = |key: u128| {
LeafNode::new(
0,
key,
Pubkey::default(),
0,
0,
1,
PostOrderType::Limit,
0,
-1,
)
};
let new_leaf =
|key: u128| LeafNode::new(0, key, Pubkey::default(), 0, 1, PostOrderType::Limit, 0, -1);
// add 100 leaves to each BookSide, mostly random
let mut keys = vec![];
@ -266,7 +255,6 @@ mod tests {
key,
Pubkey::default(),
0,
0,
1000,
PostOrderType::Limit,
tif,

View File

@ -383,7 +383,6 @@ mod tests {
assert_eq!(fill.quantity, match_quantity);
assert_eq!(fill.price, price_lots);
assert_eq!(fill.taker_client_order_id, 43);
assert_eq!(fill.maker_client_order_id, 42);
assert_eq!(fill.maker, maker_pk);
assert_eq!(fill.taker, taker_pk);
assert_eq!(fill.maker_fee, market.maker_fee);

View File

@ -140,7 +140,6 @@ pub struct LeafNode {
pub owner: Pubkey,
pub quantity: i64,
pub client_order_id: u64,
// The time the order was placed
pub timestamp: u64,
@ -148,11 +147,11 @@ pub struct LeafNode {
// Only applicable in the oracle_pegged OrderTree
pub peg_limit: i64,
pub reserved: [u8; 32],
pub reserved: [u8; 40],
}
const_assert_eq!(
size_of::<LeafNode>(),
4 + 1 + 1 + 1 + 1 + 16 + 32 + 8 + 8 + 8 + 8 + 32
4 + 1 + 1 + 1 + 1 + 16 + 32 + 8 + 8 + 8 + 40
);
const_assert_eq!(size_of::<LeafNode>(), NODE_SIZE);
const_assert_eq!(size_of::<LeafNode>() % 8, 0);
@ -164,7 +163,6 @@ impl LeafNode {
key: u128,
owner: Pubkey,
quantity: i64,
client_order_id: u64,
timestamp: u64,
order_type: PostOrderType,
time_in_force: u16,
@ -180,10 +178,9 @@ impl LeafNode {
key,
owner,
quantity,
client_order_id,
timestamp,
peg_limit,
reserved: [0; 32],
reserved: [0; 40],
}
}

View File

@ -544,7 +544,6 @@ mod tests {
key,
Pubkey::default(),
0,
0,
expiry - 1,
PostOrderType::Limit,
1,
@ -637,7 +636,6 @@ mod tests {
key,
Pubkey::default(),
0,
0,
expiry - 1,
PostOrderType::Limit,
1,

View File

@ -191,7 +191,6 @@ pub struct FillEvent {
pub maker: Pubkey,
pub maker_order_id: u128,
pub maker_client_order_id: u64,
pub maker_fee: I80F48,
// Timestamp of when the maker order was placed; copied over from the LeafNode
@ -204,7 +203,7 @@ pub struct FillEvent {
pub price: i64,
pub quantity: i64, // number of quote lots
pub reserved: [u8; 16],
pub reserved: [u8; 24],
}
const_assert_eq!(size_of::<FillEvent>() % 8, 0);
const_assert_eq!(size_of::<FillEvent>(), EVENT_SIZE);
@ -219,7 +218,6 @@ impl FillEvent {
seq_num: u64,
maker: Pubkey,
maker_order_id: u128,
maker_client_order_id: u64,
maker_fee: I80F48,
maker_timestamp: u64,
@ -241,7 +239,6 @@ impl FillEvent {
seq_num,
maker,
maker_order_id,
maker_client_order_id,
maker_fee,
maker_timestamp,
taker,
@ -250,7 +247,7 @@ impl FillEvent {
taker_fee,
price,
quantity,
reserved: [0; 16],
reserved: [0; 24],
}
}

View File

@ -960,7 +960,6 @@ export interface FillEvent extends Event {
seqNum: BN;
maker: PublicKey;
makerOrderId: BN;
makerClientOrderId: BN;
makerFee: I80F48;
makerTimestamp: BN;
taker: PublicKey;

View File

@ -5442,10 +5442,6 @@ export type MangoV4 = {
"name": "quantity",
"type": "i64"
},
{
"name": "clientOrderId",
"type": "u64"
},
{
"name": "timestamp",
"type": "u64"
@ -5459,7 +5455,7 @@ export type MangoV4 = {
"type": {
"array": [
"u8",
32
40
]
}
}
@ -5654,10 +5650,6 @@ export type MangoV4 = {
"name": "makerOrderId",
"type": "u128"
},
{
"name": "makerClientOrderId",
"type": "u64"
},
{
"name": "makerFee",
"type": {
@ -5699,7 +5691,7 @@ export type MangoV4 = {
"type": {
"array": [
"u8",
16
24
]
}
}
@ -6506,11 +6498,6 @@ export type MangoV4 = {
"type": "u128",
"index": false
},
{
"name": "makerClientOrderId",
"type": "u64",
"index": false
},
{
"name": "makerFee",
"type": "i128",
@ -12799,10 +12786,6 @@ export const IDL: MangoV4 = {
"name": "quantity",
"type": "i64"
},
{
"name": "clientOrderId",
"type": "u64"
},
{
"name": "timestamp",
"type": "u64"
@ -12816,7 +12799,7 @@ export const IDL: MangoV4 = {
"type": {
"array": [
"u8",
32
40
]
}
}
@ -13011,10 +12994,6 @@ export const IDL: MangoV4 = {
"name": "makerOrderId",
"type": "u128"
},
{
"name": "makerClientOrderId",
"type": "u64"
},
{
"name": "makerFee",
"type": {
@ -13056,7 +13035,7 @@ export const IDL: MangoV4 = {
"type": {
"array": [
"u8",
16
24
]
}
}
@ -13863,11 +13842,6 @@ export const IDL: MangoV4 = {
"type": "u128",
"index": false
},
{
"name": "makerClientOrderId",
"type": "u64",
"index": false
},
{
"name": "makerFee",
"type": "i128",