-
Notifications
You must be signed in to change notification settings - Fork 66
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
Feat/deps update #268
base: master
Are you sure you want to change the base?
Feat/deps update #268
Conversation
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
teos/src/bitcoin_cli.rs
Outdated
let binding = | ||
general_purpose::URL_SAFE.encode(format!("{}:{}", self.rpc_user, self.rpc_password)); | ||
let rpc_credentials = binding.as_str(); | ||
Ok(RpcClient::new(&rpc_credentials, http_endpoint)) |
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 need for the .as_str()
line.
&String
will be tread as &str
by the compiler.
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.
Thanks!
Could you please fix the lint errors and cln-plugin test errors?
Looks like these changes bumped the MSRV. Not that it's really important to support older versions, but we can now state this version in:
Line 9 in 4e47db2
FIXME: Define MSRV |
and also create a
rust-toolchain.toml
file with the MSRV.This doesn't have to be done in this PR.
I did a light review for now and skipped the changes in the watchtower plugin, but curious why did you update the dependencies there?
The new imports I think need a bit of a rework.
Some imports losing context when used (e.g. let binding = general_purpose::URL_SAFE.encode(format!("{}:{}", self.rpc_user, self.rpc_password));
, here general_purpose
doesn't really tell that this is doing base64 encoding, a clearer import for instance would be general_purpose::URL_SAFE as base64_encoder
)
And some other imports could be added to make type usages less lengthy (e.g. bitcoin::block::Version::from_consensus(0)
has a long path, why not let it block::Version::from_consensus(0)
and import bitcoin::block
at the top).
teos/src/bitcoin_cli.rs
Outdated
@@ -146,7 +151,7 @@ impl<'a> BitcoindClient<'a> { | |||
pub async fn send_raw_transaction(&self, raw_tx: &Transaction) -> Result<Txid, std::io::Error> { | |||
let rpc = self.bitcoind_rpc_client.lock().await; | |||
|
|||
let raw_tx_json = serde_json::json!(raw_tx.encode().to_hex()); | |||
let raw_tx_json = serde_json::json!(raw_tx.encode()); |
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 is this value no longer hex
ed? does sendrawtransaction
accept a vector of bytes now?
teos-common/src/test_utils.rs
Outdated
// FIXME: might be cleaner? | ||
// Add 1 to make sure it is not 0 | ||
let size = (get_random_int::<usize>() % 81) + 1; | ||
let random_bytes = cryptography::get_random_bytes(size); | ||
let mut fixed_bytes = [0u8; 81]; | ||
fixed_bytes[..random_bytes.len()].copy_from_slice(&random_bytes); | ||
let script_string = format!("6a{}", hex::encode(random_bytes)); | ||
let script_pubkey = ScriptBuf::from(hex::decode(script_string).unwrap()); |
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.
we can avoid doing this by hand. ScriptBuf::new_op_return
should do the job.
also the size here might shoot to 81 with the extra +1
added here, which would make this a bad tx.
no need for the +1
, opreturns wont complain with zero bytes
teos/src/tx_index.rs
Outdated
match block.deref() { | ||
lightning_block_sync::BlockData::HeaderOnly(_) => {} | ||
lightning_block_sync::BlockData::FullBlock(block) => { | ||
let map = block | ||
.txdata | ||
.iter() | ||
.map(|tx| { | ||
( | ||
K::from_txid(tx.compute_txid()), | ||
match V::get_type() { | ||
Type::Transaction => { | ||
V::from_data(Data::Transaction(tx.clone())) | ||
} | ||
Type::BlockHash => { | ||
V::from_data(Data::BlockHash(block.header.block_hash())) | ||
} | ||
}, | ||
) | ||
}) | ||
.collect(); | ||
|
||
tx_index.update(block.header, &map); | ||
} | ||
} |
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.
ummmm, we shouldn't be getting any header only responses as they can't help us populate the index.
if one of these last_n_block
is a header only, the check for previous hash will panic.
match first_block.deref() { | ||
lightning_block_sync::BlockData::FullBlock(b) => { | ||
assert_eq!( | ||
cache.get_height(&b.header.block_hash()).unwrap(), | ||
height - cache_size + 1 | ||
); | ||
} | ||
_ => panic!("Expected FullBlock"), | ||
} | ||
|
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.
aha i see u already spotted the problem with header only blocks. lets panic inside the construct of TxIndex
instead.
teos/src/responder.rs
Outdated
dispute_txid: t.dispute_tx.compute_txid().to_raw_hash().encode(), | ||
penalty_txid: t.penalty_tx.compute_txid().to_raw_hash().encode(), |
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 the .to_raw_hash()
part could be omitted.
teos/src/extended_appointment.rs
Outdated
.try_into() | ||
.unwrap(), |
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 .try_into.unwrap()
could be omitted
if let Some(receipt) = self.issued_receipts.get(&tx.compute_txid()) { | ||
log::info!("Transaction already sent: {}", tx.compute_txid()); | ||
return *receipt; | ||
} | ||
|
||
log::info!("Pushing transaction to the network: {}", tx.txid()); | ||
log::info!("Pushing transaction to the network: {}", tx.compute_txid()); | ||
let receipt = match self.bitcoin_cli.send_raw_transaction(tx) { | ||
Ok(_) => { | ||
// Here the transaction could, potentially, have been in mempool before the current height. | ||
// This shouldn't really matter though. | ||
log::info!("Transaction successfully delivered: {}", tx.txid()); | ||
log::info!("Transaction successfully delivered: {}", tx.compute_txid()); |
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.
nice to see how we abused using .txid()
now that it's apparent it's computed from scratch every time.
this should be tackled in another PR though.
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
8da267c
to
01b4e42
Compare
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
Signed-off-by: dzdidi <[email protected]>
@mariocynicys thank you for review and feedback! Unfortunately I'm stuck with CI for CLN plugin is failing. Updating version of cln fixed issues on installation but now I have issues on building default plugins. Trying to do CI steps on my machine locally makes all my tests fail with the same error on both
Logs in |
@dzdidi thanks. will try to find the issue with CLN tests on the weekend. |
@sangbida since you are interested #133 (comment), do you think #268 (comment) is something you can help with ? |
sorry for not following along, got plenty of exams these days. will take a look at this on march 1st. |
@mariocynicys , no worries, it is not a blocker. I'm working on client on top of this branch. |
Hey yes! I can have a look into this @dzdidi! |
Just thought I'd do a quick update, I'm still setting up my environment with bitcoind, lnd and eye of satoshi so it may take some time but hoping to get that done asap so I can start looking into this properly. |
you can have a look at the readmes found in the root of the repo and you don't need |
That's great to know! I'll skip lnd and get onto teos. |
Hey, I was able to get all set up. I think the error here is that the plugin can't find cargo. I've tried to add it here in this commit: 552ca48 Although, I'm not able to create a PR because I'm not a contributor on @dzdidi rust-teos repo I think? @dzdidi would be great if you could let me if this works? |
@sangbida added you as a collaborator |
Update toolchain version Change the path to link cln
Add rust toolchain to cln-plugin.yml
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.
Thanks very much!
Gonna need one (or two) extra review iterations.
- name: Install bitcoind | ||
run: | | ||
wget https://bitcoincore.org/bin/bitcoin-core-${{ env.bitcoind_version }}/bitcoin-${{ env.bitcoind_version }}-x86_64-linux-gnu.tar.gz | ||
tar -xzf bitcoin-${{ env.bitcoind_version }}-x86_64-linux-gnu.tar.gz | ||
ln -s $(pwd)/bitcoin-${{ env.bitcoind_version }}/bin/bitcoin* /usr/local/bin | ||
sudo ln -s $(pwd)/bitcoin-${{ env.bitcoind_version }}/bin/bitcoin* /usr/local/bin |
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 sudo
necessary? why?
@@ -9,20 +9,19 @@ | |||
* at your option. | |||
*/ | |||
|
|||
use base64::{engine::general_purpose::URL_SAFE, Engine as _}; |
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 trait Engine doesn't have to be exported as _
.
use base64::{engine::general_purpose::URL_SAFE as BASE64, Engine};
pub fn get_new_rpc_client(&self) -> std::io::Result<RpcClient> { | ||
let http_endpoint = HttpEndpoint::for_host(self.host.to_owned()).with_port(self.port); | ||
let rpc_credentials = base64::encode(&format!("{}:{}", self.rpc_user, self.rpc_password)); | ||
RpcClient::new(&rpc_credentials, http_endpoint) | ||
let rpc_credentials = URL_SAFE.encode(format!("{}:{}", self.rpc_user, self.rpc_password)); | ||
Ok(RpcClient::new(&rpc_credentials, http_endpoint)) | ||
} |
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.
since this func is now infallible, we can return RpcClient
right away, so without wrapping it in a result.
pub fn sign(msg: &[u8], sk: &SecretKey) -> Result<String, Error> { | ||
message_signing::sign(msg, sk) | ||
Ok(message_signing::sign(msg, sk)) | ||
} |
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.
we can unwrap this out of the result
since it's infallible
let vec = Vec::from_hex(TXID_HEX).unwrap(); | ||
let hash: bitcoin::hashes::sha256d::Hash = bitcoin::hashes::Hash::from_slice(&vec).unwrap(); | ||
let txid = Txid::from(hash); |
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.
we can Txid::from_str
here instead.
4 more instances of these are below.
@@ -1239,9 +1239,15 @@ mod tests { | |||
MAX_ELAPSED_TIME as f64 + MAX_RUN_TIME, | |||
)) | |||
.await; | |||
let state = wt_client.lock().unwrap(); | |||
assert!(state.get_retrier_status(&tower_id).unwrap().is_idle()); | |||
|
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 consistently failing or just one or two times?
after the sleep above, we should ideally have the retrier idle and not wait until it is.
also could you share what system are u using for these tests? i find out that time/sleep tests fail a lot on macos systems for some reason.
// FIXME: replace this magic number with something meaningul | ||
let bits = bitcoin::CompactTarget::from_consensus(553713663); |
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.
we can build a normal target and then convert it to a compact one.
let hashes = txdata.iter().map(|obj| obj.txid().as_hash()); | ||
let mut header = BlockHeader { | ||
version: 0, | ||
let hashes = txdata.iter().map(|obj| obj.compute_txid().to_raw_hash()); |
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.
could u please replace obj
with tx
Update dependencies for
lightning
andbitcoin
as a prerequisite for #133The suggested change is mostly brute-force update. Suggestions for improvements of overall quality are very appreciated.
I'll clean history and apply other changes upon completion of review unless requested otherwise