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

refactor(multisig)!: move from triggers to custom instructions #5217

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e37bb4d
refactor!: move multisig logics to custom instructions
s8sato Nov 1, 2024
00ec667
fix: don't continue to grant a role on failing to register the role
s8sato Nov 2, 2024
a4ac5b0
docs: fix doc test
s8sato Nov 2, 2024
657d3ad
chore: remove `CanRegisterAnyTrigger` `CanUnregisterAnyTrigger` permi…
s8sato Nov 2, 2024
b158c59
refactor: don't branch into `visit` and `execute` until leaf instruct…
s8sato Nov 3, 2024
4eedd61
refactor: clone and drop executor instance on recursive execution
s8sato Nov 3, 2024
da8e7fb
fix: don't just execute arbitrary approved instructions
s8sato Nov 4, 2024
f54bd6e
fix: propagate executor verdict
s8sato Nov 4, 2024
d75e932
review: address up to `#issuecomment-2453963837`
s8sato Nov 5, 2024
0e8f7e6
docs: Update readmes (#5219)
outoftardis Nov 5, 2024
3c1888d
review: rename to `visit_custom_instructions`
s8sato Nov 6, 2024
bc1d497
review: move to `{iroha_executor::default, iroha_executor_data_model}…
s8sato Nov 6, 2024
bdd2a09
review: minor updates since `#pullrequestreview-2414675315`
s8sato Nov 6, 2024
255782e
review: submit a new account with metadata filled
s8sato Nov 6, 2024
b0208cc
Revert "review: submit a new account with metadata filled"
s8sato Nov 6, 2024
e95f743
Merge branch 'main' into refactor/4930/custom_instructions
s8sato Nov 6, 2024
45b24d9
fix: prevent a double grant to the registrant who is also a signatory
s8sato Nov 6, 2024
e0a96f4
review: minor updates since `#pullrequestreview-2418103555`
s8sato Nov 7, 2024
183ff26
review: nonzero `quorum` and `transaction_ttl_ms`
s8sato Nov 7, 2024
70d51d0
review: replace `host.submit` with `executor.visit_*`
s8sato Nov 7, 2024
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

401 changes: 165 additions & 236 deletions crates/iroha/tests/multisig.rs

Large diffs are not rendered by default.

113 changes: 39 additions & 74 deletions crates/iroha_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,9 +1179,7 @@ mod json {
mod multisig {
use std::io::{BufReader, Read as _};

use iroha::multisig_data_model::{
MultisigAccountArgs, MultisigTransactionArgs, DEFAULT_MULTISIG_TTL_MS,
};
use iroha::multisig_data_model::*;

use super::*;

Expand All @@ -1190,7 +1188,7 @@ mod multisig {
pub enum Args {
/// Register a multisig account
Register(Register),
/// Propose a multisig transaction
/// Propose a multisig transaction, with `Vec<InstructionBox>` stdin
Propose(Propose),
/// Approve a multisig transaction
Approve(Approve),
Expand Down Expand Up @@ -1230,30 +1228,18 @@ mod multisig {

impl RunArgs for Register {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
account,
signatories,
weights,
quorum,
transaction_ttl,
} = self;
if signatories.len() != weights.len() {
if self.signatories.len() != self.weights.len() {
return Err(eyre!("signatories and weights must be equal in length"));
}
let registry_id: TriggerId = format!("multisig_accounts_{}", account.domain())
.parse()
.unwrap();
let args = MultisigAccountArgs {
account: account.signatory().clone(),
signatories: signatories.into_iter().zip(weights).collect(),
quorum,
transaction_ttl_ms: transaction_ttl
let register_multisig_account = MultisigRegister::new(
self.account,
self.signatories.into_iter().zip(self.weights).collect(),
self.quorum,
self.transaction_ttl
.as_millis()
.try_into()
.expect("ttl must be within 584942417 years"),
};
let register_multisig_account =
iroha::data_model::isi::ExecuteTrigger::new(registry_id).with_args(&args);
);

submit([register_multisig_account], Metadata::default(), context)
.wrap_err("Failed to register multisig account")
Expand All @@ -1270,14 +1256,6 @@ mod multisig {

impl RunArgs for Propose {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self { account } = self;
let registry_id: TriggerId = format!(
"multisig_transactions_{}_{}",
account.signatory(),
account.domain()
)
.parse()
.unwrap();
let instructions: Vec<InstructionBox> = {
let mut reader = BufReader::new(stdin());
let mut raw_content = Vec::new();
Expand All @@ -1287,9 +1265,7 @@ mod multisig {
};
let instructions_hash = HashOf::new(&instructions);
println!("{instructions_hash}");
let args = MultisigTransactionArgs::Propose(instructions);
let propose_multisig_transaction =
iroha::data_model::isi::ExecuteTrigger::new(registry_id).with_args(&args);
let propose_multisig_transaction = MultisigPropose::new(self.account, instructions);

submit([propose_multisig_transaction], Metadata::default(), context)
.wrap_err("Failed to propose transaction")
Expand All @@ -1309,20 +1285,8 @@ mod multisig {

impl RunArgs for Approve {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
account,
instructions_hash,
} = self;
let registry_id: TriggerId = format!(
"multisig_transactions_{}_{}",
account.signatory(),
account.domain()
)
.parse()
.unwrap();
let args = MultisigTransactionArgs::Approve(instructions_hash);
let approve_multisig_transaction =
iroha::data_model::isi::ExecuteTrigger::new(registry_id).with_args(&args);
MultisigApprove::new(self.account, self.instructions_hash);

submit([approve_multisig_transaction], Metadata::default(), context)
.wrap_err("Failed to approve transaction")
Expand All @@ -1345,6 +1309,22 @@ mod multisig {
}
}

const DELIMITER: char = '/';
const PROPOSALS: &str = "proposals";
const MULTISIG_SIGNATORY: &str = "MULTISIG_SIGNATORY";

fn multisig_account_from(role: &RoleId) -> Option<AccountId> {
role.name()
.as_ref()
.strip_prefix(MULTISIG_SIGNATORY)?
.rsplit_once(DELIMITER)
.and_then(|(init, last)| {
format!("{last}@{}", init.trim_matches(DELIMITER))
.parse()
.ok()
})
}

/// Recursively trace back to the root multisig account
fn trace_back_from(
account: AccountId,
Expand All @@ -1353,42 +1333,27 @@ mod multisig {
) -> Result<()> {
let Ok(multisig_roles) = client
.query(FindRolesByAccountId::new(account))
.filter_with(|role_id| role_id.name.starts_with("multisig_signatory_"))
.filter_with(|role_id| role_id.name.starts_with(MULTISIG_SIGNATORY))
.execute_all()
else {
return Ok(());
};

for role_id in multisig_roles {
let super_account: AccountId = role_id
.name()
.as_ref()
.strip_prefix("multisig_signatory_")
.unwrap()
.replacen('_', "@", 1)
.parse()
.unwrap();

trace_back_from(super_account, client, context)?;

let transactions_registry_id: TriggerId = role_id
.name()
.as_ref()
.replace("signatory", "transactions")
.parse()
.unwrap();

context.print_data(&transactions_registry_id)?;

let transactions_registry = client
.query(FindTriggers::new())
.filter_with(|trigger| trigger.id.eq(transactions_registry_id))
let super_account_id: AccountId = multisig_account_from(&role_id).unwrap();

trace_back_from(super_account_id.clone(), client, context)?;

context.print_data(&super_account_id)?;

let super_account = client
.query(FindAccounts)
.filter_with(|account| account.id.eq(super_account_id))
.execute_single()?;
let proposal_kvs = transactions_registry
.action()
let proposal_kvs = super_account
.metadata()
.iter()
.filter(|kv| kv.0.as_ref().starts_with("proposals"));
.filter(|kv| kv.0.as_ref().starts_with(PROPOSALS));

proposal_kvs.fold("", |acc, (k, v)| {
let mut path = k.as_ref().split('/');
Expand Down
1 change: 1 addition & 0 deletions crates/iroha_executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ debug = ["iroha_smart_contract/debug"]
iroha_executor_derive = { path = "../iroha_executor_derive" }

iroha_executor_data_model.workspace = true
iroha_multisig_data_model.workspace = true
iroha_smart_contract_utils.workspace = true
iroha_smart_contract.workspace = true
iroha_schema.workspace = true
Expand Down
Loading
Loading