Skip to content

Commit

Permalink
refactor!: Supply SignedBlock instead of SignedTransaction to peer (
Browse files Browse the repository at this point in the history
#4739)

refactor!: Supply `SignedBlock` instead of `SignedTransaction` to peer

Signed-off-by: Dmitry Murzin <diralik@yandex.ru>
  • Loading branch information
dima74 authored Jun 20, 2024
1 parent 230e0bb commit 0424c39
Show file tree
Hide file tree
Showing 23 changed files with 452 additions and 184 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ENV GID=1001

RUN <<EOT
set -eux
apk add --no-cache curl ca-certificates
apk add --no-cache curl ca-certificates jq
addgroup -g $GID $USER
adduser \
--disabled-password \
Expand Down
22 changes: 12 additions & 10 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use iroha_core::{
sumeragi::{GenesisWithPubKey, SumeragiHandle, SumeragiMetrics, SumeragiStartArgs},
IrohaNetwork,
};
use iroha_data_model::prelude::*;
use iroha_genesis::GenesisTransaction;
use iroha_data_model::{block::SignedBlock, prelude::*};
use iroha_genesis::GenesisBlock;
use iroha_logger::{actor::LoggerHandle, InitConfig as LoggerInitConfig};
use iroha_primitives::addr::SocketAddr;
use iroha_torii::Torii;
Expand Down Expand Up @@ -249,7 +249,7 @@ impl Iroha {
#[iroha_logger::log(name = "init", skip_all)] // This is actually easier to understand as a linear sequence of init statements.
pub async fn start_network(
config: Config,
genesis: Option<GenesisTransaction>,
genesis: Option<GenesisBlock>,
logger: LoggerHandle,
) -> Result<(impl core::future::Future<Output = ()>, Self), StartError> {
let network = IrohaNetwork::start(config.common.key_pair.clone(), config.network.clone())
Expand Down Expand Up @@ -597,7 +597,7 @@ pub enum ConfigError {
/// - If failed to load the genesis block
pub fn read_config_and_genesis(
args: &Args,
) -> Result<(Config, LoggerInitConfig, Option<GenesisTransaction>), ConfigError> {
) -> Result<(Config, LoggerInitConfig, Option<GenesisBlock>), ConfigError> {
let mut reader = ConfigReader::new();

if let Some(path) = &args.config {
Expand Down Expand Up @@ -627,11 +627,11 @@ pub fn read_config_and_genesis(
Ok((config, logger_config, genesis))
}

fn read_genesis(path: &Path) -> Result<GenesisTransaction, ConfigError> {
fn read_genesis(path: &Path) -> Result<GenesisBlock, ConfigError> {
let bytes = std::fs::read(path).change_context(ConfigError::ReadGenesis)?;
let genesis =
SignedTransaction::decode_all_versioned(&bytes).change_context(ConfigError::ReadGenesis)?;
Ok(GenesisTransaction(genesis))
SignedBlock::decode_all_versioned(&bytes).change_context(ConfigError::ReadGenesis)?;
Ok(GenesisBlock(genesis))
}

fn validate_config(config: &Config, submit_genesis: bool) -> Result<(), ConfigError> {
Expand Down Expand Up @@ -794,7 +794,7 @@ pub struct Args {

#[cfg(test)]
mod tests {
use iroha_genesis::GenesisTransactionBuilder;
use iroha_genesis::GenesisBuilder;

use super::*;

Expand Down Expand Up @@ -855,10 +855,11 @@ mod tests {
// Given

let genesis_key_pair = KeyPair::random();
let genesis = GenesisTransactionBuilder::default().build_and_sign(
let genesis = GenesisBuilder::default().build_and_sign(
dummy_executor(),
ChainId::from("00000000-0000-0000-0000-000000000000"),
&genesis_key_pair,
vec![],
);

let mut config = config_factory(genesis_key_pair.public_key());
Expand Down Expand Up @@ -925,10 +926,11 @@ mod tests {
// Given

let genesis_key_pair = KeyPair::random();
let genesis = GenesisTransactionBuilder::default().build_and_sign(
let genesis = GenesisBuilder::default().build_and_sign(
dummy_executor(),
ChainId::from("00000000-0000-0000-0000-000000000000"),
&genesis_key_pair,
vec![],
);

let mut config = config_factory(genesis_key_pair.public_key());
Expand Down
12 changes: 7 additions & 5 deletions client/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use iroha::{
client::{asset, Client},
data_model::prelude::*,
};
use iroha_genesis::GenesisTransactionBuilder;
use iroha_genesis::GenesisBuilder;
use iroha_primitives::unique_vec;
use iroha_version::Encode;
use irohad::samples::{construct_executor, get_config};
Expand All @@ -31,11 +31,12 @@ fn query_requests(criterion: &mut Criterion) {

let rt = Runtime::test();
let executor = construct_executor("../default_executor").expect("Failed to construct executor");
let genesis = GenesisTransactionBuilder::default()
let topology = vec![peer.id.clone()];
let genesis = GenesisBuilder::default()
.domain("wonderland".parse().expect("Valid"))
.account(get_key_pair(test_network::Signatory::Alice).into_parts().0)
.finish_domain()
.build_and_sign(executor, chain_id, &genesis_key_pair);
.build_and_sign(executor, chain_id, &genesis_key_pair, topology);

let builder = PeerBuilder::new()
.with_config(configuration)
Expand Down Expand Up @@ -118,18 +119,19 @@ fn instruction_submits(criterion: &mut Criterion) {

let chain_id = get_chain_id();
let genesis_key_pair = get_key_pair(test_network::Signatory::Genesis);
let topology = vec![peer.id.clone()];
let configuration = get_config(
unique_vec![peer.id.clone()],
chain_id.clone(),
get_key_pair(test_network::Signatory::Peer),
genesis_key_pair.public_key(),
);
let executor = construct_executor("../default_executor").expect("Failed to construct executor");
let genesis = GenesisTransactionBuilder::default()
let genesis = GenesisBuilder::default()
.domain("wonderland".parse().expect("Valid"))
.account(configuration.common.key_pair.public_key().clone())
.finish_domain()
.build_and_sign(executor, chain_id, &genesis_key_pair);
.build_and_sign(executor, chain_id, &genesis_key_pair, topology);
let builder = PeerBuilder::new()
.with_config(configuration)
.with_genesis(genesis);
Expand Down
12 changes: 7 additions & 5 deletions client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use iroha::{
crypto::KeyPair,
data_model::{isi::InstructionBox, prelude::*},
};
use iroha_genesis::{GenesisTransaction, GenesisTransactionBuilder};
use iroha_genesis::{GenesisBlock, GenesisBuilder};
use iroha_primitives::unique_vec;
use irohad::samples::{construct_executor, get_config};
use test_network::{
Expand All @@ -18,8 +18,9 @@ fn generate_genesis(
num_domains: u32,
chain_id: ChainId,
genesis_key_pair: &KeyPair,
) -> GenesisTransaction {
let mut builder = GenesisTransactionBuilder::default();
topology: Vec<PeerId>,
) -> GenesisBlock {
let mut builder = GenesisBuilder::default();

let signatory_alice = get_key_pair(test_network::Signatory::Alice).into_parts().0;
for i in 0_u32..num_domains {
Expand All @@ -34,22 +35,23 @@ fn generate_genesis(
}

let executor = construct_executor("../default_executor").expect("Failed to construct executor");
builder.build_and_sign(executor, chain_id, genesis_key_pair)
builder.build_and_sign(executor, chain_id, genesis_key_pair, topology)
}

fn main_genesis() {
let mut peer = <TestPeer>::new().expect("Failed to create peer");

let chain_id = get_chain_id();
let genesis_key_pair = get_key_pair(test_network::Signatory::Genesis);
let topology = vec![peer.id.clone()];
let configuration = get_config(
unique_vec![peer.id.clone()],
chain_id.clone(),
get_key_pair(test_network::Signatory::Peer),
genesis_key_pair.public_key(),
);
let rt = Runtime::test();
let genesis = generate_genesis(1_000_000_u32, chain_id, &genesis_key_pair);
let genesis = generate_genesis(1_000_000_u32, chain_id, &genesis_key_pair, topology);

let builder = PeerBuilder::new()
.with_genesis(genesis)
Expand Down
14 changes: 8 additions & 6 deletions client/examples/register_1000_triggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use iroha::{
client::Client,
data_model::{prelude::*, trigger::TriggerId},
};
use iroha_genesis::{GenesisTransaction, GenesisTransactionBuilder};
use iroha_genesis::{GenesisBlock, GenesisBuilder};
use iroha_primitives::unique_vec;
use irohad::samples::{construct_executor, get_config};
use test_network::{
Expand All @@ -19,8 +19,9 @@ fn generate_genesis(
num_triggers: u32,
chain_id: ChainId,
genesis_key_pair: &iroha_crypto::KeyPair,
) -> Result<GenesisTransaction, Box<dyn std::error::Error>> {
let builder = GenesisTransactionBuilder::default();
topology: Vec<PeerId>,
) -> Result<GenesisBlock, Box<dyn std::error::Error>> {
let builder = GenesisBuilder::default();

let wasm =
iroha_wasm_builder::Builder::new("tests/integration/smartcontracts/mint_rose_trigger")
Expand Down Expand Up @@ -51,17 +52,18 @@ fn generate_genesis(
let trigger = build_trigger(trigger_id);
Register::trigger(trigger)
})
.fold(builder, GenesisTransactionBuilder::append_instruction);
.fold(builder, GenesisBuilder::append_instruction);

let executor = construct_executor("../default_executor").expect("Failed to construct executor");
Ok(builder.build_and_sign(executor, chain_id, genesis_key_pair))
Ok(builder.build_and_sign(executor, chain_id, genesis_key_pair, topology))
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut peer: TestPeer = <TestPeer>::new().expect("Failed to create peer");

let chain_id = get_chain_id();
let genesis_key_pair = get_key_pair(test_network::Signatory::Genesis);
let topology = vec![peer.id.clone()];
let mut configuration = get_config(
unique_vec![peer.id.clone()],
chain_id.clone(),
Expand All @@ -73,7 +75,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
configuration.chain_wide.executor_runtime.fuel_limit = u64::MAX;
configuration.chain_wide.executor_runtime.max_memory = u32::MAX.into();

let genesis = generate_genesis(1_000_u32, chain_id, &genesis_key_pair)?;
let genesis = generate_genesis(1_000_u32, chain_id, &genesis_key_pair, topology)?;

let builder = PeerBuilder::new()
.with_genesis(genesis)
Expand Down
8 changes: 4 additions & 4 deletions client/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use iroha::{
transaction::error::TransactionRejectionReason, JsonString,
},
};
use iroha_genesis::GenesisTransaction;
use iroha_genesis::GenesisBlock;
use serde_json::json;
use test_network::{PeerBuilder, *};
use test_samples::{gen_account_in, ALICE_ID, BOB_ID};
Expand All @@ -21,11 +21,11 @@ fn genesis_transactions_are_validated() {

// Setting up genesis

let genesis = GenesisTransaction::test_with_instructions([Grant::permission(
let invalid_instruction = Grant::permission(
Permission::new("InvalidToken".parse().unwrap(), json!(null)),
ALICE_ID.clone(),
)
.into()]);
);
let genesis = GenesisBlock::test_with_instructions([invalid_instruction.into()], vec![]);

// Starting peer
let (_rt, _peer, test_client) = <PeerBuilder>::new()
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/triggers/by_call_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use iroha::{
transaction::{Executable, WasmSmartContract},
},
};
use iroha_genesis::GenesisTransaction;
use iroha_genesis::GenesisBlock;
use iroha_logger::info;
use serde_json::json;
use test_network::*;
Expand Down Expand Up @@ -440,7 +440,7 @@ fn trigger_in_genesis_using_base64() -> Result<()> {
);

// Registering trigger in genesis
let genesis = GenesisTransaction::test_with_instructions([Register::trigger(trigger).into()]);
let genesis = GenesisBlock::test_with_instructions([Register::trigger(trigger).into()], vec![]);

let (_rt, _peer, mut test_client) = <PeerBuilder>::new()
.with_genesis(genesis)
Expand Down
2 changes: 1 addition & 1 deletion config/src/parameters/actual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct Network {
pub struct Genesis {
/// Genesis account public key
pub public_key: PublicKey,
/// Path to `GenesisTransaction`.
/// Path to `GenesisBlock`.
/// If it is none, the peer can only observe the genesis block.
/// If it is some, the peer is responsible for submitting the genesis block.
pub signed_file: Option<WithOrigin<PathBuf>>,
Expand Down
17 changes: 16 additions & 1 deletion configs/swarm/docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
GENESIS_SIGNED_FILE: /tmp/genesis.signed.scale
SUMERAGI_TRUSTED_PEERS: '[{"address":"irohad1:1338","public_key":"ed012083C85E315776FD2DDC187ECB23E608F800B313A1D614B108078EC048D5013D2D"},{"address":"irohad2:1339","public_key":"ed0120A37B7B758C952FE9429E9E35D1D71E2D8BB9364EDD077B5027ABAAC798D3230E"},{"address":"irohad3:1340","public_key":"ed0120B23E14F659B91736AAB980B6ADDCE4B1DB8A138AB0267E049C082A744471714E"}]'
GENESIS_PRIVATE_KEY: 80264082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD4164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
TOPOLOGY: '[{"address":"irohad0:1337","public_key":"ed012082528CCC8727333530C8F6F19F70C23882DEB1BF2BA3BE4A6654C7E8A91A7731"},{"address":"irohad1:1338","public_key":"ed012083C85E315776FD2DDC187ECB23E608F800B313A1D614B108078EC048D5013D2D"},{"address":"irohad2:1339","public_key":"ed0120A37B7B758C952FE9429E9E35D1D71E2D8BB9364EDD077B5027ABAAC798D3230E"},{"address":"irohad3:1340","public_key":"ed0120B23E14F659B91736AAB980B6ADDCE4B1DB8A138AB0267E049C082A744471714E"}]'
ports:
- 1337:1337
- 8080:8080
Expand All @@ -22,7 +24,20 @@ services:
init: true
command: |-
/bin/sh -c "
kagami genesis sign /config/genesis.json --public-key $$GENESIS_PUBLIC_KEY --private-key 80264082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD4164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 --out-file $$GENESIS_SIGNED_FILE &&
EXECUTOR_RELATIVE_PATH=$(jq -r '.executor' /config/genesis.json) && \\
EXECUTOR_ABSOLUTE_PATH=$(realpath \"/config/$$EXECUTOR_RELATIVE_PATH\") && \\
jq \\
--arg executor \"$$EXECUTOR_ABSOLUTE_PATH\" \\
--argjson topology \"$$TOPOLOGY\" \\
'.executor = $$executor | .topology = $$topology' /config/genesis.json \\
>/tmp/genesis.json && \\
kagami genesis sign /tmp/genesis.json \\
--public-key $$GENESIS_PUBLIC_KEY \\
--private-key $$GENESIS_PRIVATE_KEY \\
--out-file $$GENESIS_SIGNED_FILE \\
&& \\
irohad --submit-genesis
"
healthcheck:
Expand Down
17 changes: 16 additions & 1 deletion configs/swarm/docker-compose.single.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ services:
API_ADDRESS: 0.0.0.0:8080
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
GENESIS_SIGNED_FILE: /tmp/genesis.signed.scale
GENESIS_PRIVATE_KEY: 80264082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD4164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
TOPOLOGY: '[{"address":"irohad0:1337","public_key":"ed012082528CCC8727333530C8F6F19F70C23882DEB1BF2BA3BE4A6654C7E8A91A7731"}]'
ports:
- 1337:1337
- 8080:8080
Expand All @@ -21,7 +23,20 @@ services:
init: true
command: |-
/bin/sh -c "
kagami genesis sign /config/genesis.json --public-key $$GENESIS_PUBLIC_KEY --private-key 80264082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD4164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 --out-file $$GENESIS_SIGNED_FILE &&
EXECUTOR_RELATIVE_PATH=$(jq -r '.executor' /config/genesis.json) && \\
EXECUTOR_ABSOLUTE_PATH=$(realpath \"/config/$$EXECUTOR_RELATIVE_PATH\") && \\
jq \\
--arg executor \"$$EXECUTOR_ABSOLUTE_PATH\" \\
--argjson topology \"$$TOPOLOGY\" \\
'.executor = $$executor | .topology = $$topology' /config/genesis.json \\
>/tmp/genesis.json && \\
kagami genesis sign /tmp/genesis.json \\
--public-key $$GENESIS_PUBLIC_KEY \\
--private-key $$GENESIS_PRIVATE_KEY \\
--out-file $$GENESIS_SIGNED_FILE \\
&& \\
irohad --submit-genesis
"
healthcheck:
Expand Down
17 changes: 16 additions & 1 deletion configs/swarm/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
GENESIS_PUBLIC_KEY: ed01204164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
GENESIS_SIGNED_FILE: /tmp/genesis.signed.scale
SUMERAGI_TRUSTED_PEERS: '[{"address":"irohad1:1338","public_key":"ed012083C85E315776FD2DDC187ECB23E608F800B313A1D614B108078EC048D5013D2D"},{"address":"irohad2:1339","public_key":"ed0120A37B7B758C952FE9429E9E35D1D71E2D8BB9364EDD077B5027ABAAC798D3230E"},{"address":"irohad3:1340","public_key":"ed0120B23E14F659B91736AAB980B6ADDCE4B1DB8A138AB0267E049C082A744471714E"}]'
GENESIS_PRIVATE_KEY: 80264082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD4164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4
TOPOLOGY: '[{"address":"irohad0:1337","public_key":"ed012082528CCC8727333530C8F6F19F70C23882DEB1BF2BA3BE4A6654C7E8A91A7731"},{"address":"irohad1:1338","public_key":"ed012083C85E315776FD2DDC187ECB23E608F800B313A1D614B108078EC048D5013D2D"},{"address":"irohad2:1339","public_key":"ed0120A37B7B758C952FE9429E9E35D1D71E2D8BB9364EDD077B5027ABAAC798D3230E"},{"address":"irohad3:1340","public_key":"ed0120B23E14F659B91736AAB980B6ADDCE4B1DB8A138AB0267E049C082A744471714E"}]'
ports:
- 1337:1337
- 8080:8080
Expand All @@ -22,7 +24,20 @@ services:
init: true
command: |-
/bin/sh -c "
kagami genesis sign /config/genesis.json --public-key $$GENESIS_PUBLIC_KEY --private-key 80264082B3BDE54AEBECA4146257DA0DE8D59D8E46D5FE34887DCD8072866792FCB3AD4164BF554923ECE1FD412D241036D863A6AE430476C898248B8237D77534CFC4 --out-file $$GENESIS_SIGNED_FILE &&
EXECUTOR_RELATIVE_PATH=$(jq -r '.executor' /config/genesis.json) && \\
EXECUTOR_ABSOLUTE_PATH=$(realpath \"/config/$$EXECUTOR_RELATIVE_PATH\") && \\
jq \\
--arg executor \"$$EXECUTOR_ABSOLUTE_PATH\" \\
--argjson topology \"$$TOPOLOGY\" \\
'.executor = $$executor | .topology = $$topology' /config/genesis.json \\
>/tmp/genesis.json && \\
kagami genesis sign /tmp/genesis.json \\
--public-key $$GENESIS_PUBLIC_KEY \\
--private-key $$GENESIS_PRIVATE_KEY \\
--out-file $$GENESIS_SIGNED_FILE \\
&& \\
irohad --submit-genesis
"
healthcheck:
Expand Down
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
3 changes: 2 additions & 1 deletion configs/swarm/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,6 @@
}
],
"executor": "./executor.wasm",
"chain": "00000000-0000-0000-0000-000000000000"
"chain": "00000000-0000-0000-0000-000000000000",
"topology": []
}
Loading

0 comments on commit 0424c39

Please sign in to comment.