-
Notifications
You must be signed in to change notification settings - Fork 15
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
Txin sequence numbers #436
Conversation
…rations to current design
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.
Let's also move these 2.5 week, 2 week constants to some constants file. We can do this in a seperate pr. I will create an issue
core/src/builder/transaction.rs
Outdated
@@ -69,7 +69,9 @@ pub fn create_sequential_collateral_txhandler( | |||
txid: input_txid, | |||
vout: 0, | |||
}]); | |||
|
|||
if max_withdrawal_time_block_count > u16::MAX as i64 { | |||
panic!("Max withdrawal time block count is larger than u16::MAX (sequence relative timelock is 16 bits"); |
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 this needed?
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.
No, but it doesn't hurt because we are casting i64 to u16. I think as Efe said we should prob move these deposit related constants to some config struct (not read through a toml file so only editable with code changes). Stuff like num_kickoffs, timetxs, timeouts etc. It should be a struct instead of constants so that we can adjust stuff like num_timetxs to be small easily for tests so that they run fast. But config::default() would have normal deposit values.
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.
@ceyhunsen had a pr to seperate the Config to parts, maybe that can be helpful, since we can seperate Bridge specific constants to a sub-category.
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'd prefer a constants module for things that'd change internal sighashes, #signatures. (basically anything that can cause errors in the deposit mechanism should not be configurable by the user)
Also, as @atacann said, we can create a test constants module that would provide very small defaults for fast tests.
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're keeping this line, I think the following would be more readable (in fact, I think the behavior in your code may be incorrect as it doesn't check the lower bound):
u16::try_from(max_withdrawal_time_block_count).expect("Max withdrawal ...");
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 think @ekrembal's mention #175 won't solve this issue. Because everything you put on BridgeConfig
can be modified by the toml file, you can't block it.
Also, it should be noted that BridgeConfig::default()
is there for testing; You may change the defaults if you think it will benefit most of the tests. Therefore we should block entity binaries from starting if no custom configuration files are specified.
core/src/builder/transaction.rs
Outdated
tx_ins.push(TxIn { | ||
/// Create tx_ins with relative time locks using block height | ||
/// This function needs to be used with any TX that has a relative time lock in at least one of the inputs. | ||
pub fn create_tx_ins_with_sequence(utxos: Vec<OutPoint>, heights: &[Option<u16>]) -> Vec<TxIn> { |
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.
In order of preference:
- Newtype paradigm for better API, more rigid enforcement of contract:
pub struct TxInArgs {
outpoint: OutPoint,
height: Option<u16>,
}
impl From<OutPoint> for TxInArgs {
...
}
impl From<Vec<OutPoint>> for Vec<TxInArgs> {
...
}
impl From<Vec<(OutPoint, u16)>> for Vec<TxInArgs> {
...
}
// Single API with easy usage
// create_tx_ins(my_outpoint_vec.into())
// create_tx_ins(&my_tx_in_args_vec)
pub fn create_tx_ins(tx_in_args: impl AsRef<[TxInArgs]>) -> Vec<TxIn> {...}
// If you want to go one level higher:
// create_tx_ins(&my_outpoint_slice)
// Might cause too much codegen, so consider monomorphizing if going this route
pub fn create_tx_ins(tx_in_args: impl AsRef<[impl Into<TxInArgs>]>) -> Vec<TxIn> {...}
- Use tuples to enforce that heights and utxos must have the same length:
pub fn create_tx_ins_with_sequence(tx_in_args: impl AsRef<[(OutPoint, Option<u16>)]>) -> Vec<TxIn> {...}
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.
Feel free to skip this, as it's likely out of scope for this PR:
I'd prefer new module for utils like this, builder::transaction::utils
. 1500 line file is not the best DX
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.
Let's create a new issue for this, can you create one? @mmtftr
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 changed create_tx_ins similar to what Efe said. TxInArgs is a wrapper around Vec because you can't impl for a Vec directly. Also I just move TxInArgs instead of AsRef because we never need the ref currently ( so we don't need to clone to create TxIn vec).
Description
Use correct sequence numbers for Txin's with timelocks, also update timelock durations to current design
Linked Issues