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

Fix sample cli and bitcoin rpc provider #210

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
on: [push, pull_request]
on:
push:
branches:
- master
- 'testci/**'
pull_request:

name: Continuous integration

Expand All @@ -8,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: install clippy
run: rustup component add clippy
- name: Run clippy
Expand All @@ -18,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: install clippy
run: rustup component add clippy
- name: Run clippy dlc
Expand All @@ -32,7 +37,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Test
Expand All @@ -44,13 +49,13 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/cache@v2
- uses: actions/cache@v3
env:
cache-name: test-cache
with:
path: target/debug/deps
key: test-cache-${{ github.run_id }}-${{ github.run_number }}
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- id: set-matrix
run: cargo test --no-run && echo "::set-output name=matrix::$(scripts/get_test_list.sh execution manager channel_execution)"
integration_tests:
Expand All @@ -62,15 +67,15 @@ jobs:
matrix:
tests: ${{ fromJson(needs.integration_tests_prepare.outputs.matrix) }}
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v4
- uses: actions/cache@v3
env:
cache-name: test-cache
with:
path: target/debug/deps
key: test-cache-${{ github.run_id }}-${{ github.run_number }}
- name: Start bitcoin node
run: docker-compose up -d
run: docker compose up -d
- name: Wait for container to run
run: ./scripts/wait_for_container.sh bitcoin-node
- name: Wait for electrs to be ready
Expand All @@ -84,14 +89,19 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- name: Set permission
run: docker-compose run oracle-db bash -c "chown postgres:postgres /certs/db.key && chgrp postgres /certs/db.key && chmod 600 /certs/db.key"
- uses: actions/checkout@v4
- name: Start environment
run: docker-compose --profile oracle up -d
run: docker compose --profile oracle up -d
- name: Wait for container to run
run: ./scripts/wait_for_container.sh oracle-server
- name: Wait for electrs to be ready
run: ./scripts/wait_for_electrs.sh
- name: Create wallets
run: docker exec bitcoin-node /scripts/create_wallets.sh
- name: Run test
run: cargo test -- --ignored sample
run: |
if ! cargo test -- --ignored sample; then
cat sample/dlc_sample_alice/.dlc/logs/logs.txt
cat sample/dlc_sample_bob/.dlc/logs/logs.txt
exit 1
fi
23 changes: 15 additions & 8 deletions bitcoin-rpc-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ impl ContractSignerProvider for BitcoinCoreProvider {
"getaddressesbylabel",
&[Value::String(keys_id.to_lower_hex_string())],
)
.map_err(rpc_err_to_manager_err)?;
.unwrap_or_default();

if let Some(address) = label_map.keys().next() {
// we should only have one address per keys_id
// if not something has gone wrong
assert_eq!(label_map.len(), 1);
// note: importing a private key seem to generate three different addresses, we thus
// check that we have exactly three addresses for a single `keys_id`.
assert_eq!(label_map.len(), 3);

let sk = self
.client
Expand Down Expand Up @@ -274,7 +274,7 @@ impl Wallet for BitcoinCoreProvider {
.unwrap()
.call::<Address<NetworkUnchecked>>(
"getrawchangeaddress",
&[Value::Null, opt_into_json(Some(AddressType::Bech32))?],
&[opt_into_json(Some(AddressType::Bech32))?],
)
.map_err(rpc_err_to_manager_err)?
.assume_checked())
Expand Down Expand Up @@ -391,11 +391,18 @@ impl Wallet for BitcoinCoreProvider {
}

fn unreserve_utxos(&self, outpoints: &[OutPoint]) -> Result<(), ManagerError> {
match self.client.lock().unwrap().unlock_unspent(outpoints).map_err(rpc_err_to_manager_err)? {
match self
.client
.lock()
.unwrap()
.unlock_unspent(outpoints)
.map_err(rpc_err_to_manager_err)?
{
true => Ok(()),
false => Err(ManagerError::StorageError(format!("Failed to unlock utxos: {outpoints:?}")))
false => Err(ManagerError::StorageError(format!(
"Failed to unlock utxos: {outpoints:?}"
))),
Comment on lines +394 to +404
Copy link
Collaborator

@luckysori luckysori Apr 3, 2024

Choose a reason for hiding this comment

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

Is this just a formatting change? Maybe this wasn't intentional.

On a similar note, I often get formatting conflicts when working on rust-dlc since I use auto-formatting on save. Are we using rustfmt or not?

}

}
}

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
volumes:
- bitcoind-data:/home/bitcoin/.bitcoin
- ./testconfig/config:/config
- ./scripts:/scripts
electrs:
image: ghcr.io/cryptogarageinc/electrs:v0.4.12-bitcoin
command: |
Expand Down
Loading