Skip to content

issue-#170#172

Merged
andrewnguyen22 merged 1 commit into
mainfrom
issue-#170
May 5, 2025
Merged

issue-#170#172
andrewnguyen22 merged 1 commit into
mainfrom
issue-#170

Conversation

@andrewnguyen22

@andrewnguyen22 andrewnguyen22 commented May 5, 2025

Copy link
Copy Markdown
Collaborator

Describe the bug

The order book structure is stored inefficiently and needs to be redone before mainnet:

Specifically

The structure of the order books as a list vs individual unique orders is estimated to have an unacceptable space complexity

Expected behavior

Change the id of the sell order

message SellOrder {
  // id: the unique identifier of the order
  uint64 Id = 1;
...

to unique deterministic bytes (the hash of the transaction hash that opened the order)

message SellOrder {
  // id: the unique identifier of the order should 
  bytes Id = 1; // transaction hash
}

And change the order book key to a prefix.

func KeyForOrderBook(id uint64) []byte  { return lib.JoinLenPrefix(orderBookPrefix, formatUint64(id)) }

to

func PrefixForOrderBook(chainId uint64) []byte  { return lib.JoinLenPrefix(orderBookPrefix, formatUint64(chainId)) }

and add

func KeyForOrder(chainId uint64, id []byte) []byte  { return lib.JoinLenPrefix(orderBookPrefix, formatUint64(id)) }

then finally change the order book logic to utilize the new design, where orders are stored individually (not a slice) and order books are created dynamically by iterating over the prefix for the committee.

Additional context

This is technically a consensus breaking issue, but because there's been no orders so far -- we should be fine to do this change on the fly.

closes #170

@andrewnguyen22 andrewnguyen22 added the FSM Finite State Machine module label May 5, 2025

@rem1niscence rem1niscence left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved! even though a lot was touched, seems like the same final behavior is kept and is more like a big refactor.

@andrewnguyen22 andrewnguyen22 merged commit 74b1a68 into main May 5, 2025
2 checks passed
@andrewnguyen22 andrewnguyen22 deleted the issue-#170 branch May 5, 2025 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FSM Finite State Machine module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Order Books are not stored efficiently

2 participants