Skip to content

Commit 145f79e

Browse files
authored
Merge pull request #1950 from mintlayer/trezor_firmware_versioning
Trezor firmware versioning
2 parents 3503b80 + 76774a6 commit 145f79e

37 files changed

Lines changed: 649 additions & 180 deletions

File tree

Cargo.lock

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ rlimit = "0.10"
211211
rstest = "0.24"
212212
rusqlite = "0.33"
213213
schnorrkel = "0.11"
214+
semver = "1.0"
214215
serde = "1.0"
215216
serde_json = "1.0"
216217
serde_test = "1.0"
@@ -248,8 +249,8 @@ zeroize = "1.5"
248249

249250
[workspace.dependencies.trezor-client]
250251
git = "https://github.com/mintlayer/mintlayer-trezor-firmware"
251-
# The commit "Remove destination from MintlayerFillOrderV1; fail if the host asks to sign a FillOrder input"
252-
rev = "198346c2f731e7ff34be03b7a16818008eeeae0d"
252+
# The commit "Mintlayer firmware versioning"
253+
rev = "397155e26660993a044e78447dad893852fa44d1"
253254
features = ["bitcoin", "mintlayer"]
254255

255256
[workspace.metadata.dist.dependencies.apt]

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Welcome to the official Github repository for Mintlayer, an innovative, open-source blockchain project. For detailed technical insights, we recommend visiting our [documentation](https://docs.mintlayer.org/).
44

5-
Please note, the code in this repository is currently under active development. Consequently, it should not be deemed production-ready. Nonetheless, you're invited to test the code in our active testnet environment.
6-
75
## Security
86

97
Discovered a potential security issue? We urge you to contact us directly at security@mintlayer.org. When reporting, please encrypt your report using Ben's GPG key which can be found [here](https://www.mintlayer.org/assets/keys/ben).
@@ -54,24 +52,26 @@ You can either keep running the code from source, using `cargo run --release --b
5452

5553
### Running software and how to control logging
5654

57-
The logging of mintlayer-core is configured via the `RUST_LOG` environment variable. All log messages are printed to the terminal screen; we prefer simplicity over complicated log machinery. For example, to see all logs of the `info` level and above (the default level for normal operation), you can run the node with `RUST_LOG=info cargo run --bin node-daemon -- testnet`. If you're facing an issue, it's recommended to use `RUST_LOG=debug` instead. We recommend using these commands that not only print the logs on the screen, but also write them to a file in case you face an issue. On Linux, this can be achieved using `tee` as shown below.
55+
Normally, the logging of mintlayer-core is configured via the `RUST_LOG` environment variable and all log messages are printed to the terminal screen. For example, to see all logs of the `info` level and above (the default level for normal operation), you can run the node with `RUST_LOG=info cargo run --bin node-daemon -- testnet`. If you're facing an issue, it's recommended to use `RUST_LOG=debug` instead. We recommend using the commands that not only print the logs on the screen, but also write them to a file in case you face an issue. On Linux, this can be achieved using `tee` as shown below.
5856

5957
If the `RUST_LOG` environment variable is not specified, the log level `info` will be used by default.
6058

59+
Additionally, independent of what is printed to the console, node's logs may also be automatically written to the data directory (on Linux, they will be inside `~/.mintlayer/mainnet/logs/` and `~/.mintlayer/testnet/logs/` for mainnet and testnet respectively); this is controlled by the `--log-to-file` option (e.g. `--log-to-file true`), which is accepted by both node-daemon and node-gui. By default, its value is false for node-daemon and true for node-gui. The log files are rotated based on size, so older logs will be automatically deleted eventually. Also note that the log level used in this case is always `info`, regardless of the value of `RUST_LOG`.
60+
6161
Here are the commands as recommended for different scenarios:
6262

6363
#### Assuming you're using the source code
6464

65-
Every release has a tag and a release branch. Make sure you checkout the release you need. For example, if you need v0.5.1, you should first run the following to check out the release branch:
65+
Every release has a tag and a release branch. Make sure you checkout the release you need. For example, if you need v1.0.0, you should first run the following to check out the release branch:
6666

6767
```sh
68-
git checkout release-v0.5.1
68+
git checkout release-v1.0.0
6969
```
7070

7171
or to checkout the tag:
7272

7373
```sh
74-
git checkout tags/v0.5.1
74+
git checkout tags/v1.0.0
7575
```
7676

7777
Release branches are more recommended than tags, because they get necessary security patches, if any. Tags are just markers.
@@ -156,11 +156,16 @@ cargo build --bin wallet-cli --target=aarch64-unknown-linux-gnu --release
156156
157157
The artifacts can be found in `target/aarch64-unknown-linux-gnu/release`, or a similar directory name.
158158
159-
160159
## Wallets
161160
162161
For more information about the wallets and their usage, [visit this readme file](wallet/README.md).
163162
163+
## Trezor support
164+
165+
Mintlayer wallets support Trezor hardware wallets, though it's still in Beta at this moment.
166+
167+
For details, [visit this readme file](wallet/TREZOR_SUPPORT.md).
168+
164169
## The API server
165170
166171
The API server is a tool for indexing the blockchain. Its source code is contained in this repository and its [readme can be found in its directory](api-server/README.md).

api-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
The Mintlayer API server is a tool that scans the blockchain and publishes its data in a database for easy access. Technically speaking, this is done to achieve the trade-off where the blockchain itself contains the minimal required amount of data, while the API server indexes all the data for easy reach. The API server is used by block explorers and web wallets. The API server is made to be usable in many ways, including in exchanges, by people interested in writing tooling for the blockchain, or anything else.
66

7-
For example to understand what problem the API server solves, the node software only stores blocks of the blockchain, but it does not index the transactions by their id. Meaning: Attempting to find a transaction by its id is virtually impossible without going through all blocks. This same applies to more information that's not directly, minimally, required to operate the blockchain. In that case, using the API server solves all these problems, since the API server is made to index the information and put it in the database.
7+
For example to understand what problem the API server solves, the node software only stores blocks of the blockchain, but it does not index the transactions by their id. Meaning: Attempting to find a transaction by its id is virtually impossible without going through all blocks. The same applies to more information that's not directly, minimally, required to operate the blockchain. In that case, using the API server solves all these problems, since the API server is made to index the information and put it in the database.
88

99
## Architecture
1010

build-tools/linux-systemd-service/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Note: If you're running mintlayer in your home or behind a consumer router, thes
77

88
Also, there are managed services that do this for you, but they're more expensive. We never had to use any of them, but it's up to you. One that comes to mind is Plesk. It's made to make server management easier. But it's not free.
99

10-
1. NEVER run mintlayer software as root or a user that has access to root. It's preferable to create a separate user for this
10+
1. NEVER run mintlayer software as root or a user that has access to root. It's preferable to create a separate user for this.
1111
2. NEVER keep all your server ports open. This is a huge security flaw that can endanger both your server and make stealing your coins easy. Mintlayer needs only port 13031 (testnet p2p) or 3031 (mainnet p2p). All other ports (maybe besides ssh) should be blocked by a firewall.
1212
3. DO NOT allow public access to RPC (port 13030 for testnet, 3030 for mainnet). RPC basically gives full control and it's meant for the owner.
1313
4. DO NOT bind RPC to 0.0.0.0 unless you know what you're doing. The correct way to reach your RPC is with an ssh tunnel, not by opening the RPC to the public.

consensus/src/pos/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ pub fn stake(
230230
let first_timestamp = *block_timestamp;
231231

232232
log::debug!(
233-
"Search for a valid block ({}..{}), pool_id: {}",
234-
first_timestamp,
235-
max_block_timestamp,
233+
"Search for a valid block, start: {}, slots count: {}, pool_id: {}",
234+
first_timestamp.into_time(),
235+
max_block_timestamp.as_int_seconds() - first_timestamp.as_int_seconds() + 1,
236236
Address::new(chain_config, *pos_data.stake_pool_id())
237237
.expect("Pool id to address cannot fail")
238238
);

node-gui/backend/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ wallet-cli-commands = { path = "../../wallet/wallet-cli-commands"}
3131
anyhow.workspace = true
3232
chrono.workspace = true
3333
futures.workspace = true
34+
itertools.workspace = true
35+
semver.workspace = true
3436
serde = { workspace = true, features = ["derive"] }
3537
serde_json.workspace = true
3638
serde_with.workspace = true

node-gui/backend/src/backend_impl.rs

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,30 @@
1515

1616
use std::{collections::BTreeMap, fmt::Debug, path::PathBuf, str::FromStr, sync::Arc};
1717

18+
use futures::{stream::FuturesOrdered, TryStreamExt};
19+
use tokio::{
20+
sync::mpsc::{UnboundedReceiver, UnboundedSender},
21+
task::JoinHandle,
22+
};
23+
1824
use common::{
1925
address::{Address, RpcAddress},
2026
chain::{ChainConfig, GenBlock, SignedTransaction},
2127
primitives::{per_thousand::PerThousand, BlockHeight, Id},
2228
};
2329
use crypto::key::hdkd::{child_number::ChildNumber, u31::U31};
24-
use futures::{stream::FuturesOrdered, TryStreamExt};
2530
use logging::log;
2631
use node_comm::rpc_client::ColdWalletClient;
2732
use node_lib::node_controller::NodeController;
2833
use serialization::hex_encoded::HexEncoded;
29-
use tokio::{
30-
sync::mpsc::{UnboundedReceiver, UnboundedSender},
31-
task::JoinHandle,
32-
};
3334
use wallet::{account::transaction_list::TransactionList, wallet::Error, WalletError};
3435
use wallet_cli_commands::{
3536
get_repl_command, parse_input, CommandHandler, ConsoleCommand, ManageableWalletCommand,
3637
WalletCommand,
3738
};
3839
use wallet_controller::{
3940
make_cold_wallet_rpc_client,
40-
types::{Balances, WalletCreationOptions, WalletTypeArgs},
41+
types::{Balances, WalletCreationOptions, WalletExtraInfo, WalletTypeArgs},
4142
ControllerConfig, NodeInterface, UtxoState, WalletHandlesClient,
4243
};
4344
use wallet_rpc_client::handles_client::WalletRpcHandlesClient;
@@ -361,6 +362,7 @@ impl Backend {
361362
};
362363

363364
let encryption = EncryptionState::Disabled;
365+
let wallet_extra_info = Self::get_wallet_extra_info(&wallet_data.controller).await?;
364366

365367
let wallet_info = WalletInfo {
366368
wallet_id,
@@ -369,13 +371,31 @@ impl Backend {
369371
accounts: accounts_info,
370372
best_block,
371373
wallet_type,
374+
extra_info: wallet_extra_info,
372375
};
373376

374377
self.wallets.insert(wallet_id, wallet_data);
375378

376379
Ok(wallet_info)
377380
}
378381

382+
async fn get_wallet_extra_info(
383+
controller: &GuiHotColdController,
384+
) -> Result<WalletExtraInfo, BackendError> {
385+
let wallet_info_from_rpc = match controller {
386+
GuiHotColdController::Hot(wallet_rpc, _) => wallet_rpc
387+
.wallet_info()
388+
.await
389+
.map_err(|err| BackendError::WalletError(err.to_string()))?,
390+
GuiHotColdController::Cold(wallet_rpc, _) => wallet_rpc
391+
.wallet_info()
392+
.await
393+
.map_err(|err| BackendError::WalletError(err.to_string()))?,
394+
};
395+
396+
Ok(wallet_info_from_rpc.extra_info)
397+
}
398+
379399
async fn create_wallet<N>(
380400
&mut self,
381401
handles_client: N,
@@ -414,10 +434,18 @@ impl Backend {
414434
overwrite_wallet_file: true,
415435
scan_blockchain: import.should_scan_blockchain(),
416436
};
417-
wallet_rpc
437+
let created_wallet = wallet_rpc
418438
.create_wallet(file_path, wallet_args, options)
419439
.await
420440
.map_err(|err| BackendError::WalletError(err.to_string()))?;
441+
match created_wallet {
442+
wallet_controller::types::CreatedWallet::UserProvidedMnemonic
443+
| wallet_controller::types::CreatedWallet::NewlyGeneratedMnemonic(_) => {}
444+
#[cfg(feature = "trezor")]
445+
wallet_controller::types::CreatedWallet::TrezorDeviceSelection(found_devices) => {
446+
return Err(BackendError::MultipleTrezorDevicesFound(found_devices))
447+
}
448+
}
421449
tokio::spawn(forward_events(
422450
wallet_events,
423451
wallet_service
@@ -572,13 +600,16 @@ impl Backend {
572600
}
573601
};
574602

603+
let wallet_extra_info = Self::get_wallet_extra_info(&wallet_data.controller).await?;
604+
575605
let wallet_info = WalletInfo {
576606
wallet_id,
577607
path: file_path,
578608
encryption,
579609
accounts: accounts_info,
580610
best_block,
581611
wallet_type,
612+
extra_info: wallet_extra_info,
582613
};
583614

584615
self.wallets.insert(wallet_id, wallet_data);
@@ -619,7 +650,7 @@ impl Backend {
619650
let node_rpc = wallet_service.node_rpc().clone();
620651
let chain_config = wallet_service.chain_config().clone();
621652
let wallet_rpc = WalletRpc::new(wallet_handle, node_rpc.clone(), chain_config.clone());
622-
wallet_rpc
653+
let opened_wallet = wallet_rpc
623654
.open_wallet(
624655
file_path,
625656
None,
@@ -629,6 +660,13 @@ impl Backend {
629660
)
630661
.await
631662
.map_err(|err| BackendError::WalletError(err.to_string()))?;
663+
match opened_wallet {
664+
| wallet_controller::types::OpenedWallet::Opened => {}
665+
#[cfg(feature = "trezor")]
666+
wallet_controller::types::OpenedWallet::TrezorDeviceSelection(found_devices) => {
667+
return Err(BackendError::MultipleTrezorDevicesFound(found_devices))
668+
}
669+
}
632670
tokio::spawn(forward_events(
633671
wallet_events,
634672
wallet_service

node-gui/backend/src/error.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
use itertools::Itertools as _;
17+
18+
#[cfg(feature = "trezor")]
19+
use wallet::signer::trezor_signer;
20+
1621
use super::{account_id::AccountId, messages::WalletId};
1722

1823
#[derive(thiserror::Error, Debug, Clone)]
@@ -47,4 +52,18 @@ pub enum BackendError {
4752
InvalidConsoleCommand(String),
4853
#[error("Empty console command")]
4954
EmptyConsoleCommand,
55+
56+
#[cfg(feature = "trezor")]
57+
#[error(
58+
"Multiple Trezor devices found: {}.\nLeave only one of them connected and try again.",
59+
format_multiple_trezor_devices_err(_0)
60+
)]
61+
MultipleTrezorDevicesFound(Vec<trezor_signer::FoundDevice>),
62+
}
63+
64+
fn format_multiple_trezor_devices_err(devices: &[trezor_signer::FoundDevice]) -> String {
65+
devices
66+
.iter()
67+
.map(|device| format!("{} (device id = {})", device.device_name, device.device_id))
68+
.join(", ")
5069
}

node-gui/backend/src/messages.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use p2p::P2pEvent;
3333
use serialization::hex_encoded::hex_encoded_serialization;
3434
use wallet::account::transaction_list::TransactionList;
3535
use wallet_cli_commands::ConsoleCommand;
36-
use wallet_controller::types::{Balances, WalletTypeArgs};
36+
use wallet_controller::types::{Balances, WalletExtraInfo, WalletTypeArgs};
3737
use wallet_rpc_lib::types::PoolInfo;
3838
use wallet_types::wallet_type::WalletType;
3939

@@ -58,6 +58,7 @@ pub struct WalletInfo {
5858
pub accounts: BTreeMap<AccountId, AccountInfo>,
5959
pub best_block: (Id<GenBlock>, BlockHeight),
6060
pub wallet_type: WalletType,
61+
pub extra_info: WalletExtraInfo,
6162
}
6263

6364
#[derive(Debug, Clone, Serialize)]

0 commit comments

Comments
 (0)