Skip to content

Commit

Permalink
chore!: upgrade bitflags crate (#5831)
Browse files Browse the repository at this point in the history
Description
---
Upgrade the bitflags crate to 2.4.0. This made a few notable changes:
- serde serialization changed from a map `{"bits": 0}` to just
outputting the compact bit `0`. It is possible to maintain the legacy
format but we don't need to keep that.
- bitflags maintain an internal representation which Borsh can't
serialize. So in the instance of KernerlFeatures the interface was
migrated from the use of the standard bitflags macro to defining the
struct ourself, and implementing a bitflags trait. This allows borsh to
operate as normal on the unit struct wrapper of the u8 rep.
- The kernel feature string representation in the faucet file required
updating, but the value is still the same once deserialized so it
shouldn't require a change in the genesis block, or tx's.
- It will still be a breaking change as old nodes and new nodes would
have a different serialized representation over rpc, and grpc.
- the bitflags crate no longer derives on the structs it creates. I've
manually added only the needed derivations to build, and pass tests.

Motivation and Context
---
We wanted to upgrade before release.
Closes: #5669 

[See v2 release changes for
bitflags](https://github.com/bitflags/bitflags/releases/tag/2.0.0)

How Has This Been Tested?
---
CI

What process can a PR reviewer use to test or verify this change?
---
Review the changes

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [ ] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [x] Other - May not be able to communicate with older nodes.

BREAKING CHANGE: May not be able to communicate with older nodes. Will
require users to upgrade their nodes

---------

Co-authored-by: SW van Heerden <swvheerden@gmail.com>
  • Loading branch information
brianp and SWvheerden authored Oct 11, 2023
1 parent f4f3845 commit dae7dd9
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 19 deletions.
11 changes: 7 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ console-subscriber = "0.1.8"
# Uncomment for normal use (non tokio-console tracing)
tokio = { version = "1.23", features = ["signal"] }

bitflags = "1.3.2"
bitflags = { version = "2.4", features = ["serde"] }
chrono = { version = "0.4.19", default-features = false }
clap = { version = "3.2", features = ["derive", "env"] }
config = "0.13.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,7 @@ pub enum UiTransactionBurnStatus {
}

bitflags! {
#[derive(Clone)]
pub struct TransactionFilter: u8 {
const NONE = 0b0000_0000;
const ABANDONED_COINBASES = 0b0000_0001;
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tari_common_sqlite = { path = "../../common_sqlite" }

async-trait = {version = "0.1.50"}
bincode = "1.1.4"
bitflags = "1"
bitflags = { version = "2.4", features = ["serde"] }
blake2 = "0.10"
borsh = { version = "0.10", features = ["const-generics"] }
bytes = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/blocks/faucets/esmeralda_faucet.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,4 @@
{"version":"V0","features":{"version":"V0","output_type":0,"maturity":3558240,"coinbase_extra":[],"sidechain_feature":null,"range_proof_type":"RevealedValue"},"commitment":"2c3dcafffc9a79dc10f6384d83519ba6b573acd4b03bad7dbb186166737fe851","proof":null,"script":"73","sender_offset_public_key":"ecc5a231ca6f0f14212d35cf91ca6ff5209396fa21f704ad9e2a127c33a04504","metadata_signature":{"ephemeral_commitment":"064193cf5831b2c35ba47230a3e3193e8878fc941b7d5cc48ef7b666d246ac6d","ephemeral_pubkey":"64779a975a3c07260a2d9cf8720852001e24de02f2dfea8b3de070e7b815e445","u_a":"082cddc87ad4086903383abad7cfb78b92a4b98b78c53bc4749ed122d431e50d","u_x":"329491fc8451e899b13d3eac400e304270b9712761d166603bea517ac6114100","u_y":"bd97658e77dcb35b0af01473abc0fa02ceb077083e4407b78645589b28f7d80e"},"covenant":"","encrypted_data":{"data":"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},"minimum_value_promise":1067769369090}
{"version":"V0","features":{"version":"V0","output_type":0,"maturity":3568320,"coinbase_extra":[],"sidechain_feature":null,"range_proof_type":"RevealedValue"},"commitment":"8cfc7c799721948ebbafbe8a7c386b43a72c02437191101090f16b2b98abc12c","proof":null,"script":"73","sender_offset_public_key":"d4f0710d42a72f5137b37d249bd9332fac41d0feef921a2646ffc1b318fcfc55","metadata_signature":{"ephemeral_commitment":"8acf637ed7bfbd8f6485a8fd1fc5deb67057aee73334b18b0fb9697162b0fb62","ephemeral_pubkey":"a81f809b36076379c61e5b75452854ae953ce56bf9649dc511e7cd15adc7262a","u_a":"6831907ab5355a0574451af3fbcab837477abaa97284a27bee6c034cee2aa909","u_x":"b2d7250e3ca94807dafab8fb0df35294fe3d25d0371b214733d2b6833aa76d03","u_y":"e0b4c7a236ad800f29de5a2dc7b6715c71eb41111e18be2eebe5a9999a296a09"},"covenant":"","encrypted_data":{"data":"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},"minimum_value_promise":1058372253648}
{"version":"V0","features":{"version":"V0","output_type":0,"maturity":3574176,"coinbase_extra":[],"sidechain_feature":null,"range_proof_type":"RevealedValue"},"commitment":"885306808c95dc65708bb406f3124f5a374d00a3f6111f6c5a26147be285d806","proof":null,"script":"73","sender_offset_public_key":"cc8cb1c24250ec490c577374bd1c7651aab9454ff982bed90c3ccfb426411f2d","metadata_signature":{"ephemeral_commitment":"faa2adb0cb7b50dcb67a0d870b628654969c4964365122dc585e1f0995b35810","ephemeral_pubkey":"629a1b26f1d5692da25868cd2d6eeb2f057e3dadd01ff7510475f1aecf048f07","u_a":"dc36aa0ae126630423b3096bb97efd42d9c9f951fac43ee8618965072dd22c07","u_x":"c9920aed9752b28fd344a8e3508de575e14722d655d3bb059667b4d11c86e204","u_y":"20d175e6da0fbccdb338cae156908abe055637aa01375fb22cedcde4d75e6703"},"covenant":"","encrypted_data":{"data":"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},"minimum_value_promise":610482446047}
{"version":"V0","features":{"bits":0},"fee":0,"lock_height":0,"excess":"ea6d44e2e369bec0c41bc23ebb3b7a9e1b06ad33b3a288e461a2fd229eb60122","excess_sig":{"public_nonce":"ea7f16718149ca831535b9109d0014c4f14ec6af59a5ebb7fed0c943c2cc1853","signature":"493edf49b9c1de9ebd6e1fa03c076260682c7767c9c9b5934f97ec8ff6513100"},"burn_commitment":null}
{"version":"V0","features":0,"fee":0,"lock_height":0,"excess":"ea6d44e2e369bec0c41bc23ebb3b7a9e1b06ad33b3a288e461a2fd229eb60122","excess_sig":{"public_nonce":"ea7f16718149ca831535b9109d0014c4f14ec6af59a5ebb7fed0c943c2cc1853","signature":"493edf49b9c1de9ebd6e1fa03c076260682c7767c9c9b5934f97ec8ff6513100"},"burn_commitment":null}
2 changes: 1 addition & 1 deletion base_layer/core/src/blocks/faucets/igor_faucet.json
Original file line number Diff line number Diff line change
Expand Up @@ -5524,4 +5524,4 @@
{"version":"V0","features":{"version":"V0","output_type":0,"maturity":11081144,"coinbase_extra":[],"sidechain_feature":null,"range_proof_type":"RevealedValue"},"commitment":"36ce6daabb0c724a25a448a28259d88ded75414a033ce0137c99acab5f033773","proof":null,"script":"73","sender_offset_public_key":"e0ee3b5f210fe858b5b5c088938b9c4b67bd265e3019836e1155abc133c3ff20","metadata_signature":{"ephemeral_commitment":"24e12529821d207d5aefe0b78e5d26e058555f07cef39be82b669b9ec8151d21","ephemeral_pubkey":"4c862f60bd8d92b72426784ed35666ac14a288d4b3a9a020fe6316399a7af14f","u_a":"5e37d07ac483f3beaf8259bcce1367c48d4ee5f905446a7fe364419984d2c301","u_x":"ae5918a416392930323764c67a08f223b2c85dca1609a8269e76e21cdfce3a0a","u_y":"dbd906f08bc6ef50d15eac666d841015d611955330821416ef0711b1040f170d"},"covenant":"","encrypted_data":{"data":"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},"minimum_value_promise":1054066742}
{"version":"V0","features":{"version":"V0","output_type":0,"maturity":11083150,"coinbase_extra":[],"sidechain_feature":null,"range_proof_type":"RevealedValue"},"commitment":"a254a0a59d30f8b1abde585a95103fda75a606e91bef66297528a5d6d1b0d301","proof":null,"script":"73","sender_offset_public_key":"b83923e9d6a0a4279232e4c2177baa99c2af1a0e3015b6559a950040ba296124","metadata_signature":{"ephemeral_commitment":"0c8d3c501de829d1e5a91c8e801ddb31344fc23b3611e657b0ffee4256996c55","ephemeral_pubkey":"963aec71faf233eed8db74bfb2196f0ba18899a0f59f2abba8bc38a08ab0fe2b","u_a":"aba654b0b8a6246847c1f45f79d45339697caea32f8780e6a80c953e5a45db05","u_x":"f750ccbdeaf4a5efc69b81048c23bb3586c33b317a30231405327a4f047bc40e","u_y":"691fbb99393d30a4c7271501dd3edce5a2304a5ff93221f7827efd745f22da04"},"covenant":"","encrypted_data":{"data":"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},"minimum_value_promise":1053060734}
{"version":"V0","features":{"version":"V0","output_type":0,"maturity":11084819,"coinbase_extra":[],"sidechain_feature":null,"range_proof_type":"RevealedValue"},"commitment":"b2467bab3f68c868c086cda08657bf74f959b53dc850b1ddfa902149ee01a857","proof":null,"script":"73","sender_offset_public_key":"1a5699ea448bdec8ab14df106892c8b59e23bcb08a0de35ab933f9cc04a66260","metadata_signature":{"ephemeral_commitment":"5ae908c58cef55c9b9c5e146e8c79dfcb2a7d1932d2d55af87cee1ca65954174","ephemeral_pubkey":"78438373e9cd7f5630e5475cc300a73a000e00fbf68b67072821b474a0af1d60","u_a":"03492fb6286f5ca19f8a496002883407ec880b191a33c90a2fb6a74c21784209","u_x":"60b8b6f13b5924b9b296b4fc903fe62ca1df4fcb5d7fbc2b8f62d94e0832df0b","u_y":"fe55c8a399ee5633abf84dda04c63ecd0cb37ed3ae3d4a5963f991870d426205"},"covenant":"","encrypted_data":{"data":"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},"minimum_value_promise":874859744}
{"version":"V0","features":{"bits":0},"fee":0,"lock_height":0,"excess":"32a0bb0088f6d8d454a1863ccdef0be227c58f4102d97107797cfba8e4ace978","excess_sig":{"public_nonce":"ecf229e5e4422e32def4ba8fcbab6c42c0d9a526707af5b0d6ec316e7b1c4a18","signature":"957a5fa257d56c58d053d7c6cb5d2704e5b5f4b80e196d359ed6f93f8183050c"},"burn_commitment":null}
{"version":"V0","features":0,"fee":0,"lock_height":0,"excess":"32a0bb0088f6d8d454a1863ccdef0be227c58f4102d97107797cfba8e4ace978","excess_sig":{"public_nonce":"ecf229e5e4422e32def4ba8fcbab6c42c0d9a526707af5b0d6ec316e7b1c4a18","signature":"957a5fa257d56c58d053d7c6cb5d2704e5b5f4b80e196d359ed6f93f8183050c"},"burn_commitment":null}
2 changes: 1 addition & 1 deletion base_layer/core/src/blocks/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ mod test {
let utxo_sum = block.block().body.outputs().iter().map(|o| &o.commitment).sum();
let kernel_sum = block.block().body.kernels().iter().map(|k| &k.excess).sum();

let db = create_new_blockchain_with_network(Network::Igor);
let db = create_new_blockchain_with_network(network);

let lock = db.db_read_access().unwrap();
ChainBalanceValidator::new(ConsensusManager::builder(network).build().unwrap(), Default::default())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};

/// Options for a kernel's structure or use.
#[derive(Serialize, Deserialize, BorshSerialize, BorshDeserialize, Clone, Copy, Debug, Eq, PartialEq)]
pub struct KernelFeatures(u8);

bitflags! {
/// Options for a kernel's structure or use.
#[derive(Deserialize, Serialize, BorshSerialize, BorshDeserialize)]
pub struct KernelFeatures: u8 {
impl KernelFeatures: u8 {
/// Coinbase transaction
const COINBASE_KERNEL = 1u8;
/// Burned output transaction
Expand Down
2 changes: 1 addition & 1 deletion comms/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tari_utilities = { version = "0.5" }

anyhow = "1.0.53"
async-trait = "0.1.36"
bitflags = "1"
bitflags = { version = "2.4", features = ["serde"] }
blake2 = "0.10"
bytes = { version = "1", features = ["serde"] }
chrono = { version = "0.4.19", default-features = false, features = ["serde", "clock"] }
Expand Down
2 changes: 1 addition & 1 deletion comms/core/src/peer_manager/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use crate::{

bitflags! {
/// Miscellaneous Peer flags
#[derive(Default, Deserialize, Serialize)]
#[derive(Default, Deserialize, Serialize, Eq, PartialEq, Debug, Clone, Copy)]
pub struct PeerFlags: u8 {
const NONE = 0x00;
const SEED = 0x01;
Expand Down
6 changes: 3 additions & 3 deletions comms/core/src/peer_manager/peer_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use serde::{Deserialize, Serialize};

bitflags! {
/// Peer feature flags. These advertised the capabilities of peer nodes.
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, PartialEq)]
pub struct PeerFeatures: u32 {
/// No capabilities
const NONE = 0b0000_0000;
Expand All @@ -37,9 +37,9 @@ bitflags! {
const DHT_STORE_FORWARD = 0b0000_0010;

/// Node is a communication node (typically a base layer node)
const COMMUNICATION_NODE = Self::MESSAGE_PROPAGATION.bits | Self::DHT_STORE_FORWARD.bits;
const COMMUNICATION_NODE = Self::MESSAGE_PROPAGATION.bits() | Self::DHT_STORE_FORWARD.bits();
/// Node is a network client
const COMMUNICATION_CLIENT = Self::NONE.bits;
const COMMUNICATION_CLIENT = Self::NONE.bits();
}
}

Expand Down
1 change: 1 addition & 0 deletions comms/core/src/protocol/negotiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct ProtocolNegotiation<'a, TSocket> {
}

bitflags! {
#[derive(Debug)]
struct Flags: u8 {
const NONE = 0x00;
const OPTIMISTIC = 0x01;
Expand Down
1 change: 1 addition & 0 deletions comms/core/src/protocol/rpc/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ impl Into<u32> for RpcMethod {
}

bitflags! {
#[derive(Debug, Clone, Copy)]
pub struct RpcMessageFlags: u8 {
/// Message stream has completed
const FIN = 0x01;
Expand Down
2 changes: 1 addition & 1 deletion comms/dht/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tari_storage = { path = "../../infrastructure/storage" }
tari_common_sqlite = { path = "../../common_sqlite" }

anyhow = "1.0.53"
bitflags = "1"
bitflags = { version = "2.4", features = ["serde"] }
chacha20 = "0.7.1"
chacha20poly1305 = "0.10.1"
chrono = { version = "0.4.19", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion comms/dht/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl fmt::Display for DhtMessageType {
bitflags! {
/// Used to indicate characteristics of the incoming or outgoing message, such
/// as whether the message is encrypted.
#[derive(Deserialize, Serialize, Default)]
#[derive(Deserialize, Serialize, Default, Copy, Clone, Debug, Eq, PartialEq)]
pub struct DhtMessageFlags: u32 {
const NONE = 0x00;
/// Set if the message is encrypted
Expand Down

0 comments on commit dae7dd9

Please sign in to comment.