Skip to content

Commit

Permalink
Update Substrate to April 2023 snapshot (#67)
Browse files Browse the repository at this point in the history
* initial attempt - just search and replace

* cargo lock

* new metadata api

* work around remove `from_entropy` method

* Reflect keystore changes in runtime code

* fix warning

* Update tuxedo-core/src/verifier.rs

Co-authored-by: Andrew <andrewburger1991@gmail.com>

* make service compile

* formatting

* make wallet compile

* remove commented code

* Rewrite multisig tests in terms of thresholds (Helped me get unconfused)

---------

Co-authored-by: Andrew <andrewburger1991@gmail.com>
  • Loading branch information
JoshOrndorff and coax1d authored Apr 20, 2023
1 parent 8c36eec commit b696cd1
Show file tree
Hide file tree
Showing 9 changed files with 445 additions and 310 deletions.
474 changes: 323 additions & 151 deletions Cargo.lock

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,42 @@ name = "node-template"
[dependencies]
clap = { version = "4.0.29", features = ["derive"] }

sc-cli = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-core = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-executor = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-service = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-telemetry = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-keystore = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-transaction-pool = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-consensus-aura = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-consensus = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-consensus = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-consensus-grandpa = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-consensus-grandpa = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-client-api = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-timestamp = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-inherents = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-keyring = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
pallet-transaction-payment = { default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-cli = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-core = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-executor = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-service = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-telemetry = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-keystore = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-transaction-pool = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-consensus-aura = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-consensus = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-consensus = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-consensus-grandpa = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-consensus-grandpa = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-client-api = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-timestamp = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-inherents = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-keyring = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
pallet-transaction-payment = { default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }

# These dependencies are used for the node template's RPCs
jsonrpsee = { version = "0.16.2", features = ["server"] }
sc-rpc = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-api = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-rpc-api = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-blockchain = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sp-block-builder = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
sc-rpc = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-api = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-rpc-api = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-blockchain = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sp-block-builder = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }

# Local Dependencies
node-template-runtime = { package = "tuxedo-template-runtime", path = "../tuxedo-template-runtime" }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-03" }
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate.git", tag = "monthly-2023-04" }

[features]
default = []
42 changes: 9 additions & 33 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use sc_client_api::BlockBackend;
use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
use sc_consensus_grandpa::SharedVoterState;
pub use sc_executor::NativeElseWasmExecutor;
use sc_keystore::LocalKeystore;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
Expand Down Expand Up @@ -55,12 +54,6 @@ pub fn new_partial(
>,
ServiceError,
> {
if config.keystore_remote.is_some() {
return Err(ServiceError::Other(
"Remote Keystores are not supported.".into(),
));
}

let telemetry = config
.telemetry_endpoints
.clone()
Expand Down Expand Up @@ -148,38 +141,19 @@ pub fn new_partial(
})
}

fn remote_keystore(_url: &str) -> Result<Arc<LocalKeystore>, &'static str> {
// FIXME: here would the concrete keystore be built,
// must return a concrete type (NOT `LocalKeystore`) that
// implements `CryptoStore` and `SyncCryptoStore`
Err("Remote Keystore not supported.")
}

/// Builds a new service for a full client.
pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError> {
let sc_service::PartialComponents {
client,
backend,
mut task_manager,
import_queue,
mut keystore_container,
keystore_container,
select_chain,
transaction_pool,
other: (block_import, grandpa_link, mut telemetry),
} = new_partial(&config)?;

if let Some(url) = &config.keystore_remote {
match remote_keystore(url) {
Ok(k) => keystore_container.set_remote_keystore(k),
Err(e) => {
return Err(ServiceError::Other(format!(
"Error hooking up remote keystore for {}: {}",
url, e
)))
}
};
}

let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name(
&client
.block_hash(0)
Expand All @@ -201,7 +175,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
Vec::default(),
));

let (network, system_rpc_tx, tx_handler_controller, network_starter) =
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
Expand Down Expand Up @@ -245,13 +219,14 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
network: network.clone(),
client: client.clone(),
keystore: keystore_container.sync_keystore(),
keystore: keystore_container.keystore(),
task_manager: &mut task_manager,
transaction_pool: transaction_pool.clone(),
rpc_builder: rpc_extensions_builder,
backend,
system_rpc_tx,
tx_handler_controller,
sync_service: sync_service.clone(),
config,
telemetry: telemetry.as_mut(),
})?;
Expand Down Expand Up @@ -287,9 +262,9 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
},
force_authoring,
backoff_authoring_blocks,
keystore: keystore_container.sync_keystore(),
sync_oracle: network.clone(),
justification_sync_link: network.clone(),
keystore: keystore_container.keystore(),
sync_oracle: sync_service.clone(),
justification_sync_link: sync_service.clone(),
block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32),
max_block_proposal_slot_portion: None,
telemetry: telemetry.as_ref().map(|x| x.handle()),
Expand All @@ -307,7 +282,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
// if the node isn't actively participating in consensus then it doesn't
// need a keystore, regardless of which protocol we use below.
let keystore = if role.is_authority() {
Some(keystore_container.sync_keystore())
Some(keystore_container.keystore())
} else {
None
};
Expand Down Expand Up @@ -335,6 +310,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
config: grandpa_config,
link: grandpa_link,
network,
sync: Arc::new(sync_service),
voting_rule: sc_consensus_grandpa::VotingRulesBuilder::default().build(),
prometheus_registry,
shared_voter_state: SharedVoterState::empty(),
Expand Down
14 changes: 7 additions & 7 deletions tuxedo-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ parity-util-mem = { version = '0.12.0', optional = true }

aggregator = { path = "aggregator" }

sp-api = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-03", default_features = false}
sp-debug-derive = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-03", default_features = false, features = ["force-debug"] }
sp-core = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-03", default_features = false}
sp-io = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-03", default_features = false, features = ["with-tracing"] }
sp-runtime = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-03", default_features = false}
sp-std = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-03", default_features = false}
sp-storage = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-03", default_features = false}
sp-api = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-04", default_features = false}
sp-debug-derive = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-04", default_features = false, features = ["force-debug"] }
sp-core = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-04", default_features = false}
sp-io = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-04", default_features = false, features = ["with-tracing"] }
sp-runtime = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-04", default_features = false}
sp-std = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-04", default_features = false}
sp-storage = { git = 'https://github.com/paritytech/substrate', tag = "monthly-2023-04", default_features = false}

[dev-dependencies]
array-bytes = "6.0.0"
Expand Down
71 changes: 30 additions & 41 deletions tuxedo-core/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,30 @@ mod test {
use super::*;
use sp_core::{crypto::Pair as _, sr25519::Pair};

/// Generate a bunch of test keypairs
fn generate_n_pairs(n: u8) -> Vec<Pair> {
let mut seed = [0u8; 32];
let mut pairs = Vec::new();

// We generate the pairs from sequential seeds. Just changing the last byte of the seed each time.
for i in 0..n {
seed[31] = i;

let pair = Pair::from_seed(&seed);
pairs.push(pair);
}

pairs
}

#[test]
fn up_for_grabs_always_verifies() {
assert!(UpForGrabs.verify(&[], &[]))
}

#[test]
fn sig_check_with_good_sig() {
let pair = Pair::from_entropy(b"entropy_entropy_entropy_entropy!".as_slice(), None).0;
let pair = Pair::from_seed(&[0u8; 32]);
let simplified_tx = b"hello world".as_slice();
let sig = pair.sign(simplified_tx);
let redeemer: &[u8] = sig.as_ref();
Expand All @@ -185,15 +201,8 @@ mod test {

#[test]
fn threshold_multisig_with_enough_sigs_passes() {
let pairs: Vec<_> = (1..3)
.map(|i| {
Pair::from_entropy(
format!("entropy_entropy_entropy_entropy{}", i).as_bytes(),
None,
)
.0
})
.collect();
let threshold = 2;
let pairs = generate_n_pairs(threshold);

let signatories: Vec<H256> = pairs.iter().map(|p| H256::from(p.public())).collect();

Expand All @@ -209,7 +218,7 @@ mod test {

let redeemer: &[u8] = &sigs.encode()[..];
let threshold_multisig = ThresholdMultiSignature {
threshold: 2,
threshold,
signatories,
};

Expand All @@ -218,21 +227,15 @@ mod test {

#[test]
fn threshold_multisig_not_enough_sigs_fails() {
let pairs: Vec<_> = (1..3)
.map(|i| {
Pair::from_entropy(
format!("entropy_entropy_entropy_entropy{}", i).as_bytes(),
None,
)
.0
})
.collect();
let threshold = 3;
let pairs = generate_n_pairs(threshold);

let signatories: Vec<H256> = pairs.iter().map(|p| H256::from(p.public())).collect();

let simplified_tx = b"hello_world".as_slice();
let sigs: Vec<_> = pairs
.iter()
.take(threshold as usize - 1)
.enumerate()
.map(|(i, p)| SignatureAndIndex {
signature: p.sign(simplified_tx),
Expand All @@ -242,7 +245,7 @@ mod test {

let redeemer: &[u8] = &sigs.encode()[..];
let threshold_multisig = ThresholdMultiSignature {
threshold: 3,
threshold,
signatories,
};

Expand All @@ -251,15 +254,8 @@ mod test {

#[test]
fn threshold_multisig_replay_sig_attack_fails() {
let pairs: Vec<_> = (1..3)
.map(|i| {
Pair::from_entropy(
format!("entropy_entropy_entropy_entropy{}", i).as_bytes(),
None,
)
.0
})
.collect();
let threshold = 2;
let pairs = generate_n_pairs(threshold);

let signatories: Vec<H256> = pairs.iter().map(|p| H256::from(p.public())).collect();

Expand All @@ -278,7 +274,7 @@ mod test {

let redeemer: &[u8] = &sigs.encode()[..];
let threshold_multisig = ThresholdMultiSignature {
threshold: 2,
threshold,
signatories,
};

Expand All @@ -287,15 +283,8 @@ mod test {

#[test]
fn threshold_multisig_has_duplicate_signatories_fails() {
let pairs: Vec<_> = (1..3)
.map(|i| {
Pair::from_entropy(
format!("entropy_entropy_entropy_entropy{}", i).as_bytes(),
None,
)
.0
})
.collect();
let threshold = 2;
let pairs = generate_n_pairs(threshold);

let signatories: Vec<H256> =
vec![H256::from(pairs[0].public()), H256::from(pairs[0].public())];
Expand All @@ -313,7 +302,7 @@ mod test {
let redeemer: &[u8] = &sigs.encode()[..];

let threshold_multisig = ThresholdMultiSignature {
threshold: 2,
threshold,
signatories,
};

Expand Down
Loading

0 comments on commit b696cd1

Please sign in to comment.