-
Notifications
You must be signed in to change notification settings - Fork 0
[wip] adds simulation factory to builder #63
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
[wip] adds simulation factory to builder #63
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
53af4b3
to
018c274
Compare
b6464cd
to
13a6ddb
Compare
018c274
to
f7df40c
Compare
13a6ddb
to
3e6203e
Compare
b13b765
to
bdc43a8
Compare
3e6203e
to
33f0c96
Compare
bdc43a8
to
0e77b32
Compare
33f0c96
to
0f17597
Compare
0e77b32
to
a18b444
Compare
0f17597
to
c0b070b
Compare
a18b444
to
a21ba47
Compare
c0b070b
to
56d569f
Compare
a21ba47
to
67e5fa9
Compare
56d569f
to
519bad3
Compare
67e5fa9
to
67dac1c
Compare
b5d24dc
to
fa51801
Compare
d8681d0
to
d56a4e7
Compare
b6cef11
to
1bdd293
Compare
0921bcb
to
f302a1c
Compare
1bdd293
to
92cc1d6
Compare
- adds initial implementation of simulator task to the builder
f302a1c
to
e0c79f7
Compare
92cc1d6
to
3fac60c
Compare
- adds a seed_database function for seeding the cache db during testing - gets tests passing to validate sim logic
@@ -43,6 +43,11 @@ impl InProgressBlock { | |||
self.transactions.is_empty() | |||
} | |||
|
|||
/// Returns the current list of transactions included in this block | |||
pub fn transactions(&self) -> Vec<TxEnvelope> { | |||
self.transactions.clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't clone, return a &[...]
|
||
impl<Db, Insp> SimulatorFactory<Db, Insp> | ||
where | ||
Insp: Inspector<Ctx<CacheOnWrite<CacheOnWrite<Arc<ConcurrentState<Db>>>>>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 2 CacheOnWrite
?
/// Scores are assigned by the evaluation function, and are Ord | ||
/// or PartialOrd to allow for sorting. | ||
#[derive(Debug, Clone)] | ||
pub struct Best<T, S: PartialOrd + Ord = U256> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is Best
the clearest naming for this? what about SimulationResult
? SimulationOutput
?
}) | ||
} | ||
|
||
/// Simulates an inbound tx and applies its state if it's successfully simualted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo: simulated
let best = Best { tx: Arc::new(tx), result, score }; | ||
|
||
// Flatten to save the result to the parent and return it | ||
let db = db.flatten(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be a dumb question, but why are Best and SimResult two different types? could these just be one combined type?
|
||
impl Cfg for PecorinoCfg { | ||
fn fill_cfg_env(&self, cfg_env: &mut CfgEnv) { | ||
cfg_env.chain_id = 17003; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't the Pecorino chain id, is it? I believe it's 14174
also, what's this function intended to be? should this info be loaded from an environment config or something?
} | ||
|
||
// return the target account balance | ||
let target_addr = address!("0x0000000000000000000000000000000000000000"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add TODO comment to replace this dummy value?
// Returns a new signed test transaction with default values | ||
fn new_test_tx(wallet: &PrivateKeySigner, nonce: u64) -> eyre::Result<TxEnvelope> { | ||
let tx = TxEip1559 { | ||
chain_id: 17003, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chain ID doesn't match anvil chain ID setup above. maybe make a constant to use in the test so there isn't discrepancy?
let best = handle.await.unwrap(); | ||
|
||
// Assert on the block | ||
assert_eq!(best.len(), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we expect the block to contain one transaction, if we sent two valid transactions to the evaluator? if the second transaction should fail for some reason, can we leave a comment indicating why?
} | ||
|
||
/// An example of a simple evaluator function for use in testing | ||
fn test_evaluator(state: &ResultAndState) -> U256 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is duplicated from simulator.rs, should we import it to the test, or else only have it here if it's not meant for general consumption?
Closing this PR stack because we're moving simulation code into |
[wip] Adds Simulator to Builder
This PR adds the SimulatorFactory to the Builder.
Related
Closes ENG-790
Closes ENG-957