-
Notifications
You must be signed in to change notification settings - Fork 87
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
Decompose consensus params #514
Conversation
In addition to tests not passing, There are a number of function signatures I'd like to improve before merging this. I'll try to document what those changes are here so we can track them. |
@@ -237,25 +242,29 @@ impl FormatValidityChecks for Create { | |||
fn check_without_signatures( | |||
&self, | |||
block_height: BlockHeight, | |||
parameters: &ConsensusParameters, | |||
tx_params: &TxParameters, |
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.
If we need a combination of the parameters, it is better to pass only ConsensusParameters
. It is not a problem if some fields are not used. The API should be simple for the user and transparent regarding requirements(like you don't need to pass ConsensusParameters
if you only need a ChainId
).
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.
For sure. I've combined them back together in some other places. Clippy just didn't catch this because it's at the limit (7). I can do the same here. Good catch.
fuel-tx/src/builder.rs
Outdated
tx_params: TxParameters, | ||
predicate_params: PredicateParameters, | ||
script_params: ScriptParameters, | ||
contract_params: ContractParameters, | ||
fee_params: FeeParameters, | ||
chain_id: ChainId, |
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.
Maybe it is still better to store all params like ConsensusParameters
inside. In this case get_params
will be useful too(it is commented now). In this case all new methods are still useable but you support old once too=)
@@ -466,7 +469,8 @@ fn iow_offset() { | |||
let bytes = tx.to_bytes(); | |||
|
|||
let mut tx_p = tx.clone(); | |||
tx_p.precompute(&ConsensusParameters::DEFAULT.chain_id) | |||
let chain_id = ChainId::new(0); | |||
tx_p.precompute(&chain_id) |
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.
I guess you can use Default::default
like you did in other places=)
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.
Done.
let chain_id = ChainId::new(0); | ||
|
||
tx.sign_inputs(&secret, &chain_id); | ||
keys.iter().for_each(|sk| tx.sign_inputs(sk, &chain_id)); |
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.
The same here, let's use one approach everywhere either Default::default()
or ChainId::default()
or ChainId::new(0)
or ChainId::DEFAULT
=)
It applies to all places=)
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.
Done.
@@ -648,7 +772,11 @@ fn transaction_with_duplicate_contract_inputs_is_invalid() { | |||
.add_output(o) | |||
.add_output(p) | |||
.finalize() | |||
.check_without_signatures(Default::default(), &Default::default()) | |||
.check_without_signatures( |
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.
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 a trait method. It gets used in the other impls of this method.
But it sounds like you want chain_id
as part of ConsensusParams
so I think it will get removed in that case anyway.
|
||
/// A collection of parameters for convenience | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct ConsensusParams<'a> { |
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.
ChainId
should be part of the ConsensusParams
, because it is the same for the whole network and without it it is impossible to continue the network
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.
It is true that the ConsensusParams
is a combination of the other parameters and references them. But at the same time, this type can be the place that actually aggregates all of them and holds them during the lifecycle of the fuel-core
. If we want to pass somewhere a reference to all params, we can pass &ConsensusParams
. The ConsensusParams
itself doesn't need to work with references to the Copy
types.
It makes the API harder to use and creates situations like in several places of your PR(Where you create each parameter -> you create a ConsensusParams
-> you pass it to the corresponding place).
I think we need to work with values instead of references, if you don't have any strong reason why we want to use references=)
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.
It does make it harder to work with.
I had reasons I preferred references, but I'm not really convinced by them anymore, so I'll just get rid of the refs. Especially since all of them are Copy
.
fuel-vm/src/checked_transaction.rs
Outdated
params: &ConsensusParameters, | ||
gas_costs: &GasCosts, | ||
) -> Result<Self, CheckError>; | ||
fn check_predicates(self, params: CheckPredicateParams) -> Result<Self, CheckError>; |
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.
I prefer &CheckPredicateParams
more than CheckPredicateParams
because we usually store this configuration somewhere. Plus, downstream code decides whether it needs to clone or not.
fuel-vm/src/interpreter.rs
Outdated
@@ -109,7 +112,14 @@ pub struct Interpreter<S, Tx = ()> { | |||
balances: RuntimeBalances, | |||
gas_costs: GasCosts, | |||
profiler: Profiler, | |||
params: ConsensusParameters, | |||
fee_params: FeeParameters, |
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.
I guess you want to use InterpreterParams
here=)
fuel-vm/src/interpreter.rs
Outdated
@@ -181,6 +191,12 @@ impl<S, Tx> Interpreter<S, Tx> { | |||
pub const fn profiler(&self) -> &Profiler { | |||
&self.profiler | |||
} | |||
|
|||
/// Modify the FeeParameters | |||
pub fn with_fee_params(mut self, fee_params: FeeParameters) -> Self { |
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.
It should be specified during creation of the Interpreter
fuel-vm/src/interpreter/debug.rs
Outdated
let tx_params = TxParameters::default(); | ||
let predicate_params = PredicateParameters::default(); | ||
let script_params = ScriptParameters::default(); | ||
let contract_params = ContractParameters::default(); | ||
let fee_params = FeeParameters::default(); | ||
let chain_id = ChainId::default(); | ||
let gas_costs = GasCosts::default(); |
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.
It adds a lot of overhead=) if ConsensusParams
works with values instead, you don't need to do it
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.
I missed this one. Adding now.
fuel-vm/src/util.rs
Outdated
self.params, | ||
self.gas_costs.clone(), | ||
); | ||
let interpreter_params = InterpreterParams { |
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.
It is better if Self
contains InterpreterParams
instead=)
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.
I added the ConsesensusParams
to Self
and used the into
.
ab3db20
to
cbb56e4
Compare
// TODO: This should be pub(crate) for the `fuel_tx` tests, but for some reason the | ||
// tests can't see the fields with `pub(crate)` |
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.
Integration tests cannot see pub(crate)
items, as they are outside the crate. Typically you'd do a public re-export behind test-helpers
feature flag, but I don't see much point in not having this as a part of the public interface anyways.
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.
Yeah. That's a good point. There are probably places outside of fuel-tx
that could use this as well. I was referring to something in fuel-tx/src/tests
, not in the integ tests.
I usually prefer getters/setters over accessing fields directly, but I'm not going to worry about it right now.
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.
One todo and some commented out code should be cleaned up, but other than that LGTM
fuel-vm/src/transactor.rs
Outdated
// /// Consensus parameters | ||
// pub const fn params(&self) -> &ConsensusParameters { | ||
// self.interpreter.params() | ||
// } | ||
// |
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.
Commented-out code that likely should be removed
FuelLabs/fuel-core#1243
The idea behind this PR was that
ConsensusParameters
was being passed to any function that needed a value inConsensusParameters
. We wanted the functions to define what they needed instead of giving them the whole kitchen sink.The work included:
ConsensusParams
from all function signaturesTxParameters
,FeeParameters