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

Refactor to abstract storage engine and fix bugs #247

Merged
merged 8 commits into from
Nov 30, 2023

Conversation

zsluedem
Copy link
Collaborator

@zsluedem zsluedem commented Nov 26, 2023

@zsluedem zsluedem requested a review from Vid201 November 26, 2023 13:59
R: ReputationEntryOp,
SanCk: SanityCheck<M>,
SimCk: SimulationCheck,
SimTrCk: SimulationTraceCheck<M>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Vid201
The side affect of not introducing dynamic dispatch in rust -> we need to provide these traits in a lot of places.

There is some performance penalty for dynamic dispatch. I need to do some benchmark later to figure out whether dynamic dispatch is better for code reading later. I think we could live with the current codes right now before the benchmark is done.

Copy link
Member

Choose a reason for hiding this comment

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

Got it.

yeah, the code readibility is not the best, but I think it's fine. We could add some comments for all these traits though.

pub trait UserOperationCodeHashAct: UserOperationCodeHashOp + ClearOp + Send + Sync {}
impl<T> UserOperationCodeHashAct for T where T: UserOperationCodeHashOp + ClearOp + Send + Sync {}

pub struct Mempool<T, Y, X, Z>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The mempool here with seperate trait could help separate the lock with data racing.

Copy link
Member

Choose a reason for hiding this comment

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

I'm just curious - does this pattern have a name? Just interested if this is some standardised approach

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am actually sure what name should be used actually. This is like a common practice for trait system (mostly for function programming language not oop). The goal is to create minimize method and compose these methods to make a program.
https://scg.unibe.ch/research/traits maybe the lists here are helpful.

Copy link
Member

@Vid201 Vid201 left a comment

Choose a reason for hiding this comment

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

Generally looks good!

Left some comments

bin/silius/src/cli/args.rs Outdated Show resolved Hide resolved
);
match (args.uopool_mode, args.use_memory) {
Copy link
Member

Choose a reason for hiding this comment

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

Possible to move this code to some other crate? match is fine here, but maybe the code for creating uopool can be in uopool crate

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the disadvantage of the refactoring. When things comes to be totally type concrete, the compiler would complain a lot about it which leads to the highly duplicate codes here. It is not easy to do that unless we introduce dynamic dispatch for Mempool , Reputation and validator.

I suggest we leave it here right now and I know it is ugly. We could optimize the codes here when I finished dynamic dispatch bench mark and it doesn't cost too much performance penalty. If the performance is an issue for dynamic dispatch, we could only introduce some macro to make codes more readible here.

R: ReputationEntryOp,
SanCk: SanityCheck<M>,
SimCk: SimulationCheck,
SimTrCk: SimulationTraceCheck<M>,
Copy link
Member

Choose a reason for hiding this comment

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

Got it.

yeah, the code readibility is not the best, but I think it's fine. We could add some comments for all these traits though.

examples/storage/examples/database.rs Outdated Show resolved Hide resolved
examples/storage/examples/memory.rs Outdated Show resolved Hide resolved
crates/uopool/src/database/mempool.rs Outdated Show resolved Hide resolved
crates/uopool/src/validate/mod.rs Show resolved Hide resolved
crates/uopool/src/validate/mod.rs Show resolved Hide resolved
pub trait UserOperationCodeHashAct: UserOperationCodeHashOp + ClearOp + Send + Sync {}
impl<T> UserOperationCodeHashAct for T where T: UserOperationCodeHashOp + ClearOp + Send + Sync {}

pub struct Mempool<T, Y, X, Z>
Copy link
Member

Choose a reason for hiding this comment

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

I'm just curious - does this pattern have a name? Just interested if this is some standardised approach

@zsluedem zsluedem requested a review from Vid201 November 28, 2023 15:40
bin/silius/src/cli/args.rs Outdated Show resolved Hide resolved
bin/silius/src/cli/args.rs Outdated Show resolved Hide resolved
Copy link
Member

@Vid201 Vid201 left a comment

Choose a reason for hiding this comment

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

Can be merged after resolve last two new comments

@zsluedem zsluedem merged commit ec8c6b7 into silius-rs:main Nov 30, 2023
2 checks passed
@zsluedem zsluedem deleted the abstract-storage branch November 30, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants