Skip to content

Commit

Permalink
Merge #387: Added participant_type to get_info
Browse files Browse the repository at this point in the history
24de726 Added participant_type to get_info. (Zshan0)
43071cf Changed `ManagerStakeholder` to `StakeholderManager`. (Zshan0)
6091013 Moved `UserRole` to `revaultd.rs`. (Zshan0)

Pull request description:

  Continuing #379, the requested features have been added and arrange in the required commit format.

ACKs for top commit:
  edouardparis:
    ACK 24de726

Tree-SHA512: 67606b42be2ecc9eca01771e549281c8c0bd9020e29d8b667e46a667bf47508a76ab668361a071f77545dc30468b6d161029b3269a4942a512d9ad1531c34e70
  • Loading branch information
darosior committed Apr 11, 2022
2 parents 209de3e + 24de726 commit 457ff85
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 32 deletions.
2 changes: 1 addition & 1 deletion doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Display general information about the current daemon state.
| `vaults` | integer | Current number of vaults (unconfirmed are included) |
| `managers_threshold` | integer | Number of managers needed for spending the `unvault_tx` |
| `descriptors` | object | Three `string` entries: `deposit`, `unvault` and `cpfp` for the three Miniscript descriptors |

| `participant_type` | string | Answer can be `stakeholder`, `manager`, `stakeholdermanager` |

### `getdepositaddress`

Expand Down
14 changes: 13 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod utils;
pub use crate::{
bitcoind::{interface::WalletTransaction, BitcoindError},
communication::ServerStatus,
revaultd::{BlockchainTip, VaultStatus},
revaultd::{BlockchainTip, UserRole, VaultStatus},
};
use crate::{
communication::{
Expand Down Expand Up @@ -268,6 +268,15 @@ impl DaemonControl {
})
.count();

assert!(revaultd.is_stakeholder() || revaultd.is_manager());
let participant_type = if revaultd.is_manager() && revaultd.is_stakeholder() {
UserRole::StakeholderManager
} else if revaultd.is_manager() {
UserRole::Manager
} else {
UserRole::Stakeholder
};

GetInfoResult {
version: VERSION.to_string(),
network: revaultd.bitcoind_config.network,
Expand All @@ -280,6 +289,7 @@ impl DaemonControl {
unvault: revaultd.unvault_descriptor.clone(),
cpfp: revaultd.cpfp_descriptor.clone(),
},
participant_type,
}
}

Expand Down Expand Up @@ -1430,6 +1440,8 @@ pub struct GetInfoResult {
pub vaults: usize,
pub managers_threshold: usize,
pub descriptors: GetInfoDescriptors,
#[serde(serialize_with = "ser_to_string", deserialize_with = "deser_from_str")]
pub participant_type: UserRole,
}

/// Information about a vault.
Expand Down
12 changes: 5 additions & 7 deletions src/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,9 @@ mod tests {
},
schema::{DbTransaction, DbVault},
},
revaultd::{RevaultD, VaultStatus},
revaultd::{RevaultD, UserRole, VaultStatus},
setup_db,
utils::test_utils::{
dummy_revaultd, insert_vault_in_db, test_datadir, MockBitcoindThread, UserRole,
},
utils::test_utils::{dummy_revaultd, insert_vault_in_db, test_datadir, MockBitcoindThread},
};
use revault_tx::{
bitcoin::{
Expand Down Expand Up @@ -888,7 +886,7 @@ mod tests {
#[test]
fn test_listvaults_from_db() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
setup_db(&mut revaultd).unwrap();
let vaults = create_vaults(&revaultd);

Expand Down Expand Up @@ -978,7 +976,7 @@ mod tests {
#[test]
fn test_vaults_from_deposits() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
let db_file = revaultd.db_file();
setup_db(&mut revaultd).unwrap();
let vaults = create_vaults(&revaultd);
Expand Down Expand Up @@ -1390,7 +1388,7 @@ mod tests {
#[test]
fn test_gethistory() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
setup_db(&mut revaultd).unwrap();
let db_file = revaultd.db_file();

Expand Down
5 changes: 3 additions & 2 deletions src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,14 @@ pub fn check_spend_transaction_size(revaultd: &RevaultD, spend_tx: SpendTransact

#[cfg(test)]
mod tests {
use crate::revaultd::UserRole;
use crate::{
communication::*,
database::{
bitcointx::{RevaultTx, TransactionType},
schema::DbTransaction,
},
utils::test_utils::{dummy_revaultd, test_datadir, UserRole},
utils::test_utils::{dummy_revaultd, test_datadir},
};
use revault_net::{
message, sodiumoxide::crypto::box_::curve25519xsalsa20poly1305::gen_keypair,
Expand Down Expand Up @@ -1205,7 +1206,7 @@ mod tests {
#[test]
fn test_check_spend_transaction_size() {
let datadir = test_datadir();
let revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
// 3 inputs, 4 outputs, 3 stakeholders and 3 manager psbt. No problem.
let tx = SpendTransaction::from_psbt_str("cHNidP8BAP0ZAQIAAAADSe9QbkOAlLapVzhNT2J2sCWXMqe2x7g7klEr3N6+p8AAAAAAAAYAAABwwCBKiamcBn5fj0oQ3WcAU+twE4XemcK4G2nlprqBKAAAAAAABgAAAAwCYIUh0y2bkIH8BVZ/evuFulOCxOyGr/rvZnR2k/9aAAAAAAAGAAAABFCoAAAAAAAAIgAgvXwvxBU2X03+pufsytFJ2dS4BKVXIKMQmyxUXTbPJPmA8PoCAAAAABYAFCMDXGnefAb487YxeNjnpbUzH+pEQEtMAAAAAAAWABT+rq2LTo+bnAo3ZQoeUg0F6xVZbIx3EwIAAAAAIgAgfAYV/vqzwEWHS6kVMjA1yQRbIQqq//o7m4ik0eSSlasAAAAAAAEBKzb0VQMAAAAAIgAgEyIAQqFnv+D0rMmVvusK3TC6fPyFk7aU1PZ8+Ttm23IBAwQBAAAAAQXBUiEDNWoO4CCloCul5eCLd1+XLPxP4LMIsUy+XM01wlm59wIhAqQ3tGeAeMBPPR26fn0kuL0CS0AybrDlu8NwIz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J9FU65kdqkU1lhk15tVMROK6qg9hZIikveK/GGIrGt2qRQgb3p9sHeUAhaBwJf4kR4PvUiZIIisbJNrdqkUT/5hNznrEzupEiToLAQKMi03zvKIrGyTU4dnVrJoIgYCBI1AhZI2dhKt8SXyO7NMrD2jcGNhD4OBvKLNKGorMhwIwxWgvwAAAAAiBgLblte6cEoOmasC9eIFsn/7H06jmkv7wWEqACpdJ6yfRQjvRRwXAAAAACIGA361G3JukjFUr0h3DGxPEWDLZiyJCq2ca+ejBd6U9uUmCFvhbX4AAAAAACICArFlfWaPsqMsvdC+/3Hise+ubUHtj4n5Uz7qaI0bCfCWCBhRVloBAAAAIgICtg6ewcvt4XnF35qT+j9KoCYt4+vS8hXmOn1NsO/QppUIgryGbgEAAAAiAgOJmnB0i/XOb8ITGRA3itrYfvWx6/B8PGMiu2SYfOACFQhTR/BbAQAAAAAAACICAr+BTfGuO1VRPxE1DJoFIsH1Vu5Dk5lSullVQjCXjVlICEPuDksBAAAAIgIC+G7/TA9DNgnMf4Nup2Py3XAF8UCLmziV3Vw4Z2KsJcwIpbzhFQEAAAAiAgOpos5KhVRQaTPJTi3mk12g5sApoQNVGdOpMcMmn7C7gwieIH0+AQAAAAA=").unwrap();
assert!(check_spend_transaction_size(&revaultd, tx));
Expand Down
17 changes: 9 additions & 8 deletions src/database/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,8 @@ pub fn db_mark_rebroadcastable_spend(
mod test {
use super::*;
use crate::database::schema::DbSpendTransaction;
use crate::utils::test_utils::{dummy_revaultd, test_datadir, UserRole};
use crate::revaultd::UserRole;
use crate::utils::test_utils::{dummy_revaultd, test_datadir};
use revault_tx::{
bitcoin::{
Network, OutPoint, PrivateKey as BitcoinPrivKey, PublicKey as BitcoinPubKey,
Expand Down Expand Up @@ -1100,7 +1101,7 @@ mod test {
#[test]
fn test_db_creation() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);

create_db(&mut revaultd).unwrap();
// There must be a wallet entry now, and there is only one so its id must
Expand Down Expand Up @@ -1129,7 +1130,7 @@ mod test {
#[test]
fn test_db_fetch_deposits() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
let db_path = revaultd.db_file();

setup_db(&mut revaultd).unwrap();
Expand Down Expand Up @@ -1235,7 +1236,7 @@ mod test {
#[test]
fn test_db_store_presigned_txs() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
let db_path = revaultd.db_file();
let secp_ctx = secp256k1::Secp256k1::new();

Expand Down Expand Up @@ -1535,7 +1536,7 @@ mod test {
#[test]
fn test_db_confirm_unvault() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
let db_path = revaultd.db_file();

setup_db(&mut revaultd).unwrap();
Expand Down Expand Up @@ -1610,7 +1611,7 @@ mod test {
#[test]
fn test_db_concurrent_write() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
let db_path = revaultd.db_file();
let secp_ctx = secp256k1::Secp256k1::new();

Expand Down Expand Up @@ -1688,7 +1689,7 @@ mod test {
#[test]
fn test_db_spend_storage() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
let db_path = revaultd.db_file();
let fresh_cancel_tx = CancelTransaction::from_psbt_str("cHNidP8BAF4CAAAAARoHs0elD2sCfWV4+b7PH3aRA+BkRVNf3m/P+Epjx2fNAAAAAAD9////AdLKAgAAAAAAIgAgB6abzQJ4vo5CO9XW3r3JnNumTwlpQbZm9FVICsLHPYQAAAAAAAEBK0ANAwAAAAAAIgAglEs6phQpv+twnAQSdjDvAEic65OtUIijeePBzAAqr50BAwSBAAAAAQWrIQO4lrAuffeRLuEEuwp2hAMZIPmqaHMTUySM3OwdA2hIW6xRh2R2qRTflccImFIy5NdTqwPuPZFB7g1pvYisa3apFOQxXoLeQv/aDFfav/l6YnYRKt+1iKxsk1KHZ1IhA32Q1DEqQ/kUP2MvQYFW46RCexZ5aYk17Arhp01th+37IQNrXQtfIXQdrv+RyyHLilJsb4ujlUMddG9X2jYkeXiWoFKvA3nxALJoIgYCEnb0lxeNI9466wDX+tqlq23zYNacTlLVLLLxtcVobG0INaO2mQoAAAAAAQFHUiED35umh5GhiToV6GS7lTokWfq/Rvy+rRI9XMQuf+foOoEhA9GtXpHhUvxcj9DJWbaRvz59CNsMwH2NEvmRa8gc2WRkUq4iAgISdvSXF40j3jrrANf62qWrbfNg1pxOUtUssvG1xWhsbQg1o7aZCgAAAAA=").unwrap();
let fresh_unvault_tx = UnvaultTransaction::from_psbt_str("cHNidP8BAIkCAAAAAfF2iPeJqz13zFlW6eLAM+uDu5IhUqcQxtMWQx7z5Y8lAAAAAAD9////AkANAwAAAAAAIgAgKb0SdnuqeHAJpRuZTbk3r81qbXpuHrMEmxT9Kph47HQwdQAAAAAAACIAIIMbpoIz4DI+aB1p/EJLyqjyDdDeZ7gG8kPhRIDiWaY8AAAAAAABASuIlAMAAAAAACIAIA9CgZ1cg/hn3iy3buDZvU5zUnQ9NzutToR/r42YZyu3AQMEAQAAAAEFR1IhA9P6hV8yf6HkNofzleom06eqkUxZayWHJnOMNlMtqvD3IQJo5Mj6Wf3ktrwEB3IQXFmgApibojplpNykg0hA8XV6SFKuIgYCEnb0lxeNI9466wDX+tqlq23zYNacTlLVLLLxtcVobG0INaO2mQoAAAAAAQGqIQMfu47eLiYeHN6Y3C1Vk0ckgmWifMy5IUhaPHbNELV93axRh2R2qRTtiGxBD5KrMQQU6UGx2zsKMMf6nIisa3apFCDKte9IuDeF0D4GA/JRUNX4xgt+iKxsk1KHZ1IhAzTPPnjrvzPFmi+raNR6sY8WTt1KNusVwp82uWebzWDwIQKl21mZX7WAQhRvdhhwqUAuQfIemg9zkTCCyMQ+Q8CVFVKvAqUBsmgiAgISdvSXF40j3jrrANf62qWrbfNg1pxOUtUssvG1xWhsbQg1o7aZCgAAAAABASUhAx+7jt4uJh4c3pjcLVWTRySCZaJ8zLkhSFo8ds0QtX3drFGHIgICEnb0lxeNI9466wDX+tqlq23zYNacTlLVLLLxtcVobG0INaO2mQoAAAAA").unwrap();
Expand Down Expand Up @@ -1956,7 +1957,7 @@ mod test {
#[test]
fn test_db_update_vault_status() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
let db_path = revaultd.db_file();

setup_db(&mut revaultd).unwrap();
Expand Down
5 changes: 3 additions & 2 deletions src/database/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,8 @@ pub fn db_vaults_with_txids_in_period(
mod test {
use super::*;
use crate::database::actions::{db_confirm_deposit, db_insert_new_unconfirmed_vault, setup_db};
use crate::utils::test_utils::{dummy_revaultd, test_datadir, UserRole};
use crate::revaultd::UserRole;
use crate::utils::test_utils::{dummy_revaultd, test_datadir};
use revault_tx::{bitcoin::OutPoint, transactions::transaction_chain};

use std::{fs, str::FromStr};
Expand All @@ -967,7 +968,7 @@ mod test {
#[test]
fn test_db_vaults_with_txids_in_period() {
let datadir = test_datadir();
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::ManagerStakeholder);
let mut revaultd = dummy_revaultd(datadir.clone(), UserRole::StakeholderManager);
let db_path = revaultd.db_file();
setup_db(&mut revaultd).unwrap();
let genesis_timestamp: u32 = 1231006505;
Expand Down
5 changes: 3 additions & 2 deletions src/jsonrpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ pub fn rpcserver_loop(
#[cfg(test)]
mod tests {
use super::{read_bytes_from_stream, rpcserver_loop, rpcserver_setup, trimmed};
use crate::utils::test_utils::{dummy_rpcutil, test_datadir, UserRole};
use crate::revaultd::UserRole;
use crate::utils::test_utils::{dummy_rpcutil, test_datadir};

use std::{
fs,
Expand All @@ -431,7 +432,7 @@ mod tests {
#[test]
fn simple_write_recv() {
let datadir = test_datadir();
let rpcutils = dummy_rpcutil(datadir.clone(), UserRole::ManagerStakeholder);
let rpcutils = dummy_rpcutil(datadir.clone(), UserRole::StakeholderManager);
let revaultd_datadir = rpcutils.revaultd.read().unwrap().data_dir.clone();
let mut rpc_socket_path = revaultd_datadir.clone();
rpc_socket_path.push("revaultd_rpc");
Expand Down
34 changes: 34 additions & 0 deletions src/revaultd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,40 @@ pub struct BlockchainTip {
pub hash: BlockHash,
}

#[derive(Debug, Clone)]
pub enum UserRole {
Stakeholder,
Manager,
StakeholderManager,
}

impl FromStr for UserRole {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"stakeholder" => Ok(Self::Stakeholder),
"stakeholdermanager" => Ok(Self::StakeholderManager),
"manager" => Ok(Self::Manager),
_ => Err(format!("Unknown role: {}", s)),
}
}
}

impl fmt::Display for UserRole {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match *self {
Self::Stakeholder => "stakeholder",
Self::Manager => "manager",
Self::StakeholderManager => "stakeholdermanager",
}
)
}
}

/// Our global state
pub struct RevaultD {
// Bitcoind stuff
Expand Down
11 changes: 2 additions & 9 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod test_utils {
use crate::{
bitcoind::{interface::WalletTransaction, BitcoindError},
database::interface::db_exec,
revaultd::{RevaultD, VaultStatus},
revaultd::{RevaultD, UserRole, VaultStatus},
threadmessages::{
BitcoindMessageOut, BitcoindSender, BitcoindThread, SigFetcherMessageOut,
},
Expand All @@ -24,13 +24,6 @@ pub mod test_utils {

use rusqlite::params;

#[derive(Debug, Clone)]
pub enum UserRole {
Stakeholder,
Manager,
ManagerStakeholder,
}

pub fn test_datadir() -> PathBuf {
static mut COUNTER: u64 = 0;
unsafe {
Expand Down Expand Up @@ -76,7 +69,7 @@ addr = "127.0.0.1:8332"
match role {
UserRole::Stakeholder => config += stake_config,
UserRole::Manager => config += man_config,
UserRole::ManagerStakeholder => {
UserRole::StakeholderManager => {
config += stake_config;
config += man_config;
}
Expand Down
1 change: 1 addition & 0 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_getinfo(revaultd_manager, bitcoind):
assert res["vaults"] == 0
# revaultd_manager always deploys with N = 2, M = 3, threshold = M
assert res["managers_threshold"] == 3
assert res["participant_type"] == "manager"
# test descriptors: RPC call & which Revaultd's were configured
assert res["descriptors"]["cpfp"] == revaultd_manager.cpfp_desc
assert res["descriptors"]["deposit"] == revaultd_manager.deposit_desc
Expand Down

0 comments on commit 457ff85

Please sign in to comment.