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

A simple mockup of L2 logic without proofs or signatures. #6

Merged
merged 7 commits into from
Jan 29, 2024

Conversation

Avi-D-coder
Copy link
Contributor

@Avi-D-coder Avi-D-coder commented Jan 22, 2024

Follow up tasks:

@Avi-D-coder Avi-D-coder requested review from marijanp and jonas089 and removed request for marijanp and jonas089 January 22, 2024 23:44
Copy link
Contributor

@marijanp marijanp left a comment

Choose a reason for hiding this comment

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

Obviously some things are missing like a token-id for all the transactions, but we didn't iron them out yet. Code is clear and easy to follow, important edge-cases have proper handling or have an according todo,.

kairos-server/src/main.rs Outdated Show resolved Hide resolved
pub balances: HashMap<PublicKey, u64>,
pub batch_epoch: u64,
/// The set of transfers that will be batched in the next epoch.
pub batched_transfers: HashSet<Transfer>,
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we introduced

pub enum Transaction {
   Deposit { .... },
   Transfer { .... },
   Withdraw { ... }
}

Then we could have a batch HashSet<Transaction>

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I just saw transfers are in a HashSet, and the others in a vector.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking here is Deposit and Withdraw need separate handling.
Although perhaps Withdraw should also be a HashSet to check for duplication.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but we could just match and dispatch accordingly. But let's move that to a later point, seems premature. Also, I think adding a timestamp to each of those types would make sense and put all of them in a hashset actually

@marijanp
Copy link
Contributor

As a next step I would also move most code out of the main.rs and put it into a run function which expects parsed CLI-Args in a server module.

Copy link
Member

Choose a reason for hiding this comment

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

The types that flow in/out of server to/from an sdk could be factored out to a dedicated crate ... I began this process in my paradox implementation.

https://github.com/cspr-rad/paradox-4/tree/main/node/types/src/external

Copy link
Member

Choose a reason for hiding this comment

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

General comment in respect of the handlers. Typically they should be a thin layer, the business logic should be handled by an inner layer that can be tested outside of the network context. But it's early days.

Copy link
Member

Choose a reason for hiding this comment

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

Another general comment in respect of the handlers. The input/output request/response types could be wrapped in generic ServerRequest & ServerResponse types. These types would provide a contextual envelope.

For an example of what I mean, check out the core external types exposed in my paradox implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another general comment in respect of the handlers. The input/output request/response types could be wrapped in generic ServerRequest & ServerResponse types. These types would provide a contextual envelope.

I'd suggest using a middle layer there.

https://docs.rs/axum/latest/axum/middleware/index.html

Copy link
Member

@asladeofgreen asladeofgreen left a comment

Choose a reason for hiding this comment

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

Finished my review. Most of my comments relate to code structure and are nit-picky ... but there again I am very nit-picky ! Also most of my comments should be taken with a pinch of salt as I know that you guys are just getting things up and running.

I would ask you to be cognizant of the fact that a successful L1/L2 will result in the development of several SDKs, e.g. rust, typescript, python ... etc. Therefore it is useful to structure the code in such a way that makes it as easy as possible for an SDK to be built. This typically means factoring out the over the wire types to a dedicated crate ... sometimes even with some meta-programming tricks so as to forward engineer the over the wire typeset in other programming language bindings. Also on this note, the cli program should be as thin as possible and depend upon the sdk ... you quite often see cli/sdk entanglements that make it difficult to use the sdk in standalone mode (e.g. from a trading bot).

@Avi-D-coder
Copy link
Contributor Author

L1/L2 will result in the development of several SDKs, e.g. rust, typescript, python

My thinking here is we are going to call into a native Rust or WASM lib for sigs anyway, those SDKs can be thin wrappers around a Rust lib. If we try and make over the wire types multi lang compatible we can not use things like rkyv or sum types. I'd have the Rust lib handle requests for this reason.

@Avi-D-coder
Copy link
Contributor Author

I switched to typed routes, and added logging and two tests.

kairos-server/src/config.rs Outdated Show resolved Hide resolved
pub balances: HashMap<PublicKey, u64>,
pub batch_epoch: u64,
/// The set of transfers that will be batched in the next epoch.
pub batched_transfers: HashSet<Transfer>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but we could just match and dispatch accordingly. But let's move that to a later point, seems premature. Also, I think adding a timestamp to each of those types would make sense and put all of them in a hashset actually

Copy link
Member

@asladeofgreen asladeofgreen left a comment

Choose a reason for hiding this comment

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

Nice. Will be running tests and going deeper into business logic but am approving.

Co-authored-by: Marijan Petričević <[email protected]>
@Avi-D-coder
Copy link
Contributor Author

So I am thinking we currently don't care about CI failing.

@marijanp
Copy link
Contributor

can you

nix flake check
nix build .#kairos

if that builds, you are good to merge I would say.

@Avi-D-coder Avi-D-coder merged commit d23e31c into main Jan 29, 2024
1 of 5 checks passed
@Avi-D-coder Avi-D-coder deleted the server-1 branch January 29, 2024 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants