From 92cb3b15bb2c029733d26c9dd62aaecc35537c04 Mon Sep 17 00:00:00 2001 From: 42Pupusas <133644935+42Pupusas@users.noreply.github.com> Date: Mon, 10 Jun 2024 05:43:14 -0600 Subject: [PATCH] Debugging and README Update (#5) --- README.md | 74 ++++++++++++++++++++++++++++++++------------ noah/src/database.rs | 24 ++++++-------- run_bitcoind.sh | 6 ++++ 3 files changed, 69 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index e16f1f5..e39b2f6 100644 --- a/README.md +++ b/README.md @@ -14,53 +14,87 @@ a library that contains all the primitives used for these implementations. You can play around with the tools as follows: -First you have to setup a regtest bitcoind node, there is a script provided for +First you have to setup a `regtest bitcoind` node, there is a script provided for that. If you want to run your own node, keep in mind that for now, we need it -to have the txindex enabled. +to have the txindex and server options enabled. ``` $ ./run_bitcoind.sh ``` +Edit the `bitcoin.conf` file in `test/bitcoindatadir` directory created by the script to include your RPC Auth credentials: + +``` +rpcauth= +``` + +The field `` comes in the format: `:$`. +RPC clients connect using `rpcuser=` and `rpcpassword=` arguments. +You can generate this value at [here](https://jlopp.github.io/bitcoin-core-rpc-auth-generator/). +This option can be specified multiple times. + +Run the script again, then take note of these lines when starting your node: + +``` +Binding RPC on address port +Using random cookie authentication. +Generated RPC authentication cookie +``` + +Your `` URL will be `:` and your `` will be the location where the cookie file was generated. + You can interact with the node using `bitcoin-cli` as follows: ``` -$ bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass getnetworkinfo +$ bitcoin-cli -regtest -rpcuser= -rpcpassword= getnetworkinfo ``` -Then, you can run an arkd server: +You can create an `arkd` server by running the following command: ``` -$ cargo run --bin arkd +$ cargo run --bin arkd create --datadir test/arkd --bitcoind-url --bitcoind-cookie ``` -This will start the server and it will work immediatelly. The configuration -currently is hard-coded in the `arkd/src/main.rs` file, and can only be changed -there. For arkd to work properly, you should fund it with some liquidity, this +This will create a new `arkd` server in the `test/` directory. You also can change the parameters as needed using the configuration file that gets created at `test/config.json`. + +You can then start the server with: + +``` +$ cargo run --bin arkd start --datadir test/arkd +``` + +For `arkd` to work properly, you should fund it with some liquidity, this can be done by sending some money to the address that is printed out when arkd is started. You can send money there as follows: ``` -$ bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass generatetoaddress 1 +$ bitcoin-cli -regtest -rpcuser= -rpcpassword= generatetoaddress 1 # Then give it 100 confirmations because it's a coinbase output. -$ bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass generatetoaddress 100 mtDDKi5mDjZqGzmbnfUnVQ8ZhCPMPVsApj +$ bitcoin-cli -regtest -rpcuser= -rpcpassword= generatetoaddress 100 mtDDKi5mDjZqGzmbnfUnVQ8ZhCPMPVsApj ``` Next, you can start some clients. To create a client, use the following command: ``` -$ cargo run --bin noah -- --datadir ./test/noah1 create -$ cargo run --bin noah -- --datadir ./test/noah2 create +$ cargo run --bin noah -- --datadir ./test/noah1 create --regtest --asp http:// --bitcoind --bitcoind-cookie +$ cargo run --bin noah -- --datadir ./test/noah2 create ... same as above ``` These will create individual wallets and print an on-chain address you can use -to **fund them the same way as you did for the ASP above**. Note that clients -can receive off-chain Ark transactions without having any on-chain balance, but -a little bit of on-chain money is needed to perform unilateral exits. +to **fund them the same way as you did for the ASP above**. -To use the onchain wallets, there are a few commands available: +Note that clients can receive off-chain Ark transactions without having any on-chain balance, +but a little bit of on-chain money is needed to perform unilateral exits. + +To use the on-chain wallets, there are a few commands available: ``` +# First lets fund one wallet +$ NOAH1_ADDR=$(cargo run --bin noah -- --datadir ./test/noah2 get-address) +$ bitcoin-cli -regtest -rpcuser= -rpcpassword= generatetoaddress 1 $NOAH1_ADDR +# Again give it 100 confirmations because it's a coinbase output. +$ bitcoin-cli -regtest -rpcuser= -rpcpassword= generatetoaddress 100 mtDDKi5mDjZqGzmbnfUnVQ8ZhCPMPVsApj +# Then send some money to the other wallet $ NOAH2_ADDR=$(cargo run --bin noah -- --datadir ./test/noah2 get-address) $ cargo run --bin noah -- --datadir ./test/noah1 send-onchain $NOAH2_ADDR "0.1 btc" $ cargo run --bin noah -- --datadir ./test/noah2 balance @@ -78,23 +112,23 @@ Remember that all txs will just be in the mempool if you don't generate blocks once a while... ``` -$ bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass generatetoaddress 1 mtDDKi5mDjZqGzmbnfUnVQ8ZhCPMPVsApj +$ bitcoin-cli -regtest -rpcuser=user -rpcpassword=pass generatetoaddress 10 mtDDKi5mDjZqGzmbnfUnVQ8ZhCPMPVsApj ``` Then, let's send some money off-chain to a third wallet: ``` -$ cargo run --bin noah -- --datadir ./test/noah3 create +$ cargo run --bin noah -- --datadir ./test/noah3 create ... with same flags as before $ cargo run --bin noah -- --datadir ./test/noah3 balance # Should be empty.. $ NOAH3_PK=$(cargo run --bin noah -- --datadir ./test/noah3 get-vtxo-pubkey) # For now every client has just a single pubkey. $ echo "${NOAH3_PK}" -$ cargo run --bin noah -- --datadir ./test/noah1 send ${NOAH3_PK} "0.1 btc" +$ cargo run --bin noah -- --datadir ./test/noah1 send-round ${NOAH3_PK} "0.1 btc" $ cargo run --bin noah -- --datadir ./test/noah3 balance ``` You will notice that there is a slight delay when sending, this is because the client needs to wait for the start of the next round and currently no out-of-round payments are supported. The round interval can be changed in the -arkd configuration. +`arkd` configuration. diff --git a/noah/src/database.rs b/noah/src/database.rs index ff340e9..fc33d43 100644 --- a/noah/src/database.rs +++ b/noah/src/database.rs @@ -49,11 +49,8 @@ impl Db { pub fn store_vtxo(&self, vtxo: &Vtxo) -> anyhow::Result<()> { let vtxo_tree = self.db.open_tree(VTXO_TREE)?; let expiry_tree = self.db.open_tree(VTXO_EXPIRY_TREE)?; - (vtxo_tree, expiry_tree).transaction(|(vtxo_tree, expiry_tree)| { - vtxo_tree.insert(vtxo.id(), vtxo.encode())?; - BucketTree::new(expiry_tree) - .insert(vtxo.spec().expiry_height.to_le_bytes(), &vtxo.id())?; - })?; + vtxo_tree.insert(vtxo.id(), vtxo.encode())?; + BucketTree::new(expiry_tree).insert(vtxo.spec().expiry_height.to_le_bytes(), &vtxo.id())?; Ok(()) } @@ -93,16 +90,13 @@ impl Db { pub fn remove_vtxo(&self, id: VtxoId) -> anyhow::Result> { let vtxo_tree = self.db.open_tree(VTXO_TREE)?; let expiry_tree = self.db.open_tree(VTXO_EXPIRY_TREE)?; - Ok((vtxo_tree, expiry_tree).transaction(|(vtxo_tree, expiry_tree)| { - if let Some(v) = vtxo_tree.remove(&id)? { - let ret = Vtxo::decode(&v).expect("corrupt db: invalid vtxo"); - BucketTree::new(expiry_tree) - .remove(ret.spec().expiry_height.to_le_bytes(), &id)?; - Ok(Some(ret)) - } else { - Ok(None) - } - })?) + if let Some(v) = vtxo_tree.remove(&id)? { + let ret = Vtxo::decode(&v).expect("corrupt db: invalid vtxo"); + BucketTree::new(expiry_tree).remove(ret.spec().expiry_height.to_le_bytes(), &id)?; + Ok(Some(ret)) + } else { + Ok(None) + } } /// This overrides the existing list of exit claim inputs with the new list. diff --git a/run_bitcoind.sh b/run_bitcoind.sh index d37273a..8790360 100755 --- a/run_bitcoind.sh +++ b/run_bitcoind.sh @@ -3,5 +3,11 @@ datadir=./test/bitcoindatadir mkdir -p ${datadir} +conf_file=${datadir}/bitcoin.conf + +# Check if bitcoin.conf exists, if not, create it +if [ ! -f "$conf_file" ]; then + touch "$conf_file" +fi bitcoind -regtest -datadir=${datadir} -server -txindex